production/Controleur/ControleurAjaxstatsmaladiefichetechniqueseptpdf.php
2025-12-02 11:29:44 +00:00

292 lines
14 KiB
PHP
Executable File

<?php
require_once 'Framework/Controleurrequete.php';
require_once 'Modele/Statistique.php';
// Création d'une classe FPDF étendue pour gérer le footer
class PDFWithFooter extends FPDF {
function Footer() {
$this->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 ControleurAjaxstatsmaladiefichetechniqueseptpdf extends Controleur
{
private $detailsp;
private $pdf;
private $maxLinesPerPage = 25; // Nombre maximum de lignes par page
public function __construct() {
$this->detailsp = new Statistique();
}
// Méthode Footer pour la numérotation des pages
private function addFooter() {
$this->pdf->SetY(-15);
$this->pdf->SetFont('Arial', 'I', 8);
$this->pdf->Cell(0, 10, 'Page ' . $this->pdf->PageNo() . '/{nb}', 0, 0, 'C');
}
// Méthode pour vérifier si on doit ajouter une nouvelle page
private function checkPageBreak($currentLine, $lineHeight = 7) {
// Vérifier le nombre maximum de lignes par page
if ($currentLine >= $this->maxLinesPerPage) {
$this->addNewPage();
return true;
}
// Vérifier si on dépasse la hauteur de page (marge basse incluse)
$yPosition = $this->pdf->GetY();
if ($yPosition + $lineHeight > 280) { // 297mm - marge basse
$this->addNewPage();
return true;
}
return false;
}
// Méthode pour ajouter une nouvelle page avec en-tête
private function addNewPage() {
$this->pdf->AddPage('L');
// Réafficher l'en-tête du tableau sur les nouvelles pages
$this->displayTableHeader();
}
// Méthode pour afficher l'en-tête du tableau
private function displayTableHeader() {
$hl = 7;
$this->pdf->SetFont('Arial', '', 7);
$this->pdf->SetFillColor(182, 216, 242);
$this->pdf->Cell(15, $hl, convertirc(_('Matricule')), 1, 0, 'C', true);
$this->pdf->Cell(60, $hl, convertirc(_("Famille")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Janvier")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Février")), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, convertirc(_("Mars")), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, convertirc(_("Avril")), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, convertirc(_("Mai")), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, convertirc(_("Juin")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Juillet")), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, convertirc(_("Août")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Septembre")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Octobre")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Novembre")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Décembre")), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, convertirc(_("Totaux")), 1, 1, 'C', true);
}
// Méthode pour créer l'en-tête du document
private function createDocumentHeader($entete, $debutStat, $finStat, $depenses, $idPolice, $codeGcAssureur) {
$this->pdf->SetMargins(10, 10, 10);
$this->pdf->Image($_SESSION['lienLogo'], 140, 3, 15);
$this->pdf->SetFont('Arial', 'B', 7);
$this->pdf->Cell(0, 5, convertirc(_('FICHE TECHNIQUE No 7')), 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(_("EVOLUTION MENSUELLE DES DEPENSES PAR FAMILLE D'ASSURE")), 1, 0, 'C', true);
$this->pdf->Ln(8);
$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(8);
$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(8);
$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($codeGcAssureur), 0, 1, 'L', false);
}
$this->pdf->Ln(4);
$this->pdf->SetX(65);
$this->pdf->Cell(170, 6, convertirc(_('DEPENSES SUPERIEURES A') . ': ' . format_N($depenses) . ' ' . $_SESSION['devise_C']), 1, 1, 'C', false);
$this->pdf->Ln(2);
}
public function index()
{
// Vérification 1: Données de base nécessaires
$idPolice = $this->requete->getParametreFormulaire("idPolice");
$debutStat = $this->requete->getParametreDate("debutStat");
$finStat = $this->requete->getParametreDate("finStat");
$depenses = $this->requete->getParametreFormulaire("depenses", "numerique");
if ($idPolice == '') {
$idPolice = null;
}
// Vérification des données avant création PDF
if (empty($debutStat) || empty($finStat) || empty($idPolice)) {
echo '<div class="alert alert-warning">' . _("Paramètres de filtrage incomplets") . '</div>';
return;
}
// Vérification des dates
if ($debutStat > $finStat) {
echo '<div class="alert alert-warning">' . _("La date de début doit être antérieure à la date de fin") . '</div>';
return;
}
$_SESSION['debutStat'] = $debutStat;
$_SESSION['finStat'] = $finStat;
$_SESSION['depenses'] = $depenses;
$codeGcAssureur = $this->requete->getParametreFormulaire("codeGcAssureur");
$entete = $this->detailsp->detailrapportspperiodepdfentete($idPolice);
// Vérification des données d'entête
if (empty($entete)) {
echo '<div class="alert alert-warning">' . _("Aucune donnée disponible pour cette police") . '</div>';
return;
}
$primeSinistre = $this->detailsp->getprimesinistre($idPolice, $debutStat, $finStat);
// Vérification des données statistiques
if (empty($primeSinistre)) {
echo '<div class="alert alert-warning">' . _("Aucune donnée statistique disponible pour cette période") . '</div>';
return;
}
$p_datedebut = $_SESSION['debutStat'];
$p_datefin = $_SESSION['finStat'];
$p_garant = $codeGcAssureur;
$p_limite = $_SESSION['depenses'];
$p_id_client = null;
$p_id_college = null;
$p_id = $idPolice;
$p_factures = $this->detailsp->evolutiondepfamilleAssrp($p_garant, $p_id_client, $p_id, $p_id_college, $p_datedebut, $p_datefin, $p_limite);
// Vérification du nombre de données avant génération
if (empty($p_factures)) {
echo '<div class="alert alert-warning">' . _("Aucune donnée à afficher pour les critères sélectionnés") . '</div>';
return;
}
// Initialisation du PDF avec footer personnalisé
$this->pdf = new PDFWithFooter();
$this->pdf->AliasNbPages();
$this->pdf->AddPage('L');
// Création de l'en-tête du document
$this->createDocumentHeader($entete, $debutStat, $finStat, $depenses, $idPolice, $codeGcAssureur);
// Affichage de l'en-tête du tableau
$this->displayTableHeader();
// Variables pour les totaux
$total_JANVIER = $total_FEVRIER = $total_MARS = $total_AVRIL = $total_MAI = $total_JUIN = 0;
$total_JUILLET = $total_AOUT = $total_SEPTEMBRE = $total_OCTOBRE = $total_NOVEMBRE = $total_DECEMBRE = $total_TOTAUX = 0;
$hl = 7;
$lineCount = 0;
foreach ($p_factures as $dep) {
$lineCount++;
// Vérification avant d'ajouter une page
$this->checkPageBreak($lineCount, $hl);
$this->pdf->Cell(15, $hl, convertirc($dep['numeroAdherent']), 1, 0, 'C', false);
$this->pdf->Cell(60, $hl, convertirc(substr($dep['adherent'],0,35)), 1, 0, 'L', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['JANVIER'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['FEVRIER'])), 1, 0, 'C', false);
$this->pdf->Cell(15, $hl, convertirc(format_N($dep['MARS'])), 1, 0, 'C', false);
$this->pdf->Cell(15, $hl, convertirc(format_N($dep['AVRIL'])), 1, 0, 'C', false);
$this->pdf->Cell(15, $hl, convertirc(format_N($dep['MAI'])), 1, 0, 'C', false);
$this->pdf->Cell(15, $hl, convertirc(format_N($dep['JUIN'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['JUILLET'])), 1, 0, 'C', false);
$this->pdf->Cell(15, $hl, convertirc(format_N($dep['AOUT'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['SEPTEMBRE'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['OCTOBRE'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['NOVEMBRE'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['DECEMBRE'])), 1, 0, 'C', false);
$this->pdf->Cell(16, $hl, convertirc(format_N($dep['TOTAUX'])), 1, 1, 'C', false);
// Calcul des totaux
$total_JANVIER += $dep['JANVIER'];
$total_FEVRIER += $dep['FEVRIER'];
$total_MARS += $dep['MARS'];
$total_AVRIL += $dep['AVRIL'];
$total_MAI += $dep['MAI'];
$total_JUIN += $dep['JUIN'];
$total_JUILLET += $dep['JUILLET'];
$total_AOUT += $dep['AOUT'];
$total_SEPTEMBRE += $dep['SEPTEMBRE'];
$total_OCTOBRE += $dep['OCTOBRE'];
$total_NOVEMBRE += $dep['NOVEMBRE'];
$total_DECEMBRE += $dep['DECEMBRE'];
$total_TOTAUX += $dep['TOTAUX'];
}
// Vérification avant d'ajouter les totaux
$this->checkPageBreak($lineCount + 2, $hl);
// Affichage des totaux
$this->pdf->SetFont('Arial', 'B', 8);
$this->pdf->SetFillColor(182, 216, 242);
$this->pdf->Cell(75, $hl, convertirc("TOTAL GENERAL"), "1", 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_JANVIER), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_FEVRIER), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, format_N($total_MARS), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, format_N($total_AVRIL), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, format_N($total_MAI), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, format_N($total_JUIN), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_JUILLET), 1, 0, 'C', true);
$this->pdf->Cell(15, $hl, format_N($total_AOUT), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_SEPTEMBRE), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_OCTOBRE), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_NOVEMBRE), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_DECEMBRE), 1, 0, 'C', true);
$this->pdf->Cell(16, $hl, format_N($total_TOTAUX), 1, 1, 'C', true);
$this->pdf->Ln(5);
$this->pdf->Cell(45, $hl, convertirc(_("Nombre de lignes: ") . count($p_factures)), 0, 0, 'L', false);
$fichier = "Temp/TMP_CUMUL_SP_FICHE7" . "_" . uniqid() . ".pdf";
$this->pdf->Output($fichier, "F");
$t_html = '<div id="div_export_b" class="alert alert-info">';
$t_html .= '<a style="font-size:15pt;" href="' . $fichier . '" target="_blank">' . _("TELECHARGER FICHE 07") . '</a>';
$t_html .= '</div>';
echo $t_html;
}
}