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.
This commit is contained in:
Amael 2022-12-26 00:05:34 +01:00 committed by GitHub
parent 6950e2be20
commit 07a1f8e651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -630,6 +630,15 @@ if (empty($reshook)) {
$tva_tx = ''; $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'); $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
$remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0); $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
@ -916,7 +925,7 @@ if (empty($reshook)) {
$info_bits |= 0x01; $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)); $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
setEventMessages($mesg, null, 'errors'); setEventMessages($mesg, null, 'errors');
} else { } else {
@ -991,6 +1000,15 @@ if (empty($reshook)) {
$vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0); $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0);
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2); $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 // Define info_bits
$info_bits = 0; $info_bits = 0;
if (preg_match('/\*/', $vat_rate)) { if (preg_match('/\*/', $vat_rate)) {
@ -1039,7 +1057,7 @@ if (empty($reshook)) {
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); $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'); setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
$error++; $error++;
} }