feat change template pdf HT
This commit is contained in:
parent
e11d11f10a
commit
b5c15c0425
@ -3522,6 +3522,13 @@ class Bdd
|
||||
$products = $this->getDevisProduits($invoice["devis_id"]);
|
||||
$invoice["products"] = $products;
|
||||
$invoice["configuration"] = $configuration;
|
||||
// Déterminer la TVA pour cette facture
|
||||
$hasTva = true; // Valeur par défaut
|
||||
if(isset($invoice['client_id']) && $invoice['client_id']) {
|
||||
$client = $this->getClientById($invoice['client_id']);
|
||||
$hasTva = ($client && isset($client['tva'])) ? ($client['tva'] == 1) : true;
|
||||
}
|
||||
$invoice["is_tva"] = $hasTva;
|
||||
|
||||
$isClientInsideGroup = $invoice["group_id"] != null;
|
||||
if($isClientInsideGroup) {
|
||||
@ -5441,6 +5448,13 @@ COMMENTAIRES: ".$comment;
|
||||
$defaultTvaValue = $configuration->tva_default;
|
||||
$factureData = $this->getFactureByFactureId($factureId);
|
||||
$isFactureForSingleClient = $factureData['fk_client_id'] != null && $factureData['fk_client_id'] != 0;
|
||||
|
||||
$hasTva = true; // Valeur par défaut
|
||||
if($isFactureForSingleClient) {
|
||||
$client = $this->getClientById($factureData['fk_client_id']);
|
||||
$hasTva = ($client && isset($client['tva'])) ? ($client['tva'] == 1) : true;
|
||||
}
|
||||
|
||||
$devisMentionFilters = [
|
||||
DevisMentionConstant::FACTURED_FORMATTED,
|
||||
DevisMentionConstant::FACTURED
|
||||
@ -5564,7 +5578,7 @@ COMMENTAIRES: ".$comment;
|
||||
} elseif($globalTvaValue > 0) {
|
||||
$tvaLabel = "TVA ".$globalTvaValue. "%";
|
||||
} else {
|
||||
$tvaLabel = "TVA (exonéré)";
|
||||
$tvaLabel = "TVA 0 %";
|
||||
}
|
||||
|
||||
$totaPricesArray = [
|
||||
@ -5573,6 +5587,7 @@ COMMENTAIRES: ".$comment;
|
||||
"TOTAL TTC" => $totalTtc
|
||||
];
|
||||
|
||||
$factureData["is_tva"] = $hasTva;
|
||||
$factureData["devis"] = $factureDevisList;
|
||||
$factureData["configuration"] = $configuration;
|
||||
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
||||
|
||||
@ -54,6 +54,8 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
public $additionalArticlesLineBasedOnMultiline = 0;
|
||||
public $interLigneHeader = 5;
|
||||
|
||||
public $hasTva = true;
|
||||
|
||||
public function Header()
|
||||
{
|
||||
if ($this->logo != "nothing") {
|
||||
@ -132,6 +134,8 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
$this->devisCountToGet = ($this->devisCount <= $this->maxArticlePerPage) ? $this->devisCount : $this->maxArticlePerPage;
|
||||
$this->devisList = $this->factureData['devis'];
|
||||
$this->logo = $logo;
|
||||
// Déterminer si la TVA est applicable
|
||||
$this->hasTva = isset($factureData['is_tva']) ? $factureData['is_tva'] : true;
|
||||
}
|
||||
|
||||
public function GetInvoiceFilename()
|
||||
@ -174,6 +178,7 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
$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);
|
||||
@ -188,7 +193,6 @@ 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));
|
||||
@ -217,7 +221,6 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
} else {
|
||||
$clientInfoYAxis += $this->interLigneHeader;
|
||||
}
|
||||
|
||||
} else {
|
||||
$clientAddresses = explode(",", $clientAddress);
|
||||
foreach ($clientAddresses as $address) {
|
||||
@ -245,15 +248,24 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
}
|
||||
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
|
||||
$this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city'])));
|
||||
if ($this->factureData['siret']) {
|
||||
|
||||
// Gestion Siret ou TVA intracommunautaire selon is_tva
|
||||
if ($this->hasTva) {
|
||||
// Avec TVA : afficher le Siret
|
||||
if ($this->factureData['siret']) {
|
||||
$clientInfoYAxis += $this->interLigneHeader;
|
||||
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
|
||||
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
|
||||
}
|
||||
} else {
|
||||
// Sans TVA : afficher N° TVA intracommunautaire (même si vide)
|
||||
$clientInfoYAxis += $this->interLigneHeader;
|
||||
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
|
||||
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
|
||||
$tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : '';
|
||||
$this->Cell(0, $this->interLigneHeader, 'TVA intracom : ' . $tvaIntracommu);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function DrawInvoiceInfoTable()
|
||||
{
|
||||
$startInvoiceInfoTable = 70;
|
||||
@ -283,22 +295,31 @@ 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");
|
||||
// $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);
|
||||
// les traits verticaux colonnes
|
||||
|
||||
// Les traits verticaux colonnes
|
||||
$additionalMargRight = 1;
|
||||
$endingLine = 233 + $additionnalheight;
|
||||
|
||||
// Lignes verticales communes
|
||||
$this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine);
|
||||
$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);
|
||||
|
||||
if ($this->hasTva) {
|
||||
// Avec TVA : 3 colonnes de prix (Date | Description | HT | TVA | TTC)
|
||||
$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 seulement (Date | Description | HT)
|
||||
$this->Line(165 + $additionalMargRight, $this->startingYOfArticlesTable, 165 + $additionalMargRight, $endingLine);
|
||||
}
|
||||
}
|
||||
|
||||
public function DrawArticlesTableHeader()
|
||||
@ -307,26 +328,30 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
$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->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');
|
||||
|
||||
$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');
|
||||
if ($this->hasTva) {
|
||||
// Avec TVA : HT | TVA | TTC
|
||||
$this->SetXY(145 + $additionalMargRight, $columnNameY); // Décalé de 145 au lieu de 143
|
||||
$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 : seulement HT
|
||||
$this->SetXY(167, $columnNameY); // Décalé de 167 au lieu de 165
|
||||
$this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C');
|
||||
}
|
||||
}
|
||||
|
||||
public function DrawArticlesTableValue()
|
||||
{
|
||||
// Set espacement avant de continue
|
||||
|
||||
$this->SetFont('ComicSans', '', 10);
|
||||
$devisData = $this->factureData['devis'];
|
||||
$tvaValue = $this->factureData["configuration"]->tva_default;
|
||||
@ -334,9 +359,9 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
$totalTtc = 0;
|
||||
$totalTva = 0;
|
||||
$yValue = $this->startingYOfArticlesTable + 13;
|
||||
// $maxDescriptionWidth = 102;
|
||||
$maxDescriptionWidth = 104.3;
|
||||
$currentIndexPosition = $this->currentIndexPosition;
|
||||
|
||||
for ($currentIndexPosition; $currentIndexPosition < ($this->initialIndexPosition + $this->devisCountToGet); $currentIndexPosition++) {
|
||||
$currentDevis = $devisData[$currentIndexPosition];
|
||||
$devisDate = $currentDevis['devis_date'];
|
||||
@ -344,27 +369,40 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
$devisDate = $devisDate->format('d-m-Y');
|
||||
$products = $currentDevis["products"];
|
||||
$productIncrement = 0;
|
||||
foreach ($products as $product) {
|
||||
|
||||
foreach ($products as $product) {
|
||||
$valueHt = $product['produit_price'] * $product["quantite"];
|
||||
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
|
||||
|
||||
if ($this->hasTva) {
|
||||
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
} else {
|
||||
$valueTtc = $valueHt; // Sans TVA, TTC = HT
|
||||
$tvaAmount = 0;
|
||||
}
|
||||
|
||||
$totalHt += $valueHt;
|
||||
$totalTtc += $valueTtc;
|
||||
$totalTva += $tvaAmount;
|
||||
|
||||
$productDescription = $product["produit_description"] ?? "";
|
||||
$dateValue = "";
|
||||
if ($productIncrement == 0) {
|
||||
$dateValue = $devisDate;
|
||||
$productDescription .= " de " . $currentDevis["defunt_nom"] ?? "";
|
||||
}
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
|
||||
// Date
|
||||
$this->SetXY(4, $yValue);
|
||||
$this->Cell(5, 6, $dateValue, 0, 0);
|
||||
|
||||
// Description (avec gestion multiligne)
|
||||
$this->SetXY(30, $yValue);
|
||||
$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');
|
||||
@ -377,29 +415,45 @@ class InvoiceGroupPdfHandler extends FPDF
|
||||
$this->Cell($maxDescriptionWidth, 6, $productDescription);
|
||||
}
|
||||
|
||||
if ($this->hasTva) {
|
||||
// Prix HT
|
||||
$this->SetXY(146, $yValue); // Décalé de 146 au lieu de 144
|
||||
$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');
|
||||
// Prix TTC
|
||||
$this->SetXY(182, $yValue);
|
||||
$this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C');
|
||||
} else {
|
||||
// Sans TVA : seulement Prix HT
|
||||
$this->SetXY(167, $yValue); // Décalé de 167 au lieu de 165
|
||||
$this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C');
|
||||
}
|
||||
|
||||
$this->SetXY(144, $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');
|
||||
$yValue += 6;
|
||||
$totalTva += $tvaAmount;
|
||||
if ($productDescriptionWidthIsGreaterThanMaxWidth) {
|
||||
$yValue += 6;
|
||||
}
|
||||
$productIncrement++;
|
||||
}
|
||||
}
|
||||
|
||||
$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()
|
||||
|
||||
@ -48,6 +48,9 @@ class InvoicePdfHandler extends FPDF
|
||||
private $articleTablesHeight = 130;
|
||||
|
||||
public $interLigneHeader = 5;
|
||||
|
||||
public $hasTva = true;
|
||||
|
||||
public function Header()
|
||||
{
|
||||
if ($this->logo != "nothing") {
|
||||
@ -112,12 +115,18 @@ 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;
|
||||
}
|
||||
|
||||
public function MutlipleInvoicePdfFactory(array $multipleInvoiceData, $logo = null)
|
||||
{
|
||||
$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)
|
||||
@ -155,6 +164,7 @@ class InvoicePdfHandler extends FPDF
|
||||
$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);
|
||||
}
|
||||
|
||||
private function DrawInvoiceClientInfo()
|
||||
{
|
||||
$this->SetFont('ComicSans', '', 10);
|
||||
@ -202,8 +212,19 @@ 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);
|
||||
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
|
||||
|
||||
// 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);
|
||||
$tvaIntracommu = isset($this->factureData['group_tva_intracommu']) ? $this->factureData['group_tva_intracommu'] : '';
|
||||
$this->Cell(0, $this->interLigneHeader, 'TVA intracom : ' . $tvaIntracommu);
|
||||
}
|
||||
|
||||
$clientInfoYAxis += $this->interLigneHeader;
|
||||
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
|
||||
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']);
|
||||
@ -268,25 +289,30 @@ 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; // mois +1 pour le groupe
|
||||
$endingLine = $this->thereIsOrderOrCaseNumber ? 231 : 230;
|
||||
$this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine);
|
||||
$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);
|
||||
|
||||
if ($this->hasTva) {
|
||||
// Avec TVA : 3 colonnes de prix (Date | Description | HT | TVA | TTC)
|
||||
$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 seulement (Date | Description | HT)
|
||||
$this->Line(165 + $additionalMargRight, $this->startingYOfArticlesTable, 165 + $additionalMargRight, $endingLine);
|
||||
}
|
||||
}
|
||||
|
||||
private function DrawArticlesTableHeader()
|
||||
{
|
||||
$additionalMargRight = 1;
|
||||
$tvaDefault = $this->factureData["configuration"]->tva_default;
|
||||
$clientTvaStatus = isset($this->factureData["tva"]) ? (int)$this->factureData["tva"] : 1;
|
||||
|
||||
// Déterminer le libellé TVA selon le statut du client
|
||||
$tvaLabel = ($clientTvaStatus === 0) ? "TVA 0%" : "TVA " . $tvaDefault . "%";
|
||||
|
||||
$columnNameY = $this->startingYOfArticlesTable - 1;
|
||||
$this->SetFont('ComicSans', '', 10);
|
||||
@ -294,12 +320,20 @@ class InvoicePdfHandler extends FPDF
|
||||
$this->Cell(7, 10, "Date", 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');
|
||||
$this->SetXY(163 + $additionalMargRight, $columnNameY);
|
||||
$this->Cell(20, 10, $tvaLabel, 0, 0, 'C');
|
||||
$this->SetXY(185, $columnNameY);
|
||||
$this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C');
|
||||
|
||||
if ($this->hasTva) {
|
||||
// Avec TVA : HT | TVA | TTC
|
||||
$this->SetXY(145 + $additionalMargRight, $columnNameY); // Décalé de 145 au lieu de 143
|
||||
$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->SetXY(185, $columnNameY);
|
||||
$this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C');
|
||||
} else {
|
||||
// Sans TVA : seulement HT
|
||||
$this->SetXY(167, $columnNameY); // Décalé de 167 au lieu de 165
|
||||
$this->Cell(20, 10, "Prix Uni. HT", 0, 0, 'C');
|
||||
}
|
||||
}
|
||||
|
||||
public function DrawArticlesTableValueAndReturnTotalPrice()
|
||||
@ -310,11 +344,6 @@ class InvoicePdfHandler extends FPDF
|
||||
$devisDate = $devisDate->format('d-m-Y');
|
||||
|
||||
$tvaDefault = $this->factureData["configuration"]->tva_default;
|
||||
$clientTvaStatus = isset($this->factureData["tva"]) ? (int)$this->factureData["tva"] : 1;
|
||||
|
||||
// Déterminer le taux de TVA à appliquer selon le statut du client
|
||||
$tvaValue = ($clientTvaStatus === 0) ? 0 : $tvaDefault;
|
||||
$tvaLabel = ($clientTvaStatus === 0) ? "0%" : $tvaDefault . "%";
|
||||
|
||||
$totalHt = 0;
|
||||
$totalTtc = 0;
|
||||
@ -326,15 +355,14 @@ class InvoicePdfHandler extends FPDF
|
||||
foreach ($products as $product) {
|
||||
$valueHt = $product['produit_price'] * $product['quantite'];
|
||||
|
||||
// Calculer la TVA selon le statut du client
|
||||
if ($clientTvaStatus === 0) {
|
||||
if ($this->hasTva) {
|
||||
// Client soumis à la TVA
|
||||
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaDefault);
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
} else {
|
||||
// Client exonéré - pas de TVA
|
||||
$valueTtc = $valueHt;
|
||||
$tvaAmount = 0;
|
||||
} else {
|
||||
// Client soumis à la TVA - utiliser le calcul normal
|
||||
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
|
||||
$tvaAmount = $valueTtc - $valueHt;
|
||||
}
|
||||
|
||||
$totalHt += $valueHt;
|
||||
@ -352,20 +380,40 @@ class InvoicePdfHandler extends FPDF
|
||||
$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');
|
||||
$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');
|
||||
|
||||
if ($this->hasTva) {
|
||||
// Prix HT
|
||||
$this->SetXY(146, $yValue); // Décalé de 146 au lieu de 144
|
||||
$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');
|
||||
// Prix TTC
|
||||
$this->SetXY(182, $yValue);
|
||||
$this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C');
|
||||
} else {
|
||||
// Sans TVA : seulement Prix HT
|
||||
$this->SetXY(167, $yValue); // Décalé de 167 au lieu de 165
|
||||
$this->Cell(25, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 1, 'C');
|
||||
}
|
||||
|
||||
$yValue += 12;
|
||||
}
|
||||
|
||||
return [
|
||||
"TOTAL HT" => $totalHt,
|
||||
"TVA " . $tvaLabel => $totalTva,
|
||||
"TOTAL TTC" => $totalTtc
|
||||
];
|
||||
// Construire le tableau de retour selon la TVA
|
||||
if ($this->hasTva) {
|
||||
$result = [
|
||||
"TOTAL HT" => $totalHt,
|
||||
"TVA " . $tvaDefault . "%" => $totalTva,
|
||||
"TOTAL TTC" => $totalTtc
|
||||
];
|
||||
} else {
|
||||
$result = [
|
||||
"TOTAL HT" => $totalHt
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function DrawBankAndTotalPriceInfo($totalPriceArray)
|
||||
|
||||
@ -171,9 +171,9 @@ class InvoicePdfService
|
||||
}
|
||||
|
||||
// NOUVELLE LOGIQUE : Vérifier si TVA exonérée
|
||||
if ($this->isTvaExempt($invoicePdfData)) {
|
||||
/*if ($this->isTvaExempt($invoicePdfData)) {
|
||||
return $this->generateWithHtmlTemplate($invoicePdfData, $storage);
|
||||
}
|
||||
}*/
|
||||
|
||||
$templateType = $invoicePdfData['template_type_key'];
|
||||
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
|
||||
@ -356,48 +356,7 @@ class InvoicePdfService
|
||||
$clean_folder = html_entity_decode(string: $invoicePdfData['configuration']->path).'/';
|
||||
$factureFolders = $this->getGroupFactureFolder($invoicePdfData, $clean_folder);
|
||||
$filenames = [];
|
||||
|
||||
foreach ($factureFolders as $folder) {
|
||||
|
||||
// --- GESTION DU CHEMIN ---
|
||||
if (($_ENV['APP_ENV'] ?? 'prod') === 'dev') {
|
||||
// En dev : remplacer les accents et caractères spéciaux pour Docker
|
||||
$relativeFolder = $this->sanitizePathDev($folder);
|
||||
$pdfFileNameSafe = $this->sanitizePathDev($pdfFilename);
|
||||
} else {
|
||||
// En prod : garder UTF-8, juste retirer slash initial
|
||||
$relativeFolder = ltrim($folder, '/');
|
||||
$pdfFileNameSafe = $pdfFilename;
|
||||
}
|
||||
|
||||
// --- CREATION DU DOSSIER ---
|
||||
try {
|
||||
if (!$storage->nodeExists($relativeFolder)) {
|
||||
$storage->newFolder($relativeFolder);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "ERROR creating folder '$relativeFolder': " . $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- CHEMIN COMPLET DU FICHIER ---
|
||||
$ff_pdf = rtrim($relativeFolder, '/') . '/' . $pdfFileNameSafe . '.pdf';
|
||||
|
||||
// --- CREATION OU MISE A JOUR DU FICHIER ---
|
||||
try {
|
||||
if ($storage->nodeExists($ff_pdf)) {
|
||||
$file_pdf = $storage->get($ff_pdf);
|
||||
} else {
|
||||
$file_pdf = $storage->newFile($ff_pdf);
|
||||
}
|
||||
$file_pdf->putContent($pdfContent);
|
||||
$filenames[] = $ff_pdf;
|
||||
} catch (\Throwable $e) {
|
||||
echo "ERROR on file '$ff_pdf': " . $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$filenames = $this->savePdfToFolders($factureFolders, $pdfFilename, $pdfContent, $storage);
|
||||
$this->gestionBdd->setFactureGeneratedDate($invoicePdfData['id']);
|
||||
|
||||
return [
|
||||
@ -424,15 +383,6 @@ class InvoicePdfService
|
||||
}
|
||||
}
|
||||
|
||||
// Vérification alternative dans les totaux si la première méthode ne fonctionne pas
|
||||
if (isset($invoicePdfData['totalPrices'])) {
|
||||
foreach ($invoicePdfData['totalPrices'] as $label => $amount) {
|
||||
if (strpos($label, 'TVA') !== false && (strpos($label, 'exonéré') !== false || $amount == 0)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -652,32 +602,8 @@ class InvoicePdfService
|
||||
$filenames = [];
|
||||
|
||||
foreach ($factureFolders as $folder) {
|
||||
// --- GESTION DU CHEMIN ---
|
||||
if (($_ENV['APP_ENV'] ?? 'prod') === 'dev') {
|
||||
// En dev : remplacer les accents et caractères spéciaux pour Docker
|
||||
$relativeFolder = $this->sanitizePathDev($folder);
|
||||
$pdfFileNameSafe = $this->sanitizePathDev($pdfFilename);
|
||||
} else {
|
||||
// En prod : garder UTF-8, juste retirer slash initial
|
||||
$relativeFolder = ltrim($folder, '/');
|
||||
$pdfFileNameSafe = $pdfFilename;
|
||||
}
|
||||
$ff_pdf = $folder . $pdfFilename . '.pdf';
|
||||
|
||||
// --- CREATION DU DOSSIER ---
|
||||
try {
|
||||
if (!$storage->nodeExists($relativeFolder)) {
|
||||
$storage->newFolder($relativeFolder);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("ERROR creating folder '$relativeFolder': " . $e->getMessage());
|
||||
// Ne pas faire exit, continuer avec les autres dossiers
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- CHEMIN COMPLET DU FICHIER ---
|
||||
$ff_pdf = rtrim($relativeFolder, '/') . '/' . $pdfFileNameSafe . '.pdf';
|
||||
|
||||
// --- CREATION OU MISE A JOUR DU FICHIER ---
|
||||
try {
|
||||
if ($storage->nodeExists($ff_pdf)) {
|
||||
$file_pdf = $storage->get($ff_pdf);
|
||||
@ -688,7 +614,6 @@ class InvoicePdfService
|
||||
$filenames[] = $ff_pdf;
|
||||
} catch (\Throwable $e) {
|
||||
error_log("ERROR on file '$ff_pdf': " . $e->getMessage());
|
||||
// Ne pas faire exit, continuer avec les autres fichiers
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user