<?php
namespace App\Controller;
use PDO;
use App\Entity\PArticles;
use App\Entity\PFactures;
use App\Entity\PReglements;
use App\Entity\PNatureBenef;
use App\Entity\PEtablissment;
use App\Entity\PNatureCharge;
use App\Entity\PBeneficiaires;
use App\Entity\PChargeSociale;
use App\Entity\PChargeSocialeLg;
use App\Entity\Motivation;
use App\Entity\POrganisme;
use App\Entity\PChargeSocialeBenef;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use \ZipArchive;
class HomeController extends AbstractController
{
/**
* @Route("/", name="dossier")
*/
public function dossier(): Response
{
$etablissment = $this->getDoctrine() ->getRepository(PEtablissment::class)->findBy(array('pec'=>'1'));
return $this->render('home/dossier.html.twig',
[ 'etablissment'=>$etablissment ]);
}
/**
* @Route("/list/{etablissment}/{statut}", name="list_pec_charge")
*/
function list(PEtablissment $etablissment, $statut, Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$data= [];
$idbenefeciaire = "";
if(isset($_GET['idbenef'])){
$idbenefeciaire = $_GET['idbenef'];
}
// $id_benefeciaire = $request->query;
if ( $idbenefeciaire) {
$pecSociales= $this->getDoctrine() ->getRepository(PChargeSociale::class)->findPecByBenef($idbenefeciaire,$etablissment->getId() );
foreach ($pecSociales as $pecSociale) {
$nestedData = array();
$MontantCharge = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pecSociale['id']);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pecSociale['id']);
$MontantRegl = $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pecSociale['id']);
$nestedData[] = "<a class='show-Pec' href='/show/Pec/".$etablissment->getId()."/".$pecSociale['id']."'>".$pecSociale['idChargeS']."</a>";
$nestedData[] = date_format($pecSociale['dateCharge'], "d/m/Y");
$nestedData[] = $pecSociale['etablissmentDemandeur'];
$nestedData[] = $pecSociale['natureCharge'];
$nestedData[] = $pecSociale['objet'];
$nestedData[] = number_format($MontantCharge, 2, ',', '') ;
$nestedData[] = number_format($MontantFact, 2, ',', '') ;
$nestedData[] = number_format($MontantRegl, 2, ',', '') ;
$buttons = "";
if($MontantCharge > $MontantFact && $MontantFact>0) {
$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">
<input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
<input type="number" hidden class="IdCharge" value="'.$pecSociale['id'].'">
AJOUTER REGLEMENT
</button>';
}elseif($MontantCharge > $MontantFact) {
$buttons = '<button type="button " class="dropdown-item btn-facture" name="'.$MontantCharge.'" id="'.$pecSociale['id'].'" data-toggle="modal" data-target="#ajouterModalFacture">FACTURER</button>';
}elseif ($MontantFact>0 && $MontantRegl < $MontantFact){
$buttons = '<button type="button " class="dropdown-item btn-reglement" id="" name="'.$MontantFact.'" data-toggle="modal" data-target="#ajouterModalReglement">
<input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
<input type="number" hidden class="IdCharge" value="'.$pecSociale['id'].'">
AJOUTER REGLEMENT
</button>';
}
$path = $this->generateUrl("pdf", ['etablissment' => $etablissment->getId(), 'id' => $pecSociale['id']]);
if($pecSociale["statutPec"]=="annuler"){
$nestedData[] = '<a class="a-href" href="'.$path.'" target="_blank" ><div class="cancel-symbol"></div></a>';
}
else{
$nestedData[] = '<div class="btn-group dropdown-btn-action ">
<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">
<i class="fa fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu dropdown-menu-right">
'.$buttons.'
<button type="button" class="dropdown-item" id="annuler-pec" name="'.$pecSociale['id'].'">
ANNULER
</button>
<button type="button" class="dropdown-item ">
<a class="a-href" href="'.$path.'" target="_blank" > PDF </a>
</button>
</div>
</div>';
}
// $nestedData[]=$pecSociale["statutPec"];
// $nestedData["DT_RowId"] = $pChargeSociale->getId();
// $nestedData["DT_RowClass"] = $pChargeSociale->getId();
$data[] = $nestedData;
// break ;
}
$json_data = array(
"data" => $data,
);
return new Response(json_encode($json_data));
}
else{
$condition=array( 'supprime'=>'0', 'idTier' => $etablissment->getId(),'statut'=>$statut );
if($statut =='toute'){
$condition= array( 'supprime'=>'0', 'idTier' => $etablissment->getId() );
}
$pChargeSociales = $em->getRepository(PChargeSociale::class)->findBy($condition);
$data = array();
foreach ($pChargeSociales as $pChargeSociale) {
$nestedData = array();
$MontantCharge = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSociale);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSociale);
$MontantRegl = $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSociale);
$nestedData[] = "<a class='show-Pec' href='/show/Pec/".$etablissment->getId()."/".$pChargeSociale->getId()."'>".$pChargeSociale->getIdChargeS()."</a>";
$nestedData[] = date_format($pChargeSociale->getDateCharge(), "d/m/Y");
$nestedData[] = $pChargeSociale->getSite()->getEtablissment();
$nestedData[] = $pChargeSociale->getNatureCharge()->getNatureCharge();
$nestedData[] = $pChargeSociale->getObjet();
$nestedData[] = "<span class='montant-td'>".number_format($MontantCharge, 2, ',', '') ."</span>";
$nestedData[] = "<span class='montant-td'>".number_format($MontantFact, 2, ',', '') ."</span>";
$nestedData[] = "<span class='montant-td'>".number_format($MontantRegl, 2, ',', '') ."</span>";
$buttons = "";
if($MontantCharge > $MontantFact && $MontantFact>0) {
$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">
<input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
<input type="number" hidden class="IdCharge" value="'.$pChargeSociale->getId().'">
AJOUTER REGLEMENT
</button>';
}elseif($MontantCharge > $MontantFact) {
$buttons = '<button type="button " class="dropdown-item btn-facture" name="'.$MontantCharge.'" id="'.$pChargeSociale->getId().'" data-toggle="modal" data-target="#ajouterModalFacture">FACTURER</button>';
}elseif ($MontantFact>0 && $MontantRegl < $MontantFact){
$buttons = '<button type="button " class="dropdown-item btn-reglement" id="'.$pChargeSociale->getPFactures()[0]->getId().'" name="'.$MontantFact.'" data-toggle="modal" data-target="#ajouterModalReglement">
<input type="number" hidden class="MontantRegl" value="'.$MontantRegl.'">
<input type="number" hidden class="IdCharge" value="'.$pChargeSociale->getId().'">
AJOUTER REGLEMENT
</button>';
}
$path = $this->generateUrl("pdf", ['etablissment' => $etablissment->getId(), 'id' => $pChargeSociale->getId()]);
if($pChargeSociale->getStatut()=="annuler"){
$nestedData[] = '<a class="a-href" href="'.$path.'" target="_blank" ><div class="cancel-symbol"></div></a>';
}
else{
$nestedData[] = '<div class="btn-group dropdown-btn-action ">
<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">
<i class="fa fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu dropdown-menu-right">
'.$buttons.'
<button type="button" class="dropdown-item" id="annuler-pec" name="'.$pChargeSociale->getId().'">
ANNULER
</button>
<button type="button" class="dropdown-item ">
<a class="a-href" href="'.$path.'" target="_blank" > PDF </a>
</button>
</div>
</div>';
}
// $nestedData[]=$pChargeSociale->getStatut();
// $nestedData["DT_RowId"] = $pChargeSociale->getId();
// $nestedData["DT_RowClass"] = $pChargeSociale->getId();
$data[] = $nestedData;
// break ;
}
// dd($data);
$json_data = array(
"data" => $data,
);
return new Response(json_encode($json_data));
}
}
/**
* @Route("home/{etablissment}/{statut}", name="home")
*/
public function index($etablissment, $statut): Response
{
$etablissmentt = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
return $this->render('home/index.html.twig',
[
'statut' => $statut,
'etablissment'=>$etablissmentt
]);
}
/**
* @Route("/{action}/Pec/{etablissment}/{id}", name="ShowEdit")
*/
public function showEdit($action ,$etablissment,$id): Response
{
$pChargeSocia = $this->getDoctrine() ->getRepository(PChargeSociale::class)->findOneBy(array('id'=>$id));
$details = $this->getDoctrine() ->getRepository(PChargeSocialeLg::class)->findBy(array('chargeS'=>$id, 'supprime'=>0));
$Benefeciaires = $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findBy(array('chargeS'=>$id, 'supprime'=>0));
$etabl = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$pChargeSocia->getSite()));
$MontantCharge = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
$MontantRegl = $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSocia);
$etablissmentt = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$organ;
$montantCharge= $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
// dd($Benefeciaires);
if ($action=='show' || $pChargeSocia->getStatut()=="annuler" || $montantCharge==$MontantFact && $montantCharge>0 ) {
return $this->render('modal/show.html.twig',
[ 'etablissment' => $etablissmentt,
'pChargeSocia' => $pChargeSocia,
'details' => $details,
'Benefeciaires' => $Benefeciaires,
'etabl' => $etabl,
'MontantCharge' => $MontantCharge,
'MontantFact' => $MontantFact,
'MontantRegl' => $MontantRegl,
'montantCharge' => $montantCharge,
'MontantFact' => $MontantFact
]);
}
else{
$all_etablissment = $this->getDoctrine() ->getRepository(PEtablissment::class)->findAll();
$all_naturecharge = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$all_natureBenef = $this->getDoctrine() ->getRepository(PNatureBenef::class)->findAll();
$all_benefeciaire = $this->getDoctrine() ->getRepository(PBeneficiaires::class)->findAll();
$all_prestation = $this->getDoctrine() ->getRepository(PNatureCharge::class)->find($pChargeSocia->getNatureCharge()->getId());
$motivations = $this->getDoctrine() ->getRepository(Motivation::class)->findAll();
$organismes = $this->getDoctrine() ->getRepository(POrganisme::class)->findAll();
return $this->render('modal/edit.html.twig',
[ 'etablissment' => $etablissmentt,
'pChargeSocia' => $pChargeSocia,
'details' => $details,
'Benefeciaires' => $Benefeciaires,
'etabl' => $etabl,
'pChargeSocia' => $pChargeSocia,
'all_etablissment' =>$all_etablissment,
'all_naturecharge' =>$all_naturecharge,
'all_natureBenef' =>$all_natureBenef,
'all_benefeciaire' =>$all_benefeciaire,
'all_prestation' =>$all_prestation,
'motivations' =>$motivations,
'organismes' =>$organismes
]);
}
}
/**
* @Route("{etablissment}/pec/new", name="interfaceNew")
*/
public function newPec( $etablissment): Response
{
// $pChargeSociale = $this->getDoctrine()->getRepository(PChargeSociale::class)->findOnePec($etablissment);
$all_etablissment = $this->getDoctrine() ->getRepository(PEtablissment::class)->findAll();
$etablissmentt = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$all_natureBenef = $this->getDoctrine() ->getRepository(PNatureBenef::class)->findAll();
$all_benefeciaire = $this->getDoctrine() ->getRepository(PBeneficiaires::class)->findAll();
$motivations = $this->getDoctrine() ->getRepository(Motivation::class)->findAll();
$organismes = $this->getDoctrine() ->getRepository(POrganisme::class)->findAll();
return $this->render('modal/add.html.twig',
[
// 'pChargeSociale'=>$pChargeSociale,
// 'etablissment'=>$etablissment,
'all_etablissment'=>$all_etablissment,
'etablissment'=>$etablissmentt,
'all_natureBenef'=>$all_natureBenef,
'all_benefeciaire'=>$all_benefeciaire,
'motivations'=>$motivations,
'organismes'=>$organismes
]);
}
/**
* @Route("/delet", name="deletPec")
*/
public function deletPec(Request $request)
{
$idPec= $_GET['id_pec'];
$etablissment= $_GET['etablissment'];
$entityManager = $this->getDoctrine()->getManager();
$pChargeSociale = $this->getDoctrine()->getRepository(PChargeSociale::class)->find(intval($idPec));
$pCFactures= $this->getDoctrine()->getRepository(PFactures::class)->findBy(array('chargeS'=>$idPec));
$pChargeSociale -> setSupprime(1)
->setUser($this->getUser()->getUsername())
-> setAction("supprimer");
$entityManager ->persist($pChargeSociale);
foreach ($pCFactures as $pCFacture) {
$pCFacture -> setSupprime(1);
$entityManager ->persist($pCFacture);
}
$entityManager->flush();
$this->addFlash('notice','Pris en charge a été supprimé avec succès');
return $this->redirectToRoute('home', array('etablissment'=> $etablissment,'statut'=> 'toute'));
}
/**
* @Route("{etablissment}/PecSociale/{action}", name="insertUpdate")
*/
public function insertUpdate($etablissment,Request $request, $action): Response
{
$entityManager = $this->getDoctrine()->getManager();
$montant =$request->request->get('_montant');
$mtPec =$request->request->get('_montantPec');
$TableBenef =json_decode($request->request->get('TableBenef'));
if($action=='new'){
// PChargeSociale
$pChargeS = $this->getDoctrine()->getRepository(PChargeSociale::class)->findOneBy([], array('id'=>'DESC'));
$numberPec='101001'+$pChargeS->getId();
$idChargeS = 'CHR_'.$numberPec;
$message ='Pris en charge a été ajouté avec succès';
$pChargeSociale = new PChargeSociale();
$operation = "ajouter";
}
else{
$pChargeSociale = $this->getDoctrine()->getRepository(PChargeSociale::class)->find(intval($action));
// PChargeSocialeLg
$id_sosiale_lg =$request->request->get('_id_sosiale_lg');
// PChargeSocialeBenef
$id_sosiale_benef =$request->request->get('_id_sosiale_benef');
$message ='Pris en charge a été modifié avec succès';
$operation = "modifier";
}
// *******************************
// ------ PChargeSociale --------
$etabl = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$nature_charge = $this->getDoctrine()->getRepository(PNatureCharge::class)->find(intval($request->request->get('_nature_charge')));
$dateCharge = new \DateTime($request->request->get('_date_charge'));
$reference_doc = $request->request->get('_reference_doc');
$date_doc = new \DateTime($request->request->get('_date_doc'));
$object = $request->request->get('_object');
$detail_motivation = $request->request->get('_detail_motivation');
$dNow = new \DateTime(date("Y/m/d"));
$nature_beneficiaire = $this->getDoctrine()->getRepository(PNatureBenef::class)->find(intval($request->request->get('_nature_beneficiaire')));
$site_tier = $this->getDoctrine()->getRepository(PEtablissment::class)->find(intval($etabl->getId()));
$motivation = $this->getDoctrine()->getRepository(Motivation::class)->find(intval($request->request->get('_motivation')));
$site_demandeur = $this->getDoctrine()->getRepository(PEtablissment::class)->find(intval($request->request->get('_site_demandeur')));
// *******************************
// ------ PChargeSocialeLg --------
$prestation =$request->request->get('_prestation');
$quantite =$request->request->get('_quantite');
$base =$request->request->get('_base');
$taux =$request->request->get('_taux');
// *******************************
// ------ PChargeSocialeBenef --------
// dd($benefeciair);
$niveau =$request->request->get('_niveau');
$annee =$request->request->get('_annee');
$cutisation =$request->request->get('_cutisation');
$id_dossier =$request->request->get('_id_dossier');
$id_inscription =$request->request->get('_id_inscription');
$id_preinscription =$request->request->get('_id_preinscription');
$id_formation =$request->request->get('_id_formation');
// ----------------------------------------------------------------
// dd(floatval($cutisation[2]) );
if($action=='new'){
$pChargeSociale -> setIdChargeS($idChargeS)
-> setStatut('encours') ;
}
$pChargeSociale -> setDateCharge($dateCharge)
-> setNatureCharge($nature_charge)
-> setRefDocAssocier($reference_doc)
-> setDateDocAssocier($date_doc)
-> setObjet($object)
-> setDateSys($dNow)
-> setSite($site_demandeur)
-> setNatureBenef($nature_beneficiaire)
-> setIdTier($site_tier)
-> setSupprime(0)
-> setMotivation($motivation)
-> setDetailMotivation($detail_motivation)
-> setUser($this->getUser()->getUsername())
-> setAction($operation);
if($request->request->get('_organisme')){
$organisme = $this->getDoctrine()->getRepository(POrganisme::class)->find(intval($request->request->get('_organisme')));
$pChargeSociale -> setOrganisme($organisme);
}
$entityManager->persist($pChargeSociale);
// ----------------------------------------------------------------
if(trim($prestation != '')){
for($i=0;$i<count($prestation);$i++){
if(($prestation[$i])){
if($action=='new'){
$pChargeSocialeLg = new PChargeSocialeLg();
$operation = "ajouter";
}
else{
if($id_sosiale_lg[$i]){
$pChargeSocialeLg = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->find(intval($id_sosiale_lg[$i]));
}
else{
$pChargeSocialeLg = new PChargeSocialeLg();
$operation = "ajouter";
}
}
$article=$this->getDoctrine()->getRepository(PArticles::class)->find(intval($prestation[$i]));
// dd($article);
$pChargeSocialeLg ->setChargeS($pChargeSociale)
->setArticle($article)
->setQuantite($quantite[$i])
->setBase($base[$i])
->setTaux($taux[$i])
->setMontantCharge(floatval($montant[$i]))
->setDateSys($dNow)
->setSupprime(0)
->setUser($this->getUser()->getUsername())
-> setAction($operation);
$entityManager->persist($pChargeSocialeLg);
}
}
}
// ----------------------------------------------------------------
if($TableBenef){
foreach ($TableBenef as $tBenef) {
if($action=='new'){
$pChargeSocialeBenef = new PChargeSocialeBenef();
$operation = "ajouter";
}
else{
if($tBenef->id_sosiale_benef){
$pChargeSocialeBenef = $this->getDoctrine()->getRepository(PChargeSocialeBenef::class)->find(intval($tBenef->id_sosiale_benef));
$operation = "modifier";
}
else{
$pChargeSocialeBenef = new PChargeSocialeBenef();
$operation = "ajouter";
}
}
if($tBenef->NFacture){
$numFacture = $this->getDoctrine() ->getRepository(PFactures::class)->findBy(array('refFacture'=>$tBenef->NFacture, 'supprime'=>0));
if($numFacture){
$error = "le numéro de facture '".$tBenef->NFacture."' déjà existe ";
return new JsonResponse(array('Boolean' => 'false', 'error' =>$error));
}
$pFactures = new PFactures();
$pFactures ->setChargeS($pChargeSociale)
->setDateFacture(new \DateTime($tBenef->dateFacture))
->setMontantFact(floatval($tBenef->montantFactuer))
->setDateSys($dNow)
->setRefFacture($tBenef->NFacture)
->setIdTier($site_tier->getEtablissment())
->setObservation($tBenef->observation)
->setSupprime(0);
$entityManager->persist($pFactures);
$pChargeSocialeBenef ->setFacture($pFactures);
}
if($tBenef->benef==0){
$pbenef = $this->getDoctrine()->getRepository(PBeneficiaires::class)->findOneBy([], array('id'=>'DESC'));
$numberBenef='101001'+$pbenef->getId();
$idBenefeciaire = 'BEF_'.$numberBenef;
$pBeneficiaires = new PBeneficiaires();
$pBeneficiaires -> setBeneficiaire($tBenef->NAME)
->setIdBeneficiaires($idBenefeciaire)
-> setDateSys($dNow);
$entityManager->persist($pBeneficiaires);
}else{
$pBeneficiaires=$this->getDoctrine()->getRepository(PBeneficiaires::class)->find(intval($tBenef->benef));
}
$pChargeSocialeBenef ->setChargeS($pChargeSociale)
->setBeneficiaire($pBeneficiaires)
->setNiveau($tBenef->NIVEAU)
->setAnneeUniv($tBenef->ANNEE)
->setCotisation(floatval($tBenef->CUTISATION))
->setDateSys($dNow)
->setIdDossier($tBenef->DOSSIER)
->setIdInscription($tBenef->INSCRIPTION)
->setIdPreinscription($tBenef->PREINSCRIPTION)
->setIdFormation($tBenef->FORMATION)
-> setSupprime(0)
-> setMontantPrest(floatval($tBenef->MTPEC))
-> setUser($this->getUser()->getUsername())
-> setAction($operation);
$entityManager->persist($pChargeSocialeBenef);
}
}else{
$error = " Veuillez remplir les informations sur le bénéficiaire ! ";
return new JsonResponse(array('Boolean' => 'false', 'error' =>$error));
}
$entityManager->flush();
// dd($TableBenef);
return new JsonResponse(array('Boolean' => 'true'));
}
/**
* @Route("/annulerPec/{id}", name="annulerPec")
*/
public function annulerPec(Request $request, $id)
{
if($request->isXmlHttpRequest()) {
$entityManager = $this->getDoctrine()->getManager();
$dNow = new \DateTime(date("Y/m/d"));
$pChargeSociale = $this->getDoctrine()->getRepository(PChargeSociale::class)->find(intval($id));
$montantCharge= $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSociale);
$article=$this->getDoctrine()->getRepository(PArticles::class)->find(60);
// dd($pChargeSociale) ;
$pChargeSocialeLg = new PChargeSocialeLg();
$pChargeSocialeLg ->setChargeS($pChargeSociale)
->setArticle($article)
->setQuantite(1)
->setBase($montantCharge*(-1))
->setTaux(100)
->setMontantCharge(floatval($montantCharge*(-1)))
->setDateSys($dNow)
->setSupprime(0)
->setUser($this->getUser()->getUsername())
-> setAction("annulation");
$entityManager->persist($pChargeSocialeLg);
$pChargeSociale-> setStatut('annuler');
$entityManager->persist($pChargeSociale);
$entityManager->flush();
return new JsonResponse('ok');
}
}
/**
* @Route("/pdf/{etablissment}/{id}", name="pdf")
*/
public function pdf($etablissment,$id) : response
{
$information = $this->getDoctrine() ->getRepository(PChargeSociale::class)->findOneBy(array('id'=>$id));
$details = $this->getDoctrine() ->getRepository(PChargeSocialeLg::class)->findBy(array('chargeS'=>$id, 'supprime'=>0));
$Benefeciaires = $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findBy(array('chargeS'=>$id, 'supprime'=>0));
$etabl = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$information->getSite()));
$MontantCharge = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($information);
$oneBenefeciaire= $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findOneBy(array('chargeS'=>$id));
$etablissmentt = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$ListeBenefeciaires = $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findByBenef($id);
// dd($Benefeciaires);
$donneeInsc=null;
if($oneBenefeciaire->getIdInscription()){
$em = $this->getDoctrine()->getManager()->getConnection();
$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
INNER JOIN v_promotion prom ON ins.promotion = prom.code_promotion
WHERE ins.code_inscription like"'.$oneBenefeciaire->getIdInscription().'" LIMIT 1');
$resultSet = $statement->executeQuery();
$data = $resultSet->fetchAll();
// dd($all_natureCharge) ;
if($data){
foreach($data as $dt){
$donneeInsc=$dt;
// dd($donneeInsc);
}
}
}
if($etablissment==31){
$typePdf="CENTRE_SOCIAL_DACTIVITEES_AU_PROFIT_PERSONNEL_ET_AYANTS_DROIT.html.twig";
}
else if($etablissment==8){
$typePdf="CENTRE_SOCIAL_MOBILE_DES_SOINS_MEDICAUX_RABAT.html.twig";
}
else if($etablissment==49){
$typePdf="DEPARTEMENT_SOCIAL_PEC_MEDICALE_FCZ_RABAT.html.twig";
}
else if($etablissment==62){
$typePdf="HOPITAUX_PUBLICS_PARTENAIRES_RABAT.html.twig";
}
else if($etablissment==68){
$typePdf="DEPARTEMENT_SOCIAL_DE_BOURSES_DEXCELLENCE_FCZ_RABAT.html.twig";
}
else if($etablissment==69){
$typePdf="LA_MAROCAINE_DES_ŒUVRES_SOCIALES_FCZ.html.twig";
}
$mpdf = new \Mpdf\Mpdf(['mode' => 'C','format' => 'A4','margin_header' => 5,'margin_footer' => 5,'margin_top' => 80,'margin_bottom' => 35]);
$html = $this->renderView('pdf/'.$typePdf, array(
'etablissment' => $etablissmentt,
'information' => $information,
'details' => $details,
'Benefeciaires' => $Benefeciaires,
'etabl' => $etabl,
'MontantCharge' => $MontantCharge,
'oneBenefeciaire' => $oneBenefeciaire,
'donneeInsc' => $donneeInsc,
'ListeBenefeciaires' => $ListeBenefeciaires
));
$mpdf->WriteHTML($html);
$mpdf->Output();
return 1;
}
/**
* @Route("/excel/{etablissment}/{statut}", name="ExporterExcel")
*/
public function ExporterExcel(PEtablissment $etablissment, $statut)
{
array_map('unlink', glob( "*.zip"));
$zip = new ZipArchive();
$zipname = 'ChargeSociales'.uniqid().'.zip';
$zip->open($zipname, ZipArchive::CREATE);
$spreadsheet = new Spreadsheet();
$condition=array( 'supprime'=>'0', 'idTier' => $etablissment->getId(),'statut'=>$statut );
if($statut =='toute'){
$condition= array( 'supprime'=>'0', 'idTier' => $etablissment->getId() );
}
$em = $this->getDoctrine()->getManager();
$pChargeSociales = $em->getRepository(PChargeSociale::class)->findBy($condition);
// dd($pChargeSociales);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'ID CHARGE');
$sheet->setCellValue('B1', 'DATE CHARGE');
$sheet->setCellValue('C1', 'ETABLISSEMENT DEMANDEUR');
$sheet->setCellValue('D1', 'NATURE CHARGE');
$sheet->setCellValue('E1', 'NATURE BENEFECIAIRE');
$sheet->setCellValue('F1', 'MOTIVATION');
$sheet->setCellValue('G1', 'DEDAIL MOTIVATION');
$sheet->setCellValue('H1', 'OBJET');
$sheet->setCellValue('I1', 'ORGANISME');
$sheet->setCellValue('J1', 'CHARGE');
$sheet->setCellValue('K1', 'FACTURE');
$sheet->setCellValue('L1', 'REGLEMENT');
$i=2;
foreach($pChargeSociales as $pChargeSociale){
$MontantCharge = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSociale);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSociale);
$MontantRegl = $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSociale);
$sheet->setCellValue('A'.$i, $pChargeSociale->getIdChargeS());
$sheet->setCellValue('B'.$i, date_format($pChargeSociale->getDateCharge(), "d/m/Y"));
$sheet->setCellValue('C'.$i, $pChargeSociale->getSite()->getEtablissment());
$sheet->setCellValue('D'.$i, $pChargeSociale->getNatureCharge()->getNatureCharge());
$sheet->setCellValue('E'.$i, $pChargeSociale->getNatureBenef()->getNatureBenef());
if($pChargeSociale->getMotivation()){
$sheet->setCellValue('F'.$i, $pChargeSociale->getMotivation()->getMotivation());
}else{
$sheet->setCellValue('F'.$i, " ");
}
$sheet->setCellValue('G'.$i, $pChargeSociale->getDetailMotivation());
$sheet->setCellValue('H'.$i, $pChargeSociale->getObjet());
if($pChargeSociale->getOrganisme()){
$sheet->setCellValue('I'.$i, $pChargeSociale->getOrganisme()->getOrganisme());
}else{
$sheet->setCellValue('I'.$i, " ");
}
$sheet->setCellValue('J'.$i, number_format($MontantCharge, 2, ',', ''));
$sheet->setCellValue('K'.$i, number_format($MontantFact, 2, ',', '') );
$sheet->setCellValue('L'.$i, number_format($MontantRegl, 2, ',', '') );
$i++;
}
foreach(range('A','Z') as $columnID)
{
$sheet->getColumnDimension($columnID)->setAutoSize(true);
}
/* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
$sheet->setTitle("PecSociale");
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = $etablissment->getEtablissment().'.xlsx';
// Create the excel file in the tmp directory of the system
$writer->save($fileName);
$zip->addFile($fileName);
// ________________________________________________________________
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'ID CHARGE');
$sheet->setCellValue('B1', 'BÉNÉFECIAIRE');
$sheet->setCellValue('C1', 'DOSSIER');
$sheet->setCellValue('D1', 'DEMANDEUR');
$sheet->setCellValue('E1', 'NATURE PEC');
$sheet->setCellValue('f1', 'DATE PEC');
$sheet->setCellValue('G1', 'REF FACTURE');
$sheet->setCellValue('H1', 'DATE FACTURE');
$sheet->setCellValue('I1', 'COTISATION');
$sheet->setCellValue('J1', 'MONTANT PREST');
$sheet->setCellValue('K1', 'NIVEAU');
$sheet->setCellValue('L1', 'ANNEE UNIV');
$i=2;
foreach($pChargeSociales as $pChargeSociale){
$ListeBenefeciaires = $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findByBenef($pChargeSociale->getId());
foreach($ListeBenefeciaires as $ListeBenefeciaire){
$sheet->setCellValue('A'.$i, $ListeBenefeciaire['idChargeS']);
$sheet->setCellValue('B'.$i, $ListeBenefeciaire['beneficiaire']);
$sheet->setCellValue('C'.$i, $ListeBenefeciaire['idDossier']);
$sheet->setCellValue('D'.$i, $ListeBenefeciaire['etablissment']);
$sheet->setCellValue('E'.$i, $ListeBenefeciaire['natureCharge']);
$sheet->setCellValue('F'.$i, $ListeBenefeciaire['dateCharge']);
$sheet->setCellValue('G'.$i, $ListeBenefeciaire['refFacture']);
if($ListeBenefeciaire['dateFacture']){
$sheet->setCellValue('H'.$i, date_format($ListeBenefeciaire['dateFacture'], "d/m/Y"));
}else{
$sheet->setCellValue('H'.$i, " ");
}
$sheet->setCellValue('I'.$i, $ListeBenefeciaire['cotisation']);
$sheet->setCellValue('J'.$i, $ListeBenefeciaire['montantPrest']);
$sheet->setCellValue('K'.$i, $ListeBenefeciaire['niveau']);
$sheet->setCellValue('L'.$i, $ListeBenefeciaire['anneeUniv']);
$i++;
}
}
foreach(range('A','Z') as $columnID)
{
$sheet->getColumnDimension($columnID)->setAutoSize(true);
}
/* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
$sheet->setTitle("Benefeciaire");
// Create your Office 2007 Excel (XLSX Format)
$writer = new Xlsx($spreadsheet);
// Create a Temporary file in the system
$fileName = 'benefeciaires.xlsx';
// Create the excel file in the tmp directory of the system
$writer->save($fileName);
$zip->addFile($fileName);
$zip->close();
// $temp_file = tempnam(sys_get_temp_dir(), $zipname);
array_map('unlink', glob( "*.xlsx"));
return new JsonResponse( $zipname);
}
/**
* @Route("/Pec/{etablissment}/{id}/dupliquer", name="dupliquerPec")
*/
public function dupliquerPec($etablissment,$id): Response
{
$pChargeSocia = $this->getDoctrine() ->getRepository(PChargeSociale::class)->findOneBy(array('id'=>$id));
$details = $this->getDoctrine() ->getRepository(PChargeSocialeLg::class)->findBy(array('chargeS'=>$id, 'supprime'=>0));
$Benefeciaires = $this->getDoctrine() ->getRepository(PChargeSocialeBenef::class)->findBy(array('chargeS'=>$id, 'supprime'=>0));
$etabl = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$pChargeSocia->getSite()));
$MontantCharge = $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
$MontantRegl = $this->getDoctrine()->getRepository(PReglements::class)->getTotalReglement($pChargeSocia);
$etablissmentt = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$organ;
$montantCharge= $this->getDoctrine()->getRepository(PChargeSocialeLg::class)->getTotalSocialC($pChargeSocia);
$MontantFact = $this->getDoctrine()->getRepository(PFactures::class)->getTotalFacture($pChargeSocia);
$all_etablissment = $this->getDoctrine() ->getRepository(PEtablissment::class)->findAll();
$all_naturecharge = $this->getDoctrine() ->getRepository(PEtablissment::class)->findOneBy(array('id'=>$etablissment));
$all_natureBenef = $this->getDoctrine() ->getRepository(PNatureBenef::class)->findAll();
$all_benefeciaire = $this->getDoctrine() ->getRepository(PBeneficiaires::class)->findAll();
$all_prestation = $this->getDoctrine() ->getRepository(PNatureCharge::class)->find($pChargeSocia->getNatureCharge()->getId());
$motivations = $this->getDoctrine() ->getRepository(Motivation::class)->findAll();
$organismes = $this->getDoctrine() ->getRepository(POrganisme::class)->findAll();
return $this->render('modal/DupliquerPec.html.twig',
[ 'etablissment' => $etablissmentt,
'pChargeSocia' => $pChargeSocia,
'details' => $details,
'Benefeciaires' => $Benefeciaires,
'etabl' => $etabl,
'pChargeSocia' => $pChargeSocia,
'all_etablissment' =>$all_etablissment,
'all_naturecharge' =>$all_naturecharge,
'all_natureBenef' =>$all_natureBenef,
'all_benefeciaire' =>$all_benefeciaire,
'all_prestation' =>$all_prestation,
'motivations' =>$motivations,
'organismes' =>$organismes
]);
}
}