Fix: Unit prices of products must use the unit precision and not the total precision.
This commit is contained in:
parent
10456c1338
commit
09a304f781
@ -2313,14 +2313,15 @@ function vatrate($rate,$addpercent=false,$info_bits=0)
|
|||||||
* \param html Type de formatage, html ou pas (par defaut)
|
* \param html Type de formatage, html ou pas (par defaut)
|
||||||
* \param outlangs Objet langs pour formatage text
|
* \param outlangs Objet langs pour formatage text
|
||||||
* \param trunc 1=Tronque affichage si trop de decimales,0=Force le non troncage
|
* \param trunc 1=Tronque affichage si trop de decimales,0=Force le non troncage
|
||||||
* \param rounding Nbre decimals minimum.
|
* \param rounding Minimum number of decimal. If not defined we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOTAL)
|
||||||
* \return string Chaine avec montant formate
|
* \return string Chaine avec montant formate
|
||||||
* \seealso price2num Revert function of price
|
* \seealso price2num Revert function of price
|
||||||
*/
|
*/
|
||||||
function price($amount, $html=0, $outlangs='', $trunc=1, $rounding=2)
|
function price($amount, $html=0, $outlangs='', $trunc=1, $rounding=-1)
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs,$conf;
|
||||||
|
|
||||||
|
if ($rounding < 0) $rounding=min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
|
||||||
$nbdecimal=$rounding;
|
$nbdecimal=$rounding;
|
||||||
|
|
||||||
// Output separators by default (french)
|
// Output separators by default (french)
|
||||||
@ -2396,13 +2397,16 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
|
|||||||
// Convert value to universal number format (no thousand separator, '.' as decimal separator)
|
// Convert value to universal number format (no thousand separator, '.' as decimal separator)
|
||||||
if ($alreadysqlnb != 1) // If not a PHP number or unknown, we change format
|
if ($alreadysqlnb != 1) // If not a PHP number or unknown, we change format
|
||||||
{
|
{
|
||||||
//print 'ZZ'.$nbofdec.'=>'.$amount.'<br>';
|
//print 'PP'.$amount.' - '.$dec.' - '.$thousand.'<br>';
|
||||||
|
|
||||||
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
|
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
|
||||||
// to format defined by LC_NUMERIC after a calculation and we want source format to be like defined by Dolibarr setup.
|
// to format defined by LC_NUMERIC after a calculation and we want source format to be like defined by Dolibarr setup.
|
||||||
if (is_numeric($amount))
|
if (is_numeric($amount))
|
||||||
{
|
{
|
||||||
$nbofdec=max(0,strlen($amount-intval($amount))-2);
|
// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
|
||||||
|
$temps=sprintf("%0.10F",$amount-intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
|
||||||
|
$temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
|
||||||
|
$nbofdec=max(0,strlen($temps)-2); // -2 to remove "0."
|
||||||
$amount=number_format($amount,$nbofdec,$dec,$thousand);
|
$amount=number_format($amount,$nbofdec,$dec,$thousand);
|
||||||
}
|
}
|
||||||
//print "QQ".$amount.'<br>';
|
//print "QQ".$amount.'<br>';
|
||||||
@ -2422,18 +2426,22 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
|
|||||||
elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
|
elseif ($rounding == 'MT') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_TOT;
|
||||||
elseif ($rounding == 'MS') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
|
elseif ($rounding == 'MS') $nbofdectoround=$conf->global->MAIN_MAX_DECIMALS_SHOWN;
|
||||||
elseif ($rounding == '2') $nbofdectoround=2; // For admin info page
|
elseif ($rounding == '2') $nbofdectoround=2; // For admin info page
|
||||||
|
//print "RR".$amount.' - '.$nbofdectoround.'<br>';
|
||||||
if (strlen($nbofdectoround)) $amount = round($amount,$nbofdectoround); // $nbofdectoround can be 0.
|
if (strlen($nbofdectoround)) $amount = round($amount,$nbofdectoround); // $nbofdectoround can be 0.
|
||||||
else return 'ErrorBadParameterProvidedToFunction';
|
else return 'ErrorBadParameterProvidedToFunction';
|
||||||
//print 'ZZ'.$nbofdec.'-'.$nbofdectoround.'=>'.$amount.'<br>';
|
//print 'SS'.$amount.' - '.$nbofdec.' - '.$dec.' - '.$thousand.' - '.$nbofdectoround.'<br>';
|
||||||
|
|
||||||
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
|
// Convert amount to format with dolibarr dec and thousand (this is because PHP convert a number
|
||||||
// to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
|
// to format defined by LC_NUMERIC after a calculation and we want source format to be defined by Dolibarr setup.
|
||||||
if (is_numeric($amount))
|
if (is_numeric($amount))
|
||||||
{
|
{
|
||||||
$nbofdec=max(0,strlen($amount-intval($amount))-2);
|
// We put in temps value of decimal ("0.00001"). Works with 0 and 2.0E-5 and 9999.10
|
||||||
|
$temps=sprintf("%0.10F",$amount-intval($amount)); // temps=0.0000000000 or 0.0000200000 or 9999.1000000000
|
||||||
|
$temps=preg_replace('/([\.1-9])0+$/','\\1',$temps); // temps=0. or 0.00002 or 9999.1
|
||||||
|
$nbofdec=max(0,strlen($temps)-2); // -2 to remove "0."
|
||||||
$amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand); // Convert amount to format with dolibarr dec and thousand
|
$amount=number_format($amount,min($nbofdec,$nbofdectoround),$dec,$thousand); // Convert amount to format with dolibarr dec and thousand
|
||||||
}
|
}
|
||||||
//print "RR".$amount.'<br>';
|
//print "TT".$amount.'<br>';
|
||||||
|
|
||||||
// Always make replace because each math function (like round) replace
|
// Always make replace because each math function (like round) replace
|
||||||
// with local values and we want a number that has a SQL string format x.y
|
// with local values and we want a number that has a SQL string format x.y
|
||||||
|
|||||||
@ -824,7 +824,7 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
global $conf,$langs;
|
global $conf,$langs;
|
||||||
|
|
||||||
dol_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level, LOG_DEBUG);
|
dol_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level);
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
if (empty($this->tva_tx)) $this->tva_tx=0;
|
if (empty($this->tva_tx)) $this->tva_tx=0;
|
||||||
@ -863,6 +863,7 @@ class Product extends CommonObject
|
|||||||
$price_min = price2num($newminprice,'MU');
|
$price_min = price2num($newminprice,'MU');
|
||||||
$price_min_ttc = price2num($newminprice) * (1 + ($newvat / 100));
|
$price_min_ttc = price2num($newminprice) * (1 + ($newvat / 100));
|
||||||
$price_min_ttc = price2num($price_min_ttc,'MU');
|
$price_min_ttc = price2num($price_min_ttc,'MU');
|
||||||
|
//print 'X'.$newminprice.'-'.$price_min;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -883,7 +884,7 @@ class Product extends CommonObject
|
|||||||
$sql.= " tva_tx='".price2num($newvat)."'";
|
$sql.= " tva_tx='".price2num($newvat)."'";
|
||||||
$sql.= " WHERE rowid = " . $id;
|
$sql.= " WHERE rowid = " . $id;
|
||||||
|
|
||||||
dol_syslog("Product::update_price sql=".$sql);
|
dol_syslog("Product::update_price sql=".$sql, LOG_DEBUG);
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user