finish export care certificate on the backend, WIP frontend button

This commit is contained in:
Tiavina 2025-01-07 15:42:22 +03:00
parent 0199b9d7ac
commit bfa8b6e88b
5 changed files with 336 additions and 3 deletions

View File

@ -133,5 +133,8 @@ return [
['name' => 'page#getClientGroups', 'url' => '/getClientGroups', 'verb' => 'PROPFIND'],
['name' => 'page#createDefaultClientGroup', 'url' => '/clientGroup/createDefaultClientGroup', 'verb' => 'POST'],
['name' => 'page#createDefaultClientGroupDiscount', 'url' => '/clientGroupDiscount/createDefaultClientGroupDiscount', 'verb' => 'POST'],
//certificate
['name' => 'page#exportCareCertificate', 'url' => '/defunt/exportCareCertificate', 'verb' => 'POST'],
]
];

View File

@ -20,6 +20,7 @@ use \DatetimeImmutable;
use \IntlDateFormatter;
use \FPDF;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Service\Certificate\CertificateService;
use OCA\Gestion\Service\ExportClientStatisticService;
use OCA\Gestion\Service\ExportThanatoStatisticService;
use OCA\Gestion\Service\InvoicePdfService;
@ -58,6 +59,9 @@ class PageController extends Controller {
/** @var InvoicePdfService */
private $invoicePdfService;
/** @var CertificateService */
private $certificateService;
private $adminStorage;
/**
@ -75,7 +79,8 @@ class PageController extends Controller {
IGroupManager $groupManager,
ExportThanatoStatisticService $exportThanatoStatisticService,
ExportClientStatisticService $exportClientStatisticService,
InvoicePdfService $invoicePdfService) {
InvoicePdfService $invoicePdfService,
CertificateService $certificateService) {
parent::__construct($AppName, $request);
@ -87,6 +92,7 @@ class PageController extends Controller {
$this->exportThanatoStatisticService = $exportThanatoStatisticService;
$this->exportClientStatisticService = $exportClientStatisticService;
$this->invoicePdfService = $invoicePdfService;
$this->certificateService = $certificateService;
$this->defaultImagePath = $this->sharedImagePath.self::DEFAULT_NEXTCLOUD_ADMIN.'/files/.gestion/';
//$this->fpdf = $fpdf;
@ -2879,13 +2885,13 @@ class PageController extends Controller {
return $this->myDb->createDefaultClientGroupDiscount();
}
/**
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function addClientGroupDiscountFeatureTables(){
public function addClientGroupDiscountFeatureTables(){
try{
$this->myDb->addClientGroupDiscountFeatureTables();
return true;
@ -2893,4 +2899,19 @@ class PageController extends Controller {
catch(\OCP\Files\NotFoundException $e) { }
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @param int $defuntId
*/
public function exportCareCertificate($defuntId){
try{
$careCertificateFilename = $this->certificateService->generateCareCertificate($defuntId,$this->idNextcloud);
return $careCertificateFilename;
}
catch(\OCP\Files\NotFoundException $e) { }
}
}

View File

@ -2673,5 +2673,39 @@ class Bdd {
return true;
}
public function getDevisOfDefunt($defuntId){
$sql = "SELECT
devis.id as id,
devis.date as devis_date,
devis.id_defunt as defunt_id,
devis.id_lieu as lieu_id,
lieu.nom as lieu_nom,
lieu.adresse as lieu_adresse,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
client.nom as client_nom,
client.prenom as client_prenom,
client.entreprise as client_entreprise,
client.adresse as client_adresse,
thanato.nom as thanato_nom,
thanato.prenom as thanato_prenom,
thanato.reference as thanato_reference,
thanato.date_habilitation as thanato_date_habilitation
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
WHERE devis.id_defunt = ? ;";
$devisOfDefunt = $this->execSQLNoJsonReturn($sql, [$defuntId]);
if(!empty( $devisOfDefunt)){
return $devisOfDefunt[0];
}
return null;
}
}

View File

@ -0,0 +1,109 @@
<?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;
use DateTime;
use DateTimeImmutable;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Service\Certificate\PdfHandler\CareCertificatePdfHandler;
use OCP\Files\IRootFolder;
class CertificateService {
/** @var Bdd */
private $gestionBdd;
/** @var IRootFolder */
private $rootFolder;
private const DEFAULT_NEXTCLOUD_ADMIN = "admin";
public function __construct(
Bdd $gestionBdd,
IRootFolder $rootFolder) {
$this->gestionBdd = $gestionBdd;
$this->rootFolder = $rootFolder;
}
private function getLogo(){
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try{
try {
if(isset($storage)){
$file = $storage->get('/.gestion/logo.png');
}else{
return "nothing";
}
} catch(\OCP\Files\NotFoundException $e) {
$file = $storage->get('/.gestion/logo.jpeg');
}
}
catch(\OCP\Files\NotFoundException $e) {
return "nothing";
}
return base64_encode($file->getContent());
}
public function generateCareCertificate($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).'/';
$careCertificateFolder = $this->getCareCertificateFolder($devisOfDefunt);
$pdf = new CareCertificatePdfHandler();
$pdf->SetCareCertificateData($devisOfDefunt,$logo);
$pdf->SetCareCertificate();
$pdf->Output();
$pdfContent = $pdf->Output('','S');
$pdfFilename = $this->GetCareCertificateFilename($devisOfDefunt);
return "";
}
private function getCareCertificateFolder($devisOfDefunt){
$careCertificateFolder = 'CLIENTS/'
.strtoupper($devisOfDefunt["client_entreprise"])
.'/DEFUNTS/'
.strtoupper($devisOfDefunt["defunt_nom"])
.'ATTESTATION/';
return $careCertificateFolder;
}
private function GetCareCertificateFilename($devisOfDefunt){
$filename = 'ATTESTATION_SOIN_'.$devisOfDefunt['defunt_nom'];
return $filename;
}
}

View File

@ -0,0 +1,166 @@
<?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 $logoPath = "/var/www/html/data/admin/files/.gestion/";
function Header()
{
if($this->logo != "nothing"){
$this->Image($this->logoPath."logo.png", 10, 10, 75, 25);
}
else{
$this->Cell(55,30,'');
}
}
function Footer()
{
$this->SetY(-15);
$this->SetFont('Arial', '', 8);
$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){
$this->devisOfDefunt = $devisOfDefunt;
$this->logo = $logo;
}
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() + 30);
$this->Cell(0,10,'Cachet et signature');
}
private function SetCareCertificateContent(){
$this->SetFont('Arial', '', 12);
$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->Cell(0,12, 'Mr/Mlle ' . FileExportHelpers::FormatTextForExport($this->devisOfDefunt['thanato_nom'] . ' ' . $this->devisOfDefunt['thanato_prenom']),0,1);
$this->MultiCell(0,7, FileExportHelpers::FormatTextForExport('Employé 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->Cell(0,12, 'M./Mme '.$this->devisOfDefunt['defunt_nom'],0,1);
$this->Cell(0,12, FileExportHelpers::FormatTextForExport("Qui reposait à l'adresse suivante"),0,1);
$this->Cell(0,12, FileExportHelpers::FormatTextForExport($this->devisOfDefunt['configuration']->adresse),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 SetCareCertificateTitle(){
$this->SetY(60);
$this->SetFont('Arial', 'B', 17);
$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;
}
}