FIX Lines are not inserted correctly if VAT have code

This commit is contained in:
Ferran Marcet 2018-12-03 12:28:17 +01:00
parent 135a94dfed
commit 7247b14bd9
7 changed files with 342 additions and 326 deletions

View File

@ -416,6 +416,8 @@ class Propal extends CommonObject
global $mysoc, $conf, $langs; global $mysoc, $conf, $langs;
dol_syslog(get_class($this)."::addline propalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type, fk_remise_except=".$fk_remise_except); dol_syslog(get_class($this)."::addline propalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type, fk_remise_except=".$fk_remise_except);
if ($this->statut == self::STATUS_DRAFT)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters // Clean parameters
@ -425,22 +427,14 @@ class Propal extends CommonObject
if (empty($rang)) $rang=0; if (empty($rang)) $rang=0;
if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$qty=price2num($qty); $qty=price2num($qty);
$pu_ht=price2num($pu_ht); $pu_ht=price2num($pu_ht);
$pu_ht_devise=price2num($pu_ht_devise); $pu_ht_devise=price2num($pu_ht_devise);
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
$txtva=price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1=price2num($txlocaltax1); $txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2); $txlocaltax2=price2num($txlocaltax2);
$pa_ht=price2num($pa_ht); $pa_ht=price2num($pa_ht);
@ -456,8 +450,6 @@ class Propal extends CommonObject
// Check parameters // Check parameters
if ($type < 0) return -1; if ($type < 0) return -1;
if ($this->statut == self::STATUS_DRAFT)
{
$this->db->begin(); $this->db->begin();
$product_type=$type; $product_type=$type;
@ -480,6 +472,16 @@ class Propal extends CommonObject
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];

View File

@ -1270,6 +1270,8 @@ class Commande extends CommonOrder
dol_syslog(get_class($this)."::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit, origin=$origin, origin_id=$origin_id, pu_ht_devise=$pu_ht_devise", LOG_DEBUG); dol_syslog(get_class($this)."::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit, origin=$origin, origin_id=$origin_id, pu_ht_devise=$pu_ht_devise", LOG_DEBUG);
if ($this->statut == self::STATUS_DRAFT)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters // Clean parameters
@ -1283,23 +1285,15 @@ class Commande extends CommonOrder
if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0;
if (empty($this->fk_multicurrency)) $this->fk_multicurrency=0; if (empty($this->fk_multicurrency)) $this->fk_multicurrency=0;
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$qty=price2num($qty); $qty=price2num($qty);
$pu_ht=price2num($pu_ht); $pu_ht=price2num($pu_ht);
$pu_ht_devise=price2num($pu_ht_devise); $pu_ht_devise=price2num($pu_ht_devise);
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
$pa_ht=price2num($pa_ht); $pa_ht=price2num($pa_ht);
$txtva = price2num($txtva); if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1 = price2num($txlocaltax1); $txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2); $txlocaltax2 = price2num($txlocaltax2);
if ($price_base_type=='HT') if ($price_base_type=='HT')
@ -1316,8 +1310,6 @@ class Commande extends CommonOrder
// Check parameters // Check parameters
if ($type < 0) return -1; if ($type < 0) return -1;
if ($this->statut == self::STATUS_DRAFT)
{
$this->db->begin(); $this->db->begin();
$product_type=$type; $product_type=$type;
@ -1336,12 +1328,21 @@ class Commande extends CommonOrder
return self::STOCK_NOT_ENOUGH_FOR_ORDER; return self::STOCK_NOT_ENOUGH_FOR_ORDER;
} }
} }
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva // qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
/*var_dump($txlocaltax1); /*var_dump($txlocaltax1);

View File

@ -2580,6 +2580,8 @@ class Facture extends CommonInvoice
global $mysoc, $conf, $langs; global $mysoc, $conf, $langs;
dol_syslog(get_class($this)."::addline id=$this->id,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type, fk_unit=$fk_unit", LOG_DEBUG); dol_syslog(get_class($this)."::addline id=$this->id,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type, fk_unit=$fk_unit", LOG_DEBUG);
if (! empty($this->brouillon))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters // Clean parameters
@ -2595,23 +2597,15 @@ class Facture extends CommonInvoice
if (empty($fk_prev_id)) $fk_prev_id = 'null'; if (empty($fk_prev_id)) $fk_prev_id = 'null';
if (! isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') $situation_percent = 100; if (! isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') $situation_percent = 100;
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$qty=price2num($qty); $qty=price2num($qty);
$pu_ht=price2num($pu_ht); $pu_ht=price2num($pu_ht);
$pu_ht_devise=price2num($pu_ht_devise); $pu_ht_devise=price2num($pu_ht_devise);
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
$pa_ht=price2num($pa_ht); $pa_ht=price2num($pa_ht);
$txtva=price2num($txtva); if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1=price2num($txlocaltax1); $txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2); $txlocaltax2=price2num($txlocaltax2);
@ -2627,8 +2621,6 @@ class Facture extends CommonInvoice
// Check parameters // Check parameters
if ($type < 0) return -1; if ($type < 0) return -1;
if (! empty($this->brouillon))
{
$this->db->begin(); $this->db->begin();
$product_type=$type; $product_type=$type;
@ -2651,6 +2643,16 @@ class Facture extends CommonInvoice
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx, $pu_ht_devise); $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx, $pu_ht_devise);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];

View File

@ -1358,21 +1358,13 @@ class Contrat extends CommonObject
{ {
$this->db->begin(); $this->db->begin();
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
// Clean parameters // Clean parameters
$pu_ht=price2num($pu_ht); $pu_ht=price2num($pu_ht);
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
$pa_ht=price2num($pa_ht); $pa_ht=price2num($pa_ht);
$txtva=price2num($txtva); if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1=price2num($txlocaltax1); $txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2); $txlocaltax2=price2num($txlocaltax2);
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
@ -1402,6 +1394,16 @@ class Contrat extends CommonObject
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->societe, $mysoc);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type); $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1,$mysoc, $localtaxes_type);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];

View File

@ -1678,6 +1678,8 @@ class ExpenseReport extends CommonObject
dol_syslog(get_class($this)."::addline qty=$qty, up=$up, fk_c_type_fees=$fk_c_type_fees, vatrate=$vatrate, date=$date, fk_project=$fk_project, type=$type, comments=$comments", LOG_DEBUG); dol_syslog(get_class($this)."::addline qty=$qty, up=$up, fk_c_type_fees=$fk_c_type_fees, vatrate=$vatrate, date=$date, fk_project=$fk_project, type=$type, comments=$comments", LOG_DEBUG);
if ($this->fk_statut == self::STATUS_DRAFT)
{
if (empty($qty)) $qty = 0; if (empty($qty)) $qty = 0;
if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) $fk_c_type_fees = 0; if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) $fk_c_type_fees = 0;
if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) $fk_c_exp_tax_cat = 0; if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) $fk_c_exp_tax_cat = 0;
@ -1685,22 +1687,21 @@ class ExpenseReport extends CommonObject
if (empty($date)) $date = ''; if (empty($date)) $date = '';
if (empty($fk_project)) $fk_project = 0; if (empty($fk_project)) $fk_project = 0;
$qty = price2num($qty);
if (!preg_match('/\((.*)\)/', $vatrate)) {
$vatrate = price2num($vatrate); // $txtva can have format '5.0(XXX)' or '5'
}
$up = price2num($up);
$this->db->begin();
$this->line = new ExpenseReportLine($this->db);
if (preg_match('/\((.*)\)/', $vatrate, $reg)) if (preg_match('/\((.*)\)/', $vatrate, $reg))
{ {
$vat_src_code = $reg[1]; $vat_src_code = $reg[1];
$vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate.
} }
$qty = price2num($qty);
$vatrate = price2num($vatrate);
$up = price2num($up);
if ($this->fk_statut == self::STATUS_DRAFT)
{
$this->db->begin();
$this->line = new ExpenseReportLine($this->db);
$vatrate = preg_replace('/\*/','',$vatrate); $vatrate = preg_replace('/\*/','',$vatrate);
$seller = ''; // seller is unknown $seller = ''; // seller is unknown

View File

@ -1425,6 +1425,9 @@ class CommandeFournisseur extends CommonOrder
$error = 0; $error = 0;
dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $fk_prod_fourn_price, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, $fk_unit, $pu_ht_devise, $origin, $origin_id"); dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $fk_prod_fourn_price, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, $fk_unit, $pu_ht_devise, $origin, $origin_id");
if ($this->statut == self::STATUS_DRAFT)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters // Clean parameters
@ -1435,22 +1438,14 @@ class CommandeFournisseur extends CommonOrder
if (empty($txlocaltax2)) $txlocaltax2=0; if (empty($txlocaltax2)) $txlocaltax2=0;
if (empty($remise_percent)) $remise_percent=0; if (empty($remise_percent)) $remise_percent=0;
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc,$this->thirdparty);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$qty=price2num($qty); $qty=price2num($qty);
$pu_ht=price2num($pu_ht); $pu_ht=price2num($pu_ht);
$pu_ht_devise=price2num($pu_ht_devise); $pu_ht_devise=price2num($pu_ht_devise);
$pu_ttc=price2num($pu_ttc); $pu_ttc=price2num($pu_ttc);
$txtva = price2num($txtva); if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1 = price2num($txlocaltax1); $txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2); $txlocaltax2 = price2num($txlocaltax2);
if ($price_base_type=='HT') if ($price_base_type=='HT')
@ -1471,8 +1466,7 @@ class CommandeFournisseur extends CommonOrder
} }
if ($type < 0) return -1; if ($type < 0) return -1;
if ($this->statut == 0)
{
$this->db->begin(); $this->db->begin();
if ($fk_product > 0) if ($fk_product > 0)
@ -1542,6 +1536,16 @@ class CommandeFournisseur extends CommonOrder
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc,$this->thirdparty);
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
$vat_src_code = $reg[1];
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
}
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx,$pu_ht_devise); $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx,$pu_ht_devise);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];

View File

@ -1392,6 +1392,7 @@ class FactureFournisseur extends CommonInvoice
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
global $mysoc; global $mysoc;
if ($this->statut == self::STATUS_DRAFT){
// Clean parameters // Clean parameters
if (empty($remise_percent)) $remise_percent=0; if (empty($remise_percent)) $remise_percent=0;
if (empty($qty)) $qty=0; if (empty($qty)) $qty=0;
@ -1407,6 +1408,15 @@ class FactureFournisseur extends CommonInvoice
$rang = $rangmax + 1; $rang = $rangmax + 1;
} }
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
$pu=price2num($pu);
if (!preg_match('/\((.*)\)/', $txtva)) {
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
}
$txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2);
$localtaxes_type=getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty); $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);
// Clean vat code // Clean vat code
@ -1417,13 +1427,6 @@ class FactureFournisseur extends CommonInvoice
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
} }
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
$pu=price2num($pu);
$txtva=price2num($txtva);
$txlocaltax1=price2num($txlocaltax1);
$txlocaltax2=price2num($txlocaltax2);
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
$total_ht = $tabprice[0]; $total_ht = $tabprice[0];
$total_tva = $tabprice[1]; $total_tva = $tabprice[1];
@ -1524,6 +1527,7 @@ class FactureFournisseur extends CommonInvoice
return -2; return -2;
} }
} }
}
/** /**
* Update a line detail into database * Update a line detail into database