From 21eb8e585f88ea8306f9a093ff7a59bbffe1b9be Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 8 Oct 2024 20:48:37 +0200 Subject: [PATCH 1/4] Fix detection of text browser with w3m --- htdocs/core/lib/functions.lib.php | 6 +++++- htdocs/main.inc.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 360cbb05edfcb..0961223b02e03 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -603,8 +603,12 @@ function getBrowserInfo($user_agent) $version = end($reg); } elseif (preg_match('/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) { // MS products at end - $name = 'lynxlinks'; + $name = 'textbrowser'; $version = empty($reg[3]) ? '' : $reg[3]; + } elseif (preg_match('/w3m\/([\d\.]+)/i', $user_agent, $reg)) { + // MS products at end + $name = 'textbrowser'; + $version = empty($reg[1]) ? '' : $reg[1]; } if ($tablet) { diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 7a8f3cebb3737..737053673f032 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -510,7 +510,7 @@ function analyseVarsForSqlAndScriptsInjection(&$var, $type, $stopcode = 1) } // Set global MAIN_OPTIMIZEFORTEXTBROWSER (must be before login part) -if (GETPOSTINT('textbrowser') || (!empty($conf->browser->name) && $conf->browser->name == 'lynxlinks')) { // If we must enable text browser +if (GETPOSTINT('textbrowser') || (!empty($conf->browser->name) && $conf->browser->name == 'textbrowser')) { // If we must enable text browser $conf->global->MAIN_OPTIMIZEFORTEXTBROWSER = 2; } From 14dec516a378f4484eb327ea4a799fa057b6509a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 8 Oct 2024 23:51:51 +0200 Subject: [PATCH 2/4] FIX Vat code is lost when updating lines in POS --- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/takepos/invoice.php | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 01d8fbe7ade76..dd18c83f75355 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4051,7 +4051,7 @@ public function addline( * @param double $remise_percent Percentage discount of the line * @param int $date_start Date de debut de validite du service * @param int $date_end Date de fin de validite du service - * @param double $txtva VAT Rate (Can be '8.5', '8.5 (ABC)') + * @param double|string $txtva VAT Rate (Can be '8.5', '8.5 (ABC)') * @param double $txlocaltax1 Local tax 1 rate * @param double $txlocaltax2 Local tax 2 rate * @param string $price_base_type HT or TTC diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 95af25c4b07a3..b52aba193cdee 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -900,7 +900,12 @@ function fail($message) if (!$permissiontoupdateline) { dol_htmloutput_errors($langs->trans("NotEnoughPermissions", "TakePos").' - No permission to updateqty', null, 1); } else { - $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + $vatratecode = $line->tva_tx; + if ($line->vat_src_code) { + $vatratecode .= ' ('.$line->vat_src_code.')'; + } + + $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, $line->date_start, $line->date_end, $vatratecode, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } } @@ -934,12 +939,18 @@ function fail($message) // TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the invoice ID } } + + $vatratecode = $line->tva_tx; + if ($line->vat_src_code) { + $vatratecode .= ' ('.$line->vat_src_code.')'; + } + if (!$permissiontoupdateline) { dol_htmloutput_errors($langs->trans("NotEnoughPermissions", "TakePos").' - No permission to updateprice', null, 1); } elseif (getDolGlobalInt('TAKEPOS_CHANGE_PRICE_HT') == 1) { - $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vatratecode, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } else { - $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'TTC', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $vatratecode, $line->localtax1_tx, $line->localtax2_tx, 'TTC', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } } @@ -982,7 +993,11 @@ function fail($message) if (!$permissiontoupdateline) { dol_htmloutput_errors($langs->trans("NotEnoughPermissions", "TakePos"), null, 1); } else { - $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + $vatratecode = $line->tva_tx; + if ($line->vat_src_code) { + $vatratecode .= ' ('.$line->vat_src_code.')'; + } + $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $vatratecode, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } } @@ -992,7 +1007,11 @@ function fail($message) $invoice->fetch($placeid); } elseif ($action == 'update_reduction_global' && $user->hasRight('takepos', 'editlines')) { foreach ($invoice->lines as $line) { - $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); + $vatratecode = $line->tva_tx; + if ($line->vat_src_code) { + $vatratecode .= ' ('.$line->vat_src_code.')'; + } + $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $vatratecode, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } $invoice->fetch($placeid); From 67156d03ca33cf826be96dc2fbb204205a6cf7a0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 9 Oct 2024 00:13:56 +0200 Subject: [PATCH 3/4] Fix phpunit --- test/phpunit/FunctionsLibTest.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index d81d49904ab8d..60069cd725d46 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -533,7 +533,7 @@ public function testGetBrowserInfo() $this->assertFalse($tmp['tablet']); $this->assertEquals('classic', $tmp['layout']); - //Internet Explorer 11 + // Internet Explorer 11 $user_agent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'; $tmp = getBrowserInfo($user_agent); $this->assertEquals('ie', $tmp['browsername']); @@ -542,7 +542,7 @@ public function testGetBrowserInfo() $this->assertFalse($tmp['tablet']); $this->assertEquals('classic', $tmp['layout']); - //Internet Explorer 11 bis + // Internet Explorer 11 bis $user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; NP06; rv:11.0) like Gecko'; $tmp = getBrowserInfo($user_agent); $this->assertEquals('ie', $tmp['browsername']); @@ -551,7 +551,7 @@ public function testGetBrowserInfo() $this->assertFalse($tmp['tablet']); $this->assertEquals('classic', $tmp['layout']); - //iPad + // iPad $user_agent = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'; $tmp = getBrowserInfo($user_agent); $this->assertEquals('safari', $tmp['browsername']); @@ -560,13 +560,21 @@ public function testGetBrowserInfo() $this->assertEquals('tablet', $tmp['layout']); $this->assertEquals('iphone', $tmp['phone']); - //Lynx + // Lynx $user_agent = 'Lynx/2.8.8dev.3 libwww‑FM/2.14 SSL‑MM/1.4.1'; $tmp = getBrowserInfo($user_agent); - $this->assertEquals('lynxlinks', $tmp['browsername']); + $this->assertEquals('textbrowser', $tmp['browsername']); $this->assertEquals('2.8.8', $tmp['browserversion']); $this->assertEquals('unknown', $tmp['browseros']); $this->assertEquals('classic', $tmp['layout']); + + // W3M + $user_agent = 'w3m/1.2.3-git123456'; + $tmp = getBrowserInfo($user_agent); + $this->assertEquals('textbrowser', $tmp['browsername']); + $this->assertEquals('1.2.3', $tmp['browserversion']); + $this->assertEquals('unknown', $tmp['browseros']); + $this->assertEquals('classic', $tmp['layout']); } From ee4776d64ed5184724f6dd661022662cc9caff66 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Wed, 9 Oct 2024 01:49:07 +0200 Subject: [PATCH 4/4] Fix: Grand total correction (#31303) --- htdocs/core/tpl/list_print_total.tpl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/tpl/list_print_total.tpl.php b/htdocs/core/tpl/list_print_total.tpl.php index 8900665eaeb95..8990ce129845b 100644 --- a/htdocs/core/tpl/list_print_total.tpl.php +++ b/htdocs/core/tpl/list_print_total.tpl.php @@ -64,7 +64,8 @@ while ($i < $totalarray['nbfield']) { $i++; if (!empty($totalarray['pos'][$i])) { - printTotalValCell($totalarray['type'][$i], $sumsarray[$totalarray['pos'][$i]]); + $fieldname = preg_replace('/[^a-z0-9]/', '', $totalarray['pos'][$i]); + printTotalValCell($totalarray['type'][$i], $sumsarray[$fieldname]); } else { if ($i == 1) { print '';