wip pacemaker certificate

This commit is contained in:
Tiavina 2025-01-20 19:52:07 +03:00
parent 9f644a2ed0
commit deb5e13efb
4 changed files with 322 additions and 74 deletions

View File

@ -2251,97 +2251,97 @@ class PageController extends Controller {
* @NoCSRFRequired
* @param string $numdefunt
*/
public function saveAttestationPacemaker($numdefunt){
$defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
$date_deces = new DateTimeImmutable($defunt->date_defunt);
$date_naissance = new DateTimeImmutable($defunt->date_naissance);
$date_habilitation = new DateTimeImmutable($defunt->date_habilitation);
$today = new DateTimeImmutable();
// public function saveAttestationPacemaker($numdefunt){
// $defunt = json_decode($this->myDb->getOneDefunt($numdefunt, $this->idNextcloud))[0];
// $date_deces = new DateTimeImmutable($defunt->date_defunt);
// $date_naissance = new DateTimeImmutable($defunt->date_naissance);
// $date_habilitation = new DateTimeImmutable($defunt->date_habilitation);
// $today = new DateTimeImmutable();
$current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
if($defunt->id_devis != NULL) {
try {
$nomDefunt = $defunt->nom_defunt;
$folderDestination = html_entity_decode($current_config[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/ATTESTATION/';
try {
$this->storage->newFolder($folderDestination);
} catch(\OCP\Files\NotPermittedException $e) { }
// $current_config = json_decode($this->myDb->getConfiguration($this->idNextcloud));
// if($defunt->id_devis != NULL) {
// try {
// $nomDefunt = $defunt->nom_defunt;
// $folderDestination = html_entity_decode($current_config[0]->path).'/CLIENTS/'.strtoupper($defunt->entreprise).'/DEFUNTS/'.strtoupper($nomDefunt).'/ATTESTATION/';
// try {
// $this->storage->newFolder($folderDestination);
// } catch(\OCP\Files\NotPermittedException $e) { }
// TODO: init pdf
$pdf = new FPDF();
$pdf->AddPage();
// // TODO: init pdf
// $pdf = new FPDF();
// $pdf->AddPage();
// on sup les 2 cm en bas
$pdf->SetAutoPagebreak(True);
$pdf->SetMargins(0,0,0);
// // on sup les 2 cm en bas
// $pdf->SetAutoPagebreak(True);
// $pdf->SetMargins(0,0,0);
// logo : 80 de largeur et 55 de hauteur
$logo = $this->getLogo();
if($logo != 'nothing'){
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 20);
}
$pdf->SetY(55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(0, 10, "ATTESTATION", 0, 0, 'C');
// // logo : 80 de largeur et 55 de hauteur
// $logo = $this->getLogo();
// if($logo != 'nothing'){
// $pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 20);
// }
// $pdf->SetY(55); $pdf->SetFont('Arial', 'B', 15); $pdf->Cell(0, 10, "ATTESTATION", 0, 0, 'C');
$pdf->SetMargins(15,0,15);
// $pdf->SetMargins(15,0,15);
$pdf->SetY(80); $pdf->SetFont('Arial', '', 10);
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Je soussigné(e) ".$defunt->prenom_thanato." ".strtoupper($defunt->nom_thanato).", Thanatopracteur, agissant pour le compte de la société ".strtoupper($current_config[0]->entreprise)." titulaire de l'habilitation n°".$defunt->reference_habilitation." du ". $date_habilitation->format('d/m/Y') . " certifie avoir procédé au retrait du simulateur cardiaque ou de la prothèse fonctionnant au moyen d'une pile de référence : ".$defunt->ref_pacemaker." ainsi qu'à la reconstruction tégumentaire de :
".(strcmp($defunt->sexe, 'm')==0 ? 'Monsieur' : 'Madame').". ".$defunt->nom_defunt."
Date de naissance : ".$date_naissance->format('d/m/Y')."
Date de décès : ".utf8_decode($date_deces->format('d/m/Y')))), '','J',0);
// $pdf->SetY(80); $pdf->SetFont('Arial', '', 10);
// $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Je soussigné(e) ".$defunt->prenom_thanato." ".strtoupper($defunt->nom_thanato).", Thanatopracteur, agissant pour le compte de la société ".strtoupper($current_config[0]->entreprise)." titulaire de l'habilitation n°".$defunt->reference_habilitation." du ". $date_habilitation->format('d/m/Y') . " certifie avoir procédé au retrait du simulateur cardiaque ou de la prothèse fonctionnant au moyen d'une pile de référence : ".$defunt->ref_pacemaker." ainsi qu'à la reconstruction tégumentaire de :
// ".(strcmp($defunt->sexe, 'm')==0 ? 'Monsieur' : 'Madame').". ".$defunt->nom_defunt."
// Date de naissance : ".$date_naissance->format('d/m/Y')."
// Date de décès : ".utf8_decode($date_deces->format('d/m/Y')))), '','J',0);
$pdf->setY($pdf->GetY()+10);
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
$pdf->setY($pdf->GetY()+10);
// $pdf->setY($pdf->GetY()+10);
// $pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
// $pdf->setY($pdf->GetY()+10);
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Acte effectué à l'adresse suivante:
".$defunt->nom_lieu."
".$defunt->adresse_lieu)), '','J',0);
// $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Acte effectué à l'adresse suivante:
// ".$defunt->nom_lieu."
// ".$defunt->adresse_lieu)), '','J',0);
$pdf->setY($pdf->GetY()+10);
$pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
$pdf->setY($pdf->GetY()+10);
// $pdf->setY($pdf->GetY()+10);
// $pdf->Line(15, $pdf->GetY(), $pdf->GetPageWidth()-15, $pdf->GetY());
// $pdf->setY($pdf->GetY()+10);
$pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Cette attestation est remise pour faire valoir ce que de droit.
Fait à Saint Senoux le ".$today->format('d/m/Y'))), '','J',0);
// $pdf->MultiCell(0, 5, utf8_decode(html_entity_decode("Cette attestation est remise pour faire valoir ce que de droit.
// Fait à Saint Senoux le ".$today->format('d/m/Y'))), '','J',0);
$pdf->setY($pdf->GetY()+10);
// signature
$pdf->SetFont('Arial','',11);
$pdf->setY($pdf->GetY()+10);
$pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($current_config[0]->nom).' '.html_entity_decode($current_config[0]->prenom)), 0, 0, 'L');
$pdf->setY($pdf->GetY()+5);
// $pdf->setY($pdf->GetY()+10);
// // signature
// $pdf->SetFont('Arial','',11);
// $pdf->setY($pdf->GetY()+10);
// $pdf->Cell( $pdf->GetPageWidth()-30, 0, utf8_decode(html_entity_decode($current_config[0]->nom).' '.html_entity_decode($current_config[0]->prenom)), 0, 0, 'L');
// $pdf->setY($pdf->GetY()+5);
$signatureExist = $this->signatureImageExists('sign.png');
if($signatureExist){
$pdf->Image($this->defaultImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
}
// $signatureExist = $this->signatureImageExists('sign.png');
// if($signatureExist){
// $pdf->Image($this->defaultImagePath."sign.png", 15, $pdf->GetY(), 55, 30);
// }
$pdf->setY($pdf->GetY()-5);
$pdf->SetFont('Arial','',11); $pdf->Cell( $pdf->GetPageWidth()-80, 0, "Pour :", 0, 0, 'R');
// $pdf->setY($pdf->GetY()-5);
// $pdf->SetFont('Arial','',11); $pdf->Cell( $pdf->GetPageWidth()-80, 0, "Pour :", 0, 0, 'R');
// Positionnement à 1,5 cm du bas
$pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
$pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
// // Positionnement à 1,5 cm du bas
// $pdf->SetY(-30); $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_one))), '', 'C');
// $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->legal_two))), '', 'C');
// $pdf->SetFont('Arial', '', 8); $pdf->MultiCell($pdf->GetPageWidth()-30, 5, utf8_decode(html_entity_decode(iconv("UTF-8", "ISO-8859-1//TRANSLIT", $current_config[0]->telephone))), '', 'C');
$ff_pdf = $folderDestination.'ATTESTATION_PACEMAKER_'.strtoupper($nomDefunt).'.pdf';
$this->storage->newFile($ff_pdf);
$pdfContent = $pdf->Output('','S');
// $ff_pdf = $folderDestination.'ATTESTATION_PACEMAKER_'.strtoupper($nomDefunt).'.pdf';
// $this->storage->newFile($ff_pdf);
// $pdfContent = $pdf->Output('','S');
$file_pdf = $this->storage->get($ff_pdf);
$file_pdf->putContent($pdfContent);
// $file_pdf = $this->storage->get($ff_pdf);
// $file_pdf->putContent($pdfContent);
$res = array();
$res['path'] = $folderDestination;
return json_encode($res);
} catch(\OCP\Files\NotFoundException $e) {
return $e;
}
} else {
return false;
}
}
// $res = array();
// $res['path'] = $folderDestination;
// return json_encode($res);
// } catch(\OCP\Files\NotFoundException $e) {
// return $e;
// }
// } else {
// return false;
// }
// }
private function calculAge($dateNaissance) {
// Convertir la date de naissance en objet DateTime
@ -3072,4 +3072,19 @@ class PageController extends Controller {
public function createDefaultClientGroupFacturation(){
return $this->myDb->createDefaultClientGroup();
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function saveAttestationPacemaker($defuntId){
try{
$careCertificateFilename = $this->certificateService->generatePacemakerCertificate($defuntId,$this->idNextcloud);
return $careCertificateFilename;
}
catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -2996,6 +2996,7 @@ class Bdd {
lieu.adresse as lieu_adresse,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
defunt.ref_pacemaker as defunt_reference_pacemaker,
client.nom as client_nom,
client.prenom as client_prenom,
client.entreprise as client_entreprise,

View File

@ -31,6 +31,7 @@ use DateTimeImmutable;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Service\Certificate\PdfHandler\CareCertificatePdfHandler;
use OCA\Gestion\Service\Certificate\PdfHandler\PacemakerCertificatePdfHandler;
use OCP\Files\IRootFolder;
class CertificateService {
@ -134,4 +135,54 @@ class CertificateService {
return $filename;
}
private function getPacemakerCertificateFolder($devisOfDefunt){
$folder = 'CLIENTS/'
.strtoupper($devisOfDefunt["client_entreprise"])
.'/DEFUNTS/'
.strtoupper($devisOfDefunt["defunt_nom"]).'/'
.'ATTESTATION/';
return $folder;
}
private function getPacemakerCertificateFilename($devisOfDefunt){
$filename = 'ATTESTATION_PACEMAKER_'.strtoupper($devisOfDefunt['defunt_nom']);
return $filename;
}
public function generatePacemakerCertificate($defuntId,$idNextCloud){
$storage = $this->rootFolder->getUserFolder($idNextCloud);
$configs = json_decode($this->gestionBdd->getConfiguration(self::DEFAULT_NEXTCLOUD_ADMIN));
$currentConfig = $configs[0];
$logo = $this->getLogo();
$devisOfDefunt = $this->gestionBdd->getDevisOfDefunt($defuntId);
if($devisOfDefunt == null){
return null;
}
$devisOfDefunt["configuration"] = $currentConfig;
$devisOfDefunt["thanato_date_habilitation"] = new DateTimeImmutable($devisOfDefunt["thanato_date_habilitation"]);
$devisOfDefunt["devis_date"] = new DateTimeImmutable($devisOfDefunt["devis_date"]);
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
$pacemakerCertificateFolder = $this->getPacemakerCertificateFolder($devisOfDefunt);
$folderDestination = $clean_folder.$pacemakerCertificateFolder;
$pdfFilename = $this->getPacemakerCertificateFilename($devisOfDefunt);
$filenamePath = $clean_folder.$pacemakerCertificateFolder.$pdfFilename.'.pdf';
$pdf = new PacemakerCertificatePdfHandler();
$signatureImageExist = $this->signatureImageExists();
$pdf->SetPacemakerCertificateData($devisOfDefunt,$logo,$signatureImageExist);
$pdf->SetPacemakerCertificate();
try {
$storage->newFolder($folderDestination);
}
catch(\OCP\Files\NotPermittedException $e) {
}
$pdfContent = $pdf->Output('','S');
$storage->newFile($filenamePath);
$pdfFile = $storage->get($filenamePath);
$pdfFile->putContent($pdfContent);
return $filenamePath;
}
}

View File

@ -0,0 +1,181 @@
<?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 PacemakerCertificatePdfHandler 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, 75, 25);
}
else{
$this->Cell(55,30,'');
}
}
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 SetPacemakerCertificateData(array $devisOfDefunt,$logo = null,$signatureImageExist = false){
$this->devisOfDefunt = $devisOfDefunt;
$this->logo = $logo;
$this->signatureImageExist = $signatureImageExist;
}
public function SetPacemakerCertificate(){
$this->AddPage();
$this->SetMargins(left:20,top:0,right:20);
$this->SetPacemakerCertificateTitle();
$this->SetPacemakerCertificateContent();
$this->SetSigning();
}
private function SetSigning(){
$this->SetXY(140,$this->GetY() + 30);
$this->Cell(0,10,'Cachet et signature');
if($this->signatureImageExist){
$this->Image($this->imagePath."sign.png", 135, $this->GetY() + 12, 55, 30);
}
}
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, 'Mr/Mlle ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['thanato_nom'] . ' ' . $this->devisOfDefunt['thanato_prenom']),0,1);
$this->SetFont('Arial', '', 14);
$this->MultiCell(0,7, FileExportHelpers::FormatTextForExport('Employé 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 cors du défunt:'));
$this->SetFont('Arial', 'B', 14);
$this->Cell(0,12, 'M./Mme '.$this->devisOfDefunt['defunt_nom'],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->Cell(0,12, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->adresse),0,1);
$this->SetFont('Arial', '', 14);
$this->Cell(0,12,
FileExportHelpers::FormatTextForExport("Numéro de série: ").
FileExportHelpers::FormatTextForExport($this->devisOfDefunt['defunt_reference_pacemaker']),0,1);
$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 SetPacemakerCertificateTitle(){
$this->SetY(60);
$this->SetFont('Arial', 'B', 20);
$this->MultiCell(130, 10, 'ATTESTATION DE RETRAIT DE LA PROTHESE FONCTIONNANT A PILE', 0, '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;
}
}