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 ControleurAjaxstatsmaladiefichetechniquehuitpdf extends Controleur { private $detailsp; private $pdf; private $hauteurPageRestante = 250; // Hauteur approximative disponible par page public function __construct() { $this->detailsp = new Statistique(); } private function verifierDonnees($idPolice, $debutStat, $finStat) { // Vérification des paramètres obligatoires if (empty($debutStat) || empty($finStat) || empty($idPolice)) { throw new Exception(_("Paramètres de filtrage incomplets")); } // Vérification des dates if ($debutStat > $finStat) { throw new Exception(_("La date de début doit être antérieure à la date de fin")); } return true; } private function verifierEspacePage($hauteurNecessaire) { // Vérifie s'il reste assez d'espace sur la page courante $hauteurRestante = $this->hauteurPageRestante - $this->pdf->GetY(); return $hauteurRestante >= $hauteurNecessaire; } private function ajouterNouvellePageSiNecessaire($hauteurNecessaire = 50) { if (!$this->verifierEspacePage($hauteurNecessaire)) { $this->pdf->AddPage(); return true; } return false; } private function preparerDonneesGraphique($p_factures) { $data = [ 'AUX' => ['color' => [255, 0, 0], 'value' => 0], 'BIO' => ['color' => [255, 255, 0], 'value' => 0], 'CON' => ['color' => [50, 0, 255], 'value' => 0], 'DEN' => ['color' => [255, 0, 255], 'value' => 0], 'EXA' => ['color' => [0, 255, 0], 'value' => 0], 'HOS' => ['color' => [200, 255, 100], 'value' => 0], 'IMA' => ['color' => [121, 248, 248], 'value' => 0], 'MAT' => ['color' => [121, 210, 180], 'value' => 0], 'OPT' => ['color' => [221, 248, 248], 'value' => 0], 'PHA' => ['color' => [0, 100, 108], 'value' => 0] ]; foreach ($p_factures as $facture) { $code = $facture['codeGarantie']; if (isset($data[$code])) { $data[$code]['value'] = $facture['Taux']; } } return $data; } private function dessinerGraphique($data) { $chartX = 15; $chartY = $this->pdf->GetY() + 10; // Vérifier l'espace pour le graphique (hauteur approximative 120) $this->ajouterNouvellePageSiNecessaire(120); // Redéfinir chartY si une nouvelle page a été ajoutée if ($this->pdf->PageNo() > 1) { $chartY = 20; } // Dimensions $chartWidth = 180; $chartHeight = 100; // Padding $chartTopPadding = 12; $chartLeftPadding = 20; $chartBottomPadding = 10; $chartRightPadding = 5; // Chart box $chartBoxX = $chartX + $chartLeftPadding; $chartBoxY = $chartY + $chartTopPadding; $chartBoxWidth = $chartWidth - $chartLeftPadding - $chartRightPadding; $chartBoxHeight = $chartHeight - $chartBottomPadding - $chartTopPadding; // Bar width $barWidth = 8; $dataMax = 0; foreach ($data as $item) { if ($item['value'] > $dataMax) { $dataMax = $item['value']; } } // Data step if ($dataMax > 200 && $dataMax < 600) { $dataStep = 20; } elseif ($dataMax < 200) { $dataStep = 10; } else { $dataStep = 100; } // Set font, line width and color $this->pdf->SetFont('Arial', '', 8); $this->pdf->SetLineWidth(0.1); $this->pdf->SetDrawColor(0); // Chart boundary $this->pdf->Rect($chartX, $chartY, $chartWidth, $chartHeight); // Vertical axis line $this->pdf->Line($chartBoxX, $chartBoxY, $chartBoxX, ($chartBoxY + $chartBoxHeight)); // Horizontal axis line $this->pdf->Line($chartBoxX - 2, ($chartBoxY + $chartBoxHeight), $chartBoxX + $chartBoxWidth, ($chartBoxY + $chartBoxHeight)); // Vertical axis $yAxisUnits = $dataMax > 0 ? $chartBoxHeight / $dataMax : 0; // Draw the vertical (y) axis labels for ($i = 0; $i <= $dataMax; $i += $dataStep) { $yAxisPos = $chartBoxY + ($yAxisUnits * $i); $this->pdf->Line($chartBoxX - 2, $yAxisPos, $chartBoxX, $yAxisPos); $this->pdf->SetXY($chartBoxX - $chartLeftPadding, $yAxisPos - 2); $this->pdf->Cell($chartLeftPadding - 4, 5, $dataMax - $i, 0, 0, 'R'); } // Horizontal axis $this->pdf->SetXY($chartBoxX, $chartBoxY + $chartBoxHeight); $xLabelWidth = $chartBoxWidth / count($data); $barXPos = 0; foreach ($data as $itemName => $item) { $this->pdf->Cell($xLabelWidth, 5, $itemName, 0, 0, 'C'); // Drawing the bar $this->pdf->SetFillColor($item['color'][0], $item['color'][1], $item['color'][2]); $barHeight = $yAxisUnits * $item['value']; $barX = ($xLabelWidth / 2) + ($xLabelWidth * $barXPos) - ($barWidth / 2) + $chartBoxX; $barY = $chartBoxHeight - $barHeight + $chartBoxY; $this->pdf->Rect($barX, $barY, $barWidth, $barHeight, 'DF'); $barXPos++; } // Axis labels $this->pdf->SetFont('Arial', 'B', 9); $this->pdf->SetXY($chartX, $chartY); $this->pdf->Cell(30, 10, "Taux", 0); $this->pdf->SetXY(($chartWidth / 2) - 50 + $chartX, $chartY + $chartHeight - ($chartBottomPadding / 2)); $this->pdf->Cell(100, 5, convertirc(_("Récapitulatif des dépenses par famille d'acte")), 0, 0, 'C'); } public function index() { try { $idPolice = $this->requete->getParametreFormulaire("idPolice"); $debutStat = $this->requete->getParametreDate("debutStat"); $finStat = $this->requete->getParametreDate("finStat"); $codeGcAssureur = $this->requete->getParametreFormulaire("codeGcAssureur"); // Vérification des données avant création PDF $this->verifierDonnees($idPolice, $debutStat, $finStat); if ($idPolice == '') { $idPolice = null; } $_SESSION['debutStat'] = $debutStat; $_SESSION['finStat'] = $finStat; $entete = $this->detailsp->detailrapportspperiodepdfentete($idPolice); // Vérification des données d'entête if (empty($entete)) { throw new Exception(_("Aucune donnée disponible pour cette police")); } $p_datedebut = $_SESSION['debutStat']; $p_datefin = $_SESSION['finStat']; $p_garant = $codeGcAssureur; $p_id = $idPolice; $p_id_college = null; $p_id_clients = null; $p_factures = $this->detailsp->etatrecapdepensesparfamilledactesmedicaux( $p_garant, $p_id_clients, $p_id, $p_id_college, $p_datedebut, $p_datefin ); // Vérification des données statistiques if (empty($p_factures)) { throw new Exception(_("Aucune donnée statistique disponible pour cette période")); } // Initialisation du PDF avec la classe étendue $this->pdf = new PDFWithFooter(); $this->pdf->AliasNbPages(); $this->pdf->AddPage(); $this->pdf->SetMargins(10, 10, 10); // Entête du document $this->pdf->Image($_SESSION['lienLogo'], 94, 3, 15); $this->pdf->SetFont('Arial', 'B', 7); $this->pdf->Cell(0, 5, convertirc(_('FICHE TECHNIQUE No 8')), 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 RECAPITULATIF DES DEPENSES PAR FAMILLE D'ACTES MEDICAUX")), 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, 5, convertirc(_('PERIODE COMPTABLE CONSIDEREE') . ': ' . dateLang($debutStat, $_SESSION['lang']) . ' ' . _('AU') . ' ' . dateLang($finStat, $_SESSION['lang'])), 0, 1, 'C', false); if ($p_id != 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->Ln(8); $this->pdf->Ln(2); // Vérifier l'espace pour le tableau avant de le dessiner $hauteurTableau = count($p_factures) * 6 + 20; // Estimation $this->ajouterNouvellePageSiNecessaire($hauteurTableau); // Tableau des données $hl = 6; $this->pdf->SetFont('Arial', 'B', 8); $this->pdf->SetFillColor(182,216,242); $this->pdf->Cell(15, $hl, convertirc(_('Code')), 1, 0, 'C', true); $this->pdf->Cell(80, $hl, convertirc(_("Libellé")), 1, 0, 'C', true); $this->pdf->Cell(20, $hl, convertirc(_("Quantité")), 1, 0, 'C', true); $this->pdf->Cell(30, $hl, convertirc(_("Montant Remboursé")), 1, 0, 'C', true); $this->pdf->Cell(25, $hl, convertirc(_("Coét Moyen")), 1, 0, 'C', true); $this->pdf->Cell(20, $hl, convertirc(_("Taux")), 1, 1, 'C', true); $this->pdf->SetFont('Arial', '', 9); $total_quantite = 0; $total_montantrembourse = 0; $total_taux = 0; foreach ($p_factures as $p_facture) { // Vérifier l'espace pour chaque ligne if (!$this->verifierEspacePage(6)) { $this->pdf->AddPage(); } $this->pdf->Cell(15, $hl, convertirc($p_facture['codeGarantie']), 1, 0, 'L', false); $this->pdf->Cell(80, $hl, convertirc($p_facture['libelle']), 1, 0, 'L', false); $this->pdf->Cell(20, $hl, convertirc(format_N($p_facture['Quantite'])), 1, 0, 'C', false); $this->pdf->Cell(30, $hl, convertirc(format_N($p_facture['MontantRembourse'])), 1, 0, 'R', false); $this->pdf->Cell(25, $hl, convertirc(format_N($p_facture['Coutmoyen'])), 1, 0, 'R', false); $this->pdf->Cell(20, $hl, convertirc($p_facture['Taux'] . " %"), 1, 1, 'C', false); $total_quantite += $p_facture['Quantite']; $total_montantrembourse += $p_facture['MontantRembourse']; $total_taux += $p_facture['Taux']; } // Ligne de total $hl = 8; $total_div = $total_quantite > 0 ? $total_montantrembourse / $total_quantite : 0; // Vérifier l'espace pour la ligne de total $this->ajouterNouvellePageSiNecessaire(8); $this->pdf->SetFont('Arial', 'B', 9); $this->pdf->SetFillColor(182,216,242); $this->pdf->Cell(95, $hl, convertirc(_('TOTAL')), 1, 0, 'C', true); $this->pdf->Cell(20, $hl, convertirc(format_N($total_quantite)), 1, 0, 'C', true); $this->pdf->Cell(30, $hl, convertirc(format_N($total_montantrembourse)), 1, 0, 'C', true); $this->pdf->Cell(25, $hl, convertirc(format_N($total_div)), 1, 0, 'C', true); $this->pdf->Cell(20, $hl, convertirc(format_N($total_taux) . " %"), 1, 1, 'C', true); // Préparer et dessiner le graphique $dataGraphique = $this->preparerDonneesGraphique($p_factures); $this->dessinerGraphique($dataGraphique); // Génération du fichier PDF $fichier = "Temp/TMP_CUMUL_SP_FICHE8" . "_" . uniqid() . ".pdf"; $this->pdf->Output($fichier, "F"); // Lien de téléchargement $t_html = '