* * @author Anna Larch * @author Richard Steinmetz * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see . * */ namespace OCA\Gestion\Service\Certificate\PdfHandler; use DateTime; use FPDF; use OCA\Gestion\Helpers\DateHelpers; use OCA\Gestion\Helpers\FileExportHelpers; use OCA\Gestion\Helpers\PriceHelpers; class PacemakerAbsentCertificatePdfHandler extends FPDF { private $devisOfDefunt = []; private $logo = null; private $signatureImageExist = false; private $tamponImageExist = false; private $imagePath = "/var/www/html/data/admin/files/.gestion/"; public function Header() { if ($this->logo != "nothing") { $this->Image($this->imagePath . "logo.png", 10, 10, 50, 35); } // En-tête avec les informations de l'entreprise - SOUS le logo $this->SetXY(10, 50); // Position sous le logo $this->SetFont('Arial', 'B', 12); $this->Cell(0, 5, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->entreprise), 0, 1); $this->SetFont('Arial', '', 10); $this->MultiCell(0, 4, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->adresse), 0, 'L'); if (isset($this->devisOfDefunt['configuration']->telephone)) { $this->Cell(0, 4, 'Tel : ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->telephone), 0, 1); } if (isset($this->devisOfDefunt['thanato_reference'])) { $this->Cell(0, 4, 'Habilitation : ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['thanato_reference']), 0, 1); } if (isset($this->devisOfDefunt['configuration']->siret)) { $this->Cell(0, 4, 'Siret : ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->siret), 0, 1); } } public function Footer() { $this->SetY(-15); $this->MultiCell(0, 5, utf8_decode(html_entity_decode($this->devisOfDefunt['configuration']->legal_one)), 0, 'C'); $this->MultiCell(0, 5, utf8_decode(html_entity_decode($this->devisOfDefunt['configuration']->adresse)), 0, 'C'); } public function SetPacemakerCertificateData(array $devisOfDefunt, $logo = null, $signatureImageExist = false, $tamponImageExist = false) { $this->devisOfDefunt = $devisOfDefunt; $this->logo = $logo; $this->signatureImageExist = $signatureImageExist; $this->tamponImageExist = $tamponImageExist; } public function SetPacemakerCertificate() { $this->AddPage(); $this->SetMargins(left: 20, top: 0, right: 20); $this->SetPacemakerCertificateTitle(); $this->SetPacemakerCertificateContent(); } private function SetPacemakerCertificateContent() { $this->SetY(100); // Position réduite après le titre $this->SetFont('Arial', '', 12); // Déterminer le genre selon la civilité $civilite = isset($this->devisOfDefunt['thanato_civilite']) ? $this->devisOfDefunt['thanato_civilite'] : 'Madame'; $pronom = 'Je soussignée'; $profession = 'thanatopractrice diplômée'; // Adaptation selon la civilité if (strtolower($civilite) === 'monsieur' || strtolower($civilite) === 'm.' || strtolower($civilite) === 'mr') { $pronom = 'Je soussigné'; $profession = 'thanatopracteur diplômé'; } // Texte principal avec genre adapté $mainText = $pronom . ', ' . $civilite . ' ' . mb_convert_encoding($this->devisOfDefunt['thanato_prenom'], 'ISO-8859-1', 'UTF-8'). ' ' .mb_convert_encoding($this->devisOfDefunt['thanato_nom'], 'ISO-8859-1', 'UTF-8'). ', ' . $profession . ', certifie ne pas avoir constaté, à la palpation, la présence d\'un pacemaker pour :'; $this->MultiCell(0, 6, FileExportHelpers::FormatTextForExport($mainText)); $this->Ln(8); // Nom du défunt $this->SetFont('Arial', 'B', 12); $this->Cell(20, 8, 'Nom :', 0, 0); $this->SetFont('Arial', '', 12); $this->Cell(0, 8, FileExportHelpers::FormatTextForExport(mb_convert_encoding($this->devisOfDefunt['defunt_nom'], 'ISO-8859-1', 'UTF-8')), 0, 1); $this->Ln(3); // Date $this->SetFont('Arial', 'B', 12); $this->Cell(20, 8, 'Date :', 0, 0); $this->SetFont('Arial', '', 12); if (isset($this->devisOfDefunt['devis_date'])) { $this->Cell(0, 8, $this->devisOfDefunt['devis_date']->format('d/m/Y'), 0, 1); } else { $this->Cell(0, 8, '', 0, 1); } $this->Ln(3); // Lieu d'intervention $this->SetFont('Arial', 'B', 12); $this->Cell(40, 8, 'Lieu d\'intervention :', 0, 0); $this->SetFont('Arial', '', 12); $lieu = isset($this->devisOfDefunt['lieu_intervention']) ? $this->devisOfDefunt['lieu_intervention'] : $this->devisOfDefunt['location_of_devis']; // Utiliser MultiCell pour permettre le retour à la ligne $this->SetX(20); // Retour au début de la ligne $this->SetFont('Arial', 'B', 12); $this->Cell(40, 8, 'Lieu d\'intervention :', 0, 1); // 1 pour aller à la ligne suivante $this->SetFont('Arial', '', 12); $this->MultiCell(0, 6, FileExportHelpers::FormatTextForExport($lieu), 0, 'L'); // Signatures et cachet - juste après le lieu d'intervention $this->Ln(15); // Petit espace après le lieu d'intervention if ($this->signatureImageExist) { $this->Image($this->imagePath."sign.png", 140, $this->GetY(), 40, 16); } if($this->tamponImageExist) { $this->SetXY(120, $this->GetY() + 20); // Augmenté de 5 à 20 pour plus d'espace $this->Image($this->imagePath."sign.jpg", 120, $this->GetY(), 80, 35); } } private function SetPacemakerCertificateTitle() { $this->SetY(y: 85); // Titre plus bas pour éviter l'en-tête $this->SetFont('Arial', 'B', 16); $this->Cell(0, 10, FileExportHelpers::FormatTextForExport('ATTESTATION D\'ABSENCE DE PACEMAKER'), 0, 1, 'C'); $this->Ln(5); // Espace réduit après le titre } public function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false) { // Store reset values for (x,y) positions $x = $this->GetX() + $w; $y = $this->GetY(); // Make a call to FPDF's MultiCell $this->MultiCell($w, $h, $text, $border, $align, $fill); // Reset the line position to the right, like in Cell if ($ln == 0) { $this->SetXY($x, $y); } } public function NbLines($w, $txt) { // Compute the number of lines a MultiCell of width w will take if (!isset($this->CurrentFont)) { $this->Error('No font has been set'); } $cw = $this->CurrentFont['cw']; if ($w == 0) { $w = $this->w - $this->rMargin - $this->x; } $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; $s = str_replace("\r", '', (string) $txt); $nb = strlen($s); if ($nb > 0 && $s[$nb - 1] == "\n") { $nb--; } $sep = -1; $i = 0; $j = 0; $l = 0; $nl = 1; while ($i < $nb) { $c = $s[$i]; if ($c == "\n") { $i++; $sep = -1; $j = $i; $l = 0; $nl++; continue; } if ($c == ' ') { $sep = $i; } $l += $cw[$c]; if ($l > $wmax) { if ($sep == -1) { if ($i == $j) { $i++; } } else { $i = $sep + 1; } $sep = -1; $j = $i; $l = 0; $nl++; } else { $i++; } } return $nl; } }