From 07dcd6d91d57634256953f9df87d342050376fee Mon Sep 17 00:00:00 2001 From: Tolotsoa Date: Wed, 27 Aug 2025 14:34:24 +0300 Subject: [PATCH] fix template final --- gestion/lib/Db/Bdd.php | 16 +- .../InvoiceGroupPdfHandler.php | 170 +++++++++--------- gestion/lib/Service/InvoicePdfHandler.php | 77 +++----- 3 files changed, 121 insertions(+), 142 deletions(-) diff --git a/gestion/lib/Db/Bdd.php b/gestion/lib/Db/Bdd.php index ad53cd7..423ff26 100644 --- a/gestion/lib/Db/Bdd.php +++ b/gestion/lib/Db/Bdd.php @@ -5581,11 +5581,17 @@ COMMENTAIRES: ".$comment; $tvaLabel = "TVA 0 %"; } - $totaPricesArray = [ - "TOTAL HT" => $totalHt, - $tvaLabel => $totalTva, - "TOTAL TTC" => $totalTtc - ]; + if($hasTva) { + $totaPricesArray = [ + "TOTAL HT" => $totalHt, + $tvaLabel => $totalTva, + "TOTAL TTC" => $totalTtc + ]; + } else { + $totaPricesArray = [ + "TOTAL HT" => $totalHt + ]; + } $factureData["is_tva"] = $hasTva; $factureData["devis"] = $factureDevisList; diff --git a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php index 3e1baac..849265c 100644 --- a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php +++ b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php @@ -50,10 +50,9 @@ class InvoiceGroupPdfHandler extends FPDF public $thereIsOrderOrCaseNumber = false; public $startingYOfArticlesTable = 100; - public int $maxArticlePerPage = 19; + public int $maxArticlePerPage = 7; public $additionalArticlesLineBasedOnMultiline = 0; public $interLigneHeader = 5; - public $hasTva = true; public function Header() @@ -70,27 +69,32 @@ class InvoiceGroupPdfHandler extends FPDF } public function AddWatermark() { - $this->SetAlpha(0.2); + try { + $this->SetAlpha(0.2); - $imagePath = $this->logoPath . "filigrane_pdf.png"; - list($originalWidth, $originalHeight) = getimagesize($imagePath); + $imagePath = $this->logoPath . "filigrane_pdf.png"; + list($originalWidth, $originalHeight) = getimagesize($imagePath); - // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) - // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) - $originalWidth = $originalWidth * 0.264583; - $originalHeight = $originalHeight * 0.264583; + // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) + // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) + $originalWidth = $originalWidth * 0.264583; + $originalHeight = $originalHeight * 0.264583; - // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine - $scale = 1.7; - $width = $originalWidth * $scale; - $height = $originalHeight * $scale; - // Calculer la position pour centrer l'image - $x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm - $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4 + // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine + $scale = 1.7; + $width = $originalWidth * $scale; + $height = $originalHeight * $scale; + // Calculer la position pour centrer l'image + $x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm + $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4 + + // Ajouter l'image en filigrane + $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur + $this->SetAlpha(0.1); // Définir l'opacité + } catch (\Throwable $th) { + + } - // Ajouter l'image en filigrane - $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur - $this->SetAlpha(0.1); // Définir l'opacité } public function SetAlpha($alpha) @@ -111,7 +115,7 @@ class InvoiceGroupPdfHandler extends FPDF public function Footer() { $this->SetY(-34); - $this->SetFont('ComicSans', '', 7); + $this->SetFont('Arial', '', 7); $this->MultiCell(0, 4, 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 '))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode('(Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.'))); @@ -121,7 +125,7 @@ class InvoiceGroupPdfHandler extends FPDF $this->MultiCell(0, 4, utf8_decode(html_entity_decode('sera due sur présentation de justificatifs (articles L.441-3 et L.441-6 du code de commerce).'))); $this->SetY(-10); - $this->SetFont('ComicSans', '', 7); + $this->SetFont('Arial', '', 7); $this->Cell(0, 10, utf8_decode(html_entity_decode($this->factureData['configuration']->legal_one)), 0, 0, 'C'); } @@ -171,17 +175,16 @@ class InvoiceGroupPdfHandler extends FPDF public function DrawInvoiceCompanyInfo() { $this->SetY(40); - $this->SetFont('ComicSans', '', 10); + $this->SetFont('Arial', '', 10); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone), 0, 1); $this->Cell(0, $this->interLigneHeader, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1); } - public function DrawInvoiceClientInfo() { - $this->SetFont('ComicSans', '', 10); + $this->SetFont('Arial', '', 10); $clientName = $this->factureData['group_name']; $clientInfoXAxis = 135; @@ -193,6 +196,7 @@ class InvoiceGroupPdfHandler extends FPDF $addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo; $addressIsMoreThanTwoLines = ($addressWidth / $availableWidhtForClientInfo) > 2; + $clientInfoYAxis = $addressIsMoreThanTwoLines ? 35 : 40; $this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName)); @@ -221,6 +225,7 @@ class InvoiceGroupPdfHandler extends FPDF } else { $clientInfoYAxis += $this->interLigneHeader; } + } else { $clientAddresses = explode(",", $clientAddress); foreach ($clientAddresses as $address) { @@ -258,7 +263,7 @@ class InvoiceGroupPdfHandler extends FPDF $this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']); } } else { - // Sans TVA : afficher N° TVA intracommunautaire (même si vide) + // Sans TVA : afficher N° TVA intracommunautaire $clientInfoYAxis += $this->interLigneHeader; $this->SetXY($clientInfoXAxis, $clientInfoYAxis); $tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : ''; @@ -266,6 +271,8 @@ class InvoiceGroupPdfHandler extends FPDF } } + + public function DrawInvoiceInfoTable() { $startInvoiceInfoTable = 70; @@ -278,13 +285,13 @@ class InvoiceGroupPdfHandler extends FPDF $factureDateEcheance->modify('last day of next month'); $factureDateEcheance = $factureDateEcheance->format('d-m-Y'); - $this->SetFont('ComicSans', '', 10); + $this->SetFont('Arial', '', 10); $this->Cell(25, 7, 'DATE', 1, 0, 'C'); $this->Cell(104, 7, 'CLIENT', 1, 0, 'C'); $this->Cell(39, 7, 'FACTURE', 1, 0, 'C'); $this->Cell(36, 7, 'ECHEANCE', 1, 1, 'C'); - $this->SetFont('ComicSans', '', 10); + $this->SetFont('Arial', '', 10); $this->Cell(25, 7, $factureDatePaiement, 1, 0, 'C'); $this->Cell(104, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 1, 0, 'C'); $this->Cell(39, 7, $this->factureData['num'], 1, 0, 'C'); @@ -295,30 +302,25 @@ class InvoiceGroupPdfHandler extends FPDF public function DrawArticlesTableRect() { + $this->SetLineWidth(0.2); $gapBetweenStartingOfArticlesTableAndColumnName = 7; $additionnalheight = 0.75; $tableHeight = $this->thereIsOrderOrCaseNumber ? (137 + $additionnalheight) : (137 + 6 + $additionnalheight); $this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D"); - - // Cadre titre des colonnes + // $this->RoundedRect(3, $this->startingYOfArticlesTable, 204, $tableHeight,5 ,'1234',"D"); + // cadre titre des colonnes $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); - - // Les traits verticaux colonnes + // les traits verticaux colonnes $additionalMargRight = 1; - $endingLine = 233 + $additionnalheight; - - // Lignes verticales communes + $endingLine = $this->startingYOfArticlesTable + $tableHeight; $this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine); + $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); if ($this->hasTva) { - // Avec TVA : 3 colonnes de prix - $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); $this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); } else { - // Sans TVA : 2 colonnes - garder la ligne séparatrice Description/Prix HT - $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); } } @@ -328,26 +330,23 @@ class InvoiceGroupPdfHandler extends FPDF $additionalMargRight = 1; $tvaValue = $this->factureData["configuration"]->tva_default; $columnNameY = $this->startingYOfArticlesTable - 1.5; - $this->SetFont('ComicSans', '', 10); - - $this->SetXY(12 + $additionalMargRight, $columnNameY); - $this->Cell(7, 10, "Date", 0, 0, 'C'); + $this->SetFont('Arial', '', 10); + $this->SetXY(35 + $additionalMargRight, $columnNameY); + $this->Cell(7, 10, "", 0, 0, 'C'); $this->SetXY(30 + $additionalMargRight, $columnNameY); $this->Cell(100, 10, "Description", 0, 0, 'C'); + $this->SetXY(143 + $additionalMargRight, $columnNameY); + $this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C'); + if ($this->hasTva) { - // Avec TVA : 3 colonnes (HT | TVA | TTC) - $this->SetXY(145 + $additionalMargRight, $columnNameY); - $this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C'); $this->SetXY(163 + $additionalMargRight, $columnNameY); $this->Cell(20, 10, 'TVA ' . $tvaValue . '%', 0, 0, 'C'); + $this->SetXY(185, $columnNameY); $this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C'); } else { - // Sans TVA : 2 colonnes seulement (HT | Montant HT) - $this->SetXY(145 + $additionalMargRight, $columnNameY); - $this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C'); $this->SetXY(185, $columnNameY); $this->Cell(20, 10, "Montant HT", 0, 0, 'C'); } @@ -355,16 +354,19 @@ class InvoiceGroupPdfHandler extends FPDF public function DrawArticlesTableValue() { - $this->SetFont('ComicSans', '', 10); + // Set espacement avant de continue + + $this->SetFont('Arial', '', 10); $devisData = $this->factureData['devis']; $tvaValue = $this->factureData["configuration"]->tva_default; $totalHt = 0; $totalTtc = 0; $totalTva = 0; $yValue = $this->startingYOfArticlesTable + 13; + // $maxDescriptionWidth = 102; $maxDescriptionWidth = 104.3; + // $maxDescriptionWidth = 51; $currentIndexPosition = $this->currentIndexPosition; - for ($currentIndexPosition; $currentIndexPosition < ($this->initialIndexPosition + $this->devisCountToGet); $currentIndexPosition++) { $currentDevis = $devisData[$currentIndexPosition]; $devisDate = $currentDevis['devis_date']; @@ -372,10 +374,9 @@ class InvoiceGroupPdfHandler extends FPDF $devisDate = $devisDate->format('d-m-Y'); $products = $currentDevis["products"]; $productIncrement = 0; - foreach ($products as $product) { - $valueHt = $product['produit_price'] * $product["quantite"]; + $valueHt = $product['produit_price'] * $product["quantite"]; if ($this->hasTva) { $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue); $tvaAmount = $valueTtc - $valueHt; @@ -386,26 +387,26 @@ class InvoiceGroupPdfHandler extends FPDF $totalHt += $valueHt; $totalTtc += $valueTtc; - $totalTva += $tvaAmount; - $productDescription = $product["produit_description"] ?? ""; + $currentDevisDefuntName = $currentDevis["defunt_nom"] ?? ""; + $dateValue = ""; + $dateAndDefuntName = ""; if ($productIncrement == 0) { $dateValue = $devisDate; - $productDescription .= " de " . $currentDevis["defunt_nom"] ?? ""; + // $productDescription .= " de " . $currentDevis["defunt_nom"] ?? ""; + $dateAndDefuntName = $dateValue . " - " . $currentDevisDefuntName; + $this->SetXY(70, $yValue); + $this->Cell(5, 6, $currentDevisDefuntName, 0, 0); + $this->SetXY(4, $yValue + 5); + $this->Cell(5, 6, $dateValue, 0, 0); } - // Date - $this->SetXY(4, $yValue); - $this->Cell(5, 6, $dateValue, 0, 0); - - // Description (avec gestion multiligne) - $this->SetXY(30, $yValue); + $this->SetXY(30, $yValue + 5); $productDescription = FileExportHelpers::FormatTextForExport($productDescription); $productDescriptionWidth = $this->GetStringWidth($productDescription); $productDescriptionWidthIsGreaterThanMaxWidth = $productDescriptionWidth > $maxDescriptionWidth; $productDescriptionIsMultiline = false; - if ($productDescriptionWidthIsGreaterThanMaxWidth) { $yBefore = $this->GetY(); $this->MultiCell($maxDescriptionWidth, 6, $productDescription, 0, 'L'); @@ -418,54 +419,47 @@ class InvoiceGroupPdfHandler extends FPDF $this->Cell($maxDescriptionWidth, 6, $productDescription); } + + $this->SetXY(144, $yValue + 5); + $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); + if ($this->hasTva) { - // Prix HT - $this->SetXY(146, $yValue); - $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); - // TVA - $this->SetXY(165, $yValue); + $this->SetXY(165, $yValue + 5); $this->Cell(20, 6, number_format($tvaAmount, 2, '.', '') . chr(128), 0, 0, 'C'); - // Prix TTC - $this->SetXY(182, $yValue); + + $this->SetXY(182, $yValue + 5); $this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C'); } else { - // Sans TVA : 2 colonnes (Prix HT | Montant HT) - $this->SetXY(146, $yValue); - $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); - $this->SetXY(182, $yValue); + $this->SetXY(182, $yValue + 5); $this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C'); } $yValue += 6; + $totalTva += $tvaAmount; if ($productDescriptionWidthIsGreaterThanMaxWidth) { $yValue += 6; } $productIncrement++; } + $yValue += 6; + $isLastLigneDevis = $currentIndexPosition == (($this->initialIndexPosition + $this->devisCountToGet) - 1); + if (!$isLastLigneDevis) { + $this->Line(3, $yValue, 207, $yValue); + } } - $this->currentIndexPosition = $currentIndexPosition; $this->initialIndexPosition = $this->currentIndexPosition; $chargedDevisCount = $this->currentIndexPosition + 1; $devisLeftToGet = $this->devisCount - $chargedDevisCount; $this->devisCountToGet = ($devisLeftToGet < $this->maxArticlePerPage) ? $devisLeftToGet + 1 : $this->maxArticlePerPage; - // Mettre à jour les totaux selon la TVA - $this->totalPrices = []; - if ($this->hasTva) { - $this->totalPrices['TOTAL HT'] = $totalHt; - $this->totalPrices['TVA ' . $tvaValue . '%'] = $totalTva; - $this->totalPrices['TOTAL TTC'] = $totalTtc; - } else { - $this->totalPrices['TOTAL HT'] = $totalHt; - } } public function DrawBankAndTotalPriceInfo() { $startOfYAfterMainTable = 239; $this->SetY($startOfYAfterMainTable); - $this->SetFont('ComicSans', '', 8); + $this->SetFont('Arial', '', 8); $this->MultiCell(0, 4, utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de " . $this->factureData['configuration']->entreprise))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :"))); @@ -473,13 +467,13 @@ class InvoiceGroupPdfHandler extends FPDF //Table IBAN $startOftable = 3; $this->SetX($startOftable); - $this->SetFont('ComicSans', '', 8); + $this->SetFont('Arial', '', 8); $ibanWidth = 62; - $this->Cell($ibanWidth, 6.5, 'IBAN : FR76 1360 6000 1436 5418 1800 038', 1, 1, 'C'); + $this->Cell($ibanWidth, 6.5, 'IBAN : FR76 1670 6052 4453 9757 9734 871', 1, 1, 'C'); $ibanCursorX = $this->GetX(); $this->SetX($startOftable); - $this->Cell($ibanWidth, 6.5, 'Code SWIFT : AGRI FR PP 836', 1, 1, 'C'); + $this->Cell($ibanWidth, 6.5, 'Code SWIFT : AGRI FR PP867', 1, 1, 'C'); //TABLE HT $tableWidth = 48; // Largeur totale de la 2e table (20+20) @@ -489,7 +483,7 @@ class InvoiceGroupPdfHandler extends FPDF $startOfArrayX = $pageWidth - $tableWidth - $marginRight; $startOfArrayY = $startOfYAfterMainTable + 0.5; - $this->SetFont('ComicSans', '', 10); + $this->SetFont('Arial', '', 10); $totalPriceArray = $this->totalPrices; foreach ($totalPriceArray as $label => $price) { $this->SetXY($startOfArrayX, $startOfArrayY); diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index 7846823..e5f82b9 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -42,20 +42,16 @@ class InvoicePdfHandler extends FPDF protected $extgstates = []; private $thereIsOrderOrCaseNumber = false; private $startingYOfArticlesTable = 100; - private $endingYOfArticlesTable = 230; - private $articleTablesHeight = 130; - public $interLigneHeader = 5; - public $hasTva = true; public function Header() { if ($this->logo != "nothing") { - $this->Image($this->logoPath . "logo.png", 4, 2, 50, 35); - $this->AddWatermark(); + $this->Image($this->logoPath . "logo.png", 2, 10, 75, 25); + //$this->AddWatermark(); } else { $this->Cell(55, 30, ''); } @@ -115,7 +111,6 @@ class InvoicePdfHandler extends FPDF { $this->factureData = $factureData; $this->logo = $logo; - // Déterminer si la TVA est applicable $this->hasTva = isset($factureData['is_tva']) ? $factureData['is_tva'] : true; } @@ -124,9 +119,6 @@ class InvoicePdfHandler extends FPDF { $this->multipleFactureData = $multipleInvoiceData; $this->logo = $logo; - - // Pour les factures multiples, vérifier le premier élément ou faire une logique plus complexe - $this->hasTva = isset($multipleInvoiceData[0]['is_tva']) ? $multipleInvoiceData[0]['is_tva'] : true; } public function GetMultipleInvoiceFilename($month, $year) @@ -212,15 +204,14 @@ class InvoicePdfHandler extends FPDF $this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); $clientInfoYAxis += $this->interLigneHeader; + $this->SetXY($clientInfoXAxis, $clientInfoYAxis); // Gestion Siret ou TVA intracommunautaire selon is_tva if ($this->hasTva) { // Avec TVA : afficher le Siret - $this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']); } else { - // Sans TVA : afficher N° TVA intracommunautaire (même si vide) - $this->SetXY($clientInfoXAxis, $clientInfoYAxis); + // Sans TVA : afficher N° TVA intracommunautaire $tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : ''; $this->Cell(0, $this->interLigneHeader, 'TVA intracom : ' . $tvaIntracommu); } @@ -289,22 +280,18 @@ class InvoicePdfHandler extends FPDF $gapBetweenStartingOfArticlesTableAndColumnName = 8; $tableHeight = $this->thereIsOrderOrCaseNumber ? $this->articleTablesHeight : $this->articleTablesHeight + 9; $this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D"); - // cadre titre des colonnes $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); - // les traits verticaux colonnes $additionalMargRight = 1; - $endingLine = $this->thereIsOrderOrCaseNumber ? 231 : 230; + $endingLine = $this->thereIsOrderOrCaseNumber ? 231 : 230; // mois +1 pour le groupe $this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine); + $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); if ($this->hasTva) { - $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); $this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); } else { - // Sans TVA : garder la ligne séparatrice Description/Prix HT - $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); } } @@ -312,27 +299,25 @@ class InvoicePdfHandler extends FPDF private function DrawArticlesTableHeader() { $additionalMargRight = 1; - $tvaDefault = $this->factureData["configuration"]->tva_default; - + $tvaValue = $this->factureData["configuration"]->tva_default; $columnNameY = $this->startingYOfArticlesTable - 1; $this->SetFont('ComicSans', '', 10); $this->SetXY(12 + $additionalMargRight, $columnNameY); - $this->Cell(7, 10, "Date", 0, 0, 'C'); + $this->Cell(7, 10, "", 0, 0, 'C'); + $this->SetXY(30 + $additionalMargRight, $columnNameY); $this->Cell(100, 10, "Description", 0, 0, 'C'); + $this->SetXY(143 + $additionalMargRight, $columnNameY); + $this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C'); + if ($this->hasTva) { - // Avec TVA : 3 colonnes - $this->SetXY(145 + $additionalMargRight, $columnNameY); - $this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C'); $this->SetXY(163 + $additionalMargRight, $columnNameY); - $this->Cell(20, 10, 'TVA ' . $tvaDefault . '%', 0, 0, 'C'); + $this->Cell(20, 10, 'TVA ' . $tvaValue . '%', 0, 0, 'C'); + $this->SetXY(185, $columnNameY); $this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C'); } else { - // Sans TVA : 2 colonnes - $this->SetXY(145 + $additionalMargRight, $columnNameY); - $this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C'); $this->SetXY(185, $columnNameY); $this->Cell(20, 10, "Montant HT", 0, 0, 'C'); } @@ -344,9 +329,7 @@ class InvoicePdfHandler extends FPDF $devisDate = $this->factureData['devis_date']; $devisDate = DateTime::createFromFormat('Y-m-d', $devisDate); $devisDate = $devisDate->format('d-m-Y'); - - $tvaDefault = $this->factureData["configuration"]->tva_default; - + $tvaValue = $this->factureData["configuration"]->tva_default; $totalHt = 0; $totalTtc = 0; $totalTva = 0; @@ -358,21 +341,18 @@ class InvoicePdfHandler extends FPDF $valueHt = $product['produit_price'] * $product['quantite']; if ($this->hasTva) { - // Client soumis à la TVA - $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaDefault); + $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue); $tvaAmount = $valueTtc - $valueHt; } else { - // Client exonéré - pas de TVA - $valueTtc = $valueHt; + $valueTtc = $valueHt; // Sans TVA, TTC = HT $tvaAmount = 0; } $totalHt += $valueHt; $totalTtc += $valueTtc; - $totalTva += $tvaAmount; - $productDescription = $product["produit_description"]; $dateValue = ""; + if ($product === end($products)) { $dateValue = $devisDate; $productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->factureData['defunt_sexe']) . ' ' . $this->factureData["defunt_nom"]; @@ -380,41 +360,40 @@ class InvoicePdfHandler extends FPDF $this->SetXY(5, $yValue); $this->Cell(5, 6, $dateValue, 0, 0); + $this->SetXY(30, $yValue); $this->MultiAlignCell($maxDescriptionWidth, 6, utf8_decode(html_entity_decode($productDescription)), 0, '0', ); + $this->SetXY(144, $yValue); + $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); + if ($this->hasTva) { - $this->SetXY(146, $yValue); - $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); $this->SetXY(165, $yValue); $this->Cell(20, 6, number_format($tvaAmount, 2, '.', '') . chr(128), 0, 0, 'C'); + $this->SetXY(182, $yValue); $this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C'); } else { - // Sans TVA : 2 colonnes - $this->SetXY(146, $yValue); - $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); $this->SetXY(182, $yValue); $this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C'); } $yValue += 12; + $totalTva += $tvaAmount; } - // Construire le tableau de retour selon la TVA + // Construction du tableau de retour selon hasTva if ($this->hasTva) { - $result = [ + return [ "TOTAL HT" => $totalHt, - "TVA " . $tvaDefault . "%" => $totalTva, + "TVA " . $tvaValue . "%" => $totalTva, "TOTAL TTC" => $totalTtc ]; } else { - $result = [ + return [ "TOTAL HT" => $totalHt ]; } - - return $result; } private function DrawBankAndTotalPriceInfo($totalPriceArray)