Fix Must make a difference between a buying/cost price == '' (not

provided) and buying/cost price = '0'. We must use default value only if
value is '' and not if forced to '0'.
This commit is contained in:
Laurent Destailleur 2015-11-04 17:51:15 +01:00
parent 832afa139a
commit a7795f25fc
7 changed files with 36 additions and 29 deletions

View File

@ -743,7 +743,7 @@ if (empty($reshook))
// Add buying price
$fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
$buyingprice = (GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
// Extrafields
$extrafieldsline = new ExtraFields($db);

View File

@ -859,8 +859,8 @@ if (empty($reshook))
}
// Margin
$fournprice = (GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
$buyingprice = (GETPOST('buying_price' . $predef) ? GETPOST('buying_price' . $predef) : '');
$fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
$buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
$date_start = dol_mktime(0, 0, 0, GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
$date_end = dol_mktime(0, 0, 0, GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
@ -954,8 +954,8 @@ if (empty($reshook))
$pu_ht = GETPOST('price_ht');
// Add buying price
$fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
$date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
$date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));

View File

@ -400,7 +400,7 @@ class Propal extends CommonObject
$txtva=price2num($txtva);
$txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2);
$pa_ht=price2num($pa_ht);
$pa_ht=price2num($pa_ht);
if ($price_base_type=='HT')
{
$pu=$pu_ht;
@ -3086,6 +3086,8 @@ class PropaleLigne extends CommonObjectLine
dol_syslog(get_class($this)."::insert rang=".$this->rang);
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
// Clean parameters
if (empty($this->tva_tx)) $this->tva_tx=0;
if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
@ -3102,11 +3104,10 @@ class PropaleLigne extends CommonObjectLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (! is_numeric($this->qty)) $this->qty = 0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{
@ -3254,7 +3255,7 @@ class PropaleLigne extends CommonObjectLine
/**
* Update propal line object into DB
*
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* @return int <0 if ko, >0 if ok
*/
function update($notrigger=0)
@ -3263,6 +3264,8 @@ class PropaleLigne extends CommonObjectLine
$error=0;
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
// Clean parameters
if (empty($this->tva_tx)) $this->tva_tx=0;
if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
@ -3281,11 +3284,10 @@ class PropaleLigne extends CommonObjectLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_fournprice)) $this->fk_fournprice=0;
if (empty($this->subprice)) $this->subprice=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{

View File

@ -733,8 +733,8 @@ if (empty($reshook))
}
// Margin
$fournprice = (GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
$buyingprice = (GETPOST('buying_price' . $predef) ? GETPOST('buying_price' . $predef) : '');
$fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
$buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
// Local Taxes
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
@ -833,9 +833,9 @@ if (empty($reshook))
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
// Add buying price
$fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = (GETPOST('buying_price') ? GETPOST('buying_price') : '');
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
// Extrafields Lines
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);

View File

@ -3507,6 +3507,8 @@ class OrderLine extends CommonOrderLine
$error=0;
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
dol_syslog(get_class($this)."::insert rang=".$this->rang);
// Clean parameters
@ -3523,11 +3525,10 @@ class OrderLine extends CommonOrderLine
if (empty($this->info_bits)) $this->info_bits=0;
if (empty($this->special_code)) $this->special_code=0;
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{
@ -3641,6 +3642,8 @@ class OrderLine extends CommonOrderLine
$error=0;
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
// Clean parameters
if (empty($this->tva_tx)) $this->tva_tx=0;
if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
@ -3661,7 +3664,7 @@ class OrderLine extends CommonOrderLine
if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{

View File

@ -1400,7 +1400,7 @@ if (empty($reshook))
// Margin
$fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
$buyingprice = price2num(GETPOST('buying_price' . $predef) ? GETPOST('buying_price' . $predef) : '');
$buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
// Local Taxes
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
@ -1507,8 +1507,8 @@ if (empty($reshook))
// Add buying price
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') ? GETPOST('buying_price') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);

View File

@ -3852,7 +3852,9 @@ class FactureLigne extends CommonInvoiceLine
$error=0;
dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG);
// Clean parameters
$this->desc=trim($this->desc);
@ -3871,11 +3873,10 @@ class FactureLigne extends CommonInvoiceLine
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (empty($this->fk_prev_id)) $this->fk_prev_id = 'null';
if (empty($this->situation_percent)) $this->situation_percent = 0;
if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{
@ -4050,6 +4051,8 @@ class FactureLigne extends CommonInvoiceLine
$error=0;
$pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'.
// Clean parameters
$this->desc=trim($this->desc);
if (empty($this->tva_tx)) $this->tva_tx=0;
@ -4065,14 +4068,13 @@ class FactureLigne extends CommonInvoiceLine
if (empty($this->product_type)) $this->product_type=0;
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
if (is_null($this->situation_percent)) $this->situation_percent=100;
if (empty($this->pa_ht)) $this->pa_ht=0;
// Check parameters
if ($this->product_type < 0) return -1;
if (empty($this->pa_ht)) $this->pa_ht=0;
// if buy price not defined, define buyprice as configured in margin admin
if ($this->pa_ht == 0)
if ($this->pa_ht == 0 && $pa_ht_isemptystring)
{
if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0)
{