src/Controller/Registration/RegistrationStudentRegistrationController.php line 1105

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Registration;
  3. use DateInterval;
  4. use Knp\Snappy\Pdf;
  5. use App\Entity\User;
  6. use DateTimeImmutable;
  7. use App\Entity\SettingFee;
  8. use App\Service\SMSSender;
  9. use App\Entity\StockKitOut;
  10. use App\Entity\TransportZone;
  11. use App\Entity\StockKitOutLine;
  12. use App\Entity\SettingClassroom;
  13. use App\Service\DateIntervalManage;
  14. use App\Entity\CommunicationMessage;
  15. use App\Entity\SettingDocumentToProvide;
  16. use App\Repository\DocManagerRepository;
  17. use App\Repository\SettingFeeRepository;
  18. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  19. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  20. use App\Repository\TransportZoneRepository;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use App\Repository\EquivalentMatterRepository;
  23. use App\Repository\SchoolReportCardRepository;
  24. use App\Repository\SettingClassroomRepository;
  25. use App\Repository\StockKitCategoryRepository;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use App\Entity\RegistrationStudentRegistration;
  28. use App\Entity\RegistrationTransportCheckpoint;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use App\Entity\AccountingStudentRegistrationFee;
  31. use Doctrine\Common\Collections\ArrayCollection;
  32. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  33. use App\Entity\RegistrationStudentPreRegistration;
  34. use App\Entity\AccountingStudentRegistrationFeeShedul;
  35. use App\Repository\SettingDocumentToProvideRepository;
  36. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  37. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  38. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  39. use App\Form\Accounting\AccountingStudentRegistrationFeeType;
  40. use App\Repository\RegistrationStudentRegistrationRepository;
  41. use App\Form\Registration\RegistrationStudentRegistrationType;
  42. use App\Form\Registration\RegistrationTransportCheckpointType;
  43. use App\Repository\AccountingStudentRegistrationFeeRepository;
  44. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  45. use App\Repository\RegistrationStudentPreRegistrationRepository;
  46. use App\Repository\RegistrationStudentRepository;
  47. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  48. /**
  49.  * @Route("/registration/student-registration")
  50.  */
  51. class RegistrationStudentRegistrationController extends AbstractController
  52. {
  53.     /**
  54.      * @Route("/index/{_from}", name="registration_student_registration_index", methods={"GET"})
  55.      */
  56.     public function index($_from 'All'): Response
  57.     {
  58.         return $this->render('registration/registration_student_registration/index.html.twig', [
  59.             '_from' => $_from,
  60.         ]);
  61.     }
  62.     /**
  63.      * @Route("/_searh-table/{_from}", name="registration_student_registration_searh_table", methods={"GET","POST"})
  64.      */
  65.     public function _searh_table($_from 'All'Request $requestRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
  66.     {
  67.         /**@var User $user */
  68.         $user $this->getUser();
  69.         $establishment $user->getEstablishment();
  70.         $schoolYear $user->getSchoolYear();
  71.         $query $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  72.         ->innerJoin('entity.student''student')
  73.         ->addSelect('student')
  74.         ->andWhere('entity.establishment = :establishment')
  75.         ->setParameter('establishment'$establishment)
  76.         
  77.         ->andWhere('entity.schoolYear = :schoolYear')
  78.         ->setParameter('schoolYear'$schoolYear)
  79.         
  80.         ->andWhere('entity.status != :status')
  81.         ->setParameter('status'RegistrationStudentRegistration::STATUS_ABANDONNE);
  82.         if ($request->get('registrationNumber')) {
  83.             $query $query
  84.             ->andWhere('student.registration_number LIKE :registration_number')
  85.             ->setParameter('registration_number''%'.$request->get('registrationNumber').'%');
  86.         }
  87.         
  88.         if ($request->get('code')) {
  89.             $query $query
  90.             ->andWhere('student.code LIKE :code')
  91.             ->setParameter('code''%'.$request->get('code').'%');
  92.         }
  93.         if ($request->get('lastName')) {
  94.             $query $query
  95.             ->andWhere('student.last_name LIKE :last_name')
  96.             ->setParameter('last_name''%'.$request->get('lastName').'%');
  97.         }
  98.         if ($request->get('firstName')) {
  99.             $query $query
  100.             ->andWhere('student.first_name LIKE :first_name')
  101.             ->setParameter('first_name''%'.$request->get('firstName').'%');
  102.         } 
  103.         if ($request->get('phoneNumber')) {
  104.             $query $query
  105.             ->andWhere('student.notification_phone_number LIKE :notification_phone_number')
  106.             ->setParameter('notification_phone_number''%'.$request->get('phoneNumber').'%');
  107.         } 
  108.         $query $query
  109.         ->orderBy('student.last_name''ASC')
  110.         ->getQuery();
  111.         $registration_student_registrations $query
  112.         ->setMaxResults(100)
  113.         ->getResult();
  114.         return $this->renderForm('registration/registration_student_registration/_searh_table.html.twig', [
  115.             'registration_student_registrations' => $registration_student_registrations,
  116.             '_from' => $_from,
  117.         ]);
  118.     }
  119.     /**
  120.      * @Route("/new", name="registration_student_registration_new", methods={"GET","POST"})
  121.      */
  122.     public function new(Request $requestSettingFeeRepository $settingFeeRepositoryRegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepositorySettingDocumentToProvideRepository $settingDocumentToProvideRepositoryRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepositorySettingClassroomRepository $settingClassroomRepository): Response
  123.     {
  124.         /**@var User $user */
  125.         $user $this->getUser();
  126.         $schoolYear $user->getSchoolYear();
  127.         $establishment $user->getEstablishment();
  128.         
  129.         if ($schoolYear == null) {
  130.             $this->addFlash('warning'"Aucune base de donnée n'est activé.");
  131.             return $this->redirectToRoute('registration_student_registration_new');
  132.         }
  133.         /* recuperation des non encore incrits */
  134.         $unregisteredRegistrationStudentPreRegistrations = new ArrayCollection();
  135.         $registrationStudentPreRegistrations $registrationStudentPreRegistrationRepository->createQueryBuilder('entity')
  136.         ->andWhere('entity.establishment = :establishment')
  137.         ->setParameter('establishment'$establishment)
  138.         ->andWhere('entity.schoolYear = :schoolYear')
  139.         ->setParameter('schoolYear'$schoolYear)
  140.         ->getQuery()
  141.         ->getResult();
  142.         foreach ($registrationStudentPreRegistrations as $key => $registrationStudentPreRegistration) {
  143.             if ($registrationStudentPreRegistration->getStudent() != null) {
  144.                 if(count($registrationStudentPreRegistration->getRegistrationStudentRegistrations()) <= 0){
  145.                     if ($registrationStudentPreRegistration->getIsEntryTestPerformed() or !$registrationStudentPreRegistration->getIsSubjectEntryTest()) {
  146.                         $unregisteredRegistrationStudentPreRegistrations->add($registrationStudentPreRegistration);
  147.                     }
  148.                 } 
  149.             }
  150.         }
  151.         $registrationStudentRegistration = new RegistrationStudentRegistration();
  152.         $registrationStudentRegistration->setPortalLogin($registrationStudentRegistration->getId().time());
  153.         $registrationStudentRegistration->setPortalPassword(uniqid());
  154.         $form $this->createForm(RegistrationStudentRegistrationType::class, $registrationStudentRegistration)
  155.         
  156.         ->add('registrationStudentPreRegistration'EntityType::class, [
  157.             'class' => RegistrationStudentPreRegistration::class,
  158.             'choices' => $unregisteredRegistrationStudentPreRegistrations
  159.         ])
  160.         ->add('classroom'EntityType::class, [
  161.             'class' => SettingClassroom::class,
  162.             'choices' => $settingClassroomRepository->findBy(['schoolYear' => $schoolYear'establishment' => $establishment], ['label' => 'ASC'])
  163.             //'choices' => $settingClassroomRepository->findBy(['schoolYear' => $schoolYear, 'is_excellent' => 0], ['label' => 'ASC'])
  164.         ])
  165.         ->add('documentProvides'EntityType::class, [
  166.             'class' => SettingDocumentToProvide::class,
  167.             'choices' => $settingDocumentToProvideRepository->findBy(['establishment' => $establishment], []),
  168.             'multiple' => true,
  169.             'required' => false
  170.         ]);
  171.         $form->handleRequest($request);
  172.         if($form->isSubmitted() && $form->isValid()) {
  173.             $entityManager $this->getDoctrine()->getManager();
  174.             $student $registrationStudentRegistration->getRegistrationStudentPreRegistration()->getStudent();
  175.             if ($registrationStudentRegistrationRepository->findOneBy(['establishment' => $establishment'schoolYear' => $schoolYear'student' => $student], []) != null) {
  176.                 $this->addFlash('warning'"Cet élève est déjà inscrit");
  177.                 return $this->redirectToRoute('registration_student_registration_new');
  178.             }
  179.             $registrationStudentRegistration->setSchoolYear($schoolYear);
  180.             $registrationStudentRegistration->setEstablishment($establishment);
  181.             
  182.             $registrationStudentRegistration->setStudent($student);
  183.             $registrationStudentRegistration->setIsAffected($student->getIsAffected());
  184.             
  185.             if (count($student->getRegistrationStudentRegistrations()) <= 0) {
  186.                 if ($student->getAnteriorBalance() > 0) {
  187.                     // Ajout de solde anterieur pour la première année de gestion
  188.                     $fee $settingFeeRepository->findOneBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $schoolYear'label'  => 'SOLDE ANTERIEUR'], []);
  189.                     if (null == $fee) {
  190.                         $fee = new SettingFee();
  191.                         $fee->setEstablishment($registrationStudentRegistration->getEstablishment());
  192.                         $fee->setCategory('AUTRE-FRAIS');
  193.                         $fee->setLabel('SOLDE ANTERIEUR');
  194.                         $fee->setAmount(0);
  195.                         $fee->setSchoolYear($schoolYear);
  196.                         $fee->setIsForAll(false);
  197.                         $fee->setIsForAffected(false);
  198.                         $fee->setIsForNonAffected(false);
  199.                         $entityManager->persist($fee);
  200.                     }
  201.                     $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
  202.                     $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
  203.                     $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  204.                     $anteriorAccountingStudentRegistrationFee->setFee($fee);
  205.                     $anteriorAccountingStudentRegistrationFee->setAmount($student->getAnteriorBalance());
  206.                     $anteriorAccountingStudentRegistrationFee->setCode($fee->getLabel().'-'.$registrationStudentRegistration->getId());
  207.                     $anteriorAccountingStudentRegistrationFee->setLabel($fee->getLabel());
  208.                     $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  209.                     $anteriorAccountingStudentRegistrationFeeShedul->setAmount($student->getAnteriorBalance());
  210.                     $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  211.                     $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum(1);
  212.                     $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
  213.                     $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
  214.                     
  215.                     $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
  216.                     $entityManager->persist($anteriorAccountingStudentRegistrationFee);
  217.                 }
  218.             }
  219.             // Ajout de solde anterieur à partir de la deuxième année de gestion
  220.             $anteriorRegistrationStudentRegistration $registrationStudentRegistrationRepository->findOneBy(['student' => $registrationStudentRegistration->getStudent()], ['id' => 'DESC']);
  221.             $order 0;
  222.             if (null != $anteriorRegistrationStudentRegistration) {
  223.                 foreach ($anteriorRegistrationStudentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
  224.                     $order++;
  225.                     if (!$accountingStudentRegistrationFee->getIsArchived()) {
  226.                         if (!$accountingStudentRegistrationFee->getIsCancel()) {
  227.                             if (!$accountingStudentRegistrationFee->getIsReported()) {
  228.                                 if ($accountingStudentRegistrationFee->getAmountRest() > 0) {
  229.                                     $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
  230.                                     $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
  231.                                     $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  232.                                     $anteriorAccountingStudentRegistrationFee->setFee($accountingStudentRegistrationFee->getFee());
  233.                                     $anteriorAccountingStudentRegistrationFee->setAmount($accountingStudentRegistrationFee->getAmountRest());
  234.                                     $anteriorAccountingStudentRegistrationFee->setCode('SA-'.$accountingStudentRegistrationFee->getLabel().'-'.$registrationStudentRegistration->getId());
  235.                                     $anteriorAccountingStudentRegistrationFee->setLabel('SOLDE ANT. '.$accountingStudentRegistrationFee->getLabel());
  236.                                     $anteriorAccountingStudentRegistrationFee->setIsArchived($accountingStudentRegistrationFee->getIsArchived());
  237.                                     $anteriorAccountingStudentRegistrationFee->setIsCancel($accountingStudentRegistrationFee->getIsCancel());
  238.                                     $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  239.                                     $anteriorAccountingStudentRegistrationFeeShedul->setAmount($anteriorAccountingStudentRegistrationFee->getAmount());
  240.                                     $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  241.                                     $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum($order);
  242.                                     $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
  243.                                     $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
  244.                                     
  245.                                     foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
  246.                                         $accountingStudentRegistrationFeeShedul->setAmountReported($accountingStudentRegistrationFeeShedul->getAmountCancel() + $accountingStudentRegistrationFeeShedul->getAmountRest());
  247.                                         $accountingStudentRegistrationFeeShedul->setIsReported(true);
  248.                                     }
  249.                                     
  250.                                     $accountingStudentRegistrationFee->setIsReported(true);
  251.                                     $accountingStudentRegistrationFee->setAmountReported($accountingStudentRegistrationFee->getAmountRest());
  252.                                     $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
  253.                                     $entityManager->persist($anteriorAccountingStudentRegistrationFee);
  254.                                 }
  255.                             }
  256.                         }
  257.                     }
  258.                 }
  259.             }
  260.             /* Ajout des frais de SCOLARITE pour tous*/
  261.             $settingScolariteFees $settingFeeRepository->findBy(['is_for_all' => true'category' => 'SCOLARITE''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  262.             foreach ($settingScolariteFees as $key => $settingFee) {
  263.                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  264.                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  265.                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  266.                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  267.                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  268.                     $accountingStudentRegistrationFee->setFee($settingFee);
  269.                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  270.                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  271.                     $entityManager->persist($accountingStudentRegistrationFee);
  272.                     /* Etablissement des echeanciers */
  273.                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
  274.                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  275.                             $order++;
  276.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  277.                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  278.                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  279.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  280.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  281.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  282.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  283.                         }
  284.                     }else {
  285.                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  286.                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  287.                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  288.                         $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  289.                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  290.                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  291.                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
  292.                     }
  293.                 }
  294.             }
  295.             /* Ajout des frais de SCOLARITE  specifiques */
  296.             $settingScolariteAffectedFees $settingFeeRepository->findBy(['is_for_affected' => true'category' => 'SCOLARITE''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  297.             $settingScolariteNonAffectedFees $settingFeeRepository->findBy(['is_for_non_affected' => true'category' => 'SCOLARITE''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  298.             if ($registrationStudentRegistration->getIsAffected()) {
  299.                 foreach ($settingScolariteAffectedFees as $key => $settingFee) {
  300.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  301.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  302.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  303.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  304.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  305.                         $accountingStudentRegistrationFee->setFee($settingFee);
  306.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  307.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  308.                         $entityManager->persist($accountingStudentRegistrationFee);
  309.                         /* Etablissement des echeancier */
  310.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  311.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  312.                                 $order++;
  313.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  314.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  315.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  316.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  317.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  318.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  319.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  320.                             }
  321.                         }else {
  322.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  323.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  324.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  325.                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  326.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  327.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  328.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  329.                         }
  330.                     }
  331.                 }
  332.             }else{
  333.                 foreach ($settingScolariteNonAffectedFees as $key => $settingFee) {
  334.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  335.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  336.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  337.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  338.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  339.                         $accountingStudentRegistrationFee->setFee($settingFee);
  340.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  341.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  342.                         $entityManager->persist($accountingStudentRegistrationFee);
  343.                         /* Etablissement des echeancier */
  344.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  345.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  346.                                 $order++;
  347.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  348.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  349.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  350.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  351.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  352.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  353.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  354.                             }
  355.                         }else {
  356.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  357.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  358.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  359.                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  360.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  361.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  362.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  363.                         }
  364.                     }
  365.                 }
  366.             }
  367.             /* Ajout des frais de ARTICLE pour tous */
  368.             $settingArticleFees $settingFeeRepository->findBy(['is_for_all' => true'category' => 'ARTICLE''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  369.             $settingArticleAffectedFees $settingFeeRepository->findBy(['is_for_affected' => true'category' => 'ARTICLE''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  370.             $settingArticleNonAffectedFees $settingFeeRepository->findBy(['is_for_non_affected' => true'category' => 'ARTICLE''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  371.             foreach ($settingArticleFees as $key => $settingFee) {
  372.                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  373.                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  374.                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  375.                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  376.                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  377.                     $accountingStudentRegistrationFee->setFee($settingFee);
  378.                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  379.                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  380.                     $entityManager->persist($accountingStudentRegistrationFee);
  381.                     /* Etablissement des echeancier */
  382.                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
  383.                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  384.                             $order++;
  385.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  386.                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  387.                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  388.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  389.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  390.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  391.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  392.                         }
  393.                     }else {
  394.                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  395.                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  396.                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  397.                         $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  398.                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  399.                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  400.                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
  401.                     }
  402.                 }
  403.             }
  404.             /* Ajout des frais de ARTICLE specifique */
  405.             if ($registrationStudentRegistration->getIsAffected()) {
  406.                 foreach ($settingArticleAffectedFees as $key => $settingFee) {
  407.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  408.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  409.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  410.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  411.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  412.                         $accountingStudentRegistrationFee->setFee($settingFee);
  413.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  414.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  415.                         $entityManager->persist($accountingStudentRegistrationFee);
  416.                         /* Etablissement des echeancier */
  417.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  418.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  419.                                 $order++;
  420.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  421.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  422.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  423.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  424.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  425.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  426.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  427.                             }
  428.                         }else {
  429.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  430.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  431.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  432.                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  433.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  434.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  435.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  436.                         }
  437.                     }
  438.                 }
  439.             }else {
  440.                 foreach ($settingArticleNonAffectedFees as $key => $settingFee) {
  441.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  442.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  443.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  444.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  445.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  446.                         $accountingStudentRegistrationFee->setFee($settingFee);
  447.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  448.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  449.                         $entityManager->persist($accountingStudentRegistrationFee);
  450.                         /* Etablissement des echeancier */
  451.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  452.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  453.                                 $order++;
  454.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  455.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  456.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  457.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  458.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  459.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  460.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  461.                             }
  462.                         }else {
  463.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  464.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  465.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  466.                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  467.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  468.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  469.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  470.                         }
  471.                     }
  472.                 }
  473.             }
  474.             /* Ajout des frais de ACTIVITE-EXTAT pour tous */
  475.             $settingActiviteExtratFees $settingFeeRepository->findBy(['is_for_all' => true'category' => 'ACTIVITE-EXTAT''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  476.             $settingActiviteExtratAffectedFees $settingFeeRepository->findBy(['is_for_affected' => true'category' => 'ACTIVITE-EXTAT''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  477.             $settingActiviteExtratNonAffectedFees $settingFeeRepository->findBy(['is_for_non_affected' => true'category' => 'ACTIVITE-EXTAT''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  478.             foreach ($settingActiviteExtratFees as $key => $settingFee) {
  479.                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  480.                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  481.                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  482.                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  483.                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  484.                     $accountingStudentRegistrationFee->setFee($settingFee);
  485.                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  486.                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  487.                     $entityManager->persist($accountingStudentRegistrationFee);
  488.                     /* Etablissement des echeancier */
  489.                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
  490.                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  491.                             $order++;
  492.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  493.                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  494.                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  495.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  496.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  497.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  498.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  499.                         }
  500.                     }else {
  501.                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  502.                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  503.                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  504.                         $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  505.                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  506.                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  507.                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
  508.                     }
  509.                 }
  510.             }
  511.             /* Ajout des frais de ACTIVITE-EXTAT specifique */
  512.             if ($registrationStudentRegistration->getIsAffected()) {
  513.                 foreach ($settingActiviteExtratAffectedFees as $key => $settingFee) {
  514.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  515.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  516.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  517.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  518.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  519.                         $accountingStudentRegistrationFee->setFee($settingFee);
  520.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  521.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  522.                         $entityManager->persist($accountingStudentRegistrationFee);
  523.                         /* Etablissement des echeancier */
  524.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  525.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  526.                                 $order++;
  527.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  528.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  529.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  530.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  531.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  532.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  533.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  534.                             }
  535.                         }else {
  536.                             $order++;
  537.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  538.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  539.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  540.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  541.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  542.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  543.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  544.                         }
  545.                     }
  546.                 }
  547.             }else {
  548.                 foreach ($settingActiviteExtratNonAffectedFees as $key => $settingFee) {
  549.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  550.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  551.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  552.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  553.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  554.                         $accountingStudentRegistrationFee->setFee($settingFee);
  555.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  556.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  557.                         $entityManager->persist($accountingStudentRegistrationFee);
  558.                         /* Etablissement des echeancier */
  559.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  560.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  561.                                 $order++;
  562.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  563.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  564.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  565.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  566.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  567.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  568.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  569.                             }
  570.                         }else {
  571.                             $order++;
  572.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  573.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  574.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  575.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  576.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  577.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  578.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  579.                         }
  580.                     }
  581.                 }
  582.             }
  583.             /* Ajout des frais de AUTRE-FRAIS pour tous */
  584.             $settingAutreFraisFees $settingFeeRepository->findBy(['is_for_all' => true'category' => 'AUTRE-FRAIS''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  585.             $settingAutreFraisAffectedFees $settingFeeRepository->findBy(['is_for_affected' => true'category' => 'AUTRE-FRAIS''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  586.             $settingAutreFraisNonAffectedFees $settingFeeRepository->findBy(['is_for_non_affected' => true'category' => 'AUTRE-FRAIS''schoolYear' => $schoolYear'establishment' => $establishment],['id' => 'DESC']);
  587.             foreach ($settingAutreFraisFees as $key => $settingFee) {
  588.                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  589.                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  590.                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  591.                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  592.                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  593.                     $accountingStudentRegistrationFee->setFee($settingFee);
  594.                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  595.                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  596.                     $entityManager->persist($accountingStudentRegistrationFee);
  597.                     /* Etablissement des echeancier */
  598.                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
  599.                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  600.                             $order++;
  601.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  602.                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  603.                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  604.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  605.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  606.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  607.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  608.                         }
  609.                     }else {
  610.                         $order++;
  611.                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  612.                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  613.                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  614.                         $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  615.                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  616.                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  617.                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
  618.                     }
  619.                 }
  620.             }
  621.             /* Ajout des frais de ACTIVITE-EXTAT specifique */
  622.             if ($registrationStudentRegistration->getIsAffected()) {
  623.                 foreach ($settingAutreFraisAffectedFees as $key => $settingFee) {
  624.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  625.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  626.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  627.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  628.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  629.                         $accountingStudentRegistrationFee->setFee($settingFee);
  630.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  631.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  632.                         $entityManager->persist($accountingStudentRegistrationFee);
  633.                         /* Etablissement des echeancier */
  634.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  635.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  636.                                 $order++;
  637.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  638.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  639.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  640.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  641.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  642.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  643.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  644.                             }
  645.                         }else {
  646.                             $order++;
  647.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  648.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  649.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  650.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  651.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  652.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  653.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  654.                         }
  655.                     }
  656.                 }
  657.             }else {
  658.                 foreach ($settingAutreFraisNonAffectedFees as $key => $settingFee) {
  659.                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
  660.                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
  661.                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  662.                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
  663.                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
  664.                         $accountingStudentRegistrationFee->setFee($settingFee);
  665.                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
  666.                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
  667.                         $entityManager->persist($accountingStudentRegistrationFee);
  668.                         /* Etablissement des echeancier */
  669.                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
  670.                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  671.                                 $order++;
  672.                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  673.                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
  674.                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  675.                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  676.                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  677.                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  678.                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  679.                             }
  680.                         }else {
  681.                             $order++;
  682.                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  683.                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
  684.                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  685.                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
  686.                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  687.                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  688.                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
  689.                         }
  690.                     }
  691.                 }
  692.             }
  693.             $entityManager->persist($registrationStudentRegistration);
  694.             try {
  695.                 $entityManager->flush();
  696.                 $this->addFlash('success'"Un inscrit à été ajouté.");
  697.             } catch (\Throwable $th) {
  698.                 $this->addFlash('warning'"Une erreure est survenue lors de l'ajout de l'inscrit.");
  699.                 $this->addFlash('info'$th->getMessage());
  700.             }
  701.             return $this->redirectToRoute('registration_student_registration_index', [], Response::HTTP_SEE_OTHER);
  702.         }
  703.         return $this->renderForm('registration/registration_student_registration/new.html.twig', [
  704.             'registration_student_registration' => $registrationStudentRegistration,
  705.             'form' => $form,
  706.         ]);
  707.     }
  708.     /**
  709.      * @Route("/{id}/show", name="registration_student_registration_show", methods={"GET","POST"})
  710.      */
  711.     public function show(Request $requestRegistrationStudentRegistration $registrationStudentRegistrationSettingFeeRepository $settingFeeRepositoryTransportZoneRepository $transportZoneRepositorySMSSender $smsSender): Response
  712.     {
  713.         /**@var User $user */
  714.         $user $this->getUser();
  715.         $schoolYear $user->getSchoolYear();
  716.         $establishment $this->getUser()->getEstablishment();
  717.         
  718.         /* Ajouter un nouveau frais */
  719.         $setting_fees $settingFeeRepository->createQueryBuilder('entity')
  720.         ->andWhere('entity.establishment = :establishment')
  721.         ->setParameter('establishment'$establishment)
  722.         ->andWhere('entity.schoolYear = :schoolYear')
  723.         ->setParameter('schoolYear'$schoolYear)
  724.         ->andWhere('entity.category != :category')
  725.         ->setParameter('category''SCOLARITE')
  726.         ->andWhere('entity.category != :category')
  727.         ->setParameter('category'SettingFee::TRANSPORT_FEE)
  728.         ->orderBy('entity.id''DESC')
  729.         ->getQuery()
  730.         ->getResult();
  731.         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
  732.         $accountingStudentRegistrationFeeForm $this->createForm(AccountingStudentRegistrationFeeType::class, $accountingStudentRegistrationFee)
  733.         ->add('fee'EntityType::class,[
  734.             'class' => SettingFee::class,
  735.             'choices' => $setting_fees
  736.         ])
  737.         ->add('quantity'NumberType::class, [
  738.             'attr' => [
  739.                 'class' => 'form-control',
  740.                 'style' => 'width: 100%;'
  741.             ],
  742.             'mapped' => false,
  743.             'required' => true,
  744.             'data' => 1
  745.         ]);
  746.         $accountingStudentRegistrationFeeForm->handleRequest($request);
  747.         if ($accountingStudentRegistrationFeeForm->isSubmitted() && $accountingStudentRegistrationFeeForm->isValid()) {
  748.             $entityManager $this->getDoctrine()->getManager();
  749.             $settingFee $accountingStudentRegistrationFee->getFee();
  750.             if (strlen($settingFee->getDuration()) > && null == $accountingStudentRegistrationFee->getStartAt()) {
  751.                 $this->addFlash('warning'"Veuillez saisir la date de debut SVP.");
  752.                 return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
  753.             }
  754.             /** set start date end end date */
  755.             if (null != $accountingStudentRegistrationFee->getStartAt()) {
  756.                 if ($settingFee->getDuration() == 'JOURNALIER') {
  757.                     $accountingStudentRegistrationFee->setEndAt($accountingStudentRegistrationFee->getStartAt());
  758.                     
  759.                 }
  760.                 if ($settingFee->getDuration() == 'HEBDOMADAIRE') {
  761.                     $date $accountingStudentRegistrationFee->getStartAt();
  762.                     $njdsc date($date->format('w') , strtotime("-7 days"));
  763.                     $njmc date("t");
  764.                     switch ($njdsc) {
  765.                         case 0:
  766.                             $accountingStudentRegistrationFee->setEndAt($date->sub(new DateInterval("P2D")));
  767.                             break;
  768.                         case 1:
  769.                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P4D")));
  770.                             break;
  771.                         case 2:
  772.                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P3D")));
  773.                             break;
  774.                         case 3:
  775.                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P2D")));
  776.                             break;
  777.                         case 4:
  778.                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P1D")));
  779.                             break;
  780.                         case 5:
  781.                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P0D")));
  782.                             break;
  783.                         case 6:
  784.                             $accountingStudentRegistrationFee->setEndAt($date->sub(new DateInterval("P1D")));
  785.                             break;
  786.                         default:
  787.                             # code...
  788.                             break;
  789.                     }
  790.                 }
  791.                 if ($settingFee->getDuration() == 'MENSUEL-SIMPLE') {
  792.                     $date $accountingStudentRegistrationFee->getStartAt();
  793.                     $njdsc date($date->format('w') , strtotime("-7 days"));
  794.                     $njmc date("t");
  795.                     $date_end = new DateTimeImmutable($date->format('Y-m-').$njmc);
  796.                     $accountingStudentRegistrationFee->setEndAt($date_end);
  797.                     if ($date_end->format('D') == 'Sun') {
  798.                         $accountingStudentRegistrationFee->setEndAt($date_end->sub(new DateInterval("P2D")));
  799.                     }
  800.                     if ($date_end->format('D') == 'Sat') {
  801.                         $accountingStudentRegistrationFee->setEndAt($date_end->sub(new DateInterval("P1D")));
  802.                     }
  803.                 }
  804.                 if ($settingFee->getDuration() == 'MENSUEL-FULL') {
  805.                     $date $accountingStudentRegistrationFee->getStartAt();
  806.                     $njdsc date($date->format('w') , strtotime("-7 days"));
  807.                     $njmc date("t");
  808.                     $date_end = new DateTimeImmutable($date->format('Y-m-').$njmc);
  809.                     $accountingStudentRegistrationFee->setEndAt($date_end);
  810.                 }
  811.                 $contacts = [];
  812.                 $contacts[] = '225'.str_replace(' ''',trim($registrationStudentRegistration->getStudent()->getNotificationPhoneNumber()));
  813.                 $message "BIENVENUE A LA GARDERIE, VOTRE ABONNEMENT "$settingFee->getLabel() ." DEBUTE LE "strtoupper(DateIntervalManage::FRENCH_DAY[$accountingStudentRegistrationFee->getStartAt()->format('D')]). ' ' .$accountingStudentRegistrationFee->getStartAt()->format('d'). ' ' .strtoupper(DateIntervalManage::FRENCH_MONTH[$accountingStudentRegistrationFee->getStartAt()->format('m')]). ' '$accountingStudentRegistrationFee->getStartAt()->format('Y') ." A 07H00 ET PRENDRA FIN LE ".  strtoupper(DateIntervalManage::FRENCH_DAY[$accountingStudentRegistrationFee->getEndAt()->format('D')]). ' ' .$accountingStudentRegistrationFee->getEndAt()->format('d'). ' ' .strtoupper(DateIntervalManage::FRENCH_MONTH[$accountingStudentRegistrationFee->getEndAt()->format('m')]). ' '$accountingStudentRegistrationFee->getEndAt()->format('Y') ." A 18H00. Contact: ".$settingFee->getEstablishment()->getMobileNumber();
  814.                 try {
  815.                     $response $smsSender->sendSmsByEstablishment($establishment$message$contacts$smsSender::UNICODE_CHARSET);
  816.                     $responses explode(':'$response);
  817.                     $code trim($responses[1]);
  818.                     $communicationMessage = new CommunicationMessage();
  819.                     $communicationMessage->setCode($code);
  820.                     $communicationMessage->setContacts($contacts);
  821.                     $communicationMessage->setContent($message);
  822.                     $communicationMessage->setEstablishment($establishment);
  823.                     $communicationMessage->setType($smsSender::UNICODE_CHARSET);
  824.                     $entityManager->persist($communicationMessage);
  825.                 } catch (\Throwable $th) {
  826.                     //throw $th;
  827.                 }
  828.                 
  829.             }
  830.             /** */
  831.             $quantity $accountingStudentRegistrationFeeForm->get('quantity')->getData() ?? 1;
  832.             $label $quantity $settingFee->getLabel() . ' x ' $quantity $settingFee->getLabel();
  833.             $amount $settingFee->getAmount() * $quantity;
  834.             $accountingStudentRegistrationFee->setDuration($settingFee->getDuration());
  835.             $accountingStudentRegistrationFee->setEstablishment($establishment);
  836.             $accountingStudentRegistrationFee->setCode(time());
  837.             $accountingStudentRegistrationFee->setLabel($label);
  838.             $accountingStudentRegistrationFee->setAmount($amount);
  839.             $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  840.             $accountingStudentRegistrationFee->setFee($settingFee);
  841.             if (count($settingFee->getSettingFeeSheduls()) > 0) {
  842.                 $order 0;
  843.                 foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
  844.                     $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  845.                     $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount() * $quantity);
  846.                     
  847.                     if (null != $accountingStudentRegistrationFee->getStartAt()) {
  848.                         $accountingStudentRegistrationFeeShedul->setDateDue($accountingStudentRegistrationFee->getStartAt());
  849.                     }else {
  850.                         $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
  851.                     }
  852.                     $accountingStudentRegistrationFeeShedul->setOrderNum($order 1);
  853.                     $accountingStudentRegistrationFeeShedul->setEstablishment($establishment);
  854.                     $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  855.                     $entityManager->persist($accountingStudentRegistrationFeeShedul);
  856.                     $order++;
  857.                 }
  858.             }else {
  859.                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  860.                 $accountingStudentRegistrationFeeShedul->setAmount($amount);
  861.                 if (null != $accountingStudentRegistrationFee->getStartAt()) {
  862.                     $accountingStudentRegistrationFeeShedul->setDateDue($accountingStudentRegistrationFee->getStartAt());
  863.                 }else {
  864.                     $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  865.                 }
  866.                 
  867.                 $accountingStudentRegistrationFeeShedul->setOrderNum(1);
  868.                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
  869.                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  870.                 
  871.                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
  872.             }
  873.             foreach ($settingFee->getStockKitCategories() as $key => $stockKitCategory) {
  874.                 // sortie de kits
  875.                 $stockKitOut = new StockKitOut();
  876.                 $stockKitOut->setEstablishment($establishment);
  877.                 $stockKitOut->setSchoolYear($schoolYear);
  878.                 $stockKitOut->setRegistrationStudent($registrationStudentRegistration);
  879.                 $stockKitOut->setAccountingStudentRegistrationFee($accountingStudentRegistrationFee);
  880.                 $stockKitOut->setIsValidated(false);
  881.                 $stockKitOut->setKitCategory($stockKitCategory);
  882.                 $stockKitOut->setCreateDate(new DateTimeImmutable());
  883.                 // lignes de sortie de kits
  884.                 foreach ($stockKitCategory->getStockKitProducts() as $key => $stockKitProduct) {
  885.                     $stockKitOutLine = new StockKitOutLine();
  886.                     $stockKitOutLine->setEstablishment($establishment);
  887.                     $stockKitOutLine->setSchoolYear($schoolYear);
  888.                     $stockKitOutLine->setStockKitOut($stockKitOut);
  889.                     $stockKitOutLine->setStockKitProduct($stockKitProduct);
  890.                     $stockKitOutLine->setProduct($stockKitProduct->getProduct());
  891.                     $stockKitOutLine->setQuantity($quantity);
  892.                     $entityManager->persist($stockKitOutLine);
  893.                 }
  894.                 $entityManager->persist($stockKitOut);
  895.             }
  896.             
  897.             $entityManager->persist($accountingStudentRegistrationFee);
  898.             
  899.             try {
  900.                 $this->getDoctrine()->getManager()->flush();
  901.                 $accountingStudentRegistrationFee->setCode('ABN-'.sprintf("%'05s"$accountingStudentRegistrationFee->getId()));
  902.                 $this->getDoctrine()->getManager()->flush();
  903.                 $this->addFlash('success'"des frais ont été ajouté.");
  904.             } catch (\Throwable $th) {
  905.                 $this->addFlash('info'$th->getMessage());
  906.             }
  907.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
  908.         }
  909.         $transport_zones $transportZoneRepository->createQueryBuilder('entity')
  910.         ->innerJoin('entity.establishment''establishment')
  911.         ->addSelect('establishment')
  912.         ->innerJoin('establishment.establishmentGroup''establishmentGroup')
  913.         ->addSelect('establishmentGroup')
  914.         ->andWhere('establishmentGroup.id = :establishmentGroupId')
  915.         ->setParameter('establishmentGroupId'$establishment->getEstablishmentGroup()->getId())
  916.         ->orderBy('entity.id''DESC')
  917.         ->getQuery()
  918.         ->getResult();
  919.         $registrationTransportCheckpoint = new RegistrationTransportCheckpoint();
  920.         $registrationTransportCheckpointForm $this->createForm(RegistrationTransportCheckpointType::class, $registrationTransportCheckpoint)
  921.         ->add('transportZone'EntityType::class, [
  922.             'class' => TransportZone::class,
  923.             'choices' => $transport_zones
  924.         ]);
  925.         $registrationTransportCheckpointForm->handleRequest($request);
  926.         if ($registrationTransportCheckpointForm->isSubmitted() && $registrationTransportCheckpointForm->isValid()) {
  927.             $entityManager $this->getDoctrine()->getManager();
  928.             $registrationTransportCheckpoint->setRegistrationStudentRegistration($registrationStudentRegistration);
  929.             $registrationTransportCheckpoint->setEstablishment($registrationStudentRegistration->getEstablishment());
  930.             $entityManager->persist($registrationTransportCheckpoint);
  931.             
  932.             try{
  933.                 $entityManager->flush();
  934.             }catch(\Throwable $th){
  935.                 $this->addFlash('info'$th->getMessage());
  936.             }
  937.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
  938.         }
  939.         if ($request->get('__cd_token___') == 'soldeAnterieur') {
  940.             $entityManager $this->getDoctrine()->getManager();
  941.             $fee $settingFeeRepository->findOneBy(['establishment' => $registrationStudentRegistration->getEstablishment(),'schoolYear' => $schoolYear'label'  => 'SOLDE ANTERIEUR'], []);
  942.             if (null == $fee) {
  943.                 $fee = new SettingFee();
  944.                 $fee->setEstablishment($registrationStudentRegistration->getEstablishment());
  945.                 $fee->setCategory('AUTRE-FRAIS');
  946.                 $fee->setLabel('SOLDE ANTERIEUR');
  947.                 $fee->setAmount(0);
  948.                 $fee->setSchoolYear($schoolYear);
  949.                 $entityManager->persist($fee);
  950.             }
  951.             $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
  952.             $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
  953.             $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  954.             $anteriorAccountingStudentRegistrationFee->setFee($fee);
  955.             $anteriorAccountingStudentRegistrationFee->setAmount(intval($request->get('anterior_balance_amount')));
  956.             $anteriorAccountingStudentRegistrationFee->setCode($fee->getLabel().'-'.$registrationStudentRegistration->getId());
  957.             $anteriorAccountingStudentRegistrationFee->setLabel($fee->getLabel());
  958.             $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  959.             $anteriorAccountingStudentRegistrationFeeShedul->setAmount($anteriorAccountingStudentRegistrationFee->getAmount());
  960.             $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  961.             $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum(1);
  962.             $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
  963.             $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
  964.             
  965.             $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
  966.             $entityManager->persist($anteriorAccountingStudentRegistrationFee);
  967.             
  968.             try{
  969.                 $entityManager->flush();
  970.             }catch(\Throwable $th){
  971.                 $this->addFlash('info'$th->getMessage());
  972.             }
  973.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
  974.         }
  975.         return $this->renderForm('registration/registration_student_registration/show.html.twig', [
  976.             'registration_student_registration' => $registrationStudentRegistration,
  977.             'accounting_student_registration_fee' => $accountingStudentRegistrationFee,
  978.             'accounting_student_registration_fee_form' => $accountingStudentRegistrationFeeForm,
  979.             'registrationTransportCheckpoint' => $registrationTransportCheckpoint,
  980.             'registrationTransportCheckpointForm' => $registrationTransportCheckpointForm,
  981.         ]);
  982.     }
  983.     /**
  984.      * @Route("/{id}/edit", name="registration_student_registration_edit", methods={"GET","POST"})
  985.      */
  986.     public function edit(Request $requestRegistrationStudentRegistration $registrationStudentRegistrationSettingDocumentToProvideRepository $settingDocumentToProvideRepository): Response
  987.     {
  988.         $establishment $this->getUser()->getEstablishment();
  989.         $form $this->createForm(RegistrationStudentRegistrationType::class, $registrationStudentRegistration)
  990.         ->add('documentProvides'EntityType::class, [
  991.             'class' => SettingDocumentToProvide::class,
  992.             'choices' => $settingDocumentToProvideRepository->findBy(['establishment' => $establishment], []),
  993.             'multiple' => true,
  994.             'required' => false
  995.         ])
  996.         ->remove('student');
  997.         $form->handleRequest($request);
  998.         if ($form->isSubmitted() && $form->isValid()) {
  999.             
  1000.             try {
  1001.                 $this->getDoctrine()->getManager()->flush();
  1002.                 $this->addFlash('success'"l'inscrit à été édité.");
  1003.             } catch (\Throwable $th) {
  1004.                 $this->addFlash('warning'"Une erreure est survenue lors de l'édition de l'inscrit.");
  1005.                 $this->addFlash('info'$th->getMessage());
  1006.             }
  1007.             return $this->redirectToRoute('registration_student_registration_edit', ['id' => $registrationStudentRegistration->getId()], Response::HTTP_SEE_OTHER);
  1008.         }
  1009.         return $this->renderForm('registration/registration_student_registration/edit.html.twig', [
  1010.             'registration_student_registration' => $registrationStudentRegistration,
  1011.             'form' => $form,
  1012.         ]);
  1013.     }
  1014.     /**
  1015.      * @Route("/delete-selection", name="registration_student_registrations_selected_delete", methods={"GET"})
  1016.     */
  1017.     public function deleteSelected(Request $requestRegistrationStudentRegistrationRepository $entityRepository): Response
  1018.     {
  1019.         $list $request->get('entities');
  1020.         $entityManager $this->getDoctrine()->getManager();
  1021.         $errors 0;
  1022.         foreach ($list as $key => $id) {
  1023.             $entity $entityRepository->findOneBy(['id' => intval($id)], []);
  1024.             if ($entity != null) {
  1025.                 foreach ($entity->getStockKitOuts() as $key => $stockKitOut) {
  1026.                     if (!$stockKitOut->getIsValidated()) {
  1027.                         foreach ($stockKitOut->getStockKitOutLines() as $key => $stockKitOutLine) {
  1028.                             $entityManager->remove($stockKitOutLine);
  1029.                         }
  1030.                         $entityManager->remove($stockKitOut);
  1031.                     }
  1032.                 }
  1033.                 
  1034.                 foreach ($entity->getStockStudentKitEntries() as $key => $stockStudentKitEntry) {
  1035.                     foreach ($stockStudentKitEntry->getStockStudentKitEntryLines() as $key => $stockStudentKitEntryLine) {
  1036.                         $entityManager->remove($stockStudentKitEntryLine);
  1037.                     }
  1038.                     $entityManager->remove($stockStudentKitEntry);
  1039.                 }
  1040.                 foreach ($entity->getAccountingCredits() as $key => $accountingCredit) {
  1041.                     foreach ($accountingCredit->getAccountingCreditLines() as $key => $accountingCreditLine) {
  1042.                         $entityManager->remove($accountingCreditLine);
  1043.                     }
  1044.                     $entityManager->remove($accountingCredit);
  1045.                 }
  1046.                 if (count($entity->getAccountingStudentRegistrationFees()) <= 0) {
  1047.                     $entityManager->remove($entity);
  1048.                 }
  1049.             }
  1050.         }
  1051.         try {
  1052.             $entityManager->flush();
  1053.             $this->addFlash('success'"Traitement effectué");
  1054.             return $this->json(['code' => 200'message' => "Traitement effectué :)"], 200);
  1055.         } catch (\Throwable $th) {
  1056.             //$th->getMessage()
  1057.             $this->addFlash('warning'$th->getMessage());
  1058.         }
  1059.         
  1060.         $this->addFlash('warning'"Traitement non effectué");
  1061.         return $this->json(['code' => 500'message' => "Traitement non effectué"], 200);
  1062.     }
  1063.     /**
  1064.      * @Route("/{id}/toggle-abandon", name="registration_student_registration_abandon", methods={"GET"})
  1065.     */
  1066.     public function abandon(RegistrationStudentRegistration $registrationStudentRegistration): Response
  1067.     {
  1068.         $registrationStudentRegistration->setIsAbandonned(!$registrationStudentRegistration->getIsAbandonned());
  1069.         if ($registrationStudentRegistration->getIsAbandonned()) {
  1070.             $registrationStudentRegistration->setStatus(RegistrationStudentRegistration::STATUS_ABANDONNE);
  1071.         } else {
  1072.             $registrationStudentRegistration->setStatus(RegistrationStudentRegistration::STATUS_INSCRIT);
  1073.         }
  1074.         $message $registrationStudentRegistration->getIsAbandonned() ? "Abandonné" "Inscrit";
  1075.         try {
  1076.             $this->getDoctrine()->getManager()->flush();
  1077.             $this->addFlash('success'"Traitement effectué : " $message);
  1078.             return $this->json(['code' => 200'message' => "Traitement effectué :) : " $message], 200);
  1079.         } catch (\Throwable $th) {
  1080.             $this->addFlash('info'$th->getMessage());
  1081.         }
  1082.         return $this->json(['code' => 500'message' => "Traitement non effectué"], 200);
  1083.     }
  1084.     /**
  1085.      * @Route("/{id}/delete", name="registration_student_registration_delete", methods={"GET"})
  1086.      * @IsGranted("ROLE_SUPER_ADMIN")
  1087.     */
  1088.     public function delete(RegistrationStudentRegistration $registrationStudentRegistration): Response
  1089.     {
  1090.         if (count($registrationStudentRegistration->getAccountingStudentRegistrationFees()) > 0) {
  1091.             return $this->json(['code' => 500'message' => "Ce inscrit a des frais, il ne peut pas être supprimé."], 200);
  1092.         }
  1093.         if(count($registrationStudentRegistration->getAccountingStudentRegistrationPayments()) > 0) {
  1094.             return $this->json(['code' => 500'message' => "Ce inscrit a des paiements, il ne peut pas être supprimé."], 200);
  1095.         }
  1096.         foreach ($registrationStudentRegistration->getStockKitOuts() as $key => $stockKitOut) {
  1097.             if (!$stockKitOut->getIsValidated()) {
  1098.                 foreach ($stockKitOut->getStockKitOutLines() as $key => $stockKitOutLine) {
  1099.                     $this->getDoctrine()->getManager()->remove($stockKitOutLine);
  1100.                 }
  1101.             }
  1102.         }
  1103.         foreach ($registrationStudentRegistration->getStockStudentKitEntries() as $key => $stockStudentKitEntry) {
  1104.             foreach ($stockStudentKitEntry->getStockStudentKitEntryLines() as $key => $stockStudentKitEntryLine) {
  1105.                 $this->getDoctrine()->getManager()->remove($stockStudentKitEntryLine);
  1106.             }
  1107.             $this->getDoctrine()->getManager()->remove($stockStudentKitEntry);
  1108.         }
  1109.         foreach ($registrationStudentRegistration->getRegistrationTransportCheckpoints() as $key => $registrationTransportCheckpoint) {
  1110.             $this->getDoctrine()->getManager()->remove($registrationTransportCheckpoint);
  1111.         }
  1112.         foreach ($registrationStudentRegistration->getRegistrationStudentDowngrades() as $key => $registrationStudentDowngrade) {
  1113.             $this->getDoctrine()->getManager()->remove($registrationStudentDowngrade);
  1114.         }
  1115.         foreach ($registrationStudentRegistration->getRegistrationStudentAbandonments() as $key => $registrationStudentAbandonment) {
  1116.             $this->getDoctrine()->getManager()->remove($registrationStudentAbandonment);
  1117.         }
  1118.         foreach ($registrationStudentRegistration->getRegistrationStudentContacts() as $key => $registrationStudentContact) {
  1119.             $this->getDoctrine()->getManager()->remove($registrationStudentContact);
  1120.         }
  1121.         try {
  1122.             $this->getDoctrine()->getManager()->remove($registrationStudentRegistration);
  1123.             $this->getDoctrine()->getManager()->flush();
  1124.         } catch (\Throwable $th) {
  1125.             return $this->json(['code' => 500'message' => $th->getMessage()], 200);
  1126.         }
  1127.         return $this->json(['code' => 200'message' => "Traitement effectué :)"], 200);
  1128.     }
  1129.     /**
  1130.      * @Route("/api/get-info", name="api_registration_student_registration_info", methods={"GET"})
  1131.     */
  1132.     public function apiGetInfo(Request $requestRegistrationStudentRegistrationRepository $entityRepositorySettingClassroomRepository $settingClassroomRepository): Response
  1133.     {
  1134.         /**@var User $user */
  1135.         $user $this->getUser();
  1136.         $establishment $user->getEstablishment();
  1137.         $schoolYear $user->getSchoolYear();
  1138.         $id intval($request->get('id'));
  1139.         $student $entityRepository->findOneBy(['id' => $id], []);
  1140.         if (null == $student) {
  1141.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  1142.         }
  1143.         $sclassrooms = new ArrayCollection();
  1144.         $_sclassrooms $settingClassroomRepository->findBy(['level' => $student->getClassroom()->getLevel(), 'schoolYear' => $schoolYear], ['label' => 'ASC']);
  1145.         
  1146.         $_sclassrooms =  $settingClassroomRepository->createQueryBuilder('entity')
  1147.         ->innerJoin('entity.level''level')
  1148.         ->addSelect('level')
  1149.         ->andWhere('entity.establishment = :establishment')
  1150.         ->setParameter('establishment'$establishment)
  1151.         ->andWhere('entity.schoolYear = :schoolYear')
  1152.         ->setParameter('schoolYear'$schoolYear)
  1153.         ->andWhere('level.parent = :parent')
  1154.         ->setParameter('parent'$student->getClassroom()->getLevel()->getParent())
  1155.         ->getQuery()
  1156.         ->getResult();
  1157.         $__sclassrooms =  $settingClassroomRepository->createQueryBuilder('entity')
  1158.         ->innerJoin('entity.level''level')
  1159.         ->addSelect('level')
  1160.         ->andWhere('entity.establishment = :establishment')
  1161.         ->setParameter('establishment'$establishment)
  1162.         ->andWhere('entity.schoolYear = :schoolYear')
  1163.         ->setParameter('schoolYear'$schoolYear)
  1164.         ->andWhere('entity.level = :level')
  1165.         ->setParameter('level'$student->getClassroom()->getLevel())
  1166.         ->getQuery()
  1167.         ->getResult();
  1168.         foreach ($_sclassrooms as $key => $_sclassroom) {
  1169.             if ($student->getClassroom() != $_sclassroom) {
  1170.                 $sclassrooms->add([
  1171.                     'id' => $_sclassroom->getId(),
  1172.                     'label' => $_sclassroom->getLabel()
  1173.                 ]);
  1174.             }
  1175.         };
  1176.         foreach ($__sclassrooms as $key => $_sclassroom) {
  1177.             if ($student->getClassroom() != $_sclassroom) {
  1178.                 if ($student->getClassroom()->getLevel()->getParent() == null) {
  1179.                     $sclassrooms->add([
  1180.                         'id' => $_sclassroom->getId(),
  1181.                         'label' => $_sclassroom->getLabel()
  1182.                     ]);
  1183.                 }
  1184.             }
  1185.         };
  1186.         if ($student != null) {
  1187.             return $this->json([
  1188.                 'code' => 200
  1189.                 'message' => "found :)"
  1190.                 'sname' => $student->getName(), 
  1191.                 'sregistrationNumber' => $student->getStudent()->getRegistrationNumber(), 
  1192.                 'scode' => $student->getStudent()->getCode(), 
  1193.                 'sclassroom' => $student->getClassroom()->getLabel(), 
  1194.                 'sclassrooms' => $sclassrooms
  1195.                 'slevel' => $student->getClassroom()->getLevel()->getId(), 
  1196.                 'sestablishment' => $student->getEstablishment()->getName(), 
  1197.                 'ssolde' => number_format(($student->getGleAmount() - $student->getAmountPaid()), 0','' '),
  1198.                 'is_affected' => $student->getStudent()->getIsAffected(), 
  1199.                 'is_redoubling' => $student->getStudent()->getIsRedoubling(), 
  1200.             ], 
  1201.             200);
  1202.         }else{
  1203.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  1204.         }
  1205.     }
  1206.     /**
  1207.      * @Route("/print/{id}/card", name="registration_student_registration_print_card", methods={"GET"})
  1208.     */
  1209.     public function printCard(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1210.     {
  1211.         /**@var User $user */
  1212.         $user $this->getUser();
  1213.         $schoolYear $user->getSchoolYear();
  1214.         $setting $registrationStudent->getEstablishment();
  1215.         $template 'registration/print/primaireCard.html.twig';
  1216.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  1217.             $template 'registration/print/secondaireCard.html.twig';
  1218.         }
  1219.         
  1220.         $html $this->renderView($template, [
  1221.             'student_registration' => $registrationStudent,
  1222.             'school_year' => $schoolYear,
  1223.             'setting' => $setting,
  1224.         ]);
  1225.         $file_name 'CARTE_DE_SORTIE_'.$registrationStudent->getStudent()->getCode().".pdf";
  1226.         return new PdfResponse(
  1227.             $knpSnappyPdf->getOutputFromHtml($html),
  1228.             $file_name,
  1229.             'application/pdf',
  1230.             'attachment'
  1231.         );
  1232.     }
  1233.     /**
  1234.      * @Route("/print/{id}/badge", name="registration_student_registration_print_badge", methods={"GET"})
  1235.     */
  1236.     public function printBadge(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1237.     {
  1238.         /**@var User $user */
  1239.         $user $this->getUser();
  1240.         $schoolYear $user->getSchoolYear();
  1241.         $setting $registrationStudent->getEstablishment();
  1242.         $template 'registration/print/primaireBadge.html.twig';
  1243.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  1244.             $template 'registration/print/secondaireBadge.html.twig';
  1245.         }
  1246.         
  1247.         $html $this->renderView($template, [
  1248.             'student_registration' => $registrationStudent,
  1249.             'school_year' => $schoolYear,
  1250.             'setting' => $setting,
  1251.         ]);
  1252.         $file_name 'BADGE_'.$registrationStudent->getStudent()->getCode().".pdf";
  1253.         return new PdfResponse(
  1254.             $knpSnappyPdf->getOutputFromHtml($html, [
  1255.                 'margin-left' => '0',
  1256.                 'margin-top' => '0',
  1257.                 'margin-right' => '0',
  1258.                 'margin-bottom' => '0',
  1259.                 'page-height' =>  35,
  1260.                 'page-width' => 53
  1261.             ]),
  1262.             $file_name,
  1263.             'application/pdf',
  1264.             'attachment'
  1265.         );
  1266.     }
  1267.     /**
  1268.      * @Route("/print/{id}/badgeVerso", name="registration_student_registration_print_badge_verso", methods={"GET"})
  1269.     */
  1270.     public function printBadgeVerso(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1271.     {
  1272.         /**@var User $user */
  1273.         $user $this->getUser();
  1274.         $schoolYear $user->getSchoolYear();
  1275.         $setting $registrationStudent->getEstablishment();
  1276.         $template 'registration/print/primaireBadgeVerso.html.twig';
  1277.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  1278.             $template 'registration/print/secondaireBadgeVerso.html.twig';
  1279.         }
  1280.         
  1281.         $html $this->renderView($template, [
  1282.             'student_registration' => $registrationStudent,
  1283.             'school_year' => $schoolYear,
  1284.             'setting' => $setting,
  1285.         ]);
  1286.         $file_name 'BADGE_VERSO'.$registrationStudent->getStudent()->getCode().".pdf";
  1287.         return new PdfResponse(
  1288.             $knpSnappyPdf->getOutputFromHtml($html, [
  1289.                 'margin-left' => '0',
  1290.                 'margin-top' => '0',
  1291.                 'margin-right' => '0',
  1292.                 'margin-bottom' => '0',
  1293.                 'page-height' =>  35,
  1294.                 'page-width' => 53
  1295.             ]),
  1296.             $file_name,
  1297.             'application/pdf',
  1298.             'attachment'
  1299.         );
  1300.     }
  1301.     /**
  1302.      * @Route("/print/{id}/attestationOfAttendance", name="registration_student_registration_print_attestation_of_attendance", methods={"GET"})
  1303.     */
  1304.     public function printAttestationOfAttendance(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1305.     {
  1306.         /**@var User $user */
  1307.         $user $this->getUser();
  1308.         $schoolYear $user->getSchoolYear();
  1309.         $setting $registrationStudent->getEstablishment();
  1310.         $template 'registration/print/attestation_of_attendance.html.twig';
  1311.         $html $this->renderView($template, [
  1312.             'student_registration' => $registrationStudent,
  1313.             'school_year' => $schoolYear,
  1314.             'setting' => $setting,
  1315.         ]);
  1316.         $file_name 'ATTESTATION_DE_FREQUENTATION_'.$registrationStudent->getStudent()->getCode().".pdf";
  1317.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
  1318.         $header $this->renderView('print/header.html.twig', ['setting' => $setting,]);
  1319.         $options = [
  1320.             'orientation' => 'Portrait'
  1321.             //'header-html' => $header
  1322.             //'footer-html' => $footer
  1323.         ];
  1324.         try {
  1325.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/students/' $file_name$optionstrue);
  1326.         } catch (\Throwable $th) {
  1327.             $this->addFlash('info'"Ce reçu à déjà été imprimé.");
  1328.         }
  1329.         
  1330.         return $this->redirectToRoute('preview', [
  1331.             'file' => $file_name,
  1332.             'dir' => 'students',
  1333.         ]);
  1334.     }
  1335.     /**
  1336.      * @Route("/print/{id}/transpotantionSheet", name="registration_student_registration_print_transpotantion_sheet", methods={"GET"})
  1337.     */
  1338.     public function printTranspotantionSheet(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1339.     {
  1340.         /**@var User $user */
  1341.         $user $this->getUser();
  1342.         $schoolYear $user->getSchoolYear();
  1343.         $setting $registrationStudent->getEstablishment();
  1344.         $template 'registration/print/transpotantion_sheet.html.twig';
  1345.         $html $this->renderView($template, [
  1346.             'student_registration' => $registrationStudent,
  1347.             'school_year' => $schoolYear,
  1348.             'setting' => $setting,
  1349.         ]);
  1350.         $file_name 'FICHE_DE_TRANSPORT_'.$registrationStudent->getStudent()->getCode().".pdf";
  1351.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
  1352.         $header $this->renderView('print/header.html.twig', ['setting' => $setting,]);
  1353.         $options = [
  1354.             'orientation' => 'Portrait',
  1355.             'header-html' => $header
  1356.             //'footer-html' => $footer
  1357.         ];
  1358.         try {
  1359.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/students/' $file_name$optionstrue);
  1360.         } catch (\Throwable $th) {
  1361.             $this->addFlash('info'$th->getMessage());
  1362.         }
  1363.         
  1364.         return $this->redirectToRoute('preview', [
  1365.             'file' => $file_name,
  1366.             'dir' => 'students',
  1367.         ]);
  1368.     }
  1369.     /**
  1370.      * @Route("/print/{id}/acknowledgmentReceip", name="registration_student_registration_print_acknowledgment_receip", methods={"GET"})
  1371.     */
  1372.     public function acknowledgment_receip(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1373.     {
  1374.         /**@var User $user */
  1375.         $user $this->getUser();
  1376.         $schoolYear $user->getSchoolYear();
  1377.         $setting $registrationStudent->getEstablishment();
  1378.         $template 'registration/print/acknowledgment_receip.html.twig';
  1379.         
  1380.         $html $this->renderView($template, [
  1381.             'student_registration' => $registrationStudent,
  1382.             'school_year' => $schoolYear,
  1383.             'setting' => $setting,
  1384.         ]);
  1385.         $file_name 'ACCUSE_DE_RECEPTION_'.$registrationStudent->getId().".pdf";
  1386.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
  1387.         $header $this->renderView('print/header.html.twig', ['setting' => $setting,]);
  1388.         $options = [
  1389.             'orientation' => 'Portrait',
  1390.             'header-html' => $header
  1391.             //'footer-html' => $footer
  1392.         ];
  1393.         try {
  1394.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/students/' $file_name$optionstrue);
  1395.         } catch (\Throwable $th) {
  1396.             $this->addFlash('info'$th->getMessage());
  1397.         }
  1398.         
  1399.         return $this->redirectToRoute('preview', [
  1400.             'file' => $file_name,
  1401.             'dir' => 'students',
  1402.         ]);
  1403.     }
  1404.     /**
  1405.      * @Route("/api/get-kit-model", name="api_registration_student_registration_get_kit_models", methods={"GET"})
  1406.     */
  1407.     public function apiGetKitModel(Request $requestRegistrationStudentRegistrationRepository $entityRepository): Response
  1408.     {
  1409.         /**@var User $user */
  1410.         $user $this->getUser();
  1411.         $schoolYear $user->getSchoolYear();
  1412.         $establishment $this->getUser()->getEstablishment();
  1413.         $id intval($request->get('id'));
  1414.         $student $entityRepository->find($id);
  1415.         $kitCategories = new ArrayCollection();
  1416.         $level $student->getClassroom()->getLevel();
  1417.         foreach ($level->getSettingFees() as $key => $settingFee) {
  1418.             foreach ($settingFee->getStockKitCategories() as $key => $stockKitCategorie) {
  1419.                 if($stockKitCategorie->getEstablishment() == $establishment && $stockKitCategorie->getSchoolYear() == $schoolYear){
  1420.                     $kitCategories->add([
  1421.                         'id' => $stockKitCategorie->getId(),
  1422.                         'name' => $stockKitCategorie->getName()
  1423.                     ]);
  1424.                 }
  1425.             };
  1426.         };
  1427.         if ($student != null) {
  1428.             return $this->json([
  1429.                 'code' => 200
  1430.                 'message' => "found :)"
  1431.                 'sname' => $student->getName(), 
  1432.                 'sregistrationNumber' => $student->getStudent()->getRegistrationNumber(), 
  1433.                 'scode' => $student->getStudent()->getCode(), 
  1434.                 'sclassroom' => $student->getClassroom()->getLabel(), 
  1435.                 'slevel' => $student->getClassroom()->getLevel()->getId(), 
  1436.                 'sestablishment' => $student->getEstablishment()->getName(), 
  1437.                 'ssolde' => number_format(($student->getGleAmount() - $student->getAmountPaid()), 0','' '),
  1438.                 'kit_categories' => $kitCategories
  1439.             ], 
  1440.             200);
  1441.         }else{
  1442.             return $this->json(['code' => 500'message' => "not found :)"], 200);
  1443.         }
  1444.     }
  1445.     /**
  1446.      * @Route("/{id}/print", name="registration_student_registration_print", methods={"GET"})
  1447.     */
  1448.     public function print(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudentRegistrationDocManagerRepository $docManagerRepository)
  1449.     {
  1450.         /**@var User $user */
  1451.         $user $this->getUser();
  1452.         $schoolYear $user->getSchoolYear();
  1453.         $setting $registrationStudentRegistration->getEstablishment();
  1454.         $template 'registration/print/rePrimaire.html.twig';
  1455.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  1456.             $template 'registration/print/reSecondaire.html.twig';
  1457.         }
  1458.         
  1459.         $html $this->renderView($template, [
  1460.             'doc_manager' => $docManagerRepository->findOneBy(['establishment' => $setting'code' => 'REGLEMENT-INTERIEUR'], []),
  1461.             'registration_student_registration' => $registrationStudentRegistration,
  1462.             'registration_student_pre_registration' => $registrationStudentRegistration->getRegistrationStudentPreRegistration(),
  1463.             'school_year' => $schoolYear,
  1464.             'setting' => $setting,
  1465.         ]);
  1466.         $file_name 'INSCRIPTION_N_'.$schoolYear->getCode().'--'.$registrationStudentRegistration->getStudent()->getCode().".pdf";
  1467.         return new PdfResponse(
  1468.             $knpSnappyPdf->getOutputFromHtml($html),
  1469.             $file_name,
  1470.             'application/pdf',
  1471.             'attachment'
  1472.         );
  1473.     }
  1474.     /**
  1475.      * @Route("/print/{id}/access-card", name="registration_student_registration_print_access_card", methods={"GET"})
  1476.     */
  1477.     public function printAccessCard(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1478.     {
  1479.         /**@var User $user */
  1480.         $user $this->getUser();
  1481.         $schoolYear $user->getSchoolYear();
  1482.         $setting $registrationStudent->getEstablishment();
  1483.         // Vérifier si l'élève a une photo
  1484.         $studentImage $registrationStudent->getStudent()->getImage();
  1485.         $registrationImage $registrationStudent->getImage();
  1486.         
  1487.         if (empty($studentImage) && empty($registrationImage)) {
  1488.             $this->addFlash('warning''Attention : Cet élève n\'a pas de photo dans la base de données. La carte d\'accès sera générée sans photo.');
  1489.         } elseif (empty($studentImage) && !empty($registrationImage)) {
  1490.             $this->addFlash('info''Information : La photo de l\'inscription sera utilisée. Pensez à synchroniser les photos si nécessaire.');
  1491.         }
  1492.         $template 'registration/print/accessCard2.html.twig';
  1493.         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
  1494.             $template 'registration/print/accessCard2.html.twig';
  1495.         }
  1496.         
  1497.         $html $this->renderView($template, [
  1498.             'student_registration' => $registrationStudent,
  1499.             'school_year' => $schoolYear,
  1500.             'setting' => $setting,
  1501.         ]);
  1502.         $options = [
  1503.             'margin-left' => '0',
  1504.             'margin-top' => '0',
  1505.             'margin-right' => '0',
  1506.             'margin-bottom' => '0',
  1507.             'page-height' =>  37,
  1508.             'page-width' => 55
  1509.         ];
  1510.         $file_name 'CARTE_DACCES_'.$registrationStudent->getStudent()->getCode().".pdf";
  1511.         try {
  1512.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/students/' $file_name$optionstrue);
  1513.         } catch (\Throwable $th) {
  1514.             $this->addFlash('info'$th->getMessage());
  1515.         }
  1516.         return $this->redirectToRoute('preview', [
  1517.             'file' => $file_name,
  1518.             'dir' => 'students',
  1519.         ]);
  1520.     }
  1521.     /**
  1522.      * @Route("/export", name="registration_student_registration_export")
  1523.     */
  1524.     public function export(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
  1525.     {
  1526.         /**@var User $user */
  1527.         $user $this->getUser();
  1528.         $schoolYear $user->getSchoolYear();
  1529.         $students = new ArrayCollection();
  1530.         $establishment $this->getUser()->getEstablishment();
  1531.         $registration_student_registrations $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  1532.             ->innerJoin('entity.student''student')
  1533.             ->addSelect('student')
  1534.             ->andWhere('entity.is_abandonned = :is_abandonned')
  1535.             ->setParameter('is_abandonned'0)
  1536.             ->andWhere('entity.establishment = :establishment')
  1537.             ->setParameter('establishment'$establishment)
  1538.             ->andWhere('entity.schoolYear = :schoolYear')
  1539.             ->setParameter('schoolYear'$schoolYear)
  1540.             ->orderBy('student.last_name''asc')
  1541.             ->getQuery()
  1542.             ->getResult();
  1543.         
  1544.         foreach ($registration_student_registrations as $key => $registration_student_registration) {
  1545.             $students->add(
  1546.                 [
  1547.                     'registrationNumber' => $registration_student_registration->getStudent()->getRegistrationNumber(),
  1548.                     'code' => $registration_student_registration->getStudent()->getCode(),
  1549.                     'name' => $registration_student_registration->getStudent()->getName(),
  1550.                     'lastName' => $registration_student_registration->getStudent()->getLastName(),
  1551.                     'firstName' => $registration_student_registration->getStudent()->getFirstName(),
  1552.                     'birthDay' => $registration_student_registration->getStudent()->getBirthDay()->format('d/m/Y'),
  1553.                     'birthLocation' => $registration_student_registration->getStudent()->getBirthLocation(),
  1554.                     'statut' => $registration_student_registration->getStudent()->getIsAffected() ? "Affecté(e)" "Non Affecté(e)",
  1555.                     'notificationPhoneNumber' => $registration_student_registration->getStudent()->getNotificationPhoneNumber(),
  1556.                     'doubling' => $registration_student_registration->getIsRedoubling() ? "Doublant(e)" "Non Doublant(e)",
  1557.                     'nationality' => $registration_student_registration->getStudent()->getNationality(),
  1558.                     'classroom' => $registration_student_registration->getClassroom()->getLabel(),
  1559.                     'level' => $registration_student_registration->getClassroom()->getLevel()->getLabel(),
  1560.                     'gender' => $registration_student_registration->getStudent()->getGender(),
  1561.                     'round' => $registration_student_registration->getClassroom()->getRound() ?  $registration_student_registration->getClassroom()->getRound()->getLabel() : '',
  1562.                     'lv1' => $registration_student_registration->getStudent()->getLv1(),
  1563.                     'lv2' => $registration_student_registration->getStudent()->getLv2(),
  1564.                     'createDate' => $registration_student_registration->getRegisteredAt() ? $registration_student_registration->getRegisteredAt()->format('d/m/Y') : '',
  1565.                 ]
  1566.             );
  1567.             
  1568.         }
  1569.         
  1570.         $iterator $students->getIterator();
  1571.         $array iterator_to_array($iterator);
  1572.         uasort($array, function ($first$second) {
  1573.             if ($first === $second) {
  1574.                 return 0;
  1575.             }
  1576.             return $first['name'] < $second['name'] ? -1;
  1577.         });
  1578.         $students = new ArrayCollection($array);
  1579.         $spreadsheet = new Spreadsheet();
  1580.         $sheet $spreadsheet->getActiveSheet();
  1581.         $index 1;
  1582.         $sheet->setCellValue('A' $index'MATRICULE NATIONAL');
  1583.         $sheet->setCellValue('B' $index'NOM');
  1584.         $sheet->setCellValue('C' $index'PRENOMS');
  1585.         $sheet->setCellValue('D' $index'DATE DE NAISSANCE');
  1586.         $sheet->setCellValue('E' $index'LIEU DE NAISSANCE');
  1587.         $sheet->setCellValue('F' $index'STATUT');
  1588.         $sheet->setCellValue('G' $index'CONTACT PARENT');
  1589.         $sheet->setCellValue('H' $index'DOUBLANT');
  1590.         $sheet->setCellValue('I' $index'NATIONALITE');
  1591.         $sheet->setCellValue('J' $index'CLASSE');
  1592.         $sheet->setCellValue('K' $index'NIVEAU');
  1593.         $sheet->setCellValue('L' $index'SEX');
  1594.         $sheet->setCellValue('M' $index'SERIE');
  1595.         $sheet->setCellValue('N' $index'LV1');
  1596.         $sheet->setCellValue('O' $index'LV2');
  1597.         $sheet->setCellValue('P' $index'MATRICULE INTERNE');
  1598.         $sheet->setCellValue('Q' $index'Date Inscription');
  1599.         $index++;
  1600.         $loopIndex 1;
  1601.         foreach ($students as $key => $student) {
  1602.             $sheet->setCellValue('A' $index$student['registrationNumber']);
  1603.             $sheet->setCellValue('B' $index$student['lastName']);
  1604.             $sheet->setCellValue('C' $index$student['firstName']);
  1605.             $sheet->setCellValue('D' $index$student['birthDay']);
  1606.             $sheet->setCellValue('E' $index$student['birthLocation']);
  1607.             $sheet->setCellValue('F' $index$student['statut']);
  1608.             $sheet->setCellValue('G' $index$student['notificationPhoneNumber']);
  1609.             $sheet->setCellValue('H' $index$student['doubling']);
  1610.             $sheet->setCellValue('I' $index$student['nationality']);
  1611.             $sheet->setCellValue('J' $index$student['classroom']);
  1612.             $sheet->setCellValue('K' $index$student['level']);
  1613.             $sheet->setCellValue('L' $index$student['gender']);
  1614.             $sheet->setCellValue('M' $index$student['round']);
  1615.             $sheet->setCellValue('N' $index$student['lv1']);
  1616.             $sheet->setCellValue('O' $index$student['lv2']);
  1617.             $sheet->setCellValue('P' $index$student['code']);
  1618.             $sheet->setCellValue('Q' $index$student['createDate']);
  1619.             $index++;
  1620.             $loopIndex++;
  1621.         }
  1622.         $sheet->setTitle('INSCRITS_' $establishment->getCode().'_'.$schoolYear->getCode());
  1623.         $writer = new Xlsx($spreadsheet);
  1624.         // Create a Temporary file in the system
  1625.         $fileName 'LISTE_INSCRITS_' $establishment->getName().'_'.date('Y').'.xlsx';
  1626.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  1627.         $writer->save($temp_file);
  1628.         // Return the excel file as an attachment
  1629.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1630.     }
  1631.     /**
  1632.      * @Route("/print/{id}/extract-school-record-book", name="registration_student_registration_print_extract_school_record_book", methods={"GET"})
  1633.     */
  1634.     public function extract_school_record_book(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudentSchoolReportCardRepository $schoolReportCardRepositoryEquivalentMatterRepository $equivalentMatterRepository)
  1635.     {
  1636.         /**@var User $user */
  1637.         $user $this->getUser();
  1638.         $schoolYear $user->getSchoolYear();
  1639.         $setting $registrationStudent->getEstablishment();
  1640.         $school_report_cards $schoolReportCardRepository->createQueryBuilder('entity')
  1641.         ->innerJoin('entity.schoolYearPeriode''schoolYearPeriode')
  1642.         ->addSelect('schoolYearPeriode')
  1643.         ->andWhere('entity.studentRegistration = :studentRegistration')
  1644.         ->setParameter('studentRegistration'$registrationStudent)
  1645.         ->orderBy('schoolYearPeriode.code''ASC')
  1646.         ->getQuery()
  1647.         ->getResult();
  1648.         $equivalent_matters $equivalentMatterRepository->createQueryBuilder('entity')
  1649.         ->orderBy('entity.num_order''ASC')
  1650.         ->getQuery()
  1651.         ->getResult();
  1652.         $template 'registration/print/extract_school_record_book.html.twig';
  1653.         
  1654.         $html $this->renderView($template, [
  1655.             'equivalent_matters' => $equivalent_matters,
  1656.             'school_report_cards' => $school_report_cards,
  1657.             'student_registration' => $registrationStudent,
  1658.             'school_year' => $schoolYear,
  1659.             'setting' => $setting,
  1660.         ]);
  1661.         $file_name 'EXTRAIT_DE_LIVRET_SCOLAIRE_'.$registrationStudent->getId().".pdf";
  1662.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting]);
  1663.         $header $this->renderView('print/header.html.twig', ['setting' => $setting]);
  1664.         $options = [
  1665.             'orientation' => 'Landscape',
  1666.             'header-html' => $header
  1667.             //'footer-html' => $footer
  1668.         ];
  1669.         try {
  1670.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/students/' $file_name$optionstrue);
  1671.         } catch (\Throwable $th) {
  1672.             $this->addFlash('info'$th->getMessage());
  1673.         }
  1674.         
  1675.         return $this->redirectToRoute('preview', [
  1676.             'file' => $file_name,
  1677.             'dir' => 'students',
  1678.         ]);
  1679.     }
  1680.     /**
  1681.      * @Route("/_statistics-table", name="registration_student_registration_statistics_table", methods={"GET","POST"})
  1682.      */
  1683.     public function _statistics_table(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
  1684.     {
  1685.         /**@var User $user */
  1686.         $user $this->getUser();
  1687.         $establishment $user->getEstablishment();
  1688.         $schoolYear $user->getSchoolYear();
  1689.         $registration_student_registrations $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  1690.         ->innerJoin('entity.student''student')
  1691.         ->addSelect('student')
  1692.         ->andWhere('entity.establishment = :establishment')
  1693.         ->setParameter('establishment'$establishment)
  1694.         
  1695.         ->andWhere('entity.schoolYear = :schoolYear')
  1696.         ->setParameter('schoolYear'$schoolYear)
  1697.         ->getQuery()
  1698.         ->getResult();
  1699.         $registration_student_registration_women $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  1700.         ->innerJoin('entity.student''student')
  1701.         ->addSelect('student')
  1702.         ->andWhere('entity.establishment = :establishment')
  1703.         ->setParameter('establishment'$establishment)
  1704.         
  1705.         ->andWhere('entity.schoolYear = :schoolYear')
  1706.         ->setParameter('schoolYear'$schoolYear)
  1707.         ->andWhere('student.gender = :gender')
  1708.         ->setParameter('gender''FEMININ')
  1709.         ->getQuery()
  1710.         ->getResult();
  1711.         $registration_student_registration_men $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  1712.         ->innerJoin('entity.student''student')
  1713.         ->addSelect('student')
  1714.         ->andWhere('entity.establishment = :establishment')
  1715.         ->setParameter('establishment'$establishment)
  1716.         
  1717.         ->andWhere('entity.schoolYear = :schoolYear')
  1718.         ->setParameter('schoolYear'$schoolYear)
  1719.         ->andWhere('student.gender = :gender')
  1720.         ->setParameter('gender''MASCULIN')
  1721.         ->getQuery()
  1722.         ->getResult();
  1723.         $registration_student_registration_affecteds $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  1724.         ->innerJoin('entity.student''student')
  1725.         ->addSelect('student')
  1726.         ->andWhere('entity.establishment = :establishment')
  1727.         ->setParameter('establishment'$establishment)
  1728.         
  1729.         ->andWhere('entity.schoolYear = :schoolYear')
  1730.         ->setParameter('schoolYear'$schoolYear)
  1731.         ->andWhere('student.is_affected = :is_affected')
  1732.         ->setParameter('is_affected'1)
  1733.         ->getQuery()
  1734.         ->getResult();
  1735.         return $this->renderForm('registration/registration_student_registration/_statistics_table.html.twig', [
  1736.             'registration_student_registrations' => count($registration_student_registrations),
  1737.             'registration_student_registration_women' => count($registration_student_registration_women),
  1738.             'registration_student_registration_men' => count($registration_student_registration_men),
  1739.             'registration_student_registration_affecteds' => count($registration_student_registration_affecteds),
  1740.         ]);
  1741.     }
  1742.     /**
  1743.      * @Route("/_registration_select", name="api_registration_student_registration_select", methods={"GET","POST"})
  1744.      */
  1745.     public function api_select(Request $requestRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository){
  1746.         /**@var User $user */
  1747.         $user $this->getUser();
  1748.         $schoolYear $user->getSchoolYear();
  1749.         $establishment $user->getEstablishment();
  1750.         $registrationStudentRegistrations $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  1751.         ->innerJoin('entity.student''student')
  1752.         ->addSelect('student')
  1753.         ->orWhere('student.code LIKE :code')
  1754.         ->setParameter('code''%'.$request->get('q').'%')
  1755.         ->orWhere('student.registration_number LIKE :registration_number')
  1756.         ->setParameter('registration_number''%'.$request->get('q').'%')
  1757.         ->orWhere('student.last_name LIKE :last_name')
  1758.         ->setParameter('last_name''%'.$request->get('q').'%')
  1759.         ->orWhere('student.first_name LIKE :first_name')
  1760.         ->setParameter('first_name''%'.$request->get('q').'%')
  1761.         ->andWhere('entity.establishment = :establishment')
  1762.         ->setParameter('establishment'$establishment)
  1763.         ->andWhere('entity.schoolYear = :schoolYear')
  1764.         ->setParameter('schoolYear'$schoolYear)
  1765.         ->andWhere('entity.is_abandonned = :is_abandonned')
  1766.         ->setParameter('is_abandonned'0)
  1767.         
  1768.         ->setMaxResults(100)
  1769.         ->getQuery()
  1770.         ->getResult();
  1771.         $data = new ArrayCollection();
  1772.         foreach ($registrationStudentRegistrations as $key => $registrationStudentRegistration) {
  1773.             if ($registrationStudentRegistration->getAmountRest() > 0) {
  1774.                 $data->add([
  1775.                     'id' => $registrationStudentRegistration->getId(),
  1776.                     'text' => '['.$registrationStudentRegistration->getStudent()->getRegistrationNumber().'] '.$registrationStudentRegistration->getName().' ['.$registrationStudentRegistration->getClassroom()->getLabel().']'
  1777.                 ]);
  1778.             }
  1779.         }
  1780.         return $this->json($data200);
  1781.     }
  1782.     /**
  1783.      * @Route("/print/{id}/fees-details", name="registration_student_registration_print_fees_details", methods={"GET"})
  1784.     */
  1785.     public function print_fees_details(Pdf $knpSnappyPdfRegistrationStudentRegistration $registrationStudent)
  1786.     {
  1787.         /**@var User $user */
  1788.         $user $this->getUser();
  1789.         $schoolYear $user->getSchoolYear();
  1790.         $setting $registrationStudent->getEstablishment();
  1791.         $template 'registration/print/frees_details.html.twig';
  1792.         
  1793.         $html $this->renderView($template, [
  1794.             'registration_student_registration' => $registrationStudent,
  1795.             'school_year' => $schoolYear,
  1796.             'setting' => $setting,
  1797.         ]);
  1798.         $file_name 'DETAILS_FRAIS_'.$registrationStudent->getId().".pdf";
  1799.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting]);
  1800.         $header $this->renderView('print/header.html.twig', ['setting' => $setting]);
  1801.         $options = [
  1802.             'orientation' => 'Portrait',
  1803.             'header-html' => $header
  1804.             //'footer-html' => $footer
  1805.         ];
  1806.         try {
  1807.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/students/' $file_name$optionstrue);
  1808.         } catch (\Throwable $th) {
  1809.             $this->addFlash('info'$th->getMessage());
  1810.         }
  1811.         
  1812.         return $this->redirectToRoute('preview', [
  1813.             'file' => $file_name,
  1814.             'dir' => 'students',
  1815.         ]);
  1816.     }
  1817.     /**
  1818.      * @Route("/_registration_fee", name="api_registration_student_registration_get_registration_fees", methods={"GET","POST"})
  1819.      */
  1820.     public function api_get_registration_fees(Request $requestStockKitCategoryRepository $stockKitCategoryRepositoryAccountingStudentRegistrationFeeRepository $accountingStudentRegistrationFeeRepositoryRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository){
  1821.         /**@var User $user */
  1822.         $user $this->getUser();
  1823.         $schoolYear $user->getSchoolYear();
  1824.         $establishment $user->getEstablishment();
  1825.         $stockKitCategory $stockKitCategoryRepository->findOneBy(['id' => $request->get('kitCategory')], []);
  1826.         $registrationStudentRegistration $registrationStudentRegistrationRepository->findOneBy(['id' => $request->get('registrationStudent')], []);
  1827.         if (null == $stockKitCategory || null == $registrationStudentRegistration) {
  1828.             return $this->json([
  1829.                 'code' => 404
  1830.                 'message' => "ok",
  1831.                 'accountingStudentRegistrationFees' => new ArrayCollection()
  1832.             ], 200);
  1833.         }
  1834.         
  1835.         $accountingStudentRegistrationFees $accountingStudentRegistrationFeeRepository->createQueryBuilder('entity')
  1836.             ->andWhere('entity.studentRegistration = :studentRegistration')
  1837.             ->setParameter('studentRegistration'$registrationStudentRegistration)
  1838.             ->andWhere('entity.fee = :fee')
  1839.             ->setParameter('fee'$stockKitCategory->getFee())
  1840.             ->orderBy('entity.label''ASC')
  1841.             ->getQuery()
  1842.             ->getResult();
  1843.         $data = new ArrayCollection();
  1844.         
  1845.         foreach ($accountingStudentRegistrationFees as $key => $accountingStudentRegistrationFee) {
  1846.             if (count($accountingStudentRegistrationFee->getStockKitOuts()) <= 0) {
  1847.                 $data->add([
  1848.                     'id' => $accountingStudentRegistrationFee->getId(),
  1849.                     'label' => $accountingStudentRegistrationFee->getLabel()
  1850.                 ]);
  1851.             }
  1852.         }
  1853.         return $this->json([
  1854.             'code' => 200
  1855.             'message' => "ok",
  1856.             'accountingStudentRegistrationFees' => $data
  1857.         ], 200);
  1858.     }
  1859.     /**
  1860.      * @Route("/{id}/set-student-to-affected/{idStudent}", name="registration_student_registration_set_student_to_affected", methods={"GET"})
  1861.      */
  1862.     public function set_student_to_affected(RegistrationStudentRegistration $registrationStudentRegistrationRegistrationStudentRepository $registrationStudent$idStudent): Response
  1863.     {
  1864.         $student $registrationStudent->findOneBy(['id' => $idStudent], []);
  1865.         if (null == $student) {
  1866.             $this->addFlash('info''Étudiant non trouvé');
  1867.             return $this->redirectToRoute('registration_student_registration_edit', ['id' => $registrationStudentRegistration->getId()]);
  1868.         }
  1869.         $registrationStudentRegistration->setStudent($student);
  1870.         $entityManager $this->getDoctrine()->getManager();
  1871.         $entityManager->flush();
  1872.         $this->addFlash('success''Inscrition : '.$registrationStudentRegistration->getSchoolYear().' - '.$registrationStudentRegistration->getStudent()->getRegistrationNumber().' - '.$registrationStudentRegistration->getStudent()->getLastName().' '.$registrationStudentRegistration->getStudent()->getFirstName().' transférée avec succès vers l\'étudiant : '.$student->getRegistrationNumber().' - '.$student->getLastName().' '.$student->getFirstName());
  1873.         return $this->redirectToRoute('registration_student_registration_edit', ['id' => $registrationStudentRegistration->getId()]);
  1874.     }
  1875.     /**
  1876.      * @Route("/{id}/get-solde-anterieur", name="registration_student_registration_get_solde_anterieur", methods={"GET"})
  1877.      */
  1878.     public function get_solde_anterieur(RegistrationStudentRegistration $registrationStudentRegistrationRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
  1879.     {
  1880.         // Ajout de solde anterieur à partir de la deuxième année de gestion
  1881.         $anteriorRegistrationStudentRegistrations $registrationStudentRegistrationRepository->findBy(['student' => $registrationStudentRegistration->getStudent()], ['id' => 'DESC']);
  1882.         $entityManager $this->getDoctrine()->getManager();
  1883.         
  1884.         foreach ($anteriorRegistrationStudentRegistrations as $key => $anteriorRegistrationStudentRegistration) {
  1885.             if ($anteriorRegistrationStudentRegistration->getSchoolYear() != $registrationStudentRegistration->getSchoolYear()) {
  1886.                 $order 0;
  1887.                 if (null != $anteriorRegistrationStudentRegistration) {
  1888.                     foreach ($anteriorRegistrationStudentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
  1889.                         $order++;
  1890.                         if (!$accountingStudentRegistrationFee->getIsArchived()) {
  1891.                             if (!$accountingStudentRegistrationFee->getIsCancel()) {
  1892.                                 if (!$accountingStudentRegistrationFee->getIsReported()) {
  1893.                                     if ($accountingStudentRegistrationFee->getAmountRest() > 0) {
  1894.                                         $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
  1895.                                         $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
  1896.                                         $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
  1897.                                         $anteriorAccountingStudentRegistrationFee->setFee($accountingStudentRegistrationFee->getFee());
  1898.                                         $anteriorAccountingStudentRegistrationFee->setAmount($accountingStudentRegistrationFee->getAmountRest());
  1899.                                         $anteriorAccountingStudentRegistrationFee->setCode('SA-'.$accountingStudentRegistrationFee->getLabel().'-'.$registrationStudentRegistration->getId());
  1900.                                         $anteriorAccountingStudentRegistrationFee->setLabel('SOLDE ANT. '.$accountingStudentRegistrationFee->getLabel());
  1901.                                         $anteriorAccountingStudentRegistrationFee->setIsArchived($accountingStudentRegistrationFee->getIsArchived());
  1902.                                         $anteriorAccountingStudentRegistrationFee->setIsCancel($accountingStudentRegistrationFee->getIsCancel());
  1903.                                         $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  1904.                                         $anteriorAccountingStudentRegistrationFeeShedul->setAmount($anteriorAccountingStudentRegistrationFee->getAmount());
  1905.                                         $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
  1906.                                         $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum($order);
  1907.                                         $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
  1908.                                         $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
  1909.                                         
  1910.                                         foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
  1911.                                             $accountingStudentRegistrationFeeShedul->setAmountReported($accountingStudentRegistrationFeeShedul->getAmountCancel() + $accountingStudentRegistrationFeeShedul->getAmountRest());
  1912.                                             $accountingStudentRegistrationFeeShedul->setIsReported(true);
  1913.                                         }
  1914.                                         
  1915.                                         $accountingStudentRegistrationFee->setIsReported(true);
  1916.                                         $accountingStudentRegistrationFee->setAmountReported($accountingStudentRegistrationFee->getAmountRest());
  1917.                                         $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
  1918.                                         $entityManager->persist($anteriorAccountingStudentRegistrationFee);
  1919.                                     }
  1920.                                 }
  1921.                             }
  1922.                         }
  1923.                     }
  1924.                 }
  1925.                 break;
  1926.             }
  1927.         }
  1928.         $entityManager $this->getDoctrine()->getManager();
  1929.         try {
  1930.             $entityManager->flush();
  1931.             $this->addFlash('success''Solde antérieur ajouté avec succès');
  1932.         } catch (\Throwable $th) {
  1933.             $this->addFlash('info'$th->getMessage());
  1934.         }
  1935.         return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
  1936.     }
  1937. }