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

257 lines
14 KiB
PHP
Executable File

<?php
require_once 'Framework/Controleurrequete.php';
require_once 'Modele/Statistique.php';
class ControleurAjaxstatsmaladiefichetechniquevingttroispdf extends Controleur
{
private $detailsp;
public function __construct() {
$this->detailsp = new Statistique();
}
public function index()
{
$codeGcAssureur = $this->requete->getParametreFormulaire("codeGcAssureur");
$idPolice = $this->requete->getParametreFormulaire("idPolice");
$debutStat = $this->requete->getParametreDate("debutStat");
$finStat = $this->requete->getParametreDate("finStat");
$Chargement = $this->requete->getParametreFormulaire("Chargement");
$_SESSION['debutStat'] = $debutStat;
$_SESSION['finStat'] = $finStat;
$p_datedebut = $_SESSION['debutStat'] ?? "";
$p_datefin = $_SESSION['finStat'] ?? "";
$p_garant = $codeGcAssureur;
if ($p_garant == "AUC") {
$p_garant = null;
}
$p_id = $idPolice;
if ($p_id == "") {
$p_id = null;
}
$idCollege = "";
$p_id_clients = null;
$p_id_college = null;
$p_code = 'QTM';
$p_taux = '18';
$recapresultattechniquesgarants = $this->detailsp->getrecapresultattechniquesgarantspolice($p_garant, $p_id_clients, $p_id, $p_id_college, $p_datedebut, $p_datefin, $p_code);
// Initialisation des variables TOTAL
$TOTALrapportSpanTotalG = 0;
$TOTALmontantnbre_policeG = 0;
$TOTALmontantApayerTotalG = 0;
$TOTALprimeAnalyseTotalG = 0;
$TOTALprimeAnnuelleTotalG = 0;
$TOTALrapportSpTotalG = 0.00;
$TOTALajustementSpG = 0.00;
$pdf = new FPDF_Protection();
$pdf->SetAuthor('EBENE SOLUTIONS INFORMATIQUES');
$userPassword = '';
$ownerPassword = null;
$pdf->SetProtection(['print'], $userPassword, $ownerPassword);
// Vérifier s'il y a des données avant de créer le PDF
if (empty($recapresultattechniquesgarants)) {
echo '<div class="alert alert-warning">' . _("Aucune donnée disponible pour les critères de filtrage") . '</div>';
return;
}
foreach ($recapresultattechniquesgarants as $recapresultattechniquesgarant) {
$p_garant = $recapresultattechniquesgarant['codeGcAssureur'];
$resultattechniques = $this->detailsp->getrecapresultattechniquespolice($p_garant, $p_id_clients, $p_id, $p_id_college, $p_datedebut, $p_datefin, $p_code, $Chargement);
// Vérifier s'il y a des données techniques avant d'ajouter une page
if (!empty($resultattechniques)) {
$pdf->AliasNbPages();
$pdf->AddPage('P', 'A4');
$pdf->SetMargins(10, 10, 10);
$pdf->Image($_SESSION['lienLogo'], 94, 3, 15);
$pdf->SetFont('Arial', 'B', 7);
$pdf->Cell(0, 5, '', 0, 1, 'L', false);
$pdf->SetY(10);
$pdf->SetFont('Arial', '', 7);
$pdf->Cell(0, 5, convertirc(_('Edition du') . ': ' . heureCouranteLang($_SESSION['lang'])), 0, 1, 'R', false);
$pdf->Ln(2);
$pdf->SetFont('Arial', 'B', 13);
$resultattechnique = "";
$pdf->SetFillColor(144, 238, 144);
$pdf->Cell(0, 8, convertirc(_("RAPPORT SINISTRES / PRIMES (R. S/P)")), 1, 0, 'C', true);
$pdf->Ln(10);
$pdf->SetFont('Arial', 'B', 11);
$pdf->SetTextColor(0);
$pdf->Ln(8);
$pdf->Cell(0, 8, convertirc(_('PERIODE CONSIDEREE') . ': ' . dateLang($debutStat, $_SESSION['lang']) . ' ' . _('AU') . ' ' . dateLang($finStat, $_SESSION['lang'])), 1, 1, 'C', false);
$pdf->Ln(8);
$pdf->SetFont('Arial', 'BUI', 11);
$pdf->Cell(35, 8, convertirc(_('COMPAGNIE') . ': '), 0, 0, 'L', false);
$pdf->SetFont('Arial', 'BI', 11);
$pdf->Cell(25, 8, convertirc(_($recapresultattechniquesgarant['codeGcAssureur'])), 0, 0, 'L', false);
$pdf->Cell(0, 8, convertirc('/ ' . $recapresultattechniquesgarant['GARANT']), 0, 1, 'L', false);
$pdf->Ln(2);
$pdf->Cell(0, 8, convertirc(_('CHARGEMENT') . ' : ' . $Chargement . ' %'), 0, 1, 'L', false);
$pdf->Ln(5);
$hl = 4;
$pdf->SetFont('Arial', 'B', 8);
$pdf->Cell(15, $hl, convertirc(_("NO Police")), 'LTR', 0, 'C', true);
$pdf->Cell(82, $hl, convertirc(_('Police')), 'LTR', 0, 'C', true);
$pdf->Cell(22, $hl, convertirc(_("Sinistre")), 'LTR', 0, 'C', true);
$pdf->Cell(22, $hl, convertirc(_("Prime nette")), 'LTR', 0, 'C', true);
$pdf->Cell(22, $hl, convertirc(_("Prime nette")), 'LTR', 0, 'C', true);
$pdf->Cell(15, $hl, convertirc(_("Rapp. S/P")), 'LTR', 0, 'C', true);
$pdf->Cell(15, $hl, convertirc(_("Rapp. S/P")), 'LTR', 1, 'C', true);
$hl = 4;
$pdf->SetFont('Arial', 'B', 8);
$pdf->Cell(15, $hl, convertirc(''), 'BLR', 0, 'C', true);
$pdf->Cell(82, $hl, convertirc(''), 'BLR', 0, 'C', true);
$pdf->Cell(22, $hl, convertirc(''), 'BLR', 0, 'C', true);
$pdf->Cell(22, $hl, convertirc(_("Période")), 'BLR', 0, 'C', true);
$pdf->Cell(22, $hl, convertirc(_("Annuelle")), 'BLR', 0, 'C', true);
$pdf->Cell(15, $hl, convertirc(_("Période")), 'BLR', 0, 'C', true);
$pdf->Cell(15, $hl, convertirc(_("Annuel")), 'BLR', 1, 'C', true);
$pdf->SetFont('Arial', '', 8);
// Initialisation des totaux pour chaque garant
$TOTALrapportSpanTotal = 0;
$TOTALmontantnbre_police = 0;
$TOTALmontantApayerTotal = 0;
$TOTALprimeAnalyseTotal = 0;
$TOTALprimeAnnuelleTotal = 0;
$TOTALrapportSpTotal = 0.00;
$TOTALajustementSp = 0.00;
foreach ($resultattechniques as $resultattechnique) {
$taillelibelle = strlen($resultattechnique['libellePolice']);
if ($taillelibelle > 58) {
$hl = 5;
$text = wordwrap($resultattechnique['libellePolice'], 45, "***", false);
$tcut = explode("***", $text);
$part1 = $tcut[0];
$part2 = '';
for ($i = 1; $i < count($tcut); $i++) {
$part2 .= $tcut[$i] . ' ';
}
$part2 = trim($part2);
$pdf->SetFont('Arial', '', 7);
$pdf->Cell(15, $hl, convertirc(_($resultattechnique['numeroPolice'])), 'TLR', 0, 'C', false);
$pdf->Cell(82, $hl, convertirc(_($part1)), 'LTR', 0, 'L', false);
$pdf->Cell(22, $hl, convertirc(format_N($resultattechnique['sinistre'])), 'LTR', 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($resultattechnique['primeAnalyse'])), 'LTR', 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($resultattechnique['primeAnnuelle'])), 'LTR', 0, 'R', false);
$pdf->Cell(15, $hl, convertirc(number_format($resultattechnique['rapportSp'], 2)), 'LTR', 0, 'R', false);
if ($resultattechnique['rapportSpAn'] < 1) {
$pdf->Cell(15, $hl, convertirc(number_format($resultattechnique['rapportSpAn'], 2)), 'LTR', 1, 'R', false);
} else {
$pdf->Cell(15, $hl, convertirc("Résilier"), 'LTR', 1, 'R', false);
}
$pdf->Cell(15, $hl, convertirc(""), 'LBR', 0, 'C', false);
$pdf->Cell(82, $hl, convertirc(_($part2)), 'LBR', 0, 'L', false);
$pdf->Cell(22, $hl, convertirc(""), 'LBR', 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(""), 'LBR', 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(""), 'LBR', 0, 'R', false);
$pdf->Cell(15, $hl, convertirc(""), 'LBR', 0, 'R', false);
$pdf->Cell(15, $hl, convertirc(""), 'LBR', 1, 'R', false);
} else {
$hl = 7;
$pdf->SetFont('Arial', '', 7);
$pdf->Cell(15, $hl, convertirc(_($resultattechnique['numeroPolice'])), 1, 0, 'C', false);
$pdf->Cell(82, $hl, convertirc(_($resultattechnique['libellePolice'])), 1, 0, 'L', false);
$pdf->Cell(22, $hl, convertirc(format_N($resultattechnique['sinistre'])), 1, 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($resultattechnique['primeAnalyse'])), 1, 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($resultattechnique['primeAnnuelle'])), 1, 0, 'R', false);
$pdf->Cell(15, $hl, convertirc(number_format($resultattechnique['rapportSp'], 2)), 1, 0, 'R', false);
$pdf->Cell(15, $hl, convertirc(number_format($resultattechnique['rapportSpAn'], 2)), 1, 1, 'R', false);
}
$hl = 7;
// Accumulation des totaux pour le garant
$TOTALmontantApayerTotal += $resultattechnique['sinistre'];
$TOTALprimeAnalyseTotal += $resultattechnique['primeAnalyse'];
$TOTALprimeAnnuelleTotal += $resultattechnique['primeAnnuelle'];
// Calcul des ratios avec vérification division par zéro
$TOTALrapportSpanTotal = ($TOTALprimeAnnuelleTotal > 0)
? round(($TOTALmontantApayerTotal / $TOTALprimeAnnuelleTotal) * 100, 2)
: 0;
$TOTALrapportSpTotal = $resultattechnique['rspGarant'] ?? 0;
$TOTALajustementSp = $resultattechnique['tauxAjustementGarant'] ?? 0;
$pdf->SetFont('Arial', 'B', 8);
$pdf->SetTextColor(75, 0, 130);
$pdf->Cell(97, $hl, convertirc(_('TOTAL') . ' ' . $resultattechnique['codeGcAssureur']), 1, 0, 'L', false);
$pdf->Cell(22, $hl, convertirc(format_N($TOTALmontantApayerTotal)), 1, 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($TOTALprimeAnalyseTotal)), 1, 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($TOTALprimeAnnuelleTotal)), 1, 0, 'R', false);
$pdf->Cell(15, $hl, convertirc($TOTALrapportSpTotal), 1, 0, 'R', false);
$pdf->Cell(15, $hl, convertirc($TOTALrapportSpanTotal), 1, 1, 'R', false);
$pdf->SetTextColor(0, 0, 0);
// Accumulation des totaux généraux
$TOTALprimeAnalyseTotalG += $TOTALprimeAnalyseTotal;
$TOTALprimeAnnuelleTotalG += $TOTALprimeAnnuelleTotal;
$TOTALmontantApayerTotalG += $TOTALmontantApayerTotal;
}
}
}
// Vérifier si au moins une page a été ajoutée avant de continuer
if ($pdf->PageNo() > 0) {
$pdf->SetTextColor(0, 0, 0);
$pdf->Ln(5);
// Calcul des totaux généraux avec vérification division par zéro
$TOTALrapportSpanTotalG = ($TOTALprimeAnnuelleTotalG > 0)
? round(($TOTALmontantApayerTotalG / $TOTALprimeAnnuelleTotalG) * 100, 2)
: 0;
$pdf->SetFont('Arial', 'B', 8);
$pdf->SetTextColor(255, 0, 0);
$pdf->Cell(97, $hl, convertirc(_('TOTAL GENERAL')), 1, 0, 'L', false);
$pdf->Cell(22, $hl, convertirc(format_N($TOTALmontantApayerTotalG)), 1, 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($TOTALprimeAnalyseTotalG)), 1, 0, 'R', false);
$pdf->Cell(22, $hl, convertirc(format_N($TOTALprimeAnnuelleTotalG)), 1, 0, 'R', false);
$pdf->Cell(15, $hl, convertirc($TOTALrapportSpTotalG), 1, 0, 'R', false);
$pdf->Cell(15, $hl, convertirc($TOTALrapportSpanTotalG), 1, 1, 'R', false);
$pdf->SetFont('Arial', '', 8);
$pdf->SetTextColor(0, 0, 0);
$pdf->Ln(8);
$pdf->Cell(45, $hl, convertirc(_("# R/SP (%). = Rapport Sinitre Total / Prime Totale période")), 0, 0, 'L', false);
$pdf->Ln(5);
$fichier = "Temp/TMP_CUMUL_FT23_RAPPORT_SINISTRES_PRIMES" . "_" . uniqid() . ".pdf";
$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 ") . _(" FT23_RAPPORT_SINISTRES_PRIMES ") . '</a>';
$t_html .= '</div>';
echo $t_html;
} else {
echo '<div class="alert alert-warning">' . _("Aucune donnée disponible pour générer le rapport") . '</div>';
}
}
}