From 9c6ba888f9dcb40f9df04932ebf54dab19ca2b58 Mon Sep 17 00:00:00 2001 From: Tiavina Date: Sun, 2 Mar 2025 15:27:50 +0300 Subject: [PATCH] finish 3 different templates for group devis to pdf --- .../InvoiceFunecapPdfHandler.php | 51 ---------- .../InvoiceGroupPdfHandler.php | 18 +--- .../InvoiceOgfPdfHandler.php | 92 +++++++++++++++++++ gestion/lib/Service/InvoicePdfService.php | 18 +++- 4 files changed, 110 insertions(+), 69 deletions(-) create mode 100644 gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceOgfPdfHandler.php diff --git a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceFunecapPdfHandler.php b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceFunecapPdfHandler.php index fa07dab..37237a6 100644 --- a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceFunecapPdfHandler.php +++ b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceFunecapPdfHandler.php @@ -33,53 +33,6 @@ use OCA\Gestion\Helpers\PriceHelpers; class InvoiceFunecapPdfHandler extends InvoiceGroupPdfHandler { public int $maxArticlePerPage = 6; - public function DrawInvoiceClientInfo(){ - $this->SetFont('ComicSans', '', 10); - $clientName = $this->factureData['group_name']; - $clientInfoXAxis = 125; - - $clientAddress = $this->factureData['client_real_adress']; - $clientAdressWidth = $this->GetStringWidth($clientAddress); - $maxWidth = $this->GetPageWidth(); - $availableWidhtForClientInfo = $maxWidth - 10 - $clientInfoXAxis; - $clientAdressIsMultiline = $clientAdressWidth > $availableWidhtForClientInfo; - - $clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40; - $this->SetXY($clientInfoXAxis,$clientInfoYAxis); - $this->Cell(0, 5, FileExportHelpers::FormatTextForExport($clientName)); - $clientInfoYAxis += 5; - $this->SetXY($clientInfoXAxis,$clientInfoYAxis); - $this->MultiCell( 0, 5, trim(FileExportHelpers::FormatTextForExport($clientAddress))); - if($clientAdressIsMultiline){ - $clientInfoYAxis += 5; - } - $clientInfoYAxis += 5; - $this->SetXY($clientInfoXAxis,$clientInfoYAxis); - $this->Cell(0, 5, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); - } - public function DrawInvoiceInfoTable(){ - $this->setY(67); - $factureDatePaiement = $this->factureData['date_paiement']; - $factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement); - $factureDateEcheance = $factureDatePaiement; - $factureDatePaiement = $factureDatePaiement->format('d-m-Y'); - $factureDateEcheance->modify('last day of next month'); - $factureDateEcheance = $factureDateEcheance->format('d-m-Y'); - $this->SetFont('ComicSans', 'B', 11); - $this->Cell(30, 7, 'DATE', 1, 0, 'C'); - $this->Cell(94, 7, 'CLIENT', 1, 0, 'C'); - $this->Cell(40, 7, 'FACTURE', 1, 0, 'C'); - $this->Cell(40, 7, 'ECHEANCE', 1, 1, 'C'); - - $this->SetFont('ComicSans', '', 10); - $this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C'); - $this->Cell(94, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C'); - $this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C'); - $this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C'); - - $this->startingYOfArticlesTable = 85; - } - public function DrawArticlesTableValue(){ $this->SetFont('ComicSans','',10); $devisData = $this->factureData['devis']; @@ -145,12 +98,8 @@ class InvoiceFunecapPdfHandler extends InvoiceGroupPdfHandler { $this->currentIndexPosition = $currentIndexPosition; $this->initialIndexPosition = $this->currentIndexPosition; $chargedDevisCount = $this->currentIndexPosition + 1; - var_dump("CURRENT POSITION : ".$this->currentIndexPosition); - var_dump("CHARGED DEVIS COUNT : ".$chargedDevisCount); $devisLeftToGet = $this->devisCount - $chargedDevisCount; - var_dump("LEFT TO GET : ".$devisLeftToGet); $this->devisCountToGet = ($devisLeftToGet <= $this->maxArticlePerPage) ? $devisLeftToGet + 1 : $this->maxArticlePerPage; - var_dump("DEVIS COUNT TO GET : ".$this->devisCountToGet); } } diff --git a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php index 36a6df1..b35d21c 100644 --- a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php +++ b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php @@ -66,7 +66,7 @@ class InvoiceGroupPdfHandler extends FPDF { function Footer() { $this->SetY(-35); - $this->SetFont('ComicSans', '', 7); + $this->SetFont('ComicSans', '', size: 7); $this->MultiCell(0,5,utf8_decode(html_entity_decode('Tout retard de paiement entraînera de plein droit une pénalité de retard de 3 fois le taux légal ( Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.'))); $this->Ln(1); $this->MultiCell(0,5,utf8_decode(html_entity_decode('Si les frais de recouvrement sont supérieurs à ce montant forfaitaire, une indemnisation complémentaire sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du code de commerce ). @@ -146,12 +146,6 @@ class InvoiceGroupPdfHandler extends FPDF { $clientInfoYAxis += 5; $this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->Cell(0, 5, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); - $clientInfoYAxis += 5; - $this->SetXY($clientInfoXAxis,$clientInfoYAxis); - $this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret']); - $clientInfoYAxis += 5; - $this->SetXY($clientInfoXAxis,$clientInfoYAxis); - $this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']); } public function DrawInvoiceCompanyAndClientInfo(){ @@ -169,17 +163,15 @@ class InvoiceGroupPdfHandler extends FPDF { $factureDateEcheance = $factureDateEcheance->format('d-m-Y'); $this->SetFont('ComicSans', 'B', 11); $this->Cell(30, 7, 'DATE', 1, 0, 'C'); - $this->Cell(60, 7, 'CLIENT', 1, 0, 'C'); + $this->Cell(94, 7, 'CLIENT', 1, 0, 'C'); $this->Cell(40, 7, 'FACTURE', 1, 0, 'C'); - $this->Cell(40, 7, 'ECHEANCE', 1, 0, 'C'); - $this->Cell(34, 7, 'COMMANDE', 1, 1, 'C'); + $this->Cell(40, 7, 'ECHEANCE', 1, 1, 'C'); $this->SetFont('ComicSans', '', 10); $this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C'); - $this->Cell(60, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C'); + $this->Cell(94, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C'); $this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C'); - $this->Cell(40, 7, $factureDateEcheance, 1, 0, 'C'); - $this->Cell(34, 7, $this->factureData["order_number"], 1, 1, 'C'); + $this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C'); $this->startingYOfArticlesTable = 85; } diff --git a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceOgfPdfHandler.php b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceOgfPdfHandler.php new file mode 100644 index 0000000..c1c69e4 --- /dev/null +++ b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceOgfPdfHandler.php @@ -0,0 +1,92 @@ + + * + * @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\InvoiceGroupPdfHandler; + +use DateTime; +use OCA\Gestion\Helpers\FileExportHelpers; +use OCA\Gestion\Helpers\PriceHelpers; + +class InvoiceOgfPdfHandler extends InvoiceGroupPdfHandler { + + public function DrawInvoiceClientInfo(){ + $this->SetFont('ComicSans', '', 10); + $clientName = $this->factureData['group_name']; + $clientInfoXAxis = 125; + + $clientAddress = $this->factureData['client_real_adress']; + $clientAdressWidth = $this->GetStringWidth($clientAddress); + $maxWidth = $this->GetPageWidth(); + $availableWidhtForClientInfo = $maxWidth - 10 - $clientInfoXAxis; + $clientAdressIsMultiline = $clientAdressWidth > $availableWidhtForClientInfo; + + $clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40; + $this->SetXY($clientInfoXAxis,$clientInfoYAxis); + $this->Cell(0, 5, FileExportHelpers::FormatTextForExport($clientName)); + $clientInfoYAxis += 5; + $this->SetXY($clientInfoXAxis,$clientInfoYAxis); + $this->MultiCell( 0, 5, trim(FileExportHelpers::FormatTextForExport($clientAddress))); + if($clientAdressIsMultiline){ + $clientInfoYAxis += 5; + } + $clientInfoYAxis += 5; + $this->SetXY($clientInfoXAxis,$clientInfoYAxis); + $this->Cell(0, 5, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); + $clientInfoYAxis += 5; + $this->SetXY($clientInfoXAxis,$clientInfoYAxis); + $this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Numéro') . ' Siret: ' . $this->factureData['siret']); + $clientInfoYAxis += 5; + $this->SetXY($clientInfoXAxis,$clientInfoYAxis); + $this->Cell(0, 5, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']); + } + + public function DrawInvoiceInfoTable(){ + $this->setY(67); + $factureDatePaiement = $this->factureData['date_paiement']; + $factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement); + $factureDateEcheance = $factureDatePaiement; + $factureDatePaiement = $factureDatePaiement->format('d-m-Y'); + $factureDateEcheance->modify('last day of next month'); + $factureDateEcheance = $factureDateEcheance->format('d-m-Y'); + $this->SetFont('ComicSans', 'B', 11); + $this->Cell(30, 7, 'DATE', 1, 0, 'C'); + $this->Cell(60, 7, 'CLIENT', 1, 0, 'C'); + $this->Cell(40, 7, 'FACTURE', 1, 0, 'C'); + $this->Cell(40, 7, 'ECHEANCE', 1, 0, 'C'); + $this->Cell(34, 7, 'COMMANDE', 1, 1, 'C'); + + $this->SetFont('ComicSans', '', 10); + $this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C'); + $this->Cell(60, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C'); + $this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C'); + $this->Cell(40, 7, $factureDateEcheance, 1, 0, 'C'); + $this->Cell(34, 7, $this->factureData["order_number"], 1, 1, 'C'); + + $this->startingYOfArticlesTable = 85; + } + + +} diff --git a/gestion/lib/Service/InvoicePdfService.php b/gestion/lib/Service/InvoicePdfService.php index f715957..2e9d84b 100644 --- a/gestion/lib/Service/InvoicePdfService.php +++ b/gestion/lib/Service/InvoicePdfService.php @@ -35,6 +35,7 @@ use OCA\Gestion\Db\Bdd; use OCA\Gestion\Helpers\DateHelpers; use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceFunecapPdfHandler; use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceGroupPdfHandler; +use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceOgfPdfHandler; use OCA\Gestion\Service\InvoiceRecap\InvoiceRecapService; use OCP\DB\Exception; use OCP\Files\IRootFolder; @@ -161,11 +162,18 @@ class InvoicePdfService { $templateType = $invoicePdfData['template_type_key']; $clean_folder = html_entity_decode(string: $currentConfig->path).'/'; $factureFolders = $this->getGroupFactureFolder($invoicePdfData,$clean_folder); - if($templateType == ClientTemplateTypeConstant::FUNECAP){ - $pdf = new InvoiceFunecapPdfHandler(); - } - else{ - $pdf = new InvoiceGroupPdfHandler(); + switch ($templateType) { + case ClientTemplateTypeConstant::FUNECAP: + $pdf = new InvoiceFunecapPdfHandler(); + break; + + case ClientTemplateTypeConstant::OGF: + $pdf = new InvoiceOgfPdfHandler(); + break; + + default: + $pdf = new InvoiceGroupPdfHandler(); + break; } $pdf->AddFont('ComicSans','','Comic Sans MS.php'); $pdf->AddFont('ComicSans','B','comic-sans-bold.php');