src/Controller/Reporting/ExtractionController.php line 657

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Reporting;
  3. use Mpdf\Mpdf;
  4. use App\Entity\Cab;
  5. use App\Entity\Lrib;
  6. use App\Entity\Type;
  7. use App\Entity\Users;
  8. use App\Entity\PPiece;
  9. use App\Entity\Periode;
  10. use App\Entity\PDossier;
  11. use App\Entity\TCnssA00;
  12. use App\Entity\TCnssB00;
  13. use App\Entity\LContract;
  14. use App\Entity\Prubrique;
  15. use App\Entity\PtypeCoti;
  16. use App\Entity\Tbulletin;
  17. use App\Entity\PBaremeCimr;
  18. use App\Entity\TbulletinLg;
  19. use App\Entity\UsOperation;
  20. use App\Entity\PPrelevement;
  21. use App\Entity\PArretTravailLg;
  22. use App\Entity\PnatureContract;
  23. use App\Entity\PMessengerStatut;
  24. use App\Controller\ApiController;
  25. use App\Entity\LmatriculationCoti;
  26. use App\Service\CalculPaieService;
  27. use Doctrine\Persistence\ManagerRegistry;
  28. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  29. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  30. use App\Message\ExtractionBouclageMessage;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\HttpFoundation\Response;
  33. use Symfony\Component\Routing\Annotation\Route;
  34. use Symfony\Component\HttpFoundation\JsonResponse;
  35. use Symfony\Component\Messenger\MessageBusInterface;
  36. use Symfony\Contracts\HttpClient\HttpClientInterface;
  37. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  38. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  39. #[Route('/reporting/extraction')]
  40. class ExtractionController extends AbstractController
  41. {
  42.     private $em;
  43.     private $calculPaieService;
  44.     private $api;
  45.     public function __construct(ManagerRegistry $doctrineCalculPaieService $calculPaieServiceApiController $api, private MessageBusInterface  $bus)
  46.     {
  47.         $this->em $doctrine->getManager();
  48.         $this->api $api;
  49.         $this->calculPaieService $calculPaieService;
  50.     }
  51.     #[Route('/'name'app_reporting_extraction'options: ['expose' => true])]
  52.     public function index(Request $request): Response
  53.     {
  54.         $operations $this->api->check($this->getUser(), 'app_reporting_extraction'$this->em$request);
  55.         if (!is_array($operations)) {
  56.             return $this->redirectToRoute('app_site');
  57.         } elseif (count($operations) == 0) {
  58.             return $this->render('includes/404.html.twig');
  59.         }
  60.         $dossier $request->getSession()->get('dossier');
  61.         $findDossier=['active' => true];
  62.         if($dossier->getId() != 47) {
  63.             $findDossier ['id'] = $dossier->getId();
  64.         }
  65.         // dd($this->em->getRepository(PDossier::class)->findBy($findDossier));
  66.         $dossiers $this->em->getRepository(PDossier::class)->findBy($findDossier);
  67.         $groupements=$this->em->createQueryBuilder()
  68.                          ->select('DISTINCT dossier.groupement')
  69.                          ->from(PDossier::class, 'dossier')
  70.                          ->Where('dossier.active = 1')
  71.                          ->getQuery()
  72.                          ->getResult();
  73.         $natures $this->em->getRepository(PnatureContract::class)->findAll();
  74.         $prets $this->em->getRepository(Prubrique::class)->findBy(['active' => true'prets' => 1]);
  75.         return $this->render('reporting/extraction/index.html.twig', [
  76.             'controller_name' => 'ExtractionController',
  77.             'groupements'=>$groupements,
  78.             'dossiers' => $dossiers,
  79.             'natures' => $natures,
  80.             'prets' => $prets
  81.         ]);
  82.     }
  83.     #[Route('/app_reporting_extraction_list'name'app_reporting_extraction_list'options: ['expose' => true])]
  84.     public function app_reporting_extraction_list(Request $request): Response
  85.     {
  86.         $draw $request->query->get('draw');
  87.         $start $request->query->get('start') ?? 0;
  88.         $length $request->query->get('length') ?? 10;
  89.         $search $request->query->all('search')["value"];
  90.         $orderColumnIndex $request->query->all('order')[0]['column'];
  91.         $orderColumn $request->query->all("columns")[$orderColumnIndex]['name'];
  92.         $orderDir $request->query->all('order')[0]['dir'] ?? 'asc';
  93.         $queryBuilder $this->em->createQueryBuilder()
  94.             ->select('o.icon, o.designation, o.idTag')
  95.             ->from(UsOperation::class, 'o')
  96.             ->innerJoin('o.sousModule''m')
  97.             ->Where('o.align = :align')
  98.             ->andWhere('m.id = 16')
  99.             ->andWhere('o.active = 1')
  100.             ->setParameter('align''1');
  101.         if (!empty($search)) {
  102.             $queryBuilder->andWhere('(o.designation LIKE :search OR o.icon LIKE :search OR o.idTag LIKE :search)')
  103.                 ->setParameter('search'"%$search%");
  104.         }
  105.         if (!empty($orderColumn)) {
  106.             $queryBuilder->orderBy("$orderColumn"$orderDir);
  107.         }
  108.         $filteredRecords count($queryBuilder->getQuery()->getResult());
  109.         // Paginate results
  110.         $queryBuilder->setFirstResult($start)
  111.             ->setMaxResults($length);
  112.         $results $queryBuilder->getQuery()->getResult();
  113.         // dd($results);
  114.         $data = [];
  115.         foreach ($results as $key => $operation) {
  116.             $array = [];
  117.             $array[] = $operation['icon'];
  118.             $array[] = '<a href="#" id="' $operation['idTag'] . '">' $operation['designation'] . '</a>';
  119.             $data[] = $array;
  120.         }
  121.         // dd($results);
  122.         $totalRecords $this->em->createQueryBuilder()
  123.             ->select('COUNT(d.id)')
  124.             ->from(UsOperation::class, 'd')
  125.             ->innerJoin('d.sousModule''m')
  126.             ->Where('d.align = :align')
  127.             ->andWhere('m.id = 16')
  128.             ->setParameter('align''1')
  129.             ->getQuery()
  130.             ->getSingleScalarResult();
  131.         return new JsonResponse([
  132.             'draw' => $draw,
  133.             'recordsTotal' => $totalRecords,
  134.             'recordsFiltered' => $filteredRecords,
  135.             'data' => $data,
  136.         ]);
  137.     }
  138.     #[Route('/app_reporting_extraction_employe_active'name'app_reporting_extraction_employe_active'options: ['expose' => true])]
  139.     public function app_reporting_extraction_employe_active(Request $request): Response
  140.     {
  141.         $dossier $request->getSession()->get('dossier');
  142.         // dd($dossier->getId());
  143.         $queryBuilder $this->em->createQueryBuilder()
  144.             ->select('affectationDossier.groupement, affectationDossier.id as id_dossier, fcy.id as fcy_id, fcy.fcy0, fcy.fcy0Libelle,affectationDossier.das,affectationDossier.abreviation, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom, employe.cin, employe.sexe, employe.adresse1,
  145.          date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, dureeContract.Designation as duree_contrat, bareme.id as id_bareme, bareme.bareme as bareme_number, bareme.Profil, baremeType.designation as bareme_type, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
  146.          date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete, f.Designation as fonction,lribs.code as rib, lribs.swift, lribs.banque, contract.cnss as cnss, contract.cimr as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\'  ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation
  147.          ')
  148.             ->from(PDossier::class, 'dossier')
  149.             ->innerJoin('dossier.contracts''contract')
  150.             ->innerJoin('contract.ldossierContracts''ldossierContract')
  151.             ->innerJoin('contract.employe''employe')
  152.             ->innerJoin('contract.pnatureContract''pnatureContract')
  153.             ->innerJoin('contract.bareme''bareme')
  154.             ->innerJoin('bareme.baremeType''baremeType')
  155.             ->innerJoin('pnatureContract.type''type')
  156.             ->innerJoin('ldossierContract.dossier_id''affectationDossier')
  157.             ->leftJoin('contract.fonction''f')
  158.             ->leftJoin('contract.dureeContract''dureeContract')
  159.             ->leftJoin('affectationDossier.fcy''fcy')
  160.             // ->leftJoin('employe.diplomes', 'diplomes')
  161.             ->leftJoin('contract.lribs''lribs''WITH''lribs.active = 1')
  162.             ->Where('contract.active = 1');
  163.             if($dossier->getId() != 47) {
  164.                 $queryBuilder->andWhere('dossier.id = :dossier')->setParameter('dossier'$dossier->getId());
  165.             } 
  166.             $result $queryBuilder->orderBy('dossier.id''desc')
  167.                                    ->getQuery()
  168.                                    ->getResult();
  169.         return new JsonResponse($result);
  170.     }
  171.     #[Route('/app_reporting_extraction_employe_entrant/{periode}'name'app_reporting_extraction_employe_entrant'options: ['expose' => true])]
  172.     public function app_reporting_extraction_employe_entrant($periode,Request $request): Response
  173.     {
  174.         $dateDebut = new \DateTime($periode);
  175.         $dateFin = new \DateTime($periode);
  176.         $dateDebut->modify('first day of this month');
  177.         $dateFin->modify('last day of this month');
  178.         $dossier $request->getSession()->get('dossier');
  179.         // dd($dossier);
  180.         $queryBuilder $this->em->createQueryBuilder()
  181.             ->select('affectationDossier.groupement, affectationDossier.id as id_dossier, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom,employe.sexe, employe.cin, employe.adresse1,
  182.          date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, bareme.id as id_bareme, bareme.bareme as bareme_number, bareme.Profil, baremeType.designation as bareme_type, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
  183.          date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete,lribs.code as rib, contract.cnss as cnss, contract.cimr as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\'  ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation ')
  184.             ->from(PDossier::class, 'dossier')
  185.             ->innerJoin('dossier.contracts''contract')
  186.             ->innerJoin('contract.ldossierContracts''ldossierContract')
  187.             ->innerJoin('contract.employe''employe')
  188.             ->innerJoin('contract.pnatureContract''pnatureContract')
  189.             ->innerJoin('contract.bareme''bareme')
  190.             ->innerJoin('bareme.baremeType''baremeType')
  191.             ->innerJoin('pnatureContract.type''type')
  192.             ->innerJoin('ldossierContract.dossier_id''affectationDossier')
  193.             ->leftJoin('contract.lribs''lribs''WITH''lribs.active = 1')
  194.             // ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCnss', 'WITH', 'lmatriculationCotisCnss.type_id = 1')
  195.             // ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCimr', 'WITH', 'lmatriculationCotisCimr.type_id = 2')
  196.             // ->leftJoin('ldossierContract.dossier_id', 'affectationDossier')
  197.             ->Where('contract.date_debut >= :date_debut')
  198.             ->andWhere('contract.date_debut <= :date_fin');
  199.             // ->andWhere('dossier.id = 20')
  200.             if($dossier->getId() != 47) {
  201.                 $queryBuilder->andWhere('dossier.id = :dossier')->setParameter('dossier'$dossier->getId());
  202.             } 
  203.             $result $queryBuilder->setParameter('date_debut'$dateDebut)
  204.             ->setParameter('date_fin'$dateFin)
  205.             ->orderBy('dossier.id''desc')
  206.             ->getQuery()
  207.             ->getResult();
  208.         return new JsonResponse($result);
  209.     }
  210.     #[Route('/app_reporting_extraction_net_theorique/{periode}'name'app_reporting_extraction_net_theorique'options: ['expose' => true])]
  211.     public function app_reporting_extraction_net_theorique($periode,Request $request): Response
  212.     {
  213.         $date = new \DateTime($periode);
  214.         $periode $this->calculPaieService->getPeriode($date->format('mY'));
  215.         $dossier $request->getSession()->get('dossier');
  216.         // dd($dossier);
  217.         $queryBuilder $this->em->createQueryBuilder()
  218.             ->select('dossier.id as id_dossier, dossier.abreviation as dossier_abreviation, contract.id as id_contract,employe.nom, employe.prenom,
  219.             employe.cin, lribs.code as rib, contractNetTheorique.montant')
  220.             ->from(Tbulletin::class, 'bulletin')
  221.             ->innerJoin('bulletin.contractNetTheoriques''contractNetTheorique')
  222.             ->innerJoin('bulletin.contract''contract')
  223.             ->innerJoin('bulletin.dossier''dossier')
  224.             ->innerJoin('contract.employe''employe')
  225.             ->innerJoin('contract.pnatureContract''pnatureContract')
  226.             ->leftJoin('contract.lribs''lribs''WITH''lribs.active = 1')
  227.             ->innerJoin('contract.bareme''bareme')
  228.             ->innerJoin('bareme.baremeType''baremeType')
  229.             ->innerJoin('pnatureContract.type''type')
  230.             ->Where('bulletin.periode = :periode')
  231.             ->andWhere('bulletin.active = 1')
  232.             ->setParameter('periode'$periode)
  233.             ->orderBy('dossier.id''desc')
  234.             ->getQuery()
  235.             ->getResult();
  236.         return new JsonResponse($queryBuilder);
  237.     }
  238.     #[Route('/app_reporting_extraction_employe_sortant/{periode}'name'app_reporting_extraction_employe_sortant'options: ['expose' => true])]
  239.     public function app_reporting_extraction_employe_sortant($periode,Request $request): Response
  240.     {
  241.         $dateDebut = new \DateTime($periode);
  242.         $dateFin = new \DateTime($periode);
  243.         $dateDebut->modify('first day of this month');
  244.         $dateFin->modify('last day of this month');
  245.         $dossier $request->getSession()->get('dossier');
  246.         $queryBuilder $this->em->createQueryBuilder()
  247.             ->select('affectationDossier.groupement, affectationDossier.id as id_dossier, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom,employe.sexe, employe.cin, employe.adresse1,
  248.          date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, bareme.id as id_bareme, bareme.bareme as bareme_number, bareme.Profil, baremeType.designation as bareme_type, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
  249.          date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete,lribs.code as rib, contract.cnss as cnss, contract.cimr as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\'  ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation, date_format(contract.date_sortie, \'%d/%m/%Y\') as date_sortie, contract.motif_sortie ')
  250.             ->from(PDossier::class, 'dossier')
  251.             ->innerJoin('dossier.contracts''contract')
  252.             ->innerJoin('contract.ldossierContracts''ldossierContract')
  253.             ->innerJoin('contract.employe''employe')
  254.             ->innerJoin('contract.pnatureContract''pnatureContract')
  255.             ->innerJoin('contract.bareme''bareme')
  256.             ->innerJoin('bareme.baremeType''baremeType')
  257.             ->innerJoin('pnatureContract.type''type')
  258.             ->innerJoin('ldossierContract.dossier_id''affectationDossier')
  259.             ->leftJoin('contract.lribs''lribs''WITH''lribs.active = 1')
  260.             // ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCnss', 'WITH', 'lmatriculationCotisCnss.type_id = 1')
  261.             // ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCimr', 'WITH', 'lmatriculationCotisCimr.type_id = 2')
  262.             // ->leftJoin('ldossierContract.dossier_id', 'affectationDossier')
  263.             ->Where('contract.date_sortie >= :date_debut')
  264.             ->andWhere('contract.date_sortie <= :date_fin');
  265.             
  266.             if($dossier->getId() != 47) {
  267.                 $queryBuilder->andWhere('dossier.id = :dossier')->setParameter('dossier'$dossier->getId());
  268.             } 
  269.             $result $queryBuilder->setParameter('date_debut'$dateDebut)
  270.                                    ->setParameter('date_fin'$dateFin)
  271.                                    ->orderBy('dossier.id''desc')
  272.                                    ->getQuery()
  273.                                    ->getResult();
  274.         // dd($result);
  275.         return new JsonResponse($result);
  276.     }
  277.     #[Route('/app_reporting_extraction_bulletin_paie/{periode}'name'app_reporting_extraction_bulletin_paie'options: ['expose' => true])]
  278.     public function app_reporting_extraction_bulletin_paie(Request $request$periode): Response
  279.     {
  280.         $date = new \DateTime($periode);
  281.         $periode $this->calculPaieService->getPeriode($date->format('mY'));
  282.         $dossier $request->getSession()->get('dossier');
  283.        
  284.         // $queryBuilder = $this->em->createQueryBuilder()
  285.         // ->select('affectationDossier.id as id_dossier, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom, employe.cin, employe.adresse1,
  286.         //  date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
  287.         //  date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete,lribs.code as rib, lmatriculationCotisCnss.code as cnss, lmatriculationCotisCimr.code as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\'  ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation ')
  288.         // ->from(PDossier::class, 'dossier')
  289.         // ->innerJoin('dossier.contracts', 'contract')
  290.         // ->innerJoin('contract.ldossierContracts', 'ldossierContract')
  291.         // ->innerJoin('contract.employe', 'employe')
  292.         // ->innerJoin('contract.pnatureContract', 'pnatureContract')
  293.         // ->innerJoin('pnatureContract.type', 'type')
  294.         // ->innerJoin('ldossierContract.dossier_id', 'affectationDossier')
  295.         // ->leftJoin('contract.lribs', 'lribs', 'WITH', 'lribs.active = 1')
  296.         // ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCnss', 'WITH', 'lmatriculationCotisCnss.type_id = 1')
  297.         // ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCimr', 'WITH', 'lmatriculationCotisCimr.type_id = 2')
  298.         // // ->leftJoin('ldossierContract.dossier_id', 'affectationDossier')
  299.         // ->Where('contract.active = 1')
  300.         // // ->andWhere('dossier.id = 20')
  301.         // ->orderBy('dossier.id', 'desc')
  302.         // ->getQuery()
  303.         // ->getResult()
  304.         // ;
  305.         $spreadsheet = new Spreadsheet();
  306.         $sheet $spreadsheet->getActiveSheet();
  307.         $sheet->setCellValue('A1''Id Dossier');
  308.         $sheet->setCellValue('B1''Dossier');
  309.         $sheet->setCellValue('C1''Id Contrat');
  310.         $sheet->setCellValue('D1''Nom');
  311.         $sheet->setCellValue('E1''Prenom');
  312.         $sheet->setCellValue('F1''Cin');
  313.         $sheet->setCellValue('G1''Rib');
  314.         $sheet->setCellValue('H1''Bulletin');
  315.         $sheet->setCellValue('I1''nbrjours');
  316.         $sheet->setCellValue('J1''netpaye');
  317.         $sheet->setCellValue('K1''type');
  318.         $sheet->setCellValue('L1''type bareme');
  319.         $findDossier=['active' => true'periode' => $periode];
  320.         if($dossier->getId() != 47) {
  321.             $findDossier ['dossier'] = $dossier;
  322.         }
  323.         $bulletins $this->em->getRepository(Tbulletin::class)->findBy($findDossier);
  324.         $i 2;
  325.         foreach ($bulletins as $key => $bulletin) {
  326.             $contract $bulletin->getContract();
  327.             $sheet->setCellValue('A' $i$contract $contract->getDossier()->getId() : '');
  328.             $sheet->setCellValue('B' $i$contract $contract->getDossier()->getAbreviation() : '');
  329.             $sheet->setCellValue('C' $i$contract $contract->getId() : '');
  330.             $sheet->setCellValue('D' $i$contract $contract->getEmploye()->getNom() : '');
  331.             $sheet->setCellValue('E' $i$contract $contract->getEmploye()->getPrenom() : '');
  332.             $sheet->setCellValue('F' $i$contract $contract->getEmploye()->getCin() : '');
  333.             if ($contract) {
  334.                 $rib $this->em->getRepository(Lrib::class)->findOneBy(['contact_id' => $contract'active' => true]);
  335.                 $nbr 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($contract->getId(), $periode);
  336.                 $sheet->setCellValue('G' $i$rib $rib->getCode() : '');
  337.             } else {
  338.                 $rib '-';
  339.                 $sheet->setCellValue('G' $i'');
  340.                 $nbr '-';
  341.             }
  342.             $sheet->setCellValue('H' $i$bulletin->getCode());
  343.             $sheet->setCellValue('I' $i$nbr);
  344.             $sheet->setCellValue('J' $i,  $this->em->getRepository(Tbulletin::class)->getNetAPaye($bulletin->getId()));
  345.             $sheet->setCellValue('K' $i$bulletin->getPPiece()->getDesignation());
  346.             $sheet->setCellValue('L' $i$contract $contract->getBareme()->getBaremeType()->getDesignation() : '');
  347.             $i++;
  348.         }
  349.         $writer = new Xlsx($spreadsheet);
  350.         $fileName 'bulletin_paies_' $periode->getCode() . '.xlsx';
  351.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  352.         $writer->save($temp_file);
  353.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  354.     }
  355.     #[Route('/app_reporting_extraction_charge_social/{periode}'name'app_reporting_extraction_charge_social'options: ['expose' => true])]
  356.     public function app_reporting_extraction_charge_social(Request $request$periode): Response
  357.     {
  358.         $connection $this->em->getConnection();
  359.         $dossier $request->getSession()->get('dossier');
  360.         $dossier $this->em->getRepository(PDossier::class)->find($dossier);
  361.         if($dossier->getId() == 47) {
  362.             $requestDossier '';
  363.         } else {
  364.             $requestDossier ' and pdossier.id = '.$dossier->getId();
  365.         }
  366.         $date = new \DateTime($periode);
  367.         $periode $this->calculPaieService->getPeriode($date->format('mY'));
  368.         $periode $periode->getId();
  369.         // $request = "SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  370.         //     pemploye.cin,tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.sens,
  371.         //     pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
  372.         //     FROM tbulletin_lg
  373.         //     INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  374.         //     INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  375.         //     INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  376.         //     INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
  377.         //     INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  378.         //     INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  379.         //     INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
  380.         //     INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  381.         //     INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  382.         //     INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  383.         //     INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  384.         //     where  tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43)";
  385.         // $stmt = $connection->prepare($request);
  386.         // $newstmt = $stmt->executeQuery();   
  387.         // $result = $newstmt->fetchAll();
  388.         // $bulletinValues = array_map(function ($item) {
  389.         //     return $item['bulletin_id'];
  390.         // }, $result);
  391.         // $bulletinValues = array_unique($bulletinValues);
  392.         // $bulletinValues = implode(', ', $bulletinValues);
  393.         // // dd($bulletinValues);
  394.         // $requestSecond = "SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  395.         //     pemploye.cin, tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, 'rémunération brute imposable' as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
  396.         //     pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
  397.         //     FROM tbulletin_lg
  398.         //     INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  399.         //     INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  400.         //     INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  401.         //     INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
  402.         //     INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  403.         //     INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  404.         //     INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
  405.         //     INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  406.         //     INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  407.         //     INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  408.         //     INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  409.         //     where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.imposable = 1 and tbulletin.id in ($bulletinValues)
  410.         //     group by tbulletin.code 
  411.         //     UNION
  412.         //     SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  413.         //     pemploye.cin,tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, 'rémunération brute' as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
  414.         //     pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
  415.         //     FROM tbulletin_lg
  416.         //     INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  417.         //     INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  418.         //     INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  419.         //     INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  420.         //     INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
  421.         //     INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  422.         //     INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
  423.         //     INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  424.         //     INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  425.         //     INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  426.         //     INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  427.         //     where  tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 and (prubrique.id in (1, 4, 6, 7,8,9) or prubrique.fixe = 1) and tbulletin.id in ($bulletinValues)
  428.         //     group by tbulletin.code 
  429.         //     UNION
  430.         //     SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  431.         //     pemploye.cin,tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.sens as sens,
  432.         //     pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
  433.         //     FROM tbulletin_lg
  434.         //     INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  435.         //     INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  436.         //     INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  437.         //     INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  438.         //     INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
  439.         //     INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  440.         //     INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
  441.         //     INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  442.         //     INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  443.         //     INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  444.         //     INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  445.         //     where  tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 and  (prubrique.prets = 1 or prubrique.id in (5, 65)) and tbulletin.id in ($bulletinValues)
  446.         //     group by tbulletin.code 
  447.         //     "
  448.         // ;
  449.         $request "SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  450.             pemploye.cin, tbulletin.code as bulletin, ppiece.designation as type_bulletin,prubrique.code as 'element_code', prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.sens,
  451.             pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau,  pbordereau.observation, pstatut.designation as statut
  452.             
  453.             FROM tbulletin_lg
  454.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  455.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  456.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  457.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  458.             INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  459.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  460.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  461.             INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
  462.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  463.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  464.             INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  465.             where tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43, 5, 68) $requestDossier
  466.             UNION
  467.             SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  468.             pemploye.cin, tbulletin.code as bulletin, ppiece.designation as type_bulletin, null as 'element_code', 'rémunération brute imposable' as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
  469.             pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
  470.             
  471.             FROM tbulletin_lg
  472.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  473.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  474.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  475.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  476.             INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  477.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  478.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  479.             INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
  480.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  481.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  482.             INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  483.             where tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.imposable = 1 $requestDossier
  484.             group by tbulletin.code 
  485.             UNION
  486.             SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  487.             pemploye.cin, tbulletin.code as bulletin, ppiece.designation as type_bulletin,
  488.             CASE WHEN prubrique.honoraire = 1 THEN prubrique.designation WHEN prubrique.indeminite = 1 THEN prubrique.code ELSE null END as element_code,
  489.             CASE WHEN prubrique.honoraire = 1 THEN prubrique.designation WHEN prubrique.indeminite = 1 THEN prubrique.designation ELSE 'rémunération brute' END as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
  490.             pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
  491.             
  492.             FROM tbulletin_lg
  493.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  494.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  495.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  496.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  497.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  498.             INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  499.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  500.             INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
  501.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  502.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  503.             INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  504.             where tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 
  505.             and (
  506.                     ((prubrique.id in (1,2, 4, 6, 7,8,9)  or prubrique.fixe = 1 ) and pbordereau.type = 'paie') or 
  507.                     (prubrique.honoraire = 1 and pbordereau.type = 'honoraire') or
  508.                     prubrique.indeminite = 1
  509.             ) $requestDossier
  510.             group by tbulletin.code 
  511.             UNION
  512.             SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  513.             pemploye.cin,tbulletin.code as bulletin, ppiece.designation as type_bulletin,prubrique.code as element_code, prubrique.designation as element, sum(tbulletin_lg.montant) as montant, tbulletin_lg.sens as sens,
  514.             pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
  515.             FROM tbulletin_lg
  516.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  517.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  518.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  519.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  520.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  521.             INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  522.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  523.             INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
  524.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  525.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  526.             INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
  527.             where  tbulletin.periode_id = $periode and pbordereau.active = 1  and tbulletin.active = 1 and tbulletin_lg.active = 1 and  prubrique.prets = 1 $requestDossier
  528.             group by tbulletin.code, prubrique.designation;
  529.             ";
  530.         $stmt $connection->prepare($request);
  531.         $newstmt $stmt->executeQuery();
  532.         $resultSecond $newstmt->fetchAll();
  533.         // dd($resultSecond[0]);
  534.         // $result = array_merge($resultSecond, $result);
  535.         return new JsonResponse($resultSecond);
  536.         // $spreadsheet = new Spreadsheet();
  537.         // $sheet = $spreadsheet->getActiveSheet();
  538.         // $sheet->setCellValue('A1', 'Id Dossier');
  539.         // $sheet->setCellValue('B1', 'Dossier');
  540.         // $sheet->setCellValue('C1', 'Id Contrat');
  541.         // $sheet->setCellValue('D1', 'Nom');
  542.         // $sheet->setCellValue('E1', 'Prenom');
  543.         // $sheet->setCellValue('F1', 'Cin');
  544.         // $sheet->setCellValue('G1', 'Bulletin'); 
  545.         // $sheet->setCellValue('H1', 'Element'); 
  546.         // $sheet->setCellValue('I1', 'Montant'); 
  547.         // $sheet->setCellValue('J1', 'Sens'); 
  548.         // $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
  549.         // $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
  550.         // $bulletins = $this->em->getRepository(Tbulletin::class)->findBy(['active' => true, 'periode'=> $periode, 'piece' => $this->em->getRepository(PPiece::class)->find(1)]);
  551.         // $bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletins, 'rubrique' => $rubriques, 'active' => true]);
  552.         // // dd($bulletinLgs);
  553.         // $i = 2;
  554.         // foreach ($bulletinLgs as $key => $bulletinLg) {
  555.         //     $bulletin = $bulletinLg->getBulletin();
  556.         //     $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
  557.         //     $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
  558.         //     $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
  559.         //     $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
  560.         //     $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
  561.         //     $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
  562.         //     $sheet->setCellValue('G'.$i, $bulletin->getCode()); 
  563.         //     $sheet->setCellValue('H'.$i, $bulletinLg->getRubrique()->getDesignation()); 
  564.         //     $sheet->setCellValue('I'.$i, $bulletinLg->getMontant());
  565.         //     $sheet->setCellValue('J'.$i, $bulletinLg->getSens());
  566.         //     $i++;
  567.         // }
  568.         // $writer = new Xlsx($spreadsheet);
  569.         // $fileName = 'charge_sociale_'.$periode->getCode().'.xlsx';
  570.         // $temp_file = tempnam(sys_get_temp_dir(), $fileName);
  571.         // $writer->save($temp_file);
  572.         // return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
  573.     }
  574.     #[Route('/app_reporting_extraction_masse_salariale/{periode}'name'app_reporting_extraction_masse_salariale'options: ['expose' => true])]
  575.     public function app_reporting_extraction_masse_salariale(Request $request$periode): Response
  576.     {
  577.         $connection $this->em->getConnection();
  578.         $dossier $request->getSession()->get('dossier');
  579.         if($dossier->getId() == 47) {
  580.             $requestDossier '';
  581.         } else {
  582.             $requestDossier ' and pdossier.id = '.$dossier->getId();
  583.         }
  584.         $date = new \DateTime($periode);
  585.         $periode $this->calculPaieService->getPeriode($date->format('mY'));
  586.         $periode $periode->getId();
  587.         $request "SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  588.             pnature_contract.designation as nature_contrat, pemploye.cin, tbulletin.code as bulletin,prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.montant_devise, tbulletin_lg.sens,
  589.             ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
  590.             
  591.             FROM tbulletin_lg
  592.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  593.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  594.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  595.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  596.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  597.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  598.             INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
  599.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  600.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  601.             INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
  602.             LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
  603.             LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  604.             LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
  605.             where  tbulletin.periode_id = $periode  and tbulletin.active = 1 and tbulletin_lg.active = 1 and pbordereau.active = 1 $requestDossier
  606.             UNION
  607.             SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle, pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  608.             pnature_contract.designation as nature_contrat, pemploye.cin, tbulletin.code as bulletin, 'brute calculé' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
  609.             ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
  610.             
  611.             FROM tbulletin_lg
  612.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  613.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  614.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  615.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  616.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  617.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  618.             INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
  619.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  620.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  621.             INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
  622.             LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
  623.             LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  624.             LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
  625.             where  tbulletin.periode_id = $periode  and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.imposable = 1 and pbordereau.active = 1 $requestDossier
  626.             group by tbulletin.code 
  627.             UNION
  628.             SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  629.             pnature_contract.designation as nature_contrat,pemploye.cin, tbulletin.code as bulletin, 'rémunération brute' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
  630.             ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
  631.             
  632.             FROM tbulletin_lg
  633.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  634.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  635.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  636.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  637.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  638.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  639.             INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
  640.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  641.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  642.             INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
  643.             LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
  644.             LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  645.             LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
  646.             where  tbulletin.periode_id = $periode  and tbulletin.active = 1 and tbulletin_lg.active = 1 and (prubrique.id in (1, 4, 6, 7,8,9) or prubrique.fixe = 1) and pbordereau.active = 1 $requestDossier
  647.             group by tbulletin.code 
  648.             UNION
  649.             SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  650.             pnature_contract.designation as nature_contrat,pemploye.cin, tbulletin.code as bulletin, 'cotisation PS' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
  651.             ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
  652.             
  653.             FROM tbulletin_lg
  654.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  655.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  656.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  657.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  658.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  659.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  660.             INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
  661.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  662.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  663.             INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
  664.             LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
  665.             LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  666.             LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
  667.             where  tbulletin.periode_id = $periode  and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (50, 47, 53, 48) and pbordereau.active = 1 $requestDossier
  668.             group by tbulletin.code 
  669.             UNION
  670.             SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
  671.             pnature_contract.designation as nature_contrat,pemploye.cin, tbulletin.code as bulletin, 'cotisation PP' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
  672.             ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
  673.             
  674.             FROM tbulletin_lg
  675.             INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
  676.             INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
  677.             INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
  678.             INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
  679.             INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
  680.             INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
  681.             INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
  682.             INNER JOIN pemploye on pemploye.id = lcontract.employe_id
  683.             INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
  684.             INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
  685.             LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
  686.             LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
  687.             LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
  688.             where  tbulletin.periode_id = $periode  and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (51, 52, 54, 55, 56, 58, 57) and pbordereau.active = 1 $requestDossier
  689.             group by tbulletin.code 
  690.         ";
  691.         $stmt $connection->prepare($request);
  692.         $newstmt $stmt->executeQuery();
  693.         $result $newstmt->fetchAll();
  694.         return new JsonResponse($result);
  695.         // $spreadsheet = new Spreadsheet();
  696.         // $sheet = $spreadsheet->getActiveSheet();
  697.         // $sheet->setCellValue('A1', 'Id Dossier');
  698.         // $sheet->setCellValue('B1', 'Dossier');
  699.         // $sheet->setCellValue('C1', 'Id Contrat');
  700.         // $sheet->setCellValue('D1', 'Nom');
  701.         // $sheet->setCellValue('E1', 'Prenom');
  702.         // $sheet->setCellValue('F1', 'Cin');
  703.         // $sheet->setCellValue('G1', 'Bulletin'); 
  704.         // $sheet->setCellValue('H1', 'Element'); 
  705.         // $sheet->setCellValue('I1', 'Montant'); 
  706.         // $sheet->setCellValue('J1', 'Sens'); 
  707.         // $sheet->setCellValue('K1', 'type'); 
  708.         // $sheet->setCellValue('L1', 'type bareme'); 
  709.         // $bulletins = $this->em->getRepository(Tbulletin::class)->findBy(['active' => true, 'periode'=> $periode]);
  710.         // // dd($bulletinLgs);
  711.         // $i = 2;
  712.         // foreach ($bulletins as $key => $bulletin) {
  713.         //     $montantBruteImposable = $this->em->createQueryBuilder()
  714.         //         ->select('sum(TbulletinLg.montant) as montant')
  715.         //         ->from(TbulletinLg::class, 'TbulletinLg')
  716.         //         ->innerJoin('TbulletinLg.bulletin', 'bulletin')
  717.         //         ->innerJoin('TbulletinLg.rubrique', 'rubrique')
  718.         //         ->andWhere('rubrique.imposable = 1')
  719.         //         ->andWhere('TbulletinLg.active = 1')
  720.         //         ->andWhere('bulletin.id = :bulletin')
  721.         //         ->setParameter('bulletin', $bulletin)
  722.         //         ->getQuery()
  723.         //         ->getOneOrNullResult()
  724.         //     ;
  725.         //     $montantBrute = $this->em->createQueryBuilder()
  726.         //         ->select('sum(TbulletinLg.montant) as montant')
  727.         //         ->from(TbulletinLg::class, 'TbulletinLg')
  728.         //         ->innerJoin('TbulletinLg.bulletin', 'bulletin')
  729.         //         ->innerJoin('TbulletinLg.rubrique', 'rubrique')
  730.         //         ->andWhere('rubrique.id in (1, 4, 6, 7,8,9) or rubrique.fixe = 1')
  731.         //         ->andWhere('TbulletinLg.active = 1')
  732.         //         ->andWhere('bulletin.id = :bulletin')
  733.         //         ->setParameter('bulletin', $bulletin)
  734.         //         ->getQuery()
  735.         //         ->getOneOrNullResult()
  736.         //     ;
  737.         //     $cotisationsPS = [50, 47, 53, 48];
  738.         //     $cotisationsPP = [51, 52, 54, 55, 56, 58, 57];
  739.         //     $montantCotisationcotisationsPS = $this->em->createQueryBuilder()
  740.         //         ->select('sum(TbulletinLg.montant) as montant')
  741.         //         ->from(TbulletinLg::class, 'TbulletinLg')
  742.         //         ->innerJoin('TbulletinLg.bulletin', 'bulletin')
  743.         //         ->innerJoin('TbulletinLg.rubrique', 'rubrique')
  744.         //         ->andWhere('rubrique.id in (:cotisations)')
  745.         //         ->andWhere('TbulletinLg.active = 1')
  746.         //         ->andWhere('bulletin.id = :bulletin')
  747.         //         ->setParameter('bulletin', $bulletin)
  748.         //         ->setParameter('cotisations', $cotisationsPS)
  749.         //         ->getQuery()
  750.         //         ->getOneOrNullResult()
  751.         //     ;
  752.         //     $montantCotisationcotisationsPP = $this->em->createQueryBuilder()
  753.         //         ->select('sum(TbulletinLg.montant) as montant')
  754.         //         ->from(TbulletinLg::class, 'TbulletinLg')
  755.         //         ->innerJoin('TbulletinLg.bulletin', 'bulletin')
  756.         //         ->innerJoin('TbulletinLg.rubrique', 'rubrique')
  757.         //         ->andWhere('rubrique.id in (:cotisations)')
  758.         //         ->andWhere('TbulletinLg.active = 1')
  759.         //         ->andWhere('bulletin.id = :bulletin')
  760.         //         ->setParameter('bulletin', $bulletin)
  761.         //         ->setParameter('cotisations', $cotisationsPP)
  762.         //         ->getQuery()
  763.         //         ->getOneOrNullResult()
  764.         //     ;
  765.         //     $bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin, 'active' => true]);
  766.         //     foreach ($bulletinLgs as $key => $bulletinLg) {
  767.         //         $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
  768.         //         $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
  769.         //         $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
  770.         //         $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
  771.         //         $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
  772.         //         $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
  773.         //         $sheet->setCellValue('G'.$i, $bulletin->getCode()); 
  774.         //         $sheet->setCellValue('H'.$i, $bulletinLg->getRubrique()->getDesignation()); 
  775.         //         $sheet->setCellValue('I'.$i, $bulletinLg->getMontant());
  776.         //         $sheet->setCellValue('J'.$i, $bulletinLg->getSens());
  777.         //         $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
  778.         //         $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
  779.         //         $i++;
  780.         //     }
  781.         //     if($montantCotisationcotisationsPS) {
  782.         //         $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
  783.         //         $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
  784.         //         $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
  785.         //         $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
  786.         //         $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
  787.         //         $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
  788.         //         $sheet->setCellValue('G'.$i, $bulletin->getCode()); 
  789.         //         $sheet->setCellValue('H'.$i, 'Cotisation PS'); 
  790.         //         $sheet->setCellValue('I'.$i, $montantCotisationcotisationsPS['montant']);
  791.         //         $sheet->setCellValue('J'.$i, '-1');
  792.         //         $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
  793.         //         $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
  794.         //         $i++;
  795.         //     }
  796.         //     if($montantCotisationcotisationsPP) {
  797.         //         $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
  798.         //         $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
  799.         //         $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
  800.         //         $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
  801.         //         $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
  802.         //         $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
  803.         //         $sheet->setCellValue('G'.$i, $bulletin->getCode()); 
  804.         //         $sheet->setCellValue('H'.$i, 'Cotisation PP'); 
  805.         //         $sheet->setCellValue('I'.$i, $montantCotisationcotisationsPP['montant']);
  806.         //         $sheet->setCellValue('J'.$i, '-1');
  807.         //         $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
  808.         //         $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
  809.         //         $i++;
  810.         //     }
  811.         //     if($montantBrute) {
  812.         //         $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
  813.         //         $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
  814.         //         $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
  815.         //         $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
  816.         //         $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
  817.         //         $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
  818.         //         $sheet->setCellValue('G'.$i, $bulletin->getCode()); 
  819.         //         $sheet->setCellValue('H'.$i, 'rémunération brute'); 
  820.         //         $sheet->setCellValue('I'.$i, $montantBrute['montant']);
  821.         //         $sheet->setCellValue('J'.$i, '1');
  822.         //         $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
  823.         //         $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
  824.         //         $i++;
  825.         //     }
  826.         //     if($montantBruteImposable) {
  827.         //         $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
  828.         //         $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
  829.         //         $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
  830.         //         $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
  831.         //         $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
  832.         //         $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
  833.         //         $sheet->setCellValue('G'.$i, $bulletin->getCode()); 
  834.         //         $sheet->setCellValue('H'.$i, 'rémunération brute imposable'); 
  835.         //         $sheet->setCellValue('I'.$i, $montantBruteImposable['montant']);
  836.         //         $sheet->setCellValue('J'.$i, '1');
  837.         //         $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
  838.         //         $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
  839.         //         $i++;
  840.         //     }
  841.         // }
  842.         // $writer = new Xlsx($spreadsheet);
  843.         // $fileName = 'masse_salariale_'.$periode->getCode().'.xlsx';
  844.         // $temp_file = tempnam(sys_get_temp_dir(), $fileName);
  845.         // $writer->save($temp_file);
  846.         // return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
  847.     }
  848.     #[Route('/app_reporting_extraction_prelevement'name'app_reporting_extraction_prelevement'options: ['expose' => true])]
  849.     public function app_reporting_extraction_prelevement(Request $request): Response
  850.     {
  851.         $dossier $request->getSession()->get('dossier');
  852.         $spreadsheet = new Spreadsheet();
  853.         $sheet $spreadsheet->getActiveSheet();
  854.         $sheet->setCellValue('A1''Id Dossier');
  855.         $sheet->setCellValue('B1''Dossier');
  856.         $sheet->setCellValue('C1''Id Contrat');
  857.         $sheet->setCellValue('D1''Nom');
  858.         $sheet->setCellValue('E1''Prenom');
  859.         $sheet->setCellValue('F1''Cin');
  860.         $sheet->setCellValue('G1''Prelevement');
  861.         $sheet->setCellValue('H1''Element');
  862.         $sheet->setCellValue('I1''nombre de mois');
  863.         $sheet->setCellValue('J1''Montant');
  864.         $sheet->setCellValue('K1''Montant echeance');
  865.         $sheet->setCellValue('L1''Periode');
  866.         $sheet->setCellValue('M1''active');
  867.         $sheet->setCellValue('N1''Montant');
  868.         $sheet->setCellValue('O1''Bulletin');
  869.         // $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
  870.         // $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
  871.         $findPrelevement=['active' => true];
  872.         if($dossier->getId() != 47) {
  873.             $findPrelevement ['dossier'] = $dossier;
  874.         }
  875.         // dd($findPrelevement);
  876.         $prelevements $this->em->getRepository(PPrelevement::class)->findBy($findPrelevement);
  877.         // dd($bulletinLgs);
  878.         $i 2;
  879.         foreach ($prelevements as $key => $prelevement) {
  880.             foreach ($prelevement->getPrelevementLgs() as $key => $prelevementLg) {
  881.                 $bulletin $prelevementLg->getBulletin();
  882.                 $sheet->setCellValue('A' $i$prelevement->getContract()->getDossier()->getId());
  883.                 $sheet->setCellValue('B' $i$prelevement->getContract()->getDossier()->getAbreviation());
  884.                 $sheet->setCellValue('C' $i$prelevement->getContract()->getId());
  885.                 $sheet->setCellValue('D' $i$prelevement->getContract()->getEmploye()->getNom());
  886.                 $sheet->setCellValue('E' $i$prelevement->getContract()->getEmploye()->getPrenom());
  887.                 $sheet->setCellValue('F' $i$prelevement->getContract()->getEmploye()->getCin());
  888.                 $sheet->setCellValue('G' $i$prelevement->getCode());
  889.                 $sheet->setCellValue('H' $i$prelevement->getRubrique()->getDesignation());
  890.                 $sheet->setCellValue('I' $i$prelevement->getNombreMois());
  891.                 $sheet->setCellValue('J' $i$prelevement->getMontant());
  892.                 $sheet->setCellValue('K' $i$prelevement->getMontantEcheance());
  893.                 $sheet->setCellValue('L' $i$prelevementLg->getPeriode()->getCode());
  894.                 $sheet->setCellValue('M' $i$prelevementLg->isActive());
  895.                 $sheet->setCellValue('N' $i$prelevementLg->getMontant());
  896.                 $sheet->setCellValue('O' $i$prelevementLg->getBulletin() ? $prelevementLg->getBulletin()->getCode() : '');
  897.                 $i++;
  898.             }
  899.         }
  900.         $writer = new Xlsx($spreadsheet);
  901.         $fileName 'prelevements.xlsx';
  902.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  903.         $writer->save($temp_file);
  904.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  905.     }
  906.     #[Route('/app_reporting_extraction_cnss_b04/{periode}'name'app_reporting_extraction_cnss_b04'options: ['expose' => true])]
  907.     public function app_reporting_extraction_cnss_b04(Request $request$periode): Response
  908.     {
  909.         $periode str_replace('-'''$periode);
  910.         $spreadsheet = new Spreadsheet();
  911.         $sheet $spreadsheet->getActiveSheet();
  912.         $sheet->setCellValue('A1''Cin');
  913.         $sheet->setCellValue('B1''Id Contrat');
  914.         $sheet->setCellValue('C1''type_enreg');
  915.         $sheet->setCellValue('D1''num_affilie');
  916.         $sheet->setCellValue('E1''periode');
  917.         $sheet->setCellValue('F1''num_assure');
  918.         $sheet->setCellValue('G1''nom_prenom');
  919.         $sheet->setCellValue('H1''num_cin');
  920.         $sheet->setCellValue('I1''nbr_jours');
  921.         $sheet->setCellValue('J1''sal_reel');
  922.         $sheet->setCellValue('K1''sal_plaf');
  923.         $sheet->setCellValue('L1''s_ctr');
  924.         $sheet->setCellValue('M1''filler');
  925.         $sheet->setCellValue('N1''site');
  926.         $sheet->setCellValue('O1''montant reel');
  927.         $sheet->setCellValue('P1''montant plaf');
  928.         // $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
  929.         // $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
  930.         $tcnss00s $this->em->getRepository(TCnssA00::class)->findBy(['active' => true'periode' => $periode]);
  931.         $tcnssb00s $this->em->getRepository(TCnssB00::class)->findBy(['cnssa00' => $tcnss00s]);
  932.         // dd($tcnssb00s);
  933.         $i 2;
  934.         foreach ($tcnssb00s as $key => $tcnssb00) {
  935.             foreach ($tcnssb00->getTCnssB04s() as $key => $tcnssB04) {
  936.                 $sheet->setCellValue('A' $i$tcnssB04->getContract() ? $tcnssB04->getContract()->getEmploye()->getCin() : '');
  937.                 $sheet->setCellValue('B' $i$tcnssB04->getContract() ? $tcnssB04->getContract()->getId() : '');
  938.                 $sheet->setCellValue('C' $i$tcnssB04->getTypeEnreg());
  939.                 $sheet->setCellValue('D' $i$tcnssB04->getNumAffilie());
  940.                 $sheet->setCellValue('E' $i$tcnssB04->getPeriode());
  941.                 $sheet->setCellValue('F' $i$tcnssB04->getNumAssure());
  942.                 $sheet->setCellValue('G' $i$tcnssB04->getNomPrenom());
  943.                 $sheet->setCellValue('H' $i$tcnssB04->getNumCin());
  944.                 $sheet->setCellValue('I' $i$tcnssB04->getNbrJours());
  945.                 $sheet->setCellValue('J' $i$tcnssB04->getSalReel());
  946.                 $sheet->setCellValue('K' $i$tcnssB04->getSalPlaf());
  947.                 $sheet->setCellValue('L' $i$tcnssB04->getSCtr());
  948.                 $sheet->setCellValue('M' $i$tcnssB04->getFiller());
  949.                 $sheet->setCellValue('N' $i$tcnssB04->getSite());
  950.                 $sheet->setCellValue('O' $i$tcnssB04->getMontantReel());
  951.                 $sheet->setCellValue('P' $i$tcnssB04->getMontantPlaf());
  952.                 $i++;
  953.             }
  954.         }
  955.         $writer = new Xlsx($spreadsheet);
  956.         $fileName 'cnssb04_' $periode '.xlsx';
  957.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  958.         $writer->save($temp_file);
  959.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  960.     }
  961.     #[Route('/app_reporting_extraction_cnss_b02/{periode}'name'app_reporting_extraction_cnss_b02'options: ['expose' => true])]
  962.     public function app_reporting_extraction_cnss_b02(Request $request$periode): Response
  963.     {
  964.         $periode str_replace('-'''$periode);
  965.         $spreadsheet = new Spreadsheet();
  966.         $sheet $spreadsheet->getActiveSheet();
  967.         $sheet->setCellValue('A1''Cin');
  968.         $sheet->setCellValue('B1''Id Contrat');
  969.         $sheet->setCellValue('C1''type_enreg');
  970.         $sheet->setCellValue('D1''num_affilie');
  971.         $sheet->setCellValue('E1''periode');
  972.         $sheet->setCellValue('F1''num_assure');
  973.         $sheet->setCellValue('G1''nom_prenom');
  974.         $sheet->setCellValue('H1''enfants');
  975.         $sheet->setCellValue('I1''af_apayer');
  976.         $sheet->setCellValue('J1''af_adeduire');
  977.         $sheet->setCellValue('K1''af_net_apayer');
  978.         $sheet->setCellValue('L1''af_areverser');
  979.         $sheet->setCellValue('M1''n_jours_declares');
  980.         $sheet->setCellValue('N1''n_salaire_reel');
  981.         $sheet->setCellValue('O1''n_salaire_plaf');
  982.         $sheet->setCellValue('P1''l_situation');
  983.         $sheet->setCellValue('Q1''l_situation_num');
  984.         $sheet->setCellValue('R1''s_ctr');
  985.         $sheet->setCellValue('S1''filler');
  986.         $sheet->setCellValue('T1''site');
  987.         $sheet->setCellValue('U1''statut');
  988.         $sheet->setCellValue('V1''montant reel');
  989.         $sheet->setCellValue('W1''montant plaf');
  990.         // $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
  991.         // $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
  992.         $tcnss00s $this->em->getRepository(TCnssA00::class)->findBy(['active' => true'periode' => $periode]);
  993.         $tcnssb00s $this->em->getRepository(TCnssB00::class)->findBy(['cnssa00' => $tcnss00s]);
  994.         // dd($tcnssb00s);
  995.         $i 2;
  996.         foreach ($tcnssb00s as $key => $tcnssb00) {
  997.             foreach ($tcnssb00->getTCnssB02s() as $key => $tcnssB02) {
  998.                 $sheet->setCellValue('A' $i$tcnssB02->getContract() ? $tcnssB02->getContract()->getEmploye()->getCin() : '');
  999.                 $sheet->setCellValue('B' $i$tcnssB02->getContract() ? $tcnssB02->getContract()->getId() : '');
  1000.                 $sheet->setCellValue('C' $i$tcnssB02->getTypeEnreg());
  1001.                 $sheet->setCellValue('D' $i$tcnssB02->getNumAffilie());
  1002.                 $sheet->setCellValue('E' $i$tcnssB02->getPeriode());
  1003.                 $sheet->setCellValue('F' $i$tcnssB02->getNumAssure());
  1004.                 $sheet->setCellValue('G' $i$tcnssB02->getNomPrenom());
  1005.                 $sheet->setCellValue('H' $i$tcnssB02->getEnfants());
  1006.                 $sheet->setCellValue('I' $i$tcnssB02->getAfApayer());
  1007.                 $sheet->setCellValue('J' $i$tcnssB02->getAfAdeduire());
  1008.                 $sheet->setCellValue('K' $i$tcnssB02->getAfNetApayer());
  1009.                 $sheet->setCellValue('L' $i$tcnssB02->getAfAreverser());
  1010.                 $sheet->setCellValue('M' $i$tcnssB02->getNJoursDeclares());
  1011.                 $sheet->setCellValue('N' $i$tcnssB02->getNSalaireReel());
  1012.                 $sheet->setCellValue('O' $i$tcnssB02->getNSalairePlaf());
  1013.                 $sheet->setCellValue('P' $i$tcnssB02->getLSituation());
  1014.                 $sheet->setCellValue('Q' $i$tcnssB02->getLSituationNum());
  1015.                 $sheet->setCellValue('R' $i$tcnssB02->getSCtr());
  1016.                 $sheet->setCellValue('S' $i$tcnssB02->getFiller());
  1017.                 $sheet->setCellValue('T' $i$tcnssB02->getSite());
  1018.                 $sheet->setCellValue('U' $i$tcnssB02->getStatut());
  1019.                 $sheet->setCellValue('V' $i$tcnssB02->getMontantReel());
  1020.                 $sheet->setCellValue('W' $i$tcnssB02->getMontantPlaf());
  1021.                 $i++;
  1022.             }
  1023.         }
  1024.         $writer = new Xlsx($spreadsheet);
  1025.         $fileName 'cnssb02_' $periode '.xlsx';
  1026.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  1027.         $writer->save($temp_file);
  1028.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1029.     }
  1030.     #[Route('/app_reporting_extraction_input'name'app_reporting_extraction_input'options: ['expose' => true])]
  1031.     public function app_reporting_extraction_input(Request $requestHttpClientInterface $client): Response
  1032.     {
  1033.         try {
  1034.             $response $client->request('GET'"http://52.213.254.104/api/rh/cab/extraction", [
  1035.                 'verify_peer' => false,
  1036.                 'verify_host' => false,
  1037.                 'timeout' => 30
  1038.             ]);        
  1039.             if($response->getStatusCode() === 200) {
  1040.                 $result $response->toArray();
  1041.                 return new JsonResponse($result);
  1042.             }
  1043.             throw new \Exception($response->getContent(false));
  1044.         } catch (\Throwable $th) {
  1045.             return new JsonResponse($th->getMessage(), 500);
  1046.         }
  1047.        
  1048.     }
  1049.     
  1050.     #[Route('/app_reporting_extraction_etat_paie_cnss/{periode}/{dossier}'name'app_reporting_extraction_etat_paie_cnss'options: ['expose' => true])]
  1051.     public function app_reporting_extraction_etat_paie_cnss($periodePDossier $dossier): Response
  1052.     {
  1053.         $date = new \DateTime($periode);
  1054.         $periode $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
  1055.         $bulletins $this->em->createQueryBuilder()
  1056.             ->select('b')
  1057.             ->from(Tbulletin::class, 'b')
  1058.             ->innerJoin('b.contract''contract')
  1059.             ->innerJoin('contract.pnatureContract''natureType')
  1060.             ->innerJoin('natureType.type''type')
  1061.             ->where('b.active = 1 ')
  1062.             ->andWhere('b.piece = 1')
  1063.             ->andWhere('type.id = 1')
  1064.             ->andWhere('b.periode = :periode')
  1065.             ->andWhere('b.dossier = :dossier')
  1066.             ->setParameter('dossier'$dossier)
  1067.             ->setParameter('periode'$periode)
  1068.             ->getQuery()
  1069.             ->getResult();
  1070.         // dd($bulletins);
  1071.         $results = [];
  1072.         foreach ($bulletins as $bulletin) {
  1073.             $result['bulletin_id'] = $bulletin->getId();
  1074.             $result['periode'] = $bulletin->getPeriode()->getCode();
  1075.             $result['contract_id'] = $bulletin->getContract()->getId();
  1076.             $result['employe'] =  $bulletin->getContract()->getEmploye()->getNom() . ' ' $bulletin->getContract()->getEmploye()->getPrenom();
  1077.             $bulletinLgs $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin'active' => true'rubrique' => [12475051525354555658]]);
  1078.             $result['details']['salaireImpo']=  0;
  1079.             $result['details']['cnssPS']=  0;
  1080.             $result['details']['cnssPP']=  0;
  1081.             foreach ($bulletinLgs as  $bulletinLg) {
  1082.                 $rubrique $bulletinLg->getRubrique()->getId();
  1083. //                 if (!isset($result['details'])) {
  1084. //                     $result['details'] = [
  1085. //                         'salaireImpo' => 0,
  1086. //                         'cnssPS' => 0,
  1087. //                         'cnssPP' => 0,
  1088. //                     ];
  1089. //                 }
  1090.                 if ($rubrique === || $rubrique === 2) {
  1091.                     $result['details']['salaireImpo'] += $bulletinLg->getMontant();
  1092.                 } elseif ($rubrique === 47 || $rubrique === 53) {
  1093.                     $result['details']['cnssPS'] += $bulletinLg->getMontant();
  1094.                     $totalCnss $bulletinLg->getMontant();
  1095.                 } elseif ($rubrique === 56 || $rubrique === 58) {
  1096.                     $result['details']['cnssPP'] += $bulletinLg->getMontant();
  1097.                     $totalCnss $bulletinLg->getMontant();
  1098.                 } else {
  1099.                     $result['details']['fraisCnss_' $rubrique] = $bulletinLg->getMontant();
  1100.                 }
  1101.             }
  1102.             if ($result['details']['salaireImpo'] > 6000) {
  1103.                 $result['details']['salaireImpoPlafond'] = 6000;
  1104.             } else {
  1105.                 $result['details']['salaireImpoPlafond'] = $result['details']['salaireImpo'];
  1106.             }
  1107.             array_push($results$result);
  1108.         }
  1109.         // dd($results);
  1110.         // dd($bulletinLgs);
  1111.         $html $this->render("reporting/extraction/pdf/cnss.html.twig", [
  1112.             'periode' => $periode,
  1113.             'dossier' => $dossier,
  1114.             'date' => $date,
  1115.             'results' => $results
  1116.         ])->getContent();
  1117.         $mpdf = new Mpdf([
  1118.             'mode' => 'utf-8',
  1119.             'margin_left' => '5',
  1120.             'margin_right' => '5',
  1121.             'format' => 'A4-L',
  1122.             'margin_header' => 5,
  1123.             'margin_top' => 5,
  1124.         ]);
  1125.         $mpdf->SetHTMLFooter("<footer class='center'>
  1126.                                 <table width='100%'>
  1127.                                   <tr>
  1128.                                       <td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
  1129.                                       <td width='33%' style='text-align: center;'>" date("d/m/y") . "</td>
  1130.                                   </tr>
  1131.                                 </table>
  1132.                               </footer>");
  1133.         $mpdf->SetTitle('CNSS');
  1134.         $mpdf->WriteHTML($html);
  1135.         $mpdf->Output("CNSS_" $dossier->getAbreviation() . "_" $date->format('mY') . ".pdf""I");
  1136.     }
  1137.     #[Route('/app_reporting_extraction_etat_paie_cimr/{periode}/{dossier}'name'app_reporting_extraction_etat_paie_cimr'options: ['expose' => true])]
  1138.     public function app_reporting_extraction_etat_paie_cimr($periodePDossier $dossier): Response
  1139.     {
  1140.         $date = new \DateTime($periode);
  1141.         $periode $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
  1142.         $bulletins $this->em->createQueryBuilder()
  1143.             ->select('b')
  1144.             ->from(Tbulletin::class, 'b')
  1145.             ->innerJoin('b.contract''contract')
  1146.             ->innerJoin('contract.pnatureContract''natureType')
  1147.             ->innerJoin('natureType.type''type')
  1148.             ->where('b.active = 1 ')
  1149.             ->andWhere('b.piece = 1')
  1150.             ->andWhere('type.id = 1')
  1151.             ->andWhere('b.periode = :periode')
  1152.             ->andWhere('b.dossier = :dossier')
  1153.             ->setParameter('dossier'$dossier)
  1154.             ->setParameter('periode'$periode)
  1155.             ->getQuery()
  1156.             ->getResult();
  1157.         // dd($bulletins);
  1158.         $results = [];
  1159.         foreach ($bulletins as $bulletin) {
  1160.             $result['bulletin_id'] = $bulletin->getId();
  1161.             $result['periode'] = $bulletin->getPeriode()->getCode();
  1162.             $result['contract_id'] = $bulletin->getContract()->getId();
  1163.             $result['employe'] =  $bulletin->getContract()->getEmploye()->getNom() . ' ' $bulletin->getContract()->getEmploye()->getPrenom();
  1164.             $bulletinLgs $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin'active' => true'rubrique' => [124857]]);
  1165.             $totalCimr 0;
  1166.             $result['details']['salaireImpo']=  0;
  1167.             foreach ($bulletinLgs as  $bulletinLg) {
  1168.                 $rubrique $bulletinLg->getRubrique()->getId();
  1169. //                 if (!isset($result['details'])) {
  1170. //                     $result['details'] = [
  1171. //                         'salaireImpo' => 0
  1172. //                     ];
  1173. //                 }
  1174.                 if ($rubrique === || $rubrique === 2) {
  1175.                     $result['details']['salaireImpo'] += $bulletinLg->getMontant();
  1176.                 } else {
  1177.                     
  1178.                     $baremeCimrs=$bulletin->getContract()->getBareme()->getPbaremeCimrs();
  1179.                     foreach ($baremeCimrs as $baremeCimr) {
  1180.                         if( $baremeCimr->getRubrique()->getId()== $rubrique){
  1181.                             $result['details']['taux_' $rubrique] = $baremeCimr->getTaux();
  1182.                             // dd($baremeCimr->getTaux());
  1183.                         }
  1184.                     }
  1185.                     $result['details']['fraisCimr_' $rubrique] = $bulletinLg->getMontant();
  1186.                     $totalCimr += $bulletinLg->getMontant();
  1187.                     
  1188.                 }
  1189.             }
  1190.             $result['details']['totalCimr'] = $totalCimr;
  1191.             array_push($results$result);
  1192.         }
  1193.         // dd($results);
  1194.         $html $this->render("reporting/extraction/pdf/cimr.html.twig", [
  1195.             'periode' => $periode,
  1196.             'dossier' => $dossier,
  1197.             'date' => $date,
  1198.             'results' => $results
  1199.         ])->getContent();
  1200.         $mpdf = new Mpdf([
  1201.             'mode' => 'utf-8',
  1202.             'margin_left' => '5',
  1203.             'margin_right' => '5',
  1204.             'format' => 'A4-L',
  1205.             'margin_header' => 5,
  1206.             'margin_top' => 5,
  1207.         ]);
  1208.         $mpdf->SetHTMLFooter("<footer class='center'>
  1209.                                   <table width='100%'>
  1210.                                     <tr>
  1211.                                         <td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
  1212.                                         <td width='33%' style='text-align: center;'>" date("d/m/y") . "</td>
  1213.                                     </tr>
  1214.                                   </table>
  1215.                               </footer>");
  1216.         $mpdf->SetTitle('CIMR');
  1217.         $mpdf->WriteHTML($html);
  1218.         $mpdf->Output("CIMR_" $dossier->getAbreviation() . "_" $date->format('mY') . ".pdf""I");
  1219.     }
  1220.     #[Route('/app_reporting_extraction_etat_paie_ir/{periode}/{dossier}/{natureType}'name'app_reporting_extraction_etat_paie_ir'options: ['expose' => true])]
  1221.     public function app_reporting_extraction_etat_paie_ir($periodePDossier $dossierPnatureContract $natureType): Response
  1222.     {
  1223.         $date = new \DateTime($periode);
  1224.         $periode $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
  1225.         $bulletins $this->em->createQueryBuilder()
  1226.             ->select('b')
  1227.             ->from(Tbulletin::class, 'b')
  1228.             ->innerJoin('b.contract''contract')
  1229.             // ->innerJoin('contract.pnatureContract', 'natureType')
  1230.             // ->innerJoin('natureType.type', 'type')
  1231.             ->where('b.active = 1 ')
  1232.             ->andWhere('b.piece = 1')
  1233.             ->andWhere('contract.pnatureContract = :natureType')
  1234.             // ->andWhere('type.id = 1')
  1235.             ->andWhere('b.periode = :periode')
  1236.             ->andWhere('b.dossier = :dossier')
  1237.             ->setParameter('dossier'$dossier)
  1238.             ->setParameter('periode'$periode)
  1239.             ->setParameter('natureType'$natureType)
  1240.             ->getQuery()
  1241.             ->getResult();
  1242.         // dd($bulletins);
  1243.         $results = [];
  1244.         foreach ($bulletins as $bulletin) {
  1245.             $result['bulletin_id'] = $bulletin->getId();
  1246.             $result['periode'] = $bulletin->getPeriode()->getCode();
  1247.             $result['contract_id'] = $bulletin->getContract()->getId();
  1248.             $result['employe'] =  $bulletin->getContract()->getEmploye()->getNom() . ' ' $bulletin->getContract()->getEmploye()->getPrenom();
  1249.             if ($natureType->getType()->getId() === 1) {
  1250.                 $bulletinLgs $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin'active' => true'rubrique' => [1243]]);
  1251.                 foreach ($bulletinLgs as  $bulletinLg) {
  1252.                     $rubrique $bulletinLg->getRubrique()->getId();
  1253.                     if (!isset($result['details'])) {
  1254.                         $result['details'] = [
  1255.                             'salaireImpo' => 0
  1256.                         ];
  1257.                     }
  1258.                     if ($rubrique === || $rubrique === 2) {
  1259.                         $result['details']['salaireImpo'] += $bulletinLg->getMontant();
  1260.                     } else{
  1261.                         $result['details']['ir_43'] = $bulletinLg->getMontant();
  1262.                     }
  1263.                     $result['details']['fraisProf'] = $result['details']['salaireImpo'] * 0.2;
  1264.                     $montantCotisationTotale $this->em->createQueryBuilder()
  1265.                         ->select('sum(TbulletinLg.montant) as montant')
  1266.                         ->from(TbulletinLg::class, 'TbulletinLg')
  1267.                         ->innerJoin('TbulletinLg.bulletin''bulletin')
  1268.                         ->innerJoin('TbulletinLg.rubrique''rubrique')
  1269.                         ->andWhere('rubrique.id  in(50, 47, 53, 48)')
  1270.                         ->andWhere('TbulletinLg.active = 1')
  1271.                         ->andWhere('bulletin.id = :bulletin')
  1272.                         ->setParameter('bulletin'$bulletin)
  1273.                         ->getQuery()
  1274.                         ->getOneOrNullResult();
  1275.                     $result['details']['salaireNetImpo'] = $result['details']['salaireImpo'] - ($montantCotisationTotale['montant'] + ($result['details']['fraisProf']));
  1276.                 }
  1277.             } else {
  1278.                 $bulletinLgs $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin'active' => true'rubrique' => [656843]]);
  1279.                 foreach ($bulletinLgs as  $bulletinLg) {
  1280.                     $rubrique $bulletinLg->getRubrique()->getId();
  1281.                     $result['details']['ir_' $rubrique] = $bulletinLg->getMontant();
  1282.                 }
  1283.                 $prelevement $this->em->createQueryBuilder()
  1284.                     ->select('sum(TbulletinLg.montant) as montant')
  1285.                     ->from(TbulletinLg::class, 'TbulletinLg')
  1286.                     ->innerJoin('TbulletinLg.bulletin''bulletin')
  1287.                     ->innerJoin('TbulletinLg.rubrique''rubrique')
  1288.                     ->andWhere('rubrique.prets = 1')
  1289.                     ->andWhere('TbulletinLg.active = 1')
  1290.                     ->andWhere('bulletin.id = :bulletin')
  1291.                     ->setParameter('bulletin'$bulletin)
  1292.                     ->getQuery()
  1293.                     ->getOneOrNullResult();
  1294.                 if (!($prelevement['montant'])) {
  1295.                     // dd('h');
  1296.                     $result['details']['prets'] = 0;
  1297.                 } else {
  1298.                     $result['details']['prets'] = $prelevement['montant'];
  1299.                 }
  1300.             }
  1301.             array_push($results$result);
  1302.         }
  1303.         // dd($results);
  1304.         $html $this->render("reporting/extraction/pdf/ir.html.twig", [
  1305.             'periode' => $periode,
  1306.             'dossier' => $dossier,
  1307.             'date' => $date,
  1308.             'results' => $results,
  1309.             'nature' => $natureType
  1310.         ])->getContent();
  1311.         $mpdf = new Mpdf([
  1312.             'mode' => 'utf-8',
  1313.             'margin_left' => '5',
  1314.             'margin_right' => '5',
  1315.             'format' => 'A4-L',
  1316.             'margin_header' => 5,
  1317.             'margin_top' => 5,
  1318.         ]);
  1319.         $mpdf->SetHTMLFooter("<footer class='center'>
  1320.                                    <table width='100%'>
  1321.                                      <tr>
  1322.                                          <td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
  1323.                                          <td width='33%' style='text-align: center;'>" date("d/m/y") . "</td>
  1324.                                      </tr>
  1325.                                    </table>
  1326.                                </footer>");
  1327.         $mpdf->SetTitle('IR');
  1328.         $mpdf->WriteHTML($html);
  1329.         $mpdf->Output("IR_" $dossier->getAbreviation() . "_" $natureType->getDesignation() . "_" $date->format('mY') . ".pdf""I");
  1330.     }
  1331.     #[Route('/pdf_etat_recapitulatif/{periode}/{dossier}/{natureType}'name'app_extraction_recapitulatif_pdf'options: ['expose' => true])]
  1332.     public function pdf_honoraire(Request $request,$periode,PDossier $dossier,PnatureContract $natureType): Response
  1333.     {
  1334.         // dd($natureType);
  1335.         $date = new \DateTime($periode);
  1336.         $periode $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
  1337.         if($natureType->getType()->getId() === 1){
  1338.             $queryBuilder $this->em->createQueryBuilder()
  1339.             ->select('sum(bl.montant) as Montant,r.id as rubrique,r.designation as element,
  1340.             p.date,d.abreviation as dossier,
  1341.             CASE WHEN r.id in (37,33, 37, 38,39,77,78,79,80,84,85) THEN 4 ELSE SUBSTRING(pc.compteComptable, 1, 1) END as compteComptable,
  1342.             r.code,r.designation')
  1343.                 ->from(Tbulletin::class, 'tb')
  1344.                 ->innerJoin('tb.bulletinLgs''bl')
  1345.                 ->innerJoin('tb.piece''piece')
  1346.                 ->innerJoin('tb.bordereau''b')
  1347.                 ->innerJoin('b.natureContract''n')
  1348.                 ->innerJoin('bl.rubrique''r')
  1349.                 ->innerJoin('tb.periode''p')
  1350.                 ->innerJoin('tb.dossier''d')
  1351.                 ->innerJoin('r.compteComptables''pc')
  1352.                 ->where('n.id =:natureType')
  1353.                 ->andWhere('pc.natureContract = :natureType')
  1354.                 ->andWhere('tb.periode = :periode')
  1355.                 ->andWhere('tb.dossier = :dossier')
  1356.                 ->andWhere('bl.montant != 0')
  1357.                 ->andWhere('tb.active = 1')
  1358.                 ->andWhere('b.active = 1')
  1359.                 ->andWhere('piece.id in( 1,2)')
  1360.                 ->andWhere('bl.active = 1')
  1361.                 ->andWhere('r.id NOT IN (51, 52, 54, 55, 56, 57, 58)')
  1362.                 ->setParameter('dossier'$dossier)
  1363.                 ->setParameter('periode'$periode)
  1364.                 ->setParameter('natureType'$natureType)
  1365.                 ->groupBy('r.id')
  1366.                 ->orderBy('compteComptable''DESC');
  1367.         }else{
  1368.             $queryBuilder $this->em->createQueryBuilder()
  1369.             ->select('sum(bl.montant) as Montant,r.id as rubrique,r.designation as element,
  1370.             p.date,d.abreviation as dossier,
  1371.             CASE WHEN r.id in (37,33, 37, 38,39,77,78,79,80,84,85) THEN 4 ELSE SUBSTRING(pc.compteComptable, 1, 1) END as compteComptable,
  1372.             r.code,r.designation')
  1373.                 ->from(Tbulletin::class, 'tb')
  1374.                 ->innerJoin('tb.bulletinLgs''bl')
  1375.                 ->innerJoin('tb.piece''piece')
  1376.                 ->innerJoin('tb.bordereau''b')
  1377.                 ->innerJoin('b.natureContract''n')
  1378.                 ->innerJoin('bl.rubrique''r')
  1379.                 ->innerJoin('tb.periode''p')
  1380.                 ->innerJoin('tb.dossier''d')
  1381.                 ->innerJoin('r.compteComptables''pc')
  1382.                 ->innerJoin('tb.contract''contract')
  1383.                 ->innerJoin('contract.bareme''bareme')
  1384.                 ->where('n.id =:natureType')
  1385.                 ->andWhere('pc.natureContract = :natureType')
  1386.                 ->andWhere('tb.periode = :periode')
  1387.                 ->andWhere('tb.dossier = :dossier')
  1388.                 ->andWhere('bl.montant != 0')
  1389.                 ->andWhere('tb.active = 1')
  1390.                 ->andWhere('b.active = 1')
  1391.                 ->andWhere('piece.id in( 1,2)')
  1392.                 ->andWhere('bl.active = 1')
  1393.                 ->andWhere('r.id NOT IN (51, 52, 54, 55, 56, 57, 58,1,16)')
  1394.                 ->andWhere('bareme.baremeType IN (1,2)')
  1395.                 ->setParameter('dossier'$dossier)
  1396.                 ->setParameter('periode'$periode)
  1397.                 ->setParameter('natureType'$natureType)
  1398.                 ->groupBy('r.id')
  1399.                 ->orderBy('compteComptable''DESC');
  1400.         }
  1401.         
  1402.         $results $queryBuilder->getQuery()->getResult();
  1403.         //  dd($queryBuilder);
  1404.         // $date = $results[0]['date'];
  1405.         $date->modify('last day of this month'); //30-09-2023
  1406.         $html $this->render("reporting/extraction/pdf/recapitulatif.html.twig", [
  1407.             'results' => $results'date' => $date'dossier' => $dossier
  1408.         ])->getContent();
  1409.         $mpdf = new Mpdf([
  1410.             'mode' => 'utf-8',
  1411.             'margin_left' => '5',
  1412.             'margin_right' => '5',
  1413.         ]);
  1414.         $mpdf->SetTitle('Etat_RECAPITULATIF');
  1415.         // $mpdf->SetHTMLFooter(
  1416.         //     $this->render("planification/pdfs/footer.html.twig")->getContent()
  1417.         // );
  1418.         $mpdf->WriteHTML($html);
  1419.         $mpdf->Output("Etat_RECAPITULATIF"$dossier->getAbreviation() . "_" $date->format('mY') . "_" $natureType->getDesignation().".pdf""I");
  1420.     }
  1421.     #[Route('/app_reporting_extraction_etat_pret/{periode}/{dossier}/{rubrique}'name'app_reporting_extraction_etat_pret'options: ['expose' => true])]
  1422.     public function app_reporting_extraction_etat_pret($periodePDossier $dossierPrubrique $rubrique): Response
  1423.     {
  1424.         $date = new \DateTime($periode);
  1425.         $periode $this->em->getRepository(periode::class)->findOneBy(['code' => $date->format('mY')]);
  1426.         //  dd($periode,$rubrique,$dossier);
  1427.         $bulletinLgs $this->em->createQueryBuilder()
  1428.             ->select('lg')
  1429.             ->from(TbulletinLg::class, 'lg')
  1430.             ->innerJoin('lg.bulletin''b')
  1431.             ->where('lg.active = 1')
  1432.             ->andWhere('lg.rubrique = :rubrique ')
  1433.             ->andWhere('b.active = 1 ')
  1434.             ->andWhere('b.piece = 1')
  1435.             ->andWhere('b.periode = :periode')
  1436.             ->andWhere('b.dossier = :dossier')
  1437.             ->setParameter('dossier'$dossier)
  1438.             ->setParameter('periode'$periode)
  1439.             ->setParameter('rubrique'$rubrique)
  1440.             ->getQuery()
  1441.             ->getResult();
  1442.         //  dd($bulletinLgs[0]->getBulletin()->getContract()->getEmploye()->getNom());
  1443.         $html $this->render("reporting/extraction/pdf/pret.html.twig", [
  1444.             'periode' => $periode,
  1445.             'dossier' => $dossier,
  1446.             'date' => $date,
  1447.             'rubrique' => $rubrique,
  1448.             'bulletinLgs' => $bulletinLgs
  1449.         ])->getContent();
  1450.         $mpdf = new Mpdf([
  1451.             'mode' => 'utf-8',
  1452.             'margin_left' => '5',
  1453.             'margin_right' => '5',
  1454.             'format' => 'A4',
  1455.             'margin_header' => 5,
  1456.             'margin_top' => 5,
  1457.         ]);
  1458.         $mpdf->SetHTMLFooter("<footer class='center'>
  1459.                                 <table width='100%'>
  1460.                                   <tr>
  1461.                                       <td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
  1462.                                       <td width='33%' style='text-align: center;'>" date("d/m/y") . "</td>
  1463.                                   </tr>
  1464.                                 </table>
  1465.                               </footer>");
  1466.         $mpdf->SetTitle('pret');
  1467.         $mpdf->WriteHTML($html);
  1468.         $mpdf->Output("pret_" $dossier->getAbreviation() . "_" $date->format('mY') . "_" $rubrique->getDesignation() . ".pdf""I");
  1469.     }
  1470.     #[Route('/app_reporting_extraction_synthese_paie/{periode}/{groupement}/{devise}'name'app_reporting_extraction_synthese_paie'options: ['expose' => true])]
  1471.     public function app_reporting_extraction_synthese_paie($periode,$groupement,$devise): Response
  1472.     {   
  1473.         $date = new \DateTime($periode);
  1474.         $previousMonth=$date->modify('-1 month')->format('mY');
  1475.         $date = new \DateTime($periode);
  1476.         $currentMonth=$date->format('mY');
  1477.         $dossier=$this->em->getRepository(pdossier::class)->findOneBy(['groupement' => $groupement]);
  1478.         // dd($date,$previousMonth,$currentMonth,$devise);
  1479.         
  1480.         $currentperiode $this->em->getRepository(periode::class)->findOneBy(['code' => $currentMonth]);
  1481.         $previousPeriode $this->em->getRepository(periode::class)->findOneBy(['code' => $previousMonth]);
  1482.         $periode $this->em->getRepository(periode::class)->findBy(['code' => [$previousMonth,$currentMonth]]);
  1483.         
  1484.         // dd($periode);
  1485.         if($groupement=='FCZ'){
  1486.             $designationGrp='FONDATION CHEIKH ZAID';
  1487.         }elseif ($groupement=='RGA'){
  1488.             $designationGrp='AFRIC-MED REPARTITEUR GROSSISTE';
  1489.         }elseif ($groupement=='SSS'){
  1490.             $designationGrp='SOCIETE AFRICAINE DES SERVICES DE LA SANTE - METIERS';
  1491.         }
  1492.         elseif ($groupement=='SST'){
  1493.             $designationGrp='SOCIETE AFRICAINE DES SERVICES DE LA SANTE - TRAVAUX';
  1494.         } 
  1495.         $details['groupement']=$groupement;
  1496.         $details['designationGrp']=$designationGrp;
  1497.         $details['date']=$date;
  1498.         $details['periode']=$periode;
  1499.         $details['dossier']=$dossier;
  1500.         $paieEffectif=$paieMontant=$indeminiteEffectif=$indeminiteMontant=$honoraireEffectif=$honoraireMontant=$stcEffectif=$stcMontant=$totalM1Effectif=$totalM1Montant=$totalMEffectif=$totalMMontant=0;
  1501.         $natureContracts =  $this->em->createQueryBuilder()
  1502.             ->select('distinct  natureContract.id,natureContract.designation as nature_contract,d.groupement')
  1503.             ->from(TbulletinLg::class, 'lg')
  1504.             ->innerJoin('lg.bulletin''b')
  1505.             ->innerJoin('b.dossier''d')
  1506.             ->innerJoin('b.bordereau''bordereau')
  1507.             ->innerJoin('bordereau.natureContract''natureContract')
  1508.             ->innerJoin('b.periode''periode')
  1509.             ->where('lg.active = 1')
  1510.             ->andWhere('b.active = 1')
  1511.             ->andWhere('bordereau.active = 1 ')
  1512.             ->andWhere('lg.rubrique in (5,68) ')
  1513.             ->andWhere('b.periode in( :periode)')
  1514.             ->andWhere('d.groupement = :groupement')
  1515.             ->setParameter('groupement'$groupement)
  1516.             ->setParameter('periode'$periode);
  1517.             $natureContracts $this->applyDeviseFilter($natureContracts$devise)
  1518.                                 ->orderBy('natureContract.id''ASC')
  1519.                                 ->getQuery()
  1520.                                 ->getResult();
  1521.         foreach ($natureContracts as $key => $natureContract) {
  1522.             $results[$key]['natureContrat']=$natureContract['nature_contract'];
  1523.             
  1524.             $totalEffectif=0;
  1525.             $totalMontant=0;
  1526.             $paie=$this->em->createQueryBuilder()
  1527.             ->select('count(contract.id) as effectif,sum(lg.montant) as montant')
  1528.             ->from(TbulletinLg::class, 'lg')
  1529.             ->innerJoin('lg.bulletin''b')
  1530.             ->innerJoin('b.dossier''d')
  1531.             ->innerJoin('b.piece''piece')
  1532.             ->innerJoin('b.contract''contract')
  1533.             ->innerJoin('b.bordereau''bordereau')
  1534.             ->innerJoin('bordereau.natureContract''natureContract')
  1535.             ->innerJoin('b.periode''periode')
  1536.             ->where('lg.active = 1')
  1537.             ->andWhere('b.active = 1')
  1538.             ->andWhere('bordereau.active = 1 ')
  1539.             ->andWhere('lg.rubrique in (5,68) ')
  1540.             ->andWhere('b.piece = 1')
  1541.             ->andWhere('b.periode in( :periode)')
  1542.             ->andWhere('d.groupement = :groupement')
  1543.             ->andWhere('natureContract.id =:natureContract')
  1544.             ->setParameter('groupement'$groupement)
  1545.             ->setParameter('natureContract'$natureContract['id'])
  1546.             ->setParameter('periode'$currentperiode);
  1547.             
  1548.             $paie $this->applyDeviseFilter($paie$devise)
  1549.                    ->getQuery()
  1550.                    ->getOneOrNullResult();
  1551.             $totalEffectif+=$results[$key]['effectifPaie']=$paie['effectif'];
  1552.             $totalMontant+=$results[$key]['montantPaie']=$paie['montant'];
  1553.             $paieEffectif+=$paie['effectif'];
  1554.             $paieMontant+=$paie['montant'];
  1555.             $indeminite=$this->em->createQueryBuilder()
  1556.             ->select('count(contract.id) as effectif,sum(lg.montant) as montant')
  1557.             ->from(TbulletinLg::class, 'lg')
  1558.             ->innerJoin('lg.bulletin''b')
  1559.             ->innerJoin('b.dossier''d')
  1560.             ->innerJoin('b.piece''piece')
  1561.             ->innerJoin('b.contract''contract')
  1562.             ->innerJoin('b.bordereau''bordereau')
  1563.             ->innerJoin('bordereau.natureContract''natureContract')
  1564.             ->innerJoin('b.periode''periode')
  1565.             ->where('lg.active = 1')
  1566.             ->andWhere('b.active = 1')
  1567.             ->andWhere('bordereau.active = 1 ')
  1568.             ->andWhere('lg.rubrique in (5,68) ')
  1569.             ->andWhere('b.piece = 3')
  1570.             ->andWhere('b.periode in( :periode)')
  1571.             ->andWhere('d.groupement = :groupement')
  1572.             ->andWhere('natureContract.id =:natureContract')
  1573.             ->setParameter('groupement'$groupement)
  1574.             ->setParameter('natureContract'$natureContract['id'])
  1575.             ->setParameter('periode'$currentperiode);
  1576.             $indeminite $this->applyDeviseFilter($indeminite$devise)
  1577.                    ->getQuery()
  1578.                    ->getOneOrNullResult();
  1579.             $totalEffectif+=$results[$key]['effectifIndeminite']=$indeminite['effectif'];
  1580.             $totalMontant+=$results[$key]['montantIndeminite']=$indeminite['montant'];
  1581.             $indeminiteEffectif+=$indeminite['effectif'];
  1582.             $indeminiteMontant+=$indeminite['montant'];
  1583.             $honoraire=$this->em->createQueryBuilder()
  1584.             ->select('count(contract.id) as effectif,sum(lg.montant) as montant')
  1585.             ->from(TbulletinLg::class, 'lg')
  1586.             ->innerJoin('lg.bulletin''b')
  1587.             ->innerJoin('b.dossier''d')
  1588.             ->innerJoin('b.piece''piece')
  1589.             ->innerJoin('b.contract''contract')
  1590.             ->innerJoin('b.bordereau''bordereau')
  1591.             ->innerJoin('bordereau.natureContract''natureContract')
  1592.             ->innerJoin('b.periode''periode')
  1593.             ->where('lg.active = 1')
  1594.             ->andWhere('b.active = 1')
  1595.             ->andWhere('bordereau.active = 1 ')
  1596.             ->andWhere('lg.rubrique in (5,68) ')
  1597.             ->andWhere('b.piece = 2')
  1598.             ->andWhere('b.periode in( :periode)')
  1599.             ->andWhere('d.groupement = :groupement')
  1600.             ->andWhere('natureContract.id =:natureContract')
  1601.             ->setParameter('groupement'$groupement)
  1602.             ->setParameter('natureContract'$natureContract['id'])
  1603.             ->setParameter('periode'$currentperiode);
  1604.             $honoraire $this->applyDeviseFilter($honoraire$devise)
  1605.                    ->getQuery()
  1606.                    ->getOneOrNullResult();
  1607.             $totalEffectif+=$results[$key]['effectifHonoraire']=$honoraire['effectif'];
  1608.             $totalMontant+=$results[$key]['montantHonoraire']=$honoraire['montant'];
  1609.             $honoraireEffectif+=$honoraire['effectif'];
  1610.             $honoraireMontant+=$honoraire['montant'];
  1611.             $stc=$this->em->createQueryBuilder()
  1612.             ->select('count(contract.id) as effectif,sum(lg.montant) as montant')
  1613.             ->from(TbulletinLg::class, 'lg')
  1614.             ->innerJoin('lg.bulletin''b')
  1615.             ->innerJoin('b.dossier''d')
  1616.             ->innerJoin('b.piece''piece')
  1617.             ->innerJoin('b.contract''contract')
  1618.             ->innerJoin('b.bordereau''bordereau')
  1619.             ->innerJoin('bordereau.natureContract''natureContract')
  1620.             ->innerJoin('b.periode''periode')
  1621.             ->where('lg.active = 1')
  1622.             ->andWhere('b.active = 1')
  1623.             ->andWhere('bordereau.active = 1 ')
  1624.             ->andWhere('lg.rubrique in (5,68) ')
  1625.             ->andWhere('b.piece = 13')
  1626.             ->andWhere('b.periode in( :periode)')
  1627.             ->andWhere('d.groupement = :groupement')
  1628.             ->andWhere('natureContract.id =:natureContract')
  1629.             ->setParameter('groupement'$groupement)
  1630.             ->setParameter('natureContract'$natureContract['id'])
  1631.             ->setParameter('periode'$currentperiode);
  1632.             $stc $this->applyDeviseFilter($stc$devise)
  1633.                    ->getQuery()
  1634.                    ->getOneOrNullResult();
  1635.             $totalEffectif+=$results[$key]['effectifStc']=$stc['effectif'];
  1636.             $totalMontant+=$results[$key]['montantStc']=$stc['montant'];
  1637.             $stcEffectif+=$stc['effectif'];
  1638.             $stcMontant+=$stc['montant'];
  1639.             $totalM1 $this->em->createQueryBuilder()
  1640.             ->select('count(contract.id) as effectif,sum(lg.montant) as montant')
  1641.             ->from(TbulletinLg::class, 'lg')
  1642.             ->innerJoin('lg.bulletin''b')
  1643.             ->innerJoin('b.dossier''d')
  1644.             ->innerJoin('b.piece''piece')
  1645.             ->innerJoin('b.contract''contract')
  1646.             ->innerJoin('b.bordereau''bordereau')
  1647.             ->innerJoin('bordereau.natureContract''natureContract')
  1648.             ->innerJoin('b.periode''periode')
  1649.             ->where('lg.active = 1')
  1650.             ->andWhere('b.active = 1')
  1651.             ->andWhere('bordereau.active = 1 ')
  1652.             ->andWhere('lg.rubrique in (5,68) ')
  1653.             ->andWhere('b.periode in( :periode)')
  1654.             ->andWhere('d.groupement = :groupement')
  1655.             ->andWhere('natureContract.id =:natureContract')
  1656.             ->setParameter('groupement'$groupement)
  1657.             ->setParameter('periode'$previousPeriode)
  1658.             ->setParameter('natureContract'$natureContract['id']);
  1659.             $totalM1 $this->applyDeviseFilter($totalM1$devise)
  1660.                    ->getQuery()
  1661.                    ->getOneOrNullResult();
  1662.             $results[$key]['effectifTotalM1']=$totalM1['effectif'];
  1663.             $results[$key]['montantTotalM1']=$totalM1['montant'];
  1664.             
  1665.             $totalM1Effectif+=$totalM1['effectif'];
  1666.             $totalM1Montant+=$totalM1['montant'];
  1667.             $results[$key]['totalEffectif']=$totalEffectif;
  1668.             $results[$key]['totalMontant']=$totalMontant;
  1669.             $totalMEffectif+=$totalEffectif;
  1670.             $totalMMontant+=$totalMontant;
  1671.             // dd($results,$totalM1,$stc,$groupement);
  1672.         }
  1673.                 
  1674.         $total['effectifPaie']=$paieEffectif;
  1675.         $total['montantPaie']=$paieMontant;
  1676.         $total['effectifIndeminite']=$indeminiteEffectif;
  1677.         $total['montantIndeminite']=$indeminiteMontant;
  1678.         $total['effectifHonoraire']=$honoraireEffectif;
  1679.         $total['montantHonoraire']=$honoraireMontant;
  1680.         $total['effectifStc']=$stcEffectif;
  1681.         $total['montantStc']=$stcMontant;
  1682.         $total['effectifM1']=$totalM1Effectif;
  1683.         $total['montantM1']=$totalM1Montant;
  1684.         $total['effectifMois']=$totalMEffectif;
  1685.         $total['montantMois']=$totalMMontant;
  1686.         // dd($results);
  1687.         
  1688.         $html $this->render("reporting/extraction/pdf/synthese_paie.html.twig", [
  1689.             'results'=>$results,
  1690.             'details'=>$details,
  1691.             'total'=>$total
  1692.         ])->getContent();
  1693.         $mpdf = new Mpdf([
  1694.             'mode' => 'utf-8',
  1695.             'margin_left' => '5',
  1696.             'margin_right' => '5',
  1697.             'format' => 'A4-L',
  1698.             'margin_header' => 5,
  1699.             'margin_top' => 10,
  1700.         ]);
  1701.         $mpdf->SetHTMLFooter("<footer class='center'>
  1702.                                 <table width='100%'>
  1703.                                   <tr>
  1704.                                       <td width='33%' style='text-align: center;'>page {PAGENO} de {nbpg}</td>
  1705.                                   </tr>
  1706.                                 </table>
  1707.                               </footer>");
  1708.         $mpdf->SetTitle('synthese paie');
  1709.         $mpdf->WriteHTML($html);
  1710.         $mpdf->Output("Synthèse Paie " $groupement " " $date->format('F Y') .".pdf""I");
  1711.     }
  1712.     private function applyDeviseFilter($queryBuilder$devise)
  1713.     {
  1714.         if (strtoupper($devise) == 'MAD') {
  1715.             $queryBuilder->andWhere('natureContract.id not in (15,16,17)')
  1716.                          ->andWhere('bordereau.devise = 1');
  1717.         } else {
  1718.             $queryBuilder->andWhere('bordereau.devise != 1');
  1719.         }
  1720.     
  1721.         return $queryBuilder;
  1722.     }
  1723.     #[Route('/app_reporting_extraction_bouclage_paie/{periodeController}/{periodeComparer}'name'app_reporting_extraction_bouclage_paie'options: ['expose' => true])]
  1724.     public function app_reporting_extraction_bouclage_paie($periodeController$periodeComparer): Response
  1725.     {
  1726.         $date = new \DateTime($periodeController);
  1727.         $periodeController $this->calculPaieService->getPeriode($date->format('mY'));
  1728.         $date = new \DateTime($periodeComparer);
  1729.         $periodeComparer $this->calculPaieService->getPeriode($date->format('mY'));
  1730.         $user $this->em->getRepository(Users::class)->find($this->getUser());
  1731.         $messageStatut = new PMessengerStatut();
  1732.         $messageStatut->setStatut('en cours');
  1733.         $messageStatut->setClasse('Generation extraction de bouclage pour la periode  '.$periodeController->getCode().' à comparer avec la periode '.$periodeComparer->getCode().' ');
  1734.         
  1735.         $messageStatut->setUser($this->getUser());
  1736.         $this->em->persist($messageStatut);
  1737.         $this->em->flush();
  1738.         $this->bus->dispatch(new ExtractionBouclageMessage([
  1739.             'periodeController' => $periodeController,
  1740.             'periodeComparer' => $periodeComparer,
  1741.             'user' => $user->getId(),
  1742.             'messageStatut' => $messageStatut->getId(),
  1743.         ]));
  1744.         return new JsonResponse('Votre demande a été envoyée, veuillez consulter la page de demande'200);
  1745.     }
  1746.     #[Route('/app_reporting_amine_test'name'app_reporting_amine_test'options: ['expose' => true])]
  1747.     public function app_reporting_amine_test(): Response
  1748.     {
  1749.         return new JsonResponse('amine');
  1750.     }
  1751.     #[Route('/app_reporting_extraction_nbrjour_paie/{year}'name'app_reporting_extraction_nbrjour_paie'options: ['expose' => true])]
  1752.     public function app_reporting_extraction_nbrjour_paie(Request $request$year): Response
  1753.     {
  1754.         $year1'%'$year;
  1755.         
  1756.         $queryBuilder $this->em->createQueryBuilder()
  1757.             ->select('DISTINCT p.id AS employe_id, lc.id AS contract_id, p.nombre_enfants, p.nbr_pris_en_charge, 
  1758.                       d.designation, d.abreviation, d.groupement, d.das,sf.Designation AS situation_familiale,d.id as dossier_id,periode.code AS period')
  1759.             ->from(Tbulletin::class, 'b')
  1760.             ->innerJoin('b.contract''lc')
  1761.             ->innerJoin('lc.employe''p')
  1762.             ->innerJoin('b.periode''periode')
  1763.             ->innerJoin('b.dossier''d')
  1764.             ->innerJoin('p.situation_familiale_id''sf')
  1765.             ->where('b.active = :active')
  1766.             ->andWhere('periode.code LIKE :year')
  1767.             ->andWhere('b.observation IS NULL')
  1768.             ->setParameter('active'1)
  1769.             ->setParameter('year'$year1)
  1770.             ->getQuery()
  1771.             ->getResult();
  1772.         // dd($queryBuilder);
  1773.         $spreadsheet = new Spreadsheet();
  1774.         $sheet $spreadsheet->getActiveSheet();
  1775.         $sheet->setCellValue('A1''Id Employe');
  1776.         $sheet->setCellValue('B1''Id Contract');
  1777.         $sheet->setCellValue('C1''Nombre enfants');
  1778.         $sheet->setCellValue('D1''Nombre pris en charge');
  1779.         $sheet->setCellValue('E1''Dossier');
  1780.         $sheet->setCellValue('F1''Abreviation Dossier');
  1781.         $sheet->setCellValue('G1''Das');
  1782.         $sheet->setCellValue('H1''groupement');
  1783.         $sheet->setCellValue('I1''nbrjours');
  1784.         $sheet->setCellValue('J1''situation familiale');
  1785.         $sheet->setCellValue('K1''periode');
  1786.         
  1787.         // $findDossier=['active' => true, 'periode' => $periode];
  1788.         // if($dossier->getId() != 47) {
  1789.         //     $findDossier ['dossier'] = $dossier;
  1790.         // }
  1791.         // $bulletins = $this->em->getRepository(Tbulletin::class)->findBy($findDossier);
  1792.         $i 2;
  1793.         foreach ($queryBuilder as $key => $q) {
  1794.             // dd($q['situation_familiale']);
  1795.             // $contract = $bulletin->getContract();
  1796.             $sheet->setCellValue('A' $i, isset($q['employe_id']) ? $q['employe_id'] : '-');
  1797.             $sheet->setCellValue('B' $i, isset($q['contract_id']) ? $q['contract_id'] : '-');
  1798.             $sheet->setCellValue('C' $i, isset($q['nombre_enfants']) ? $q['nombre_enfants'] : '-');
  1799.             $sheet->setCellValue('D' $i, isset($q['nbr_pris_en_charge']) ? $q['nbr_pris_en_charge'] : '-');
  1800.             $sheet->setCellValue('E' $i, isset($q['designation']) ? $q['designation'] : '-');
  1801.             $sheet->setCellValue('F' $i, isset($q['abreviation']) ? $q['abreviation'] : '-');
  1802.             $sheet->setCellValue('G' $i, isset($q['groupement']) ? $q['groupement'] : '-');
  1803.             $sheet->setCellValue('H' $i, isset($q['das']) ? $q['das'] : '-');
  1804.             // $periode = 0;
  1805.             $nbr=0;
  1806.             
  1807.             // $bulletins = $this->em->getRepository(Tbulletin::class)->findBy(['active' => true,'contract'=>$q['contract_id'],'dossier'=>$q['dossier_id'],'observation'=>null]);
  1808.             // foreach ($bulletins as $b) {
  1809.                 // dd($b);
  1810.                 // $periode= $b->getPeriode()->getCode();
  1811.                 $nbr += 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($q['contract_id'], $q['period']);
  1812.             // }
  1813.             // dd($nbr);
  1814.             if($nbr == 0){
  1815.                 $nbr '-';   
  1816.             } 
  1817.             $sheet->setCellValue('I' $i$nbr);
  1818.             $sheet->setCellValue('J' .$i, isset($q['situation_familiale']) ? $q['situation_familiale'] : '-');
  1819.             $sheet->setCellValue('K' .$i, isset($q['period']) ? $q['period'] : '-');
  1820.             $i++;
  1821.         }
  1822.         $writer = new Xlsx($spreadsheet);
  1823.         $fileName 'extraction_nbrjours' $year '.xlsx';
  1824.         $temp_file tempnam(sys_get_temp_dir(), $fileName);
  1825.         $writer->save($temp_file);
  1826.         return $this->file($temp_file$fileNameResponseHeaderBag::DISPOSITION_INLINE);
  1827.     }
  1828. }