From 1778e567458b3f1b564bff2e3812cd1805d9f6a7 Mon Sep 17 00:00:00 2001 From: sonikf <93765174+sonikf@users.noreply.github.com> Date: Sat, 26 Oct 2024 19:29:06 +0300 Subject: [PATCH] NEW: PDF add discount total if line discount exists (#31483) * NEW: PDF add total discount if line discount exists * NEW: PDF add total discount if line discount exists * NEW: PDF add discount total if line discount exists * NEW: PDF add discount total if line discount exists * NEW: PDF add discount total if line discount exists * NEW: PDF add discount total if line discount exists * php doc * Add missing translation * fix missing translation --- dev/translation/ignore_translation_keys.lst | 2 -- htdocs/core/lib/pdf.lib.php | 10 +++--- .../commande/doc/pdf_einstein.modules.php | 36 +++++++++++++++++-- .../commande/doc/pdf_eratosthene.modules.php | 36 +++++++++++++++++-- .../modules/facture/doc/pdf_crabe.modules.php | 36 +++++++++++++++++-- .../facture/doc/pdf_sponge.modules.php | 29 +++++++-------- .../modules/propale/doc/pdf_azur.modules.php | 36 +++++++++++++++++-- .../modules/propale/doc/pdf_cyan.modules.php | 36 +++++++++++++++++-- htdocs/langs/en_US/main.lang | 2 ++ 9 files changed, 190 insertions(+), 33 deletions(-) diff --git a/dev/translation/ignore_translation_keys.lst b/dev/translation/ignore_translation_keys.lst index 1002aae7500..500670884a2 100644 --- a/dev/translation/ignore_translation_keys.lst +++ b/dev/translation/ignore_translation_keys.lst @@ -1113,8 +1113,6 @@ TicketMessageMailSignatureText TicketSetupPage Tiers Timeline -TotalDiscount -TotalHTBeforeDiscount Transfer TryAnotherConnectionMode UndefinedKey diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 307c2e22dd8..ea8e314b441 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -2670,11 +2670,11 @@ function pdf_getSizeForImage($realpath) /** * Return line total amount discount * - * @param Facture $object Object - * @param int $i Current line number - * @param Translate $outputlangs Object langs for output - * @param int<0,2> $hidedetails Hide details (0=no, 1=yes, 2=just special lines) - * @return float|string Return total of line excl tax + * @param Commande|Facture|Propal $object Object + * @param int $i Current line number + * @param Translate $outputlangs Object langs for output + * @param int<0,2> $hidedetails Hide details (0=no, 1=yes, 2=just special lines) + * @return float|string Return total of line excl tax */ function pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, $hidedetails = 0) { diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index ca9ea643366..c4b8fb77461 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -912,13 +912,45 @@ class pdf_einstein extends ModelePDFCommandes $useborder = 0; $index = 0; + // Get Total HT + $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht); + + // Total remise + $total_line_remise = 0; + foreach ($object->lines as $i => $line) { + $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); + $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0); + // Gestion remise sous forme de ligne négative + if ($line->total_ht < 0) { + $total_line_remise += -$line->total_ht; + } + } + if ($total_line_remise > 0) { + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + + $index++; + + // Show total NET before discount + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); + + $index++; + } + // Total HT $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top); + $pdf->SetXY($col1x, $tab2_top+ $tab2_hl * $index); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1); $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht); - $pdf->SetXY($col2x, $tab2_top); + $pdf->SetXY($col2x, $tab2_top+ $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1); // Show VAT by rates and total diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 81f05d766c3..4f5bee5ca83 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -1123,12 +1123,44 @@ class pdf_eratosthene extends ModelePDFCommandes $useborder = 0; $index = 0; + // Get Total HT + $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht); + + // Total remise + $total_line_remise = 0; + foreach ($object->lines as $i => $line) { + $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); + $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0); + // Gestion remise sous forme de ligne négative + if ($line->total_ht < 0) { + $total_line_remise += -$line->total_ht; + } + } + if ($total_line_remise > 0) { + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + + $index++; + + // Show total NET before discount + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); + + $index++; + } + // Total HT $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1); $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht); - $pdf->SetXY($col2x, $tab2_top); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1); // Show VAT by rates and total diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index a9fe63c44b0..8caa7364cc0 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1395,13 +1395,45 @@ class pdf_crabe extends ModelePDFFactures $useborder = 0; $index = 0; + // Get Total HT + $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht); + + // Total remise + $total_line_remise = 0; + foreach ($object->lines as $i => $line) { + $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); + $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0); + // Gestion remise sous forme de ligne négative + if ($line->total_ht < 0) { + $total_line_remise += -$line->total_ht; + } + } + if ($total_line_remise > 0) { + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + + $index++; + + // Show total NET before discount + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); + + $index++; + } + // Total HT $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities(!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ? "TotalHT" : "Total").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities(!getDolGlobalString('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT') ? "TotalHT" : "Total") : ''), 0, 'L', 1); $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht); - $pdf->SetXY($col2x, $tab2_top); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (!empty($object->remise) ? $object->remise : 0)), 0, $outputlangs), 0, 'R', 1); // Show VAT by rates and total diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index b443fea19ea..a1e328cf31c 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -1663,25 +1663,22 @@ class pdf_sponge extends ModelePDFFactures } } if ($total_line_remise > 0) { - if (getDolGlobalString('MAIN_SHOW_AMOUNT_DISCOUNT')) { - $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top + $tab2_hl); - $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); - $pdf->SetXY($col2x, $tab2_top + $tab2_hl); - $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + + $index++; - $index++; - } // Show total NET before discount - if (getDolGlobalString('MAIN_SHOW_AMOUNT_BEFORE_DISCOUNT')) { - $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top); - $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); - $pdf->SetXY($col2x, $tab2_top); - $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); - $index++; - } + $index++; } // Total HT diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index f7e3f40834a..6bd03083132 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -1096,13 +1096,45 @@ class pdf_azur extends ModelePDFPropales $useborder = 0; $index = 0; + // Get Total HT + $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht); + + // Total remise + $total_line_remise = 0; + foreach ($object->lines as $i => $line) { + $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); + $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0); + // Gestion remise sous forme de ligne négative + if ($line->total_ht < 0) { + $total_line_remise += -$line->total_ht; + } + } + if ($total_line_remise > 0) { + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + + $index++; + + // Show total NET before discount + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); + + $index++; + } + // Total HT $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht); - $pdf->SetXY($col2x, $tab2_top); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1); // Show VAT by rates and total diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index f8fcb4bb136..7a727af8176 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -1201,13 +1201,45 @@ class pdf_cyan extends ModelePDFPropales $useborder = 0; $index = 0; + // Get Total HT + $total_ht = (isModEnabled("multicurrency") && $object->multicurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht); + + // Total remise + $total_line_remise = 0; + foreach ($object->lines as $i => $line) { + $resdiscount = pdfGetLineTotalDiscountAmount($object, $i, $outputlangs, 2); + $total_line_remise += (is_numeric($resdiscount) ? $resdiscount : 0); + // Gestion remise sous forme de ligne négative + if ($line->total_ht < 0) { + $total_line_remise += -$line->total_ht; + } + } + if ($total_line_remise > 0) { + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top + $tab2_hl); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise, 0, $outputlangs), 0, 'R', 1); + + $index++; + + // Show total NET before discount + $pdf->SetFillColor(255, 255, 255); + $pdf->SetXY($col1x, $tab2_top); + $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHTBeforeDiscount").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHTBeforeDiscount") : ''), 0, 'L', 1); + $pdf->SetXY($col2x, $tab2_top); + $pdf->MultiCell($largcol2, $tab2_hl, price($total_line_remise + $total_ht, 0, $outputlangs), 0, 'R', 1); + + $index++; + } + // Total HT $pdf->SetFillColor(255, 255, 255); - $pdf->SetXY($col1x, $tab2_top); + $pdf->SetXY($col1x, $tab2_top+ $tab2_hl * $index); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1); $total_ht = ((isModEnabled("multicurrency") && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht); - $pdf->SetXY($col2x, $tab2_top); + $pdf->SetXY($col2x, $tab2_top+ $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1); // Show VAT by rates and total diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index cad3a86d4f2..c3e4bf429a6 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1316,3 +1316,5 @@ NbRecordQualified=Number of qualified records auto=auto UploadFile=Direct import of document OrClickToSelectAFile=or click to select a file on disk +TotalDiscount=Total discount +TotalHTBeforeDiscount=Total net before discount