From ce0abd17fe543c12606f585ca9085925072deb5a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 2 Jan 2021 16:18:16 +0100 Subject: [PATCH] Debug v13 --- htdocs/commande/card.php | 6 +++--- htdocs/compta/facture/card-rec.php | 8 ++++---- htdocs/contrat/card.php | 8 ++++---- htdocs/core/lib/functions.lib.php | 18 +++++++++++++----- htdocs/fourn/commande/card.php | 10 +++++----- htdocs/fourn/facture/card.php | 10 +++++----- htdocs/supplier_proposal/card.php | 10 +++++----- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 213819b0915..2ea5c37bf39 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -631,9 +631,9 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); - $price_ht = GETPOST('price_ht'); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index b978de677a9..097585dbea0 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -437,9 +437,9 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); - $price_ht = GETPOST('price_ht'); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha'); if ($prod_entry_mode == 'free') { @@ -450,7 +450,7 @@ if (empty($reshook)) $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); // Extrafields diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 2e692dc25c4..d07b8dcc60e 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -383,9 +383,9 @@ if (empty($reshook)) { // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); - $price_ht = price2num(GETPOST('price_ht')); - $price_ht_devise = price2num(GETPOST('multicurrency_price_ht')); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CR'); if (GETPOST('prod_entry_mode', 'alpha') == 'free') { $idprod = 0; @@ -395,7 +395,7 @@ if (empty($reshook)) $tva_tx = ''; } - $qty = price2num(GETPOST('qty'.$predef)); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = ((GETPOST('remise_percent'.$predef) != '') ? GETPOST('remise_percent'.$predef) : 0); if ($qty == '') diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a156f35292e..8c1765620ec 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4810,7 +4810,7 @@ function price($amount, $form = 0, $outlangs = '', $trunc = 1, $rounding = -1, $ * 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) * 'MT'=Round to Max for totals with Tax (MAIN_MAX_DECIMALS_TOT) * 'MS'=Round to Max for stock quantity (MAIN_MAX_DECIMALS_STOCK) - * 'CR'=Currency rate + * 'CR'=Foreign currency accurancy * Numeric = Nb of digits for rounding * @param int $option Put 1 if you know that content is already universal format number (so no correction on decimal will be done) * Put 2 if you know that number is a user input (so we know we don't have to fix decimal separator). @@ -4871,10 +4871,18 @@ function price2num($amount, $rounding = '', $option = 0) if ($rounding) { $nbofdectoround = ''; - if ($rounding == 'MU') $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT; - elseif ($rounding == 'MT') $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT; - elseif ($rounding == 'MS') $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK; - elseif ($rounding == 'CR') $nbofdectoround = 8; + if ($rounding == 'MU') { + $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT; + } + elseif ($rounding == 'MT') { + $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT; + } + elseif ($rounding == 'MS') { + $nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK; + } + elseif ($rounding == 'CR') { + $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8); + } elseif (is_numeric($rounding)) $nbofdectoround = $rounding; //print "RR".$amount.' - '.$nbofdectoround.'
'; if (dol_strlen($nbofdectoround)) $amount = round(is_string($amount) ? (float) $amount : $amount, $nbofdectoround); // $nbofdectoround can be 0. diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 987b80aa3ea..710657e1c16 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -356,24 +356,24 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $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')); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { $idprod = 0; - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { $idprod = GETPOST('idprod', 'int'); - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index c615817e36f..998ef884766 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1175,7 +1175,7 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $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')); @@ -1183,17 +1183,17 @@ if (empty($reshook)) if ($prod_entry_mode == 'free') { $idprod = 0; - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { $idprod = GETPOST('idprod', 'int'); - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index ae40784aa68..a571a207bc5 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -540,24 +540,24 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef = ''; - $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : ''); + $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : ''); $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')); $ref_supplier = GETPOST('fourn_ref', 'alpha'); $prod_entry_mode = GETPOST('prod_entry_mode'); if ($prod_entry_mode == 'free') { $idprod = 0; - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); } else { $idprod = GETPOST('idprod', 'int'); - $price_ht = GETPOST('price_ht'); + $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = ''; } - $qty = GETPOST('qty'.$predef); + $qty = price2num(GETPOST('qty'.$predef), 'alpha'); $remise_percent = GETPOST('remise_percent'.$predef); - $price_ht_devise = GETPOST('multicurrency_price_ht'); + $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR'); // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);