From b191330a79011f2c41392373aaeb656e80ec06bb Mon Sep 17 00:00:00 2001 From: David Pareja Rodriguez Date: Tue, 28 Feb 2023 13:24:11 +0100 Subject: [PATCH 01/33] Ignore localtaxes if localtax1_type or localtax2_type is 0 --- htdocs/core/lib/functions.lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c275e4fd310..73bd7419a8c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5688,7 +5688,7 @@ function isOnlyOneLocalTax($local) function get_localtax_by_third($local) { global $db, $mysoc; - $sql = "SELECT t.localtax1, t.localtax2 "; + $sql = "SELECT t.localtax1_type, t.localtax2_type, t.localtax1, t.localtax2 "; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays"; $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux=("; $sql .= " SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays"; @@ -5698,9 +5698,9 @@ function get_localtax_by_third($local) $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); - if ($local == 1) { + if ($local == 1 && $obj->localtax1_type > 0) { return $obj->localtax1; - } elseif ($local == 2) { + } elseif ($local == 2 && $obj->localtax2_type > 0) { return $obj->localtax2; } } From 590373a620495bcaf5561089e99ca03c3ef1babd Mon Sep 17 00:00:00 2001 From: David Pareja Rodriguez Date: Tue, 28 Feb 2023 13:33:52 +0100 Subject: [PATCH 02/33] Forgot to loop on the results --- htdocs/core/lib/functions.lib.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 73bd7419a8c..e2bbb122176 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5697,11 +5697,12 @@ function get_localtax_by_third($local) $resql = $db->query($sql); if ($resql) { - $obj = $db->fetch_object($resql); - if ($local == 1 && $obj->localtax1_type > 0) { - return $obj->localtax1; - } elseif ($local == 2 && $obj->localtax2_type > 0) { - return $obj->localtax2; + while ($obj = $db->fetch_object($resql)) { + if ($local == 1 && $obj->localtax1_type > 0) { + return $obj->localtax1; + } elseif ($local == 2 && $obj->localtax2_type > 0) { + return $obj->localtax2; + } } } From 927d0a2fa15b61658c58763c0f5c05fed71a0505 Mon Sep 17 00:00:00 2001 From: David Pareja Rodriguez Date: Mon, 13 Mar 2023 11:16:37 +0100 Subject: [PATCH 03/33] ORDER BY rowid --- htdocs/core/lib/functions.lib.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e2bbb122176..4d0367562df 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5688,22 +5688,20 @@ function isOnlyOneLocalTax($local) function get_localtax_by_third($local) { global $db, $mysoc; - $sql = "SELECT t.localtax1_type, t.localtax2_type, t.localtax1, t.localtax2 "; + + $sql = " SELECT t.localtax$local as localtax"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays"; $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux=("; $sql .= " SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays"; $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1"; - $sql .= " )"; + $sql .= " ) "; + $sql .= " AND t.localtax${local}_type > 0"; + $sql .= " ORDER BY rowid DESC"; $resql = $db->query($sql); if ($resql) { - while ($obj = $db->fetch_object($resql)) { - if ($local == 1 && $obj->localtax1_type > 0) { - return $obj->localtax1; - } elseif ($local == 2 && $obj->localtax2_type > 0) { - return $obj->localtax2; - } - } + $obj = $db->fetch_object($resql); + return $obj->localtax; } return 0; From 645b0c563ec176ef0055950e4d56665204d30d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Courtier?= Date: Tue, 14 Mar 2023 11:43:36 +0100 Subject: [PATCH 04/33] FIX: Add more context for selectForFormsListWhere Hook --- htdocs/core/class/html.form.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9c14bfeb866..c4ade09e00f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6782,7 +6782,13 @@ class Form } // Add where from hooks - $parameters = array(); + $parameters = [ + 'object' => $objecttmp, + 'htmlname' => $htmlname, + 'filter' => $filter, + 'searchkey' => $searchkey + ]; + $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook if (!empty($hookmanager->resPrint)) { $sql .= $hookmanager->resPrint; From e618eb3e64252dc0106802c89bfb7845b9b54e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Courtier?= Date: Fri, 17 Mar 2023 10:58:41 +0100 Subject: [PATCH 05/33] FIX: Add missing hook on LibStatut --- htdocs/ticket/class/ticket.class.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index e03bdabe617..e77c7cc2562 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -1273,7 +1273,7 @@ class Ticket extends CommonObject public function LibStatut($status, $mode = 0, $notooltip = 0) { // phpcs:enable - global $langs; + global $langs, $hookmanager; $labelStatus = $this->statuts[$status]; $labelStatusShort = $this->statuts_short[$status]; @@ -1301,6 +1301,18 @@ class Ticket extends CommonObject $mode = 0; } + $parameters = array( + 'status' => $status, + 'mode' => $mode, + ); + + // Note that $action and $object may have been modified by hook + $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this); + + if ($reshook > 0) { + return $hookmanager->resPrint; + } + $params = array(); if ($notooltip) { $params = array('tooltip' => 'no'); From 5351fe75ac8ff2e9a0bdf1efcdf87f7421217a41 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 17 Mar 2023 22:13:09 +0100 Subject: [PATCH 06/33] Fix #24240 Dolibarr V17.0.0 PHP8 fatal error --- htdocs/compta/facture/card-rec.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 06e9a762bca..96faccfd3e5 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2013-2023 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Alexandre Spangaro @@ -637,7 +637,7 @@ if (empty($reshook)) { $info_bits |= 0x01; } - if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { + if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num((float)$remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessages($mesg, null, 'errors'); } else { From 1073944cf48dbe427458175fe52f6d00147cb5cc Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 17 Mar 2023 21:27:57 +0000 Subject: [PATCH 07/33] Fixing style errors. --- htdocs/compta/facture/card-rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 96faccfd3e5..5f90769688b 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -637,7 +637,7 @@ if (empty($reshook)) { $info_bits |= 0x01; } - if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num((float)$remise_percent) / 100) < price2num($price_min)))) { + if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num((float) $remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessages($mesg, null, 'errors'); } else { From a4683e614df85f986ccb67d1f9820aee81e1fce7 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 17 Mar 2023 22:52:01 +0100 Subject: [PATCH 08/33] Fix #24186 V17.0.0 Product listing, Barcode column appears empty --- htdocs/product/list.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 3f26c3bade6..356253cfab7 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012-2016 Marcos García - * Copyright (C) 2013-2019 Juanjo Menent + * Copyright (C) 2013-2023 Juanjo Menent * Copyright (C) 2013-2015 Raphaël Doursenaud * Copyright (C) 2013 Jean Heimburger * Copyright (C) 2013 Cédric Salvador @@ -1356,6 +1356,7 @@ while ($i < min($num, $limit)) { $product_static->ref_fourn = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; // deprecated $product_static->ref_supplier = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; $product_static->label = $obj->label; + $product_static->barcode = $obj->barcode; $product_static->finished = $obj->finished; $product_static->type = $obj->fk_product_type; $product_static->status_buy = $obj->tobuy; From 66643a0dc6e17533389e34daec126b7f83f2b9fa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 00:33:51 +0100 Subject: [PATCH 09/33] Fix phpcs --- htdocs/ticket/class/ticket.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 9c883296305..e7392c33f1d 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -1306,8 +1306,8 @@ class Ticket extends CommonObject 'mode' => $mode, ); - // Note that $action and $object may have been modified by hook - $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this); + // Note that $action and $object may have been modified by hook + $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this); if ($reshook > 0) { return $hookmanager->resPrint; From 926c99f91344bf5efc5e5f50a1cf99e8efafdbd0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 02:35:31 +0100 Subject: [PATCH 10/33] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c4ade09e00f..36754934a0d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6782,12 +6782,12 @@ class Form } // Add where from hooks - $parameters = [ + $parameters = array( 'object' => $objecttmp, 'htmlname' => $htmlname, 'filter' => $filter, 'searchkey' => $searchkey - ]; + ); $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook if (!empty($hookmanager->resPrint)) { From 21102244a25d9c07febb57b40b28784d39e86258 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Sat, 18 Mar 2023 07:38:17 +0100 Subject: [PATCH 11/33] Most efficient solution to fatal error --- htdocs/compta/facture/card-rec.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 5f90769688b..1e7ae045cae 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -437,6 +437,9 @@ if (empty($reshook)) { $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2); $remise_percent = price2num(GETPOST('remise_percent'.$predef), '', 2); + if (empty($remise_percent)) { + $remise_percent = 0; + } // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); @@ -637,7 +640,7 @@ if (empty($reshook)) { $info_bits |= 0x01; } - if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num((float) $remise_percent) / 100) < price2num($price_min)))) { + if ($usercanproductignorepricemin && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessages($mesg, null, 'errors'); } else { @@ -784,6 +787,9 @@ if (empty($reshook)) { }*/ $remise_percent = price2num(GETPOST('remise_percent'), '', 2); + if (empty($remise_percent)) { + $remise_percent = 0; + } // Check minimum price $productid = GETPOST('productid', 'int'); @@ -803,7 +809,7 @@ if (empty($reshook)) { $typeinvoice = Facture::TYPE_STANDARD; // Check price is not lower than minimum (check is done only for standard or replacement invoices) - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT) && $price_min && ((float) price2num($pu_ht) * (1 - (float) $remise_percent / 100) < (float) price2num($price_min)))) { + if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min)))) { setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); $error++; } From bd027dc71e5f3a25d8fc3995bdf66e817ba2c6df Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 10:31:54 +0100 Subject: [PATCH 12/33] Update card-rec.php --- htdocs/compta/facture/card-rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 1e7ae045cae..12567f00f99 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -809,7 +809,7 @@ if (empty($reshook)) { $typeinvoice = Facture::TYPE_STANDARD; // Check price is not lower than minimum (check is done only for standard or replacement invoices) - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min)))) { + if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT) && $price_min && ((float) price2num($pu_ht) * (1 - $remise_percent / 100) < (float) price2num($price_min)))) { setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); $error++; } From d1f79fabfb2ceabc009b3c902b9e2dab3900a837 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 10:32:45 +0100 Subject: [PATCH 13/33] Update card-rec.php --- htdocs/compta/facture/card-rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 12567f00f99..27b039d8b4c 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -809,7 +809,7 @@ if (empty($reshook)) { $typeinvoice = Facture::TYPE_STANDARD; // Check price is not lower than minimum (check is done only for standard or replacement invoices) - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT) && $price_min && ((float) price2num($pu_ht) * (1 - $remise_percent / 100) < (float) price2num($price_min)))) { + if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT) && $price_min && ((float) price2num($pu_ht) * (1 - (float) $remise_percent / 100) < (float) price2num($price_min)))) { setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); $error++; } From 91cf865583653ad6e5f79d0c2360b2243cd257df Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 10:41:07 +0100 Subject: [PATCH 14/33] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4d0367562df..c1459b1206b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5689,13 +5689,13 @@ function get_localtax_by_third($local) { global $db, $mysoc; - $sql = " SELECT t.localtax$local as localtax"; + $sql = " SELECT t.localtax".$local." as localtax"; $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays"; $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux=("; $sql .= " SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays"; $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1"; $sql .= " ) "; - $sql .= " AND t.localtax${local}_type > 0"; + $sql .= " AND t.localtax".$local."_type > 0"; $sql .= " ORDER BY rowid DESC"; $resql = $db->query($sql); From 8d2a3a863da8c6ecd97cceff3e164317834e0022 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 10:48:09 +0100 Subject: [PATCH 15/33] Add phpunit for get_localtax_by_third --- test/phpunit/FunctionsLibTest.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 1bf3b6378fb..3b6a4d44942 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -1168,7 +1168,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase } /** - * testGetDefaultTva + * testGetDefaultLocalTax * * @return void */ @@ -1255,6 +1255,27 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase } + /** + * testGetLocalTaxByThird + * + * @return void + */ + public function testGetLocalTaxByThird() + { + global $mysoc; + + $mysoc->country_code = 'ES'; + + $result = get_localtax_by_third(1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('5.2', $result); + + $result = get_localtax_by_third(2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('-19:-15:-9', $result); + } + + /** * testDolExplodeIntoArray * From 6e17c0c96183bfcca015bc415d658b5079887af7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 10:51:07 +0100 Subject: [PATCH 16/33] Merge branch '15.0' of git@github.com:Dolibarr/dolibarr.git into 15.0 --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ef5b837587d..f32d983150f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5696,7 +5696,7 @@ function get_localtax_by_third($local) $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1"; $sql .= " ) "; $sql .= " AND t.localtax".$local."_type > 0"; - $sql .= " ORDER BY rowid DESC"; + $sql .= " ORDER BY t.rowid DESC"; $resql = $db->query($sql); if ($resql) { From bfc3ccb56cd43a5358a3a188bc3209e1673246ef Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 16:11:27 +0100 Subject: [PATCH 17/33] Fix label --- htdocs/accountancy/bookkeeping/card.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 4620bf37e4e..651afe93562 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -412,7 +412,11 @@ if ($action == 'create') { if (!empty($object->piece_num)) { $backlink = ''.$langs->trans('BackToList').''; - print load_fiche_titre($langs->trans("UpdateMvts"), $backlink); + if ($mode == '_tmp') { + print load_fiche_titre($langs->trans("CreateMvts"), $backlink); + } else { + print load_fiche_titre($langs->trans("UpdateMvts"), $backlink); + } $head = array(); $h = 0; From 83174ee70321fa4e0144bf684afaab0e1740ca84 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Mar 2023 16:53:40 +0100 Subject: [PATCH 18/33] Fix date --- htdocs/accountancy/bookkeeping/list.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index e28d70e8051..9231ae96a95 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -1460,7 +1460,7 @@ while ($i < min($num, $limit)) { // Creation operation date if (!empty($arrayfields['t.date_creation']['checked'])) { - print ''.dol_print_date($line->date_creation, 'dayhour').''; + print ''.dol_print_date($line->date_creation, 'dayhour', 'tzuserel').''; if (!$i) { $totalarray['nbfield']++; } @@ -1468,7 +1468,7 @@ while ($i < min($num, $limit)) { // Modification operation date if (!empty($arrayfields['t.tms']['checked'])) { - print ''.dol_print_date($line->date_modification, 'dayhour').''; + print ''.dol_print_date($line->date_modification, 'dayhour', 'tzuserel').''; if (!$i) { $totalarray['nbfield']++; } @@ -1476,7 +1476,7 @@ while ($i < min($num, $limit)) { // Exported operation date if (!empty($arrayfields['t.date_export']['checked'])) { - print ''.dol_print_date($line->date_export, 'dayhour').''; + print ''.dol_print_date($line->date_export, 'dayhour', 'tzuserel').''; if (!$i) { $totalarray['nbfield']++; } @@ -1484,7 +1484,7 @@ while ($i < min($num, $limit)) { // Validated operation date if (!empty($arrayfields['t.date_validated']['checked'])) { - print ''.dol_print_date($line->date_validation, 'dayhour').''; + print ''.dol_print_date($line->date_validation, 'dayhour', 'tzuserel').''; if (!$i) { $totalarray['nbfield']++; } From ff1d6ff0401802cff924b58e84578a62fbe0d478 Mon Sep 17 00:00:00 2001 From: priojk Date: Sun, 19 Mar 2023 10:32:39 +0100 Subject: [PATCH 19/33] fixed hook (correct return value, option to change params) --- .../product/dynamic_price/class/price_parser.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index 412d015f8b9..64c92752075 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -127,12 +127,12 @@ class PriceParser global $user; global $hookmanager; $action = 'PARSEEXPRESSION'; - if ($result = $hookmanager->executeHooks('doDynamiPrice', array( - 'expression' =>$expression, - 'product' => $product, - 'values' => $values + if ($reshook = $hookmanager->executeHooks('doDynamiPrice', array( + 'expression' => &$expression, + 'product' => &$product, + 'values' => &$values ), $this, $action)) { - return $result; + return $hookmanager->resArray['return']; } //Check if empty $expression = trim($expression); From 72860e3385401eba0f1cf4ce4a23205729640e5d Mon Sep 17 00:00:00 2001 From: priojk Date: Sun, 19 Mar 2023 11:03:05 +0100 Subject: [PATCH 20/33] Fix: loading the extrafields of the related product --- htdocs/product/dynamic_price/class/price_parser.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index 412d015f8b9..9bc1fd2a5a4 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -156,11 +156,10 @@ class PriceParser //Retrieve all extrafield for product and add it to values $extrafields = new ExtraFields($this->db); + $extralabels = $extrafields->fetch_name_optionals_label($product->table_element); $product->fetch_optionals(); - if (is_array($extrafields->attributes[$product->table_element]['label'])) { - foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) { - $values["extrafield_".$key] = $product->array_options['options_'.$key]; - } + foreach ($extralabels as $key => $label) { + $values["extrafield_".$key] = $product->array_options['options_'.$key]; } //Process any pending updaters From 4a79bf2667dc63fa018013a74d846dea12bce72a Mon Sep 17 00:00:00 2001 From: priojk Date: Sun, 19 Mar 2023 11:10:01 +0100 Subject: [PATCH 21/33] Sickler: indentation --- htdocs/product/dynamic_price/class/price_parser.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index 9bc1fd2a5a4..0e32613088a 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -156,7 +156,7 @@ class PriceParser //Retrieve all extrafield for product and add it to values $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($product->table_element); + $extralabels = $extrafields->fetch_name_optionals_label($product->table_element); $product->fetch_optionals(); foreach ($extralabels as $key => $label) { $values["extrafield_".$key] = $product->array_options['options_'.$key]; From 502badad4b68e850c6954dd13a6e689ae7cc54d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 11:25:36 +0100 Subject: [PATCH 22/33] Better error management --- htdocs/core/class/html.formcompany.class.php | 12 ++++++------ htdocs/core/lib/functions.lib.php | 17 +++++++++-------- .../install/mysql/migration/14.0.0-15.0.0.sql | 4 ++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 103db86998c..a42ffc604a3 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -984,15 +984,15 @@ class FormCompany extends Form // phpcs:enable $tax = get_localtax_by_third($local); - $num = $this->db->num_rows($tax); - $i = 0; - if ($num) { + if ($tax) { $valors = explode(":", $tax); + $nbvalues = count($valors); - if (count($valors) > 1) { + if ($nbvalues > 1) { //montar select print ''; + print ''; } } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f32d983150f..9c3126c3a80 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5682,19 +5682,18 @@ function isOnlyOneLocalTax($local) /** * Get values of localtaxes (1 or 2) for company country for the common vat with the highest value * - * @param int $local LocalTax to get - * @return number Values of localtax + * @param int $local LocalTax to get + * @return string Values of localtax (Can be '20', '-19:-15:-9') */ function get_localtax_by_third($local) { global $db, $mysoc; $sql = " SELECT t.localtax".$local." as localtax"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays"; - $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux=("; - $sql .= " SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays"; - $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1"; - $sql .= " ) "; + $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t INNER JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = t.fk_pays"; + $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux = ("; + $sql .= "SELECT MAX(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt INNER JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = tt.fk_pays"; + $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1)"; $sql .= " AND t.localtax".$local."_type > 0"; $sql .= " ORDER BY t.rowid DESC"; @@ -5702,9 +5701,11 @@ function get_localtax_by_third($local) if ($resql) { $obj = $db->fetch_object($resql); return $obj->localtax; + } else { + return 'Error'; } - return 0; + return '0'; } diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index bef7621d282..4b2655818c1 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -533,3 +533,7 @@ ALTER TABLE llx_bank ADD COLUMN amount_main_currency double(24,8) NULL; ALTER TABLE llx_commande_fournisseurdet MODIFY COLUMN ref varchar(128); ALTER TABLE llx_facture_fourn_det MODIFY COLUMN ref varchar(128); + +ALTER TABLE llx_c_tva SET localtax2 = '-19:-15:-9' WHERE localtax2 = '-19' AND localtax2_type = '5' AND fk_pays = 4 AND rowid = 44; + + From c895f366a10f4f8449657d3d58b5690cdb78f635 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 11:36:06 +0100 Subject: [PATCH 23/33] Fix sql --- htdocs/install/mysql/migration/14.0.0-15.0.0.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index 4b2655818c1..67ff6f1fab3 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -534,6 +534,5 @@ ALTER TABLE llx_bank ADD COLUMN amount_main_currency double(24,8) NULL; ALTER TABLE llx_commande_fournisseurdet MODIFY COLUMN ref varchar(128); ALTER TABLE llx_facture_fourn_det MODIFY COLUMN ref varchar(128); -ALTER TABLE llx_c_tva SET localtax2 = '-19:-15:-9' WHERE localtax2 = '-19' AND localtax2_type = '5' AND fk_pays = 4 AND rowid = 44; - +UPDATE llx_c_tva SET localtax2 = '-19:-15:-9' WHERE localtax2 = '-19' AND localtax2_type = '5' AND fk_pays = 4 AND taux = 21; From d3f679f2b1923a9ba4ea1d3353eabf0fe3abb6f3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 12:54:11 +0100 Subject: [PATCH 24/33] Fix sql regression --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9c3126c3a80..4f33a68811c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5694,7 +5694,7 @@ function get_localtax_by_third($local) $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND t.active = 1 AND t.taux = ("; $sql .= "SELECT MAX(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt INNER JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = tt.fk_pays"; $sql .= " WHERE c.code = '".$db->escape($mysoc->country_code)."' AND tt.active = 1)"; - $sql .= " AND t.localtax".$local."_type > 0"; + $sql .= " AND t.localtax".$local."_type <> '0'"; $sql .= " ORDER BY t.rowid DESC"; $resql = $db->query($sql); From ee30114ed90ed386771ad0fa23c59769aa922362 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 14:28:32 +0100 Subject: [PATCH 25/33] Fix extralabels must not be used anymore. #24268 --- .../class/price_parser.class.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/htdocs/product/dynamic_price/class/price_parser.class.php b/htdocs/product/dynamic_price/class/price_parser.class.php index fd609a85d27..47e290677c6 100644 --- a/htdocs/product/dynamic_price/class/price_parser.class.php +++ b/htdocs/product/dynamic_price/class/price_parser.class.php @@ -124,8 +124,8 @@ class PriceParser */ public function parseExpression($product, $expression, $values) { - global $user; - global $hookmanager; + global $user, $hookmanager, $extrafields; + $action = 'PARSEEXPRESSION'; if ($reshook = $hookmanager->executeHooks('doDynamiPrice', array( 'expression' => &$expression, @@ -154,12 +154,17 @@ class PriceParser "pmp" => $product->pmp, )); - //Retrieve all extrafield for product and add it to values - $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($product->table_element); + // Retrieve all extrafields if not already not know (should not happen) + if (! is_object($extrafields)) { + $extrafields = new ExtraFields($this->db); + $extrafields->fetch_name_optionals_label(); + } + $product->fetch_optionals(); - foreach ($extralabels as $key => $label) { - $values["extrafield_".$key] = $product->array_options['options_'.$key]; + if (is_array($extrafields->attributes[$product->table_element]['label'])) { + foreach ($extrafields->attributes[$product->table_element]['label'] as $key => $label) { + $values["extrafield_".$key] = $product->array_options['options_'.$key]; + } } //Process any pending updaters From 249a6ea9a9c76cbd1aaaf99487a427c0b5301990 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 14:49:54 +0100 Subject: [PATCH 26/33] Remove warning --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4f33a68811c..3f25d9cdfd0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5814,7 +5814,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi } $sql .= ", ".MAIN_DB_PREFIX."c_country as c"; - if ($mysoc->country_code == 'ES') { + if (!empty($mysoc) && $mysoc->country_code == 'ES') { $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($buyer->country_code)."'"; // local tax in spain use the buyer country ?? } else { $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape(empty($seller->country_code) ? $mysoc->country_code : $seller->country_code)."'"; From 88353ee5ba3c2bcf7a840d8ce19e1fea38bdd03c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 17:38:22 +0100 Subject: [PATCH 27/33] Fix tests --- htdocs/compta/facture/class/facture.class.php | 1 + test/phpunit/NumberingModulesTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 484b44851fd..ec36314c999 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3192,6 +3192,7 @@ class Facture extends CommonInvoice /** * Add an invoice line into database (linked to product/service or not). + * Note: ->thirdparty must be defined. * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index ceab1948732..755eeb68956 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -152,6 +152,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1915); // we use year 1915 to be sure to not have existing invoice for this year (usefull only if numbering is {0000@1} $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); From b1695085779ecd428430cecb7dfc56b8294ae6ac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 19:11:16 +0100 Subject: [PATCH 28/33] Removed phpnightly build --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 62d04901e17..15fad8bf01f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,10 +56,6 @@ jobs: if: type = push AND branch = develop php: nightly env: DB=mysql - - stage: PHP Dev - if: type = push AND branch = 15.0 - php: nightly - env: DB=mysql notifications: email: From df001fc01a072994ea4a5b51dedcc253d9d0c6a0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 19 Mar 2023 20:29:34 +0100 Subject: [PATCH 29/33] Try to fix phpunit --- test/phpunit/NumberingModulesTest.php | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index a6c96d2da11..6e482fe75b0 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -167,8 +167,11 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result=$localobject->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; $this->assertGreaterThanOrEqual(1, $result, 'Test for is_erasable, 1st invoice'); // Can be deleted + $localobject2=new Facture($this->savdb); $localobject2->initAsSpecimen(); + $localobject2->fetch_thirdparty(); + $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1916); // we use following year for second invoice (there is no reset into mask) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject2, 'last'); @@ -195,6 +198,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1910); // we use year 1910 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -202,15 +207,21 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result3=$localobject->validate($user, $result); print __METHOD__." result=".$result."\n"; $this->assertEquals('1910-0001', $result, 'Test for {yyyy}-{0000@1} 1st invoice'); // counter must start to 1 + $localobject2=new Facture($this->savdb); $localobject2->initAsSpecimen(); + $localobject2->fetch_thirdparty(); + $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1910); // we use same year for second invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject2); print __METHOD__." result=".$result."\n"; $this->assertEquals('1910-0002', $result, 'Test for {yyyy}-{0000@1} 2nd invoice, same day'); // counter must be now 2 + $localobject3=new Facture($this->savdb); $localobject3->initAsSpecimen(); + $localobject3->fetch_thirdparty(); + $localobject3->date=dol_mktime(12, 0, 0, 1, 1, 1911); // we use next year for third invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject3); @@ -220,8 +231,11 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase // Same but we add month after year $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@1}'; $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@1}'; + $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1920); // we use year 1920 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -232,8 +246,11 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result=$localobject->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; $this->assertGreaterThanOrEqual(1, $result); // Can be deleted + $localobject2=new Facture($this->savdb); $localobject2->initAsSpecimen(); + $localobject2->fetch_thirdparty(); + $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1921); // we use following year for second invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject2); @@ -253,6 +270,7 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $conf->global->FACTURE_MERCURE_MASK_INVOICE='{mm}{yy}-{0000@1}'; $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1925); // we use year 1925 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -263,8 +281,10 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result=$localobject->is_erasable(); // This call get getNextNumRef with param 'last' print __METHOD__." is_erasable=".$result."\n"; $this->assertGreaterThanOrEqual(1, $result); // Can be deleted + $localobject2=new Facture($this->savdb); $localobject2->initAsSpecimen(); + $localobject2->fetch_thirdparty(); $localobject2->date=dol_mktime(12, 0, 0, 1, 1, 1925); // we use same year 1925 for second invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject2); @@ -278,8 +298,10 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result=$localobject->is_erasable(); print __METHOD__." is_erasable=".$result."\n"; $this->assertLessThanOrEqual(0, $result); // Case 1 can not be deleted (because there is an invoice 2) + $localobject3=new Facture($this->savdb); $localobject3->initAsSpecimen(); + $localobject3->fetch_thirdparty(); $localobject3->date=dol_mktime(12, 0, 0, 1, 1, 1926); // we use following year for third invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject3); @@ -297,6 +319,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject, 'last'); @@ -313,6 +337,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject, 'last'); @@ -326,6 +352,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1931); // we use same fiscal year but different year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -336,6 +364,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -350,6 +380,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1940); // we use year 1940 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -360,6 +392,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1940); // we use same year but fiscal month after $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -380,6 +414,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1941); // we use different discal year but same year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -394,6 +430,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1950); // we use year 1950 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -404,6 +442,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1950); // we use same year but fiscal month after $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -414,6 +454,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1951); // we use same fiscal year but different year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -424,6 +466,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1951); // we use different discal year but same year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -438,6 +482,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1960); // we use year 1960 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -448,6 +494,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1960); // we use same year but fiscal month after $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -458,6 +506,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1961); // we use same fiscal year but different year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -468,6 +518,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1961); // we use different discal year but same year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -482,6 +534,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1970); // we use year 1970 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -492,6 +546,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1970); // we use same year but fiscal month after $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -502,6 +558,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1971); // we use same fiscal year but different year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -512,6 +570,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1971); // we use different fiscal year but same year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -555,6 +615,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -574,6 +636,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1982); // we use year 1982 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($tmpthirdparty, $localobject); From 8ca17bdbc0881b3cd7b232ec6ba6aaeee5f783c7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Mar 2023 01:54:29 +0100 Subject: [PATCH 30/33] Fix warning --- test/phpunit/NumberingModulesTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index 6e482fe75b0..19d55d7932e 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -404,6 +404,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1941); // we use same fiscal year but different year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); From 0c49dc2b464af0ac3c68acfc0a9504cde91e5d67 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Mar 2023 02:26:49 +0100 Subject: [PATCH 31/33] Fix warning --- test/phpunit/NumberingModulesTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index 19d55d7932e..e5d31df1cf7 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2012-2023 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -587,6 +587,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -597,6 +599,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); @@ -607,6 +611,8 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); + $localobject->fetch_thirdparty(); + $localobject->date=dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject); From 9ddb7b619814b859a8da162eca466c41bd01e68e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Mar 2023 12:00:21 +0100 Subject: [PATCH 32/33] Debug v17 --- htdocs/core/lib/functions.lib.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a26d77f947a..35c121536de 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6283,9 +6283,11 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi $sql .= ", ".MAIN_DB_PREFIX."c_country as c"; if (!empty($mysoc) && $mysoc->country_code == 'ES') { - $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($buyer->country_code)."'"; // local tax in spain use the buyer country ?? + $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ? $mysoc->country_code : $buyer->country_code); + $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse)."'"; // local tax in spain use the buyer country ?? } else { - $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape(empty($seller->country_code) ? $mysoc->country_code : $seller->country_code)."'"; + $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ? $mysoc->country_code : $seller->country_code); + $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse)."'"; } $sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1"; if ($vatratecode) { From 1151a8e65e1ea42d07f14d38d2a35f06aa6c03a3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Mar 2023 12:05:44 +0100 Subject: [PATCH 33/33] Fix more robust phpunit test --- test/phpunit/FunctionsLibTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index b573044d1c4..642e36e37c6 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -80,6 +80,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $savmysoc; /** * Constructor @@ -92,11 +93,12 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase parent::__construct(); //$this->sharedFixture - global $conf,$user,$langs,$db; + global $conf,$user,$langs,$db,$mysoc; $this->savconf=$conf; $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + $this->savmysoc=$mysoc; print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -142,17 +144,18 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase } /** - * Init phpunit tests + * Init phpunit tests. Restore variables before each test. * * @return void */ protected function setUp(): void { - global $conf,$user,$langs,$db; + global $conf,$user,$langs,$db,$mysoc; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $mysoc=$this->savmysoc; print __METHOD__."\n"; } @@ -1225,7 +1228,6 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase // We do same tests but with option SERVICE_ARE_ECOMMERCE_200238EC on. $conf->global->SERVICE_ARE_ECOMMERCE_200238EC = 1; - // Test RULE 1 (FR-US) $vat=get_default_tva($companyfr, $companyus, 0); $this->assertEquals(0, $vat, 'RULE 1 ECOMMERCE_200238EC');