src/Controller/Accounting/AccountingStudentRegistrationFeeShedulController.php line 118

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Accounting;
  3. use DateTimeImmutable;
  4. use App\Entity\LogOperation;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use App\Entity\AccountingStudentRegistrationFeeShedul;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use App\Repository\AccountingStudentRegistrationFeeShedulRepository;
  12. /**
  13.  * @Route("/accounting/student-registration-fee-shedul")
  14.  */
  15. class AccountingStudentRegistrationFeeShedulController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/delete-selection", name="accounting_student_registration_fee_sheduls_selected_delete", methods={"GET"})
  19.     */
  20.     public function deleteSelected(Request $requestAccountingStudentRegistrationFeeShedulRepository $entityRepository): Response
  21.     {
  22.         $list $request->get('entities');
  23.         $entityManager $this->getDoctrine()->getManager();
  24.         $errors 0;
  25.         foreach ($list as $key => $id) {
  26.             $entity $entityRepository->findOneBy(['id' => intval($id)], []);
  27.             if ($entity != null) {
  28.                 if (count($entity->getAccountingStudentRegistrationFeeShedulPayments()) <= 0) {
  29.                     $entityManager->remove($entity);
  30.                 }
  31.             }
  32.         }
  33.         try {
  34.             $entityManager->flush();
  35.             $this->addFlash('success'"Traitement effectué");
  36.             return $this->json(['code' => 200'message' => "Traitement effectué :)"], 200);
  37.         } catch (\Throwable $th) {
  38.             //$th->getMessage()
  39.             $this->addFlash('warning'$th->getMessage());
  40.         }
  41.         
  42.         $this->addFlash('warning'"Traitement non effectué");
  43.         return $this->json(['code' => 500'message' => "Traitement non effectué"], 200);
  44.     }
  45.     /**
  46.      * @Route("/delete/{id}", name="accounting_student_registration_fee_shedul_delete", methods={"GET"})
  47.     */
  48.     public function delete(AccountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedul): Response
  49.     {
  50.         if ($accountingStudentRegistrationFeeShedul->getAmountPaid() > 0) {
  51.             return $this->json(['code' => 500'message' => "Impossible de supprimer cet échéancier. Des paiement ont été effectués dessus."], 200);
  52.         }
  53.         $entityManager $this->getDoctrine()->getManager();
  54.         $entityManager->remove($accountingStudentRegistrationFeeShedul);
  55.         try {
  56.             $entityManager->flush();
  57.             return $this->json(['code' => 200'message' => "Suppression effectuée :)"], 200);
  58.         } catch (\Throwable $th) {
  59.             //$th->getMessage()
  60.             $this->addFlash('warning'$th->getMessage());
  61.         }
  62.         return $this->json(['code' => 500'message' => "Suppression non effectuée"], 200);
  63.     }
  64.     /**
  65.      * @Route("/cancel/{id}", name="accounting_student_registration_fee_shedul_cancel", methods={"GET"})
  66.     */
  67.     public function cancel(Request $requestAccountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedul): Response
  68.     {
  69.         if ($accountingStudentRegistrationFeeShedul->getAmountCancel() > 0) {
  70.             $this->addFlash('warning'"Impossible, une remise à déjà été effectuée sur cet échéancier.");
  71.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getStudentRegistration()->getId()]);
  72.         }
  73.         $amount $request->get('shedulAmount');
  74.         if ($amount <= 0) {
  75.             $this->addFlash('warning'"Impossible, le montant de la remise doit être supérieur à zéro");
  76.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getStudentRegistration()->getId()]);
  77.         }
  78.         if ($accountingStudentRegistrationFeeShedul->getAmountRest() <= 0) {
  79.             $this->addFlash('warning'"Impossible, le reste à payer doit être supérieur à zéro(0)");
  80.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getStudentRegistration()->getId()]);
  81.         }
  82.         if ($accountingStudentRegistrationFeeShedul->getAmountRest() < $amount) {
  83.             $this->addFlash('warning'"Impossible, le montant de la remise doit être inférieur ou égale au reste à payer");
  84.             return $this->redirectToRoute('registration_student_registration_show', ['id' => $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getStudentRegistration()->getId()]);
  85.         }
  86.         
  87.         $entityManager $this->getDoctrine()->getManager();
  88.         $accountingStudentRegistrationFeeShedul->setAmountCancel($amount);
  89.         //$accountingStudentRegistrationFeeShedul->setIsCancel(true);
  90.         try {
  91.             $entityManager->flush();
  92.             $this->addFlash('success'"Remise effectué :)");
  93.         } catch (\Throwable $th) {
  94.             $this->addFlash('warning'$th->getMessage());
  95.         }
  96.         
  97.         return $this->redirectToRoute('registration_student_registration_show', ['id' => $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getStudentRegistration()->getId()]);
  98.     }
  99.     /**
  100.      * 
  101.      * @Route("/api/shedul-update-date-due/{id}", name="api_accounting_student_registration_fee_shedul_update_date_due", methods={"GET"})
  102.     */
  103.     public function api_fee_shedul_update_date_due(Request $requestAccountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedulEntityManagerInterface $entityManager): Response
  104.     {
  105.         if ($request->get('date_due') == '' or $request->get('date_due') == null) {
  106.             return $this->json(['code' => 500'message' => "Impossible: Veuillez selectionner une date SVP."], 200);
  107.         }
  108.         if ($request->get('date_due') <= date('Y-m-d')) {
  109.             return $this->json(['code' => 500'message' => "Impossible: Veuillez selectionner une date superieur à la date du jour SVP."], 200);
  110.         }
  111.         try {
  112.             $date_due = new DateTimeImmutable($request->get('date_due'));
  113.         } catch (\Throwable $th) {
  114.             return $this->json(['code' => 500'message' => $th->getMessage()], 200);
  115.         }
  116.         try {
  117.             $logOperation = new LogOperation(
  118.                 $request->getClientIp(), 
  119.                 $accountingStudentRegistrationFeeShedul->getId(), 
  120.                 AccountingStudentRegistrationFeeShedul::class, 
  121.                 "Modification échéance : <strong>".$accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getFee()->getLabel()."( ".$accountingStudentRegistrationFeeShedul->getDateDue()->format('d/m/Y').": ".number_format($accountingStudentRegistrationFeeShedul->getAmount(), 0','' ')." XOF)".", élève : " $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getStudentRegistration()->getName() . ", Nouvelle date: "$date_due->format('d/m/Y') . " </strong>"
  122.                 $this->getUser()->getUserIdentifier(), 
  123.             "danger");
  124.             $logOperation->setEstablishment($accountingStudentRegistrationFeeShedul->getEstablishment());
  125.             $entityManager->persist($logOperation);
  126.             $accountingStudentRegistrationFeeShedul->setDateDue($date_due);
  127.         } catch (\Throwable $th) {
  128.             return $this->json(['code' => 500'message' => "Impossible: Veuillez selectionner une date valide SVP."], 200);
  129.         }
  130.         
  131.         try {
  132.             $entityManager->flush();
  133.             return $this->json(['code' => 200'message' => "Modification effectuée :)"], 200);
  134.         } catch (\Throwable $th) {
  135.             //$th->getMessage()
  136.             return $this->json(['code' => 500'message' => $th->getMessage()], 200);
  137.             $this->addFlash('warning'$th->getMessage());
  138.         }
  139.         return $this->json(['code' => 500'message' => "Une erreur s'est produite!"], 200);
  140.     }
  141.     /**
  142.      * @Route("/{id}/re-shedul", name="accounting_student_registration_fee_shedul_re_shedul", methods={"GET","POST"})
  143.      */
  144.     public function re_shedul(Request $requestAccountingStudentRegistrationFeeShedul $accountingStudentRegistrationFeeShedulAccountingStudentRegistrationFeeShedulRepository $accountingStudentRegistrationFeeShedulRepository): Response
  145.     {
  146.         /* Ajout des echeancies */
  147.         $accountingStudentRegistrationFee $accountingStudentRegistrationFeeShedul->getStudentRegistrationFee();
  148.         $fee_shedul_amount $request->get('fee_shedul_amount');
  149.         $fee_shedul_date $request->get('fee_shedul_date');
  150.         if ($fee_shedul_amount <= 0) {
  151.             $this->addFlash('warning'"Montant invalide.");
  152.             return $this->redirectToRoute('accounting_student_registration_fee_edit', ['id' => $accountingStudentRegistrationFee->getId()]);
  153.         }
  154.         if ($fee_shedul_amount >= $accountingStudentRegistrationFeeShedul->getAmount()) {
  155.             $this->addFlash('warning'"Montant trop élevé.");
  156.             return $this->redirectToRoute('accounting_student_registration_fee_edit', ['id' => $accountingStudentRegistrationFee->getId()]);
  157.         }
  158.         if ($fee_shedul_date <= date('Y-m-d')) {
  159.             $this->addFlash('warning'"Date invalide.");
  160.             return $this->redirectToRoute('accounting_student_registration_fee_edit', ['id' => $accountingStudentRegistrationFee->getId()]);
  161.         }
  162.         $newAccountingStudentRegistrationFeeShedul = new AccountingStudentRegistrationFeeShedul();
  163.         $newAccountingStudentRegistrationFeeShedul->setOrderNum(count($accountingStudentRegistrationFeeShedul->getStudentRegistrationFee()->getAccountingStudentRegistrationFeeSheduls()) + 1);
  164.         $newAccountingStudentRegistrationFeeShedul->setEstablishment($accountingStudentRegistrationFee->getEstablishment());
  165.         $newAccountingStudentRegistrationFeeShedul->setStudentRegistrationFee($accountingStudentRegistrationFee);
  166.         $newAccountingStudentRegistrationFeeShedul->setAmount($fee_shedul_amount);
  167.         $newAccountingStudentRegistrationFeeShedul->setAmountPaid(0);
  168.         $newAccountingStudentRegistrationFeeShedul->setAmountCancel(0);
  169.         $newAccountingStudentRegistrationFeeShedul->setAmountReported(0);
  170.         $newAccountingStudentRegistrationFeeShedul->setLastAmountPaid(0);
  171.         $newAccountingStudentRegistrationFeeShedul->setDateDue(new DateTimeImmutable($fee_shedul_date));
  172.         $entityManager $this->getDoctrine()->getManager();
  173.         $entityManager->persist($newAccountingStudentRegistrationFeeShedul);
  174.         $accountingStudentRegistrationFeeShedul->setAmount($accountingStudentRegistrationFeeShedul->getAmount() - $fee_shedul_amount);
  175.         
  176.         try {
  177.             $entityManager->flush();
  178.             $this->addFlash('success'"un écheancier à été ajouté.");
  179.         } catch (\Throwable $th) {
  180.             $this->addFlash('warning'"Une erreur est survenue lors de l'ajout de l'échéancier.");
  181.             $this->addFlash('info'$th->getMessage());
  182.         }
  183.         return $this->redirectToRoute('accounting_student_registration_fee_edit', ['id' => $accountingStudentRegistrationFee->getId()]);
  184.     }
  185. }