<?php
namespace App\Controller\Reporting;
use Mpdf\Mpdf;
use App\Entity\Cab;
use App\Entity\Lrib;
use App\Entity\Type;
use App\Entity\PPiece;
use App\Entity\Periode;
use App\Entity\PDossier;
use App\Entity\TCnssA00;
use App\Entity\TCnssB00;
use App\Entity\LContract;
use App\Entity\Prubrique;
use App\Entity\PtypeCoti;
use App\Entity\Tbulletin;
use App\Entity\PBaremeCimr;
use App\Entity\TbulletinLg;
use App\Entity\UsOperation;
use App\Entity\PPrelevement;
use App\Entity\PArretTravailLg;
use App\Entity\PnatureContract;
use App\Controller\ApiController;
use App\Entity\LmatriculationCoti;
use App\Service\CalculPaieService;
use Doctrine\Persistence\ManagerRegistry;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
#[Route('/reporting/extraction')]
class ExtractionController extends AbstractController
{
private $em;
private $calculPaieService;
private $api;
public function __construct(ManagerRegistry $doctrine, CalculPaieService $calculPaieService, ApiController $api)
{
$this->em = $doctrine->getManager();
$this->api = $api;
$this->calculPaieService = $calculPaieService;
}
#[Route('/', name: 'app_reporting_extraction', options: ['expose' => true])]
public function index(Request $request): Response
{
$operations = $this->api->check($this->getUser(), 'app_reporting_extraction', $this->em, $request);
if (!is_array($operations)) {
return $this->redirectToRoute('app_site');
} elseif (count($operations) == 0) {
return $this->render('includes/404.html.twig');
}
$groupements=$this->em->createQueryBuilder()
->select('DISTINCT dossier.groupement')
->from(PDossier::class, 'dossier')
->Where('dossier.active = 1')
->getQuery()
->getResult();
$dossiers = $this->em->getRepository(PDossier::class)->findBy(['active' => true]);
$natures = $this->em->getRepository(PnatureContract::class)->findAll();
$prets = $this->em->getRepository(Prubrique::class)->findBy(['active' => true, 'prets' => 1]);
return $this->render('reporting/extraction/index.html.twig', [
'controller_name' => 'ExtractionController',
'groupements'=>$groupements,
'dossiers' => $dossiers,
'natures' => $natures,
'prets' => $prets
]);
}
#[Route('/app_reporting_extraction_list', name: 'app_reporting_extraction_list', options: ['expose' => true])]
public function app_reporting_extraction_list(Request $request): Response
{
$draw = $request->query->get('draw');
$start = $request->query->get('start') ?? 0;
$length = $request->query->get('length') ?? 10;
$search = $request->query->all('search')["value"];
$orderColumnIndex = $request->query->all('order')[0]['column'];
$orderColumn = $request->query->all("columns")[$orderColumnIndex]['name'];
$orderDir = $request->query->all('order')[0]['dir'] ?? 'asc';
$queryBuilder = $this->em->createQueryBuilder()
->select('o.icon, o.designation, o.idTag')
->from(UsOperation::class, 'o')
->innerJoin('o.sousModule', 'm')
->Where('o.align = :align')
->andWhere('m.id = 16')
->andWhere('o.active = 1')
->setParameter('align', '1');
if (!empty($search)) {
$queryBuilder->andWhere('(o.designation LIKE :search OR o.icon LIKE :search OR o.idTag LIKE :search)')
->setParameter('search', "%$search%");
}
if (!empty($orderColumn)) {
$queryBuilder->orderBy("$orderColumn", $orderDir);
}
$filteredRecords = count($queryBuilder->getQuery()->getResult());
// Paginate results
$queryBuilder->setFirstResult($start)
->setMaxResults($length);
$results = $queryBuilder->getQuery()->getResult();
// dd($results);
$data = [];
foreach ($results as $key => $operation) {
$array = [];
$array[] = $operation['icon'];
$array[] = '<a href="#" id="' . $operation['idTag'] . '">' . $operation['designation'] . '</a>';
$data[] = $array;
}
// dd($results);
$totalRecords = $this->em->createQueryBuilder()
->select('COUNT(d.id)')
->from(UsOperation::class, 'd')
->innerJoin('d.sousModule', 'm')
->Where('d.align = :align')
->andWhere('m.id = 16')
->setParameter('align', '1')
->getQuery()
->getSingleScalarResult();
return new JsonResponse([
'draw' => $draw,
'recordsTotal' => $totalRecords,
'recordsFiltered' => $filteredRecords,
'data' => $data,
]);
}
#[Route('/app_reporting_extraction_employe_active', name: 'app_reporting_extraction_employe_active', options: ['expose' => true])]
public function app_reporting_extraction_employe_active(Request $request): Response
{
$queryBuilder = $this->em->createQueryBuilder()
->select('affectationDossier.groupement, affectationDossier.id as id_dossier, fcy.id as fcy_id, fcy.fcy0, fcy.fcy0Libelle,affectationDossier.das,affectationDossier.abreviation, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom, employe.cin, employe.sexe, employe.adresse1,
date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, dureeContract.Designation as duree_contrat, bareme.id as id_bareme, bareme.bareme as bareme_number, bareme.Profil, baremeType.designation as bareme_type, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete, f.Designation as fonction,lribs.code as rib, lribs.swift, lribs.banque, contract.cnss as cnss, contract.cimr as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\' ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation
')
->from(PDossier::class, 'dossier')
->innerJoin('dossier.contracts', 'contract')
->innerJoin('contract.ldossierContracts', 'ldossierContract')
->innerJoin('contract.employe', 'employe')
->innerJoin('contract.pnatureContract', 'pnatureContract')
->innerJoin('contract.bareme', 'bareme')
->innerJoin('bareme.baremeType', 'baremeType')
->innerJoin('pnatureContract.type', 'type')
->innerJoin('ldossierContract.dossier_id', 'affectationDossier')
->leftJoin('contract.fonction', 'f')
->leftJoin('contract.dureeContract', 'dureeContract')
->leftJoin('affectationDossier.fcy', 'fcy')
// ->leftJoin('employe.diplomes', 'diplomes')
->leftJoin('contract.lribs', 'lribs', 'WITH', 'lribs.active = 1')
->Where('contract.active = 1')
->orderBy('dossier.id', 'desc')
->getQuery()
->getResult();
return new JsonResponse($queryBuilder);
}
#[Route('/app_reporting_extraction_employe_entrant/{periode}', name: 'app_reporting_extraction_employe_entrant', options: ['expose' => true])]
public function app_reporting_extraction_employe_entrant($periode): Response
{
$dateDebut = new \DateTime($periode);
$dateFin = new \DateTime($periode);
$dateDebut->modify('first day of this month');
$dateFin->modify('last day of this month');
$queryBuilder = $this->em->createQueryBuilder()
->select('affectationDossier.groupement, affectationDossier.id as id_dossier, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom,employe.sexe, employe.cin, employe.adresse1,
date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, bareme.id as id_bareme, bareme.bareme as bareme_number, bareme.Profil, baremeType.designation as bareme_type, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete,lribs.code as rib, contract.cnss as cnss, contract.cimr as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\' ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation ')
->from(PDossier::class, 'dossier')
->innerJoin('dossier.contracts', 'contract')
->innerJoin('contract.ldossierContracts', 'ldossierContract')
->innerJoin('contract.employe', 'employe')
->innerJoin('contract.pnatureContract', 'pnatureContract')
->innerJoin('contract.bareme', 'bareme')
->innerJoin('bareme.baremeType', 'baremeType')
->innerJoin('pnatureContract.type', 'type')
->innerJoin('ldossierContract.dossier_id', 'affectationDossier')
->leftJoin('contract.lribs', 'lribs', 'WITH', 'lribs.active = 1')
// ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCnss', 'WITH', 'lmatriculationCotisCnss.type_id = 1')
// ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCimr', 'WITH', 'lmatriculationCotisCimr.type_id = 2')
// ->leftJoin('ldossierContract.dossier_id', 'affectationDossier')
->Where('contract.date_debut >= :date_debut')
->andWhere('contract.date_debut <= :date_fin')
// ->andWhere('dossier.id = 20')
->setParameter('date_debut', $dateDebut)
->setParameter('date_fin', $dateFin)
->orderBy('dossier.id', 'desc')
->getQuery()
->getResult();
return new JsonResponse($queryBuilder);
}
#[Route('/app_reporting_extraction_employe_sortant/{periode}', name: 'app_reporting_extraction_employe_sortant', options: ['expose' => true])]
public function app_reporting_extraction_employe_sortant($periode): Response
{
$dateDebut = new \DateTime($periode);
$dateFin = new \DateTime($periode);
$dateDebut->modify('first day of this month');
$dateFin->modify('last day of this month');
$queryBuilder = $this->em->createQueryBuilder()
->select('affectationDossier.groupement, affectationDossier.id as id_dossier, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom,employe.sexe, employe.cin, employe.adresse1,
date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, bareme.id as id_bareme, bareme.bareme as bareme_number, bareme.Profil, baremeType.designation as bareme_type, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete,lribs.code as rib, contract.cnss as cnss, contract.cimr as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\' ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation, date_format(contract.date_sortie, \'%d/%m/%Y\') as date_sortie, contract.motif_sortie ')
->from(PDossier::class, 'dossier')
->innerJoin('dossier.contracts', 'contract')
->innerJoin('contract.ldossierContracts', 'ldossierContract')
->innerJoin('contract.employe', 'employe')
->innerJoin('contract.pnatureContract', 'pnatureContract')
->innerJoin('contract.bareme', 'bareme')
->innerJoin('bareme.baremeType', 'baremeType')
->innerJoin('pnatureContract.type', 'type')
->innerJoin('ldossierContract.dossier_id', 'affectationDossier')
->leftJoin('contract.lribs', 'lribs', 'WITH', 'lribs.active = 1')
// ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCnss', 'WITH', 'lmatriculationCotisCnss.type_id = 1')
// ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCimr', 'WITH', 'lmatriculationCotisCimr.type_id = 2')
// ->leftJoin('ldossierContract.dossier_id', 'affectationDossier')
->Where('contract.date_sortie >= :date_debut')
->andWhere('contract.date_sortie <= :date_fin')
// ->andWhere('dossier.id = 20')
->setParameter('date_debut', $dateDebut)
->setParameter('date_fin', $dateFin)
->orderBy('dossier.id', 'desc')
->getQuery()
->getResult();
return new JsonResponse($queryBuilder);
}
#[Route('/app_reporting_extraction_bulletin_paie/{periode}', name: 'app_reporting_extraction_bulletin_paie', options: ['expose' => true])]
public function app_reporting_extraction_bulletin_paie(Request $request, $periode): Response
{
$date = new \DateTime($periode);
$periode = $this->calculPaieService->getPeriode($date->format('mY'));
// $queryBuilder = $this->em->createQueryBuilder()
// ->select('affectationDossier.id as id_dossier, affectationDossier.designation as dossier_designation,employe.id as id_employe, contract.id as id_contrat, employe.nom, employe.prenom, employe.cin, employe.adresse1,
// date_format(employe.date_naissance, \'%d/%m/%Y\') as date_naissance, pnatureContract.id as id_nature_contrat, pnatureContract.designation as nature_contrat,type.designation as type_nature_contrat, contract.priseEnCharge as pers_en_charge, employe.nombre_enfants as nbr_enfants,employe.tel1,
// date_format(contract.date_debut, \'%d/%m/%Y\') as date_debut, date_format(contract.date_fin, \'%d/%m/%Y\') as date_fin, date_format(contract.dateAnciennete, \'%d/%m/%Y\') as date_anciennete,lribs.code as rib, lmatriculationCotisCnss.code as cnss, lmatriculationCotisCimr.code as cimr, CASE WHEN ldossierContract.active = 1 THEN \'affectation actuelle\' ELSE \'ancien site\' END as affectation_statut, date_format(ldossierContract.created, \'%d/%m/%Y\') as debut_affectation ')
// ->from(PDossier::class, 'dossier')
// ->innerJoin('dossier.contracts', 'contract')
// ->innerJoin('contract.ldossierContracts', 'ldossierContract')
// ->innerJoin('contract.employe', 'employe')
// ->innerJoin('contract.pnatureContract', 'pnatureContract')
// ->innerJoin('pnatureContract.type', 'type')
// ->innerJoin('ldossierContract.dossier_id', 'affectationDossier')
// ->leftJoin('contract.lribs', 'lribs', 'WITH', 'lribs.active = 1')
// ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCnss', 'WITH', 'lmatriculationCotisCnss.type_id = 1')
// ->leftJoin('contract.lmatriculationCotis', 'lmatriculationCotisCimr', 'WITH', 'lmatriculationCotisCimr.type_id = 2')
// // ->leftJoin('ldossierContract.dossier_id', 'affectationDossier')
// ->Where('contract.active = 1')
// // ->andWhere('dossier.id = 20')
// ->orderBy('dossier.id', 'desc')
// ->getQuery()
// ->getResult()
// ;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Id Dossier');
$sheet->setCellValue('B1', 'Dossier');
$sheet->setCellValue('C1', 'Id Contrat');
$sheet->setCellValue('D1', 'Nom');
$sheet->setCellValue('E1', 'Prenom');
$sheet->setCellValue('F1', 'Cin');
$sheet->setCellValue('G1', 'Rib');
$sheet->setCellValue('H1', 'Bulletin');
$sheet->setCellValue('I1', 'nbrjours');
$sheet->setCellValue('J1', 'netpaye');
$sheet->setCellValue('K1', 'type');
$sheet->setCellValue('L1', 'type bareme');
$bulletins = $this->em->getRepository(Tbulletin::class)->findBy(['active' => true, 'periode' => $periode]);
$i = 2;
foreach ($bulletins as $key => $bulletin) {
$contract = $bulletin->getContract();
$sheet->setCellValue('A' . $i, $contract ? $contract->getDossier()->getId() : '');
$sheet->setCellValue('B' . $i, $contract ? $contract->getDossier()->getAbreviation() : '');
$sheet->setCellValue('C' . $i, $contract ? $contract->getId() : '');
$sheet->setCellValue('D' . $i, $contract ? $contract->getEmploye()->getNom() : '');
$sheet->setCellValue('E' . $i, $contract ? $contract->getEmploye()->getPrenom() : '');
$sheet->setCellValue('F' . $i, $contract ? $contract->getEmploye()->getCin() : '');
if ($contract) {
$rib = $this->em->getRepository(Lrib::class)->findOneBy(['contact_id' => $contract, 'active' => true]);
$nbr = 26 - $this->em->getRepository(PArretTravailLg::class)->getNombreJoursArret($contract->getId(), $periode);
$sheet->setCellValue('G' . $i, $rib ? $rib->getCode() : '');
} else {
$rib = '-';
$sheet->setCellValue('G' . $i, '');
$nbr = '-';
}
$sheet->setCellValue('H' . $i, $bulletin->getCode());
$sheet->setCellValue('I' . $i, $nbr);
$sheet->setCellValue('J' . $i, $this->em->getRepository(Tbulletin::class)->getNetAPaye($bulletin->getId()));
$sheet->setCellValue('K' . $i, $bulletin->getPPiece()->getDesignation());
$sheet->setCellValue('L' . $i, $contract ? $contract->getBareme()->getBaremeType()->getDesignation() : '');
$i++;
}
$writer = new Xlsx($spreadsheet);
$fileName = 'bulletin_paies_' . $periode->getCode() . '.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
$writer->save($temp_file);
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
#[Route('/app_reporting_extraction_charge_social/{periode}', name: 'app_reporting_extraction_charge_social', options: ['expose' => true])]
public function app_reporting_extraction_charge_social(Request $request, $periode): Response
{
$connection = $this->em->getConnection();
$date = new \DateTime($periode);
$periode = $this->calculPaieService->getPeriode($date->format('mY'));
$periode = $periode->getId();
// $request = "SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
// pemploye.cin,tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.sens,
// pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
// FROM tbulletin_lg
// INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
// INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
// INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
// INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
// INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
// INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
// INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
// INNER JOIN pemploye on pemploye.id = lcontract.employe_id
// INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
// INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
// INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
// where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43)";
// $stmt = $connection->prepare($request);
// $newstmt = $stmt->executeQuery();
// $result = $newstmt->fetchAll();
// $bulletinValues = array_map(function ($item) {
// return $item['bulletin_id'];
// }, $result);
// $bulletinValues = array_unique($bulletinValues);
// $bulletinValues = implode(', ', $bulletinValues);
// // dd($bulletinValues);
// $requestSecond = "SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
// pemploye.cin, tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, 'rémunération brute imposable' as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
// pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
// FROM tbulletin_lg
// INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
// INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
// INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
// INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
// INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
// INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
// INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
// INNER JOIN pemploye on pemploye.id = lcontract.employe_id
// INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
// INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
// INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
// where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.imposable = 1 and tbulletin.id in ($bulletinValues)
// group by tbulletin.code
// UNION
// SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
// pemploye.cin,tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, 'rémunération brute' as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
// pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
// FROM tbulletin_lg
// INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
// INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
// INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
// INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
// INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
// INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
// INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
// INNER JOIN pemploye on pemploye.id = lcontract.employe_id
// INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
// INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
// INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
// where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and (prubrique.id in (1, 4, 6, 7,8,9) or prubrique.fixe = 1) and tbulletin.id in ($bulletinValues)
// group by tbulletin.code
// UNION
// SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
// pemploye.cin,tbulletin.id as bulletin_id, tbulletin.code as bulletin, ppiece.designation as type_bulletin, prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.sens as sens,
// pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pstatut.designation as statut
// FROM tbulletin_lg
// INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
// INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
// INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
// INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
// INNER JOIN pnature_contract on pnature_contract.id = lcontract.pnature_contract_id
// INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
// INNER JOIN pdossier on pdossier.id = lcontract.dossier_id
// INNER JOIN pemploye on pemploye.id = lcontract.employe_id
// INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
// INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
// INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
// where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and (prubrique.prets = 1 or prubrique.id in (5, 65)) and tbulletin.id in ($bulletinValues)
// group by tbulletin.code
// "
// ;
$request = "SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pemploye.cin, tbulletin.code as bulletin, ppiece.designation as type_bulletin,prubrique.code as 'element_code', prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.sens,
pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43, 5, 68)
UNION
SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pemploye.cin, tbulletin.code as bulletin, ppiece.designation as type_bulletin, null as 'element_code', 'rémunération brute imposable' as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.imposable = 1
group by tbulletin.code
UNION
SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pemploye.cin, tbulletin.code as bulletin, ppiece.designation as type_bulletin,
CASE WHEN prubrique.honoraire = 1 THEN prubrique.designation WHEN prubrique.indeminite = 1 THEN prubrique.code ELSE null END as element_code,
CASE WHEN prubrique.honoraire = 1 THEN prubrique.designation WHEN prubrique.indeminite = 1 THEN prubrique.designation ELSE 'rémunération brute' END as element, sum(tbulletin_lg.montant) as montant, '1' as sens,
pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1
and (
((prubrique.id in (1,2, 4, 6, 7,8,9) or prubrique.fixe = 1 ) and pbordereau.type = 'paie') or
(prubrique.honoraire = 1 and pbordereau.type = 'honoraire') or
prubrique.indeminite = 1
)
group by tbulletin.code
UNION
SELECT pdossier.id as id_dossier, pdossier.abreviation, pdossier.groupement, pdossier.designation as dossier, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pemploye.cin,tbulletin.code as bulletin, ppiece.designation as type_bulletin,prubrique.code as element_code, prubrique.designation as element, sum(tbulletin_lg.montant) as montant, tbulletin_lg.sens as sens,
pnature_contract.designation as nature_contrat, pbareme_type.designation as type_bareme, pbordereau.code as bordereau, pbordereau.observation, pstatut.designation as statut
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = tbulletin.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN pstatut on pstatut.id = pbordereau.statut_id
where tbulletin.periode_id = $periode and pbordereau.active = 1 and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.prets = 1
group by tbulletin.code, prubrique.designation;
";
$stmt = $connection->prepare($request);
$newstmt = $stmt->executeQuery();
$resultSecond = $newstmt->fetchAll();
// dd($resultSecond[0]);
// $result = array_merge($resultSecond, $result);
return new JsonResponse($resultSecond);
// $spreadsheet = new Spreadsheet();
// $sheet = $spreadsheet->getActiveSheet();
// $sheet->setCellValue('A1', 'Id Dossier');
// $sheet->setCellValue('B1', 'Dossier');
// $sheet->setCellValue('C1', 'Id Contrat');
// $sheet->setCellValue('D1', 'Nom');
// $sheet->setCellValue('E1', 'Prenom');
// $sheet->setCellValue('F1', 'Cin');
// $sheet->setCellValue('G1', 'Bulletin');
// $sheet->setCellValue('H1', 'Element');
// $sheet->setCellValue('I1', 'Montant');
// $sheet->setCellValue('J1', 'Sens');
// $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
// $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
// $bulletins = $this->em->getRepository(Tbulletin::class)->findBy(['active' => true, 'periode'=> $periode, 'piece' => $this->em->getRepository(PPiece::class)->find(1)]);
// $bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletins, 'rubrique' => $rubriques, 'active' => true]);
// // dd($bulletinLgs);
// $i = 2;
// foreach ($bulletinLgs as $key => $bulletinLg) {
// $bulletin = $bulletinLg->getBulletin();
// $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
// $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
// $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
// $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
// $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
// $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
// $sheet->setCellValue('G'.$i, $bulletin->getCode());
// $sheet->setCellValue('H'.$i, $bulletinLg->getRubrique()->getDesignation());
// $sheet->setCellValue('I'.$i, $bulletinLg->getMontant());
// $sheet->setCellValue('J'.$i, $bulletinLg->getSens());
// $i++;
// }
// $writer = new Xlsx($spreadsheet);
// $fileName = 'charge_sociale_'.$periode->getCode().'.xlsx';
// $temp_file = tempnam(sys_get_temp_dir(), $fileName);
// $writer->save($temp_file);
// return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
#[Route('/app_reporting_extraction_masse_salariale/{periode}', name: 'app_reporting_extraction_masse_salariale', options: ['expose' => true])]
public function app_reporting_extraction_masse_salariale(Request $request, $periode): Response
{
$connection = $this->em->getConnection();
$date = new \DateTime($periode);
$periode = $this->calculPaieService->getPeriode($date->format('mY'));
$periode = $periode->getId();
$request = "SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pnature_contract.designation as nature_contrat, pemploye.cin, tbulletin.code as bulletin,prubrique.designation as element, tbulletin_lg.montant, tbulletin_lg.montant_devise, tbulletin_lg.sens,
ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
where tbulletin.periode_id = $periode and tbulletin.active = 1 and tbulletin_lg.active = 1 and pbordereau.active = 1
UNION
SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle, pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pnature_contract.designation as nature_contrat, pemploye.cin, tbulletin.code as bulletin, 'rémunération brute imposable' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
where tbulletin.periode_id = $periode and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.imposable = 1 and pbordereau.active = 1
group by tbulletin.code
UNION
SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pnature_contract.designation as nature_contrat,pemploye.cin, tbulletin.code as bulletin, 'rémunération brute' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
where tbulletin.periode_id = $periode and tbulletin.active = 1 and tbulletin_lg.active = 1 and (prubrique.id in (1, 4, 6, 7,8,9) or prubrique.fixe = 1) and pbordereau.active = 1
group by tbulletin.code
UNION
SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pnature_contract.designation as nature_contrat,pemploye.cin, tbulletin.code as bulletin, 'cotisation PS' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
where tbulletin.periode_id = $periode and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (50, 47, 53, 48) and pbordereau.active = 1
group by tbulletin.code
UNION
SELECT pdossier.id as id_dossier, pdossier.designation as dossier, pfcy.id as id_fcy, pfcy.fcy0, pfcy.fcy0_libelle,pemploye.id as employe_id, lcontract.id as id_contract, pemploye.nom, pemploye.prenom,
pnature_contract.designation as nature_contrat,pemploye.cin, tbulletin.code as bulletin, 'cotisation PP' as element, sum(tbulletin_lg.montant) as montant, sum(tbulletin_lg.montant_devise) as montant_devise, '1' as sens,
ppiece.designation as type, pbareme_type.designation as type_bareme, pfonction.designation as fonction, lcontract.date_anciennete , tbulletin_lg.id,pbordereau.id as id_bordereau, pbordereau.code as bordereau, pbordereau.observation as bordereau_observation,ppaiement.designation as paiement, pbordereau.date_integration
FROM tbulletin_lg
INNER JOIN tbulletin on tbulletin.id = tbulletin_lg.bulletin_id
INNER JOIN ppiece on ppiece.id = tbulletin.piece_id
INNER JOIN lcontract on lcontract.id = tbulletin.contract_id
INNER JOIN pbordereau on pbordereau.id = tbulletin.bordereau_id
INNER JOIN pbareme on lcontract.bareme_id = pbareme.id
INNER JOIN pbareme_type on pbareme.bareme_type_id = pbareme_type.id
INNER JOIN pdossier on pdossier.id = pbordereau.dossier_id
INNER JOIN pemploye on pemploye.id = lcontract.employe_id
INNER JOIN prubrique on prubrique.id = tbulletin_lg.rubrique_id
INNER JOIN ppaiement on ppaiement.id = pbordereau.paiement_id
LEFT JOIN pfonction on pfonction.id = lcontract.fonction_id
LEFT JOIN pnature_contract on pnature_contract.id = pbordereau.nature_contract_id
LEFT JOIN pfcy on pfcy.id = pdossier.fcy_id
where tbulletin.periode_id = $periode and tbulletin.active = 1 and tbulletin_lg.active = 1 and prubrique.id in (51, 52, 54, 55, 56, 58, 57) and pbordereau.active = 1
group by tbulletin.code
";
$stmt = $connection->prepare($request);
$newstmt = $stmt->executeQuery();
$result = $newstmt->fetchAll();
return new JsonResponse($result);
// $spreadsheet = new Spreadsheet();
// $sheet = $spreadsheet->getActiveSheet();
// $sheet->setCellValue('A1', 'Id Dossier');
// $sheet->setCellValue('B1', 'Dossier');
// $sheet->setCellValue('C1', 'Id Contrat');
// $sheet->setCellValue('D1', 'Nom');
// $sheet->setCellValue('E1', 'Prenom');
// $sheet->setCellValue('F1', 'Cin');
// $sheet->setCellValue('G1', 'Bulletin');
// $sheet->setCellValue('H1', 'Element');
// $sheet->setCellValue('I1', 'Montant');
// $sheet->setCellValue('J1', 'Sens');
// $sheet->setCellValue('K1', 'type');
// $sheet->setCellValue('L1', 'type bareme');
// $bulletins = $this->em->getRepository(Tbulletin::class)->findBy(['active' => true, 'periode'=> $periode]);
// // dd($bulletinLgs);
// $i = 2;
// foreach ($bulletins as $key => $bulletin) {
// $montantBruteImposable = $this->em->createQueryBuilder()
// ->select('sum(TbulletinLg.montant) as montant')
// ->from(TbulletinLg::class, 'TbulletinLg')
// ->innerJoin('TbulletinLg.bulletin', 'bulletin')
// ->innerJoin('TbulletinLg.rubrique', 'rubrique')
// ->andWhere('rubrique.imposable = 1')
// ->andWhere('TbulletinLg.active = 1')
// ->andWhere('bulletin.id = :bulletin')
// ->setParameter('bulletin', $bulletin)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// $montantBrute = $this->em->createQueryBuilder()
// ->select('sum(TbulletinLg.montant) as montant')
// ->from(TbulletinLg::class, 'TbulletinLg')
// ->innerJoin('TbulletinLg.bulletin', 'bulletin')
// ->innerJoin('TbulletinLg.rubrique', 'rubrique')
// ->andWhere('rubrique.id in (1, 4, 6, 7,8,9) or rubrique.fixe = 1')
// ->andWhere('TbulletinLg.active = 1')
// ->andWhere('bulletin.id = :bulletin')
// ->setParameter('bulletin', $bulletin)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// $cotisationsPS = [50, 47, 53, 48];
// $cotisationsPP = [51, 52, 54, 55, 56, 58, 57];
// $montantCotisationcotisationsPS = $this->em->createQueryBuilder()
// ->select('sum(TbulletinLg.montant) as montant')
// ->from(TbulletinLg::class, 'TbulletinLg')
// ->innerJoin('TbulletinLg.bulletin', 'bulletin')
// ->innerJoin('TbulletinLg.rubrique', 'rubrique')
// ->andWhere('rubrique.id in (:cotisations)')
// ->andWhere('TbulletinLg.active = 1')
// ->andWhere('bulletin.id = :bulletin')
// ->setParameter('bulletin', $bulletin)
// ->setParameter('cotisations', $cotisationsPS)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// $montantCotisationcotisationsPP = $this->em->createQueryBuilder()
// ->select('sum(TbulletinLg.montant) as montant')
// ->from(TbulletinLg::class, 'TbulletinLg')
// ->innerJoin('TbulletinLg.bulletin', 'bulletin')
// ->innerJoin('TbulletinLg.rubrique', 'rubrique')
// ->andWhere('rubrique.id in (:cotisations)')
// ->andWhere('TbulletinLg.active = 1')
// ->andWhere('bulletin.id = :bulletin')
// ->setParameter('bulletin', $bulletin)
// ->setParameter('cotisations', $cotisationsPP)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// $bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin, 'active' => true]);
// foreach ($bulletinLgs as $key => $bulletinLg) {
// $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
// $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
// $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
// $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
// $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
// $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
// $sheet->setCellValue('G'.$i, $bulletin->getCode());
// $sheet->setCellValue('H'.$i, $bulletinLg->getRubrique()->getDesignation());
// $sheet->setCellValue('I'.$i, $bulletinLg->getMontant());
// $sheet->setCellValue('J'.$i, $bulletinLg->getSens());
// $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
// $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
// $i++;
// }
// if($montantCotisationcotisationsPS) {
// $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
// $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
// $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
// $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
// $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
// $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
// $sheet->setCellValue('G'.$i, $bulletin->getCode());
// $sheet->setCellValue('H'.$i, 'Cotisation PS');
// $sheet->setCellValue('I'.$i, $montantCotisationcotisationsPS['montant']);
// $sheet->setCellValue('J'.$i, '-1');
// $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
// $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
// $i++;
// }
// if($montantCotisationcotisationsPP) {
// $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
// $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
// $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
// $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
// $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
// $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
// $sheet->setCellValue('G'.$i, $bulletin->getCode());
// $sheet->setCellValue('H'.$i, 'Cotisation PP');
// $sheet->setCellValue('I'.$i, $montantCotisationcotisationsPP['montant']);
// $sheet->setCellValue('J'.$i, '-1');
// $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
// $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
// $i++;
// }
// if($montantBrute) {
// $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
// $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
// $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
// $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
// $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
// $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
// $sheet->setCellValue('G'.$i, $bulletin->getCode());
// $sheet->setCellValue('H'.$i, 'rémunération brute');
// $sheet->setCellValue('I'.$i, $montantBrute['montant']);
// $sheet->setCellValue('J'.$i, '1');
// $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
// $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
// $i++;
// }
// if($montantBruteImposable) {
// $sheet->setCellValue('A'.$i, $bulletin->getContract()->getDossier()->getId());
// $sheet->setCellValue('B'.$i, $bulletin->getContract()->getDossier()->getAbreviation());
// $sheet->setCellValue('C'.$i, $bulletin->getContract()->getId());
// $sheet->setCellValue('D'.$i, $bulletin->getContract()->getEmploye()->getNom());
// $sheet->setCellValue('E'.$i, $bulletin->getContract()->getEmploye()->getPrenom());
// $sheet->setCellValue('F'.$i, $bulletin->getContract()->getEmploye()->getCin());
// $sheet->setCellValue('G'.$i, $bulletin->getCode());
// $sheet->setCellValue('H'.$i, 'rémunération brute imposable');
// $sheet->setCellValue('I'.$i, $montantBruteImposable['montant']);
// $sheet->setCellValue('J'.$i, '1');
// $sheet->setCellValue('K'.$i, $bulletin->getPPiece()->getDesignation());
// $sheet->setCellValue('L'.$i, $bulletin->getContract()->getBareme()->getBaremeType()->getDesignation());
// $i++;
// }
// }
// $writer = new Xlsx($spreadsheet);
// $fileName = 'masse_salariale_'.$periode->getCode().'.xlsx';
// $temp_file = tempnam(sys_get_temp_dir(), $fileName);
// $writer->save($temp_file);
// return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
#[Route('/app_reporting_extraction_prelevement', name: 'app_reporting_extraction_prelevement', options: ['expose' => true])]
public function app_reporting_extraction_prelevement(Request $request): Response
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Id Dossier');
$sheet->setCellValue('B1', 'Dossier');
$sheet->setCellValue('C1', 'Id Contrat');
$sheet->setCellValue('D1', 'Nom');
$sheet->setCellValue('E1', 'Prenom');
$sheet->setCellValue('F1', 'Cin');
$sheet->setCellValue('G1', 'Prelevement');
$sheet->setCellValue('H1', 'Element');
$sheet->setCellValue('I1', 'nombre de mois');
$sheet->setCellValue('J1', 'Montant');
$sheet->setCellValue('K1', 'Montant echeance');
$sheet->setCellValue('L1', 'Periode');
$sheet->setCellValue('M1', 'active');
$sheet->setCellValue('N1', 'Montant');
$sheet->setCellValue('O1', 'Bulletin');
// $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
// $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
$prelevements = $this->em->getRepository(PPrelevement::class)->findBy(['active' => true]);
// dd($bulletinLgs);
$i = 2;
foreach ($prelevements as $key => $prelevement) {
foreach ($prelevement->getPrelevementLgs() as $key => $prelevementLg) {
$bulletin = $prelevementLg->getBulletin();
$sheet->setCellValue('A' . $i, $prelevement->getContract()->getDossier()->getId());
$sheet->setCellValue('B' . $i, $prelevement->getContract()->getDossier()->getAbreviation());
$sheet->setCellValue('C' . $i, $prelevement->getContract()->getId());
$sheet->setCellValue('D' . $i, $prelevement->getContract()->getEmploye()->getNom());
$sheet->setCellValue('E' . $i, $prelevement->getContract()->getEmploye()->getPrenom());
$sheet->setCellValue('F' . $i, $prelevement->getContract()->getEmploye()->getCin());
$sheet->setCellValue('G' . $i, $prelevement->getCode());
$sheet->setCellValue('H' . $i, $prelevement->getRubrique()->getDesignation());
$sheet->setCellValue('I' . $i, $prelevement->getNombreMois());
$sheet->setCellValue('J' . $i, $prelevement->getMontant());
$sheet->setCellValue('K' . $i, $prelevement->getMontantEcheance());
$sheet->setCellValue('L' . $i, $prelevementLg->getPeriode()->getCode());
$sheet->setCellValue('M' . $i, $prelevementLg->isActive());
$sheet->setCellValue('N' . $i, $prelevementLg->getMontant());
$sheet->setCellValue('O' . $i, $prelevementLg->getBulletin() ? $prelevementLg->getBulletin()->getCode() : '');
$i++;
}
}
$writer = new Xlsx($spreadsheet);
$fileName = 'prelevements.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
$writer->save($temp_file);
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
#[Route('/app_reporting_extraction_cnss_b04/{periode}', name: 'app_reporting_extraction_cnss_b04', options: ['expose' => true])]
public function app_reporting_extraction_cnss_b04(Request $request, $periode): Response
{
$periode = str_replace('-', '', $periode);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Cin');
$sheet->setCellValue('B1', 'Id Contrat');
$sheet->setCellValue('C1', 'type_enreg');
$sheet->setCellValue('D1', 'num_affilie');
$sheet->setCellValue('E1', 'periode');
$sheet->setCellValue('F1', 'num_assure');
$sheet->setCellValue('G1', 'nom_prenom');
$sheet->setCellValue('H1', 'num_cin');
$sheet->setCellValue('I1', 'nbr_jours');
$sheet->setCellValue('J1', 'sal_reel');
$sheet->setCellValue('K1', 'sal_plaf');
$sheet->setCellValue('L1', 's_ctr');
$sheet->setCellValue('M1', 'filler');
$sheet->setCellValue('N1', 'site');
$sheet->setCellValue('O1', 'montant reel');
$sheet->setCellValue('P1', 'montant plaf');
// $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
// $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
$tcnss00s = $this->em->getRepository(TCnssA00::class)->findBy(['active' => true, 'periode' => $periode]);
$tcnssb00s = $this->em->getRepository(TCnssB00::class)->findBy(['cnssa00' => $tcnss00s]);
// dd($tcnssb00s);
$i = 2;
foreach ($tcnssb00s as $key => $tcnssb00) {
foreach ($tcnssb00->getTCnssB04s() as $key => $tcnssB04) {
$sheet->setCellValue('A' . $i, $tcnssB04->getContract() ? $tcnssB04->getContract()->getEmploye()->getCin() : '');
$sheet->setCellValue('B' . $i, $tcnssB04->getContract() ? $tcnssB04->getContract()->getId() : '');
$sheet->setCellValue('C' . $i, $tcnssB04->getTypeEnreg());
$sheet->setCellValue('D' . $i, $tcnssB04->getNumAffilie());
$sheet->setCellValue('E' . $i, $tcnssB04->getPeriode());
$sheet->setCellValue('F' . $i, $tcnssB04->getNumAssure());
$sheet->setCellValue('G' . $i, $tcnssB04->getNomPrenom());
$sheet->setCellValue('H' . $i, $tcnssB04->getNumCin());
$sheet->setCellValue('I' . $i, $tcnssB04->getNbrJours());
$sheet->setCellValue('J' . $i, $tcnssB04->getSalReel());
$sheet->setCellValue('K' . $i, $tcnssB04->getSalPlaf());
$sheet->setCellValue('L' . $i, $tcnssB04->getSCtr());
$sheet->setCellValue('M' . $i, $tcnssB04->getFiller());
$sheet->setCellValue('N' . $i, $tcnssB04->getSite());
$sheet->setCellValue('O' . $i, $tcnssB04->getMontantReel());
$sheet->setCellValue('P' . $i, $tcnssB04->getMontantPlaf());
$i++;
}
}
$writer = new Xlsx($spreadsheet);
$fileName = 'cnssb04_' . $periode . '.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
$writer->save($temp_file);
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
#[Route('/app_reporting_extraction_cnss_b02/{periode}', name: 'app_reporting_extraction_cnss_b02', options: ['expose' => true])]
public function app_reporting_extraction_cnss_b02(Request $request, $periode): Response
{
$periode = str_replace('-', '', $periode);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Cin');
$sheet->setCellValue('B1', 'Id Contrat');
$sheet->setCellValue('C1', 'type_enreg');
$sheet->setCellValue('D1', 'num_affilie');
$sheet->setCellValue('E1', 'periode');
$sheet->setCellValue('F1', 'num_assure');
$sheet->setCellValue('G1', 'nom_prenom');
$sheet->setCellValue('H1', 'enfants');
$sheet->setCellValue('I1', 'af_apayer');
$sheet->setCellValue('J1', 'af_adeduire');
$sheet->setCellValue('K1', 'af_net_apayer');
$sheet->setCellValue('L1', 'af_areverser');
$sheet->setCellValue('M1', 'n_jours_declares');
$sheet->setCellValue('N1', 'n_salaire_reel');
$sheet->setCellValue('O1', 'n_salaire_plaf');
$sheet->setCellValue('P1', 'l_situation');
$sheet->setCellValue('Q1', 'l_situation_num');
$sheet->setCellValue('R1', 's_ctr');
$sheet->setCellValue('S1', 'filler');
$sheet->setCellValue('T1', 'site');
$sheet->setCellValue('U1', 'statut');
$sheet->setCellValue('V1', 'montant reel');
$sheet->setCellValue('W1', 'montant plaf');
// $cotisations = [50, 47, 53, 51, 52, 54, 55, 56, 58, 48, 57, 43];
// $rubriques = $this->em->getRepository(Prubrique::class)->findBy(['id' => $cotisations]);
$tcnss00s = $this->em->getRepository(TCnssA00::class)->findBy(['active' => true, 'periode' => $periode]);
$tcnssb00s = $this->em->getRepository(TCnssB00::class)->findBy(['cnssa00' => $tcnss00s]);
// dd($tcnssb00s);
$i = 2;
foreach ($tcnssb00s as $key => $tcnssb00) {
foreach ($tcnssb00->getTCnssB02s() as $key => $tcnssB02) {
$sheet->setCellValue('A' . $i, $tcnssB02->getContract() ? $tcnssB02->getContract()->getEmploye()->getCin() : '');
$sheet->setCellValue('B' . $i, $tcnssB02->getContract() ? $tcnssB02->getContract()->getId() : '');
$sheet->setCellValue('C' . $i, $tcnssB02->getTypeEnreg());
$sheet->setCellValue('D' . $i, $tcnssB02->getNumAffilie());
$sheet->setCellValue('E' . $i, $tcnssB02->getPeriode());
$sheet->setCellValue('F' . $i, $tcnssB02->getNumAssure());
$sheet->setCellValue('G' . $i, $tcnssB02->getNomPrenom());
$sheet->setCellValue('H' . $i, $tcnssB02->getEnfants());
$sheet->setCellValue('I' . $i, $tcnssB02->getAfApayer());
$sheet->setCellValue('J' . $i, $tcnssB02->getAfAdeduire());
$sheet->setCellValue('K' . $i, $tcnssB02->getAfNetApayer());
$sheet->setCellValue('L' . $i, $tcnssB02->getAfAreverser());
$sheet->setCellValue('M' . $i, $tcnssB02->getNJoursDeclares());
$sheet->setCellValue('N' . $i, $tcnssB02->getNSalaireReel());
$sheet->setCellValue('O' . $i, $tcnssB02->getNSalairePlaf());
$sheet->setCellValue('P' . $i, $tcnssB02->getLSituation());
$sheet->setCellValue('Q' . $i, $tcnssB02->getLSituationNum());
$sheet->setCellValue('R' . $i, $tcnssB02->getSCtr());
$sheet->setCellValue('S' . $i, $tcnssB02->getFiller());
$sheet->setCellValue('T' . $i, $tcnssB02->getSite());
$sheet->setCellValue('U' . $i, $tcnssB02->getStatut());
$sheet->setCellValue('V' . $i, $tcnssB02->getMontantReel());
$sheet->setCellValue('W' . $i, $tcnssB02->getMontantPlaf());
$i++;
}
}
$writer = new Xlsx($spreadsheet);
$fileName = 'cnssb02_' . $periode . '.xlsx';
$temp_file = tempnam(sys_get_temp_dir(), $fileName);
$writer->save($temp_file);
return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
}
#[Route('/app_reporting_extraction_input', name: 'app_reporting_extraction_input', options: ['expose' => true])]
public function app_reporting_extraction_input(Request $request, HttpClientInterface $client): Response
{
try {
$response = $client->request('GET', "http://52.213.254.104/api/rh/cab/extraction", [
'verify_peer' => false,
'verify_host' => false,
'timeout' => 30
]);
if($response->getStatusCode() === 200) {
$result = $response->toArray();
return new JsonResponse($result);
}
throw new \Exception($response->getContent(false));
} catch (\Throwable $th) {
return new JsonResponse($th->getMessage(), 500);
}
}
#[Route('/app_reporting_extraction_etat_paie_cnss/{periode}/{dossier}', name: 'app_reporting_extraction_etat_paie_cnss', options: ['expose' => true])]
public function app_reporting_extraction_etat_paie_cnss($periode, PDossier $dossier): Response
{
$date = new \DateTime($periode);
$periode = $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
$bulletins = $this->em->createQueryBuilder()
->select('b')
->from(Tbulletin::class, 'b')
->innerJoin('b.contract', 'contract')
->innerJoin('contract.pnatureContract', 'natureType')
->innerJoin('natureType.type', 'type')
->where('b.active = 1 ')
->andWhere('b.piece = 1')
->andWhere('type.id = 1')
->andWhere('b.periode = :periode')
->andWhere('b.dossier = :dossier')
->setParameter('dossier', $dossier)
->setParameter('periode', $periode)
->getQuery()
->getResult();
// dd($bulletins);
$results = [];
foreach ($bulletins as $bulletin) {
$result['bulletin_id'] = $bulletin->getId();
$result['periode'] = $bulletin->getPeriode()->getCode();
$result['contract_id'] = $bulletin->getContract()->getId();
$result['employe'] = $bulletin->getContract()->getEmploye()->getNom() . ' ' . $bulletin->getContract()->getEmploye()->getPrenom();
$bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin, 'active' => true, 'rubrique' => [1, 2, 47, 50, 51, 52, 53, 54, 55, 56, 58]]);
$result['details']['salaireImpo']= 0;
$result['details']['cnssPS']= 0;
$result['details']['cnssPP']= 0;
foreach ($bulletinLgs as $bulletinLg) {
$rubrique = $bulletinLg->getRubrique()->getId();
// if (!isset($result['details'])) {
// $result['details'] = [
// 'salaireImpo' => 0,
// 'cnssPS' => 0,
// 'cnssPP' => 0,
// ];
// }
if ($rubrique === 1 || $rubrique === 2) {
$result['details']['salaireImpo'] += $bulletinLg->getMontant();
} elseif ($rubrique === 47 || $rubrique === 53) {
$result['details']['cnssPS'] += $bulletinLg->getMontant();
$totalCnss = $bulletinLg->getMontant();
} elseif ($rubrique === 56 || $rubrique === 58) {
$result['details']['cnssPP'] += $bulletinLg->getMontant();
$totalCnss = $bulletinLg->getMontant();
} else {
$result['details']['fraisCnss_' . $rubrique] = $bulletinLg->getMontant();
}
}
if ($result['details']['salaireImpo'] > 6000) {
$result['details']['salaireImpoPlafond'] = 6000;
} else {
$result['details']['salaireImpoPlafond'] = $result['details']['salaireImpo'];
}
array_push($results, $result);
}
// dd($results);
// dd($bulletinLgs);
$html = $this->render("reporting/extraction/pdf/cnss.html.twig", [
'periode' => $periode,
'dossier' => $dossier,
'date' => $date,
'results' => $results
])->getContent();
$mpdf = new Mpdf([
'mode' => 'utf-8',
'margin_left' => '5',
'margin_right' => '5',
'format' => 'A4-L',
'margin_header' => 5,
'margin_top' => 5,
]);
$mpdf->SetHTMLFooter("<footer class='center'>
<table width='100%'>
<tr>
<td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
<td width='33%' style='text-align: center;'>" . date("d/m/y") . "</td>
</tr>
</table>
</footer>");
$mpdf->SetTitle('CNSS');
$mpdf->WriteHTML($html);
$mpdf->Output("CNSS_" . $dossier->getAbreviation() . "_" . $date->format('mY') . ".pdf", "I");
}
#[Route('/app_reporting_extraction_etat_paie_cimr/{periode}/{dossier}', name: 'app_reporting_extraction_etat_paie_cimr', options: ['expose' => true])]
public function app_reporting_extraction_etat_paie_cimr($periode, PDossier $dossier): Response
{
$date = new \DateTime($periode);
$periode = $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
$bulletins = $this->em->createQueryBuilder()
->select('b')
->from(Tbulletin::class, 'b')
->innerJoin('b.contract', 'contract')
->innerJoin('contract.pnatureContract', 'natureType')
->innerJoin('natureType.type', 'type')
->where('b.active = 1 ')
->andWhere('b.piece = 1')
->andWhere('type.id = 1')
->andWhere('b.periode = :periode')
->andWhere('b.dossier = :dossier')
->setParameter('dossier', $dossier)
->setParameter('periode', $periode)
->getQuery()
->getResult();
// dd($bulletins);
$results = [];
foreach ($bulletins as $bulletin) {
$result['bulletin_id'] = $bulletin->getId();
$result['periode'] = $bulletin->getPeriode()->getCode();
$result['contract_id'] = $bulletin->getContract()->getId();
$result['employe'] = $bulletin->getContract()->getEmploye()->getNom() . ' ' . $bulletin->getContract()->getEmploye()->getPrenom();
$bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin, 'active' => true, 'rubrique' => [1, 2, 48, 57]]);
$totalCimr = 0;
$result['details']['salaireImpo']= 0;
foreach ($bulletinLgs as $bulletinLg) {
$rubrique = $bulletinLg->getRubrique()->getId();
// if (!isset($result['details'])) {
// $result['details'] = [
// 'salaireImpo' => 0
// ];
// }
if ($rubrique === 1 || $rubrique === 2) {
$result['details']['salaireImpo'] += $bulletinLg->getMontant();
} else {
$result['details']['fraisCimr_' . $rubrique] = $bulletinLg->getMontant();
$bareme = $this->em->getRepository(PBaremeCimr::class)->findOneBy(['rubrique' => $rubrique, 'bareme' => $bulletin->getContract()->getBareme()->getId()]);
$result['details']['taux_' . $rubrique] = $bareme->getTaux();
$totalCimr += $bulletinLg->getMontant();
}
}
$result['details']['totalCimr'] = $totalCimr;
array_push($results, $result);
}
// dd($results);
$html = $this->render("reporting/extraction/pdf/cimr.html.twig", [
'periode' => $periode,
'dossier' => $dossier,
'date' => $date,
'results' => $results
])->getContent();
$mpdf = new Mpdf([
'mode' => 'utf-8',
'margin_left' => '5',
'margin_right' => '5',
'format' => 'A4-L',
'margin_header' => 5,
'margin_top' => 5,
]);
$mpdf->SetHTMLFooter("<footer class='center'>
<table width='100%'>
<tr>
<td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
<td width='33%' style='text-align: center;'>" . date("d/m/y") . "</td>
</tr>
</table>
</footer>");
$mpdf->SetTitle('CIMR');
$mpdf->WriteHTML($html);
$mpdf->Output("CIMR_" . $dossier->getAbreviation() . "_" . $date->format('mY') . ".pdf", "I");
}
#[Route('/app_reporting_extraction_etat_paie_ir/{periode}/{dossier}/{natureType}', name: 'app_reporting_extraction_etat_paie_ir', options: ['expose' => true])]
public function app_reporting_extraction_etat_paie_ir($periode, PDossier $dossier, PnatureContract $natureType): Response
{
$date = new \DateTime($periode);
$periode = $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
$bulletins = $this->em->createQueryBuilder()
->select('b')
->from(Tbulletin::class, 'b')
->innerJoin('b.contract', 'contract')
// ->innerJoin('contract.pnatureContract', 'natureType')
// ->innerJoin('natureType.type', 'type')
->where('b.active = 1 ')
->andWhere('b.piece = 1')
->andWhere('contract.pnatureContract = :natureType')
// ->andWhere('type.id = 1')
->andWhere('b.periode = :periode')
->andWhere('b.dossier = :dossier')
->setParameter('dossier', $dossier)
->setParameter('periode', $periode)
->setParameter('natureType', $natureType)
->getQuery()
->getResult();
// dd($bulletins);
$results = [];
foreach ($bulletins as $bulletin) {
$result['bulletin_id'] = $bulletin->getId();
$result['periode'] = $bulletin->getPeriode()->getCode();
$result['contract_id'] = $bulletin->getContract()->getId();
$result['employe'] = $bulletin->getContract()->getEmploye()->getNom() . ' ' . $bulletin->getContract()->getEmploye()->getPrenom();
if ($natureType->getType()->getId() === 1) {
$bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin, 'active' => true, 'rubrique' => [1, 2, 43]]);
foreach ($bulletinLgs as $bulletinLg) {
$rubrique = $bulletinLg->getRubrique()->getId();
if (!isset($result['details'])) {
$result['details'] = [
'salaireImpo' => 0
];
}
if ($rubrique === 1 || $rubrique === 2) {
$result['details']['salaireImpo'] += $bulletinLg->getMontant();
} else {
$result['details']['ir_' . $rubrique] = $bulletinLg->getMontant();
}
$result['details']['fraisProf'] = $result['details']['salaireImpo'] * 0.2;
$montantCotisationTotale = $this->em->createQueryBuilder()
->select('sum(TbulletinLg.montant) as montant')
->from(TbulletinLg::class, 'TbulletinLg')
->innerJoin('TbulletinLg.bulletin', 'bulletin')
->innerJoin('TbulletinLg.rubrique', 'rubrique')
->andWhere('rubrique.id in(50, 47, 53, 48)')
->andWhere('TbulletinLg.active = 1')
->andWhere('bulletin.id = :bulletin')
->setParameter('bulletin', $bulletin)
->getQuery()
->getOneOrNullResult();
$result['details']['salaireNetImpo'] = $result['details']['salaireImpo'] - ($montantCotisationTotale['montant'] + ($result['details']['fraisProf']));
}
} else {
$bulletinLgs = $this->em->getRepository(TbulletinLg::class)->findBy(['bulletin' => $bulletin, 'active' => true, 'rubrique' => [65, 68, 43]]);
foreach ($bulletinLgs as $bulletinLg) {
$rubrique = $bulletinLg->getRubrique()->getId();
$result['details']['ir_' . $rubrique] = $bulletinLg->getMontant();
}
$prelevement = $this->em->createQueryBuilder()
->select('sum(TbulletinLg.montant) as montant')
->from(TbulletinLg::class, 'TbulletinLg')
->innerJoin('TbulletinLg.bulletin', 'bulletin')
->innerJoin('TbulletinLg.rubrique', 'rubrique')
->andWhere('rubrique.prets = 1')
->andWhere('TbulletinLg.active = 1')
->andWhere('bulletin.id = :bulletin')
->setParameter('bulletin', $bulletin)
->getQuery()
->getOneOrNullResult();
if (!($prelevement['montant'])) {
// dd('h');
$result['details']['prets'] = 0;
} else {
$result['details']['prets'] = $prelevement['montant'];
}
}
array_push($results, $result);
}
// dd($results);
$html = $this->render("reporting/extraction/pdf/ir.html.twig", [
'periode' => $periode,
'dossier' => $dossier,
'date' => $date,
'results' => $results,
'nature' => $natureType
])->getContent();
$mpdf = new Mpdf([
'mode' => 'utf-8',
'margin_left' => '5',
'margin_right' => '5',
'format' => 'A4-L',
'margin_header' => 5,
'margin_top' => 5,
]);
$mpdf->SetHTMLFooter("<footer class='center'>
<table width='100%'>
<tr>
<td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
<td width='33%' style='text-align: center;'>" . date("d/m/y") . "</td>
</tr>
</table>
</footer>");
$mpdf->SetTitle('IR');
$mpdf->WriteHTML($html);
$mpdf->Output("IR_" . $dossier->getAbreviation() . "_" . $natureType->getDesignation() . "_" . $date->format('mY') . ".pdf", "I");
}
#[Route('/pdf_etat_recapitulatif/{periode}/{dossier}/{natureType}', name: 'app_extraction_recapitulatif_pdf', options: ['expose' => true])]
public function pdf_honoraire(Request $request,$periode,PDossier $dossier,PnatureContract $natureType): Response
{
// dd($natureType);
$date = new \DateTime($periode);
$periode = $this->em->getRepository(periode::class)->findBy(['code' => $date->format('mY')]);
$queryBuilder = $this->em->createQueryBuilder()
->select('sum(bl.montant) as Montant,r.id as rubrique,r.designation as element,
p.date,d.abreviation as dossier,
CASE WHEN r.id in (37,33, 37, 38,39,77,78,79,80,84,85) THEN 4 ELSE SUBSTRING(pc.compteComptable, 1, 1) END as compteComptable,
r.code,r.designation')
->from(Tbulletin::class, 'tb')
->innerJoin('tb.bulletinLgs', 'bl')
->innerJoin('tb.piece', 'piece')
->innerJoin('tb.bordereau', 'b')
->innerJoin('b.natureContract', 'n')
->innerJoin('bl.rubrique', 'r')
->innerJoin('tb.periode', 'p')
->innerJoin('tb.dossier', 'd')
->innerJoin('r.compteComptables', 'pc')
->where('n.id =:natureType')
->andWhere('pc.natureContract = :natureType')
->andWhere('tb.periode = :periode')
->andWhere('tb.dossier = :dossier')
->andWhere('bl.montant != 0')
->andWhere('tb.active = 1')
->andWhere('piece.id = 1')
->andWhere('bl.active = 1')
->andWhere('r.id NOT IN (51, 52, 54, 55, 56, 57, 58)')
->setParameter('dossier', $dossier)
->setParameter('periode', $periode)
->setParameter('natureType', $natureType)
->groupBy('r.id')
->orderBy('compteComptable', 'DESC');
$results = $queryBuilder->getQuery()->getResult();
// dd($results);
// $date = $results[0]['date'];
$date->modify('last day of this month'); //30-09-2023
$html = $this->render("reporting/extraction/pdf/recapitulatif.html.twig", [
'results' => $results, 'date' => $date, 'dossier' => $dossier
])->getContent();
$mpdf = new Mpdf([
'mode' => 'utf-8',
'margin_left' => '5',
'margin_right' => '5',
]);
$mpdf->SetTitle('Etat_RECAPITULATIF');
// $mpdf->SetHTMLFooter(
// $this->render("planification/pdfs/footer.html.twig")->getContent()
// );
$mpdf->WriteHTML($html);
$mpdf->Output("Etat_RECAPITULATIF". $dossier->getAbreviation() . "_" . $date->format('mY') . "_" . $natureType->getDesignation().".pdf", "I");
}
#[Route('/app_reporting_extraction_etat_pret/{periode}/{dossier}/{rubrique}', name: 'app_reporting_extraction_etat_pret', options: ['expose' => true])]
public function app_reporting_extraction_etat_pret($periode, PDossier $dossier, Prubrique $rubrique): Response
{
$date = new \DateTime($periode);
$periode = $this->em->getRepository(periode::class)->findOneBy(['code' => $date->format('mY')]);
// dd($periode,$rubrique,$dossier);
$bulletinLgs = $this->em->createQueryBuilder()
->select('lg')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->where('lg.active = 1')
->andWhere('lg.rubrique = :rubrique ')
->andWhere('b.active = 1 ')
->andWhere('b.piece = 1')
->andWhere('b.periode = :periode')
->andWhere('b.dossier = :dossier')
->setParameter('dossier', $dossier)
->setParameter('periode', $periode)
->setParameter('rubrique', $rubrique)
->getQuery()
->getResult();
// dd($bulletinLgs[0]->getBulletin()->getContract()->getEmploye()->getNom());
$html = $this->render("reporting/extraction/pdf/pret.html.twig", [
'periode' => $periode,
'dossier' => $dossier,
'date' => $date,
'rubrique' => $rubrique,
'bulletinLgs' => $bulletinLgs
])->getContent();
$mpdf = new Mpdf([
'mode' => 'utf-8',
'margin_left' => '5',
'margin_right' => '5',
'format' => 'A4',
'margin_header' => 5,
'margin_top' => 5,
]);
$mpdf->SetHTMLFooter("<footer class='center'>
<table width='100%'>
<tr>
<td width='33%' style='text-align: center;'>page {PAGENO} sur {nbpg}</td>
<td width='33%' style='text-align: center;'>" . date("d/m/y") . "</td>
</tr>
</table>
</footer>");
$mpdf->SetTitle('pret');
$mpdf->WriteHTML($html);
$mpdf->Output("pret_" . $dossier->getAbreviation() . "_" . $date->format('mY') . "_" . $rubrique->getDesignation() . ".pdf", "I");
}
#[Route('/app_reporting_extraction_synthese_paie/{periode}/{groupement}/{devise}', name: 'app_reporting_extraction_synthese_paie', options: ['expose' => true])]
public function app_reporting_extraction_synthese_paie($periode,$groupement,$devise): Response
{
$date = new \DateTime($periode);
$previousMonth=$date->modify('-1 month')->format('mY');
$date = new \DateTime($periode);
$currentMonth=$date->format('mY');
$dossier=$this->em->getRepository(pdossier::class)->findOneBy(['groupement' => $groupement]);
// dd($date,$previousMonth,$currentMonth,$devise);
$currentperiode = $this->em->getRepository(periode::class)->findOneBy(['code' => $currentMonth]);
$previousPeriode = $this->em->getRepository(periode::class)->findOneBy(['code' => $previousMonth]);
$periode = $this->em->getRepository(periode::class)->findBy(['code' => [$previousMonth,$currentMonth]]);
// dd($periode);
if($groupement=='FCZ'){
$designationGrp='FONDATION CHEIKH ZAID';
}elseif ($groupement=='RGA'){
$designationGrp='AFRIC-MED REPARTITEUR GROSSISTE';
}elseif ($groupement=='SSS'){
$designationGrp='SOCIETE AFRICAINE DES SERVICES DE LA SANTE - METIERS';
}
elseif ($groupement=='SST'){
$designationGrp='SOCIETE AFRICAINE DES SERVICES DE LA SANTE - TRAVAUX';
}
$details['groupement']=$groupement;
$details['designationGrp']=$designationGrp;
$details['date']=$date;
$details['periode']=$periode;
$details['dossier']=$dossier;
$paieEffectif=$paieMontant=$indeminiteEffectif=$indeminiteMontant=$honoraireEffectif=$honoraireMontant=$stcEffectif=$stcMontant=$totalM1Effectif=$totalM1Montant=$totalMEffectif=$totalMMontant=0;
$natureContracts = $this->em->createQueryBuilder()
->select('distinct natureContract.id,natureContract.designation as nature_contract,d.groupement')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->innerJoin('b.dossier', 'd')
->innerJoin('b.bordereau', 'bordereau')
->innerJoin('bordereau.natureContract', 'natureContract')
->innerJoin('b.periode', 'periode')
->where('lg.active = 1')
->andWhere('b.active = 1')
->andWhere('bordereau.active = 1 ')
->andWhere('lg.rubrique in (5,68) ')
->andWhere('b.periode in( :periode)')
->andWhere('d.groupement = :groupement')
->setParameter('groupement', $groupement)
->setParameter('periode', $periode);
$natureContracts = $this->applyDeviseFilter($natureContracts, $devise)
->orderBy('natureContract.id', 'ASC')
->getQuery()
->getResult();
foreach ($natureContracts as $key => $natureContract) {
$results[$key]['natureContrat']=$natureContract['nature_contract'];
$totalEffectif=0;
$totalMontant=0;
$paie=$this->em->createQueryBuilder()
->select('count(contract.id) as effectif,sum(lg.montant) as montant')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->innerJoin('b.dossier', 'd')
->innerJoin('b.piece', 'piece')
->innerJoin('b.contract', 'contract')
->innerJoin('b.bordereau', 'bordereau')
->innerJoin('bordereau.natureContract', 'natureContract')
->innerJoin('b.periode', 'periode')
->where('lg.active = 1')
->andWhere('b.active = 1')
->andWhere('bordereau.active = 1 ')
->andWhere('lg.rubrique in (5,68) ')
->andWhere('b.piece = 1')
->andWhere('b.periode in( :periode)')
->andWhere('d.groupement = :groupement')
->andWhere('natureContract.id =:natureContract')
->setParameter('groupement', $groupement)
->setParameter('natureContract', $natureContract['id'])
->setParameter('periode', $currentperiode);
$paie = $this->applyDeviseFilter($paie, $devise)
->getQuery()
->getOneOrNullResult();
$totalEffectif+=$results[$key]['effectifPaie']=$paie['effectif'];
$totalMontant+=$results[$key]['montantPaie']=$paie['montant'];
$paieEffectif+=$paie['effectif'];
$paieMontant+=$paie['montant'];
$indeminite=$this->em->createQueryBuilder()
->select('count(contract.id) as effectif,sum(lg.montant) as montant')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->innerJoin('b.dossier', 'd')
->innerJoin('b.piece', 'piece')
->innerJoin('b.contract', 'contract')
->innerJoin('b.bordereau', 'bordereau')
->innerJoin('bordereau.natureContract', 'natureContract')
->innerJoin('b.periode', 'periode')
->where('lg.active = 1')
->andWhere('b.active = 1')
->andWhere('bordereau.active = 1 ')
->andWhere('lg.rubrique in (5,68) ')
->andWhere('b.piece = 3')
->andWhere('b.periode in( :periode)')
->andWhere('d.groupement = :groupement')
->andWhere('natureContract.id =:natureContract')
->setParameter('groupement', $groupement)
->setParameter('natureContract', $natureContract['id'])
->setParameter('periode', $currentperiode);
$indeminite = $this->applyDeviseFilter($indeminite, $devise)
->getQuery()
->getOneOrNullResult();
$totalEffectif+=$results[$key]['effectifIndeminite']=$indeminite['effectif'];
$totalMontant+=$results[$key]['montantIndeminite']=$indeminite['montant'];
$indeminiteEffectif+=$indeminite['effectif'];
$indeminiteMontant+=$indeminite['montant'];
$honoraire=$this->em->createQueryBuilder()
->select('count(contract.id) as effectif,sum(lg.montant) as montant')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->innerJoin('b.dossier', 'd')
->innerJoin('b.piece', 'piece')
->innerJoin('b.contract', 'contract')
->innerJoin('b.bordereau', 'bordereau')
->innerJoin('bordereau.natureContract', 'natureContract')
->innerJoin('b.periode', 'periode')
->where('lg.active = 1')
->andWhere('b.active = 1')
->andWhere('bordereau.active = 1 ')
->andWhere('lg.rubrique in (5,68) ')
->andWhere('b.piece = 2')
->andWhere('b.periode in( :periode)')
->andWhere('d.groupement = :groupement')
->andWhere('natureContract.id =:natureContract')
->setParameter('groupement', $groupement)
->setParameter('natureContract', $natureContract['id'])
->setParameter('periode', $currentperiode);
$honoraire = $this->applyDeviseFilter($honoraire, $devise)
->getQuery()
->getOneOrNullResult();
$totalEffectif+=$results[$key]['effectifHonoraire']=$honoraire['effectif'];
$totalMontant+=$results[$key]['montantHonoraire']=$honoraire['montant'];
$honoraireEffectif+=$honoraire['effectif'];
$honoraireMontant+=$honoraire['montant'];
$stc=$this->em->createQueryBuilder()
->select('count(contract.id) as effectif,sum(lg.montant) as montant')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->innerJoin('b.dossier', 'd')
->innerJoin('b.piece', 'piece')
->innerJoin('b.contract', 'contract')
->innerJoin('b.bordereau', 'bordereau')
->innerJoin('bordereau.natureContract', 'natureContract')
->innerJoin('b.periode', 'periode')
->where('lg.active = 1')
->andWhere('b.active = 1')
->andWhere('bordereau.active = 1 ')
->andWhere('lg.rubrique in (5,68) ')
->andWhere('b.piece = 13')
->andWhere('b.periode in( :periode)')
->andWhere('d.groupement = :groupement')
->andWhere('natureContract.id =:natureContract')
->setParameter('groupement', $groupement)
->setParameter('natureContract', $natureContract['id'])
->setParameter('periode', $currentperiode);
$stc = $this->applyDeviseFilter($stc, $devise)
->getQuery()
->getOneOrNullResult();
$totalEffectif+=$results[$key]['effectifStc']=$stc['effectif'];
$totalMontant+=$results[$key]['montantStc']=$stc['montant'];
$stcEffectif+=$stc['effectif'];
$stcMontant+=$stc['montant'];
$totalM1 = $this->em->createQueryBuilder()
->select('count(contract.id) as effectif,sum(lg.montant) as montant')
->from(TbulletinLg::class, 'lg')
->innerJoin('lg.bulletin', 'b')
->innerJoin('b.dossier', 'd')
->innerJoin('b.piece', 'piece')
->innerJoin('b.contract', 'contract')
->innerJoin('b.bordereau', 'bordereau')
->innerJoin('bordereau.natureContract', 'natureContract')
->innerJoin('b.periode', 'periode')
->where('lg.active = 1')
->andWhere('b.active = 1')
->andWhere('bordereau.active = 1 ')
->andWhere('lg.rubrique in (5,68) ')
->andWhere('b.periode in( :periode)')
->andWhere('d.groupement = :groupement')
->andWhere('natureContract.id =:natureContract')
->setParameter('groupement', $groupement)
->setParameter('periode', $previousPeriode)
->setParameter('natureContract', $natureContract['id']);
$totalM1 = $this->applyDeviseFilter($totalM1, $devise)
->getQuery()
->getOneOrNullResult();
$results[$key]['effectifTotalM1']=$totalM1['effectif'];
$results[$key]['montantTotalM1']=$totalM1['montant'];
$totalM1Effectif+=$totalM1['effectif'];
$totalM1Montant+=$totalM1['montant'];
$results[$key]['totalEffectif']=$totalEffectif;
$results[$key]['totalMontant']=$totalMontant;
$totalMEffectif+=$totalEffectif;
$totalMMontant+=$totalMontant;
// dd($results,$totalM1,$stc,$groupement);
}
$total['effectifPaie']=$paieEffectif;
$total['montantPaie']=$paieMontant;
$total['effectifIndeminite']=$indeminiteEffectif;
$total['montantIndeminite']=$indeminiteMontant;
$total['effectifHonoraire']=$honoraireEffectif;
$total['montantHonoraire']=$honoraireMontant;
$total['effectifStc']=$stcEffectif;
$total['montantStc']=$stcMontant;
$total['effectifM1']=$totalM1Effectif;
$total['montantM1']=$totalM1Montant;
$total['effectifMois']=$totalMEffectif;
$total['montantMois']=$totalMMontant;
// dd($results);
$html = $this->render("reporting/extraction/pdf/synthese_paie.html.twig", [
'results'=>$results,
'details'=>$details,
'total'=>$total
])->getContent();
$mpdf = new Mpdf([
'mode' => 'utf-8',
'margin_left' => '5',
'margin_right' => '5',
'format' => 'A4-L',
'margin_header' => 5,
'margin_top' => 10,
]);
$mpdf->SetHTMLFooter("<footer class='center'>
<table width='100%'>
<tr>
<td width='33%' style='text-align: center;'>page {PAGENO} de {nbpg}</td>
</tr>
</table>
</footer>");
$mpdf->SetTitle('synthese paie');
$mpdf->WriteHTML($html);
$mpdf->Output("Synthèse Paie " . $groupement . " " . $date->format('F Y') .".pdf", "I");
}
private function applyDeviseFilter($queryBuilder, $devise)
{
if (strtoupper($devise) == 'MAD') {
$queryBuilder->andWhere('natureContract.id not in (15,16,17)')
->andWhere('bordereau.devise = 1');
} else {
$queryBuilder->andWhere('bordereau.devise != 1');
}
return $queryBuilder;
}
#[Route('/app_reporting_amine_test', name: 'app_reporting_amine_test', options: ['expose' => true])]
public function app_reporting_amine_test(): Response
{
return new JsonResponse('amine');
}
}