From 15cc0f8775147ccc2db3a1f7a000218b27badace Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Mon, 1 Mar 2021 23:09:07 +0100 Subject: [PATCH 1/2] Avoid php errors if negative var in Receipt Module Solved in develop branch with PR https://github.com/Dolibarr/dolibarr/pull/15994/files After testing we introduce it in version 13 --- htdocs/core/class/dolreceiptprinter.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index e075005b437..b984f1ab2ce 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -634,7 +634,7 @@ class dolReceiptPrinter extends Printer if ($line->fk_product) { $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($line->ref.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n"); $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label))."\n"); } From 5bb7c521aa2933c555926d563b5723a881e87464 Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Mon, 1 Mar 2021 23:30:38 +0100 Subject: [PATCH 2/2] Update dolreceiptprinter.class.php --- htdocs/core/class/dolreceiptprinter.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index b984f1ab2ce..4dfca1186c0 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -640,7 +640,7 @@ class dolReceiptPrinter extends Printer } else { $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($line->description.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n"); } } @@ -653,7 +653,7 @@ class dolReceiptPrinter extends Printer } foreach ($vatarray as $vatkey => $vatvalue) { $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($spaces.$vatkey.'% '.str_pad(price($vatvalue), 10, ' ', STR_PAD_LEFT)."\n"); } break; @@ -680,15 +680,15 @@ class dolReceiptPrinter extends Printer case 'DOL_PRINT_OBJECT_TOTAL': $title = $langs->trans('TotalHT'); $spacestoadd = $nbcharactbyline - strlen($title) - 10; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($title.$spaces.str_pad(price($object->total_ht), 10, ' ', STR_PAD_LEFT)."\n"); $title = $langs->trans('TotalVAT'); $spacestoadd = $nbcharactbyline - strlen($title) - 10; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($title.$spaces.str_pad(price($object->total_tva), 10, ' ', STR_PAD_LEFT)."\n"); $title = $langs->trans('TotalTTC'); $spacestoadd = $nbcharactbyline - strlen($title) - 10; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($title.$spaces.str_pad(price($object->total_ttc), 10, ' ', STR_PAD_LEFT)."\n"); break; case 'DOL_LINE_FEED': @@ -778,7 +778,7 @@ class dolReceiptPrinter extends Printer if ($line->special_code == $this->orderprinter) { $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($line->ref.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n"); $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc))."\n"); } @@ -799,14 +799,14 @@ class dolReceiptPrinter extends Printer while ($i < $num) { $row = $this->db->fetch_object($resql); $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv("PaymentTypeShort".$row->code)) - 12; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $amount_payment = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount; if ($row->code == "LIQ") $amount_payment = $amount_payment + $row->pos_change; // Show amount with excess received if is cash payment $this->printer->text($spaces.$langs->transnoentitiesnoconv("PaymentTypeShort".$row->code).' '.str_pad(price($amount_payment), 10, ' ', STR_PAD_LEFT)."\n"); if ($row->code == "LIQ" && $row->pos_change > 0) // Print change only in cash payments { $spacestoadd = $nbcharactbyline - strlen($langs->trans("Change")) - 12; - $spaces = str_repeat(' ', $spacestoadd); + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); $this->printer->text($spaces.$langs->trans("Change").' '.str_pad(price($row->pos_change), 10, ' ', STR_PAD_LEFT)."\n"); } $i++;