mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-15 05:51:28 +01:00
Fix rounding of currency unit prices
This commit is contained in:
@@ -633,7 +633,7 @@ if (empty($reshook))
|
|||||||
$predef = '';
|
$predef = '';
|
||||||
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
||||||
$price_ht = price2num(GETPOST('price_ht'), 'MU');
|
$price_ht = price2num(GETPOST('price_ht'), 'MU');
|
||||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR');
|
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU');
|
||||||
$prod_entry_mode = GETPOST('prod_entry_mode');
|
$prod_entry_mode = GETPOST('prod_entry_mode');
|
||||||
if ($prod_entry_mode == 'free')
|
if ($prod_entry_mode == 'free')
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ if (empty($reshook))
|
|||||||
$predef = '';
|
$predef = '';
|
||||||
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
||||||
$price_ht = price2num(GETPOST('price_ht'), 'MU');
|
$price_ht = price2num(GETPOST('price_ht'), 'MU');
|
||||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR');
|
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU');
|
||||||
$prod_entry_mode = GETPOST('prod_entry_mode', 'alpha');
|
$prod_entry_mode = GETPOST('prod_entry_mode', 'alpha');
|
||||||
if ($prod_entry_mode == 'free')
|
if ($prod_entry_mode == 'free')
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ if (empty($reshook))
|
|||||||
$predef = '';
|
$predef = '';
|
||||||
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
||||||
$price_ht = price2num(GETPOST('price_ht'), 'MU');
|
$price_ht = price2num(GETPOST('price_ht'), 'MU');
|
||||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CR'));
|
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht', 'CU'));
|
||||||
if (GETPOST('prod_entry_mode', 'alpha') == 'free')
|
if (GETPOST('prod_entry_mode', 'alpha') == 'free')
|
||||||
{
|
{
|
||||||
$idprod = 0;
|
$idprod = 0;
|
||||||
|
|||||||
@@ -4881,7 +4881,7 @@ class Form
|
|||||||
print '<form method="POST" action="'.$page.'">';
|
print '<form method="POST" action="'.$page.'">';
|
||||||
print '<input type="hidden" name="action" value="setmulticurrencyrate">';
|
print '<input type="hidden" name="action" value="setmulticurrencyrate">';
|
||||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||||
print '<input type="text" class="maxwidth100" name="'.$htmlname.'" value="'.(!empty($rate) ? price(price2num($rate, 'CR')) : 1).'" /> ';
|
print '<input type="text" class="maxwidth100" name="'.$htmlname.'" value="'.(!empty($rate) ? price(price2num($rate, 'CU')) : 1).'" /> ';
|
||||||
print '<select name="calculation_mode">';
|
print '<select name="calculation_mode">';
|
||||||
print '<option value="1">'.$currency.' > '.$conf->currency.'</option>';
|
print '<option value="1">'.$currency.' > '.$conf->currency.'</option>';
|
||||||
print '<option value="2">'.$conf->currency.' > '.$currency.'</option>';
|
print '<option value="2">'.$conf->currency.' > '.$currency.'</option>';
|
||||||
|
|||||||
@@ -4896,8 +4896,11 @@ function price2num($amount, $rounding = '', $option = 0)
|
|||||||
elseif ($rounding == 'MS') {
|
elseif ($rounding == 'MS') {
|
||||||
$nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
|
$nbofdectoround = empty($conf->global->MAIN_MAX_DECIMALS_STOCK) ? 5 : $conf->global->MAIN_MAX_DECIMALS_STOCK;
|
||||||
}
|
}
|
||||||
elseif ($rounding == 'CR') {
|
elseif ($rounding == 'CU') {
|
||||||
$nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8);
|
$nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8); // TODO Use param of currency
|
||||||
|
}
|
||||||
|
elseif ($rounding == 'CT') {
|
||||||
|
$nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8); // TODO Use param of currency
|
||||||
}
|
}
|
||||||
elseif (is_numeric($rounding)) $nbofdectoround = $rounding;
|
elseif (is_numeric($rounding)) $nbofdectoround = $rounding;
|
||||||
//print "RR".$amount.' - '.$nbofdectoround.'<br>';
|
//print "RR".$amount.' - '.$nbofdectoround.'<br>';
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ if (empty($reshook))
|
|||||||
|
|
||||||
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
||||||
$remise_percent = GETPOST('remise_percent'.$predef);
|
$remise_percent = GETPOST('remise_percent'.$predef);
|
||||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR');
|
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU');
|
||||||
|
|
||||||
// Extrafields
|
// Extrafields
|
||||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||||
|
|||||||
@@ -1193,7 +1193,7 @@ if (empty($reshook))
|
|||||||
|
|
||||||
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
||||||
$remise_percent = GETPOST('remise_percent'.$predef);
|
$remise_percent = GETPOST('remise_percent'.$predef);
|
||||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR');
|
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU');
|
||||||
|
|
||||||
// Extrafields
|
// Extrafields
|
||||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||||
@@ -1292,10 +1292,10 @@ if (empty($reshook))
|
|||||||
if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
|
if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
|
||||||
|
|
||||||
$type = $productsupplier->type;
|
$type = $productsupplier->type;
|
||||||
if ($price_ht != '' || $price_ht_devise != '') {
|
if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
|
||||||
$price_base_type = 'HT';
|
$price_base_type = 'HT';
|
||||||
$pu = price2num($price_ht, 'MU');
|
$pu = price2num($price_ht, 'MU');
|
||||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
$pu_ht_devise = price2num($price_ht_devise, 'CU');
|
||||||
} else {
|
} else {
|
||||||
$price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
|
$price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
|
||||||
if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
|
if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
|
||||||
@@ -1373,15 +1373,14 @@ if (empty($reshook))
|
|||||||
$localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
|
$localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
|
||||||
$localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
|
$localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
|
||||||
|
|
||||||
if ($price_ht !== '')
|
if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
|
||||||
{
|
|
||||||
$pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
|
$pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
|
||||||
} else {
|
} else {
|
||||||
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
|
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
|
||||||
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
|
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
|
||||||
}
|
}
|
||||||
$price_base_type = 'HT';
|
$price_base_type = 'HT';
|
||||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
$pu_ht_devise = price2num($price_ht_devise, 'CU');
|
||||||
|
|
||||||
$result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_ht_devise, $ref_supplier);
|
$result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_ht_devise, $ref_supplier);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ if (empty($reshook))
|
|||||||
|
|
||||||
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
||||||
$remise_percent = GETPOST('remise_percent'.$predef);
|
$remise_percent = GETPOST('remise_percent'.$predef);
|
||||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CR');
|
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU');
|
||||||
|
|
||||||
// Extrafields
|
// Extrafields
|
||||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||||
|
|||||||
Reference in New Issue
Block a user