src/Controller/Paie/BulletinController.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Paie;
  3. use App\Entity\PMessengerStatut;
  4. use App\Entity\Users;
  5. use App\Message\GenerateFileMessage;
  6. use App\Message\PaieMessage;
  7. use Mpdf\Mpdf;
  8. use App\Entity\PPiece;
  9. use App\Entity\PDevise;
  10. use App\Entity\Periode;
  11. use App\Entity\PStatut;
  12. use App\Entity\VMatrix;
  13. use App\Entity\PDossier;
  14. use App\Entity\Pemploye;
  15. use App\Entity\Probleme;
  16. use App\Entity\LContract;
  17. use App\Entity\PPaiement;
  18. use App\Entity\Prubrique;
  19. use App\Entity\Tbulletin;
  20. use App\Entity\PBordereau;
  21. use App\Entity\PBaremeCimr;
  22. use App\Entity\TbulletinLg;
  23. use App\Entity\LelementFixe;
  24. use App\Entity\PbaremeBrute;
  25. use App\Entity\PPrelevementLg;
  26. use App\Entity\PArretTravailLg;
  27. use App\Entity\HonoraireDetFixe;
  28. use App\Entity\LElementEcheance;
  29. use App\Controller\ApiController;
  30. use App\Service\CalculPaieService;
  31. use Doctrine\Persistence\ManagerRegistry;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\HttpFoundation\Response;
  34. use Symfony\Component\Messenger\MessageBusInterface;
  35. use Symfony\Component\Routing\Annotation\Route;
  36. use Symfony\Component\HttpFoundation\JsonResponse;
  37. use Symfony\Component\Finder\Exception\AccessDeniedException;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. #[Route('/paie/bulletin')]
  40. class BulletinController extends AbstractController
  41. {
  42.     private $em;
  43.     private $calculPaieService;
  44.     private $api;
  45.     private $bus;
  46.     public function __construct(ManagerRegistry $doctrineCalculPaieService $calculPaieServiceApiController $api,MessageBusInterface  $bus)
  47.     {
  48.         $this->em $doctrine->getManager();
  49.         $this->api $api;
  50.         $this->calculPaieService $calculPaieService;
  51.         $this->bus $bus;
  52.     }
  53.     #[Route('/'name'app_paie_bulletin')]
  54.     public function index(Request $request): Response
  55.     {
  56.         $operations $this->api->check($this->getUser(), 'app_paie_bulletin'$this->em$request);
  57.         if (!is_array($operations)) {
  58.             return $this->redirectToRoute('app_site');
  59.         } elseif (count($operations) == 0) {
  60.             return $this->render('includes/404.html.twig');
  61.         }
  62.         return $this->render('paie/bulletin/index.html.twig', [
  63.             'operations' => $operations,
  64.         ]);
  65.     }
  66.     #[Route('/app_bulletin_employe_list/{periode}'name'app_bulletin_employe_list'options: ['expose' => true])]
  67.     public function app_bulletin_employe_list(Request $request$periode): Response
  68.     {
  69.         $date = new \DateTime($periode);
  70.         $periode $this->calculPaieService->getPeriode($date->format('mY'));
  71.         $draw $request->query->get('draw');
  72.         $start $request->query->get('start') ?? 0;
  73.         $length $request->query->get('length') ?? 10;
  74.         $search $request->query->all('search')["value"];
  75.         $orderColumnIndex $request->query->all('order')[0]['column'];
  76.         $orderColumn $request->query->all("columns")[$orderColumnIndex]['name'];
  77.         $orderDir $request->query->all('order')[0]['dir'] ?? 'asc';
  78.         $dossier $request->getSession()->get('dossier');
  79.         $queryBuilder $this->em->createQueryBuilder()
  80.             ->select('b.code as bulletin, b.id as bulletin_id, contract.id as id, contract.code as contract_code, p.nom as nom, p.matricule as matricule , p.prenom')
  81.             ->from(LContract::class, 'contract')
  82.             ->innerJoin('contract.employe''p')
  83.             ->innerJoin('contract.bulletins''b')
  84.             ->innerJoin('b.piece''piece')
  85.             // ->Where('contract.active = 1')
  86.             ->Where('b.dossier = :dossier')
  87.             ->andWhere('b.dossier = :dossier')
  88.             ->andWhere('b.periode = :periode')
  89.             ->andWhere('piece.id = 1')
  90.             ->andWhere('b.active = 1')
  91.             ->setParameter('dossier'$dossier)
  92.             ->setParameter('periode'$periode);
  93.         if (!empty($search)) {
  94.             $queryBuilder->andWhere('(contract.code LIKE :search OR b.code LIKE :search OR p.matricule LIKE :search OR  p.nom LIKE :search OR p.prenom LIKE :search)')
  95.                 ->setParameter('search'"%$search%");
  96.         }
  97.         if (!empty($orderColumn)) {
  98.             $queryBuilder->orderBy("$orderColumn"$orderDir);
  99.         }
  100.         $filteredRecords count($queryBuilder->getQuery()->getResult());
  101.         // Paginate results
  102.         $queryBuilder->setFirstResult($start)
  103.             ->setMaxResults($length);
  104.         $results $queryBuilder->getQuery()->getResult();
  105.         // dd($results);
  106.         foreach ($results as $key => $contract) {
  107.             // dd('amine');
  108.             // if($contract['id'] == 1301) {
  109.             //     dd($this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($contract['id'], $periode));
  110.             // }
  111.             $results[$key]['DT_RowId'] = $contract['id'];
  112.             $results[$key]['nombreJourTravails'] = 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($contract['id'], $periode);
  113.             $montant $this->em->getRepository(Tbulletin::class)->getNetAPaye($contract['bulletin_id']);
  114.             $results[$key]['salaire'] = '<p style="text-align: right !important; margin:0 !important">' number_format($montant2','' ') . '</p>';;
  115.             $results[$key]['problemes'] = $this->em->getRepository(Probleme::class)->checkIfTheresProblemes($periode$contract['id']);
  116.         }
  117.         // dd($results);
  118.         $totalRecords $this->em->createQueryBuilder()
  119.             ->select('COUNT(d.id)')
  120.             ->from(LContract::class, 'd')
  121.             ->innerJoin('d.bulletins''bulletins')
  122.             ->innerJoin('bulletins.piece''piece')
  123.             ->Where('bulletins.dossier = :dossier')
  124.             ->andWhere('bulletins.active = 1')
  125.             ->andWhere('piece.id = 1')
  126.             ->andWhere('bulletins.periode = :periode')
  127.             ->setParameter('dossier'$dossier)
  128.             ->setParameter('periode'$periode)
  129.             ->getQuery()
  130.             ->getSingleScalarResult();
  131.         return new JsonResponse([
  132.             'draw' => $draw,
  133.             'recordsTotal' => $totalRecords,
  134.             'recordsFiltered' => $filteredRecords,
  135.             'data' => $results,
  136.         ]);
  137.     }
  138.     #[Route('/app_bulletin_employe_calcul'name'app_bulletin_employe_calcul'options: ['expose' => true])]
  139.     public function app_bulletin_employe_calcul(Request $request): Response
  140.     {
  141.         // dd($request);
  142.         $dossier $request->getSession()->get('dossier');
  143.         $dossier $this->em->getRepository(PDossier::class)->find($dossier);
  144.         // dd($dossier);
  145.         $periode $this->calculPaieService->getPeriode();
  146.         if($periode->IsValider()) {
  147.             return new JsonResponse('Periode est valider !'500, [], JSON_UNESCAPED_UNICODE);
  148.         }
  149.         $bordoreauIds = [];
  150.         // dd(count($dossier->getActiveContracts()));
  151.         foreach ($dossier->getActiveContracts() as $contract) {
  152.             // dump($contract->getBareme()->getBaremeType()->getId());
  153.             if (!$contract->getBareme()) {
  154.                 continue;
  155.             }
  156.             $natureContract $contract->getPnatureContract();
  157.             if ($contract->getBareme()->getBaremeType()->getId() == 1) { // standard
  158.                 if ($contract->getDateAnciennete() == null) {
  159.                     return new JsonResponse('Date anciennete introuvable !'500, [], JSON_UNESCAPED_UNICODE);
  160.                 }
  161.                 $piece $this->em->getRepository(PPiece::class)->find(4); // paie
  162.                 // get nature contract 
  163.                 $bordoreau $this->em->getRepository(PBordereau::class)->findOneBy(['dossier' => $dossier'active' => true'periode' => $periode'piece' => $piece'natureContract' => $natureContract]);
  164.                 if (!$bordoreau) {
  165.                     $bordoreau = new PBordereau;
  166.                     $bordoreau->setPiece($piece);
  167.                     $bordoreau->setPeriode($periode);
  168.                     $bordoreau->setNatureContract($natureContract);
  169.                     $bordoreau->setDossier($dossier);
  170.                     $bordoreau->setType('paie');
  171.                     $bordoreau->setPaiement(
  172.                         $this->em->getRepository(PPaiement::class)->find(1)
  173.                     );
  174.                     $bordoreau->setStatut(
  175.                         $this->em->getRepository(PStatut::class)->find(1)
  176.                     );
  177.                     $bordoreau->setDevise(
  178.                         $this->em->getRepository(PDevise::class)->find(1)
  179.                     );
  180.                     $bordoreau->setUserCreated($this->getUser());
  181.                     $this->em->persist($bordoreau);
  182.                     $this->em->flush();// flush because the next contract will search for the same bordreau if i dont flush he will not find it
  183.                 } else {
  184.                     $bordoreau->setStatut($this->em->getRepository(PStatut::class)->find(1));
  185.                 }
  186.                 if (in_array($bordoreau->getStatut()->getId(), [34])) { // valider , integrer
  187.                     return new JsonResponse('Vous ne pouvez pas modifier un bordereau déja ' $bordoreau->getStatut()->getDesignation() . ' !'500);
  188.                 }
  189.                 // dd($natureContract->getType());
  190.                 $this->generateBulletin($bordoreau$dossier$contract$periode);
  191.                 array_push($bordoreauIds$bordoreau->getId());
  192.             } elseif ($contract->getBareme()->getBaremeType()->getId() == 2) { // detail
  193.                 $honoraireDetFixe $this->em->getRepository(HonoraireDetFixe::class)->findOneBy(['contract' => $contract'active' => true]);
  194.                 if (!$honoraireDetFixe) {
  195.                     continue;
  196.                 }
  197.                 $piece $this->em->getRepository(PPiece::class)->find(5);
  198.                 $devise $this->em->getRepository(PDevise::class)->find(1);
  199.                 $paiement $this->em->getRepository(PPaiement::class)->find(1);
  200.                 $bordoreau $this->em->getRepository(PBordereau::class)->findOneBy([
  201.                     'dossier' => $dossier
  202.                     'active' => true
  203.                     'periode' => $periode
  204.                     'piece' => $piece
  205.                     'devise' => $devise,
  206.                     'natureContract' => $natureContract,
  207.                     'paiement' => $paiement,
  208.                     'observation' => 'Honoraire det fixe (' $periode->getCode() . ')'
  209.                 ]);
  210.                 if (!$bordoreau) {
  211.                     $bordoreau = new PBordereau;
  212.                     $bordoreau->setPiece($this->em->getRepository(PPiece::class)->find(5));
  213.                     $bordoreau->setStatut(
  214.                         $this->em->getRepository(PStatut::class)->find(1)
  215.                     );
  216.                     $bordoreau->setPeriode($periode);
  217.                     $bordoreau->setType('honoraire');
  218.                     $bordoreau->setPaiement($paiement);
  219.                     $bordoreau->setNatureContract($natureContract);
  220.                     $bordoreau->setUserCreated($this->getUser());
  221.                     $bordoreau->setDossier($dossier);
  222.                     $bordoreau->setDevise($devise);
  223.                     $bordoreau->setObservation('Honoraire det fixe (' $periode->getCode() . ')');
  224.                     $this->em->persist($bordoreau);
  225.                     $this->em->flush();// flush because the next contract will search for the same bordreau if i dont flush he will not find it
  226.                 } else {
  227.                     $bordoreau->setStatut($this->em->getRepository(PStatut::class)->find(1));
  228.                 }
  229.                 if (in_array($bordoreau->getStatut()->getId(), [34])) { // valider , integrer
  230.                     return new JsonResponse('Vous ne pouvez pas modifier un bordereau déja ' $bordoreau->getStatut()->getDesignation() . ' !'500);
  231.                 }
  232.                 $this->generateBulletinHonoraire($bordoreau$dossier$contract$periode$honoraireDetFixe);
  233.                 $bordoreauIds[] = $bordoreau->getId();
  234.             }
  235.             $this->em->flush();
  236.         }
  237.         $bordoreauIds array_unique($bordoreauIds);
  238.         if (count($bordoreauIds) > 0) {
  239.             $request->request->add(['bordoreauIds' => json_encode($bordoreauIds)]);
  240.         }
  241.         return new JsonResponse('Bien enregistrer !'200);
  242.     }
  243.     #[Route('/get_dossiers'name'get_dossiers'options: ['expose' => true])]
  244.     public function get_dossiers(): JsonResponse
  245.     {
  246.         $dossiers $this->em->getRepository(PDossier::class)->findBy(['active' => true]);
  247.         $array = [];
  248.         foreach ($dossiers as $key => $dossier) {
  249.             $array[] = $dossier->getId();
  250.         }
  251.         return new JsonResponse($array);
  252.     }
  253.     #[Route('/app_bulletin_employe_calcul_all/{dossier}'name'app_bulletin_employe_calcul_all'options: ['expose' => true])]
  254.     public function app_bulletin_employe_calcul_all(PDossier $dossierRequest $request): Response
  255.     {
  256.         // dd($request);
  257.         // $dossier = $request->getSession()->get('dossier');
  258.         // $dossier = $this->em->getRepository(PDossier::class)->find($dossier);
  259.         $periode $this->calculPaieService->getPeriode();
  260.         if($periode->IsValider()) {
  261.             return new JsonResponse('Periode est valider !'500, [], JSON_UNESCAPED_UNICODE);
  262.         }
  263.         $bordoreauIds = [];
  264.         foreach ($dossier->getActiveContracts() as $contract) {
  265.             if (!$contract->getBareme()) {
  266.                 continue;
  267.             }
  268.             $natureContract $contract->getPnatureContract();
  269.             if ($contract->getBareme()->getBaremeType()->getId() == 1) { // standard
  270.                 if ($contract->getDateAnciennete() == null) {
  271.                     return new JsonResponse('Date anciennete introuvable !'500, [], JSON_UNESCAPED_UNICODE);
  272.                 }
  273.                 $piece $this->em->getRepository(PPiece::class)->find(4); // paie
  274.                 $bordoreau $this->em->getRepository(PBordereau::class)->findOneBy(['dossier' => $dossier'periode' => $periode'active' => true'piece' => $piece'natureContract' => $natureContract]);
  275.                 if (!$bordoreau) {
  276.                     $bordoreau = new PBordereau;
  277.                     $bordoreau->setPiece($piece);
  278.                     $bordoreau->setPeriode($periode);
  279.                     $bordoreau->setNatureContract($natureContract);
  280.                     $bordoreau->setDossier($dossier);
  281.                     // if($natureContract->getType() == "stagiaires") {
  282.                     //     $bordoreau->setType('honoraire');
  283.                     // } else {
  284.                     $bordoreau->setType('paie');
  285.                     // }
  286.                     $bordoreau->setPaiement(
  287.                         $this->em->getRepository(PPaiement::class)->find(1)
  288.                     );
  289.                     $bordoreau->setStatut(
  290.                         $this->em->getRepository(PStatut::class)->find(1)
  291.                     );
  292.                     $bordoreau->setDevise(
  293.                         $this->em->getRepository(PDevise::class)->find(1)
  294.                     );
  295.                     $bordoreau->setUserCreated($this->getUser());
  296.                     $this->em->persist($bordoreau);
  297.                     $this->em->flush(); // flush because the next contract will search for the same bordreau if i dont flush he will not find it
  298.                 } else {
  299.                     $bordoreau->setStatut($this->em->getRepository(PStatut::class)->find(1));
  300.                 }
  301.                 if (in_array($bordoreau->getStatut()->getId(), [34])) { // valider , integrer
  302.                     return new JsonResponse('Vous ne pouvez pas modifier un bordereau déja ' $bordoreau->getStatut()->getDesignation() . ' !'500);
  303.                 }
  304.                 $this->generateBulletin($bordoreau$dossier$contract$periode);
  305.                 array_push($bordoreauIds$bordoreau->getId());
  306.             } elseif ($contract->getBareme()->getBaremeType()->getId() == 2) { // detail
  307.                 $honoraireDetFixe $this->em->getRepository(HonoraireDetFixe::class)->findOneBy(['contract' => $contract'active' => true]);
  308.                 $piece $this->em->getRepository(PPiece::class)->find(5);
  309.                 if (!$honoraireDetFixe) {
  310.                     continue;
  311.                 }
  312.                 $devise $this->em->getRepository(PDevise::class)->find(1);
  313.                 $paiement $this->em->getRepository(PPaiement::class)->find(1);
  314.                 $bordoreau $this->em->getRepository(PBordereau::class)->findOneBy([
  315.                     'dossier' => $dossier
  316.                     'active' => true
  317.                     'periode' => $periode
  318.                     'piece' => $piece
  319.                     'devise' => $devise,
  320.                     'natureContract' => $natureContract,
  321.                     'paiement' => $paiement,
  322.                     'observation' => 'Honoraire det fixe (' $periode->getCode() . ')'
  323.                 ]);
  324.                 if (!$bordoreau) {
  325.                     $bordoreau = new PBordereau;
  326.                     $bordoreau->setPiece($piece);
  327.                     $bordoreau->setStatut($this->em->getRepository(PStatut::class)->find(1));
  328.                     $bordoreau->setPeriode($periode);
  329.                     $bordoreau->setType('honoraire');
  330.                     $bordoreau->setPaiement($paiement);
  331.                     $bordoreau->setDevise($devise);
  332.                     $bordoreau->setNatureContract($natureContract);
  333.                     $bordoreau->setUserCreated($this->getUser());
  334.                     $bordoreau->setDossier($dossier);
  335.                     $bordoreau->setObservation('Honoraire det fixe (' $periode->getCode() . ')');
  336.                     $this->em->persist($bordoreau);
  337.                     $this->em->flush();// flush because the next contract will search for the same bordreau if i dont flush he will not find it
  338.                 } else {
  339.                     $bordoreau->setStatut($this->em->getRepository(PStatut::class)->find(1));
  340.                 }
  341.                 if (in_array($bordoreau->getStatut()->getId(), [34])) { // valider , integrer
  342.                     return new JsonResponse('Vous ne pouvez pas modifier un bordereau déja ' $bordoreau->getStatut()->getDesignation() . ' !'500);
  343.                 }
  344.                 $this->generateBulletinHonoraire($bordoreau$dossier$contract$periode$honoraireDetFixe);
  345.                 array_push($bordoreauIds$bordoreau->getId());
  346.             }
  347.             $this->em->flush();
  348.         }
  349.         $bordoreauIds array_unique($bordoreauIds);
  350.         if (count($bordoreauIds) > 0) {
  351.             $request->request->add(['bordoreauIds' => json_encode($bordoreauIds)]);
  352.         }
  353.         return new JsonResponse('Bien enregistrer !'200);
  354.     }
  355.     #[Route('/app_bulletin_employe_problemes/{contract}'name'app_bulletin_employe_problemes'options: ['expose' => true])]
  356.     public function app_bulletin_employe_problemes(LContract $contract): Response
  357.     {
  358.         // dd($request);
  359.         $periode $this->calculPaieService->getPeriode();
  360.         $problemes $this->em->getRepository(Probleme::class)->findBy(['periode' => $periode'contract' => $contract'resoudre' => false]);
  361.         $html $this->renderView('paie/bulletin/includes/probleme.html.twig', ['problemes' => $problemes'contract' => $contract]);
  362.         return new JsonResponse($html);
  363.     }
  364.     #[Route('/app_bulletin_employe_probleme_solves'name'app_bulletin_employe_probleme_solves'options: ['expose' => true])]
  365.     public function app_bulletin_employe_probleme_solves(Request $request): Response
  366.     {
  367.         $problemes json_decode($request->get('problemes'));
  368.         foreach ($problemes as $key => $probleme) {
  369.             $date = new \DateTime($probleme->periode);
  370.             $probleme $this->em->getRepository(Probleme::class)->find($probleme->id);
  371.             $periode $this->calculPaieService->getPeriode($date->format('mY'));
  372.             if ($probleme->getPrelevementLg()) {
  373.                 $prelevementLg = new PPrelevementLg();
  374.                 $prelevementLg->setPrelevement($probleme->getPrelevementLg()->getPrelevement());
  375.                 $prelevementLg->setMontant($probleme->getPrelevementLg()->getMontant());
  376.                 $prelevementLg->setPeriode($periode);
  377.                 $this->em->persist($prelevementLg);
  378.                 $probleme->getPrelevementLg()->setActive(false);
  379.             } else if ($probleme->getElementEcheance()) {
  380.                 $elementEcheance = new LElementEcheance();
  381.                 $elementEcheance->setContract($probleme->getElementEcheance()->getContract());
  382.                 $elementEcheance->setPeriode($periode);
  383.                 $elementEcheance->setRubrique($probleme->getElementEcheance()->getRubrique());
  384.                 $elementEcheance->setDateEcheance($date);
  385.                 $elementEcheance->setCreated(new \DateTime('now'));
  386.                 $elementEcheance->setSens($probleme->getElementEcheance()->getSens());
  387.                 $elementEcheance->setMontant($probleme->getElementEcheance()->getMontant());
  388.                 $elementEcheance->setMontant($probleme->getElementEcheance()->getMontant());
  389.                 $this->em->persist($elementEcheance);
  390.                 $probleme->getElementEcheance()->setActive(false);
  391.             }
  392.             $probleme->setResoudre(true);
  393.         }
  394.         $this->em->flush();
  395.         return new JsonResponse("Bien Enregistrer");
  396.     }
  397.     #[Route('/app_bulletin_employe_bulletin_details/{code}'name'app_bulletin_employe_bulletin_details'options: ['expose' => true])]
  398.     public function app_bulletin_employe_bulletin_details($code): Response
  399.     {
  400.         // dd($request);
  401.         $bulletin $this->em->getRepository(Tbulletin::class)->findOneBy(['code' => $code]);
  402.         $html $this->renderView('paie/bulletin/includes/bulletin_details.html.twig', ['bulletin' => $bulletin'bulletinLgs' => $bulletin->getActiveBulletinLgs()]);
  403.         return new JsonResponse($html);
  404.     }
  405.     #[Route('/app_bulletin_employe_disable'name'app_bulletin_employe_disable'options: ['expose' => true])]
  406.     public function app_bulletin_employe_disable(Request $request)
  407.     {
  408.         // dd($request);
  409.         $motif $request->get('motif');
  410.         $bulletinIds json_decode($request->get('bulletinIds'));
  411.         foreach ($bulletinIds as $key => $bulletinId) {
  412.             $bulletin $this->em->getRepository(Tbulletin::class)->find($bulletinId);
  413.             if (in_array($bulletin->getBordereau()->getStatut()->getId(), [34])) { // valider , integrer
  414.                 return new JsonResponse('Vous ne pouvez pas supprimer. bordereau déja ' $bulletin->getBordereau()->getStatut()->getDesignation() . ' !'500);
  415.             }
  416.             $bulletin->setMotifAnnulation($motif);
  417.             $bulletin->setUserAnnulation($this->getUser());
  418.             $bulletin->setActive(false);
  419.             foreach ($bulletin->getBulletinLgs() as $key => $bulletinLg) {
  420.                 $bulletinLg->setActive(false);
  421.             }
  422.             foreach ($bulletin->getJournalBulletinLgs() as $key => $JournalBulletinLg) {
  423.                 $JournalBulletinLg->setActive(false);
  424.             }
  425.             if($bulletin->getBordereau()->getType() == 'stc') {
  426.                 $bulletin->getContract()->getEmploye()->setStc(false);
  427.             }
  428.         }
  429.         $this->em->flush();
  430.         return new JsonResponse("Bien Enregistrer");
  431.     }
  432.     #[Route('/print/{bulletin}'name'app_bulletin_employe_bulletin_print'options: ['expose' => true])]
  433.     public function app_bulletin_employe_bulletin_print(Tbulletin $bulletin): Response
  434.     {
  435.         // dd($bulletin->getContract()->getPnatureContract()->getType());
  436.         if ($bulletin->getContract()->getPnatureContract()->getType()->getId() == 1) {
  437.             $brute = [1246789101116606976,93,94];
  438.         } else {
  439.             $brute = [65];
  440.         }
  441.         $bulletinLgBrute $this->getPbulletinsLgQueryBuilder($brute$bulletin);
  442.         
  443.         // dd($bulletin->getContract()->getEmploye()->getPrenom());
  444.         $bulletinLgPrets =  $this->em->createQueryBuilder('b')
  445.             ->select('bulletinLgs')
  446.             ->from(TbulletinLg::class, 'bulletinLgs')
  447.             ->innerJoin('bulletinLgs.bulletin''b')
  448.             ->innerJoin('bulletinLgs.rubrique''rubrique')
  449.             ->innerJoin('b.bordereau''bordereau')
  450.             ->innerJoin('bordereau.devise''devise'// 5 is net a paye
  451.             ->andWhere('rubrique.prets = 1')
  452.             ->andWhere('b.id = :bulletin')
  453.             ->andWhere('bulletinLgs.active = 1')
  454.             ->andWhere('bulletinLgs.montant != 0')
  455.             ->setParameter('bulletin'$bulletin->getId())
  456.             ->getQuery()
  457.             ->getResult();
  458.         $bulletinLgCotisationsPS $this->getPbulletinsLgQueryBuilder([50475348], $bulletin);
  459.         // $bulletinLgCotisationsPS = $this->em->createQueryBuilder()
  460.         //     ->select('TbulletinLg')
  461.         //     ->from(TbulletinLg::class, 'TbulletinLg')
  462.         //     ->innerJoin('TbulletinLg.bulletin', 'bulletin')
  463.         //     ->innerJoin('TbulletinLg.rubrique', 'rubrique')
  464.         //     ->andWhere('rubrique.id in (50, 47, 53, 48)')
  465.         //     ->andWhere('TbulletinLg.active = 1')
  466.         //     ->andWhere('bulletin.id = :bulletin')
  467.         //     ->andWhere('TbulletinLg.montant != 0')
  468.         //     ->setParameter('bulletin', $bulletin)
  469.         //     ->getQuery()
  470.         //     ->getResult()
  471.         // ;
  472.         $bulletinLgIR $this->em->createQueryBuilder()
  473.             ->select('TbulletinLg')
  474.             ->from(TbulletinLg::class, 'TbulletinLg')
  475.             ->innerJoin('TbulletinLg.bulletin''bulletin')
  476.             ->innerJoin('TbulletinLg.rubrique''rubrique')
  477.             ->andWhere('rubrique.id = 43')
  478.             ->andWhere('TbulletinLg.active = 1')
  479.             ->andWhere('bulletin.id = :bulletin')
  480.             ->andWhere('TbulletinLg.montant != 0')
  481.             ->setParameter('bulletin'$bulletin)
  482.             ->getQuery()
  483.             ->getOneOrNullResult();
  484.         // dd($bulletinLgIR);
  485.         $montantNetPaye $this->em->createQueryBuilder()
  486.             ->select('sum(TbulletinLg.montant) as montant')
  487.             ->from(TbulletinLg::class, 'TbulletinLg')
  488.             ->innerJoin('TbulletinLg.bulletin''bulletin')
  489.             ->innerJoin('TbulletinLg.rubrique''rubrique')
  490.             ->andWhere('rubrique.id in(5,68)')
  491.             ->andWhere('TbulletinLg.active = 1')
  492.             ->andWhere('bulletin.id = :bulletin')
  493.             ->setParameter('bulletin'$bulletin)
  494.             ->getQuery()
  495.             ->getOneOrNullResult();
  496.         // dd($bulletinLgNetPaye);
  497.         $montantImposable $this->em->createQueryBuilder()
  498.             ->select('sum(TbulletinLg.montant) as montant')
  499.             ->from(TbulletinLg::class, 'TbulletinLg')
  500.             ->innerJoin('TbulletinLg.bulletin''bulletin')
  501.             ->innerJoin('TbulletinLg.rubrique''rubrique')
  502.             ->andWhere('rubrique.imposable = 1')
  503.             ->andWhere('TbulletinLg.active = 1')
  504.             ->andWhere('bulletin.id = :bulletin')
  505.             ->setParameter('bulletin'$bulletin)
  506.             ->getQuery()
  507.             ->getOneOrNullResult();
  508.         // dd($bulletinLgCotisationsPS);
  509.         $html $this->render("paie/bulletin/pdf/bulletin.html.twig", [
  510.             'bulletin' => $bulletin,
  511.             'bulletinLgPrets' => $bulletinLgPrets,
  512.             'bulletinLgCotisationsPS' => $bulletinLgCotisationsPS,
  513.             'bulletinLgBrute' => $bulletinLgBrute,
  514.             'bulletinLgIR' => $bulletinLgIR,
  515.             'montantNetPaye' => $montantNetPaye,
  516.             'montantImposable' => $montantImposable,
  517.         ])->getContent();
  518.         $mpdf = new Mpdf([
  519.             'mode' => 'c',
  520.             'margin_left' => '5',
  521.             'margin_right' => '5',
  522.         ]);
  523.         $mpdf->SetTitle('Bulletin');
  524.         $mpdf->WriteHTML($html);
  525.         $mpdf->Output($bulletin->getContract()->getEmploye()->getNom() . "_" $bulletin->getContract()->getEmploye()->getPrenom() . ".pdf""I");
  526.         die;
  527.     }
  528.     public function getPbulletinsLgQueryBuilder($rubrique$bulletin)
  529.     {
  530.         $bulletinLgs $this->em->createQueryBuilder()
  531.             ->select('TbulletinLg')
  532.             ->from(TbulletinLg::class, 'TbulletinLg')
  533.             ->innerJoin('TbulletinLg.bulletin''bulletin')
  534.             ->innerJoin('TbulletinLg.rubrique''rubrique')
  535.             ->andWhere('rubrique.id in (:rubrique)')
  536.             ->andWhere('TbulletinLg.active = 1')
  537.             ->andWhere('bulletin.id = :bulletin')
  538.             ->andWhere('TbulletinLg.montant != 0')
  539.             ->setParameter('bulletin'$bulletin)
  540.             ->setParameter('rubrique'$rubrique)
  541.             ->addOrderBy('rubrique.code''ASC')
  542.             ->getQuery()
  543.             ->getResult();
  544.         // $results = $bulletinLgs->getQuery()->getResult();
  545.         $montant 0;
  546.         $resultArray = [];
  547.         
  548.         foreach ($bulletinLgs as $key => $bulletinLg) {
  549.             /** @var TbulletinLg $bulletinLg */
  550.             // dd();
  551.             $base $taux 0;
  552.             switch ($bulletinLg->getRubrique()->getId()) {
  553.                 case 1:
  554.                     $base 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($bulletinLg->getBulletin()->getContract()->getId(), $bulletinLg->getBulletin()->getPeriode()->getId());
  555.                     $taux $this->em->getRepository(PbaremeBrute::class)->findOneBy(['bareme' => $bulletinLg->getBulletin()->getContract()->getBareme()->getId(), 'rubrique' => 1])->getTauxPs();
  556.                     $montant $bulletinLg->getMontant();
  557.                     break;
  558.                 case 2:
  559.                     $base $montant;
  560.                     $taux $this->em->getRepository(VMatrix::class)->getNombreAnneeAnciennte($bulletinLg->getBulletin()->getContract()->getDateAnciennete())->getTaux();
  561.                     break;
  562.                 case 48:
  563.                     // $taux = $this->em->getRepository(PBaremeCimr::class)->findOneBy(['rubrique' => $bulletinLg->getRubrique()->getId(), 'bareme' => $bulletinLg->getBulletin()->getContract()->getBareme()->getId()])->getTaux();
  564.                     $taux $bulletinLg->getBulletin()->getTauxCotisCimr();
  565.                 case 47:
  566.                 case 50:
  567.                 case 53:
  568.                     $taux $this->em->getRepository(VMatrix::class)->findOneBy(['rubrique' => $bulletinLg->getRubrique()->getId()])->getTaux();
  569.                     break;
  570.                 default:
  571.                     $base $bulletinLg->getMontant();
  572.                     $taux 1;
  573.                     break;
  574.             }
  575.             $resultArray[$key] = [
  576.                 'bulletinLg' => $bulletinLg,
  577.                 'base' => $base,
  578.                 'taux' => $taux,
  579.             ];
  580.         }
  581.         return $resultArray;
  582.     }
  583.     public function generateBulletin($bordoreau$dossier$contract$periode)
  584.     {
  585.         $nombreJourTravails 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($contract->getId(), $periode);
  586.         $natureContract $contract->getPnatureContract();;
  587.         if ($contract->getBareme()->getBaremeType()->getId() == 1) {
  588.             if ($natureContract->getType()->getId() == 1) {
  589.                 $this->calculPaieService->permanentPaie($contract$dossier$nombreJourTravails$periode$bordoreau);
  590.             } else if (in_array($natureContract->getType()->getId(), [26])) {
  591.                 $this->calculPaieService->vacatairePaie($contract$dossier$nombreJourTravails$periode$bordoreau);
  592.             } else if (in_array($natureContract->getType()->getId(), [457])) {
  593.                 $this->calculPaieService->stagairePaie($contract$dossier$nombreJourTravails$periode$bordoreau);
  594.             }
  595.         }
  596.     }
  597.     public function generateBulletinHonoraire($bordoreau$dossier$contract$periode$honoraireDetFixe)
  598.     {
  599.         $returnueIR $this->em->getRepository(Prubrique::class)->find(43);
  600.         $divers $this->em->getRepository(Prubrique::class)->find(68);
  601.         $honoraireRubrique $this->em->getRepository(Prubrique::class)->find(65);
  602.         $dossier $contract->getDossier();
  603.         $piece $this->em->getRepository(PPiece::class)->find(2);
  604.         $bulletin $this->em->getRepository(Tbulletin::class)->findOneBy(['contract' => $contract'bordereau' => $bordoreau'dossier' => $dossier'piece' => $piece'active' => true'periode' => $periode]);
  605.         if ($bulletin) {
  606.             foreach ($bulletin->getBulletinLgs() as $bulletinLg) {
  607.                 $bulletinLg->setActive(false);
  608.             }
  609.         } else {
  610.             $bulletin = new Tbulletin();
  611.             $bulletin->setDossier($dossier);
  612.             $bulletin->setPPiece(
  613.                 $this->em->getRepository(PPiece::class)->find(2)
  614.             );
  615.             $bulletin->setBordereau($bordoreau);
  616.             $bulletin->setObservation('Honoraire det fixe (' $periode->getCode() . ')');
  617.             $bulletin->setContract($contract);
  618.             $bulletin->setPeriode($periode);
  619.             $this->em->persist($bulletin);
  620.         }
  621.         $bulletinDet = new TbulletinLg();
  622.         $bulletinDet->setBulletin($bulletin);
  623.         $bulletinDet->setRubrique($honoraireRubrique);
  624.         $bulletinDet->setSens(1);
  625.         $bulletinDet->setMontant($honoraireDetFixe->getBrute());
  626.         $this->em->persist($bulletinDet);
  627.         $bulletinDetRetunueIr = new TbulletinLg();
  628.         $bulletinDetRetunueIr->setBulletin($bulletin);
  629.         $bulletinDetRetunueIr->setRubrique($returnueIR);
  630.         $bulletinDetRetunueIr->setSens(-1);
  631.         $bulletinDetRetunueIr->setMontant($honoraireDetFixe->getIr());
  632.         $this->em->persist($bulletinDetRetunueIr);
  633.         $netAPaye $honoraireDetFixe->getMontant();
  634.         $prelevementLgs $this->em->getRepository(PPrelevementLg::class)->getPrelevementByPeriodeAndContract($contract$periode);
  635.         foreach ($prelevementLgs as $prelevementLg) {
  636.             if ($prelevementLg->getMontant() > $netAPaye) {
  637.                 $prelevementLg->setActive(false);
  638.                 $prelevementLg->setValider(false);
  639.                 $prelevementLg->setMotif('Solde insuffisant!');
  640.                 $prelevementLg->setBulletin(null);
  641.                 $lastPrelevementDet $this->em->getRepository(PPrelevementLg::class)->findBy(['prelevement' => $prelevementLg->getPrelevement()], ['id' => 'desc'])[0];
  642.                 $newPeriode $lastPrelevementDet->getPeriode()->getDate()->modify('+1 month');
  643.                 $newPeriode $this->calculPaieService->getPeriode($newPeriode->format('mY'));
  644.                 $prelevementDet = new PPrelevementLg();
  645.                 $prelevementDet->setPeriode($newPeriode);
  646.                 $prelevementDet->setMontant($prelevementLg->getMontant());
  647.                 $prelevementDet->setPrelevement($prelevementLg->getPrelevement());
  648.                 $this->em->persist($prelevementDet);
  649.             } else {
  650.                 $bulletinDet = new TbulletinLg();
  651.                 $bulletinDet->setMontant($prelevementLg->getMontant());
  652.                 $bulletinDet->setSens(-1);
  653.                 $bulletinDet->setRubrique($prelevementLg->getPrelevement()->getRubrique());
  654.                 $bulletinDet->setBulletin($bulletin);
  655.                 $this->em->persist($bulletinDet);
  656.                 $prelevementLg->setBulletin($bulletin);
  657.                 $prelevementLg->setValider(true);
  658.                 $netAPaye -= round($prelevementLg->getMontant(), 2);
  659.             }
  660.         }
  661.         $bulletinDetDivers = new TbulletinLg();
  662.         $bulletinDetDivers->setBulletin($bulletin);
  663.         $bulletinDetDivers->setRubrique($divers);
  664.         $bulletinDetDivers->setSens(1);
  665.         $bulletinDetDivers->setMontant($netAPaye);
  666.         $this->em->persist($bulletinDetDivers);
  667.     }
  668.     public function totalMontant($rubriqueTbulletin $bulletin)
  669.     {
  670.         // dd('h');
  671.         $bulletinLgCumul $this->em->createQueryBuilder()
  672.             ->select('sum(TbulletinLg.montant) as montant')
  673.             ->from(TbulletinLg::class, 'TbulletinLg')
  674.             ->innerJoin('TbulletinLg.bulletin''bulletin')
  675.             ->innerJoin('TbulletinLg.rubrique''rubrique')
  676.             ->innerJoin('bulletin.contract''contract')
  677.             ->innerJoin('bulletin.periode''periode')
  678.             ->innerJoin('bulletin.bordereau''bordereau')
  679.             ->andWhere('rubrique.id in (:rubrique)')
  680.             ->andWhere('TbulletinLg.active = 1')
  681.             ->andWhere('contract.id = :contract')
  682.             ->andWhere('bordereau.type = :bordereauType ')
  683.             // ->andWhere('DATE_FORMAT(periode.date, "%Y") = :year')
  684.             ->setParameter('contract'$bulletin->getContract()->getId())
  685.             ->setParameter('rubrique'$rubrique)
  686.             // ->setParameter('year', $bulletin->getPeriode()->getDate()->format('Y'))
  687.             ->setParameter('bordereauType''paie')
  688.             ->getQuery()
  689.             ->getOneOrNullResult();
  690.         if ($bulletinLgCumul['montant'] != null) {
  691.             return new Response($bulletinLgCumul['montant']);
  692.         }
  693.         return new Response(0);
  694.     }
  695.     #[Route('/app_bulletin_employe_calcul_messenger'name'app_bulletin_employe_calcul_messenger'options: ['expose' => true])]
  696.     public function app_bulletin_employe_calcul_messenger(Request $request): Response
  697.     {
  698.         $dossier $request->get('dossier');
  699.         $user $this->em->getRepository(Users::class)->find($this->getUser());
  700.         $messageStatut = new PMessengerStatut();
  701.         $messageStatut->setStatut('en cours');
  702.         if($dossier == 'all') {
  703.             $messageStatut->setClasse('Generation de paie pour tout les dossiers');
  704.         } else {
  705.             $messageStatut->setClasse('Generation de paie pour dossier: '.$request->getSession()->get('dossier')->getAbreviation());
  706.         }
  707.         $messageStatut->setUser($this->getUser());
  708.         $this->em->persist($messageStatut);
  709.         $this->em->flush();
  710.         $this->bus->dispatch(new PaieMessage([
  711.             'dossier' => $dossier === 'all' 'all' $request->getSession()->get('dossier')->getId(),
  712.             'user' => $user->getId(),
  713.             'messageStatut' => $messageStatut->getId(),
  714.         ]));
  715.         return new JsonResponse('Votre demande a été envoyée, veuillez consulter la page de demande'200);
  716.     }
  717. }