SetY(-15); $this->SetFont('Arial', 'I', 9); $this->SetTextColor(100, 100, 100); $this->Cell(0, 10, 'Page ' . $this->PageNo() . ' / {nb}', 0, 0, 'C'); $this->SetTextColor(0); } } class ControleurAjaxstatsmaladiefichetechniquesixpdf extends Controleur { private $detailsp; private $pdf; private $maxPages = 50; private $currentRow = 0; private $rowsPerPage = 30; public function __construct() { $this->detailsp = new Statistique(); } private function validateRequestData($idPolice, $debutStat, $finStat, $codeGcAssureur) { if (empty($debutStat) || empty($finStat)) { throw new Exception(_("Paramètres de filtrage incomplets")); } if ($debutStat > $finStat) { throw new Exception(_("La date de début doit être antérieure à la date de fin")); } if (!strtotime($debutStat) || !strtotime($finStat)) { throw new Exception(_("Format de date invalide")); } return true; } private function validateHeaderData($entete, $idPolice) { if ($idPolice != null && empty($entete)) { throw new Exception(_("Aucune donnée disponible pour cette police")); } return true; } private function checkPageLimit() { if ($this->pdf->PageNo() >= $this->maxPages) { throw new Exception(_("Le document dépasse la limite de 50 pages autorisée")); } } private function addPageWithValidation() { $this->checkPageLimit(); $this->pdf->AddPage(); $this->currentRow = 0; $this->addTableHeaders(); } private function setupPagination() { // Configuration correcte de la pagination $this->pdf->AliasNbPages(); $this->pdf->SetAutoPageBreak(true, 20); // Marge de 20mm en bas } private function addFooter() { // CORRECTION : Pagination en bas au centre - positionnement correct $this->pdf->SetY(-15); // 15mm from bottom $this->pdf->SetFont('Arial', 'I', 9); $this->pdf->SetTextColor(100, 100, 100); // Option 1: Centrée $this->pdf->Cell(0, 10, 'Page ' . $this->pdf->PageNo() . ' / {nb}', 0, 0, 'C'); // Option 2: Alignée à droite (décommentez la ligne suivante et commentez la précédente) // $this->pdf->Cell(0, 10, 'Page ' . $this->pdf->PageNo() . ' / {nb}', 0, 0, 'R'); $this->pdf->SetTextColor(0); } private function createPDF() { $this->pdf = new PDFWithFooter(); // Utilisez la classe étendue $this->pdf->SetAuthor('EBENE SOLUTIONS INFORMATIQUES'); $userPassword = ''; $ownerPassword = null; $this->pdf->SetProtection(['print'], $userPassword, $ownerPassword); $this->setupPagination(); $this->pdf->SetMargins(10, 10, 10); $this->pdf->AddPage(); return $this->pdf; } private function addHeaderContent($debutStat, $finStat, $entete, $idPolice, $p_garant, $depenses) { $this->pdf->Image($_SESSION['lienLogo'],94,3,15); $this->pdf->SetFont('Arial','B',7); $this->pdf->Cell(0,5,convertirc(_('FICHE TECHNIQUE No 6')),0,1,'L',false); $this->pdf->SetY(10); $this->pdf->SetFont('Arial','',7); $this->pdf->Cell(0,5,convertirc(_('Edition du').': '.heureCouranteLang($_SESSION['lang'])),0,1,'R',false); $this->pdf->Ln(2); $this->pdf->SetFont('Arial','B',13); $this->pdf->SetFillColor(182,216,242); $this->pdf->Cell(0,8,convertirc(_("ETAT DES DEPENSES PAR FAMILLE D'ASSURES")),1,0,'C',true); $this->pdf->Ln(10); $this->pdf->SetFont('Arial', 'B', 11); $this->pdf->SetTextColor(0); $this->pdf->Ln(8); $this->pdf->Cell(0, 6, convertirc(_('PERIODE COMPTABLE CONSIDEREE').': '.dateLang($debutStat, $_SESSION['lang']).' '._('AU').' '.dateLang($finStat, $_SESSION['lang'])), 0, 1, 'C', false); if ($idPolice != null) { $this->pdf->Ln(10); $this->pdf->SetFont('Arial', 'BUI', 11); $this->pdf->Cell(35, 8, convertirc(_('GARANT').': '), 0, 0, 'L', false); $this->pdf->SetFont('Arial', 'BI', 11); $this->pdf->Cell(0, 8, convertirc($entete['garant']), 0, 1, 'L', false); $this->pdf->SetFont('Arial', 'BUI', 11); $this->pdf->Cell(35, 8, convertirc(_('SOUSCRIPTEUR').': '), 0, 0, 'L', false); $this->pdf->SetFont('Arial', 'BI', 11); $this->pdf->Cell(0, 8, convertirc($entete['souscripteur']), 0, 1, 'L', false); $this->pdf->SetFont('Arial', 'BUI', 11); $this->pdf->Cell(35, 8, convertirc(_('POLICE No').': '), 0, 0, 'L', false); $this->pdf->SetFont('Arial', 'BI', 11); $this->pdf->Cell(0, 8, convertirc($entete['numeroPolice'].' / '.$entete['libellePolice']), 0, 1, 'L', false); $this->pdf->SetFont('Arial', 'BUI', 11); $this->pdf->Cell(35, 8, convertirc(_('COURTIER').': '), 0, 0, 'L', false); $this->pdf->SetFont('Arial', 'BI', 11); $this->pdf->Cell(0, 8, convertirc($entete['courtier']), 0, 1, 'L', false); } else { $this->pdf->Ln(10); $this->pdf->SetFont('Arial', 'BUI', 11); $this->pdf->Cell(35, 8, convertirc(_('GARANT').': '), 0, 0, 'L', false); $this->pdf->SetFont('Arial', 'BI', 11); $this->pdf->Cell(0, 8, convertirc($p_garant), 0, 1, 'L', false); } $this->pdf->SetX(20); $this->pdf->Cell(170,6,convertirc(_('DEPENSES SUPERIEURES A').': '.format_N($depenses).' '.$_SESSION['devise_C']),1,1,'C',false); } private function addTableHeaders() { $hl = 7; $this->pdf->Ln(2); $this->pdf->SetFont('Arial','B',7); $this->pdf->SetFillColor(182,216,242); $this->pdf->Cell(15,$hl,convertirc(_('Matricule')),1,0,'C',true); $this->pdf->Cell(63,$hl,convertirc(_("Famille")),1,0,'C',true); $this->pdf->Cell(15,$hl,convertirc(_("Pop. active")),1,0,'C',true); $this->pdf->Cell(15,$hl,convertirc(_("Pop. traitée")),1,0,'C',true); $this->pdf->Cell(22,$hl,convertirc(_("Réclamé")),1,0,'C',true); $this->pdf->Cell(22,$hl,convertirc(_("# Non Remb.")),1,0,'C',true); $this->pdf->Cell(22,$hl,convertirc(_("Remboursé")),1,0,'C',true); $this->pdf->Cell(16,$hl,convertirc(_("Coût moyen")),1,1,'C',true); $this->pdf->SetFont('Arial','',7); } private function processDataInChunks($depensesFamille) { $totals = [ 'popActive' => 0, 'popTraite' => 0, 'montantReclame' => 0, 'montantNonRembourse' => 0, 'montantRembourse' => 0 ]; $hl = 7; $chunkSize = 100; for ($i = 0; $i < count($depensesFamille); $i += $chunkSize) { $chunk = array_slice($depensesFamille, $i, $chunkSize); foreach ($chunk as $dep) { // Vérifier s'il faut ajouter une nouvelle page if ($this->currentRow >= $this->rowsPerPage) { $this->addPageWithValidation(); } $this->pdf->Cell(15,$hl,convertirc($dep['numeroAdherent']),1,0,'C',false); $this->pdf->Cell(63,$hl,convertirc(substr($dep['adherent'],0,35)),1,0,'L',false); $this->pdf->Cell(15,$hl,convertirc($dep['popActive']),1,0,'C',false); $this->pdf->Cell(15,$hl,convertirc($dep['popTraite']),1,0,'C',false); $this->pdf->Cell(22,$hl,convertirc(format_N($dep['montantReclame'])),1,0,'C',false); $this->pdf->Cell(22,$hl,convertirc(format_N($dep['montantNonRembourse'])),1,0,'C',false); $this->pdf->Cell(22,$hl,convertirc(format_N($dep['montantRembourse'])),1,0,'C',false); $this->pdf->Cell(16,$hl,convertirc(format_N($dep['Coutmoyen'])),1,1,'C',false); $this->currentRow++; $totals['popActive'] += $dep['popActive']; $totals['popTraite'] += $dep['popTraite']; $totals['montantReclame'] += $dep['montantReclame']; $totals['montantNonRembourse'] += $dep['montantNonRembourse']; $totals['montantRembourse'] += $dep['montantRembourse']; } unset($chunk); } return $totals; } private function addFooterContent($depensesFamille, $totals) { $hl = 7; $total_coutMoyen = ($totals['popTraite'] > 0) ? $totals['montantRembourse'] / $totals['popTraite'] : 0; $this->pdf->SetFont('Arial','B',8); $this->pdf->SetFillColor(182,216,242); $this->pdf->Cell(78, $hl, convertirc("TOTAL GENERAL"), "1", 0, 'C', true); $this->pdf->Cell(15, $hl, format_N($totals['popActive']), 1, 0, 'C', true); $this->pdf->Cell(15, $hl, format_N($totals['popTraite']), 1, 0, 'C', true); $this->pdf->Cell(22, $hl, format_N($totals['montantReclame']), 1, 0, 'C', true); $this->pdf->Cell(22, $hl, format_N($totals['montantNonRembourse']), 1, 0, 'C', true); $this->pdf->Cell(22, $hl, format_N($totals['montantRembourse']), 1, 0, 'C', true); $this->pdf->Cell(16, $hl, format_N($total_coutMoyen), 1, 1, 'C', true); $this->pdf->Ln(5); $this->pdf->Cell(45, $hl, convertirc(_("Nombre de lignes: ").count($depensesFamille)), 0, 0, 'L', false); $this->pdf->Ln(8); $this->pdf->Cell(45, $hl, convertirc(_("# Non remb.= Ticket modérateur + exclusion + dépassement de plafond")), 0, 0, 'L', false); $this->pdf->Ln(5); $this->pdf->Cell(45, $hl, convertirc(_("# Pop.active= Population active sur la période")), 0, 0, 'L', false); $this->pdf->Ln(5); $this->pdf->Cell(45, $hl, convertirc(_("# Pop.traitée= Population traitée sur la période")), 0, 0, 'L', false); } public function index() { try { $idPolice = $this->requete->getParametreFormulaire("idPolice"); $debutStat = $this->requete->getParametreDate("debutStat"); $finStat = $this->requete->getParametreDate("finStat"); $codeGcAssureur = $this->requete->getParametreFormulaire("codeGcAssureur"); $depenses = $this->requete->getParametreFormulaire("depenses","numerique"); if($idPolice == ''){ $idPolice = null; } $this->validateRequestData($idPolice, $debutStat, $finStat, $codeGcAssureur); $_SESSION['debutStat'] = $debutStat; $_SESSION['finStat'] = $finStat; $_SESSION['depenses'] = $depenses; $entete = $this->detailsp->detailrapportspperiodepdfentete($idPolice); $this->validateHeaderData($entete, $idPolice); $p_datedebut = $_SESSION['debutStat']; $p_datefin = $_SESSION['finStat']; $p_garant = $codeGcAssureur; $p_id = $idPolice; $p_limite = $depenses; $p_id_college = null; $p_id_clients = null; $depensesFamille = $this->detailsp->detaildepensefamilleass($p_garant, $p_id_clients, $p_id, $p_id_college, $p_datedebut, $p_datefin, $p_limite); if (empty($depensesFamille)) { throw new Exception(_("Aucune donnée de dépenses disponible pour cette période")); } // CORRECTION : S'assurer que le footer est appelé sur chaque page $this->pdf = $this->createPDF(); $this->addHeaderContent($debutStat, $finStat, $entete, $idPolice, $p_garant, $depenses); $this->addTableHeaders(); $totals = $this->processDataInChunks($depensesFamille); $this->addFooterContent($depensesFamille, $totals); $fichier = "Temp/TMP_CUMUL_SP_FICHE6"."_".uniqid().".pdf"; $this->pdf->Output($fichier, "F"); $t_html = '
'; $t_html .= ''._("TELECHARGER FICHE 06").''; $t_html .= '
'; echo $t_html; } catch (Exception $e) { echo '
' . $e->getMessage() . '
'; return; } } }