From 415b0943145bd533a85c118df41411f03fbc447e Mon Sep 17 00:00:00 2001 From: Tiavina Date: Fri, 3 Jan 2025 10:09:29 +0300 Subject: [PATCH 1/3] finsh address from facture recap, margin right from right text , WIP facture date --- gestion/lib/Controller/PageController.php | 58 +++++++++++++---------- gestion/lib/Helpers/FileExportHelpers.php | 16 +++++++ 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/gestion/lib/Controller/PageController.php b/gestion/lib/Controller/PageController.php index a4bd6a2..c485ed9 100644 --- a/gestion/lib/Controller/PageController.php +++ b/gestion/lib/Controller/PageController.php @@ -782,14 +782,17 @@ class PageController extends Controller { $pdf = new FPDF(); $current_client = ''; - $adresse = ''; + $clientAddress = ''; + $clientCity = ''; $date_facture; $j=1; foreach ($client as $key => $facture) { if($j==1) { $current_client = $facture['prenoms_client'].' '.$facture['nom_client']; - $adresse = $facture['adresse_client']; $date_facture = $facture['date_facture']; + $clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($facture['adresse_client']); + $clientAddress = $clientAddresses['address']; + $clientCity = $clientAddresses['city']; } $j++; } @@ -804,19 +807,23 @@ class PageController extends Controller { $pdf->AddPage(); // on sup les 2 cm en bas $pdf->SetAutoPagebreak(False); - $pdf->SetMargins(0,0,0); + $pdf->SetMargins(0,0,10); // logo : 80 de largeur et 55 de hauteur if($isLogoExist){ $pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30); } // adresse du facture - $pdf->SetFont('Arial','B',size: 11); $_x = 122 ; $_y = 40; - $pdf->SetXY( $_x, $_y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $_y += 8; - $pdf->SetXY( $_x, $_y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, ''); + $pdf->SetFont('Arial','B',size: 11); + $pdf->SetY(40); + $pdf->Cell( 0, 8, utf8_decode($current_client), 0, 1, 'R'); + $pdf->Cell( 0, 8, utf8_decode(html_entity_decode($clientAddress)), 0,1,'R'); + if($clientCity != ''){ + $pdf->Cell( 0, 8, utf8_decode(html_entity_decode($clientCity)), 0, 1, 'R'); + } // date facture - $pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 60 ); - $pdf->MultiCell( 60, 8, $current_config[0]->adresse . " le, ".utf8_decode($date_formated), 0, 0, ''); + $pdf->SetFont('Arial','',11); + $pdf->Cell( 0, 8, "Saint Senoux le, ".utf8_decode($date_formated), 0, 1, 'R'); // observations $pdf->SetFont( "Arial", "BU", 10 ); $pdf->SetXY( 10, 85 ) ; $pdf->Cell($pdf->GetStringWidth("Objet:"), 0, "Objet:", 0, "L"); @@ -834,17 +841,17 @@ class PageController extends Controller { $pdf->SetFont( "Arial", "", 10 ); $pdf->SetXY( $pdf->GetStringWidth("Objet")+15, 120 ) ; $pdf->Cell($pdf->GetStringWidth($text3), 0, $text3, 0, "L"); // signature - $pdf->SetFont('Arial','',11); $pdf->SetXY( 122, 145 ); + $pdf->SetFont('Arial','',11); $pdf->SetXY( 145, 145 ); $pdf->Cell( $pdf->GetStringWidth($current_config[0]->nom.' '.$current_config[0]->prenom), 0, utf8_decode(html_entity_decode($current_config[0]->nom.' '.$current_config[0]->prenom)), 0, 0, 'L'); $signatureExists = $this->signatureImageExists('sign.png'); if($signatureExists){ - $pdf->Image($this->currentUserImagePath."sign.png", 122, 150, 55, 30); + $pdf->Image($this->currentUserImagePath."sign.png", 135, 150, 55, 30); } $y0 = 260; $pageWidth = $pdf->GetPageWidth(); //Positionnement en bas et tout centrer - $pdf->SetFont('Arial','',6); + $pdf->SetFont('Arial','',8); $pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->mentions_default)), 0, 0, 'C'); $pdf->SetXY( 1, $y0 + 8 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C'); $pdf->SetXY( 1, $y0 + 12 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C'); @@ -866,7 +873,7 @@ class PageController extends Controller { $pdf->AddPage(); // on sup les 2 cm en bas $pdf->SetAutoPagebreak(False); - $pdf->SetMargins(0,0,0); + $pdf->SetMargins(0,0,10); if($isLogoExist){ $pdf->Image($this->currentUserImagePath."logo.png", 10, 10, 55, 30); } @@ -877,21 +884,24 @@ class PageController extends Controller { } // date facture - $pdf->SetFont('Arial','',11); $pdf->SetXY( 122, y: 10 ); - $pdf->MultiCell( 60, 8, $current_config[0]->adresse . " le, ".utf8_decode($date_formated), 0, 0, ''); + $pdf->SetFont('Arial','',11); + $pdf->SetY(10); + $pdf->Cell( 0, 8,"Saint Senoux le, ".utf8_decode($date_formated), 0, 0, 'R'); // n° facture, date echeance et reglement et obs - $pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(100, 30, 85, 8, "DF"); - $pdf->SetXY( 100, 30 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' FAC/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C'); + $pdf->SetLineWidth(0.1); $pdf->SetFillColor(255); $pdf->Rect(114, 20, 85, 8, "DF"); + $pdf->SetXY( 114, 20 ); $pdf->SetFont( "Arial", "B", 12 ); $pdf->Cell( 85, 8, 'FACTURE N'.utf8_decode('°').' FAC/'.$key_annee.'/'.strtoupper($this->convert_special_char(explode(' ', $date_formated)[1])), 0, 0, 'C'); // adresse du facture - $pdf->SetFont('Arial','B',11); $x = 122 ; $y = 45; - $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode($current_client), 0, 0, ''); $y += 8; - $pdf->SetXY( $x, $y ); $pdf->MultiCell( 80, 4, utf8_decode(html_entity_decode($adresse)), 0, 0, ''); $y += 7; - $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, FileExportHelpers::FormatTextForExport('Numéro') . ' TVA:', 0, 0, ''); $x+=25; - $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, FileExportHelpers::FormatTextForExport($tvaIntraCommuValue), 0, 0, '');$y += 7;$x-=25; - $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, 'Email:', 0, 0, ''); $x+=13; - $pdf->SetXY( $x, $y ); $pdf->Cell( 100, 8, utf8_decode(html_entity_decode($facture['mail_client'])), 0, 0, ''); + $pdf->SetFont('Arial','B',11); + $pdf->SetY(y: 32); + $pdf->Cell( 0, 6, utf8_decode($current_client), 0, 1, 'R'); + $pdf->Cell( 0, 6, utf8_decode(html_entity_decode($clientAddress)), 0, 1, 'R'); + if($clientCity != ''){ + $pdf->Cell( 0, 6, utf8_decode(html_entity_decode($clientCity)), 0, 1, 'R'); + } + $pdf->Cell( 0, 6, FileExportHelpers::FormatTextForExport('Numéro') . ' TVA: ' . FileExportHelpers::FormatTextForExport($tvaIntraCommuValue), 0, 1, 'R'); + $pdf->Cell( 0, 6, 'Email: ' . utf8_decode(html_entity_decode($facture['mail_client'])), 0, 1, 'R'); // *********************** // le cadre des articles @@ -972,7 +982,7 @@ class PageController extends Controller { // pied de page // ************************** - $pdf->SetFont('Arial','',6); + $pdf->SetFont('Arial','',8); $pdf->SetXY( 1, $y0 + 4 ); $pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->mentions_default)), 0, 0, 'C'); $pdf->SetXY( 1, $y0 + 8 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_one)), 0, 0, 'C'); $pdf->SetXY( 1, $y0 + 12 );$pdf->Cell( $pageWidth, 5, utf8_decode(html_entity_decode($current_config[0]->legal_two)), 0, 0, 'C'); diff --git a/gestion/lib/Helpers/FileExportHelpers.php b/gestion/lib/Helpers/FileExportHelpers.php index 160f54d..0cde77f 100644 --- a/gestion/lib/Helpers/FileExportHelpers.php +++ b/gestion/lib/Helpers/FileExportHelpers.php @@ -11,4 +11,20 @@ class FileExportHelpers return $textFormatted; } + public static function GetAddressAndCityFromAddress(string $adresse){ + $adresseResult = ""; + $cityResult = ""; + $adresses = explode("-",$adresse); + if(isset($adresses[0])){ + $adresseResult = trim($adresses[0]); + } + if(isset($adresses[1])){ + $cityResult = trim($adresses[1]); + } + return [ + "address" => $adresseResult, + "city" => $cityResult + ]; + } + } From fca12c05dcd495f4d9ccec3fe75effa59d9c7b82 Mon Sep 17 00:00:00 2001 From: Tiavina Date: Fri, 3 Jan 2025 10:25:42 +0300 Subject: [PATCH 2/3] fix facture date echeance , margins, WIP nom defunt --- gestion/lib/Service/InvoicePdfHandler.php | 39 ++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index 3d1f53a..4ee99bf 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -79,13 +79,22 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod public function GetFactureContent(){ $this->AddPage(); - + $this->SetMargins(10,0,10); $factureDate = $this->factureData['date']; $factureDate = DateTime::createFromFormat('Y-m-d',$factureDate); $factureDate = $factureDate->format('d-m-Y'); $factureDatePaiement = $this->factureData['date_paiement']; $factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement); + $factureDateEcheance = $factureDatePaiement; $factureDatePaiement = $factureDatePaiement->format('d-m-Y'); + + $factureDateEcheance->modify('+30 days'); + $factureDateEcheance = $factureDateEcheance->format('d-m-Y'); + + $devisDate = $this->factureData['devis_date']; + $devisDate = DateTime::createFromFormat('Y-m-d',$devisDate); + $devisDate = $devisDate->format('d-m-Y'); + $this->SetFont('Arial', '', 12); $this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['configuration']->entreprise)), 0, 0); $this->Cell(0, 7, utf8_decode(html_entity_decode($this->factureData['client_nom'] . ' ' . $this->factureData['client_entreprise'])), 0, 1,'R'); @@ -101,15 +110,15 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod //facture infos $this->SetFont('Arial', 'B', 11); $this->Cell(30, 7, 'DATE', 1, 0, 'C'); - $this->Cell(70, 7, 'CLIENT', 1, 0, 'C'); + $this->Cell(80, 7, 'CLIENT', 1, 0, 'C'); $this->Cell(40, 7, 'FACTURE', 1, 0, 'C'); $this->Cell(40, 7, 'ECHEANCE', 1, 1, 'C'); $this->SetFont('Arial', '', 10); - $this->Cell(30, 7, $factureDate, 1, 0, 'C'); - $this->Cell(70, 7, utf8_decode(html_entity_decode($this->factureData['client_nom'])), 1, 0, 'C'); + $this->Cell(30, 7, $factureDatePaiement, 1, 0, 'C'); + $this->Cell(80, 7, utf8_decode(html_entity_decode($this->factureData['client_nom'])), 1, 0, 'C'); $this->Cell(40, 7, $this->factureData['num'], 1, 0, 'C'); - $this->Cell(40, 7, $factureDatePaiement, 1, 1, 'C'); + $this->Cell(40, 7, $factureDateEcheance, 1, 1, 'C'); $this->Ln(8); @@ -117,7 +126,7 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod $tvaValue = $this->factureData["configuration"]->tva_default; $this->SetFont('Arial', 'B', 11); $this->Cell(20, 8, 'Date', 1, 0); - $this->Cell(80, 8, 'Description', 1, 0,'C'); + $this->Cell(90, 8, 'Description', 1, 0,'C'); $this->Cell(30, 8, 'Prix Uni. HT', 1, 0, 'C'); $this->Cell(20, 8, 'TVA ' . $tvaValue . '%', 1, 0, 'C'); $this->Cell(30, 8, 'Prix Uni. TTC', 1, 1, 'C'); @@ -129,17 +138,17 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue); $totalHt+=$valueHt; $totalTtc+=$valueTtc; - $descriptionLineNumber = $this->NbLines(80,$product["produit_description"]); + $descriptionLineNumber = $this->NbLines(90,$product["produit_description"]); $articleListMaxHeight = $descriptionLineNumber * 10; $tvaAmount = $valueTtc - $valueHt; $this->SetFont('Arial', '', 10); - $this->Cell(20, $articleListMaxHeight, $factureDate, 'LR',0); - $this->MultiAlignCell(80, $articleListMaxHeight, utf8_decode(html_entity_decode($product["produit_description"])),'LR','0',); - $this->Cell(30, $articleListMaxHeight, number_format($valueHt,2,'.',''), 'LR', 0, 'C'); - $this->Cell(20, $articleListMaxHeight, number_format($tvaAmount,2,'.',''), 'LR', 0, 'C'); - $this->Cell(30, $articleListMaxHeight, number_format($valueTtc,2,'.',''), 'LR', 1, 'C'); + $this->Cell(20, $articleListMaxHeight, $devisDate, 'LR',0); + $this->MultiAlignCell(90, $articleListMaxHeight, utf8_decode(html_entity_decode($product["produit_description"])),'LR','0',); + $this->Cell(30, $articleListMaxHeight, number_format($valueHt,2,'.','').chr(128), 'LR', 0, 'C'); + $this->Cell(20, $articleListMaxHeight, number_format($tvaAmount,2,'.','').chr(128), 'LR', 0, 'C'); + $this->Cell(30, $articleListMaxHeight, number_format($valueTtc,2,'.','').chr(128), 'LR', 1, 'C'); } - $this->Cell(180,0,'','T'); + $this->Cell(190,0,'','T'); $this->Ln(8); $this->SetFont('Arial', '', 9); $this->MultiCell(0,5,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->factureData['configuration']->entreprise))); @@ -163,7 +172,7 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod $this->Cell($totalHtArrayWidth, 7, 'TOTAL HT', 1, 1, 'C'); $this->SetXY($ibanLastPositionX,$ibanCursorY); $this->SetFont('Arial', '', 11); - $this->Cell($totalHtArrayWidth, 20, number_format($totalHt,2,'.',''), 1, 1, 'C'); + $this->Cell($totalHtArrayWidth, 20, number_format($totalHt,2,'.','').chr(128), 1, 1, 'C'); $tableHTLastPostionX = $ibanLastPositionX + $totalHtArrayWidth + 10; //TABLE TTC @@ -172,7 +181,7 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod $this->Cell(30, 7, 'TOTAL TTC', 1, 1, 'C'); $this->SetXY($tableHTLastPostionX,$ibanCursorY+14); $this->SetFont('Arial', '', 11); - $this->Cell(30, 7, number_format($totalTtc,2,'.',''), 1, 1, 'C'); + $this->Cell(30, 7, number_format($totalTtc,2,'.','').chr(128), 1, 1, 'C'); $pdfContent = $this->Output('','S'); From 0fcbc2c0c943a930466ef7def095cd2b00ca7329 Mon Sep 17 00:00:00 2001 From: Tiavina Date: Fri, 3 Jan 2025 10:49:01 +0300 Subject: [PATCH 3/3] finish facture requirements (add nom defunt and sexe detunt add the last product in the table , add date to the last product in the table) --- gestion/lib/Db/Bdd.php | 1 + gestion/lib/Helpers/FileExportHelpers.php | 4 ++++ gestion/lib/Service/InvoicePdfHandler.php | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index 21f5516..eebdaaf 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -2322,6 +2322,7 @@ class Bdd { client.entreprise as client_entreprise, client.adresse as client_adresse, defunt.nom as defunt_nom, + defunt.sexe as defunt_sexe, lieu.nom as lieu_nom, lieu.adresse as lieu_adresse, thanato.nom as thanato_nom, diff --git a/gestion/lib/Helpers/FileExportHelpers.php b/gestion/lib/Helpers/FileExportHelpers.php index 0cde77f..1be25f9 100644 --- a/gestion/lib/Helpers/FileExportHelpers.php +++ b/gestion/lib/Helpers/FileExportHelpers.php @@ -27,4 +27,8 @@ class FileExportHelpers ]; } + public static function GetSexeLabel(string $sexeKey){ + return $sexeKey === 'f' ? 'Mme' : 'Mr'; + } + } diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index 4ee99bf..a07a41e 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -28,6 +28,7 @@ namespace OCA\Gestion\Service; use DateTime; use \FPDF; +use OCA\Gestion\Helpers\FileExportHelpers; use OCA\Gestion\Helpers\PriceHelpers; class InvoicePdfHandler extends FPDF { @@ -133,17 +134,24 @@ sera due sur présentation de justificatifs ( articles L.441-3 et L.441-6 du cod $totalHt = 0; $totalTtc = 0; - foreach($this->factureData["products"] as $product){ + $products = $this->factureData["products"]; + foreach($products as $product){ $valueHt = $product['produit_price']; $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue); $totalHt+=$valueHt; $totalTtc+=$valueTtc; $descriptionLineNumber = $this->NbLines(90,$product["produit_description"]); - $articleListMaxHeight = $descriptionLineNumber * 10; + $productDescription = $product["produit_description"]; + $dateValue = ""; + if($product === end($products)){ + $dateValue = $devisDate; + $productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->factureData['defunt_sexe']) . ' '. $this->factureData["defunt_nom"]; + } + $articleListMaxHeight = $descriptionLineNumber * 6; $tvaAmount = $valueTtc - $valueHt; $this->SetFont('Arial', '', 10); - $this->Cell(20, $articleListMaxHeight, $devisDate, 'LR',0); - $this->MultiAlignCell(90, $articleListMaxHeight, utf8_decode(html_entity_decode($product["produit_description"])),'LR','0',); + $this->Cell(20, $articleListMaxHeight, $dateValue, 'LR',0); + $this->MultiAlignCell(90, $articleListMaxHeight, utf8_decode(html_entity_decode($productDescription)),'LR','0',); $this->Cell(30, $articleListMaxHeight, number_format($valueHt,2,'.','').chr(128), 'LR', 0, 'C'); $this->Cell(20, $articleListMaxHeight, number_format($tvaAmount,2,'.','').chr(128), 'LR', 0, 'C'); $this->Cell(30, $articleListMaxHeight, number_format($valueTtc,2,'.','').chr(128), 'LR', 1, 'C');