src/Controller/Registration/RegistrationStudentRegistrationController.php line 133

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