fix template final

This commit is contained in:
Tolotsoa 2025-08-27 14:34:24 +03:00
parent 4ce0f3c350
commit 07dcd6d91d
3 changed files with 121 additions and 142 deletions

View File

@ -5581,11 +5581,17 @@ COMMENTAIRES: ".$comment;
$tvaLabel = "TVA 0 %"; $tvaLabel = "TVA 0 %";
} }
$totaPricesArray = [ if($hasTva) {
"TOTAL HT" => $totalHt, $totaPricesArray = [
$tvaLabel => $totalTva, "TOTAL HT" => $totalHt,
"TOTAL TTC" => $totalTtc $tvaLabel => $totalTva,
]; "TOTAL TTC" => $totalTtc
];
} else {
$totaPricesArray = [
"TOTAL HT" => $totalHt
];
}
$factureData["is_tva"] = $hasTva; $factureData["is_tva"] = $hasTva;
$factureData["devis"] = $factureDevisList; $factureData["devis"] = $factureDevisList;

View File

@ -50,10 +50,9 @@ class InvoiceGroupPdfHandler extends FPDF
public $thereIsOrderOrCaseNumber = false; public $thereIsOrderOrCaseNumber = false;
public $startingYOfArticlesTable = 100; public $startingYOfArticlesTable = 100;
public int $maxArticlePerPage = 19; public int $maxArticlePerPage = 7;
public $additionalArticlesLineBasedOnMultiline = 0; public $additionalArticlesLineBasedOnMultiline = 0;
public $interLigneHeader = 5; public $interLigneHeader = 5;
public $hasTva = true; public $hasTva = true;
public function Header() public function Header()
@ -70,27 +69,32 @@ class InvoiceGroupPdfHandler extends FPDF
} }
public function AddWatermark() public function AddWatermark()
{ {
$this->SetAlpha(0.2); try {
$this->SetAlpha(0.2);
$imagePath = $this->logoPath . "filigrane_pdf.png"; $imagePath = $this->logoPath . "filigrane_pdf.png";
list($originalWidth, $originalHeight) = getimagesize($imagePath); 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)
// 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; $originalWidth = $originalWidth * 0.264583;
$originalHeight = $originalHeight * 0.264583; $originalHeight = $originalHeight * 0.264583;
// Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine
$scale = 1.7; $scale = 1.7;
$width = $originalWidth * $scale; $width = $originalWidth * $scale;
$height = $originalHeight * $scale; $height = $originalHeight * $scale;
// Calculer la position pour centrer l'image // Calculer la position pour centrer l'image
$x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm $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 $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) public function SetAlpha($alpha)
@ -111,7 +115,7 @@ class InvoiceGroupPdfHandler extends FPDF
public function Footer() public function Footer()
{ {
$this->SetY(-34); $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('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.'))); $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->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->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'); $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() public function DrawInvoiceCompanyInfo()
{ {
$this->SetY(40); $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']->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']), 0, 1);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 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, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone), 0, 1);
$this->Cell(0, $this->interLigneHeader, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1); $this->Cell(0, $this->interLigneHeader, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
} }
public function DrawInvoiceClientInfo() public function DrawInvoiceClientInfo()
{ {
$this->SetFont('ComicSans', '', 10); $this->SetFont('Arial', '', 10);
$clientName = $this->factureData['group_name']; $clientName = $this->factureData['group_name'];
$clientInfoXAxis = 135; $clientInfoXAxis = 135;
@ -193,6 +196,7 @@ class InvoiceGroupPdfHandler extends FPDF
$addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo; $addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo;
$addressIsMoreThanTwoLines = ($addressWidth / $availableWidhtForClientInfo) > 2; $addressIsMoreThanTwoLines = ($addressWidth / $availableWidhtForClientInfo) > 2;
$clientInfoYAxis = $addressIsMoreThanTwoLines ? 35 : 40; $clientInfoYAxis = $addressIsMoreThanTwoLines ? 35 : 40;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName)); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName));
@ -221,6 +225,7 @@ class InvoiceGroupPdfHandler extends FPDF
} else { } else {
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
} }
} else { } else {
$clientAddresses = explode(",", $clientAddress); $clientAddresses = explode(",", $clientAddress);
foreach ($clientAddresses as $address) { foreach ($clientAddresses as $address) {
@ -258,7 +263,7 @@ class InvoiceGroupPdfHandler extends FPDF
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']); $this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
} }
} else { } else {
// Sans TVA : afficher N° TVA intracommunautaire (même si vide) // Sans TVA : afficher N° TVA intracommunautaire
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : ''; $tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : '';
@ -266,6 +271,8 @@ class InvoiceGroupPdfHandler extends FPDF
} }
} }
public function DrawInvoiceInfoTable() public function DrawInvoiceInfoTable()
{ {
$startInvoiceInfoTable = 70; $startInvoiceInfoTable = 70;
@ -278,13 +285,13 @@ class InvoiceGroupPdfHandler extends FPDF
$factureDateEcheance->modify('last day of next month'); $factureDateEcheance->modify('last day of next month');
$factureDateEcheance = $factureDateEcheance->format('d-m-Y'); $factureDateEcheance = $factureDateEcheance->format('d-m-Y');
$this->SetFont('ComicSans', '', 10); $this->SetFont('Arial', '', 10);
$this->Cell(25, 7, 'DATE', 1, 0, 'C'); $this->Cell(25, 7, 'DATE', 1, 0, 'C');
$this->Cell(104, 7, 'CLIENT', 1, 0, 'C'); $this->Cell(104, 7, 'CLIENT', 1, 0, 'C');
$this->Cell(39, 7, 'FACTURE', 1, 0, 'C'); $this->Cell(39, 7, 'FACTURE', 1, 0, 'C');
$this->Cell(36, 7, 'ECHEANCE', 1, 1, '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(25, 7, $factureDatePaiement, 1, 0, 'C');
$this->Cell(104, 7, utf8_decode(html_entity_decode($this->factureData['group_name'])), 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'); $this->Cell(39, 7, $this->factureData['num'], 1, 0, 'C');
@ -295,30 +302,25 @@ class InvoiceGroupPdfHandler extends FPDF
public function DrawArticlesTableRect() public function DrawArticlesTableRect()
{ {
$this->SetLineWidth(0.2); $this->SetLineWidth(0.2);
$gapBetweenStartingOfArticlesTableAndColumnName = 7; $gapBetweenStartingOfArticlesTableAndColumnName = 7;
$additionnalheight = 0.75; $additionnalheight = 0.75;
$tableHeight = $this->thereIsOrderOrCaseNumber ? (137 + $additionnalheight) : (137 + 6 + $additionnalheight); $tableHeight = $this->thereIsOrderOrCaseNumber ? (137 + $additionnalheight) : (137 + 6 + $additionnalheight);
$this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D"); $this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D");
// $this->RoundedRect(3, $this->startingYOfArticlesTable, 204, $tableHeight,5 ,'1234',"D");
// Cadre titre des colonnes // cadre titre des colonnes
$this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName);
// les traits verticaux colonnes
// Les traits verticaux colonnes
$additionalMargRight = 1; $additionalMargRight = 1;
$endingLine = 233 + $additionnalheight; $endingLine = $this->startingYOfArticlesTable + $tableHeight;
// Lignes verticales communes
$this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine); $this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine);
$this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine);
if ($this->hasTva) { 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(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine);
$this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine);
} else { } 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); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine);
} }
} }
@ -328,26 +330,23 @@ class InvoiceGroupPdfHandler extends FPDF
$additionalMargRight = 1; $additionalMargRight = 1;
$tvaValue = $this->factureData["configuration"]->tva_default; $tvaValue = $this->factureData["configuration"]->tva_default;
$columnNameY = $this->startingYOfArticlesTable - 1.5; $columnNameY = $this->startingYOfArticlesTable - 1.5;
$this->SetFont('ComicSans', '', 10); $this->SetFont('Arial', '', 10);
$this->SetXY(35 + $additionalMargRight, $columnNameY);
$this->SetXY(12 + $additionalMargRight, $columnNameY); $this->Cell(7, 10, "", 0, 0, 'C');
$this->Cell(7, 10, "Date", 0, 0, 'C');
$this->SetXY(30 + $additionalMargRight, $columnNameY); $this->SetXY(30 + $additionalMargRight, $columnNameY);
$this->Cell(100, 10, "Description", 0, 0, 'C'); $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) { 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->SetXY(163 + $additionalMargRight, $columnNameY);
$this->Cell(20, 10, 'TVA ' . $tvaValue . '%', 0, 0, 'C'); $this->Cell(20, 10, 'TVA ' . $tvaValue . '%', 0, 0, 'C');
$this->SetXY(185, $columnNameY); $this->SetXY(185, $columnNameY);
$this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C'); $this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C');
} else { } 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->SetXY(185, $columnNameY);
$this->Cell(20, 10, "Montant HT", 0, 0, 'C'); $this->Cell(20, 10, "Montant HT", 0, 0, 'C');
} }
@ -355,16 +354,19 @@ class InvoiceGroupPdfHandler extends FPDF
public function DrawArticlesTableValue() public function DrawArticlesTableValue()
{ {
$this->SetFont('ComicSans', '', 10); // Set espacement avant de continue
$this->SetFont('Arial', '', 10);
$devisData = $this->factureData['devis']; $devisData = $this->factureData['devis'];
$tvaValue = $this->factureData["configuration"]->tva_default; $tvaValue = $this->factureData["configuration"]->tva_default;
$totalHt = 0; $totalHt = 0;
$totalTtc = 0; $totalTtc = 0;
$totalTva = 0; $totalTva = 0;
$yValue = $this->startingYOfArticlesTable + 13; $yValue = $this->startingYOfArticlesTable + 13;
// $maxDescriptionWidth = 102;
$maxDescriptionWidth = 104.3; $maxDescriptionWidth = 104.3;
// $maxDescriptionWidth = 51;
$currentIndexPosition = $this->currentIndexPosition; $currentIndexPosition = $this->currentIndexPosition;
for ($currentIndexPosition; $currentIndexPosition < ($this->initialIndexPosition + $this->devisCountToGet); $currentIndexPosition++) { for ($currentIndexPosition; $currentIndexPosition < ($this->initialIndexPosition + $this->devisCountToGet); $currentIndexPosition++) {
$currentDevis = $devisData[$currentIndexPosition]; $currentDevis = $devisData[$currentIndexPosition];
$devisDate = $currentDevis['devis_date']; $devisDate = $currentDevis['devis_date'];
@ -372,10 +374,9 @@ class InvoiceGroupPdfHandler extends FPDF
$devisDate = $devisDate->format('d-m-Y'); $devisDate = $devisDate->format('d-m-Y');
$products = $currentDevis["products"]; $products = $currentDevis["products"];
$productIncrement = 0; $productIncrement = 0;
foreach ($products as $product) { foreach ($products as $product) {
$valueHt = $product['produit_price'] * $product["quantite"];
$valueHt = $product['produit_price'] * $product["quantite"];
if ($this->hasTva) { if ($this->hasTva) {
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue); $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
$tvaAmount = $valueTtc - $valueHt; $tvaAmount = $valueTtc - $valueHt;
@ -386,26 +387,26 @@ class InvoiceGroupPdfHandler extends FPDF
$totalHt += $valueHt; $totalHt += $valueHt;
$totalTtc += $valueTtc; $totalTtc += $valueTtc;
$totalTva += $tvaAmount;
$productDescription = $product["produit_description"] ?? ""; $productDescription = $product["produit_description"] ?? "";
$currentDevisDefuntName = $currentDevis["defunt_nom"] ?? "";
$dateValue = ""; $dateValue = "";
$dateAndDefuntName = "";
if ($productIncrement == 0) { if ($productIncrement == 0) {
$dateValue = $devisDate; $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(30, $yValue + 5);
$this->SetXY(4, $yValue);
$this->Cell(5, 6, $dateValue, 0, 0);
// Description (avec gestion multiligne)
$this->SetXY(30, $yValue);
$productDescription = FileExportHelpers::FormatTextForExport($productDescription); $productDescription = FileExportHelpers::FormatTextForExport($productDescription);
$productDescriptionWidth = $this->GetStringWidth($productDescription); $productDescriptionWidth = $this->GetStringWidth($productDescription);
$productDescriptionWidthIsGreaterThanMaxWidth = $productDescriptionWidth > $maxDescriptionWidth; $productDescriptionWidthIsGreaterThanMaxWidth = $productDescriptionWidth > $maxDescriptionWidth;
$productDescriptionIsMultiline = false; $productDescriptionIsMultiline = false;
if ($productDescriptionWidthIsGreaterThanMaxWidth) { if ($productDescriptionWidthIsGreaterThanMaxWidth) {
$yBefore = $this->GetY(); $yBefore = $this->GetY();
$this->MultiCell($maxDescriptionWidth, 6, $productDescription, 0, 'L'); $this->MultiCell($maxDescriptionWidth, 6, $productDescription, 0, 'L');
@ -418,54 +419,47 @@ class InvoiceGroupPdfHandler extends FPDF
$this->Cell($maxDescriptionWidth, 6, $productDescription); $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) { if ($this->hasTva) {
// Prix HT $this->SetXY(165, $yValue + 5);
$this->SetXY(146, $yValue);
$this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C');
// TVA
$this->SetXY(165, $yValue);
$this->Cell(20, 6, number_format($tvaAmount, 2, '.', '') . chr(128), 0, 0, 'C'); $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'); $this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C');
} else { } else {
// Sans TVA : 2 colonnes (Prix HT | Montant HT) $this->SetXY(182, $yValue + 5);
$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'); $this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C');
} }
$yValue += 6; $yValue += 6;
$totalTva += $tvaAmount;
if ($productDescriptionWidthIsGreaterThanMaxWidth) { if ($productDescriptionWidthIsGreaterThanMaxWidth) {
$yValue += 6; $yValue += 6;
} }
$productIncrement++; $productIncrement++;
} }
$yValue += 6;
$isLastLigneDevis = $currentIndexPosition == (($this->initialIndexPosition + $this->devisCountToGet) - 1);
if (!$isLastLigneDevis) {
$this->Line(3, $yValue, 207, $yValue);
}
} }
$this->currentIndexPosition = $currentIndexPosition; $this->currentIndexPosition = $currentIndexPosition;
$this->initialIndexPosition = $this->currentIndexPosition; $this->initialIndexPosition = $this->currentIndexPosition;
$chargedDevisCount = $this->currentIndexPosition + 1; $chargedDevisCount = $this->currentIndexPosition + 1;
$devisLeftToGet = $this->devisCount - $chargedDevisCount; $devisLeftToGet = $this->devisCount - $chargedDevisCount;
$this->devisCountToGet = ($devisLeftToGet < $this->maxArticlePerPage) ? $devisLeftToGet + 1 : $this->maxArticlePerPage; $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() public function DrawBankAndTotalPriceInfo()
{ {
$startOfYAfterMainTable = 239; $startOfYAfterMainTable = 239;
$this->SetY($startOfYAfterMainTable); $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("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 :"))); $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 //Table IBAN
$startOftable = 3; $startOftable = 3;
$this->SetX($startOftable); $this->SetX($startOftable);
$this->SetFont('ComicSans', '', 8); $this->SetFont('Arial', '', 8);
$ibanWidth = 62; $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(); $ibanCursorX = $this->GetX();
$this->SetX($startOftable); $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 //TABLE HT
$tableWidth = 48; // Largeur totale de la 2e table (20+20) $tableWidth = 48; // Largeur totale de la 2e table (20+20)
@ -489,7 +483,7 @@ class InvoiceGroupPdfHandler extends FPDF
$startOfArrayX = $pageWidth - $tableWidth - $marginRight; $startOfArrayX = $pageWidth - $tableWidth - $marginRight;
$startOfArrayY = $startOfYAfterMainTable + 0.5; $startOfArrayY = $startOfYAfterMainTable + 0.5;
$this->SetFont('ComicSans', '', 10); $this->SetFont('Arial', '', 10);
$totalPriceArray = $this->totalPrices; $totalPriceArray = $this->totalPrices;
foreach ($totalPriceArray as $label => $price) { foreach ($totalPriceArray as $label => $price) {
$this->SetXY($startOfArrayX, $startOfArrayY); $this->SetXY($startOfArrayX, $startOfArrayY);

View File

@ -42,20 +42,16 @@ class InvoicePdfHandler extends FPDF
protected $extgstates = []; protected $extgstates = [];
private $thereIsOrderOrCaseNumber = false; private $thereIsOrderOrCaseNumber = false;
private $startingYOfArticlesTable = 100; private $startingYOfArticlesTable = 100;
private $endingYOfArticlesTable = 230; private $endingYOfArticlesTable = 230;
private $articleTablesHeight = 130; private $articleTablesHeight = 130;
public $interLigneHeader = 5; public $interLigneHeader = 5;
public $hasTva = true; public $hasTva = true;
public function Header() public function Header()
{ {
if ($this->logo != "nothing") { if ($this->logo != "nothing") {
$this->Image($this->logoPath . "logo.png", 4, 2, 50, 35); $this->Image($this->logoPath . "logo.png", 2, 10, 75, 25);
$this->AddWatermark(); //$this->AddWatermark();
} else { } else {
$this->Cell(55, 30, ''); $this->Cell(55, 30, '');
} }
@ -115,7 +111,6 @@ class InvoicePdfHandler extends FPDF
{ {
$this->factureData = $factureData; $this->factureData = $factureData;
$this->logo = $logo; $this->logo = $logo;
// Déterminer si la TVA est applicable // Déterminer si la TVA est applicable
$this->hasTva = isset($factureData['is_tva']) ? $factureData['is_tva'] : true; $this->hasTva = isset($factureData['is_tva']) ? $factureData['is_tva'] : true;
} }
@ -124,9 +119,6 @@ class InvoicePdfHandler extends FPDF
{ {
$this->multipleFactureData = $multipleInvoiceData; $this->multipleFactureData = $multipleInvoiceData;
$this->logo = $logo; $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) public function GetMultipleInvoiceFilename($month, $year)
@ -212,15 +204,14 @@ class InvoicePdfHandler extends FPDF
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); $this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city'])));
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
// Gestion Siret ou TVA intracommunautaire selon is_tva // Gestion Siret ou TVA intracommunautaire selon is_tva
if ($this->hasTva) { if ($this->hasTva) {
// Avec TVA : afficher le Siret // Avec TVA : afficher le Siret
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']); $this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
} else { } else {
// Sans TVA : afficher N° TVA intracommunautaire (même si vide) // Sans TVA : afficher N° TVA intracommunautaire
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : ''; $tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : '';
$this->Cell(0, $this->interLigneHeader, 'TVA intracom : ' . $tvaIntracommu); $this->Cell(0, $this->interLigneHeader, 'TVA intracom : ' . $tvaIntracommu);
} }
@ -289,22 +280,18 @@ class InvoicePdfHandler extends FPDF
$gapBetweenStartingOfArticlesTableAndColumnName = 8; $gapBetweenStartingOfArticlesTableAndColumnName = 8;
$tableHeight = $this->thereIsOrderOrCaseNumber ? $this->articleTablesHeight : $this->articleTablesHeight + 9; $tableHeight = $this->thereIsOrderOrCaseNumber ? $this->articleTablesHeight : $this->articleTablesHeight + 9;
$this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D"); $this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D");
// cadre titre des colonnes // cadre titre des colonnes
$this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName);
// les traits verticaux colonnes // les traits verticaux colonnes
$additionalMargRight = 1; $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(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine);
$this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine);
if ($this->hasTva) { if ($this->hasTva) {
$this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine);
$this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine); $this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine);
$this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine);
} else { } 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); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine);
} }
} }
@ -312,27 +299,25 @@ class InvoicePdfHandler extends FPDF
private function DrawArticlesTableHeader() private function DrawArticlesTableHeader()
{ {
$additionalMargRight = 1; $additionalMargRight = 1;
$tvaDefault = $this->factureData["configuration"]->tva_default; $tvaValue = $this->factureData["configuration"]->tva_default;
$columnNameY = $this->startingYOfArticlesTable - 1; $columnNameY = $this->startingYOfArticlesTable - 1;
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 10);
$this->SetXY(12 + $additionalMargRight, $columnNameY); $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->SetXY(30 + $additionalMargRight, $columnNameY);
$this->Cell(100, 10, "Description", 0, 0, 'C'); $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) { 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->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->SetXY(185, $columnNameY);
$this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C'); $this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C');
} else { } 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->SetXY(185, $columnNameY);
$this->Cell(20, 10, "Montant HT", 0, 0, 'C'); $this->Cell(20, 10, "Montant HT", 0, 0, 'C');
} }
@ -344,9 +329,7 @@ class InvoicePdfHandler extends FPDF
$devisDate = $this->factureData['devis_date']; $devisDate = $this->factureData['devis_date'];
$devisDate = DateTime::createFromFormat('Y-m-d', $devisDate); $devisDate = DateTime::createFromFormat('Y-m-d', $devisDate);
$devisDate = $devisDate->format('d-m-Y'); $devisDate = $devisDate->format('d-m-Y');
$tvaValue = $this->factureData["configuration"]->tva_default;
$tvaDefault = $this->factureData["configuration"]->tva_default;
$totalHt = 0; $totalHt = 0;
$totalTtc = 0; $totalTtc = 0;
$totalTva = 0; $totalTva = 0;
@ -358,21 +341,18 @@ class InvoicePdfHandler extends FPDF
$valueHt = $product['produit_price'] * $product['quantite']; $valueHt = $product['produit_price'] * $product['quantite'];
if ($this->hasTva) { if ($this->hasTva) {
// Client soumis à la TVA $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaDefault);
$tvaAmount = $valueTtc - $valueHt; $tvaAmount = $valueTtc - $valueHt;
} else { } else {
// Client exonéré - pas de TVA $valueTtc = $valueHt; // Sans TVA, TTC = HT
$valueTtc = $valueHt;
$tvaAmount = 0; $tvaAmount = 0;
} }
$totalHt += $valueHt; $totalHt += $valueHt;
$totalTtc += $valueTtc; $totalTtc += $valueTtc;
$totalTva += $tvaAmount;
$productDescription = $product["produit_description"]; $productDescription = $product["produit_description"];
$dateValue = ""; $dateValue = "";
if ($product === end($products)) { if ($product === end($products)) {
$dateValue = $devisDate; $dateValue = $devisDate;
$productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->factureData['defunt_sexe']) . ' ' . $this->factureData["defunt_nom"]; $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->SetXY(5, $yValue);
$this->Cell(5, 6, $dateValue, 0, 0); $this->Cell(5, 6, $dateValue, 0, 0);
$this->SetXY(30, $yValue); $this->SetXY(30, $yValue);
$this->MultiAlignCell($maxDescriptionWidth, 6, utf8_decode(html_entity_decode($productDescription)), 0, '0', ); $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) { 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->SetXY(165, $yValue);
$this->Cell(20, 6, number_format($tvaAmount, 2, '.', '') . chr(128), 0, 0, 'C'); $this->Cell(20, 6, number_format($tvaAmount, 2, '.', '') . chr(128), 0, 0, 'C');
$this->SetXY(182, $yValue); $this->SetXY(182, $yValue);
$this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C'); $this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C');
} else { } 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->SetXY(182, $yValue);
$this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C'); $this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C');
} }
$yValue += 12; $yValue += 12;
$totalTva += $tvaAmount;
} }
// Construire le tableau de retour selon la TVA // Construction du tableau de retour selon hasTva
if ($this->hasTva) { if ($this->hasTva) {
$result = [ return [
"TOTAL HT" => $totalHt, "TOTAL HT" => $totalHt,
"TVA " . $tvaDefault . "%" => $totalTva, "TVA " . $tvaValue . "%" => $totalTva,
"TOTAL TTC" => $totalTtc "TOTAL TTC" => $totalTtc
]; ];
} else { } else {
$result = [ return [
"TOTAL HT" => $totalHt "TOTAL HT" => $totalHt
]; ];
} }
return $result;
} }
private function DrawBankAndTotalPriceInfo($totalPriceArray) private function DrawBankAndTotalPriceInfo($totalPriceArray)