* * @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 PacemakerCertificatePdfHandler extends FPDF { private $devisOfDefunt = []; private $logo = null; private $signatureImageExist = false; private $imagePath = "/var/www/html/data/admin/files/.gestion/"; private $tamponImageExist = false; public function Header() { if ($this->logo != "nothing") { $this->Image($this->imagePath."logo.png", 4, 2, 40, 45); } else { $this->Cell(55, 30, ''); } } public function Footer() { // Augmenter l'espace pour le footer pour éviter les chevauchements $this->SetY(-18); $this->SetFont('Arial', '', 10); $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(); $this->SetSigning(); } private function SetSigning() { // Ajouter plus d'espace avant la signature et le tampon $this->Ln(5); // Ajouter de l'espace vertical // Calculer la position Y pour éviter le chevauchement avec le footer $maxY = $this->GetPageHeight() - 65; $currentY = $this->GetY(); // Si on est trop bas, ne pas dépasser la limite if ($currentY > $maxY) { $currentY = $maxY; } // Positionner le tampon if($this->tamponImageExist) { $this->Image($this->imagePath."sign.jpg", 120, $currentY, 80, 25); // Réduire la hauteur de 30 à 25 } // Positionner la signature sous le tampon if ($this->signatureImageExist) { $this->Image($this->imagePath."sign.png", 140, $currentY + 28, 40, 16); // Ajuster la position Y } } private function SetPacemakerCertificateContent() { $this->SetFont('Arial', '', 14); $this->MultiCell(0, 7, FileExportHelpers::FormatTextForExport('La Société ' . $this->devisOfDefunt['configuration']->entreprise . ' habilitée sous le numéro ' . $this->devisOfDefunt['thanato_reference'] . ', certifie par la présente que : ')); $this->SetFont('Arial', 'B', 14); $this->Cell(0, 12, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['thanato_nom'] . ' ' . $this->devisOfDefunt['thanato_prenom']), 0, 1); $this->SetFont('Arial', '', 14); $this->MultiCell(0, 7, FileExportHelpers::FormatTextForExport('Employé(e) au sein de notre société et titulaire du diplôme national de Thanatopracteur, a retiré ce jour, la prothèse fonctionnant à pile implantée sur le corps du défunt :')); $this->SetFont('Arial', 'B', 14); $this->Cell(0, 12, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['defunt_nom']), 0, 1); $this->SetFont('Arial', '', 14); $this->Cell(0, 12, FileExportHelpers::FormatTextForExport("Date du décès") . ' : ' . $this->devisOfDefunt['defunt_date'], 0, 1); $this->SetFont('Arial', '', 14); $this->Cell(0, 12, FileExportHelpers::FormatTextForExport("Lieu du décès") . ' : ' . $this->devisOfDefunt['lieu_deces'], 0, 1); $this->SetFont('Arial', '', 14); $this->Cell(0, 12, FileExportHelpers::FormatTextForExport("Qui reposait à l'adresse suivante") . ' : ', 0, 1); $this->SetFont('Arial', 'B', 14); $this->MultiCell(0, 6, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['location_of_devis'])); $this->Ln(6); $this->SetFont('Arial', '', 14); $this->Cell( 0, 6, FileExportHelpers::FormatTextForExport("Numéro de série : ") . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['defunt_reference_pacemaker']), 0, 1 ); $this->Cell( 0, 6, FileExportHelpers::FormatTextForExport("Marque du produit : ") . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['defunt_product_brand']), 0, 1 ); $this->Cell(0, 12, FileExportHelpers::FormatTextForExport("La présente attestation est établie pour faire valoir ce que de droit."), 0, 1); $this->Ln(5); // Positionner "Fait le" de manière relative plutôt qu'absolue $this->SetX(140); $this->Cell(0, 7, 'Fait le ' . $this->devisOfDefunt['devis_date']->format('d/m/Y'), 0); } private function SetPacemakerCertificateTitle() { $this->SetY(y: 50); $this->SetFont('Arial', 'B', 15); $this->Cell(0, 10, 'ATTESTATION DE RECUPERATION DE', 0, 1, 'C'); $this->Cell(0, 10, 'PROTHESE FONCTIONNANT AU MOYEN D\'UNE PILE', 0, 1, 'C'); $this->SetFont('Arial', 'B', 12); $this->Cell(0, 10, '(dernier alinea de l\'article R.2213-15 du code des collectivites territoriales)', 0, 1, 'C'); $this->Ln(10); } 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; } }