src/Controller/Treasury/TreasuryCashRegisterController.php line 347

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Treasury;
  3. use Knp\Snappy\Pdf;
  4. use App\Entity\User;
  5. use DateTimeImmutable;
  6. use App\Service\SMSSender;
  7. use App\Entity\LogOperation;
  8. use App\Entity\TreasuryPayment;
  9. use App\Entity\SettingClassroom;
  10. use App\Entity\TreasuryCheckout;
  11. use App\Repository\UserRepository;
  12. use App\Entity\FoundingNotification;
  13. use App\Entity\TreasuryCashMovement;
  14. use App\Entity\TreasuryCashRegister;
  15. use App\Repository\SchoolYearRepository;
  16. use App\Form\Treasury\TreasuryPaymentType;
  17. use Knp\Component\Pager\PaginatorInterface;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use App\Repository\TreasuryCheckoutRepository;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use App\Entity\RegistrationStudentRegistration;
  22. use App\Form\Treasury\TreasuryCashRegisterType;
  23. use App\Repository\AccountingExpenseRepository;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use Doctrine\Common\Collections\ArrayCollection;
  26. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  27. use App\Repository\TreasuryCashRegisterRepository;
  28. use App\Entity\AccountingStudentRegistrationPayment;
  29. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  30. use App\Entity\AccountingStudentRegistrationFeeShedulPayment;
  31. use App\Repository\RegistrationStudentRegistrationRepository;
  32. use App\Form\Accounting\AccountingStudentRegistrationPaymentType;
  33. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  34. use App\Repository\AccountingStudentRegistrationPaymentRepository;
  35. use App\Repository\AccountingStudentRegistrationFeeShedulRepository;
  36. /**
  37.  * @Route("/treasury/cash-register")
  38.  */
  39. class TreasuryCashRegisterController extends AbstractController
  40. {
  41.     /**
  42.      * @Route("/index", name="treasury_cash_register_index", methods={"GET","POST"})
  43.      */
  44.     public function index(Request $requestPaginatorInterface $paginatorTreasuryCashRegisterRepository $treasuryCashRegisterRepositoryTreasuryCheckoutRepository $treasuryCheckoutRepository): Response
  45.     {
  46.         /**@var User $user */
  47.         $user $this->getUser();
  48.         $schoolYear $user->getSchoolYear();
  49.         $establishment $user->getEstablishment();
  50.         
  51.         
  52.         if ($schoolYear == null) {
  53.             $this->addFlash('warning'"Aucune base de donnée n'est activé.");
  54.             return $this->redirectToRoute('treasury_cash_register_new', []);
  55.         }
  56.         $treasuryCashRegister = new TreasuryCashRegister();
  57.         $treasuryCashRegister->setCode($this->getUser()->getUserIdentifier().'-du-'.$treasuryCashRegister->getCreateAt()->format('d-m-Y'));
  58.         $establishment $this->getUser()->getEstablishment();
  59.         $checkouts $treasuryCheckoutRepository->createQueryBuilder('entity')
  60.         ->andWhere('entity.created_by = :created_by')
  61.         ->setParameter('created_by'$this->getUser()->getId())
  62.         ->orderBy('entity.id''desc')
  63.         ->getQuery()
  64.         ->getResult();
  65.         $form $this->createForm(TreasuryCashRegisterType::class, $treasuryCashRegister)
  66.         ->add('checkout'EntityType::class, [
  67.             'class' => TreasuryCheckout::class,
  68.             'choices' => $checkouts
  69.         ]);
  70.         $form->handleRequest($request);
  71.         if ($form->isSubmitted() && $form->isValid()) {
  72.             $entityManager $this->getDoctrine()->getManager();
  73.             $treasuryCashRegister->setSchoolYear($schoolYear);
  74.             $treasuryCashRegister->setEstablishment($treasuryCashRegister->getCheckout()->getEstablishment());
  75.             $treasuryCashRegister->setCreateAt(new DateTimeImmutable());
  76.             
  77.             $entityManager->persist($treasuryCashRegister);
  78.             try {
  79.                 $entityManager->flush();
  80.                 $this->addFlash('success'"Un releve à été ajoutée.");
  81.                 return $this->redirectToRoute('treasury_cash_register_show', ['id' => $treasuryCashRegister->getId()]);
  82.             } catch (\Throwable $th) {
  83.                 $this->addFlash('warning'"Une erreure est survenue lors de l'ajout du releve.");
  84.                 $this->addFlash('info'$th->getMessage());
  85.                 return $this->redirectToRoute('treasury_cash_register_index', []);
  86.             }
  87.         }
  88.         if ($this->isGranted("ROLE_INDENTANT")) {
  89.             $query $treasuryCashRegisterRepository->createQueryBuilder('entity')
  90.             ->innerJoin('entity.establishment''establishment')
  91.             ->addSelect('establishment')
  92.             ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  93.             ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  94.             ->orderBy('entity.id''DESC')
  95.             ->getQuery();
  96.         }else {
  97.             $query $treasuryCashRegisterRepository->createQueryBuilder('entity')
  98.             ->innerJoin('entity.establishment''establishment')
  99.             ->addSelect('establishment')
  100.     
  101.             ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  102.             ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  103.             ->andWhere('entity.created_by = :created_by')
  104.             ->setParameter('created_by'$user->getId())
  105.             ->orderBy('entity.id''DESC')
  106.             ->getQuery();
  107.         }
  108.         $treasuryCashRegisters $paginator->paginate($query$request->query->getInt('page'1), 10);
  109.         return $this->renderForm('treasury/treasury_cash_register/index.html.twig', [
  110.             'treasury_cash_registers' => $treasuryCashRegisters,
  111.             'treasury_cash_register' => $treasuryCashRegister,
  112.             'treasuryCashRegisterRepository' => $treasuryCashRegisterRepository,
  113.             'form' => $form,
  114.         ]);
  115.     }
  116.     /**
  117.      * @Route("/{id}/show", name="treasury_cash_register_show", methods={"GET", "POST"})
  118.     */
  119.     public function show(Request $requestTreasuryCashRegister $treasuryCashRegisterRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepositoryAccountingStudentRegistrationPaymentRepository $accountingStudentRegistrationPaymentRepositoryAccountingExpenseRepository $accountingExpenseRepositoryUserRepository $userRepositoryTreasuryCashRegisterRepository $treasuryCashRegisterRepositorySMSSender $smsSender): Response
  120.     {
  121.         /**@var User $user */
  122.         $user $this->getUser();
  123.         $schoolYear $user->getSchoolYear();
  124.         $establishment $user->getEstablishment();
  125.         $accountingStudentRegistrationPayment = new AccountingStudentRegistrationPayment();
  126.         $registrationStudentRegistrationUnsolds = new ArrayCollection();
  127.         $studentRegistrations $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  128.         
  129.         ->innerJoin('entity.student''student')
  130.         ->addSelect('student')
  131.         
  132.         ->andWhere('entity.establishment = :establishment')
  133.         ->setParameter('establishment'$establishment)
  134.         ->andWhere('entity.schoolYear = :schoolYear')
  135.         ->setParameter('schoolYear'$schoolYear)
  136.         ->andWhere('entity.is_abandonned = :is_abandonned')
  137.         ->setParameter('is_abandonned'0)
  138.         ->orderBy('entity.id''DESC')
  139.         ->getQuery()
  140.         ->getResult();
  141.         foreach ($studentRegistrations as $key => $registrationStudentRegistration) {
  142.             if ($registrationStudentRegistration->getAmountRest() > 0) {
  143.                 $registrationStudentRegistrationUnsolds->add($registrationStudentRegistration);
  144.             }
  145.         }
  146.         /* $parentStudentRegistrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  147.         ->innerJoin('entity.student', 'student')
  148.         ->addSelect('student')
  149.         
  150.         ->innerJoin('entity.establishment', 'establishment')
  151.         ->addSelect('establishment')
  152.         ->innerJoin('establishment.childEstablishments', 'childEstablishment')
  153.         ->addSelect('childEstablishment')
  154.         ->andWhere('childEstablishment.id = :idChild')
  155.         ->setParameter('idChild', $establishment->getId())
  156.         ->andWhere('entity.schoolYear = :schoolYear')
  157.         ->setParameter('schoolYear', $schoolYear)
  158.         ->andWhere('entity.is_abandonned = :is_abandonned')
  159.         ->setParameter('is_abandonned', 0)
  160.         ->orderBy('entity.id', 'DESC')
  161.         ->getQuery()
  162.         ->getResult();
  163.         foreach ($parentStudentRegistrations as $key => $parentStudentRegistration) {
  164.             if ($parentStudentRegistration->getAmountRest() > 0) {
  165.                 if (!$registrationStudentRegistrationUnsolds->contains($parentStudentRegistration)) {
  166.                     $registrationStudentRegistrationUnsolds->add($parentStudentRegistration);
  167.                 }
  168.             }
  169.         } */
  170.         
  171.         $form $this->createForm(AccountingStudentRegistrationPaymentType::class, $accountingStudentRegistrationPayment)
  172.         ->add('studentRegistration'EntityType::class, [
  173.             'class' => RegistrationStudentRegistration::class,
  174.             'choices' => $registrationStudentRegistrationUnsolds,
  175.             'required' => true
  176.         ]);
  177.         $form->handleRequest($request);
  178.         if ($form->isSubmitted() && $form->isValid()) {
  179.             $entityManager $this->getDoctrine()->getManager();
  180.             if ($schoolYear == null) {
  181.                 $this->addFlash('warning'"Aucune base de donnée n'est activé.");
  182.                 return $this->redirectToRoute('treasury_cash_register_show', ['id' => $treasuryCashRegister->getId()]);
  183.             }
  184.             if ($accountingStudentRegistrationPayment->getAmount() > ($accountingStudentRegistrationPayment->getStudentRegistration()->getGleAmount() - $accountingStudentRegistrationPayment->getStudentRegistration()->getAmountPaid())) {
  185.                 $this->addFlash('warning'"Le montant du paiement depasse le solde. Veuillez saisir un montant inferieur ou égal au solde.");
  186.                 return $this->redirectToRoute('treasury_cash_register_show', ['id' => $treasuryCashRegister->getId()]);
  187.             }
  188.             $accountingStudentRegistrationPayment->setSchoolYear($schoolYear);
  189.             $accountingStudentRegistrationPayment->setCashRegister($treasuryCashRegister);
  190.             $accountingStudentRegistrationPayment->setEstablishment($accountingStudentRegistrationPayment->getStudentRegistration()->getEstablishment());
  191.             $nextIndex count($accountingStudentRegistrationPaymentRepository->findBy(['establishment' => $accountingStudentRegistrationPayment->getStudentRegistration()->getEstablishment()], [])) + 1;
  192.             $accountingStudentRegistrationPayment->setCode(date('Y-').$accountingStudentRegistrationPayment->getStudentRegistration()->getEstablishment()->getId().'-'.sprintf("%'05s"$nextIndex));
  193.             $entityManager->persist($accountingStudentRegistrationPayment);
  194.             
  195.             try {
  196.                 $entityManager->flush();
  197.                 $studentRegistration $accountingStudentRegistrationPayment->getStudentRegistration();
  198.                 $studentRegistration->setLastPaymentAt(new DateTimeImmutable());
  199.                 $studentRegistration->setLastAmountPaid(floatval($request->get('_shedul_payment')));
  200.                 $studentRegistration->setLastPaymentId($accountingStudentRegistrationPayment->getId());
  201.                 $accountingStudentRegistrationPayment->setCode(date('Y-').$accountingStudentRegistrationPayment->getStudentRegistration()->getEstablishment()->getId().'-'.sprintf("%'05s"$accountingStudentRegistrationPayment->getId()));
  202.                 $logOperation = new LogOperation($request->getClientIp(), $accountingStudentRegistrationPayment->getId(), AccountingStudentRegistrationPayment::class, "Création de paiement N°: <strong>".$accountingStudentRegistrationPayment->getCode().", élève : " $accountingStudentRegistrationPayment->getStudentRegistration()->getStudent()->getCode() . ", montant: "number_format($accountingStudentRegistrationPayment->getAmount(), 0','' ') . " </strong>"$this->getUser()->getUserIdentifier(), "primary");
  203.                 $logOperation->setEstablishment($establishment);
  204.                 $entityManager->persist($logOperation);
  205.                 
  206.                 $entityManager->flush();
  207.                 $this->addFlash('success'"Un paiement à été ajouté.");
  208.             } catch (\Throwable $th) {
  209.                 $this->addFlash('warning'"Une erreure est survenue lors de l'ajout du paiement.");
  210.                 $this->addFlash('info'$th->getMessage());
  211.             }
  212.             return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]);
  213.         }
  214.         //versements
  215.         $treasuryPayment = new TreasuryPayment();
  216.         $treasuryPayment->setCreateAt(new DateTimeImmutable());
  217.         $treasuryPaymentForm $this->createForm(TreasuryPaymentType::class, $treasuryPayment);
  218.         $treasuryPaymentForm->handleRequest($request);
  219.         if ($treasuryPaymentForm->isSubmitted() && $treasuryPaymentForm->isValid()) {
  220.             $entityManager $this->getDoctrine()->getManager();
  221.             /*
  222.              * 20/08/2022
  223.              * si le solde de la caisse est insuffisant pour effectué un versement 
  224.              * le fondateur à demande de désactiver cette option pour permeetre
  225.              * un versement même si le solde est insuffisant
  226.              * 
  227.                 if ($treasuryCashRegister->toForward($treasuryCashRegisterRepository) < $treasuryPayment->getAmount()) {
  228.                     $this->addFlash('warning', "Le solde de la caisse est insuffisant.");
  229.                     return $this->redirectToRoute('treasury_cash_register_show', ['id' => $treasuryCashRegister->getId()]);
  230.                 }
  231.             */ 
  232.             
  233.             $treasuryPayment->setCashRegister($treasuryCashRegister);
  234.             $treasuryPayment->setEstablishment($treasuryCashRegister->getEstablishment());
  235.             $treasuryPayment->setSchoolYear($treasuryCashRegister->getSchoolYear());
  236.             $entityManager->persist($treasuryPayment);
  237.             //notification fondateur
  238.             $foundingNotification = new FoundingNotification();
  239.             $foundingNotification->setCreateDate(new DateTimeImmutable());
  240.             $foundingNotification->setAction("Versement");
  241.             $foundingNotification->setElement("Versement: #".$treasuryCashRegister->getCode());
  242.             $foundingNotification->setDescription("Versement: #".$treasuryCashRegister->getCode().' Mt: '.number_format($treasuryPayment->getAmount(), 0','' ').' Date: '.$foundingNotification->getCreateDate()->format('d/m/Y'));
  243.             $foundingNotification->setEstablishment($treasuryPayment->getEstablishment());
  244.             $foundingNotification->setIpAddress($request->getClientIp());
  245.             $foundingNotification->setSchoolYear($treasuryPayment->getSchoolYear());
  246.             $foundingNotification->setUsername($this->getUser()->getUserIdentifier());
  247.             $entityManager->persist($foundingNotification);
  248.             /*---------------------------------------------*/
  249.             try {
  250.                 $entityManager->flush();
  251.                 $this->addFlash('success'"Un versement à été ajouté.");
  252.                 $message "La caissiere ".$treasuryCashRegister->getCheckout()->getLabel()." vient d'effectuer un versement a la banque. Vous etes prie de bien vouloir valider, Montant : ".number_format($treasuryPayment->getAmount(), 0','' ').' Date: '.$foundingNotification->getCreateDate()->format('d/m/Y');
  253.                 $contacts = [];
  254.                 //$contacts[] = '225'.str_replace(' ', '',trim('0748808080'));
  255.                 //$contacts[] = '225'.str_replace(' ', '',trim('0749565147'));
  256.                 //$contacts[] = '225'.str_replace(' ', '',trim('0757357534'));
  257.                 $contacts[] = '225'.str_replace(' ''',trim($establishment->getSmsBankPayment()));
  258.                 $response $smsSender->sendSmsByEstablishment($establishment$message$contacts$smsSender::UNICODE_CHARSET);
  259.             } catch (\Throwable $th) {
  260.                 $this->addFlash('warning'"Une erreure est survenue lors de l'ajout du versement.");
  261.                 $this->addFlash('info'$th->getMessage());
  262.             }
  263.             return $this->redirectToRoute('treasury_cash_register_show', ['id' => $treasuryCashRegister->getId()]);
  264.         }
  265.         // depenses
  266.         $expenses $accountingExpenseRepository->createQueryBuilder('entity')
  267.         ->innerJoin('entity.establishment''establishment')
  268.         ->addSelect('establishment')
  269.         ->andWhere('establishment.establishmentGroup = :establishmentGroup')
  270.         ->setParameter('establishmentGroup'$establishment->getEstablishmentGroup())
  271.         ->andWhere('entity.is_aproved = :is_aproved')
  272.         ->setParameter('is_aproved'1)
  273.         ->andWhere('entity.is_submited = :is_submited')
  274.         ->setParameter('is_submited'1)
  275.         /* ->andWhere('entity.is_paid = :is_paid')
  276.         ->setParameter('is_paid', 0) */
  277.         ->andWhere('entity.is_canceled = :is_canceled')
  278.         ->setParameter('is_canceled'0)
  279.         ->orderBy('entity.id''DESC')
  280.         ->getQuery()
  281.         ->getResult();
  282.         
  283.         return $this->renderForm('treasury/treasury_cash_register/show.html.twig', [
  284.             'treasury_cash_register' => $treasuryCashRegister,
  285.             'registrationStudentRegistrationUnsolds' => $registrationStudentRegistrationUnsolds,
  286.             'form' => $form,
  287.             'treasuryPaymentForm' => $treasuryPaymentForm,
  288.             'treasuryPayment' => $treasuryPayment,
  289.             'expenses' => $expenses,
  290.             'userRepository' => $userRepository,
  291.             'treasuryCashRegisterRepository' => $treasuryCashRegisterRepository,
  292.         ]);
  293.     }
  294.     /**
  295.      * @Route("/shedul-payment/{id}", name="treasury_cash_register_shedul_payments", methods={"GET", "POST"})
  296.     */
  297.     public function shedulPayment(Request $requestAccountingStudentRegistrationPayment $accountingStudentRegistrationPaymentAccountingStudentRegistrationFeeShedulRepository $accountingStudentRegistrationFeeShedulRepository): Response
  298.     {
  299.         if ($accountingStudentRegistrationPayment->isPrintable()) {
  300.             return $this->redirectToRoute('treasury_cash_register_shedul_payment_print', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  301.         }
  302.         if ($request->get('_submitting') == $this->getUser()->getUserIdentifier()) {
  303.             if (($accountingStudentRegistrationPayment->getAmount() - $accountingStudentRegistrationPayment->getShedulAmount())  < floatval($request->get('_shedul_payment'))) {
  304.                 $this->addFlash('warning'"Le montant doit être inférieur ou égale au reste à imputer.");
  305.                 return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  306.             }
  307.             
  308.             $accountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedulRepository->find(intval($request->get('_feeId')));
  309.             if (null == $accountingStudentRegistrationFeeShedul) {
  310.                 $this->addFlash('warning'"L'échéancié que vous souhaitez payer n'existe pas.");
  311.                 return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  312.             }
  313.             $accountingStudentRegistrationFee $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee();
  314.             $studentRegistration $accountingStudentRegistrationPayment->getStudentRegistration();
  315.             
  316.             if (floatval($request->get('_shedul_payment')) > 0) {
  317.                 if(floatval($request->get('_shedul_payment')) <= $accountingStudentRegistrationFeeShedul->getAmountRest()){
  318.                     $accountingStudentRegistrationFeeShedulPayment = new AccountingStudentRegistrationFeeShedulPayment();
  319.                     $accountingStudentRegistrationFeeShedulPayment->setCode('PE-'.$accountingStudentRegistrationPayment->getId().'-'.time());
  320.                     $accountingStudentRegistrationFeeShedulPayment->setLabel('PE-'.$accountingStudentRegistrationPayment->getId().'-'.time());
  321.                     $accountingStudentRegistrationFeeShedulPayment->setAmount(floatval($request->get('_shedul_payment')));
  322.                     $accountingStudentRegistrationFeeShedulPayment->setCashRegister($accountingStudentRegistrationPayment->getCashRegister());
  323.                     $accountingStudentRegistrationFeeShedulPayment->setEstablishment($accountingStudentRegistrationPayment->getEstablishment());
  324.                     $accountingStudentRegistrationFeeShedulPayment->setStudentRegistrationFeeShedul($accountingStudentRegistrationFeeShedul);
  325.                     $accountingStudentRegistrationFeeShedulPayment->setStudentRegistrationFee($accountingStudentRegistrationFee);
  326.                     $accountingStudentRegistrationFeeShedulPayment->setStudentRegistrationPayment($accountingStudentRegistrationPayment);
  327.                     $accountingStudentRegistrationFeeShedulPayment->setAccountingAccount($accountingStudentRegistrationFee->getFee()->getAccountingAccount());
  328.                     
  329.                     $accountingStudentRegistrationFeeShedul->setAmountPaid($accountingStudentRegistrationFeeShedul->getAmountPaid() + floatval($request->get('_shedul_payment')));
  330.                     $accountingStudentRegistrationFeeShedul->setLastPaymentAt(new DateTimeImmutable());
  331.                     $accountingStudentRegistrationFeeShedul->setLastAmountPaid(floatval($request->get('_shedul_payment')));
  332.                     $accountingStudentRegistrationFeeShedul->setLastPaymentId($accountingStudentRegistrationPayment->getId());
  333.                     $accountingStudentRegistrationFee->setLastPaymentAt(new DateTimeImmutable());
  334.                     $accountingStudentRegistrationFee->setLastAmountPaid(floatval($request->get('_shedul_payment')));
  335.                     $accountingStudentRegistrationFee->setLastPaymentId($accountingStudentRegistrationPayment->getId());
  336.                     $studentRegistration->setLastPaymentAt(new DateTimeImmutable());
  337.                     $studentRegistration->setLastAmountPaid(floatval($request->get('_shedul_payment')));
  338.                     $studentRegistration->setLastPaymentId($accountingStudentRegistrationPayment->getId());
  339.                     
  340.                     $cashMovement = new TreasuryCashMovement();
  341.                     $cashMovement->setAmount(floatval($request->get('_shedul_payment')));
  342.                     $cashMovement->setAccountingStudentRegistrationFeeShedulPayment($accountingStudentRegistrationFeeShedulPayment);
  343.                     $cashMovement->setCashRegister($accountingStudentRegistrationPayment->getCashRegister());
  344.                     $cashMovement->setCode($accountingStudentRegistrationPayment->getId().'-'.time());
  345.                     $cashMovement->setEstablishment($accountingStudentRegistrationPayment->getEstablishment());
  346.                     $cashMovement->setType('in');
  347.                     $cashMovement->setLabel('paiement écheancié'.$accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getFee()->getLabel());
  348.                     $cashMovement->setAccountingStudentRegistrationFeeShedulPayment($accountingStudentRegistrationFeeShedulPayment);
  349.                     
  350.                     $entityManager $this->getDoctrine()->getManager();
  351.                     $entityManager->persist($accountingStudentRegistrationFeeShedulPayment);
  352.                     $entityManager->persist($cashMovement);
  353.                     try {
  354.                         $entityManager->flush();
  355.                         return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  356.                     } catch (\Throwable $th) {
  357.                         $this->addFlash('warning'"Une erreur s'est produite.");
  358.                         $this->addFlash('info'$th->getMessage());
  359.                         return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  360.                     }
  361.                     
  362.                 }else {
  363.                     $this->addFlash('warning'"Le montant doit être inférieur ou égale au reste de l'échéancié.");
  364.                     return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  365.                 }
  366.             }else{
  367.                 $this->addFlash('warning'"Le montant doit être supérieur à zéro(0).");
  368.                 return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  369.             }
  370.         }
  371.         return $this->render('treasury/treasury_cash_register/shedul_payments.html.twig', [
  372.             'accounting_student_registration_payment' => $accountingStudentRegistrationPayment,
  373.             'treasury_cash_register' => $accountingStudentRegistrationPayment->getCashRegister(),
  374.             'student_registration' => $accountingStudentRegistrationPayment->getStudentRegistration(),
  375.             'student_registration_fees' => $accountingStudentRegistrationPayment->getStudentRegistration()->getAccountingStudentRegistrationFees(),
  376.         ]);
  377.     }
  378.     /**
  379.      * @Route("/shedul-payment/{id}/print", name="treasury_cash_register_shedul_payment_print", methods={"GET"})
  380.     */
  381.     public function print(Pdf $knpSnappyPdfAccountingStudentRegistrationPayment $accountingStudentRegistrationPaymentAccountingStudentRegistrationFeeShedulRepository $accountingStudentRegistrationFeeShedulRepositoryUserRepository $userRepository)
  382.     {
  383.         if (!$accountingStudentRegistrationPayment->isPrintable()) {
  384.             $this->addFlash('warning'"Veuillez terminer les imputations avant d'imprimer.");
  385.             return $this->redirectToRoute('treasury_cash_register_shedul_payments', ['id' => $accountingStudentRegistrationPayment->getId()]); 
  386.         }
  387.         $setting $accountingStudentRegistrationPayment->getEstablishment();
  388.         
  389.         $html $this->renderView('treasury/treasury_cash_register/print/payment.html.twig', [
  390.             'ref' => sprintf("%'04s"$accountingStudentRegistrationPayment->getId()),
  391.             'accounting_student_registration_payment' => $accountingStudentRegistrationPayment,
  392.             'student_registration' => $accountingStudentRegistrationPayment->getStudentRegistration(),
  393.             'student_registration_fees' => $accountingStudentRegistrationPayment->getStudentRegistration()->getAccountingStudentRegistrationFees(),
  394.             'school_year' => $accountingStudentRegistrationPayment->getSchoolYear(),
  395.             'userRepository' => $userRepository,
  396.             'setting' => $setting,
  397.         ]);
  398.         $file_name 'RECU_N_'.$accountingStudentRegistrationPayment->getStudentRegistration()->getStudent()->getCode().'_'.$accountingStudentRegistrationPayment->getCode().".pdf";
  399.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting]);
  400.         $header $this->renderView('print/header.html.twig', ['setting' => $setting]);
  401.         
  402.         $options = [
  403.             'orientation' => 'Portrait',
  404.             /*'header-html' => $header
  405.             'footer-html' => $footer*/
  406.         ];
  407.         try {
  408.             $knpSnappyPdf->generateFromHtml($html$this->getParameter('app.app_directory').'/downloads/cashRegister/' $file_name$optionstrue);
  409.         } catch (\Throwable $th) {
  410.             $this->addFlash('info'"Ce reçu à déjà été imprimé.");
  411.         }
  412.         
  413.         $id $accountingStudentRegistrationPayment->getCashRegister()->getId();
  414.         return $this->redirectToRoute('preview_payment', [
  415.             'id' => $id,
  416.             'file' => $file_name,
  417.             'dir' => 'cashRegister'
  418.         ]);
  419.     }
  420.     /**
  421.      * @Route("/{id}/edit", name="treasury_cash_register_edit", methods={"GET","POST"})
  422.      */
  423.     public function edit(Request $requestTreasuryCashRegister $treasuryCashRegister): Response
  424.     {
  425.         $form $this->createForm(TreasuryCashRegisterType::class, $treasuryCashRegister);
  426.         $form->handleRequest($request);
  427.         if ($form->isSubmitted() && $form->isValid()) {
  428.             try {
  429.                 $this->getDoctrine()->getManager()->flush();
  430.                 $this->addFlash('success'"le releve à été édité.");
  431.             } catch (\Throwable $th) {
  432.                 $this->addFlash('warning'"Une erreure est survenue lors de l'édition du releve.");
  433.                 $this->addFlash('info'$th->getMessage());
  434.             }
  435.             return $this->redirectToRoute('treasury_cash_register_index', [], Response::HTTP_SEE_OTHER);
  436.         }
  437.         return $this->renderForm('treasury/treasury_cash_register/edit.html.twig', [
  438.             'treasury_cash_register' => $treasuryCashRegister,
  439.             'form' => $form,
  440.         ]);
  441.     }
  442.     /**
  443.      * @Route("/delete-selection", name="treasury_cash_registers_selected_delete", methods={"GET"})
  444.     */
  445.     public function deleteSelected(Request $requestTreasuryCashRegisterRepository $entityRepository): Response
  446.     {
  447.         $list $request->get('entities');
  448.         $entityManager $this->getDoctrine()->getManager();
  449.         $errors 0;
  450.         foreach ($list as $key => $id) {
  451.             $entity $entityRepository->findOneBy(['id' => intval($id)], []);
  452.             if ($entity != null) {
  453.                 if (count($entity->getAccountingStudentRegistrationPayments()) <= 0) {
  454.                     $entityManager->remove($entity);
  455.                 }
  456.             }
  457.         }
  458.         try {
  459.             $entityManager->flush();
  460.             $this->addFlash('success'"Traitement effectué");
  461.             return $this->json(['code' => 200'message' => "Traitement effectué :)"], 200);
  462.         } catch (\Throwable $th) {
  463.             //$th->getMessage()
  464.             $this->addFlash('warning'$th->getMessage());
  465.         }
  466.         
  467.         $this->addFlash('warning'"Traitement non effectué");
  468.         return $this->json(['code' => 500'message' => "Traitement non effectué"], 200);
  469.     }
  470.     /**
  471.      * @Route("/close/{id}", name="treasury_cash_register_close", methods={"GET"})
  472.     */
  473.     public function close(TreasuryCashRegister $entity): Response
  474.     {
  475.         foreach ($entity->getAccountingStudentRegistrationPayments() as $key => $studentRegistrationPayment) {
  476.             if ($studentRegistrationPayment->isCanBeShow()) {
  477.                 return $this->json(['code' => 500'message' => "Tous les paiement n'ont pas été traités correctement."], 200);
  478.             }
  479.         }
  480.         $entityManager $this->getDoctrine()->getManager();
  481.         $entity->setIsClosed(true);
  482.         
  483.         try {
  484.             $entityManager->flush();
  485.             //$this->addFlash('success', "Paiement supprimé");
  486.             return $this->json(['code' => 200'message' => "Caisse clôturé :)"], 200);
  487.         } catch (\Throwable $th) {
  488.             $this->addFlash('warning'$th->getMessage());
  489.             return $this->json(['code' => 500'message' => "Une erreur s'est produite !)"], 200);
  490.         }
  491.         return $this->json(['code' => 500'message' => "Caisse non clôturé"], 200);
  492.     }
  493.     /**
  494.      * @Route("/reOpen/{id}", name="treasury_cash_register_reopen", methods={"GET"})
  495.     */
  496.     public function reOpen(TreasuryCashRegister $entity): Response
  497.     {
  498.         foreach ($entity->getAccountingStudentRegistrationPayments() as $key => $studentRegistrationPayment) {
  499.             if ($studentRegistrationPayment->isCanBeShow()) {
  500.                 return $this->json(['code' => 500'message' => "Tous les paiement n'ont pas été traités correctement."], 200);
  501.             }
  502.         }
  503.         
  504.         $entityManager $this->getDoctrine()->getManager();
  505.         $entity->setIsClosed(false);
  506.         
  507.         try {
  508.             $entityManager->flush();
  509.             //$this->addFlash('success', "Paiement supprimé");
  510.             return $this->json(['code' => 200'message' => "Caisse ré-ouverte :)"], 200);
  511.         } catch (\Throwable $th) {
  512.             $this->addFlash('warning'$th->getMessage());
  513.             return $this->json(['code' => 500'message' => "Une erreur s'est produite !)"], 200);
  514.         }
  515.         return $this->json(['code' => 500'message' => "Caisse non clôturé"], 200);
  516.     }
  517.     /**
  518.      * @Route("/re-print-all/{id}", name="treasury_cash_register_re_print", methods={"GET"})
  519.     */
  520.     public function rePrint(Pdf $knpSnappyPdfSettingClassroom $settingClassroomAccountingStudentRegistrationPaymentRepository $accountingStudentRegistrationPaymentRepositoryUserRepository $userRepository)
  521.     {
  522.         $accountingStudentRegistrations $accountingStudentRegistrationPaymentRepository->createQueryBuilder('entity')
  523.         ->innerJoin('entity.studentRegistration''studentRegistration')
  524.         ->addSelect('studentRegistration')
  525.         ->andWhere('studentRegistration.classroom = :classroom')
  526.         ->setParameter('classroom'$settingClassroom)
  527.         ->getQuery()
  528.         ->getResult();
  529.         $setting $this->getUser()->getEstablishment();
  530.         $html $this->renderView('treasury/treasury_cash_register/print/payments.html.twig', [
  531.             'accounting_student_registration_payments' => $accountingStudentRegistrations,
  532.             'userRepository' => $userRepository,
  533.             'setting' => $this->getUser()->getEstablishment(),
  534.         ]);
  535.         $file_name "RECUS_".date('dmY_Hi_').".pdf";
  536.         $footer $this->renderView('print/footer.html.twig', ['setting' => $setting]);
  537.         $header $this->renderView('print/header.html.twig', ['setting' => $setting]);
  538.         
  539.         $options = [
  540.             'orientation' => 'Portrait',
  541.             'header-html' => $header
  542.             //'footer-html' => $footer
  543.         ];
  544.         return new PdfResponse(
  545.             $knpSnappyPdf->getOutputFromHtml($html$options),
  546.             $file_name,
  547.             'application/pdf',
  548.             'attachment'
  549.         );
  550.     }
  551. }