From 07a1f8e65188d5b352aa233cfca13128de8c1bf8 Mon Sep 17 00:00:00 2001 From: Amael <41053833+Amael-PE@users.noreply.github.com> Date: Mon, 26 Dec 2022 00:05:34 +0100 Subject: [PATCH 1/4] FIX #23334 Implement a price equivalent in command Implement a price equivalent when dealing with minimum prices and foreign currencies. Added in command/card.php for add and update. --- htdocs/commande/card.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index d394df997ff..051f047241a 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -629,6 +629,15 @@ if (empty($reshook)) { $idprod = GETPOST('idprod', 'int'); $tva_tx = ''; } + + $price_equivalent = $price_ht; + $currency_tx = $object->multicurrency_tx; + + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($price_ht == '' && $price_ht_devise != '' && $currency_tx != '') { + $price_equivalent = $price_ht_devise * $currency_tx; + } $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); @@ -916,7 +925,7 @@ if (empty($reshook)) { $info_bits |= 0x01; } - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($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)) && (!empty($price_min) && (price2num($price_equivalent) * (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 { @@ -990,6 +999,15 @@ if (empty($reshook)) { $pu_ht = price2num(GETPOST('price_ht'), '', 2); $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0); $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); + + $pu_equivalent = $pu_ht; + $currency_tx = $object->multicurrency_tx; + + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { + $pu_equivalent = $pu_ht_devise * $currency_tx; + } // Define info_bits $info_bits = 0; @@ -1039,7 +1057,7 @@ if (empty($reshook)) { $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($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)) && ($price_min && (price2num($pu_equivalent) * (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 58d3cdb13cc55fe5d221270d4c8babe107639fa3 Mon Sep 17 00:00:00 2001 From: Amael <41053833+Amael-PE@users.noreply.github.com> Date: Mon, 26 Dec 2022 00:31:38 +0100 Subject: [PATCH 2/4] FIX #23334 Implement a price equivalent in propal Implement a price equivalent when dealing with minimum prices and foreign currencies. Added in comm/propal/card.php as it was done in command/card.php for add and update. --- htdocs/comm/propal/card.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index da4c756705f..9461927bec5 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1116,7 +1116,17 @@ if (empty($reshook)) { $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); + + // Prepare a price equivlanet for mimum price check + $pu_equivalent = $pu_ht; + $currency_tx = $object->multicurrency_tx; + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { + $pu_equivalent = $pu_ht_devise * $currency_tx; + } + // Local Taxes $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr); @@ -1125,8 +1135,9 @@ if (empty($reshook)) { if ($tva_npr) { $info_bits |= 0x01; } - - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { + + // Check minimum price + if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_equivalent) * (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 { @@ -1218,6 +1229,16 @@ if (empty($reshook)) { $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); $remise_percent = price2num(GETPOST('remise_percent'), '', 2); + + // Prepare pu_equivament for checking the minimun price + $pu_equivalent = $pu_ht; + $currency_tx = $object->multicurrency_tx; + + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { + $pu_equivalent = $pu_ht_devise * $currency_tx; + } // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); @@ -1250,7 +1271,7 @@ if (empty($reshook)) { } $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($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)) && ($price_min && (price2num($pu_equivalent) * (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 50e2545bea8bbb7d3632fe54d81c655cb51831b7 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 25 Dec 2022 23:41:03 +0000 Subject: [PATCH 3/4] Fixing style errors. --- htdocs/comm/propal/card.php | 12 ++++++------ htdocs/commande/card.php | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 9461927bec5..4881209e386 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1116,7 +1116,7 @@ if (empty($reshook)) { $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); - + // Prepare a price equivlanet for mimum price check $pu_equivalent = $pu_ht; $currency_tx = $object->multicurrency_tx; @@ -1126,7 +1126,7 @@ if (empty($reshook)) { if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { $pu_equivalent = $pu_ht_devise * $currency_tx; } - + // Local Taxes $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr); @@ -1135,7 +1135,7 @@ if (empty($reshook)) { if ($tva_npr) { $info_bits |= 0x01; } - + // Check minimum price if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_equivalent) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); @@ -1229,7 +1229,7 @@ if (empty($reshook)) { $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); $remise_percent = price2num(GETPOST('remise_percent'), '', 2); - + // Prepare pu_equivament for checking the minimun price $pu_equivalent = $pu_ht; $currency_tx = $object->multicurrency_tx; @@ -1237,8 +1237,8 @@ if (empty($reshook)) { // Check if we have a foreing currency // If so, we update the pu_equiv as the equivalent price in base currency if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { - $pu_equivalent = $pu_ht_devise * $currency_tx; - } + $pu_equivalent = $pu_ht_devise * $currency_tx; + } // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 051f047241a..e48b3183006 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -629,14 +629,14 @@ if (empty($reshook)) { $idprod = GETPOST('idprod', 'int'); $tva_tx = ''; } - + $price_equivalent = $price_ht; $currency_tx = $object->multicurrency_tx; // Check if we have a foreing currency // If so, we update the pu_equiv as the equivalent price in base currency if ($price_ht == '' && $price_ht_devise != '' && $currency_tx != '') { - $price_equivalent = $price_ht_devise * $currency_tx; + $price_equivalent = $price_ht_devise * $currency_tx; } $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); @@ -999,14 +999,14 @@ if (empty($reshook)) { $pu_ht = price2num(GETPOST('price_ht'), '', 2); $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0); $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); - + $pu_equivalent = $pu_ht; $currency_tx = $object->multicurrency_tx; // Check if we have a foreing currency // If so, we update the pu_equiv as the equivalent price in base currency if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { - $pu_equivalent = $pu_ht_devise * $currency_tx; + $pu_equivalent = $pu_ht_devise * $currency_tx; } // Define info_bits From 59ed7b9f96f8b6ad5bf42ac4fc04e56f587ec9c1 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 2 Jan 2023 11:52:34 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/comm/propal/card.php | 26 ++++++++++----------- htdocs/commande/card.php | 45 ++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 73a94a2a503..7953691f11b 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1235,7 +1235,7 @@ if (empty($reshook)) { // Prepare a price equivalent for minimum price check $pu_equivalent = $pu_ht; - $pu_equivalent_ttc = $pu_ttc; + $pu_equivalent_ttc = $pu_ttc; $currency_tx = $object->multicurrency_tx; // Check if we have a foreing currency @@ -1243,7 +1243,7 @@ if (empty($reshook)) { if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { $pu_equivalent = $pu_ht_devise * $currency_tx; } - if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { + if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; } @@ -1364,18 +1364,18 @@ if (empty($reshook)) { $remise_percent = price2num(GETPOST('remise_percent'), '', 2); // Prepare a price equivalent for minimum price check - $pu_equivalent = $pu_ht; - $pu_equivalent_ttc = $pu_ttc; - $currency_tx = $object->multicurrency_tx; + $pu_equivalent = $pu_ht; + $pu_equivalent_ttc = $pu_ttc; + $currency_tx = $object->multicurrency_tx; - // Check if we have a foreing currency - // If so, we update the pu_equiv as the equivalent price in base currency - if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { - $pu_equivalent = $pu_ht_devise * $currency_tx; - } - if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { - $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; - } + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { + $pu_equivalent = $pu_ht_devise * $currency_tx; + } + if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { + $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; + } // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index f5b204c6889..135c6fc9ab9 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -684,18 +684,18 @@ if (empty($reshook)) { // Prepare a price equivalent for minimum price check - $pu_equivalent = $pu_ht; - $pu_equivalent_ttc = $pu_ttc; - $currency_tx = $object->multicurrency_tx; + $pu_equivalent = $pu_ht; + $pu_equivalent_ttc = $pu_ttc; + $currency_tx = $object->multicurrency_tx; - // Check if we have a foreing currency - // If so, we update the pu_equiv as the equivalent price in base currency - if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { - $pu_equivalent = $pu_ht_devise * $currency_tx; - } - if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { - $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; - } + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { + $pu_equivalent = $pu_ht_devise * $currency_tx; + } + if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { + $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; + } $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2); @@ -1013,7 +1013,6 @@ if (empty($reshook)) { } if (!$error) { - // Insert line $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit, '', 0, $pu_ht_devise); @@ -1093,18 +1092,18 @@ if (empty($reshook)) { $qty = price2num(GETPOST('qty', 'alpha'), 'MS'); // Prepare a price equivalent for minimum price check - $pu_equivalent = $pu_ht; - $pu_equivalent_ttc = $pu_ttc; - $currency_tx = $object->multicurrency_tx; + $pu_equivalent = $pu_ht; + $pu_equivalent_ttc = $pu_ttc; + $currency_tx = $object->multicurrency_tx; - // Check if we have a foreing currency - // If so, we update the pu_equiv as the equivalent price in base currency - if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { - $pu_equivalent = $pu_ht_devise * $currency_tx; - } - if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { - $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; - } + // Check if we have a foreing currency + // If so, we update the pu_equiv as the equivalent price in base currency + if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') { + $pu_equivalent = $pu_ht_devise * $currency_tx; + } + if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') { + $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx; + } // Define info_bits $info_bits = 0;