src/Controller/Reporting/CnssController.php line 865

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Reporting;
  3. use App\Entity\PDossier;
  4. use App\Entity\Pemploye;
  5. use App\Entity\TCnssA00;
  6. use App\Entity\TCnssA01;
  7. use App\Entity\TCnssA02;
  8. use App\Entity\TCnssA03;
  9. use App\Entity\TCnssB00;
  10. use App\Entity\TCnssB01;
  11. use App\Entity\TCnssB02;
  12. use App\Entity\TCnssB03;
  13. use App\Entity\TCnssB04;
  14. use App\Entity\TCnssB05;
  15. use App\Entity\TCnssB06;
  16. use App\Entity\LContract;
  17. use App\Entity\PtypeCoti;
  18. use App\Entity\Tbulletin;
  19. use App\Entity\TbulletinLg;
  20. use App\Entity\PArretTravailLg;
  21. use App\Controller\ApiController;
  22. use App\Entity\LmatriculationCoti;
  23. use App\Entity\PnatureContract;
  24. use App\Entity\PsituationFamiliale;
  25. use App\Service\CalculPaieService;
  26. use Doctrine\Persistence\ManagerRegistry;
  27. use Symfony\Component\Finder\SplFileInfo;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpFoundation\Response;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Component\HttpFoundation\JsonResponse;
  32. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  33. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  34. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  35. use PhpOffice\PhpSpreadsheet\Reader\Xlsx as Reader;
  36. #[Route('/reporting/cnss')]
  37. class CnssController extends AbstractController
  38. {
  39.     private $em;
  40.     private $calculPaieService;
  41.     private $api;
  42.     public function __construct(ManagerRegistry $doctrineCalculPaieService $calculPaieServiceApiController $api)
  43.     {
  44.         $this->em $doctrine->getManager();
  45.         $this->calculPaieService $calculPaieService;
  46.         $this->api $api;
  47.         
  48.     }
  49.     #[Route('/'name'app_reporting_cnss'options: ['expose' => true])]
  50.     public function index(Request $request): Response
  51.     {
  52.         $operations $this->api->check($this->getUser(), 'app_reporting_cnss'$this->em$request);
  53.         if(!is_array($operations)) {
  54.             return $this->redirectToRoute('app_site');  
  55.         }elseif(count($operations) == 0) {
  56.             return $this->render('includes/404.html.twig');
  57.         }
  58.         $affiliations $this->em->createQueryBuilder()
  59.         ->select('d.statutCimr')
  60.         ->distinct()
  61.         ->from(PDossier::class, 'd')
  62.         ->where('d.statutCimr is not null')
  63.         ->getQuery()->getResult();
  64.         // dd($affiliations);
  65.         return $this->render('reporting/cnss/index.html.twig', [
  66.             'operations' => $operations,
  67.             'affiliations' => $affiliations,
  68.         ]);
  69.     }
  70.     #[Route('/app_reporting_cnss_list'name'app_reporting_cnss_list'options: ['expose' => true])]
  71.     public function app_reporting_cnss_list(Request $request): Response
  72.     {
  73.         $draw $request->query->get('draw');
  74.         $start $request->query->get('start') ?? 0;
  75.         $length $request->query->get('length') ?? 10;
  76.         $search $request->query->all('search')["value"];
  77.         $orderColumnIndex $request->query->all('order')[0]['column'];
  78.         $orderColumn $request->query->all("columns")[$orderColumnIndex]['name'];
  79.         $orderDir $request->query->all('order')[0]['dir'] ?? 'asc';
  80.         $queryBuilder $this->em->createQueryBuilder()
  81.         ->select('cnss0.id as id, cnss0.periode,cnss0.created, cnss1.raisonSociale')
  82.         ->from(TCnssA00::class, 'cnss0')
  83.         ->innerJoin('cnss0.tCnssA01s''cnss1')
  84.         ->Where('cnss0.active = 1');
  85.         if (!empty($search)) {
  86.             $queryBuilder->andWhere('(cnss0.periode LIKE :search OR cnss1.raisonSociale LIKE :search )')
  87.                 ->setParameter('search'"%$search%");
  88.         }
  89.         if (!empty($orderColumn)) {
  90.             $queryBuilder->orderBy("$orderColumn"$orderDir);
  91.         }
  92.         // dd($orderColumn);
  93.         $filteredRecords count($queryBuilder->getQuery()->getResult());
  94.         
  95.         // Paginate results
  96.         $queryBuilder->setFirstResult($start)
  97.             ->setMaxResults($length);
  98.         $results $queryBuilder->getQuery()->getResult();
  99.         // dd($results);
  100.         
  101.         // dd($results);
  102.         $totalRecords $this->em->createQueryBuilder()
  103.         ->select('COUNT(cnss0.id)')
  104.         ->from(TCnssA00::class, 'cnss0')
  105.         ->innerJoin('cnss0.tCnssA01s''cnss1')
  106.         ->Where('cnss0.active = 1')
  107.         ->getQuery()
  108.         ->getSingleScalarResult();
  109.         return new JsonResponse([
  110.             'draw' => $draw,
  111.             'recordsTotal' => $totalRecords,
  112.             'recordsFiltered' => $filteredRecords,
  113.             'data' => $results,
  114.         ]);
  115.     }
  116.     #[Route('/app_reporting_cnss_import'name'app_reporting_cnss_import'options: ['expose' => true])]
  117.     public function app_reporting_cnss_import(Request $request): Response
  118.     {
  119.         $file $request->files->get('file');
  120.         if(!$file){
  121.             return new JsonResponse('Veuillez import un fichier'500);
  122.         }
  123.         $file = new SplFileInfo($file'''');
  124.         
  125.         $cnssFile explode("\n"$file->getContents());
  126.         // dd($cnssFile);
  127.         $tcnssA00 null;
  128.         foreach($cnssFile as $cnss)
  129.         {
  130.           
  131.             if(substr($cnss,0,3)=='A00')
  132.             {
  133.                 $cnss00=trim($cnss);
  134.                 $cnss00=trim($cnss00,'A00A0');
  135.                 $tcnssA00 $this->em->getRepository(TCnssA00::class)->findOneBy(['periode' => date('Ym'strtotime('last month')), 'typeEnreg' => 'A00''IdentiTransfert' =>$cnss00'cat' => 'A0''active' => true]);
  136.                 if($tcnssA00) {
  137.                     $tcnssA00->setActive(false);
  138.                 }
  139.                 // $periode=$this->calculPaieService->getPeriode(date('mY', strtotime('last month')));
  140.                 $tcnssA00 = new TCnssA00();
  141.                 $tcnssA00->setPeriode(date('Ym'strtotime('last month')));
  142.                 $tcnssA00->setTypeEnreg('A00');
  143.                 $tcnssA00->setIdentiTransfert($cnss00);
  144.                 $tcnssA00->setCat('A0');
  145.                 $tcnssA00->setFiller('');
  146.                 $tcnssA00->setUserCreated($this->getUser());
  147.                 $tcnssA00->setCreated(new \DateTime());
  148.                 $this->em->persist($tcnssA00);
  149.                 
  150.             }
  151.             elseif(substr($cnss,0,3)=='A01')
  152.             {
  153.                 $cnss01 =preg_split('/\s{2,}/'$cnss);
  154.                //dd($cnss01);
  155.                 $Num_Affilie=substr($cnss01[0],3,7);
  156.                 
  157.                 $Raison_Sociale=substr($cnss01[0],16);
  158.                 
  159.                 $periode=substr($cnss01[0],10,-strlen($Raison_Sociale));
  160.                 $C_Code=explode(" "$cnss01[3]);
  161.                
  162.                 if(sizeof($C_Code) == 1)
  163.                 {
  164.                     $Code_Agence=substr(trim($C_Code[0]),0,-16);
  165.                     $Date_Exig=substr(trim($C_Code[0]),10);
  166.                     $Date_Emission=substr(trim($C_Code[0]),2,8);
  167.                     $Code_Postal=null;
  168.                 }
  169.                 else{
  170.                     $Code_Agence=substr(trim($C_Code[1]),0,-16);
  171.                     $Date_Exig=substr(trim($C_Code[1]),10);
  172.                     $Date_Emission=substr(trim($C_Code[1]),2,8);
  173.                     $Code_Postal=$C_Code[0];
  174.                 }
  175.                 $tcnssA01 = new TCnssA01();
  176.                 $tcnssA01->setCnssa00($tcnssA00);
  177.                 $tcnssA01->setTypeEnreg('A01');
  178.                 $tcnssA01->setNumAffilie($Num_Affilie);
  179.                 $tcnssA01->setPeriode($periode);
  180.                 $tcnssA01->setRaisonSociale($Raison_Sociale);
  181.                 $tcnssA01->setAdresse($cnss01[1]);
  182.                 $tcnssA01->setVille($cnss01[2]);
  183.                 $tcnssA01->setCodePostal($Code_Postal);
  184.                 $tcnssA01->setCodeAgence($Code_Agence);
  185.                 $tcnssA01->setDateEmission($Date_Emission);
  186.                 $tcnssA01->setDateExig($Date_Exig);
  187.                 
  188.                 $this->em->persist($tcnssA01);              
  189.               
  190.               
  191.             }
  192.             elseif(substr($cnss,0,3)=='A02'){
  193.                 
  194.                 $cnss2=trim($cnss);
  195.                 $nom_prenom=str_replace("'","''",trim(substr($cnss2,25,-20)));
  196.                 $Num_Affilie=substr($cnss2,-strlen($cnss2)+3,7);
  197.                 $Période=substr($cnss2,-strlen($cnss2)+10,6);
  198.                 $Num_Assure=substr($cnss2,-strlen($cnss2)+16,9);
  199.                 $Enfants=substr($cnss2,-20,2);
  200.                 $AF_A_Payer=substr($cnss2,-18,6);
  201.                 $AF_A_Deduire=substr($cnss2,-12,6);
  202.                 $AF_Net_A_Payer=substr($cnss2,-6);
  203.                 
  204.                 $tcnssA02 = new TCnssA02();
  205.                 $tcnssA02->setCnssa00($tcnssA00);
  206.                 $tcnssA02->setTypeEnreg('A02');
  207.                 $tcnssA02->setNumAffilie($Num_Affilie);
  208.                 $tcnssA02->setPeriode($Période);
  209.                 $tcnssA02->setNumAssure($Num_Assure);
  210.                 $tcnssA02->setNomPrenom($nom_prenom);
  211.                 $tcnssA02->setEnfants($Enfants);
  212.                 $tcnssA02->setAfAPayer($AF_A_Payer);
  213.                 $tcnssA02->setAfADeduire($AF_A_Deduire);
  214.                 $tcnssA02->setAfNetAPayer($AF_Net_A_Payer);
  215.                 $this->em->persist($tcnssA02);
  216.             }
  217.             elseif(substr($cnss,0,3)=='A03'){ 
  218.                 $cnss03=trim($cnss);
  219.                 $Num_Affilie=substr($cnss03,-strlen($cnss03)+3,7);    
  220.                 $Période=substr($cnss03,-strlen($cnss03)+10,6); 
  221.                 $Nbr_Salaries=substr($cnss03,-strlen($cnss03)+16,6); 
  222.                 $T_Enfants=substr($cnss03,-56,5);
  223.                 $T_AF_A_Payer=substr($cnss03,-51,12);
  224.                 $T_AF_A_Deduire=substr($cnss03,-39,12);
  225.                 $T_AF_Net_A_Payer=substr($cnss03,-27,12);
  226.                 $T_Num_Imma=substr($cnss03,-15);
  227.                 $tcnssA03 = new TCnssA03();
  228.                 $tcnssA03->setCnssa00($tcnssA00);
  229.                 $tcnssA03->setTypeEnreg('A03');
  230.                 $tcnssA03->setNumAffilie($Num_Affilie);
  231.                 $tcnssA03->setPeriode($Période);
  232.                 $tcnssA03->setNbrSalaries($Nbr_Salaries);
  233.                 $tcnssA03->setTEnfants($T_Enfants);
  234.                 $tcnssA03->setTAfAPayer($T_AF_A_Payer);
  235.                 $tcnssA03->setTAfADeduire($T_AF_A_Deduire);
  236.                 $tcnssA03->setTAfNetAPayer($T_AF_Net_A_Payer);
  237.                 $tcnssA03->setTNumImma($T_Num_Imma);
  238.                 $this->em->persist($tcnssA03);
  239.               
  240.             }
  241.        
  242.         
  243.         }
  244.         $this->em->flush();
  245.         $nbr_salaries=0;
  246.         $jour_decale=0;
  247.         $num_imma=0;
  248.         $salaireR=0;
  249.         $salaireP=0;
  250.         $T_Ctr=0;
  251.         $T_nbr_salaries=0;
  252.         $T_jour_decale=0;
  253.         $T_num_imma=0;
  254.         $T_salaireR=0;
  255.         $T_salaireP=0;
  256.         $T_Ctr6=0;
  257.         $periode date('Ym'strtotime('last month'));
  258.         $periode1=substr($periode4strlen($periode)-4).substr($periode,04);
  259.         $periode1 $this->calculPaieService->getPeriode($periode1);
  260.         $tcnssB00 $this->em->getRepository(TCnssB00::class)->findOneBy(['cnssa00' => $tcnssA00'identiTransfert' => $tcnssA00->getIdentiTransfert(), 'periode' => $periode]);
  261.         if(!$tcnssB00) {
  262.             $num_affilie substr($tcnssA00->getIdentiTransfert(), 07);
  263.             $tcnssB00 = new TCnssB00();
  264.             $tcnssB00->setTypeEnreg('B00');
  265.             $tcnssB00->setCnssa00($tcnssA00);
  266.             $tcnssB00->setIdentiTransfert($tcnssA00->getIdentiTransfert());
  267.             $tcnssB00->setCat('B0');
  268.             $tcnssB00->setPeriode($periode);
  269.             $this->em->persist($tcnssB00);
  270.             $this->em->refresh($tcnssA00);
  271.             foreach ($tcnssA00->getTCnssA01s() as $key => $value) {
  272.                 $tcnssB01 = new TCnssB01();
  273.                 $tcnssB01->setTypeEnreg('B01');
  274.                 $tcnssB01->setCnssb00($tcnssB00);
  275.                 $tcnssB01->setNumAffilie($value->getNumAffilie());
  276.                 $tcnssB01->setPeriode($value->getPeriode());
  277.                 $tcnssB01->setRaisonSociale($value->getRaisonSociale());
  278.                 $tcnssB01->setAdresse($value->getAdresse());
  279.                 $tcnssB01->setVille($value->getVille());
  280.                 $tcnssB01->setCodePostal($value->getCodePostal());
  281.                 $tcnssB01->setCodeAgence($value->getCodeAgence());
  282.                 $tcnssB01->setDateEmission($value->getDateEmission());
  283.                 $tcnssB01->setDateExig($value->getDateEmission());
  284.                 $this->em->persist($tcnssB01);
  285.             }
  286.             $typesContracts $this->em->getRepository(PnatureContract::class)->findBy(['id' => [118]]);
  287.             foreach($tcnssA00->getTCnssA02s() as $value)
  288.             {
  289.                 $numCat=0;
  290.                 $categorie='';
  291.                 $reel 0;
  292.                 $montantReel 0;
  293.                 $plafond 0;
  294.                 $montantPlafond 0;
  295.                 
  296.                 // $cnssPersonnel = $this->em->getRepository(LmatriculationCoti::class)->findOneBy(['code' => $value->getNumAssure(), 'type_id' => $this->em->getRepository(PtypeCoti::class)->find(1), 'active' => true]);
  297.                 $contract $this->em->getRepository(LContract::class)->findOneBy(['cnss' => $value->getNumAssure(), 'active' => true'pnatureContract' => $typesContracts]);
  298.                 if(!$contract) {
  299.                     $contract $this->em->getRepository(LContract::class)->findOneBy(['cnss' => $value->getNumAssure(), 'pnatureContract' => $typesContracts]);
  300.                 }
  301.                 // $contract = null;
  302.                 if($contract and $contract->getActive() == 1) {
  303.                     if($contract->getPnatureContract() and $contract->getPnatureContract()->getType()->getId() == 1) {
  304.                         $queryBuilder $this->em->createQueryBuilder();
  305.                         $montantImposable $queryBuilder->select('SUM(TbulletinLg.montant) as reel, CASE WHEN (SUM(TbulletinLg.montant) > 6000) THEN 6000 ELSE SUM(TbulletinLg.montant) END as plafond')
  306.                                     ->from(TbulletinLg::class, 'TbulletinLg')
  307.                                     ->innerJoin('TbulletinLg.bulletin''bulletin')
  308.                                     ->innerJoin('TbulletinLg.rubrique''rubrique')
  309.                                     ->innerJoin('bulletin.dossier''dossier')
  310.                                     ->where('bulletin.contract = :contract')
  311.                                     ->andWhere('rubrique.imposable = 1')
  312.                                     ->andWhere('TbulletinLg.active = 1')
  313.                                     ->andWhere('dossier.affiliation = :affiliation')
  314.                                     ->andWhere('bulletin.periode = :periode1')
  315.                                     ->setParameter('contract'$contract)
  316.                                     ->setParameter('affiliation'$value->getNumAffilie())
  317.                                     ->setParameter('periode1'$periode1)
  318.                                     ->getQuery()
  319.                                     ->getOneOrNullResult()
  320.                         ;
  321.                         if($montantImposable['reel'] === null) {
  322.                             $categorie='SO'
  323.                             $numCat=1;
  324.                             $nbrJour=0
  325.                         } else {
  326.                             $reel =  (int)number_format($montantImposable['reel'], 2'''');
  327.                             $montantReel $montantImposable['reel'];
  328.                             $plafond = (int)number_format($montantImposable['plafond'], 2'''');
  329.                             $montantPlafond $montantImposable['plafond'];
  330.                             $nbrJour 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($contract->getId(), $periode1);
  331.                             $nbrJour sprintf("%02d"substr($nbrJour02));
  332.                             if($nbrJour 26) {
  333.                                 $motif $this->em->getRepository(PArretTravailLg::class)->getMotifArretTravail($contract->getId(), $periode1);
  334.                                 $categorie $motif['abreviation'] ? $motif['abreviation'] : '';
  335.                                 switch ($categorie) {
  336.                                     case 'DE':
  337.                                         $numCat=2;
  338.                                         break;
  339.                                     case 'IT':
  340.                                         $numCat=3;
  341.                                         break;
  342.                                     case 'IL':
  343.                                         $numCat=4;
  344.                                         break;
  345.                                     case 'AT':
  346.                                         $numCat=5;
  347.                                         break;
  348.                                     case 'CS':
  349.                                         $numCat=6;
  350.                                         break;
  351.                                     case 'MS':
  352.                                         $numCat=7;
  353.                                         break;
  354.                                     case 'MP':
  355.                                         $numCat=8;
  356.                                         break;
  357.                                     default:
  358.                                         $numCat=0;
  359.                                 }
  360.                             }
  361.                         }
  362.                     } else {
  363.                         $categorie='SO'
  364.                         $numCat=1;
  365.                         $nbrJour=0
  366.                     }
  367.                 } else {
  368.                     $categorie='SO'
  369.                     $numCat=1;
  370.                     $nbrJour=0
  371.                 }
  372.                 
  373.              
  374.                 
  375.                 
  376.                
  377.                 $S_Ctr=intval($numCat+$value->getAfAPayer()+$nbrJour+$value->getEnfants()+$value->getNumAssure()+$reel+$plafond);
  378.                 // dd($S_Ctr);
  379.                 $tcnssB02 = new TCnssB02();
  380.                 $tcnssB02->setCnssb00($tcnssB00);
  381.                 $tcnssB02->setMontantPlaf($montantPlafond);
  382.                 $tcnssB02->setMontantReel($montantReel);
  383.                 $tcnssB02->setContract($contract);
  384.                 $tcnssB02->setTypeEnreg('B02');
  385.                 $tcnssB02->setNumAffilie($value->getNumAffilie());
  386.                 $tcnssB02->setPeriode($periode);
  387.                 $tcnssB02->setNumAssure($value->getNumAssure());
  388.                 $tcnssB02->setNomPrenom(str_replace("'","''",$value->getNomPrenom()));
  389.                 $tcnssB02->setEnfants($value->getEnfants());
  390.                 $tcnssB02->setAfAPayer($value->getAfAPayer());
  391.                 $tcnssB02->setAfADeduire($value->getAfADeduire());
  392.                 $tcnssB02->setAfNetAPayer($value->getAfNetAPayer());
  393.                 $tcnssB02->setSite($contract $contract->getDossier()->getCode() : '');
  394.                 $tcnssB02->setNJoursDeclares($nbrJour);
  395.                 $tcnssB02->setLSituation($categorie);
  396.                 $tcnssB02->setLSituationNum($numCat);
  397.                 $tcnssB02->setNSalaireReel($reel);
  398.                 $tcnssB02->setNSalairePlaf($plafond);
  399.                 $tcnssB02->setSCtr($S_Ctr);
  400.                 $this->em->persist($tcnssB02);
  401.             
  402.                 $jour_decale $jour_decale+$nbrJour;
  403.         
  404.                 $salaireR intval($salaireR+$reel);
  405.                 $salaireP=$salaireP+$plafond;
  406.                 $T_Ctr $T_Ctr $S_Ctr
  407.                  
  408.             }
  409.             // die;
  410.             
  411.             foreach($tcnssA00->getTCnssA03s() as $value)
  412.             {   
  413.                 $tcnssB03 = new TCnssB03();
  414.                 $tcnssB03->setCnssb00($tcnssB00);
  415.                 $tcnssB03->setTypeEnreg('B03');
  416.                 $tcnssB03->setNumAffilie($value->getNumAffilie());
  417.                 $tcnssB03->setPeriode($periode);
  418.                 $tcnssB03->setNbrSalaries($value->getNbrSalaries());
  419.                 $tcnssB03->setTEnfants($value->getTEnfants());
  420.                 $tcnssB03->setTAfAPayer($value->getTAfAPayer());
  421.                 $tcnssB03->setTAfADeduire($value->getTAfADeduire());
  422.                 $tcnssB03->setTAfNetAPayer($value->getTAfNetAPayer());
  423.                 $tcnssB03->setTNumImma($value->getTNumImma());
  424.                 $tcnssB03->setTAfAReverser($value->getTAfAReverser());
  425.                 $tcnssB03->setTJoursDeclares($jour_decale);
  426.                 $tcnssB03->setTSalaireReel($salaireR);
  427.                 $tcnssB03->setTSalairePlaf($salaireP);
  428.                 $tcnssB03->setTCtr($T_Ctr);
  429.                 $this->em->persist($tcnssB03);
  430.                 $T_nbr_salaries=$T_nbr_salaries+$value->getNbrSalaries();
  431.                 $T_jour_decale=$T_jour_decale+$jour_decale;
  432.                 $T_num_imma=$T_num_imma+$value->getTNumImma();
  433.                 $T_salaireR=$T_salaireR+$salaireR;
  434.                 $T_salaireP=$T_salaireP+$salaireP;
  435.                 $T_Ctr6=$T_Ctr6+$T_Ctr;
  436.                 
  437.             }
  438.             $jour_decale=0;
  439.             
  440.             $salaireR=0;
  441.             $salaireP=0;
  442.             $T_Ctr=0;
  443.             // dd('amine');
  444.             $personnesNoDeclares $this->em->getRepository(Tbulletin::class)->getPersonneNoDeclarer($periode1$num_affilie$periode);
  445.             // $personnesNoDeclares = [];
  446.             // dd($personnesNoDeclares);
  447.             if(count($personnesNoDeclares) > 0)
  448.             {
  449.                 foreach($personnesNoDeclares as $row4)
  450.                 {
  451.                     $contract $this->em->getRepository(LContract::class)->find($row4['contractId']);
  452.                     // $sql = "select  b.Nom,B.Prénom,b.CIN,REPLACE(CAST(b.SBI AS NUMERIC(18,2)),'.','') as  Reel ,REPLACE(CAST(b.SBI_Plaf AS NUMERIC(18,2)),'.','') as Plafond   from  Q_SBI_Vir b where Période=$periode1 and ID_Employer='".$row4["ID_Employer"]."'";
  453.                     // $stmt4 = $this->getDoctrine()->getConnection()->prepare($sql);
  454.                     // $stmt4->execute();
  455.                     // $datab04 = $stmt4->fetch();
  456.                     // $request = "select REPLACE(CAST(SUM(TbulletinLg.montant) AS NUMERIC(18,2)),'.','') as  Reel, CASE WHEN (SUM(TbulletinLg.montant) > 6000) THEN 600000 ELSE REPLACE(CAST(SUM(TbulletinLg.montant) AS NUMERIC(18,2)),'.','') END as plafond"
  457.                     $queryBuilder $this->em->createQueryBuilder();
  458.                     $montantImposable $queryBuilder->select('SUM(TbulletinLg.montant) as reel, CASE WHEN (SUM(TbulletinLg.montant) > 6000) THEN 6000 ELSE SUM(TbulletinLg.montant) END as plafond')
  459.                         ->from(TbulletinLg::class, 'TbulletinLg')
  460.                         ->innerJoin('TbulletinLg.bulletin''bulletin')
  461.                         ->innerJoin('TbulletinLg.rubrique''rubrique')
  462.                         ->where('bulletin.contract = :contract')
  463.                         ->andWhere('rubrique.imposable = 1')
  464.                         ->andWhere('TbulletinLg.active = 1')
  465.                         ->andWhere('bulletin.periode = :periode1')
  466.                         ->setParameter('contract'$contract)
  467.                         ->setParameter('periode1'$periode1)
  468.                         ->getQuery()
  469.                         ->getOneOrNullResult()
  470.                     ;
  471.                     $reel =  (int)number_format($montantImposable['reel'], 2'''');
  472.                     $plafond = (int)number_format($montantImposable['plafond'], 2'''');
  473.                     if($reel == 0) {
  474.                         continue;
  475.                     }
  476.                     // $sql = "select lg.Base_App_HRM from pBulletins b inner join  pBulletins_LG lg on b.ID_Bulletin=lg.ID_Bulletin where  b.obs is null and lg.ID_Eléments='R10001' and Période=$periode1 and ID_Employer='".$row4["ID_Employer"]."'";
  477.                     // $stmt4 = $this->getDoctrine()->getConnection()->prepare($sql);
  478.                     // $stmt4->execute();
  479.                     // $dataBaselg4 = $stmt4->fetch();
  480.                     $nbrJour 26 $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($row4['contractId'], $periode1);
  481.                     $nbrJour substr($nbrJour,0,2);
  482.                     $str str_replace('\'',' ',$contract->getEmploye()->getNom().' '.$contract->getEmploye()->getPrenom());
  483.                     if (is_numeric($row4["CNSS"]))
  484.                     {
  485.                        $cnss $row4["CNSS"];
  486.                     }else{
  487.                         $cnss=0;
  488.                     }
  489.                     // dump($cnss);
  490.                    
  491.                     $S_Ctr=round($plafond $reel+$cnss+$nbrJour);
  492.                    
  493.                     $tcnssB04 = new TCnssB04();
  494.                     $tcnssB04->setCnssb00($tcnssB00);
  495.                     $tcnssB04->setContract($contract);
  496.                     $tcnssB04->setTypeEnreg('B04');
  497.                     $tcnssB04->setNumAffilie($num_affilie);
  498.                     $tcnssB04->setPeriode($periode);
  499.                     $tcnssB04->setNumAssure($row4["CNSS"]);
  500.                     $tcnssB04->setNomPrenom($str);
  501.                     $tcnssB04->setNumCin($contract->getEmploye()->getCin());
  502.                     $tcnssB04->setSite($contract->getDossier()->getCode());
  503.                     $tcnssB04->setNbrJours($nbrJour);
  504.                     $tcnssB04->setSalReel($reel);
  505.                     $tcnssB04->setSalPlaf($plafond);
  506.                     $tcnssB04->setSCtr($S_Ctr);
  507.                     $tcnssB04->setMontantReel($montantImposable['reel']);
  508.                     $tcnssB04->setMontantPlaf($montantImposable['plafond']);
  509.                     
  510.                     $this->em->persist($tcnssB04);
  511.                     // $stmt4 = $this->getDoctrine()->getConnection()->prepare($sql4);
  512.                     // $stmt4->execute();
  513.                     $nbr_salaries++;
  514.                     $jour_decale=$jour_decale+$nbrJour;
  515.                     $num_imma=$num_imma+$cnss;
  516.                     $salaireR=$salaireR+$reel;
  517.                     $salaireP=$salaireP+$plafond;
  518.                     
  519.                 
  520.                     //dd($sql4);
  521.                 }
  522.             } else {
  523.                 $tcnssB04 = new TCnssB04();
  524.                 $tcnssB04->setCnssb00($tcnssB00);
  525.                 $tcnssB04->setTypeEnreg('B04');
  526.                 $tcnssB04->setNumAffilie($num_affilie);
  527.                 $tcnssB04->setPeriode($periode);
  528.                 $tcnssB04->setNumAssure(0);
  529.                 $tcnssB04->setNbrJours(0);
  530.                 $tcnssB04->setSalReel(0);
  531.                 $tcnssB04->setSalPlaf(0);
  532.                 
  533.                 $this->em->persist($tcnssB04);
  534.                 // $sql4="INSERT INTO cnss_b04( Type_Enreg, Num_Affilie, Période, Num_Assure, Nbr_Jours,Sal_Reel, Sal_Plaf)   VALUES ('B04','$num_affilie','$periode','0','0','0','0')";
  535.                 // $stmt4 = $this->getDoctrine()->getConnection()->prepare($sql4);
  536.                 // $stmt4->execute();
  537.             }
  538.             // dd($num_imma);
  539.             $T_Ctr=$nbr_salaries+$jour_decale+$num_imma+$salaireR+$salaireP;
  540.             // $sql5="INSERT INTO cnss_b05(Type_Enreg, Num_Affilie, Période, Nbr_Salaries, T_Num_Imma, T_Jours_Declares, T_Salaire_Reel, T_Salaire_Plaf, T_Ctr) V
  541.             // ALUES ('B05','$num_affilie', '$periode','$nbr_salaries','$num_imma','$jour_decale','$salaireR','$salaireP','$T_Ctr')";
  542.             // $stmt5 = $this->getDoctrine()->getConnection()->prepare($sql5);
  543.             // $stmt5->execute();
  544.             $tcnssB05 = new TCnssB05();
  545.             $tcnssB05->setCnssb00($tcnssB00);
  546.             $tcnssB05->setTypeEnreg('B05');
  547.             $tcnssB05->setNumAffilie($num_affilie);
  548.             $tcnssB05->setPeriode($periode);
  549.             $tcnssB05->setNbrSalaries($nbr_salaries);
  550.             $tcnssB05->setTNumImma($num_imma);
  551.             $tcnssB05->setTJoursDeclares($jour_decale);
  552.             $tcnssB05->setTSalaireReel($salaireR);
  553.             $tcnssB05->setTSalairePlaf($salaireP);
  554.             $tcnssB05->setTCtr($T_Ctr);
  555.             
  556.             $this->em->persist($tcnssB05);
  557.     
  558.             $T_nbr_salaries=$T_nbr_salaries+$nbr_salaries;
  559.             $T_jour_decale=$T_jour_decale+$jour_decale;
  560.             $T_num_imma=$T_num_imma+$num_imma;
  561.             $T_salaireR=$T_salaireR+$salaireR;
  562.             $T_salaireP=$T_salaireP+$salaireP;
  563.             $T_Ctr6=$T_Ctr6+$T_Ctr;
  564.             // $sql6="INSERT INTO cnss_b06(Type_Enreg, Num_Affilie, Période, Nbr_Salaries, T_Num_Imma, T_Jours_Declares, T_Salaire_Reel, T_Salaire_Plaf, T_Ctr) 
  565.             // VALUES ('B06','$num_affilie', '$periode','$T_nbr_salaries','$T_num_imma','$T_jour_decale','$T_salaireR','$T_salaireP','$T_Ctr6')";
  566.             // $stmt6 = $this->getDoctrine()->getConnection()->prepare($sql6);
  567.             // $stmt6->execute();
  568.             $tcnssB06 = new TCnssB06();
  569.             $tcnssB06->setCnssb00($tcnssB00);
  570.             $tcnssB06->setTypeEnreg('B06');
  571.             $tcnssB06->setNumAffilie($num_affilie);
  572.             $tcnssB06->setPeriode($periode);
  573.             $tcnssB06->setNbrSalaries($T_nbr_salaries);
  574.             $tcnssB06->setTNumImma($T_num_imma);
  575.             $tcnssB06->setTJoursDeclares($T_jour_decale);
  576.             $tcnssB06->setTSalaireReel($T_salaireR);
  577.             $tcnssB06->setTSalairePlaf($T_salaireP);
  578.             $tcnssB06->setTCtr($T_Ctr6);
  579.             
  580.             $this->em->persist($tcnssB06);
  581.                 
  582.                 
  583.             
  584.         }
  585.         $this->em->flush();
  586.         return new JsonResponse('Bien enregistrer');
  587.    
  588.     }
  589.     #[Route('/app_reporting_cnss_export/{cnssa00}'name'app_reporting_cnss_export'options: ['expose' => true])]
  590.     public function app_reporting_cnss_export(TCnssA00 $cnssa00): Response
  591.     {
  592.         $myFile 'DS_';
  593.         $myFinalData '';
  594.         /* cnss_b00 */
  595.         $cnssB00 $this->em->getRepository(TCnssB00::class)->findOneBy(['cnssa00' => $cnssa00]);
  596.         $table TCnssB00::class;
  597.         $typeEnreg $this->getFinalLength($cnssB00->getTypeEnreg(),$table'typeEnreg''AN');
  598.         $identiTransfert $this->getFinalLength($cnssB00->getIdentiTransfert(), $table'identiTransfert''N');
  599.         $cat $this->getFinalLength($cnssB00->getCat(), $table'cat''AN');
  600.         $filler $this->getFinalLength($cnssB00->getFiller(), $table'filler''AN');
  601.         $myFinalData .= $typeEnreg $identiTransfert $cat $filler.PHP_EOL;
  602.      
  603.         // echo $myFinalData;
  604.         // die;
  605.         /* cnss_b01 */
  606.         // dd($cnssB01Data);
  607.         $table TCnssB01::class;
  608.         foreach ($cnssB00->getTCnssB01s() as $cnssB01) {
  609.             $typeEnreg $this->getFinalLength($cnssB01->getTypeEnreg(),$table'typeEnreg''AN');
  610.             $numAffilie $this->getFinalLength($cnssB01->getNumAffilie(),$table'numAffilie''N');
  611.             $periode $this->getFinalLength($cnssB01->getPeriode(),$table'periode''N');
  612.             $raisonSociale $this->getFinalLength($cnssB01->getRaisonSociale(),$table'raisonSociale''AN');
  613.             $activite $this->getFinalLength($cnssB01->getActivite(),$table'activite''AN');
  614.             $adresse $this->getFinalLength($cnssB01->getAdresse(),$table'adresse''AN');
  615.             $ville $this->getFinalLength($cnssB01->getVille(),$table'ville''AN');
  616.             $codePostal $this->getFinalLength($cnssB01->getCodePostal(),$table'codePostal''AN');
  617.             $codeAgence $this->getFinalLength($cnssB01->getCodeAgence(),$table'codeAgence''N');
  618.             $dateEmission $this->getFinalLength($cnssB01->getDateEmission(),$table'dateEmission''N');
  619.             $dateExig $this->getFinalLength($cnssB01->getDateExig(),$table'dateExig''N');
  620.             $myFinalData .= $typeEnreg $numAffilie $periode $raisonSociale $activite $adresse $ville $codePostal $codeAgence $dateEmission $dateExig.PHP_EOL;
  621.             
  622.         }
  623.         $myFile .=$numAffilie.'_'.$cnssa00->getPeriode();
  624.         
  625.        
  626.         /* cnss_b02 */
  627.         // dd($cnssB02Data);
  628.         $table TCnssB02::class;
  629.         // dd($table);
  630.         foreach ($cnssB00->getTCnssB02s() as $cnssB02) {
  631.             // dd($cnssB02->Num_Assure);
  632.             // if($cnssB02->getId() == 38) {
  633.                 
  634.             
  635.             // $idEmployer = $this->getFinalLength($cnssB02->ID_Employer,'cnss_b02', 'ID_Employer', 'AN');
  636.             $typeEnreg $this->getFinalLength($cnssB02->getTypeEnreg(),$table'typeEnreg''AN');
  637.             $numAffilie $this->getFinalLength($cnssB02->getNumAffilie(),$table'numAffilie''N');
  638.             $periode $this->getFinalLength($cnssB02->getPeriode(),$table'periode''N');
  639.             $numAssure $this->getFinalLength($cnssB02->getNumAssure(),$table'numAssure''N');
  640.             $nomPrenom $this->getFinalLength($cnssB02->getNomPrenom(),$table'nomPrenom''AN');
  641.             $enfants $this->getFinalLength($cnssB02->getEnfants(),$table'enfants''N');
  642.             $aFAPayer $this->getFinalLength($cnssB02->getAFAPayer(),$table'afAPayer''N');
  643.             $aFADeduire $this->getFinalLength($cnssB02->getAfADeduire(),$table'afADeduire''N');
  644.             $aFNetAPayer $this->getFinalLength($cnssB02->getAfNetAPayer(),$table'afNetAPayer''N');
  645.             $aFAReverser $this->getFinalLength($cnssB02->getAfAReverser(),$table'afAReverser''N');
  646.             $nJoursDeclares $this->getFinalLength($cnssB02->getNJoursDeclares(),$table'nJoursDeclares''NN');
  647.             $nSalaireReel $this->getFinalLength($cnssB02->getNSalaireReel(),$table'nSalaireReel''NN');
  648.             $nSalairePlaf $this->getFinalLength($cnssB02->getNSalairePlaf(),$table'nSalairePlaf''NN');
  649.             $lSituation $this->getFinalLength($cnssB02->getLSituation(),$table'lSituation''AN');
  650.             $sCtr $this->getFinalLength($cnssB02->getSCtr(),$table'sCtr''NN');
  651.             $filler $this->getFinalLength($cnssB02->getFiller(),$table'filler''AN');
  652.             $myFinalData .= $typeEnreg $numAffilie $periode $numAssure $nomPrenom $enfants $aFAPayer $aFADeduire $aFNetAPayer $aFAReverser $nJoursDeclares $nSalaireReel $nSalairePlaf $lSituation $sCtr $filler.PHP_EOL;
  653.             // dump($myFinalData);
  654.             // }
  655.         }
  656.         /* cnss_b03 */
  657.         // dd($cnssB03Data);
  658.         $table TCnssB03::class;
  659.         foreach ($cnssB00->getTCnssB03s() as $cnssB03) {
  660.             // dd($cnssB02->Num_Assure);
  661.             $typeEnreg $this->getFinalLength($cnssB03->getTypeEnreg(),$table'typeEnreg''AN');
  662.             $numAffilie $this->getFinalLength($cnssB03->getNumAffilie(),$table'numAffilie''N');
  663.             $periode $this->getFinalLength($cnssB03->getPeriode(),$table'periode''N');
  664.             $nbrSalaries $this->getFinalLength($cnssB03->getNbrSalaries(),$table'nbrSalaries''N');
  665.             $enfants $this->getFinalLength($cnssB03->getTEnfants(),$table'tEnfants''N');
  666.             $aFAPayer $this->getFinalLength($cnssB03->getTAfAPayer(),$table'tAfAPayer''N');
  667.             $aFADeduire $this->getFinalLength($cnssB03->getTAfADeduire(),$table'tAfADeduire''N');
  668.             $aFNetAPayer $this->getFinalLength($cnssB03->getTAfNetAPayer(),$table'tAfNetAPayer''N');
  669.             $tNumImma $this->getFinalLength($cnssB03->getTNumImma(),$table'tNumImma''N');
  670.             $aFAReverser $this->getFinalLength($cnssB03->getTAfAReverser(),$table'tAfAReverser''N');
  671.             $nJoursDeclares $this->getFinalLength($cnssB03->getTJoursDeclares(),$table'tJoursDeclares''NN');
  672.             $nSalaireReel $this->getFinalLength($cnssB03->getTSalaireReel(),$table'tSalaireReel''NN');
  673.             $nSalairePlaf $this->getFinalLength($cnssB03->getTSalairePlaf(),$table'tSalairePlaf''NN');
  674.             $sCtr $this->getFinalLength($cnssB03->getTCtr(),$table'tCtr''NN');
  675.             $filler $this->getFinalLength($cnssB03->getFiller(),$table'filler''AN');
  676.             $myFinalData .= $typeEnreg $numAffilie $periode $nbrSalaries $enfants $aFAPayer $aFADeduire $aFNetAPayer $tNumImma $aFAReverser $nJoursDeclares $nSalaireReel $nSalairePlaf $sCtr $filler.PHP_EOL;
  677.            
  678.         }
  679.       
  680.         /* cnss_b04 */
  681.         $table TCnssB04::class;
  682.         foreach ($cnssB00->getTCnssB04s() as $cnssB04) {
  683.             // dd($cnssB04->getNumAssure() == 0 ? ' ' : $cnssB04->getNumAssure());
  684.             $typeEnreg $this->getFinalLength($cnssB04->getTypeEnreg(),$table'typeEnreg''AN');
  685.             $numAffilie $this->getFinalLength($cnssB04->getNumAffilie(),$table'numAffilie''N');
  686.             $periode $this->getFinalLength($cnssB04->getPeriode(),$table'periode''N');
  687.             $numAssure $this->getFinalLength($cnssB04->getNumAssure() == '' $cnssB04->getNumAssure() ,$table'numAssure''AN');
  688.             // $numAssure = $this->getFinalLength(
  689.             //     $cnssB04->getNumAssure() == 0 ? ' ' : $cnssB04->getNumAssure(),
  690.             //     $table, 
  691.             //     'numAssure', 
  692.             //     $cnssB04->getNumAssure() == 0 ? 'AN' : 'N'
  693.             // );
  694.             $nomPrenom $this->getFinalLength($cnssB04->getNomPrenom(),$table'nomPrenom''AN');
  695.             $numCIN $this->getFinalLength($cnssB04->getNumCIN(),$table'numCin''AN');
  696.             $nbrJours $this->getFinalLength($cnssB04->getNbrJours(),$table'nbrJours''NN');
  697.             $salReel $this->getFinalLength($cnssB04->getSalReel(),$table'salReel''NN');
  698.             $salPlaf $this->getFinalLength($cnssB04->getSalPlaf(),$table'salPlaf''NN');
  699.             $sCtr $this->getFinalLength($cnssB04->getSCtr(),$table'sCtr''NN');
  700.             $filler $this->getFinalLength($cnssB04->getFiller(),$table'filler''AN');
  701.             $myFinalData .= $typeEnreg $numAffilie $periode $numAssure $nomPrenom $numCIN $nbrJours $salReel $salPlaf $sCtr $filler.PHP_EOL;
  702.            
  703.         }
  704.        
  705.         
  706.         /* cnss_b05 */
  707.         $table TCnssB05::class;
  708.         // dd($cnssB05Data);
  709.         foreach ($cnssB00->getTCnssB05s() as $cnssB05) {
  710.             // dd($cnssB02->Num_Assure);
  711.             $typeEnreg $this->getFinalLength($cnssB05->getTypeEnreg(),$table'typeEnreg''AN');
  712.             $numAffilie $this->getFinalLength($cnssB05->getNumAffilie(),$table'numAffilie''N');
  713.             $periode $this->getFinalLength($cnssB05->getPeriode(),$table'periode''N');
  714.             $nbrSalaries $this->getFinalLength($cnssB05->getNbrSalaries(),$table'nbrSalaries''NN');
  715.             $tNumImma $this->getFinalLength($cnssB05->getTNumImma(),$table'tNumImma''NN');
  716.             $tJoursDeclares $this->getFinalLength($cnssB05->getTJoursDeclares(),$table'tJoursDeclares''NN');
  717.             $salReel $this->getFinalLength($cnssB05->getTSalaireReel(),$table'tSalaireReel''NN');
  718.             $salPlaf $this->getFinalLength($cnssB05->getTSalairePlaf(),$table'tSalairePlaf''NN');
  719.             $sCtr $this->getFinalLength($cnssB05->getTCtr(),$table'tCtr''NN');
  720.             $filler $this->getFinalLength($cnssB05->getFiller(),$table'filler''AN');
  721.             $myFinalData .= $typeEnreg $numAffilie $periode $nbrSalaries $tNumImma $tJoursDeclares $salReel $salPlaf $sCtr $filler.PHP_EOL;
  722.            
  723.         }
  724.         
  725.        
  726.         /* cnss_b06 */
  727.         // dd($cnssB06Data);
  728.         $table TCnssB06::class;
  729.         foreach ($cnssB00->getTCnssB06s() as $cnssB06) {
  730.             // dd($cnssB02->Num_Assure);
  731.             $typeEnreg $this->getFinalLength($cnssB06->getTypeEnreg(),$table'typeEnreg''AN');
  732.             $numAffilie $this->getFinalLength($cnssB06->getNumAffilie(),$table'numAffilie''N');
  733.             $periode $this->getFinalLength($cnssB06->getPeriode(),$table'periode''N');
  734.             $nbrSalaries $this->getFinalLength($cnssB06->getNbrSalaries(),$table'nbrSalaries''NN');
  735.             $tNumImma $this->getFinalLength($cnssB06->getTNumImma(),$table'tNumImma''NN');
  736.             $tJoursDeclares $this->getFinalLength($cnssB06->getTJoursDeclares(),$table'tJoursDeclares''NN');
  737.             $salReel $this->getFinalLength($cnssB06->getTSalaireReel(),$table'tSalaireReel''NN');
  738.             $salPlaf $this->getFinalLength($cnssB06->getTSalairePlaf(),$table'tSalairePlaf''NN');
  739.             $sCtr $this->getFinalLength($cnssB06->getTCtr(),$table'tCtr''NN');
  740.             $filler $this->getFinalLength($cnssB06->getFiller(),$table'filler''AN');
  741.             $myFinalData .= $typeEnreg $numAffilie $periode $nbrSalaries $tNumImma $tJoursDeclares $salReel $salPlaf $sCtr $filler.PHP_EOL;
  742.            
  743.         }
  744.         $tempFileName tempnam(sys_get_temp_dir(), 'text_file');
  745.         file_put_contents($tempFileName$myFinalData);
  746.         // Create a BinaryFileResponse
  747.         $response = new BinaryFileResponse($tempFileName);
  748.         // Set the response headers
  749.         $response->headers->set('Content-Type''text/plain');
  750.         $response->headers->set('Content-Disposition'$response->headers->makeDisposition(
  751.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  752.             $myFile.'.txt'
  753.         ));
  754.         return $response;
  755.        
  756.     }
  757.     // public function getFinalLengthCimr($data,$long, $type) {
  758.         
  759.     //     $diffrenceCaracterType =  $long - (int)(strlen($data));
  760.     //     if($diffrenceCaracterType==0) {
  761.     //         return $data; 
  762.     //     }
  763.     //     else {
  764.     //         if($type == 'A') {
  765.     //             return  $data .str_repeat(' ', $diffrenceCaracterType);
  766.     //         } else if ($type == 'N') {
  767.     //             return  str_repeat('0', $diffrenceCaracterType).$data ;
  768.     //         }
  769.     //         else if ($type == 'AN') {
  770.     //              return  $data.str_repeat(' ', $diffrenceCaracterType) ;
  771.     //         }   
  772.     //     }
  773.     // }
  774.     public function getFinalLength($data,$table,$column$type) {
  775.         $nom trim($data);
  776.         if($column == 'nomPrenom' and $table=='App\Entity\TCnssB02') {
  777.             // dd(());
  778.             // $data = preg_split('/\s{2,}/', $nom); this old code because i found el kihel has more than one whitespace in her last name
  779.             $data preg_split('/\s{3,}/'$nom);
  780.             if(count($data) < 2) {
  781.                 $data preg_split('/\s+/'$nom);
  782.                 if (count($data) == 3) {
  783.                     $data = [$data[0].' ' $data[1], $data[2]];
  784.                     //dd($data);
  785.                 }
  786.             }
  787.             $diffrence 30 - (int)strlen($data[0]);
  788.             $nom $data[0] . str_repeat(' '$diffrence);
  789.             $diffrence 30 - (int)strlen($data[1]);
  790.             $prenom $data[1] . str_repeat(' '$diffrence);
  791.             // dump(strip_tags($prenom));
  792.             // dd( $nom . $prenom);
  793.             return $nom $prenom;
  794.         }
  795.         $numberOfLengthColumn $this->getNumberOfLength($table$column);
  796.         if((strlen($data)) == $numberOfLengthColumn) {
  797.             return $data;
  798.         } 
  799.         else {
  800.             $diffrenceCaracterType =  $numberOfLengthColumn - (int)(strlen($data));
  801.             if($type == 'AN') {
  802.                 return $data str_repeat(' '$diffrenceCaracterType);
  803.             } else if ($type == 'N') {
  804.                 return $data str_repeat('0'$diffrenceCaracterType);
  805.             }
  806.             else if ($type == 'NN') {
  807.                // dd($data);
  808.                
  809.                 return  str_repeat('0'$diffrenceCaracterType).$data ;
  810.             }
  811.         }
  812.     }
  813.     public function getNumberOfLength($table$column) {
  814.         // $em = $this->getDoctrine()->getManager()->getConnection();
  815.         // $sql = "SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column'";
  816.         // $stmt  = $em->prepare($sql);
  817.         // $stmt->execute();
  818.         // // dd($stmt->fetch(PDO::FETCH_OBJ)->CHARACTER_MAXIMUM_LENGTH);
  819.         // return $stmt->fetch(PDO::FETCH_OBJ)->CHARACTER_MAXIMUM_LENGTH;
  820.         // $entityManager = $this->getDoctrine()->getManager();
  821.         $classMetadata $this->em->getClassMetadata($table);
  822.         $length $classMetadata->getFieldMapping($column)['length'];
  823.         return $length;
  824.     }
  825.     #[Route('/import'name'app_reporting_import_cnss'options: ['expose' => true])]
  826.     public function app_reporting_import_cnss(Request $request): Response
  827.     {
  828.         $reader = new Reader();
  829.         $spreadsheet $reader->load($request->files->get('file'));
  830.         $worksheet $spreadsheet->getActiveSheet();
  831.         $spreadSheetArys $worksheet->toArray();
  832.         unset($spreadSheetArys[0]);
  833.         foreach ($spreadSheetArys as $key => $sheet) {
  834.             $employe $this->em->getRepository(Pemploye::class)->findOneBy(['id' => $sheet[0], 'cin' => $sheet[1]]);
  835.             if(!$employe) {
  836.                 return new JsonResponse('Employe introuvable à la ligne '.($key 1).' !'500);                
  837.             }
  838.             if($sheet[5] != '') {
  839.                 $situation $this->em->getRepository(PsituationFamiliale::class)->findOneBy(['Abreviation' => $sheet[5]]);
  840.     
  841.                 if(!$situation) {
  842.                     return new JsonResponse('Situation introuvable à la ligne '.($key 1).' !'500);                
  843.                 }
  844.                 $employe->setSituationFamilialeId($situation);
  845.             }
  846.             if($sheet[6] != '') {
  847.                 $employe->setNbrPrisEnCharge($sheet[6]);
  848.                 foreach ($employe->getContracts() as $key => $contract) {
  849.                     $contract->setPriseEnCharge($sheet[6]);
  850.                 }
  851.             }
  852.             if($sheet[4] != '') {
  853.                 foreach ($employe->getContracts() as $key => $contract) {
  854.                     $contract->setCnss(trim($sheet[4]));
  855.                 }
  856.             }
  857.             if($sheet['7'] != '') {
  858.                 foreach ($employe->getContracts() as $key => $contract) {
  859.                     $contract->setDateCnss(new \DateTime($sheet['7']));
  860.                 }
  861.             }
  862.         }
  863.         
  864.         $this->em->flush();
  865.         return new JsonResponse('Bien enregistre !');
  866.     }
  867. }