THANASOFT-HFC/gestion/lib/Service/Certificate/PdfHandler/CareCertificatePdfHandler.php

196 lines
7.0 KiB
PHP

<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
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 $tamponImageExist = false;
private $imagePath = "/var/www/html/data/admin/files/.gestion/";
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()
{
$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 SetCareCertificateData(array $devisOfDefunt, $logo = null, $signatureImageExist = false, $tamponImageExist = false)
{
$this->devisOfDefunt = $devisOfDefunt;
$this->logo = $logo;
$this->signatureImageExist = $signatureImageExist;
$this->tamponImageExist = $tamponImageExist;
}
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->tamponImageExist) {
$this->Image($this->imagePath."sign.jpg", 120, $this->GetY() + 8, 80, 35);
}
if($this->signatureImageExist) {
$this->Image($this->imagePath."sign.png", 140, $this->GetY() + 40, 40, 16);
}
}
private function SetCareCertificateContent()
{
$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 effectué des soins de conservation 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->SetFont('Arial', '', 14);
$this->Cell(0, 12, FileExportHelpers::FormatTextForExport("La présente attestation est établie pour faire valoir ce que de droit."), 0, 5);
$this->Ln(5);
// $this->MultiAlignCell(120,7,FileExportHelpers::FormatTextForExport('Fait à '). FileExportHelpers::FormatTextForExport($this->devisOfDefunt['location_of_devis']),0);
// $this->SetX(140);
$this->Cell(0, 7, 'Fait le '. $this->devisOfDefunt['devis_date']->format('d/m/Y'), 0);
}
private function SetCareCertificateTitle()
{
$this->SetY(60);
$this->SetFont('Arial', 'B', 20);
$this->Cell(0, 10, 'ATTESTATION DE SOINS DE CONSERVATION', 0, 1, 'C');
$this->Ln(20);
}
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;
}
}