src/Controller/HomeController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use PDO;
  4. use App\Entity\PArticles;
  5. use App\Entity\PFactures;
  6. use App\Entity\PReglements;
  7. use App\Entity\PNatureBenef;
  8. use App\Entity\PEtablissment;
  9. use App\Entity\PNatureCharge;
  10. use App\Entity\PBeneficiaires;
  11. use App\Entity\PChargeSociale;
  12. use App\Entity\PChargeSocialeLg;
  13. use App\Entity\Motivation;
  14. use App\Entity\POrganisme;
  15. use App\Entity\PChargeSocialeBenef;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  22. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  23. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  24. use \ZipArchive;
  25. class HomeController extends AbstractController
  26. {
  27.     /**
  28.      * @Route("/", name="dossier")
  29.      */
  30.     public function dossier(): Response
  31.     {
  32.         $etablissment $this->getDoctrine() ->getRepository(PEtablissment::class)->findBy(array('pec'=>'1'));
  33.         return $this->render('home/dossier.html.twig'
  34.         [ 'etablissment'=>$etablissment  ]);
  35.     }
  36.     /**
  37.      * @Route("/list/{etablissment}/{statut}", name="list_pec_charge")
  38.      */
  39.     function list(PEtablissment $etablissment$statutRequest $request): Response 
  40.     
  41.         $em $this->getDoctrine()->getManager();
  42.         $data= [];
  43.         $idbenefeciaire  "";
  44.         if(isset($_GET['idbenef'])){
  45.             $idbenefeciaire  $_GET['idbenef'];
  46.         }
  47.         
  48.         // $id_benefeciaire = $request->query;
  49.         if ( $idbenefeciaire) {
  50.            
  51.             $pecSociales$this->getDoctrine() ->getRepository(PChargeSociale::class)->findPecByBenef($idbenefeciaire,$etablissment->getId() );
  52.             foreach ($pecSociales as $pecSociale) {
  53.                 
  54.                 
  55.                 $nestedData = array();
  56.                 $MontantCharge $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pecSociale['id']);
  57.                 $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pecSociale['id']);
  58.                 $MontantRegl $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pecSociale['id']);
  59.                 $nestedData[] = "<a class='show-Pec' href='/show/Pec/".$etablissment->getId()."/".$pecSociale['id']."'>".$pecSociale['idChargeS']."</a>";
  60.                 $nestedData[] = date_format($pecSociale['dateCharge'], "d/m/Y");
  61.                 $nestedData[] = $pecSociale['etablissmentDemandeur'];
  62.                 $nestedData[] = $pecSociale['natureCharge'];
  63.                 $nestedData[] = $pecSociale['objet'];
  64.                 $nestedData[] = number_format($MontantCharge2',''') ;
  65.                 $nestedData[] = number_format($MontantFact2',''')  ;
  66.                 $nestedData[] = number_format($MontantRegl2',''')  ;
  67.                 $buttons "";
  68.                 
  69.                 if($MontantCharge $MontantFact && $MontantFact>0) {
  70.                     $buttons '<button type="button " class="dropdown-item btn-facture" name="'.$MontantCharge.'" id="'.$pecSociale['id'].'" data-toggle="modal" data-target="#ajouterModalFacture">FACTURER</button><button type="button " class="dropdown-item btn-reglement" id=""  name="'.$MontantFact.'" data-toggle="modal" data-target="#ajouterModalReglement">
  71.                     <input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
  72.                     <input type="number" hidden class="IdCharge" value="'.$pecSociale['id'].'">
  73.                     AJOUTER REGLEMENT 
  74.                 </button>';
  75.                 
  76.                 }elseif($MontantCharge $MontantFact) {
  77.                     $buttons '<button type="button " class="dropdown-item btn-facture" name="'.$MontantCharge.'" id="'.$pecSociale['id'].'" data-toggle="modal" data-target="#ajouterModalFacture">FACTURER</button>';
  78.                 
  79.                 }elseif ($MontantFact>&& $MontantRegl $MontantFact){
  80.                     $buttons '<button type="button " class="dropdown-item btn-reglement" id="" name="'.$MontantFact.'" data-toggle="modal" data-target="#ajouterModalReglement">
  81.                     <input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
  82.                     <input type="number" hidden class="IdCharge" value="'.$pecSociale['id'].'">
  83.                     AJOUTER REGLEMENT 
  84.                 </button>';
  85.                 }
  86.                 $path $this->generateUrl("pdf", ['etablissment' => $etablissment->getId(), 'id' => $pecSociale['id']]);
  87.                 
  88.                 if($pecSociale["statutPec"]=="annuler"){
  89.                     $nestedData[] = '<a class="a-href" href="'.$path.'" target="_blank" ><div class="cancel-symbol"></div></a>';
  90.                 }
  91.                 else{
  92.                     $nestedData[] = '<div class="btn-group dropdown-btn-action ">
  93.                                     <button type="button" class="btn btn-outline-info  btn-sm  dropdown-toggle btn-dropdown" id="dropdown_table" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  94.                                     <i class="fa fa-ellipsis-h"></i>
  95.                                     </button>
  96.                                     <div class="dropdown-menu dropdown-menu-right">
  97.                                         '.$buttons.'
  98.                                         <button type="button" class="dropdown-item" id="annuler-pec" name="'.$pecSociale['id'].'">
  99.                                             ANNULER
  100.                                         </button> 
  101.                                         <button type="button" class="dropdown-item ">
  102.                                             <a class="a-href" href="'.$path.'" target="_blank" > PDF </a>
  103.                                         </button>  
  104.                                     </div>
  105.                                 </div>';
  106.                 }
  107.                 // $nestedData[]=$pecSociale["statutPec"];
  108.                 // $nestedData["DT_RowId"] = $pChargeSociale->getId();
  109.                 // $nestedData["DT_RowClass"] = $pChargeSociale->getId();
  110.                 
  111.                 $data[] = $nestedData;
  112.                 // break ;
  113.             }
  114.             $json_data = array(
  115.                 "data" => $data,
  116.             );
  117.             return new Response(json_encode($json_data));
  118.             
  119.         }
  120.         else{
  121.             $condition=array( 'supprime'=>'0''idTier' => $etablissment->getId(),'statut'=>$statut );
  122.             if($statut =='toute'){
  123.                 $condition= array( 'supprime'=>'0''idTier' => $etablissment->getId() );
  124.             }
  125.             
  126.             
  127.             $pChargeSociales   $em->getRepository(PChargeSociale::class)->findBy($condition);
  128.             
  129.             
  130.             $data = array();
  131.             foreach ($pChargeSociales as $pChargeSociale) {
  132.                 $nestedData = array();
  133.                 $MontantCharge $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSociale);
  134.                 $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSociale);
  135.                 $MontantRegl $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSociale);
  136.                 $nestedData[] = "<a class='show-Pec' href='/show/Pec/".$etablissment->getId()."/".$pChargeSociale->getId()."'>".$pChargeSociale->getIdChargeS()."</a>";
  137.                 $nestedData[] = date_format($pChargeSociale->getDateCharge(), "d/m/Y");
  138.                 $nestedData[] = $pChargeSociale->getSite()->getEtablissment();
  139.                 $nestedData[] = $pChargeSociale->getNatureCharge()->getNatureCharge();
  140.                 $nestedData[] = $pChargeSociale->getObjet();
  141.                 $nestedData[] = "<span class='montant-td'>".number_format($MontantCharge2',''') ."</span>";
  142.                 $nestedData[] = "<span class='montant-td'>".number_format($MontantFact2',''')  ."</span>";
  143.                 $nestedData[] = "<span class='montant-td'>".number_format($MontantRegl2',''')  ."</span>";
  144.                 $buttons "";
  145.                 
  146.                 if($MontantCharge $MontantFact && $MontantFact>0) {
  147.                     $buttons '<button type="button " class="dropdown-item btn-facture" name="'.$MontantCharge.'" id="'.$pChargeSociale->getId().'" data-toggle="modal" data-target="#ajouterModalFacture">FACTURER</button><button type="button " class="dropdown-item btn-reglement" id="'.$pChargeSociale->getPFactures()[0]->getId().'" name="'.$MontantFact.'" data-toggle="modal" data-target="#ajouterModalReglement">
  148.                     <input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
  149.                     <input type="number" hidden class="IdCharge" value="'.$pChargeSociale->getId().'">
  150.                     AJOUTER REGLEMENT 
  151.                 </button>';
  152.                 
  153.                 }elseif($MontantCharge $MontantFact) {
  154.                     $buttons '<button type="button " class="dropdown-item btn-facture" name="'.$MontantCharge.'" id="'.$pChargeSociale->getId().'" data-toggle="modal" data-target="#ajouterModalFacture">FACTURER</button>';
  155.                 
  156.                 }elseif ($MontantFact>&& $MontantRegl $MontantFact){
  157.                     $buttons '<button type="button " class="dropdown-item btn-reglement" id="'.$pChargeSociale->getPFactures()[0]->getId().'" name="'.$MontantFact.'" data-toggle="modal" data-target="#ajouterModalReglement">
  158.                     <input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
  159.                     <input type="number" hidden class="IdCharge" value="'.$pChargeSociale->getId().'">
  160.                     AJOUTER REGLEMENT 
  161.                 </button>';
  162.                 }
  163.                 $path $this->generateUrl("pdf", ['etablissment' => $etablissment->getId(), 'id' => $pChargeSociale->getId()]);
  164.                 if($pChargeSociale->getStatut()=="annuler"){
  165.                     $nestedData[] = '<a class="a-href" href="'.$path.'" target="_blank" ><div class="cancel-symbol"></div></a>';
  166.                 }
  167.                 else{
  168.                     $nestedData[] = '<div class="btn-group dropdown-btn-action ">
  169.                     <button type="button" class="btn btn-outline-info  btn-sm  dropdown-toggle btn-dropdown" id="dropdown_table" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  170.                     <i class="fa fa-ellipsis-h"></i>
  171.                     </button>
  172.                     <div class="dropdown-menu dropdown-menu-right">
  173.                         '.$buttons.'
  174.                         <button type="button" class="dropdown-item" id="annuler-pec" name="'.$pChargeSociale->getId().'">
  175.                         ANNULER
  176.                         </button> 
  177.                         <button type="button" class="dropdown-item ">
  178.                             <a class="a-href" href="'.$path.'" target="_blank" > PDF </a>
  179.                         </button>                                                                            
  180.                     </div>
  181.                 </div>';
  182.                 }
  183.                 
  184.                 // $nestedData[]=$pChargeSociale->getStatut();
  185.                 // $nestedData["DT_RowId"] = $pChargeSociale->getId();
  186.                 // $nestedData["DT_RowClass"] = $pChargeSociale->getId();
  187.                 
  188.                 $data[] = $nestedData;
  189.                 // break ;
  190.             }
  191.             // dd($data);
  192.             $json_data = array(
  193.                 "data" => $data,
  194.             );
  195.             return new Response(json_encode($json_data));
  196.         }
  197.     }
  198.     /**
  199.      * @Route("home/{etablissment}/{statut}", name="home")
  200.      */
  201.     public function index($etablissment$statut): Response
  202.     {
  203.         
  204.         $etablissmentt $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  205.         
  206.         
  207.         return $this->render('home/index.html.twig'
  208.         [   
  209.             'statut' => $statut,
  210.             'etablissment'=>$etablissmentt
  211.         ]);
  212.     }
  213.     
  214.     /**
  215.      * @Route("/{action}/Pec/{etablissment}/{id}", name="ShowEdit")
  216.      */
  217.     public function showEdit($action ,$etablissment,$id): Response
  218.     {
  219.         
  220.         $pChargeSocia    $this->getDoctrine() ->getRepository(PChargeSociale::class)->findOneBy(array('id'=>$id));
  221.         $details        $this->getDoctrine() ->getRepository(PChargeSocialeLg::class)->findBy(array('chargeS'=>$id'supprime'=>0));
  222.  
  223.         $Benefeciaires  $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findBy(array('chargeS'=>$id'supprime'=>0));
  224.         $etabl   $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$pChargeSocia->getSite()));
  225.         
  226.         $MontantCharge $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
  227.         $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
  228.         $MontantRegl $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSocia);
  229.         $etablissmentt $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  230.         $organ;
  231.         $montantCharge$this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
  232.         $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
  233.      
  234.        
  235.         // dd($Benefeciaires);
  236.         if ($action=='show' || $pChargeSocia->getStatut()=="annuler"  || $montantCharge==$MontantFact && $montantCharge>) {
  237.             return $this->render('modal/show.html.twig'
  238.             [   'etablissment'      => $etablissmentt,
  239.                 'pChargeSocia'      => $pChargeSocia,
  240.                 'details'           => $details,
  241.                 'Benefeciaires'     => $Benefeciaires,
  242.                 'etabl'             => $etabl,
  243.                 'MontantCharge'     => $MontantCharge,
  244.                 'MontantFact'       => $MontantFact,
  245.                 'MontantRegl'       => $MontantRegl,
  246.                 'montantCharge'     => $montantCharge,
  247.                 'MontantFact'       => $MontantFact
  248.             ]);
  249.         }
  250.         else{
  251.             $all_etablissment $this->getDoctrine() ->getRepository(PEtablissment::class)->findAll();
  252.             $all_naturecharge $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  253.             $all_natureBenef $this->getDoctrine() ->getRepository(PNatureBenef::class)->findAll();
  254.             $all_benefeciaire $this->getDoctrine() ->getRepository(PBeneficiaires::class)->findAll();
  255.             $all_prestation $this->getDoctrine() ->getRepository(PNatureCharge::class)->find($pChargeSocia->getNatureCharge()->getId()); 
  256.             $motivations $this->getDoctrine() ->getRepository(Motivation::class)->findAll();
  257.             $organismes $this->getDoctrine() ->getRepository(POrganisme::class)->findAll();
  258.             return $this->render('modal/edit.html.twig'
  259.             [   'etablissment'      => $etablissmentt,
  260.                 'pChargeSocia'       => $pChargeSocia,
  261.                 'details'           => $details,
  262.                 'Benefeciaires'     => $Benefeciaires,
  263.                 'etabl'             => $etabl,
  264.                 'pChargeSocia'      => $pChargeSocia,
  265.                 'all_etablissment'  =>$all_etablissment,
  266.                 'all_naturecharge'  =>$all_naturecharge,
  267.                 'all_natureBenef'   =>$all_natureBenef,
  268.                 'all_benefeciaire'  =>$all_benefeciaire,
  269.                 'all_prestation'    =>$all_prestation,
  270.                 'motivations'       =>$motivations,
  271.                 'organismes'        =>$organismes
  272.             ]);
  273.         }
  274.     }
  275.     
  276.     
  277.     
  278.     /**
  279.      * @Route("{etablissment}/pec/new", name="interfaceNew")
  280.      */
  281.     public function newPec$etablissment): Response
  282.     {
  283.         // $pChargeSociale   = $this->getDoctrine()->getRepository(PChargeSociale::class)->findOnePec($etablissment);
  284.         $all_etablissment $this->getDoctrine() ->getRepository(PEtablissment::class)->findAll();
  285.         $etablissmentt $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  286.         $all_natureBenef $this->getDoctrine() ->getRepository(PNatureBenef::class)->findAll();
  287.         $all_benefeciaire $this->getDoctrine() ->getRepository(PBeneficiaires::class)->findAll();
  288.         $motivations $this->getDoctrine() ->getRepository(Motivation::class)->findAll();
  289.         $organismes $this->getDoctrine() ->getRepository(POrganisme::class)->findAll();
  290.         
  291.         return $this->render('modal/add.html.twig'
  292.         [   
  293.             // 'pChargeSociale'=>$pChargeSociale,
  294.             // 'etablissment'=>$etablissment,
  295.             'all_etablissment'=>$all_etablissment,
  296.             'etablissment'=>$etablissmentt,
  297.             'all_natureBenef'=>$all_natureBenef,
  298.             'all_benefeciaire'=>$all_benefeciaire,
  299.             'motivations'=>$motivations,
  300.             'organismes'=>$organismes
  301.         ]);
  302.     }
  303.     /**
  304.      * @Route("/delet", name="deletPec")
  305.      */
  306.     public function deletPec(Request $request)
  307.     {
  308.         $idPec$_GET['id_pec'];
  309.         $etablissment$_GET['etablissment'];
  310.         $entityManager $this->getDoctrine()->getManager();
  311.         $pChargeSociale $this->getDoctrine()->getRepository(PChargeSociale::class)->find(intval($idPec));
  312.         $pCFactures$this->getDoctrine()->getRepository(PFactures::class)->findBy(array('chargeS'=>$idPec));
  313.         $pChargeSociale -> setSupprime(1)
  314.                         ->setUser($this->getUser()->getUsername())
  315.                         -> setAction("supprimer");
  316.         $entityManager ->persist($pChargeSociale);
  317.         foreach ($pCFactures as $pCFacture) {
  318.             $pCFacture -> setSupprime(1);
  319.             $entityManager ->persist($pCFacture);
  320.         }
  321.                         
  322.         $entityManager->flush(); 
  323.         $this->addFlash('notice','Pris en charge a été supprimé avec succès');
  324.         return  $this->redirectToRoute('home', array('etablissment'=> $etablissment,'statut'=> 'toute'));
  325.     }
  326.     /**
  327.      * @Route("{etablissment}/PecSociale/{action}", name="insertUpdate")
  328.      */
  329.     public function insertUpdate($etablissment,Request $request$action): Response
  330.     {
  331.         $entityManager $this->getDoctrine()->getManager();
  332.       
  333.         
  334.         $montant    =$request->request->get('_montant');
  335.         $mtPec  =$request->request->get('_montantPec');
  336.         $TableBenef =json_decode($request->request->get('TableBenef'));
  337.             
  338.             if($action=='new'){
  339.                 // PChargeSociale
  340.                 $pChargeS  $this->getDoctrine()->getRepository(PChargeSociale::class)->findOneBy([], array('id'=>'DESC'));
  341.                 $numberPec='101001'+$pChargeS->getId();
  342.                 $idChargeS 'CHR_'.$numberPec;
  343.                 $message ='Pris en charge a été ajouté avec succès';
  344.                 $pChargeSociale = new PChargeSociale();
  345.                 $operation "ajouter";
  346.             }
  347.             else{
  348.                 $pChargeSociale $this->getDoctrine()->getRepository(PChargeSociale::class)->find(intval($action));
  349.                 // PChargeSocialeLg
  350.                 $id_sosiale_lg =$request->request->get('_id_sosiale_lg');
  351.                 // PChargeSocialeBenef
  352.                 $id_sosiale_benef    =$request->request->get('_id_sosiale_benef');
  353.                 $message ='Pris en charge a été modifié avec succès';
  354.                 $operation "modifier";
  355.             }
  356.             // *******************************
  357.             // ------ PChargeSociale --------
  358.             $etabl $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  359.             $nature_charge $this->getDoctrine()->getRepository(PNatureCharge::class)->find(intval($request->request->get('_nature_charge')));
  360.             $dateCharge = new \DateTime($request->request->get('_date_charge'));
  361.             $reference_doc $request->request->get('_reference_doc');
  362.             $date_doc = new \DateTime($request->request->get('_date_doc'));
  363.             $object $request->request->get('_object');
  364.             $detail_motivation $request->request->get('_detail_motivation');
  365.             $dNow        = new \DateTime(date("Y/m/d"));
  366.             
  367.             $nature_beneficiaire $this->getDoctrine()->getRepository(PNatureBenef::class)->find(intval($request->request->get('_nature_beneficiaire')));
  368.             $site_tier $this->getDoctrine()->getRepository(PEtablissment::class)->find(intval($etabl->getId()));
  369.             $motivation $this->getDoctrine()->getRepository(Motivation::class)->find(intval($request->request->get('_motivation')));
  370.             $site_demandeur $this->getDoctrine()->getRepository(PEtablissment::class)->find(intval($request->request->get('_site_demandeur')));
  371.             // *******************************
  372.             // ------ PChargeSocialeLg --------
  373.             $prestation =$request->request->get('_prestation');
  374.             $quantite   =$request->request->get('_quantite');
  375.             $base       =$request->request->get('_base');
  376.             $taux       =$request->request->get('_taux');
  377.             
  378.             // *******************************
  379.             // ------ PChargeSocialeBenef --------
  380.             
  381.             // dd($benefeciair);
  382.             $niveau  =$request->request->get('_niveau');
  383.             $annee  =$request->request->get('_annee');
  384.             $cutisation  =$request->request->get('_cutisation');
  385.             $id_dossier       =$request->request->get('_id_dossier');
  386.             $id_inscription   =$request->request->get('_id_inscription');
  387.             $id_preinscription       =$request->request->get('_id_preinscription');
  388.             $id_formation    =$request->request->get('_id_formation');
  389.             // ----------------------------------------------------------------
  390.             // dd(floatval($cutisation[2])  );
  391.             if($action=='new'){ 
  392.                 $pChargeSociale -> setIdChargeS($idChargeS)
  393.                                 -> setStatut('encours') ;
  394.             }
  395.             $pChargeSociale -> setDateCharge($dateCharge)
  396.                             -> setNatureCharge($nature_charge)
  397.                             -> setRefDocAssocier($reference_doc)
  398.                             -> setDateDocAssocier($date_doc)
  399.                             -> setObjet($object)
  400.                             -> setDateSys($dNow)
  401.                             -> setSite($site_demandeur)
  402.                             -> setNatureBenef($nature_beneficiaire)
  403.                             -> setIdTier($site_tier)
  404.                             -> setSupprime(0)
  405.                             -> setMotivation($motivation)
  406.                             -> setDetailMotivation($detail_motivation)
  407.                             -> setUser($this->getUser()->getUsername())
  408.                             -> setAction($operation);
  409.             if($request->request->get('_organisme')){
  410.                 $organisme $this->getDoctrine()->getRepository(POrganisme::class)->find(intval($request->request->get('_organisme')));
  411.                 $pChargeSociale -> setOrganisme($organisme);
  412.             }
  413.             $entityManager->persist($pChargeSociale);
  414.             // ----------------------------------------------------------------
  415.             if(trim($prestation != '')){
  416.                 for($i=0;$i<count($prestation);$i++){
  417.                     if(($prestation[$i])){
  418.                         if($action=='new'){ 
  419.                             $pChargeSocialeLg = new PChargeSocialeLg();
  420.                             $operation "ajouter";
  421.                             
  422.                         }
  423.                         else{
  424.                             if($id_sosiale_lg[$i]){
  425.                                 $pChargeSocialeLg $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->find(intval($id_sosiale_lg[$i]));
  426.                             }
  427.                             else{
  428.                                 $pChargeSocialeLg = new PChargeSocialeLg();
  429.                                 $operation "ajouter";
  430.                             }
  431.                         }
  432.                         $article=$this->getDoctrine()->getRepository(PArticles::class)->find(intval($prestation[$i]));
  433.                         // dd($article);
  434.                         $pChargeSocialeLg   ->setChargeS($pChargeSociale)
  435.                                             ->setArticle($article)
  436.                                             ->setQuantite($quantite[$i])
  437.                                             ->setBase($base[$i])
  438.                                             ->setTaux($taux[$i])
  439.                                             ->setMontantCharge(floatval($montant[$i]))
  440.                                             ->setDateSys($dNow)
  441.                                             ->setSupprime(0)
  442.                                             ->setUser($this->getUser()->getUsername())
  443.                                             -> setAction($operation);          
  444.                         $entityManager->persist($pChargeSocialeLg);
  445.                     }
  446.                 }
  447.             }
  448.             // ----------------------------------------------------------------
  449.            
  450.             if($TableBenef){
  451.                 foreach ($TableBenef as $tBenef) {
  452.                         if($action=='new'){ 
  453.                             $pChargeSocialeBenef = new PChargeSocialeBenef();
  454.                             $operation "ajouter";
  455.                         }
  456.                         else{
  457.                             if($tBenef->id_sosiale_benef){
  458.                                 $pChargeSocialeBenef $this->getDoctrine()->getRepository(PChargeSocialeBenef::class)->find(intval($tBenef->id_sosiale_benef));
  459.                                 $operation "modifier";
  460.                                  
  461.                             }
  462.                             else{
  463.                                 $pChargeSocialeBenef = new PChargeSocialeBenef();
  464.                                 $operation "ajouter";
  465.                             }
  466.                         }
  467.                         if($tBenef->NFacture){
  468.                             $numFacture $this->getDoctrine() ->getRepository(PFactures::class)->findBy(array('refFacture'=>$tBenef->NFacture'supprime'=>0));
  469.                             if($numFacture){
  470.                                 $error "le numéro de facture '".$tBenef->NFacture."' déjà existe ";
  471.                                 return new JsonResponse(array('Boolean' => 'false''error' =>$error));
  472.                             }
  473.                             $pFactures = new PFactures();
  474.                             $pFactures  ->setChargeS($pChargeSociale)
  475.                             ->setDateFacture(new \DateTime($tBenef->dateFacture))
  476.                             ->setMontantFact(floatval($tBenef->montantFactuer))
  477.                             ->setDateSys($dNow)
  478.                             ->setRefFacture($tBenef->NFacture)
  479.                             ->setIdTier($site_tier->getEtablissment())
  480.                             ->setObservation($tBenef->observation)
  481.                             ->setSupprime(0);
  482.                             $entityManager->persist($pFactures);
  483.                             $pChargeSocialeBenef ->setFacture($pFactures);
  484.                             
  485.                         }
  486.                         
  487.                         if($tBenef->benef==0){
  488.                             $pbenef  $this->getDoctrine()->getRepository(PBeneficiaires::class)->findOneBy([], array('id'=>'DESC'));
  489.                             $numberBenef='101001'+$pbenef->getId();
  490.                             $idBenefeciaire 'BEF_'.$numberBenef;
  491.                             $pBeneficiaires = new PBeneficiaires();
  492.                             $pBeneficiaires -> setBeneficiaire($tBenef->NAME)
  493.                                             ->setIdBeneficiaires($idBenefeciaire)
  494.                                             -> setDateSys($dNow);
  495.                             $entityManager->persist($pBeneficiaires);
  496.                         }else{
  497.                             $pBeneficiaires=$this->getDoctrine()->getRepository(PBeneficiaires::class)->find(intval($tBenef->benef));
  498.                         }
  499.                         
  500.                         $pChargeSocialeBenef    ->setChargeS($pChargeSociale)
  501.                                                 ->setBeneficiaire($pBeneficiaires)
  502.                                                 ->setNiveau($tBenef->NIVEAU)
  503.                                                 ->setAnneeUniv($tBenef->ANNEE)
  504.                                                 ->setCotisation(floatval($tBenef->CUTISATION))
  505.                                                 ->setDateSys($dNow)
  506.                                                 ->setIdDossier($tBenef->DOSSIER)
  507.                                                 ->setIdInscription($tBenef->INSCRIPTION)
  508.                                                 ->setIdPreinscription($tBenef->PREINSCRIPTION)
  509.                                                 ->setIdFormation($tBenef->FORMATION)
  510.                                                 -> setSupprime(0)
  511.                                                 -> setMontantPrest(floatval($tBenef->MTPEC))
  512.                                                 -> setUser($this->getUser()->getUsername())
  513.                                                 -> setAction($operation); 
  514.                                                 
  515.                         $entityManager->persist($pChargeSocialeBenef);
  516.                       
  517.                 }
  518.             }else{
  519.                 $error " Veuillez remplir les informations sur le bénéficiaire ! ";
  520.                 return new JsonResponse(array('Boolean' => 'false''error' =>$error));
  521.             }
  522.             
  523.             $entityManager->flush();        
  524.             
  525.             // dd($TableBenef);
  526.             return new JsonResponse(array('Boolean' => 'true'));
  527.         
  528.     }
  529.     /**
  530.      * @Route("/annulerPec/{id}", name="annulerPec")
  531.      */
  532.     public function annulerPec(Request $request$id)
  533.     {
  534.         if($request->isXmlHttpRequest()) {
  535.           
  536.             $entityManager $this->getDoctrine()->getManager();
  537.         
  538.             $dNow = new \DateTime(date("Y/m/d"));
  539.                 $pChargeSociale $this->getDoctrine()->getRepository(PChargeSociale::class)->find(intval($id));  
  540.                 $montantCharge$this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSociale);
  541.                 $article=$this->getDoctrine()->getRepository(PArticles::class)->find(60);
  542.                     // dd($pChargeSociale) ;      
  543.                 $pChargeSocialeLg = new PChargeSocialeLg();
  544.                 $pChargeSocialeLg   ->setChargeS($pChargeSociale)
  545.                                     ->setArticle($article)
  546.                                     ->setQuantite(1)
  547.                                     ->setBase($montantCharge*(-1))
  548.                                     ->setTaux(100)
  549.                                     ->setMontantCharge(floatval($montantCharge*(-1)))
  550.                                     ->setDateSys($dNow)
  551.                                     ->setSupprime(0)
  552.                                     ->setUser($this->getUser()->getUsername())
  553.                                     -> setAction("annulation");          
  554.                 $entityManager->persist($pChargeSocialeLg);
  555.                 $pChargeSociale-> setStatut('annuler');
  556.                 $entityManager->persist($pChargeSociale);
  557.                 
  558.                     
  559.                 $entityManager->flush();
  560.             return new JsonResponse('ok');     
  561.         }
  562.     }
  563.         
  564.    
  565.     /**
  566.      * @Route("/pdf/{etablissment}/{id}", name="pdf")
  567.      */
  568.     public function pdf($etablissment,$id) : response
  569.     {
  570.         $information    $this->getDoctrine() ->getRepository(PChargeSociale::class)->findOneBy(array('id'=>$id));
  571.         $details        $this->getDoctrine() ->getRepository(PChargeSocialeLg::class)->findBy(array('chargeS'=>$id'supprime'=>0));
  572.         $Benefeciaires  $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findBy(array('chargeS'=>$id'supprime'=>0));
  573.         $etabl   $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$information->getSite()));
  574.         $MontantCharge $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($information);
  575.         $oneBenefeciaire$this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findOneBy(array('chargeS'=>$id));
  576.         $etablissmentt $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  577.         $ListeBenefeciaires  $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findByBenef($id);
  578.         // dd($Benefeciaires);
  579.         
  580.         $donneeInsc=null;
  581.         if($oneBenefeciaire->getIdInscription()){
  582.             $em $this->getDoctrine()->getManager()->getConnection();
  583.             $statement $em->prepare(' SELECT ins.code_inscription, ins.cin , pre.code_cab , pre.date_naissance, pre.lieu_naissance, pre.tel1, pre.adresse, prom.promotion, prom.formation   FROM x_inscription ins   INNER JOIN t_preinscription pre ON ins.code_etudiant=pre.code_etudiant
  584.             INNER JOIN v_promotion prom ON ins.promotion = prom.code_promotion
  585.             WHERE ins.code_inscription like"'.$oneBenefeciaire->getIdInscription().'" LIMIT 1');
  586.             $resultSet $statement->executeQuery();
  587.             $data $resultSet->fetchAll();
  588.                         
  589.                 // dd($all_natureCharge)  ;   
  590.             if($data){
  591.                 foreach($data as $dt){
  592.                     $donneeInsc=$dt;
  593.                     // dd($donneeInsc);
  594.                 }
  595.             }
  596.         }
  597.         if($etablissment==31){
  598.             $typePdf="CENTRE_SOCIAL_DACTIVITEES_AU_PROFIT_PERSONNEL_ET_AYANTS_DROIT.html.twig";
  599.         }
  600.         else if($etablissment==8){
  601.             $typePdf="CENTRE_SOCIAL_MOBILE_DES_SOINS_MEDICAUX_RABAT.html.twig";
  602.         }
  603.         else if($etablissment==49){
  604.             $typePdf="DEPARTEMENT_SOCIAL_PEC_MEDICALE_FCZ_RABAT.html.twig";
  605.         }
  606.         else if($etablissment==62){
  607.             $typePdf="HOPITAUX_PUBLICS_PARTENAIRES_RABAT.html.twig";
  608.         }
  609.         else if($etablissment==68){
  610.             $typePdf="DEPARTEMENT_SOCIAL_DE_BOURSES_DEXCELLENCE_FCZ_RABAT.html.twig";
  611.         }
  612.         else if($etablissment==69){
  613.             $typePdf="LA_MAROCAINE_DES_ŒUVRES_SOCIALES_FCZ.html.twig";
  614.         }
  615.         
  616.         $mpdf = new \Mpdf\Mpdf(['mode' => 'C','format' => 'A4','margin_header' => 5,'margin_footer' => 5,'margin_top' => 80,'margin_bottom' => 35]);
  617.         $html $this->renderView('pdf/'.$typePdf, array(
  618.             'etablissment'  => $etablissmentt,
  619.             'information'   => $information,
  620.             'details'       => $details,
  621.             'Benefeciaires' => $Benefeciaires,
  622.             'etabl'         => $etabl,
  623.             'MontantCharge'  => $MontantCharge,
  624.             'oneBenefeciaire' => $oneBenefeciaire,
  625.             'donneeInsc' => $donneeInsc,
  626.             'ListeBenefeciaires' => $ListeBenefeciaires
  627.         ));
  628.         $mpdf->WriteHTML($html);
  629.         $mpdf->Output();
  630.         return 1;
  631.     }
  632.     /**
  633.      * @Route("/excel/{etablissment}/{statut}", name="ExporterExcel")
  634.      */
  635.     public function ExporterExcel(PEtablissment $etablissment$statut)
  636.     {
  637.         array_map('unlink'glob"*.zip"));     
  638.         $zip = new ZipArchive();
  639.         $zipname 'ChargeSociales'.uniqid().'.zip';
  640.         $zip->open($zipnameZipArchive::CREATE);
  641.         $spreadsheet = new Spreadsheet();
  642.         $condition=array( 'supprime'=>'0''idTier' => $etablissment->getId(),'statut'=>$statut );
  643.         if($statut =='toute'){
  644.             $condition= array( 'supprime'=>'0''idTier' => $etablissment->getId() );
  645.         }
  646.         $em $this->getDoctrine()->getManager();
  647.         $pChargeSociales   $em->getRepository(PChargeSociale::class)->findBy($condition);
  648.         // dd($pChargeSociales);
  649.         $sheet $spreadsheet->getActiveSheet();
  650.         $sheet->setCellValue('A1''ID CHARGE');
  651.         $sheet->setCellValue('B1''DATE CHARGE');
  652.         $sheet->setCellValue('C1''ETABLISSEMENT DEMANDEUR');
  653.         $sheet->setCellValue('D1''NATURE CHARGE');
  654.         $sheet->setCellValue('E1''NATURE BENEFECIAIRE');
  655.         $sheet->setCellValue('F1''MOTIVATION');
  656.         $sheet->setCellValue('G1''DEDAIL MOTIVATION');
  657.         $sheet->setCellValue('H1''OBJET');
  658.         $sheet->setCellValue('I1''ORGANISME');
  659.         $sheet->setCellValue('J1''CHARGE'); 
  660.         $sheet->setCellValue('K1''FACTURE'); 
  661.         $sheet->setCellValue('L1''REGLEMENT'); 
  662.   
  663.        $i=2;
  664.       
  665.         foreach($pChargeSociales as $pChargeSociale){
  666.             $MontantCharge $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSociale);
  667.             $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSociale);
  668.             $MontantRegl $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSociale);
  669.             $sheet->setCellValue('A'.$i$pChargeSociale->getIdChargeS());
  670.             $sheet->setCellValue('B'.$idate_format($pChargeSociale->getDateCharge(), "d/m/Y"));
  671.             $sheet->setCellValue('C'.$i$pChargeSociale->getSite()->getEtablissment());
  672.             $sheet->setCellValue('D'.$i$pChargeSociale->getNatureCharge()->getNatureCharge());
  673.             $sheet->setCellValue('E'.$i$pChargeSociale->getNatureBenef()->getNatureBenef());
  674.             if($pChargeSociale->getMotivation()){
  675.                 $sheet->setCellValue('F'.$i$pChargeSociale->getMotivation()->getMotivation());
  676.             }else{
  677.                 $sheet->setCellValue('F'.$i"  ");  
  678.             }
  679.             $sheet->setCellValue('G'.$i$pChargeSociale->getDetailMotivation());
  680.             $sheet->setCellValue('H'.$i$pChargeSociale->getObjet());
  681.             if($pChargeSociale->getOrganisme()){
  682.                 $sheet->setCellValue('I'.$i$pChargeSociale->getOrganisme()->getOrganisme());
  683.             }else{
  684.                 $sheet->setCellValue('I'.$i"  ");  
  685.             }
  686.             $sheet->setCellValue('J'.$inumber_format($MontantCharge2','''));
  687.             $sheet->setCellValue('K'.$inumber_format($MontantFact2',''') );
  688.             $sheet->setCellValue('L'.$inumber_format($MontantRegl2',''') );
  689.          
  690.            $i++;
  691.          }
  692.          foreach(range('A','Z') as $columnID)
  693.          {
  694.              $sheet->getColumnDimension($columnID)->setAutoSize(true);
  695.          }  
  696.         /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  697.             $sheet->setTitle("PecSociale");
  698.         // Create your Office 2007 Excel (XLSX Format)
  699.             $writer = new Xlsx($spreadsheet);
  700.         // Create a Temporary file in the system
  701.             $fileName $etablissment->getEtablissment().'.xlsx';
  702.         // Create the excel file in the tmp directory of the system
  703.         $writer->save($fileName);
  704.         $zip->addFile($fileName);
  705.         
  706.     
  707.         // ________________________________________________________________
  708.         $spreadsheet = new Spreadsheet();
  709.         $sheet $spreadsheet->getActiveSheet();
  710.         $sheet->setCellValue('A1''ID CHARGE');
  711.         $sheet->setCellValue('B1''BÉNÉFECIAIRE');
  712.         $sheet->setCellValue('C1''DOSSIER');
  713.         $sheet->setCellValue('D1''DEMANDEUR');
  714.         $sheet->setCellValue('E1''NATURE PEC');
  715.         $sheet->setCellValue('f1''DATE PEC');
  716.         $sheet->setCellValue('G1''REF FACTURE');
  717.         $sheet->setCellValue('H1''DATE FACTURE');
  718.         $sheet->setCellValue('I1''COTISATION');
  719.         $sheet->setCellValue('J1''MONTANT PREST');
  720.         $sheet->setCellValue('K1''NIVEAU');
  721.         $sheet->setCellValue('L1''ANNEE UNIV');
  722.         $i=2;
  723.       
  724.         foreach($pChargeSociales as $pChargeSociale){
  725.             $ListeBenefeciaires  $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findByBenef($pChargeSociale->getId());
  726.             foreach($ListeBenefeciaires as $ListeBenefeciaire){
  727.                 $sheet->setCellValue('A'.$i$ListeBenefeciaire['idChargeS']);
  728.                 $sheet->setCellValue('B'.$i$ListeBenefeciaire['beneficiaire']);
  729.                 $sheet->setCellValue('C'.$i$ListeBenefeciaire['idDossier']);
  730.                 $sheet->setCellValue('D'.$i$ListeBenefeciaire['etablissment']);
  731.                 $sheet->setCellValue('E'.$i$ListeBenefeciaire['natureCharge']);
  732.                 $sheet->setCellValue('F'.$i$ListeBenefeciaire['dateCharge']);
  733.                 $sheet->setCellValue('G'.$i$ListeBenefeciaire['refFacture']);
  734.                 if($ListeBenefeciaire['dateFacture']){
  735.                     $sheet->setCellValue('H'.$idate_format($ListeBenefeciaire['dateFacture'], "d/m/Y"));
  736.                 }else{
  737.                     $sheet->setCellValue('H'.$i"  "); 
  738.                 }
  739.                 $sheet->setCellValue('I'.$i$ListeBenefeciaire['cotisation']);
  740.                 $sheet->setCellValue('J'.$i$ListeBenefeciaire['montantPrest']);
  741.                 $sheet->setCellValue('K'.$i$ListeBenefeciaire['niveau']);
  742.                 $sheet->setCellValue('L'.$i$ListeBenefeciaire['anneeUniv']);
  743.                 $i++;
  744.             }
  745.          }
  746.          foreach(range('A','Z') as $columnID)
  747.          {
  748.              $sheet->getColumnDimension($columnID)->setAutoSize(true);
  749.          }  
  750.         /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  751.          $sheet->setTitle("Benefeciaire");
  752.         
  753.         // Create your Office 2007 Excel (XLSX Format)
  754.         $writer = new Xlsx($spreadsheet);
  755.         
  756.         // Create a Temporary file in the system
  757.         $fileName 'benefeciaires.xlsx';
  758.         
  759.         // Create the excel file in the tmp directory of the system
  760.         $writer->save($fileName);
  761.         $zip->addFile($fileName);
  762.         
  763.         $zip->close();
  764.         // $temp_file = tempnam(sys_get_temp_dir(), $zipname);
  765.         array_map('unlink'glob"*.xlsx"));
  766.         return new JsonResponse$zipname);
  767.     }
  768.     /**
  769.      * @Route("/Pec/{etablissment}/{id}/dupliquer", name="dupliquerPec")
  770.      */
  771.     public function dupliquerPec($etablissment,$id): Response
  772.     {
  773.         
  774.         $pChargeSocia    $this->getDoctrine() ->getRepository(PChargeSociale::class)->findOneBy(array('id'=>$id));
  775.         $details        $this->getDoctrine() ->getRepository(PChargeSocialeLg::class)->findBy(array('chargeS'=>$id'supprime'=>0));
  776.  
  777.         $Benefeciaires  $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findBy(array('chargeS'=>$id'supprime'=>0));
  778.         $etabl   $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$pChargeSocia->getSite()));
  779.         
  780.         $MontantCharge $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
  781.         $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
  782.         $MontantRegl $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSocia);
  783.         $etablissmentt $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  784.         $organ;
  785.         $montantCharge$this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
  786.         $MontantFact $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
  787.      
  788.        
  789.             $all_etablissment $this->getDoctrine() ->getRepository(PEtablissment::class)->findAll();
  790.             $all_naturecharge $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
  791.             $all_natureBenef $this->getDoctrine() ->getRepository(PNatureBenef::class)->findAll();
  792.             $all_benefeciaire $this->getDoctrine() ->getRepository(PBeneficiaires::class)->findAll();
  793.             $all_prestation $this->getDoctrine() ->getRepository(PNatureCharge::class)->find($pChargeSocia->getNatureCharge()->getId()); 
  794.             $motivations $this->getDoctrine() ->getRepository(Motivation::class)->findAll();
  795.             $organismes $this->getDoctrine() ->getRepository(POrganisme::class)->findAll();
  796.         return $this->render('modal/DupliquerPec.html.twig'
  797.         [   'etablissment'      => $etablissmentt,
  798.             'pChargeSocia'       => $pChargeSocia,
  799.             'details'           => $details,
  800.             'Benefeciaires'     => $Benefeciaires,
  801.             'etabl'             => $etabl,
  802.             'pChargeSocia'      => $pChargeSocia,
  803.             'all_etablissment'  =>$all_etablissment,
  804.             'all_naturecharge'  =>$all_naturecharge,
  805.             'all_natureBenef'   =>$all_natureBenef,
  806.             'all_benefeciaire'  =>$all_benefeciaire,
  807.             'all_prestation'    =>$all_prestation,
  808.             'motivations'       =>$motivations,
  809.             'organismes'        =>$organismes
  810.         ]);
  811.         
  812.     }
  813. }
  814.