* * @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 CareCertificatePdfHandler extends FPDF { private $devisOfDefunt = []; private $logo = null; private $signatureImageExist = false; private $imagePath = "/var/www/html/data/admin/files/.gestion/"; function Header() { if($this->logo != "nothing"){ $this->Image($this->imagePath."logo.png", 10, 10, 85, 25); } else{ $this->Cell(55,30,''); } } function Footer() { $this->SetY(-18); $this->SetFont('ComicSans', '', 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 SetCareCertificateData(array $devisOfDefunt,$logo = null,$signatureImageExist = false){ $this->devisOfDefunt = $devisOfDefunt; $this->logo = $logo; $this->signatureImageExist = $signatureImageExist; } public function SetCareCertificate(){ $this->AddPage(); $this->SetMargins(left:20,top:0,right:20); $this->SetCareCertificateTitle(); $this->SetCareCertificateContent(); $this->SetSigning(); } private function SetSigning(){ $this->SetXY(140,$this->GetY() + 15); $this->Cell(0,10,'Cachet et signature'); if($this->signatureImageExist){ $this->Image($this->imagePath."sign.png", 135, $this->GetY() + 12, 60, 40); } } private function SetCareCertificateContent(){ $this->SetFont('ComicSans', '', 14); $this->Cell(0,7,FileExportHelpers::FormatTextForExport('La Société '. $this->devisOfDefunt['configuration']->entreprise. ' habilitée sous le numéro ' . $this->devisOfDefunt['thanato_reference'] . ', certifie par '),0,1); $this->Cell(0,7,FileExportHelpers::FormatTextForExport('la présente que : '),0,1); $this->SetFont('ComicSans', 'B', 14); $this->Cell(0,12, 'Mr/Mme ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['thanato_nom'] . ' ' . $this->devisOfDefunt['thanato_prenom']),0,1); $this->SetFont('ComicSans', '', 14); $this->MultiCell(0,7, FileExportHelpers::FormatTextForExport('Employé(e) au sein de notre société et titulaire du diplôme national de Thanatopracteur, a effectué des soins de conservation sur le corps du défunt :')); $this->SetFont('ComicSans', 'B', 14); $this->Cell(0,12, 'Mr/Mme '.$this->devisOfDefunt['defunt_nom'],0,1); $this->SetFont('ComicSans', '', 14); $this->Cell(0,12, FileExportHelpers::FormatTextForExport("Qui reposait à l'adresse suivante") . ' : ',0,1); $this->SetFont('ComicSans', 'B', 14); $this->Cell(0,12, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['location_of_devis']),0,1); $this->SetFont('ComicSans', '', 14); $this->Cell(0,12, FileExportHelpers::FormatTextForExport("La présente attestion est établie pour faire valoir ce que de droit."),0,5); $this->Ln(5); $this->Cell(0,12,FileExportHelpers::FormatTextForExport('Fait à '). FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->adresse)); $this->SetX(140); $this->Cell(0,12,'le '. $this->devisOfDefunt['devis_date']->format('d/m/Y'),0); } private function SetCareCertificateTitle(){ $this->SetY(60); $this->SetFont('ComicSans', 'B', 20); $this->Cell(0, 10, 'ATTESTATION DE SOINS DE CONSERVATION', 0, 1,'C'); $this->Ln(20); } 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); } } 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; } }