- <?php
- namespace App\Controller\Registration;
- use DateInterval;
- use Knp\Snappy\Pdf;
- use App\Entity\User;
- use DateTimeImmutable;
- use App\Entity\SettingFee;
- use App\Service\SMSSender;
- use App\Entity\StockKitOut;
- use App\Entity\TransportZone;
- use App\Entity\StockKitOutLine;
- use App\Entity\SettingClassroom;
- use App\Service\DateIntervalManage;
- use App\Entity\CommunicationMessage;
- use App\Entity\SettingDocumentToProvide;
- use App\Repository\DocManagerRepository;
- use App\Repository\SettingFeeRepository;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use App\Repository\TransportZoneRepository;
- use Symfony\Component\HttpFoundation\Request;
- use App\Repository\EquivalentMatterRepository;
- use App\Repository\SchoolReportCardRepository;
- use App\Repository\SettingClassroomRepository;
- use App\Repository\StockKitCategoryRepository;
- use Symfony\Component\HttpFoundation\Response;
- use App\Entity\RegistrationStudentRegistration;
- use App\Entity\RegistrationTransportCheckpoint;
- use Symfony\Component\Routing\Annotation\Route;
- use App\Entity\AccountingStudentRegistrationFee;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Bridge\Doctrine\Form\Type\EntityType;
- use App\Entity\RegistrationStudentPreRegistration;
- use App\Entity\AccountingStudentRegistrationFeeShedul;
- use App\Repository\SettingDocumentToProvideRepository;
- use Symfony\Component\HttpFoundation\ResponseHeaderBag;
- use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
- use Symfony\Component\Form\Extension\Core\Type\NumberType;
- use App\Form\Accounting\AccountingStudentRegistrationFeeType;
- use App\Repository\RegistrationStudentRegistrationRepository;
- use App\Form\Registration\RegistrationStudentRegistrationType;
- use App\Form\Registration\RegistrationTransportCheckpointType;
- use App\Repository\AccountingStudentRegistrationFeeRepository;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
- use App\Repository\RegistrationStudentPreRegistrationRepository;
- use App\Repository\RegistrationStudentRepository;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- /**
-  * @Route("/registration/student-registration")
-  */
- class RegistrationStudentRegistrationController extends AbstractController
- {
-     /**
-      * @Route("/index/{_from}", name="registration_student_registration_index", methods={"GET"})
-      */
-     public function index($_from = 'All'): Response
-     {
-         return $this->render('registration/registration_student_registration/index.html.twig', [
-             '_from' => $_from,
-         ]);
-     }
-     /**
-      * @Route("/_searh-table/{_from}", name="registration_student_registration_searh_table", methods={"GET","POST"})
-      */
-     public function _searh_table($_from = 'All', Request $request, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $establishment = $user->getEstablishment();
-         $schoolYear = $user->getSchoolYear();
-         $query = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.student', 'student')
-         ->addSelect('student')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         
-         ->andWhere('entity.status != :status')
-         ->setParameter('status', RegistrationStudentRegistration::STATUS_ABANDONNE);
-         if ($request->get('registrationNumber')) {
-             $query = $query
-             ->andWhere('student.registration_number LIKE :registration_number')
-             ->setParameter('registration_number', '%'.$request->get('registrationNumber').'%');
-         }
-         
-         if ($request->get('code')) {
-             $query = $query
-             ->andWhere('student.code LIKE :code')
-             ->setParameter('code', '%'.$request->get('code').'%');
-         }
-         if ($request->get('lastName')) {
-             $query = $query
-             ->andWhere('student.last_name LIKE :last_name')
-             ->setParameter('last_name', '%'.$request->get('lastName').'%');
-         }
-         if ($request->get('firstName')) {
-             $query = $query
-             ->andWhere('student.first_name LIKE :first_name')
-             ->setParameter('first_name', '%'.$request->get('firstName').'%');
-         } 
-         if ($request->get('phoneNumber')) {
-             $query = $query
-             ->andWhere('student.notification_phone_number LIKE :notification_phone_number')
-             ->setParameter('notification_phone_number', '%'.$request->get('phoneNumber').'%');
-         } 
-         $query = $query
-         ->orderBy('student.last_name', 'ASC')
-         ->getQuery();
-         $registration_student_registrations = $query
-         ->setMaxResults(100)
-         ->getResult();
-         return $this->renderForm('registration/registration_student_registration/_searh_table.html.twig', [
-             'registration_student_registrations' => $registration_student_registrations,
-             '_from' => $_from,
-         ]);
-     }
-     /**
-      * @Route("/new", name="registration_student_registration_new", methods={"GET","POST"})
-      */
-     public function new(Request $request, SettingFeeRepository $settingFeeRepository, RegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepository, SettingDocumentToProvideRepository $settingDocumentToProvideRepository, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository, SettingClassroomRepository $settingClassroomRepository): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $establishment = $user->getEstablishment();
-         
-         if ($schoolYear == null) {
-             $this->addFlash('warning', "Aucune base de donnée n'est activé.");
-             return $this->redirectToRoute('registration_student_registration_new');
-         }
-         /* recuperation des non encore incrits */
-         $unregisteredRegistrationStudentPreRegistrations = new ArrayCollection();
-         $registrationStudentPreRegistrations = $registrationStudentPreRegistrationRepository->createQueryBuilder('entity')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->getQuery()
-         ->getResult();
-         foreach ($registrationStudentPreRegistrations as $key => $registrationStudentPreRegistration) {
-             if ($registrationStudentPreRegistration->getStudent() != null) {
-                 if(count($registrationStudentPreRegistration->getRegistrationStudentRegistrations()) <= 0){
-                     if ($registrationStudentPreRegistration->getIsEntryTestPerformed() or !$registrationStudentPreRegistration->getIsSubjectEntryTest()) {
-                         $unregisteredRegistrationStudentPreRegistrations->add($registrationStudentPreRegistration);
-                     }
-                 } 
-             }
-         }
-         $registrationStudentRegistration = new RegistrationStudentRegistration();
-         $registrationStudentRegistration->setPortalLogin($registrationStudentRegistration->getId().time());
-         $registrationStudentRegistration->setPortalPassword(uniqid());
-         $form = $this->createForm(RegistrationStudentRegistrationType::class, $registrationStudentRegistration)
-         
-         ->add('registrationStudentPreRegistration', EntityType::class, [
-             'class' => RegistrationStudentPreRegistration::class,
-             'choices' => $unregisteredRegistrationStudentPreRegistrations
-         ])
-         ->add('classroom', EntityType::class, [
-             'class' => SettingClassroom::class,
-             'choices' => $settingClassroomRepository->findBy(['schoolYear' => $schoolYear, 'establishment' => $establishment], ['label' => 'ASC'])
-             //'choices' => $settingClassroomRepository->findBy(['schoolYear' => $schoolYear, 'is_excellent' => 0], ['label' => 'ASC'])
-         ])
-         ->add('documentProvides', EntityType::class, [
-             'class' => SettingDocumentToProvide::class,
-             'choices' => $settingDocumentToProvideRepository->findBy(['establishment' => $establishment], []),
-             'multiple' => true,
-             'required' => false
-         ]);
-         $form->handleRequest($request);
-         if($form->isSubmitted() && $form->isValid()) {
-             $entityManager = $this->getDoctrine()->getManager();
-             $student = $registrationStudentRegistration->getRegistrationStudentPreRegistration()->getStudent();
-             if ($registrationStudentRegistrationRepository->findOneBy(['establishment' => $establishment, 'schoolYear' => $schoolYear, 'student' => $student], []) != null) {
-                 $this->addFlash('warning', "Cet élève est déjà inscrit");
-                 return $this->redirectToRoute('registration_student_registration_new');
-             }
-             $registrationStudentRegistration->setSchoolYear($schoolYear);
-             $registrationStudentRegistration->setEstablishment($establishment);
-             
-             $registrationStudentRegistration->setStudent($student);
-             $registrationStudentRegistration->setIsAffected($student->getIsAffected());
-             
-             if (count($student->getRegistrationStudentRegistrations()) <= 0) {
-                 if ($student->getAnteriorBalance() > 0) {
-                     // Ajout de solde anterieur pour la première année de gestion
-                     $fee = $settingFeeRepository->findOneBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $schoolYear, 'label'  => 'SOLDE ANTERIEUR'], []);
-                     if (null == $fee) {
-                         $fee = new SettingFee();
-                         $fee->setEstablishment($registrationStudentRegistration->getEstablishment());
-                         $fee->setCategory('AUTRE-FRAIS');
-                         $fee->setLabel('SOLDE ANTERIEUR');
-                         $fee->setAmount(0);
-                         $fee->setSchoolYear($schoolYear);
-                         $fee->setIsForAll(false);
-                         $fee->setIsForAffected(false);
-                         $fee->setIsForNonAffected(false);
-                         $entityManager->persist($fee);
-                     }
-                     $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
-                     $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
-                     $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                     $anteriorAccountingStudentRegistrationFee->setFee($fee);
-                     $anteriorAccountingStudentRegistrationFee->setAmount($student->getAnteriorBalance());
-                     $anteriorAccountingStudentRegistrationFee->setCode($fee->getLabel().'-'.$registrationStudentRegistration->getId());
-                     $anteriorAccountingStudentRegistrationFee->setLabel($fee->getLabel());
-                     $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                     $anteriorAccountingStudentRegistrationFeeShedul->setAmount($student->getAnteriorBalance());
-                     $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                     $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum(1);
-                     $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
-                     $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
-                     
-                     $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
-                     $entityManager->persist($anteriorAccountingStudentRegistrationFee);
-                 }
-             }
-             // Ajout de solde anterieur à partir de la deuxième année de gestion
-             $anteriorRegistrationStudentRegistration = $registrationStudentRegistrationRepository->findOneBy(['student' => $registrationStudentRegistration->getStudent()], ['id' => 'DESC']);
-             $order = 0;
-             if (null != $anteriorRegistrationStudentRegistration) {
-                 foreach ($anteriorRegistrationStudentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
-                     $order++;
-                     if (!$accountingStudentRegistrationFee->getIsArchived()) {
-                         if (!$accountingStudentRegistrationFee->getIsCancel()) {
-                             if (!$accountingStudentRegistrationFee->getIsReported()) {
-                                 if ($accountingStudentRegistrationFee->getAmountRest() > 0) {
-                                     $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
-                                     $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
-                                     $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                                     $anteriorAccountingStudentRegistrationFee->setFee($accountingStudentRegistrationFee->getFee());
-                                     $anteriorAccountingStudentRegistrationFee->setAmount($accountingStudentRegistrationFee->getAmountRest());
-                                     $anteriorAccountingStudentRegistrationFee->setCode('SA-'.$accountingStudentRegistrationFee->getLabel().'-'.$registrationStudentRegistration->getId());
-                                     $anteriorAccountingStudentRegistrationFee->setLabel('SOLDE ANT. '.$accountingStudentRegistrationFee->getLabel());
-                                     $anteriorAccountingStudentRegistrationFee->setIsArchived($accountingStudentRegistrationFee->getIsArchived());
-                                     $anteriorAccountingStudentRegistrationFee->setIsCancel($accountingStudentRegistrationFee->getIsCancel());
-                                     $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                     $anteriorAccountingStudentRegistrationFeeShedul->setAmount($anteriorAccountingStudentRegistrationFee->getAmount());
-                                     $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                                     $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                     $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
-                                     $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
-                                     
-                                     foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
-                                         $accountingStudentRegistrationFeeShedul->setAmountReported($accountingStudentRegistrationFeeShedul->getAmountCancel() + $accountingStudentRegistrationFeeShedul->getAmountRest());
-                                         $accountingStudentRegistrationFeeShedul->setIsReported(true);
-                                     }
-                                     
-                                     $accountingStudentRegistrationFee->setIsReported(true);
-                                     $accountingStudentRegistrationFee->setAmountReported($accountingStudentRegistrationFee->getAmountRest());
-                                     $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
-                                     $entityManager->persist($anteriorAccountingStudentRegistrationFee);
-                                 }
-                             }
-                         }
-                     }
-                 }
-             }
-             /* Ajout des frais de SCOLARITE pour tous*/
-             $settingScolariteFees = $settingFeeRepository->findBy(['is_for_all' => true, 'category' => 'SCOLARITE', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             foreach ($settingScolariteFees as $key => $settingFee) {
-                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                     $accountingStudentRegistrationFee->setFee($settingFee);
-                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                     $entityManager->persist($accountingStudentRegistrationFee);
-                     /* Etablissement des echeanciers */
-                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }else {
-                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                         $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                     }
-                 }
-             }
-             /* Ajout des frais de SCOLARITE  specifiques */
-             $settingScolariteAffectedFees = $settingFeeRepository->findBy(['is_for_affected' => true, 'category' => 'SCOLARITE', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingScolariteNonAffectedFees = $settingFeeRepository->findBy(['is_for_non_affected' => true, 'category' => 'SCOLARITE', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             if ($registrationStudentRegistration->getIsAffected()) {
-                 foreach ($settingScolariteAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }else{
-                 foreach ($settingScolariteNonAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }
-             /* Ajout des frais de ARTICLE pour tous */
-             $settingArticleFees = $settingFeeRepository->findBy(['is_for_all' => true, 'category' => 'ARTICLE', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingArticleAffectedFees = $settingFeeRepository->findBy(['is_for_affected' => true, 'category' => 'ARTICLE', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingArticleNonAffectedFees = $settingFeeRepository->findBy(['is_for_non_affected' => true, 'category' => 'ARTICLE', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             foreach ($settingArticleFees as $key => $settingFee) {
-                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                     $accountingStudentRegistrationFee->setFee($settingFee);
-                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                     $entityManager->persist($accountingStudentRegistrationFee);
-                     /* Etablissement des echeancier */
-                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }else {
-                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                         $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                     }
-                 }
-             }
-             /* Ajout des frais de ARTICLE specifique */
-             if ($registrationStudentRegistration->getIsAffected()) {
-                 foreach ($settingArticleAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }else {
-                 foreach ($settingArticleNonAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }
-             /* Ajout des frais de ACTIVITE-EXTAT pour tous */
-             $settingActiviteExtratFees = $settingFeeRepository->findBy(['is_for_all' => true, 'category' => 'ACTIVITE-EXTAT', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingActiviteExtratAffectedFees = $settingFeeRepository->findBy(['is_for_affected' => true, 'category' => 'ACTIVITE-EXTAT', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingActiviteExtratNonAffectedFees = $settingFeeRepository->findBy(['is_for_non_affected' => true, 'category' => 'ACTIVITE-EXTAT', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             foreach ($settingActiviteExtratFees as $key => $settingFee) {
-                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                     $accountingStudentRegistrationFee->setFee($settingFee);
-                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                     $entityManager->persist($accountingStudentRegistrationFee);
-                     /* Etablissement des echeancier */
-                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }else {
-                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                         $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                     }
-                 }
-             }
-             /* Ajout des frais de ACTIVITE-EXTAT specifique */
-             if ($registrationStudentRegistration->getIsAffected()) {
-                 foreach ($settingActiviteExtratAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }else {
-                 foreach ($settingActiviteExtratNonAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }
-             /* Ajout des frais de AUTRE-FRAIS pour tous */
-             $settingAutreFraisFees = $settingFeeRepository->findBy(['is_for_all' => true, 'category' => 'AUTRE-FRAIS', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingAutreFraisAffectedFees = $settingFeeRepository->findBy(['is_for_affected' => true, 'category' => 'AUTRE-FRAIS', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             $settingAutreFraisNonAffectedFees = $settingFeeRepository->findBy(['is_for_non_affected' => true, 'category' => 'AUTRE-FRAIS', 'schoolYear' => $schoolYear, 'establishment' => $establishment],['id' => 'DESC']);
-             foreach ($settingAutreFraisFees as $key => $settingFee) {
-                 if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                     $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                     $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                     $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                     $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                     $accountingStudentRegistrationFee->setFee($settingFee);
-                     $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                     $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                     $entityManager->persist($accountingStudentRegistrationFee);
-                     /* Etablissement des echeancier */
-                     if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                         foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }else {
-                         $order++;
-                         $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                         $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                         $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                         $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                         $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                     }
-                 }
-             }
-             /* Ajout des frais de ACTIVITE-EXTAT specifique */
-             if ($registrationStudentRegistration->getIsAffected()) {
-                 foreach ($settingAutreFraisAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }else {
-                 foreach ($settingAutreFraisNonAffectedFees as $key => $settingFee) {
-                     if($settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()->getParent()) || $settingFee->getLevels()->contains($registrationStudentRegistration->getClassroom()->getLevel()) || count($settingFee->getLevels()) <= 0){
-                         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee;
-                         $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                         $accountingStudentRegistrationFee->setAmount($settingFee->getAmount());
-                         $accountingStudentRegistrationFee->setCode('ASF-'.$registrationStudentRegistration->getId().$settingFee->getId());
-                         $accountingStudentRegistrationFee->setFee($settingFee);
-                         $accountingStudentRegistrationFee->setEstablishment($this->getUser()->getEstablishment());
-                         $accountingStudentRegistrationFee->setLabel($settingFee->getLabel());
-                         $entityManager->persist($accountingStudentRegistrationFee);
-                         /* Etablissement des echeancier */
-                         if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                             foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                                 $order++;
-                                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                 $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount());
-                                 $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                                 $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                             }
-                         }else {
-                             $order++;
-                             $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                             $accountingStudentRegistrationFeeShedul->setAmount($settingFee->getAmount());
-                             $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                             $accountingStudentRegistrationFeeShedul->setOrderNum($order);
-                             $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                             $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                             $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                         }
-                     }
-                 }
-             }
-             $entityManager->persist($registrationStudentRegistration);
-             try {
-                 $entityManager->flush();
-                 $this->addFlash('success', "Un inscrit à été ajouté.");
-             } catch (\Throwable $th) {
-                 $this->addFlash('warning', "Une erreure est survenue lors de l'ajout de l'inscrit.");
-                 $this->addFlash('info', $th->getMessage());
-             }
-             return $this->redirectToRoute('registration_student_registration_index', [], Response::HTTP_SEE_OTHER);
-         }
-         return $this->renderForm('registration/registration_student_registration/new.html.twig', [
-             'registration_student_registration' => $registrationStudentRegistration,
-             'form' => $form,
-         ]);
-     }
-     /**
-      * @Route("/{id}/show", name="registration_student_registration_show", methods={"GET","POST"})
-      */
-     public function show(Request $request, RegistrationStudentRegistration $registrationStudentRegistration, SettingFeeRepository $settingFeeRepository, TransportZoneRepository $transportZoneRepository, SMSSender $smsSender): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $establishment = $this->getUser()->getEstablishment();
-         
-         /* Ajouter un nouveau frais */
-         $setting_fees = $settingFeeRepository->createQueryBuilder('entity')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('entity.category != :category')
-         ->setParameter('category', 'SCOLARITE')
-         ->andWhere('entity.category != :category')
-         ->setParameter('category', SettingFee::TRANSPORT_FEE)
-         ->orderBy('entity.id', 'DESC')
-         ->getQuery()
-         ->getResult();
-         $accountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
-         $accountingStudentRegistrationFeeForm = $this->createForm(AccountingStudentRegistrationFeeType::class, $accountingStudentRegistrationFee)
-         ->add('fee', EntityType::class,[
-             'class' => SettingFee::class,
-             'choices' => $setting_fees
-         ])
-         ->add('quantity', NumberType::class, [
-             'attr' => [
-                 'class' => 'form-control',
-                 'style' => 'width: 100%;'
-             ],
-             'mapped' => false,
-             'required' => true,
-             'data' => 1
-         ]);
-         $accountingStudentRegistrationFeeForm->handleRequest($request);
-         if ($accountingStudentRegistrationFeeForm->isSubmitted() && $accountingStudentRegistrationFeeForm->isValid()) {
-             $entityManager = $this->getDoctrine()->getManager();
-             $settingFee = $accountingStudentRegistrationFee->getFee();
-             if (strlen($settingFee->getDuration()) > 0 && null == $accountingStudentRegistrationFee->getStartAt()) {
-                 $this->addFlash('warning', "Veuillez saisir la date de debut SVP.");
-                 return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
-             }
-             /** set start date end end date */
-             if (null != $accountingStudentRegistrationFee->getStartAt()) {
-                 if ($settingFee->getDuration() == 'JOURNALIER') {
-                     $accountingStudentRegistrationFee->setEndAt($accountingStudentRegistrationFee->getStartAt());
-                     
-                 }
-                 if ($settingFee->getDuration() == 'HEBDOMADAIRE') {
-                     $date = $accountingStudentRegistrationFee->getStartAt();
-                     $njdsc = date($date->format('w') , strtotime("-7 days"));
-                     $njmc = date("t");
-                     switch ($njdsc) {
-                         case 0:
-                             $accountingStudentRegistrationFee->setEndAt($date->sub(new DateInterval("P2D")));
-                             break;
-                         case 1:
-                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P4D")));
-                             break;
-                         case 2:
-                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P3D")));
-                             break;
-                         case 3:
-                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P2D")));
-                             break;
-                         case 4:
-                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P1D")));
-                             break;
-                         case 5:
-                             $accountingStudentRegistrationFee->setEndAt($date->add(new DateInterval("P0D")));
-                             break;
-                         case 6:
-                             $accountingStudentRegistrationFee->setEndAt($date->sub(new DateInterval("P1D")));
-                             break;
-                         default:
-                             # code...
-                             break;
-                     }
-                 }
-                 if ($settingFee->getDuration() == 'MENSUEL-SIMPLE') {
-                     $date = $accountingStudentRegistrationFee->getStartAt();
-                     $njdsc = date($date->format('w') , strtotime("-7 days"));
-                     $njmc = date("t");
-                     $date_end = new DateTimeImmutable($date->format('Y-m-').$njmc);
-                     $accountingStudentRegistrationFee->setEndAt($date_end);
-                     if ($date_end->format('D') == 'Sun') {
-                         $accountingStudentRegistrationFee->setEndAt($date_end->sub(new DateInterval("P2D")));
-                     }
-                     if ($date_end->format('D') == 'Sat') {
-                         $accountingStudentRegistrationFee->setEndAt($date_end->sub(new DateInterval("P1D")));
-                     }
-                 }
-                 if ($settingFee->getDuration() == 'MENSUEL-FULL') {
-                     $date = $accountingStudentRegistrationFee->getStartAt();
-                     $njdsc = date($date->format('w') , strtotime("-7 days"));
-                     $njmc = date("t");
-                     $date_end = new DateTimeImmutable($date->format('Y-m-').$njmc);
-                     $accountingStudentRegistrationFee->setEndAt($date_end);
-                 }
-                 $contacts = [];
-                 $contacts[] = '225'.str_replace(' ', '',trim($registrationStudentRegistration->getStudent()->getNotificationPhoneNumber()));
-                 $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();
-                 try {
-                     $response = $smsSender->sendSmsByEstablishment($establishment, $message, $contacts, $smsSender::UNICODE_CHARSET);
-                     $responses = explode(':', $response);
-                     $code = trim($responses[1]);
-                     $communicationMessage = new CommunicationMessage();
-                     $communicationMessage->setCode($code);
-                     $communicationMessage->setContacts($contacts);
-                     $communicationMessage->setContent($message);
-                     $communicationMessage->setEstablishment($establishment);
-                     $communicationMessage->setType($smsSender::UNICODE_CHARSET);
-                     $entityManager->persist($communicationMessage);
-                 } catch (\Throwable $th) {
-                     //throw $th;
-                 }
-                 
-             }
-             /** */
-             $quantity = $accountingStudentRegistrationFeeForm->get('quantity')->getData() ?? 1;
-             $label = $quantity > 1 ? $settingFee->getLabel() . ' x ' . $quantity : $settingFee->getLabel();
-             $amount = $settingFee->getAmount() * $quantity;
-             $accountingStudentRegistrationFee->setDuration($settingFee->getDuration());
-             $accountingStudentRegistrationFee->setEstablishment($establishment);
-             $accountingStudentRegistrationFee->setCode(time());
-             $accountingStudentRegistrationFee->setLabel($label);
-             $accountingStudentRegistrationFee->setAmount($amount);
-             $accountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-             $accountingStudentRegistrationFee->setFee($settingFee);
-             if (count($settingFee->getSettingFeeSheduls()) > 0) {
-                 $order = 0;
-                 foreach ($settingFee->getSettingFeeSheduls() as $key => $feeShedul) {
-                     $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                     $accountingStudentRegistrationFeeShedul->setAmount($feeShedul->getAmount() * $quantity);
-                     
-                     if (null != $accountingStudentRegistrationFee->getStartAt()) {
-                         $accountingStudentRegistrationFeeShedul->setDateDue($accountingStudentRegistrationFee->getStartAt());
-                     }else {
-                         $accountingStudentRegistrationFeeShedul->setDateDue($feeShedul->getDateDue());
-                     }
-                     $accountingStudentRegistrationFeeShedul->setOrderNum($order + 1);
-                     $accountingStudentRegistrationFeeShedul->setEstablishment($establishment);
-                     $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                     $entityManager->persist($accountingStudentRegistrationFeeShedul);
-                     $order++;
-                 }
-             }else {
-                 $accountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                 $accountingStudentRegistrationFeeShedul->setAmount($amount);
-                 if (null != $accountingStudentRegistrationFee->getStartAt()) {
-                     $accountingStudentRegistrationFeeShedul->setDateDue($accountingStudentRegistrationFee->getStartAt());
-                 }else {
-                     $accountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                 }
-                 
-                 $accountingStudentRegistrationFeeShedul->setOrderNum(1);
-                 $accountingStudentRegistrationFeeShedul->setEstablishment($this->getUser()->getEstablishment());
-                 $accountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
-                 
-                 $entityManager->persist($accountingStudentRegistrationFeeShedul);
-             }
-             foreach ($settingFee->getStockKitCategories() as $key => $stockKitCategory) {
-                 // sortie de kits
-                 $stockKitOut = new StockKitOut();
-                 $stockKitOut->setEstablishment($establishment);
-                 $stockKitOut->setSchoolYear($schoolYear);
-                 $stockKitOut->setRegistrationStudent($registrationStudentRegistration);
-                 $stockKitOut->setAccountingStudentRegistrationFee($accountingStudentRegistrationFee);
-                 $stockKitOut->setIsValidated(false);
-                 $stockKitOut->setKitCategory($stockKitCategory);
-                 $stockKitOut->setCreateDate(new DateTimeImmutable());
-                 // lignes de sortie de kits
-                 foreach ($stockKitCategory->getStockKitProducts() as $key => $stockKitProduct) {
-                     $stockKitOutLine = new StockKitOutLine();
-                     $stockKitOutLine->setEstablishment($establishment);
-                     $stockKitOutLine->setSchoolYear($schoolYear);
-                     $stockKitOutLine->setStockKitOut($stockKitOut);
-                     $stockKitOutLine->setStockKitProduct($stockKitProduct);
-                     $stockKitOutLine->setProduct($stockKitProduct->getProduct());
-                     $stockKitOutLine->setQuantity($quantity);
-                     $entityManager->persist($stockKitOutLine);
-                 }
-                 $entityManager->persist($stockKitOut);
-             }
-             
-             $entityManager->persist($accountingStudentRegistrationFee);
-             
-             try {
-                 $this->getDoctrine()->getManager()->flush();
-                 $accountingStudentRegistrationFee->setCode('ABN-'.sprintf("%'05s", $accountingStudentRegistrationFee->getId()));
-                 $this->getDoctrine()->getManager()->flush();
-                 $this->addFlash('success', "des frais ont été ajouté.");
-             } catch (\Throwable $th) {
-                 $this->addFlash('info', $th->getMessage());
-             }
-             return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
-         }
-         $transport_zones = $transportZoneRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.establishment', 'establishment')
-         ->addSelect('establishment')
-         ->innerJoin('establishment.establishmentGroup', 'establishmentGroup')
-         ->addSelect('establishmentGroup')
-         ->andWhere('establishmentGroup.id = :establishmentGroupId')
-         ->setParameter('establishmentGroupId', $establishment->getEstablishmentGroup()->getId())
-         ->orderBy('entity.id', 'DESC')
-         ->getQuery()
-         ->getResult();
-         $registrationTransportCheckpoint = new RegistrationTransportCheckpoint();
-         $registrationTransportCheckpointForm = $this->createForm(RegistrationTransportCheckpointType::class, $registrationTransportCheckpoint)
-         ->add('transportZone', EntityType::class, [
-             'class' => TransportZone::class,
-             'choices' => $transport_zones
-         ]);
-         $registrationTransportCheckpointForm->handleRequest($request);
-         if ($registrationTransportCheckpointForm->isSubmitted() && $registrationTransportCheckpointForm->isValid()) {
-             $entityManager = $this->getDoctrine()->getManager();
-             $registrationTransportCheckpoint->setRegistrationStudentRegistration($registrationStudentRegistration);
-             $registrationTransportCheckpoint->setEstablishment($registrationStudentRegistration->getEstablishment());
-             $entityManager->persist($registrationTransportCheckpoint);
-             
-             try{
-                 $entityManager->flush();
-             }catch(\Throwable $th){
-                 $this->addFlash('info', $th->getMessage());
-             }
-             return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
-         }
-         if ($request->get('__cd_token___') == 'soldeAnterieur') {
-             $entityManager = $this->getDoctrine()->getManager();
-             $fee = $settingFeeRepository->findOneBy(['establishment' => $registrationStudentRegistration->getEstablishment(),'schoolYear' => $schoolYear, 'label'  => 'SOLDE ANTERIEUR'], []);
-             if (null == $fee) {
-                 $fee = new SettingFee();
-                 $fee->setEstablishment($registrationStudentRegistration->getEstablishment());
-                 $fee->setCategory('AUTRE-FRAIS');
-                 $fee->setLabel('SOLDE ANTERIEUR');
-                 $fee->setAmount(0);
-                 $fee->setSchoolYear($schoolYear);
-                 $entityManager->persist($fee);
-             }
-             $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
-             $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
-             $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-             $anteriorAccountingStudentRegistrationFee->setFee($fee);
-             $anteriorAccountingStudentRegistrationFee->setAmount(intval($request->get('anterior_balance_amount')));
-             $anteriorAccountingStudentRegistrationFee->setCode($fee->getLabel().'-'.$registrationStudentRegistration->getId());
-             $anteriorAccountingStudentRegistrationFee->setLabel($fee->getLabel());
-             $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-             $anteriorAccountingStudentRegistrationFeeShedul->setAmount($anteriorAccountingStudentRegistrationFee->getAmount());
-             $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-             $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum(1);
-             $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
-             $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
-             
-             $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
-             $entityManager->persist($anteriorAccountingStudentRegistrationFee);
-             
-             try{
-                 $entityManager->flush();
-             }catch(\Throwable $th){
-                 $this->addFlash('info', $th->getMessage());
-             }
-             return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
-         }
-         return $this->renderForm('registration/registration_student_registration/show.html.twig', [
-             'registration_student_registration' => $registrationStudentRegistration,
-             'accounting_student_registration_fee' => $accountingStudentRegistrationFee,
-             'accounting_student_registration_fee_form' => $accountingStudentRegistrationFeeForm,
-             'registrationTransportCheckpoint' => $registrationTransportCheckpoint,
-             'registrationTransportCheckpointForm' => $registrationTransportCheckpointForm,
-         ]);
-     }
-     /**
-      * @Route("/{id}/edit", name="registration_student_registration_edit", methods={"GET","POST"})
-      */
-     public function edit(Request $request, RegistrationStudentRegistration $registrationStudentRegistration, SettingDocumentToProvideRepository $settingDocumentToProvideRepository): Response
-     {
-         $establishment = $this->getUser()->getEstablishment();
-         $form = $this->createForm(RegistrationStudentRegistrationType::class, $registrationStudentRegistration)
-         ->add('documentProvides', EntityType::class, [
-             'class' => SettingDocumentToProvide::class,
-             'choices' => $settingDocumentToProvideRepository->findBy(['establishment' => $establishment], []),
-             'multiple' => true,
-             'required' => false
-         ])
-         ->remove('student');
-         $form->handleRequest($request);
-         if ($form->isSubmitted() && $form->isValid()) {
-             
-             try {
-                 $this->getDoctrine()->getManager()->flush();
-                 $this->addFlash('success', "l'inscrit à été édité.");
-             } catch (\Throwable $th) {
-                 $this->addFlash('warning', "Une erreure est survenue lors de l'édition de l'inscrit.");
-                 $this->addFlash('info', $th->getMessage());
-             }
-             return $this->redirectToRoute('registration_student_registration_edit', ['id' => $registrationStudentRegistration->getId()], Response::HTTP_SEE_OTHER);
-         }
-         return $this->renderForm('registration/registration_student_registration/edit.html.twig', [
-             'registration_student_registration' => $registrationStudentRegistration,
-             'form' => $form,
-         ]);
-     }
-     /**
-      * @Route("/delete-selection", name="registration_student_registrations_selected_delete", methods={"GET"})
-     */
-     public function deleteSelected(Request $request, RegistrationStudentRegistrationRepository $entityRepository): Response
-     {
-         $list = $request->get('entities');
-         $entityManager = $this->getDoctrine()->getManager();
-         $errors = 0;
-         foreach ($list as $key => $id) {
-             $entity = $entityRepository->findOneBy(['id' => intval($id)], []);
-             if ($entity != null) {
-                 foreach ($entity->getStockKitOuts() as $key => $stockKitOut) {
-                     if (!$stockKitOut->getIsValidated()) {
-                         foreach ($stockKitOut->getStockKitOutLines() as $key => $stockKitOutLine) {
-                             $entityManager->remove($stockKitOutLine);
-                         }
-                         $entityManager->remove($stockKitOut);
-                     }
-                 }
-                 
-                 foreach ($entity->getStockStudentKitEntries() as $key => $stockStudentKitEntry) {
-                     foreach ($stockStudentKitEntry->getStockStudentKitEntryLines() as $key => $stockStudentKitEntryLine) {
-                         $entityManager->remove($stockStudentKitEntryLine);
-                     }
-                     $entityManager->remove($stockStudentKitEntry);
-                 }
-                 foreach ($entity->getAccountingCredits() as $key => $accountingCredit) {
-                     foreach ($accountingCredit->getAccountingCreditLines() as $key => $accountingCreditLine) {
-                         $entityManager->remove($accountingCreditLine);
-                     }
-                     $entityManager->remove($accountingCredit);
-                 }
-                 if (count($entity->getAccountingStudentRegistrationFees()) <= 0) {
-                     $entityManager->remove($entity);
-                 }
-             }
-         }
-         try {
-             $entityManager->flush();
-             $this->addFlash('success', "Traitement effectué");
-             return $this->json(['code' => 200, 'message' => "Traitement effectué :)"], 200);
-         } catch (\Throwable $th) {
-             //$th->getMessage()
-             $this->addFlash('warning', $th->getMessage());
-         }
-         
-         $this->addFlash('warning', "Traitement non effectué");
-         return $this->json(['code' => 500, 'message' => "Traitement non effectué"], 200);
-     }
-     /**
-      * @Route("/{id}/toggle-abandon", name="registration_student_registration_abandon", methods={"GET"})
-     */
-     public function abandon(RegistrationStudentRegistration $registrationStudentRegistration): Response
-     {
-         $registrationStudentRegistration->setIsAbandonned(!$registrationStudentRegistration->getIsAbandonned());
-         if ($registrationStudentRegistration->getIsAbandonned()) {
-             $registrationStudentRegistration->setStatus(RegistrationStudentRegistration::STATUS_ABANDONNE);
-         } else {
-             $registrationStudentRegistration->setStatus(RegistrationStudentRegistration::STATUS_INSCRIT);
-         }
-         $message = $registrationStudentRegistration->getIsAbandonned() ? "Abandonné" : "Inscrit";
-         try {
-             $this->getDoctrine()->getManager()->flush();
-             $this->addFlash('success', "Traitement effectué : " . $message);
-             return $this->json(['code' => 200, 'message' => "Traitement effectué :) : " . $message], 200);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         return $this->json(['code' => 500, 'message' => "Traitement non effectué"], 200);
-     }
-     /**
-      * @Route("/{id}/delete", name="registration_student_registration_delete", methods={"GET"})
-      * @IsGranted("ROLE_SUPER_ADMIN")
-     */
-     public function delete(RegistrationStudentRegistration $registrationStudentRegistration): Response
-     {
-         if (count($registrationStudentRegistration->getAccountingStudentRegistrationFees()) > 0) {
-             return $this->json(['code' => 500, 'message' => "Ce inscrit a des frais, il ne peut pas être supprimé."], 200);
-         }
-         if(count($registrationStudentRegistration->getAccountingStudentRegistrationPayments()) > 0) {
-             return $this->json(['code' => 500, 'message' => "Ce inscrit a des paiements, il ne peut pas être supprimé."], 200);
-         }
-         foreach ($registrationStudentRegistration->getStockKitOuts() as $key => $stockKitOut) {
-             if (!$stockKitOut->getIsValidated()) {
-                 foreach ($stockKitOut->getStockKitOutLines() as $key => $stockKitOutLine) {
-                     $this->getDoctrine()->getManager()->remove($stockKitOutLine);
-                 }
-             }
-         }
-         foreach ($registrationStudentRegistration->getStockStudentKitEntries() as $key => $stockStudentKitEntry) {
-             foreach ($stockStudentKitEntry->getStockStudentKitEntryLines() as $key => $stockStudentKitEntryLine) {
-                 $this->getDoctrine()->getManager()->remove($stockStudentKitEntryLine);
-             }
-             $this->getDoctrine()->getManager()->remove($stockStudentKitEntry);
-         }
-         foreach ($registrationStudentRegistration->getRegistrationTransportCheckpoints() as $key => $registrationTransportCheckpoint) {
-             $this->getDoctrine()->getManager()->remove($registrationTransportCheckpoint);
-         }
-         foreach ($registrationStudentRegistration->getRegistrationStudentDowngrades() as $key => $registrationStudentDowngrade) {
-             $this->getDoctrine()->getManager()->remove($registrationStudentDowngrade);
-         }
-         foreach ($registrationStudentRegistration->getRegistrationStudentAbandonments() as $key => $registrationStudentAbandonment) {
-             $this->getDoctrine()->getManager()->remove($registrationStudentAbandonment);
-         }
-         foreach ($registrationStudentRegistration->getRegistrationStudentContacts() as $key => $registrationStudentContact) {
-             $this->getDoctrine()->getManager()->remove($registrationStudentContact);
-         }
-         try {
-             $this->getDoctrine()->getManager()->remove($registrationStudentRegistration);
-             $this->getDoctrine()->getManager()->flush();
-         } catch (\Throwable $th) {
-             return $this->json(['code' => 500, 'message' => $th->getMessage()], 200);
-         }
-         return $this->json(['code' => 200, 'message' => "Traitement effectué :)"], 200);
-     }
-     /**
-      * @Route("/api/get-info", name="api_registration_student_registration_info", methods={"GET"})
-     */
-     public function apiGetInfo(Request $request, RegistrationStudentRegistrationRepository $entityRepository, SettingClassroomRepository $settingClassroomRepository): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $establishment = $user->getEstablishment();
-         $schoolYear = $user->getSchoolYear();
-         $id = intval($request->get('id'));
-         $student = $entityRepository->findOneBy(['id' => $id], []);
-         if (null == $student) {
-             return $this->json(['code' => 500, 'message' => "not found :)"], 200);
-         }
-         $sclassrooms = new ArrayCollection();
-         $_sclassrooms = $settingClassroomRepository->findBy(['level' => $student->getClassroom()->getLevel(), 'schoolYear' => $schoolYear], ['label' => 'ASC']);
-         
-         $_sclassrooms =  $settingClassroomRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.level', 'level')
-         ->addSelect('level')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('level.parent = :parent')
-         ->setParameter('parent', $student->getClassroom()->getLevel()->getParent())
-         ->getQuery()
-         ->getResult();
-         $__sclassrooms =  $settingClassroomRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.level', 'level')
-         ->addSelect('level')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('entity.level = :level')
-         ->setParameter('level', $student->getClassroom()->getLevel())
-         ->getQuery()
-         ->getResult();
-         foreach ($_sclassrooms as $key => $_sclassroom) {
-             if ($student->getClassroom() != $_sclassroom) {
-                 $sclassrooms->add([
-                     'id' => $_sclassroom->getId(),
-                     'label' => $_sclassroom->getLabel()
-                 ]);
-             }
-         };
-         foreach ($__sclassrooms as $key => $_sclassroom) {
-             if ($student->getClassroom() != $_sclassroom) {
-                 if ($student->getClassroom()->getLevel()->getParent() == null) {
-                     $sclassrooms->add([
-                         'id' => $_sclassroom->getId(),
-                         'label' => $_sclassroom->getLabel()
-                     ]);
-                 }
-             }
-         };
-         if ($student != null) {
-             return $this->json([
-                 'code' => 200, 
-                 'message' => "found :)", 
-                 'sname' => $student->getName(), 
-                 'sregistrationNumber' => $student->getStudent()->getRegistrationNumber(), 
-                 'scode' => $student->getStudent()->getCode(), 
-                 'sclassroom' => $student->getClassroom()->getLabel(), 
-                 'sclassrooms' => $sclassrooms, 
-                 'slevel' => $student->getClassroom()->getLevel()->getId(), 
-                 'sestablishment' => $student->getEstablishment()->getName(), 
-                 'ssolde' => number_format(($student->getGleAmount() - $student->getAmountPaid()), 0, ',', ' '),
-                 'is_affected' => $student->getStudent()->getIsAffected(), 
-                 'is_redoubling' => $student->getStudent()->getIsRedoubling(), 
-             ], 
-             200);
-         }else{
-             return $this->json(['code' => 500, 'message' => "not found :)"], 200);
-         }
-     }
-     /**
-      * @Route("/print/{id}/card", name="registration_student_registration_print_card", methods={"GET"})
-     */
-     public function printCard(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/primaireCard.html.twig';
-         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
-             $template = 'registration/print/secondaireCard.html.twig';
-         }
-         
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'CARTE_DE_SORTIE_'.$registrationStudent->getStudent()->getCode().".pdf";
-         return new PdfResponse(
-             $knpSnappyPdf->getOutputFromHtml($html),
-             $file_name,
-             'application/pdf',
-             'attachment'
-         );
-     }
-     /**
-      * @Route("/print/{id}/badge", name="registration_student_registration_print_badge", methods={"GET"})
-     */
-     public function printBadge(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/primaireBadge.html.twig';
-         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
-             $template = 'registration/print/secondaireBadge.html.twig';
-         }
-         
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'BADGE_'.$registrationStudent->getStudent()->getCode().".pdf";
-         return new PdfResponse(
-             $knpSnappyPdf->getOutputFromHtml($html, [
-                 'margin-left' => '0',
-                 'margin-top' => '0',
-                 'margin-right' => '0',
-                 'margin-bottom' => '0',
-                 'page-height' =>  35,
-                 'page-width' => 53
-             ]),
-             $file_name,
-             'application/pdf',
-             'attachment'
-         );
-     }
-     /**
-      * @Route("/print/{id}/badgeVerso", name="registration_student_registration_print_badge_verso", methods={"GET"})
-     */
-     public function printBadgeVerso(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/primaireBadgeVerso.html.twig';
-         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
-             $template = 'registration/print/secondaireBadgeVerso.html.twig';
-         }
-         
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'BADGE_VERSO'.$registrationStudent->getStudent()->getCode().".pdf";
-         return new PdfResponse(
-             $knpSnappyPdf->getOutputFromHtml($html, [
-                 'margin-left' => '0',
-                 'margin-top' => '0',
-                 'margin-right' => '0',
-                 'margin-bottom' => '0',
-                 'page-height' =>  35,
-                 'page-width' => 53
-             ]),
-             $file_name,
-             'application/pdf',
-             'attachment'
-         );
-     }
-     /**
-      * @Route("/print/{id}/attestationOfAttendance", name="registration_student_registration_print_attestation_of_attendance", methods={"GET"})
-     */
-     public function printAttestationOfAttendance(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/attestation_of_attendance.html.twig';
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'ATTESTATION_DE_FREQUENTATION_'.$registrationStudent->getStudent()->getCode().".pdf";
-         $footer = $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
-         $header = $this->renderView('print/header.html.twig', ['setting' => $setting,]);
-         $options = [
-             'orientation' => 'Portrait'
-             //'header-html' => $header
-             //'footer-html' => $footer
-         ];
-         try {
-             $knpSnappyPdf->generateFromHtml($html, $this->getParameter('app.app_directory').'/downloads/students/' . $file_name, $options, true);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', "Ce reçu à déjà été imprimé.");
-         }
-         
-         return $this->redirectToRoute('preview', [
-             'file' => $file_name,
-             'dir' => 'students',
-         ]);
-     }
-     /**
-      * @Route("/print/{id}/transpotantionSheet", name="registration_student_registration_print_transpotantion_sheet", methods={"GET"})
-     */
-     public function printTranspotantionSheet(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/transpotantion_sheet.html.twig';
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'FICHE_DE_TRANSPORT_'.$registrationStudent->getStudent()->getCode().".pdf";
-         $footer = $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
-         $header = $this->renderView('print/header.html.twig', ['setting' => $setting,]);
-         $options = [
-             'orientation' => 'Portrait',
-             'header-html' => $header
-             //'footer-html' => $footer
-         ];
-         try {
-             $knpSnappyPdf->generateFromHtml($html, $this->getParameter('app.app_directory').'/downloads/students/' . $file_name, $options, true);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         
-         return $this->redirectToRoute('preview', [
-             'file' => $file_name,
-             'dir' => 'students',
-         ]);
-     }
-     /**
-      * @Route("/print/{id}/acknowledgmentReceip", name="registration_student_registration_print_acknowledgment_receip", methods={"GET"})
-     */
-     public function acknowledgment_receip(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/acknowledgment_receip.html.twig';
-         
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'ACCUSE_DE_RECEPTION_'.$registrationStudent->getId().".pdf";
-         $footer = $this->renderView('print/footer.html.twig', ['setting' => $setting,]);
-         $header = $this->renderView('print/header.html.twig', ['setting' => $setting,]);
-         $options = [
-             'orientation' => 'Portrait',
-             'header-html' => $header
-             //'footer-html' => $footer
-         ];
-         try {
-             $knpSnappyPdf->generateFromHtml($html, $this->getParameter('app.app_directory').'/downloads/students/' . $file_name, $options, true);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         
-         return $this->redirectToRoute('preview', [
-             'file' => $file_name,
-             'dir' => 'students',
-         ]);
-     }
-     /**
-      * @Route("/api/get-kit-model", name="api_registration_student_registration_get_kit_models", methods={"GET"})
-     */
-     public function apiGetKitModel(Request $request, RegistrationStudentRegistrationRepository $entityRepository): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $establishment = $this->getUser()->getEstablishment();
-         $id = intval($request->get('id'));
-         $student = $entityRepository->find($id);
-         $kitCategories = new ArrayCollection();
-         $level = $student->getClassroom()->getLevel();
-         foreach ($level->getSettingFees() as $key => $settingFee) {
-             foreach ($settingFee->getStockKitCategories() as $key => $stockKitCategorie) {
-                 if($stockKitCategorie->getEstablishment() == $establishment && $stockKitCategorie->getSchoolYear() == $schoolYear){
-                     $kitCategories->add([
-                         'id' => $stockKitCategorie->getId(),
-                         'name' => $stockKitCategorie->getName()
-                     ]);
-                 }
-             };
-         };
-         if ($student != null) {
-             return $this->json([
-                 'code' => 200, 
-                 'message' => "found :)", 
-                 'sname' => $student->getName(), 
-                 'sregistrationNumber' => $student->getStudent()->getRegistrationNumber(), 
-                 'scode' => $student->getStudent()->getCode(), 
-                 'sclassroom' => $student->getClassroom()->getLabel(), 
-                 'slevel' => $student->getClassroom()->getLevel()->getId(), 
-                 'sestablishment' => $student->getEstablishment()->getName(), 
-                 'ssolde' => number_format(($student->getGleAmount() - $student->getAmountPaid()), 0, ',', ' '),
-                 'kit_categories' => $kitCategories, 
-             ], 
-             200);
-         }else{
-             return $this->json(['code' => 500, 'message' => "not found :)"], 200);
-         }
-     }
-     /**
-      * @Route("/{id}/print", name="registration_student_registration_print", methods={"GET"})
-     */
-     public function print(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudentRegistration, DocManagerRepository $docManagerRepository)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudentRegistration->getEstablishment();
-         $template = 'registration/print/rePrimaire.html.twig';
-         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
-             $template = 'registration/print/reSecondaire.html.twig';
-         }
-         
-         $html = $this->renderView($template, [
-             'doc_manager' => $docManagerRepository->findOneBy(['establishment' => $setting, 'code' => 'REGLEMENT-INTERIEUR'], []),
-             'registration_student_registration' => $registrationStudentRegistration,
-             'registration_student_pre_registration' => $registrationStudentRegistration->getRegistrationStudentPreRegistration(),
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'INSCRIPTION_N_'.$schoolYear->getCode().'--'.$registrationStudentRegistration->getStudent()->getCode().".pdf";
-         return new PdfResponse(
-             $knpSnappyPdf->getOutputFromHtml($html),
-             $file_name,
-             'application/pdf',
-             'attachment'
-         );
-     }
-     /**
-      * @Route("/print/{id}/access-card", name="registration_student_registration_print_access_card", methods={"GET"})
-     */
-     public function printAccessCard(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         // Vérifier si l'élève a une photo
-         $studentImage = $registrationStudent->getStudent()->getImage();
-         $registrationImage = $registrationStudent->getImage();
-         
-         if (empty($studentImage) && empty($registrationImage)) {
-             $this->addFlash('warning', 'Attention : Cet élève n\'a pas de photo dans la base de données. La carte d\'accès sera générée sans photo.');
-         } elseif (empty($studentImage) && !empty($registrationImage)) {
-             $this->addFlash('info', 'Information : La photo de l\'inscription sera utilisée. Pensez à synchroniser les photos si nécessaire.');
-         }
-         $template = 'registration/print/accessCard2.html.twig';
-         if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
-             $template = 'registration/print/accessCard2.html.twig';
-         }
-         
-         $html = $this->renderView($template, [
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $options = [
-             'margin-left' => '0',
-             'margin-top' => '0',
-             'margin-right' => '0',
-             'margin-bottom' => '0',
-             'page-height' =>  37,
-             'page-width' => 55
-         ];
-         $file_name = 'CARTE_DACCES_'.$registrationStudent->getStudent()->getCode().".pdf";
-         try {
-             $knpSnappyPdf->generateFromHtml($html, $this->getParameter('app.app_directory').'/downloads/students/' . $file_name, $options, true);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         return $this->redirectToRoute('preview', [
-             'file' => $file_name,
-             'dir' => 'students',
-         ]);
-     }
-     /**
-      * @Route("/export", name="registration_student_registration_export")
-     */
-     public function export(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $students = new ArrayCollection();
-         $establishment = $this->getUser()->getEstablishment();
-         $registration_student_registrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-             ->innerJoin('entity.student', 'student')
-             ->addSelect('student')
-             ->andWhere('entity.is_abandonned = :is_abandonned')
-             ->setParameter('is_abandonned', 0)
-             ->andWhere('entity.establishment = :establishment')
-             ->setParameter('establishment', $establishment)
-             ->andWhere('entity.schoolYear = :schoolYear')
-             ->setParameter('schoolYear', $schoolYear)
-             ->orderBy('student.last_name', 'asc')
-             ->getQuery()
-             ->getResult();
-         
-         foreach ($registration_student_registrations as $key => $registration_student_registration) {
-             $students->add(
-                 [
-                     'registrationNumber' => $registration_student_registration->getStudent()->getRegistrationNumber(),
-                     'code' => $registration_student_registration->getStudent()->getCode(),
-                     'name' => $registration_student_registration->getStudent()->getName(),
-                     'lastName' => $registration_student_registration->getStudent()->getLastName(),
-                     'firstName' => $registration_student_registration->getStudent()->getFirstName(),
-                     'birthDay' => $registration_student_registration->getStudent()->getBirthDay()->format('d/m/Y'),
-                     'birthLocation' => $registration_student_registration->getStudent()->getBirthLocation(),
-                     'statut' => $registration_student_registration->getStudent()->getIsAffected() ? "Affecté(e)" : "Non Affecté(e)",
-                     'notificationPhoneNumber' => $registration_student_registration->getStudent()->getNotificationPhoneNumber(),
-                     'doubling' => $registration_student_registration->getIsRedoubling() ? "Doublant(e)" : "Non Doublant(e)",
-                     'nationality' => $registration_student_registration->getStudent()->getNationality(),
-                     'classroom' => $registration_student_registration->getClassroom()->getLabel(),
-                     'level' => $registration_student_registration->getClassroom()->getLevel()->getLabel(),
-                     'gender' => $registration_student_registration->getStudent()->getGender(),
-                     'round' => $registration_student_registration->getClassroom()->getRound() ?  $registration_student_registration->getClassroom()->getRound()->getLabel() : '',
-                     'lv1' => $registration_student_registration->getStudent()->getLv1(),
-                     'lv2' => $registration_student_registration->getStudent()->getLv2(),
-                     'createDate' => $registration_student_registration->getRegisteredAt() ? $registration_student_registration->getRegisteredAt()->format('d/m/Y') : '',
-                 ]
-             );
-             
-         }
-         
-         $iterator = $students->getIterator();
-         $array = iterator_to_array($iterator);
-         uasort($array, function ($first, $second) {
-             if ($first === $second) {
-                 return 0;
-             }
-             return $first['name'] < $second['name'] ? -1 : 1;
-         });
-         $students = new ArrayCollection($array);
-         $spreadsheet = new Spreadsheet();
-         $sheet = $spreadsheet->getActiveSheet();
-         $index = 1;
-         $sheet->setCellValue('A' . $index, 'MATRICULE NATIONAL');
-         $sheet->setCellValue('B' . $index, 'NOM');
-         $sheet->setCellValue('C' . $index, 'PRENOMS');
-         $sheet->setCellValue('D' . $index, 'DATE DE NAISSANCE');
-         $sheet->setCellValue('E' . $index, 'LIEU DE NAISSANCE');
-         $sheet->setCellValue('F' . $index, 'STATUT');
-         $sheet->setCellValue('G' . $index, 'CONTACT PARENT');
-         $sheet->setCellValue('H' . $index, 'DOUBLANT');
-         $sheet->setCellValue('I' . $index, 'NATIONALITE');
-         $sheet->setCellValue('J' . $index, 'CLASSE');
-         $sheet->setCellValue('K' . $index, 'NIVEAU');
-         $sheet->setCellValue('L' . $index, 'SEX');
-         $sheet->setCellValue('M' . $index, 'SERIE');
-         $sheet->setCellValue('N' . $index, 'LV1');
-         $sheet->setCellValue('O' . $index, 'LV2');
-         $sheet->setCellValue('P' . $index, 'MATRICULE INTERNE');
-         $sheet->setCellValue('Q' . $index, 'Date Inscription');
-         $index++;
-         $loopIndex = 1;
-         foreach ($students as $key => $student) {
-             $sheet->setCellValue('A' . $index, $student['registrationNumber']);
-             $sheet->setCellValue('B' . $index, $student['lastName']);
-             $sheet->setCellValue('C' . $index, $student['firstName']);
-             $sheet->setCellValue('D' . $index, $student['birthDay']);
-             $sheet->setCellValue('E' . $index, $student['birthLocation']);
-             $sheet->setCellValue('F' . $index, $student['statut']);
-             $sheet->setCellValue('G' . $index, $student['notificationPhoneNumber']);
-             $sheet->setCellValue('H' . $index, $student['doubling']);
-             $sheet->setCellValue('I' . $index, $student['nationality']);
-             $sheet->setCellValue('J' . $index, $student['classroom']);
-             $sheet->setCellValue('K' . $index, $student['level']);
-             $sheet->setCellValue('L' . $index, $student['gender']);
-             $sheet->setCellValue('M' . $index, $student['round']);
-             $sheet->setCellValue('N' . $index, $student['lv1']);
-             $sheet->setCellValue('O' . $index, $student['lv2']);
-             $sheet->setCellValue('P' . $index, $student['code']);
-             $sheet->setCellValue('Q' . $index, $student['createDate']);
-             $index++;
-             $loopIndex++;
-         }
-         $sheet->setTitle('INSCRITS_' . $establishment->getCode().'_'.$schoolYear->getCode());
-         $writer = new Xlsx($spreadsheet);
-         // Create a Temporary file in the system
-         $fileName = 'LISTE_INSCRITS_' . $establishment->getName().'_'.date('Y').'.xlsx';
-         $temp_file = tempnam(sys_get_temp_dir(), $fileName);
-         $writer->save($temp_file);
-         // Return the excel file as an attachment
-         return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
-     }
-     /**
-      * @Route("/print/{id}/extract-school-record-book", name="registration_student_registration_print_extract_school_record_book", methods={"GET"})
-     */
-     public function extract_school_record_book(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent, SchoolReportCardRepository $schoolReportCardRepository, EquivalentMatterRepository $equivalentMatterRepository)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $school_report_cards = $schoolReportCardRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.schoolYearPeriode', 'schoolYearPeriode')
-         ->addSelect('schoolYearPeriode')
-         ->andWhere('entity.studentRegistration = :studentRegistration')
-         ->setParameter('studentRegistration', $registrationStudent)
-         ->orderBy('schoolYearPeriode.code', 'ASC')
-         ->getQuery()
-         ->getResult();
-         $equivalent_matters = $equivalentMatterRepository->createQueryBuilder('entity')
-         ->orderBy('entity.num_order', 'ASC')
-         ->getQuery()
-         ->getResult();
-         $template = 'registration/print/extract_school_record_book.html.twig';
-         
-         $html = $this->renderView($template, [
-             'equivalent_matters' => $equivalent_matters,
-             'school_report_cards' => $school_report_cards,
-             'student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'EXTRAIT_DE_LIVRET_SCOLAIRE_'.$registrationStudent->getId().".pdf";
-         $footer = $this->renderView('print/footer.html.twig', ['setting' => $setting]);
-         $header = $this->renderView('print/header.html.twig', ['setting' => $setting]);
-         $options = [
-             'orientation' => 'Landscape',
-             'header-html' => $header
-             //'footer-html' => $footer
-         ];
-         try {
-             $knpSnappyPdf->generateFromHtml($html, $this->getParameter('app.app_directory').'/downloads/students/' . $file_name, $options, true);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         
-         return $this->redirectToRoute('preview', [
-             'file' => $file_name,
-             'dir' => 'students',
-         ]);
-     }
-     /**
-      * @Route("/_statistics-table", name="registration_student_registration_statistics_table", methods={"GET","POST"})
-      */
-     public function _statistics_table(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $establishment = $user->getEstablishment();
-         $schoolYear = $user->getSchoolYear();
-         $registration_student_registrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.student', 'student')
-         ->addSelect('student')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->getQuery()
-         ->getResult();
-         $registration_student_registration_women = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.student', 'student')
-         ->addSelect('student')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('student.gender = :gender')
-         ->setParameter('gender', 'FEMININ')
-         ->getQuery()
-         ->getResult();
-         $registration_student_registration_men = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.student', 'student')
-         ->addSelect('student')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('student.gender = :gender')
-         ->setParameter('gender', 'MASCULIN')
-         ->getQuery()
-         ->getResult();
-         $registration_student_registration_affecteds = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.student', 'student')
-         ->addSelect('student')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('student.is_affected = :is_affected')
-         ->setParameter('is_affected', 1)
-         ->getQuery()
-         ->getResult();
-         return $this->renderForm('registration/registration_student_registration/_statistics_table.html.twig', [
-             'registration_student_registrations' => count($registration_student_registrations),
-             'registration_student_registration_women' => count($registration_student_registration_women),
-             'registration_student_registration_men' => count($registration_student_registration_men),
-             'registration_student_registration_affecteds' => count($registration_student_registration_affecteds),
-         ]);
-     }
-     /**
-      * @Route("/_registration_select", name="api_registration_student_registration_select", methods={"GET","POST"})
-      */
-     public function api_select(Request $request, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository){
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $establishment = $user->getEstablishment();
-         $registrationStudentRegistrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
-         ->innerJoin('entity.student', 'student')
-         ->addSelect('student')
-         ->orWhere('student.code LIKE :code')
-         ->setParameter('code', '%'.$request->get('q').'%')
-         ->orWhere('student.registration_number LIKE :registration_number')
-         ->setParameter('registration_number', '%'.$request->get('q').'%')
-         ->orWhere('student.last_name LIKE :last_name')
-         ->setParameter('last_name', '%'.$request->get('q').'%')
-         ->orWhere('student.first_name LIKE :first_name')
-         ->setParameter('first_name', '%'.$request->get('q').'%')
-         ->andWhere('entity.establishment = :establishment')
-         ->setParameter('establishment', $establishment)
-         ->andWhere('entity.schoolYear = :schoolYear')
-         ->setParameter('schoolYear', $schoolYear)
-         ->andWhere('entity.is_abandonned = :is_abandonned')
-         ->setParameter('is_abandonned', 0)
-         
-         ->setMaxResults(100)
-         ->getQuery()
-         ->getResult();
-         $data = new ArrayCollection();
-         foreach ($registrationStudentRegistrations as $key => $registrationStudentRegistration) {
-             if ($registrationStudentRegistration->getAmountRest() > 0) {
-                 $data->add([
-                     'id' => $registrationStudentRegistration->getId(),
-                     'text' => '['.$registrationStudentRegistration->getStudent()->getRegistrationNumber().'] '.$registrationStudentRegistration->getName().' ['.$registrationStudentRegistration->getClassroom()->getLabel().']'
-                 ]);
-             }
-         }
-         return $this->json($data, 200);
-     }
-     /**
-      * @Route("/print/{id}/fees-details", name="registration_student_registration_print_fees_details", methods={"GET"})
-     */
-     public function print_fees_details(Pdf $knpSnappyPdf, RegistrationStudentRegistration $registrationStudent)
-     {
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $setting = $registrationStudent->getEstablishment();
-         $template = 'registration/print/frees_details.html.twig';
-         
-         $html = $this->renderView($template, [
-             'registration_student_registration' => $registrationStudent,
-             'school_year' => $schoolYear,
-             'setting' => $setting,
-         ]);
-         $file_name = 'DETAILS_FRAIS_'.$registrationStudent->getId().".pdf";
-         $footer = $this->renderView('print/footer.html.twig', ['setting' => $setting]);
-         $header = $this->renderView('print/header.html.twig', ['setting' => $setting]);
-         $options = [
-             'orientation' => 'Portrait',
-             'header-html' => $header
-             //'footer-html' => $footer
-         ];
-         try {
-             $knpSnappyPdf->generateFromHtml($html, $this->getParameter('app.app_directory').'/downloads/students/' . $file_name, $options, true);
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         
-         return $this->redirectToRoute('preview', [
-             'file' => $file_name,
-             'dir' => 'students',
-         ]);
-     }
-     /**
-      * @Route("/_registration_fee", name="api_registration_student_registration_get_registration_fees", methods={"GET","POST"})
-      */
-     public function api_get_registration_fees(Request $request, StockKitCategoryRepository $stockKitCategoryRepository, AccountingStudentRegistrationFeeRepository $accountingStudentRegistrationFeeRepository, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository){
-         /**@var User $user */
-         $user = $this->getUser();
-         $schoolYear = $user->getSchoolYear();
-         $establishment = $user->getEstablishment();
-         $stockKitCategory = $stockKitCategoryRepository->findOneBy(['id' => $request->get('kitCategory')], []);
-         $registrationStudentRegistration = $registrationStudentRegistrationRepository->findOneBy(['id' => $request->get('registrationStudent')], []);
-         if (null == $stockKitCategory || null == $registrationStudentRegistration) {
-             return $this->json([
-                 'code' => 404, 
-                 'message' => "ok",
-                 'accountingStudentRegistrationFees' => new ArrayCollection()
-             ], 200);
-         }
-         
-         $accountingStudentRegistrationFees = $accountingStudentRegistrationFeeRepository->createQueryBuilder('entity')
-             ->andWhere('entity.studentRegistration = :studentRegistration')
-             ->setParameter('studentRegistration', $registrationStudentRegistration)
-             ->andWhere('entity.fee = :fee')
-             ->setParameter('fee', $stockKitCategory->getFee())
-             ->orderBy('entity.label', 'ASC')
-             ->getQuery()
-             ->getResult();
-         $data = new ArrayCollection();
-         
-         foreach ($accountingStudentRegistrationFees as $key => $accountingStudentRegistrationFee) {
-             if (count($accountingStudentRegistrationFee->getStockKitOuts()) <= 0) {
-                 $data->add([
-                     'id' => $accountingStudentRegistrationFee->getId(),
-                     'label' => $accountingStudentRegistrationFee->getLabel()
-                 ]);
-             }
-         }
-         return $this->json([
-             'code' => 200, 
-             'message' => "ok",
-             'accountingStudentRegistrationFees' => $data
-         ], 200);
-     }
-     /**
-      * @Route("/{id}/set-student-to-affected/{idStudent}", name="registration_student_registration_set_student_to_affected", methods={"GET"})
-      */
-     public function set_student_to_affected(RegistrationStudentRegistration $registrationStudentRegistration, RegistrationStudentRepository $registrationStudent, $idStudent): Response
-     {
-         $student = $registrationStudent->findOneBy(['id' => $idStudent], []);
-         if (null == $student) {
-             $this->addFlash('info', 'Étudiant non trouvé');
-             return $this->redirectToRoute('registration_student_registration_edit', ['id' => $registrationStudentRegistration->getId()]);
-         }
-         $registrationStudentRegistration->setStudent($student);
-         $entityManager = $this->getDoctrine()->getManager();
-         $entityManager->flush();
-         $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());
-         return $this->redirectToRoute('registration_student_registration_edit', ['id' => $registrationStudentRegistration->getId()]);
-     }
-     /**
-      * @Route("/{id}/get-solde-anterieur", name="registration_student_registration_get_solde_anterieur", methods={"GET"})
-      */
-     public function get_solde_anterieur(RegistrationStudentRegistration $registrationStudentRegistration, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
-     {
-         // Ajout de solde anterieur à partir de la deuxième année de gestion
-         $anteriorRegistrationStudentRegistrations = $registrationStudentRegistrationRepository->findBy(['student' => $registrationStudentRegistration->getStudent()], ['id' => 'DESC']);
-         $entityManager = $this->getDoctrine()->getManager();
-         
-         foreach ($anteriorRegistrationStudentRegistrations as $key => $anteriorRegistrationStudentRegistration) {
-             if ($anteriorRegistrationStudentRegistration->getSchoolYear() != $registrationStudentRegistration->getSchoolYear()) {
-                 $order = 0;
-                 if (null != $anteriorRegistrationStudentRegistration) {
-                     foreach ($anteriorRegistrationStudentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
-                         $order++;
-                         if (!$accountingStudentRegistrationFee->getIsArchived()) {
-                             if (!$accountingStudentRegistrationFee->getIsCancel()) {
-                                 if (!$accountingStudentRegistrationFee->getIsReported()) {
-                                     if ($accountingStudentRegistrationFee->getAmountRest() > 0) {
-                                         $anteriorAccountingStudentRegistrationFee = new AccountingStudentRegistrationFee();
-                                         $anteriorAccountingStudentRegistrationFee->setEstablishment($registrationStudentRegistration->getEstablishment());
-                                         $anteriorAccountingStudentRegistrationFee->setStudentRegistration($registrationStudentRegistration);
-                                         $anteriorAccountingStudentRegistrationFee->setFee($accountingStudentRegistrationFee->getFee());
-                                         $anteriorAccountingStudentRegistrationFee->setAmount($accountingStudentRegistrationFee->getAmountRest());
-                                         $anteriorAccountingStudentRegistrationFee->setCode('SA-'.$accountingStudentRegistrationFee->getLabel().'-'.$registrationStudentRegistration->getId());
-                                         $anteriorAccountingStudentRegistrationFee->setLabel('SOLDE ANT. '.$accountingStudentRegistrationFee->getLabel());
-                                         $anteriorAccountingStudentRegistrationFee->setIsArchived($accountingStudentRegistrationFee->getIsArchived());
-                                         $anteriorAccountingStudentRegistrationFee->setIsCancel($accountingStudentRegistrationFee->getIsCancel());
-                                         $anteriorAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
-                                         $anteriorAccountingStudentRegistrationFeeShedul->setAmount($anteriorAccountingStudentRegistrationFee->getAmount());
-                                         $anteriorAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable());
-                                         $anteriorAccountingStudentRegistrationFeeShedul->setOrderNum($order);
-                                         $anteriorAccountingStudentRegistrationFeeShedul->setEstablishment($registrationStudentRegistration->getEstablishment());
-                                         $anteriorAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($anteriorAccountingStudentRegistrationFee);
-                                         
-                                         foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
-                                             $accountingStudentRegistrationFeeShedul->setAmountReported($accountingStudentRegistrationFeeShedul->getAmountCancel() + $accountingStudentRegistrationFeeShedul->getAmountRest());
-                                             $accountingStudentRegistrationFeeShedul->setIsReported(true);
-                                         }
-                                         
-                                         $accountingStudentRegistrationFee->setIsReported(true);
-                                         $accountingStudentRegistrationFee->setAmountReported($accountingStudentRegistrationFee->getAmountRest());
-                                         $entityManager->persist($anteriorAccountingStudentRegistrationFeeShedul);
-                                         $entityManager->persist($anteriorAccountingStudentRegistrationFee);
-                                     }
-                                 }
-                             }
-                         }
-                     }
-                 }
-                 break;
-             }
-         }
-         $entityManager = $this->getDoctrine()->getManager();
-         try {
-             $entityManager->flush();
-             $this->addFlash('success', 'Solde antérieur ajouté avec succès');
-         } catch (\Throwable $th) {
-             $this->addFlash('info', $th->getMessage());
-         }
-         return $this->redirectToRoute('registration_student_registration_show', ['id' => $registrationStudentRegistration->getId()]);
-     }
- }
-