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