src/Controller/Registration/RegistrationStudentRegistrationController.php line 1105

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