NEW Usage of vat code seems ok everywhere.

This commit is contained in:
Laurent Destailleur 2016-10-29 21:02:08 +02:00
parent 03b882d095
commit e9edbba093
9 changed files with 267 additions and 182 deletions

View File

@ -389,8 +389,8 @@ class Propal extends CommonObject
* @param int $date_end End date of the line
* @param array $array_options extrafields array
* @param string $fk_unit Code of the unit to use. Null to use the default one
* @param string $origin 'order', ...
* @param int $origin_id Id of origin object
* @param string $origin 'order', ...
* @param int $origin_id Id of origin object
* @return int >0 if OK, <0 if KO
*
* @see add_product
@ -454,7 +454,14 @@ class Propal extends CommonObject
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// 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);
@ -496,6 +503,8 @@ class Propal extends CommonObject
$this->line->label=$label;
$this->line->desc=$desc;
$this->line->qty=$qty;
$this->line->vat_src_code=$vat_src_code;
$this->line->tva_tx=$txtva;
$this->line->localtax1_tx=$txlocaltax1;
$this->line->localtax2_tx=$txlocaltax2;
@ -629,7 +638,14 @@ class Propal extends CommonObject
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// 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, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx);
$total_ht = $tabprice[0];
@ -681,6 +697,8 @@ class Propal extends CommonObject
$this->line->remise_percent = $remise_percent;
$this->line->subprice = $pu;
$this->line->info_bits = $info_bits;
$this->line->vat_src_code = $vat_src_code;
$this->line->total_ht = $total_ht;
$this->line->total_tva = $total_tva;
$this->line->total_localtax1 = $total_localtax1;
@ -3288,14 +3306,14 @@ class Propal extends CommonObject
// For other object, here we call fetch_lines. But fetch_lines does not exists on proposal
$sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
$sql.= ' pt.qty, pt.vat_src_code, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
$sql.= ' pt.date_start, pt.date_end, pt.product_type, pt.rang, pt.fk_parent_line,';
$sql.= ' pt.fk_unit,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
$sql.= ' p.description as product_desc,';
$sql.= ' p.entity';
$sql.= ' ,pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc';
$sql.= ' p.entity,';
$sql.= ' pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
$sql.= ' WHERE pt.fk_propal = '.$this->id;
@ -3330,6 +3348,8 @@ class Propal extends CommonObject
$this->lines[$i]->subprice = $obj->subprice;
$this->lines[$i]->fk_remise_except = $obj->fk_remise_except;
$this->lines[$i]->remise_percent = $obj->remise_percent;
$this->lines[$i]->vat_src_code = $obj->vat_src_code;
$this->lines[$i]->tva_tx = $obj->tva_tx;
$this->lines[$i]->info_bits = $obj->info_bits;
$this->lines[$i]->total_ht = $obj->total_ht;
@ -3685,7 +3705,7 @@ class PropaleLigne extends CommonObjectLine
// Insert line into database
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet';
$sql.= ' (fk_propal, fk_parent_line, label, description, fk_product, product_type,';
$sql.= ' fk_remise_except, qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' fk_remise_except, qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' subprice, remise_percent, ';
$sql.= ' info_bits, ';
$sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
@ -3700,6 +3720,7 @@ class PropaleLigne extends CommonObjectLine
$sql.= " '".$this->product_type."',";
$sql.= " ".($this->fk_remise_except?"'".$this->fk_remise_except."'":"null").",";
$sql.= " ".price2num($this->qty).",";
$sql.= " ".(empty($this->vat_src_code)?"''":"'".$this->vat_src_code."'").",";
$sql.= " ".price2num($this->tva_tx).",";
$sql.= " ".price2num($this->localtax1_tx).",";
$sql.= " ".price2num($this->localtax2_tx).",";
@ -3873,41 +3894,42 @@ class PropaleLigne extends CommonObjectLine
// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET";
$sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= " , label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= " , product_type=".$this->product_type;
$sql.= " , tva_tx='".price2num($this->tva_tx)."'";
$sql.= " , localtax1_tx=".price2num($this->localtax1_tx);
$sql.= " , localtax2_tx=".price2num($this->localtax2_tx);
$sql.= " , localtax1_type='".$this->localtax1_type."'";
$sql.= " , localtax2_type='".$this->localtax2_type."'";
$sql.= " , qty='".price2num($this->qty)."'";
$sql.= " , subprice=".price2num($this->subprice)."";
$sql.= " , remise_percent=".price2num($this->remise_percent)."";
$sql.= " , price=".price2num($this->price).""; // TODO A virer
$sql.= " , remise=".price2num($this->remise).""; // TODO A virer
$sql.= " , info_bits='".$this->info_bits."'";
$sql.= ", label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= ", product_type=".$this->product_type;
$sql.= ", vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'";
$sql.= ", tva_tx='".price2num($this->tva_tx)."'";
$sql.= ", localtax1_tx=".price2num($this->localtax1_tx);
$sql.= ", localtax2_tx=".price2num($this->localtax2_tx);
$sql.= ", localtax1_type='".$this->localtax1_type."'";
$sql.= ", localtax2_type='".$this->localtax2_type."'";
$sql.= ", qty='".price2num($this->qty)."'";
$sql.= ", subprice=".price2num($this->subprice)."";
$sql.= ", remise_percent=".price2num($this->remise_percent)."";
$sql.= ", price=".price2num($this->price).""; // TODO A virer
$sql.= ", remise=".price2num($this->remise).""; // TODO A virer
$sql.= ", info_bits='".$this->info_bits."'";
if (empty($this->skip_update_total))
{
$sql.= " , total_ht=".price2num($this->total_ht)."";
$sql.= " , total_tva=".price2num($this->total_tva)."";
$sql.= " , total_ttc=".price2num($this->total_ttc)."";
$sql.= " , total_localtax1=".price2num($this->total_localtax1)."";
$sql.= " , total_localtax2=".price2num($this->total_localtax2)."";
$sql.= ", total_ht=".price2num($this->total_ht)."";
$sql.= ", total_tva=".price2num($this->total_tva)."";
$sql.= ", total_ttc=".price2num($this->total_ttc)."";
$sql.= ", total_localtax1=".price2num($this->total_localtax1)."";
$sql.= ", total_localtax2=".price2num($this->total_localtax2)."";
}
$sql.= " , fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->fk_fournprice."'":"null");
$sql.= " , buy_price_ht=".price2num($this->pa_ht);
if (strlen($this->special_code)) $sql.= " , special_code=".$this->special_code;
$sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
$sql.= ", fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->fk_fournprice."'":"null");
$sql.= ", buy_price_ht=".price2num($this->pa_ht);
if (strlen($this->special_code)) $sql.= ", special_code=".$this->special_code;
$sql.= ", fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql.= " , date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= " , date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= ", date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= ", date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
// Multicurrency
$sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
$sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= ", multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
$sql.= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= " WHERE rowid = ".$this->rowid;

View File

@ -1285,7 +1285,14 @@ class Commande extends CommonOrder
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// 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);
@ -1327,6 +1334,8 @@ class Commande extends CommonOrder
$this->line->label=$label;
$this->line->desc=$desc;
$this->line->qty=$qty;
$this->line->vat_src_code=$vat_src_code;
$this->line->tva_tx=$txtva;
$this->line->localtax1_tx=$txlocaltax1;
$this->line->localtax2_tx=$txlocaltax2;
@ -1727,7 +1736,7 @@ class Commande extends CommonOrder
{
$this->lines=array();
$sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.tva_tx,';
$sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.vat_src_code, l.tva_tx,';
$sql.= ' l.localtax1_tx, l.localtax2_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.rang, l.info_bits, l.special_code,';
$sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,';
$sql.= ' l.fk_unit,';
@ -1762,6 +1771,8 @@ class Commande extends CommonOrder
$line->description = $objp->description; // Description line
$line->product_type = $objp->product_type;
$line->qty = $objp->qty;
$line->vat_src_code = $objp->vat_src_code;
$line->tva_tx = $objp->tva_tx;
$line->localtax1_tx = $objp->localtax1_tx;
$line->localtax2_tx = $objp->localtax2_tx;
@ -2774,7 +2785,14 @@ class Commande extends CommonOrder
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// 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, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx);
@ -2848,26 +2866,28 @@ class Commande extends CommonOrder
$this->line->label=$label;
$this->line->desc=$desc;
$this->line->qty=$qty;
$this->line->tva_tx=$txtva;
$this->line->localtax1_tx=$txlocaltax1;
$this->line->localtax2_tx=$txlocaltax2;
$this->line->vat_src_code = $vat_src_code;
$this->line->tva_tx = $txtva;
$this->line->localtax1_tx = $txlocaltax1;
$this->line->localtax2_tx = $txlocaltax2;
$this->line->localtax1_type = $localtaxes_type[0];
$this->line->localtax2_type = $localtaxes_type[2];
$this->line->remise_percent=$remise_percent;
$this->line->subprice=$subprice;
$this->line->info_bits=$info_bits;
$this->line->special_code=$special_code;
$this->line->total_ht=$total_ht;
$this->line->total_tva=$total_tva;
$this->line->total_localtax1=$total_localtax1;
$this->line->total_localtax2=$total_localtax2;
$this->line->total_ttc=$total_ttc;
$this->line->date_start=$date_start;
$this->line->date_end=$date_end;
$this->line->product_type=$type;
$this->line->fk_parent_line=$fk_parent_line;
$this->line->remise_percent = $remise_percent;
$this->line->subprice = $subprice;
$this->line->info_bits = $info_bits;
$this->line->special_code = $special_code;
$this->line->total_ht = $total_ht;
$this->line->total_tva = $total_tva;
$this->line->total_localtax1= $total_localtax1;
$this->line->total_localtax2= $total_localtax2;
$this->line->total_ttc = $total_ttc;
$this->line->date_start = $date_start;
$this->line->date_end = $date_end;
$this->line->product_type = $type;
$this->line->fk_parent_line = $fk_parent_line;
$this->line->skip_update_total=$skip_update_total;
$this->line->fk_unit=$fk_unit;
$this->line->fk_unit = $fk_unit;
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
@ -3931,7 +3951,7 @@ class OrderLine extends CommonOrderLine
// Insertion dans base de la ligne
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet';
$sql.= ' (fk_commande, fk_parent_line, label, description, qty, ';
$sql.= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,';
$sql.= ' special_code, rang, fk_product_fournisseur_price, buy_price_ht,';
$sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end,';
@ -3943,6 +3963,7 @@ class OrderLine extends CommonOrderLine
$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
$sql.= " '".$this->db->escape($this->desc)."',";
$sql.= " '".price2num($this->qty)."',";
$sql.= " ".(empty($this->vat_src_code)?"''":"'".$this->vat_src_code."'").",";
$sql.= " '".price2num($this->tva_tx)."',";
$sql.= " '".price2num($this->localtax1_tx)."',";
$sql.= " '".price2num($this->localtax2_tx)."',";

View File

@ -2626,7 +2626,14 @@ class Facture extends CommonInvoice
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// 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, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx);
@ -2690,7 +2697,7 @@ class Facture extends CommonInvoice
$this->line->desc = $desc;
$this->line->qty = ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative
$this->line->vat_src_code=$vat_src_code;
$this->line->vat_src_code = $vat_src_code;
$this->line->tva_tx = $txtva;
$this->line->localtax1_tx = $txlocaltax1;
$this->line->localtax2_tx = $txlocaltax2;
@ -4543,43 +4550,43 @@ class FactureLigne extends CommonInvoiceLine
// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
$sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= ",label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= ",subprice=".price2num($this->subprice)."";
$sql.= ",remise_percent=".price2num($this->remise_percent)."";
if ($this->fk_remise_except) $sql.= ",fk_remise_except=".$this->fk_remise_except;
else $sql.= ",fk_remise_except=null";
$sql.= ",vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'";
$sql.= ",tva_tx=".price2num($this->tva_tx)."";
$sql.= ",localtax1_tx=".price2num($this->localtax1_tx)."";
$sql.= ",localtax2_tx=".price2num($this->localtax2_tx)."";
$sql.= ",localtax1_type='".$this->localtax1_type."'";
$sql.= ",localtax2_type='".$this->localtax2_type."'";
$sql.= ",qty=".price2num($this->qty)."";
$sql.= ",date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= ",date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ",product_type=".$this->product_type;
$sql.= ",info_bits='".$this->info_bits."'";
$sql.= ",special_code='".$this->special_code."'";
$sql.= ", label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= ", subprice=".price2num($this->subprice)."";
$sql.= ", remise_percent=".price2num($this->remise_percent)."";
if ($this->fk_remise_except) $sql.= ", fk_remise_except=".$this->fk_remise_except;
else $sql.= ", fk_remise_except=null";
$sql.= ", vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'";
$sql.= ", tva_tx=".price2num($this->tva_tx)."";
$sql.= ", localtax1_tx=".price2num($this->localtax1_tx)."";
$sql.= ", localtax2_tx=".price2num($this->localtax2_tx)."";
$sql.= ", localtax1_type='".$this->localtax1_type."'";
$sql.= ", localtax2_type='".$this->localtax2_type."'";
$sql.= ", qty=".price2num($this->qty)."";
$sql.= ", date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= ", date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ", product_type=".$this->product_type;
$sql.= ", info_bits='".$this->info_bits."'";
$sql.= ", special_code='".$this->special_code."'";
if (empty($this->skip_update_total))
{
$sql.= ",total_ht=".price2num($this->total_ht)."";
$sql.= ",total_tva=".price2num($this->total_tva)."";
$sql.= ",total_ttc=".price2num($this->total_ttc)."";
$sql.= ",total_localtax1=".price2num($this->total_localtax1)."";
$sql.= ",total_localtax2=".price2num($this->total_localtax2)."";
$sql.= ", total_ht=".price2num($this->total_ht)."";
$sql.= ", total_tva=".price2num($this->total_tva)."";
$sql.= ", total_ttc=".price2num($this->total_ttc)."";
$sql.= ", total_localtax1=".price2num($this->total_localtax1)."";
$sql.= ", total_localtax2=".price2num($this->total_localtax2)."";
}
$sql.= " , fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null");
$sql.= " , buy_price_ht='".price2num($this->pa_ht)."'";
$sql.= ",fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
$sql.= ", fk_product_fournisseur_price=".(! empty($this->fk_fournprice)?"'".$this->db->escape($this->fk_fournprice)."'":"null");
$sql.= ", buy_price_ht='".price2num($this->pa_ht)."'";
$sql.= ", fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql .= ", situation_percent=" . $this->situation_percent;
$sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= ", situation_percent=" . $this->situation_percent;
$sql.= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
// Multicurrency
$sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
$sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= ", multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
$sql.= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= " WHERE rowid = ".$this->rowid;

View File

@ -4214,21 +4214,21 @@ class Form
* Output an HTML select vat rate.
* The name of this function should be selectVat. We keep bad name for compatibility purpose.
*
* @param string $htmlname Name of HTML select field
* @param float|string $selectedrate Force preselected vat rate. Can be '8.5' or '8.5 (NOO)' for example. Use '' for no forcing.
* @param Societe $societe_vendeuse Thirdparty seller
* @param Societe $societe_acheteuse Thirdparty buyer
* @param int $idprod Id product
* @param int $info_bits Miscellaneous information on line (1 for NPR)
* @param int $type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
* Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle.
* Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
* Si (vendeur et acheteur dans Communaute europeenne) et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
* Si vendeur et acheteur dans Communauté européenne et acheteur= particulier alors TVA par défaut=TVA du produit vendu. Fin de règle.
* Si vendeur et acheteur dans Communauté européenne et acheteur= entreprise alors TVA par défaut=0. Fin de règle.
* Sinon la TVA proposee par defaut=0. Fin de regle.
* @param bool $options_only Return HTML options lines only (for ajax treatment)
* @param int $addcode Add code into key in select list
* @param string $htmlname Name of HTML select field
* @param float|string $selectedrate Force preselected vat rate. Can be '8.5' or '8.5 (NOO)' for example. Use '' for no forcing.
* @param Societe $societe_vendeuse Thirdparty seller
* @param Societe $societe_acheteuse Thirdparty buyer
* @param int $idprod Id product
* @param int $info_bits Miscellaneous information on line (1 for NPR)
* @param int $type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
* Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle.
* Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
* Si (vendeur et acheteur dans Communaute europeenne) et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
* Si vendeur et acheteur dans Communauté européenne et acheteur= particulier alors TVA par défaut=TVA du produit vendu. Fin de règle.
* Si vendeur et acheteur dans Communauté européenne et acheteur= entreprise alors TVA par défaut=0. Fin de règle.
* Sinon la TVA proposee par defaut=0. Fin de regle.
* @param bool $options_only Return HTML options lines only (for ajax treatment)
* @param int $addcode Add code into key in select list
* @return string
*/
function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false, $addcode=0)
@ -4242,7 +4242,7 @@ class Form
$defaultnpr=(preg_match('/\*/',$selectedrate) ? 1 : $defaultnpr);
$defaulttx=str_replace('*','',$selectedrate);
$defaultcode='';
if (preg_match('/\s*\((.*)\)/', $defaulttx, $reg))
if (preg_match('/\((.*)\)/', $defaulttx, $reg))
{
$defaultcode=$reg[1];
$defaulttx=preg_replace('/\s*\(.*\)/','',$defaulttx);
@ -4337,6 +4337,7 @@ class Form
if (! $options_only) $return.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').$title.'>';
$selectedfound=false;
foreach ($this->cache_vatrates as $rate)
{
// Keep only 0 if seller is not subject to VAT
@ -4346,13 +4347,21 @@ class Form
$return.= $rate['nprtva'] ? '*': '';
if ($addcode && $rate['code']) $return.=' ('.$rate['code'].')';
$return.= '"';
if ($defaultcode) // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag
if (! $selectedfound)
{
if ($defaultcode == $rate['code']) $return.= ' selected';
}
elseif ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr)
{
$return.= ' selected';
if ($defaultcode) // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag
{
if ($defaultcode == $rate['code'])
{
$return.= ' selected';
$selectedfound=true;
}
}
elseif ($rate['txtva'] == $defaulttx && $rate['nprtva'] == $defaultnpr)
{
$return.= ' selected';
$selectedfound=true;
}
}
$return.= '>'.vatrate($rate['libtva']);
//$return.=($rate['code']?' '.$rate['code']:'');

View File

@ -3327,13 +3327,13 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
* Return a string with VAT rate label formated for view output
* Used into pdf and HTML pages
*
* @param float $rate Rate value to format (19.6 19,6 19.6% 19,6%,...)
* @param string $rate Rate value to format ('19.6', '19,6', '19.6%', '19,6%', '19.6 (CODEX)', ...)
* @param boolean $addpercent Add a percent % sign in output
* @param int $info_bits Miscellaneous information on vat (0=Default, 1=French NPR vat)
* @param int $usestarfornpr 1=Use '*' for NPR vat rate intead of MAIN_LABEL_MENTION_NPR
* @return string String with formated amounts (19,6 or 19,6% or 8.5% NPR or 8.5% *)
* @return string String with formated amounts ('19,6' or '19,6%' or '8.5% (NPR)' or '8.5% *' or '19,6 (CODEX)')
*/
function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
{
$morelabel='';
@ -3345,7 +3345,7 @@ function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
if (preg_match('/\((.*)\)/',$rate,$reg))
{
$morelabel=' ('.$reg[1].')';
$rate=preg_replace('/'.preg_quote($morelabel,'/').'/','',$rate);
$rate=preg_replace('/\s*'.preg_quote($morelabel,'/').'/','',$rate);
}
if (preg_match('/\*/',$rate) || preg_match('/'.constant('MAIN_LABEL_MENTION_NPR').'/i',$rate))
{

View File

@ -111,7 +111,7 @@ $coldisplay=-1; // We remove first td
<?php
$coldisplay++;
if ($this->situation_counter == 1 || !$this->situation_cycle_ref) {
print '<td align="right">' . $form->load_tva('tva_tx', $line->tva_tx, $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1) . '</td>';
print '<td align="right">' . $form->load_tva('tva_tx', $line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''), $seller, $buyer, 0, $line->info_bits, $line->product_type, false, 1) . '</td>';
} else {
print '<td align="right"><input size="1" type="text" class="flat" name="tva_tx" value="' . price($line->tva_tx) . '" readonly />%</td>';
}

View File

@ -129,8 +129,10 @@ if (empty($usemargins)) $usemargins=0;
</td>
<?php if ($object->element == 'supplier_proposal') { ?>
<td class="linecolrefsupplier" align="right"><?php echo $line->ref_fourn; ?></td>
<?php } ?>
<td align="right" class="linecolvat nowrap"><?php $coldisplay++; ?><?php echo vatrate($line->tva_tx,'%',$line->info_bits); ?></td>
<?php }
// VAT Rate
?>
<td align="right" class="linecolvat nowrap"><?php $coldisplay++; ?><?php echo vatrate($line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''),'%',$line->info_bits); ?></td>
<td align="right" class="linecoluht nowrap"><?php $coldisplay++; ?><?php echo price($line->subprice); ?></td>

View File

@ -275,9 +275,8 @@ class CommandeFournisseur extends CommonOrder
$this->lines=array();
$sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description,";
$sql.= " l.qty,";
$sql.= " l.tva_tx, l.remise_percent, l.subprice,";
$sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
$sql.= " l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
$sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,";
$sql.= " l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,";
@ -313,6 +312,8 @@ class CommandeFournisseur extends CommonOrder
$line->subprice = $objp->subprice;
$line->pu_ht = $objp->subprice;
$line->remise_percent = $objp->remise_percent;
$line->vat_src_code = $objp->vat_src_code;
$line->total_ht = $objp->total_ht;
$line->total_tva = $objp->total_tva;
$line->total_localtax1 = $objp->total_localtax1;
@ -1416,8 +1417,15 @@ class CommandeFournisseur extends CommonOrder
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// 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);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@ -1457,6 +1465,8 @@ class CommandeFournisseur extends CommonOrder
$this->line->subprice=$pu_ht;
$this->line->rang=$this->rang;
$this->line->info_bits=$info_bits;
$this->line->vat_src_code=$vat_src_code;
$this->line->total_ht=$total_ht;
$this->line->total_tva=$total_tva;
$this->line->total_localtax1=$total_localtax1;
@ -2260,8 +2270,15 @@ class CommandeFournisseur extends CommonOrder
// 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);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
// Clean vat code
$vat_src_code='';
if (preg_match('/\((.*)\)/', $vatrate, $reg))
{
$vat_src_code = $reg[1];
$vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate.
}
$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);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@ -2288,28 +2305,29 @@ class CommandeFournisseur extends CommonOrder
//$this->line->label=$label;
$this->line->desc=$desc;
$this->line->qty=$qty;
$this->line->tva_tx=$txtva;
$this->line->localtax1_tx=$txlocaltax1;
$this->line->localtax2_tx=$txlocaltax2;
$this->line->vat_src_code = $vat_src_code;
$this->line->tva_tx = $txtva;
$this->line->localtax1_tx = $txlocaltax1;
$this->line->localtax2_tx = $txlocaltax2;
$this->line->localtax1_type = $localtaxes_type[0];
$this->line->localtax2_type = $localtaxes_type[2];
$this->line->remise_percent=$remise_percent;
$this->line->subprice=$pu;
$this->line->rang=$this->rang;
$this->line->info_bits=$info_bits;
$this->line->total_ht=$total_ht;
$this->line->total_tva=$total_tva;
$this->line->total_localtax1=$total_localtax1;
$this->line->total_localtax2=$total_localtax2;
$this->line->total_ttc=$total_ttc;
$this->line->product_type=$type;
$this->line->special_code=$this->special_code;
$this->line->origin=$this->origin;
$this->line->fk_unit=$fk_unit;
$this->line->date_start=$date_start;
$this->line->date_end=$date_end;
$this->line->remise_percent = $remise_percent;
$this->line->subprice = $pu;
$this->line->rang = $this->rang;
$this->line->info_bits = $info_bits;
$this->line->total_ht = $total_ht;
$this->line->total_tva = $total_tva;
$this->line->total_localtax1= $total_localtax1;
$this->line->total_localtax2= $total_localtax2;
$this->line->total_ttc = $total_ttc;
$this->line->product_type = $type;
$this->line->special_code = $this->special_code;
$this->line->origin = $this->origin;
$this->line->fk_unit = $fk_unit;
$this->line->date_start = $date_start;
$this->line->date_end = $date_end;
// Multicurrency
$this->line->fk_multicurrency = $this->fk_multicurrency;
@ -2995,8 +3013,8 @@ class CommandeFournisseurLigne extends CommonOrderLine
if (empty($this->tva_tx)) $this->tva_tx=0;
if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
if (empty($this->localtax1_type)) $this->localtax1_type=0;
if (empty($this->localtax2_type)) $this->localtax2_type=0;
if (empty($this->localtax1_type)) $this->localtax1_type='0';
if (empty($this->localtax2_type)) $this->localtax2_type='0';
if (empty($this->total_localtax1)) $this->total_localtax1=0;
if (empty($this->total_localtax2)) $this->total_localtax2=0;
if (empty($this->rang)) $this->rang=0;
@ -3025,7 +3043,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
$sql.= " (fk_commande, label, description, date_start, date_end,";
$sql.= " fk_product, product_type,";
$sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
$sql.= " qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
$sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
$sql.= " fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc";
$sql.= ")";
@ -3035,17 +3053,20 @@ class CommandeFournisseurLigne extends CommonOrderLine
if ($this->fk_product) { $sql.= $this->fk_product.","; }
else { $sql.= "null,"; }
$sql.= "'".$this->product_type."',";
$sql.= "'".$this->qty."', ".$this->tva_tx.", ".$this->localtax1_tx.", ".$this->localtax2_tx;
$sql.= "'".$this->qty."', ";
$sql.= ", '".$this->localtax1_type."',";
$sql.= " '".$this->localtax2_type."'";
$sql.= ", ".$this->remise_percent.",'".price2num($this->subprice,'MU')."','".$this->ref_supplier."',";
$sql.= "'".price2num($this->total_ht)."',";
$sql.= "'".price2num($this->total_tva)."',";
$sql.= "'".price2num($this->total_localtax1)."',";
$sql.= "'".price2num($this->total_localtax2)."',";
$sql.= "'".price2num($this->total_ttc)."',";
$sql.= " ".(empty($this->vat_src_code)?"''":"'".$this->vat_src_code."'").",";
$sql.= " ".$this->tva_tx.", ";
$sql.= " ".$this->localtax1_tx.",";
$sql.= " ".$this->localtax2_tx.",";
$sql.= " '".$this->localtax1_type."',";
$sql.= " '".$this->localtax2_type."',";
$sql.= " ".$this->remise_percent.", ".price2num($this->subprice,'MU').", '".$this->db->escape($this->ref_supplier)."',";
$sql.= " ".price2num($this->total_ht).",";
$sql.= " ".price2num($this->total_tva).",";
$sql.= " ".price2num($this->total_localtax1).",";
$sql.= " ".price2num($this->total_localtax2).",";
$sql.= " ".price2num($this->total_ttc).",";
$sql.= ($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'":"null");
$sql.= ", ".($this->fk_multicurrency ? $this->fk_multicurrency : "null");
$sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
@ -3114,32 +3135,34 @@ class CommandeFournisseurLigne extends CommonOrderLine
// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
$sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= ",subprice='".price2num($this->subprice)."'";
$sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= ", subprice='".price2num($this->subprice)."'";
//$sql.= ",remise='".price2num($remise)."'";
$sql.= ",remise_percent='".price2num($this->remise_percent)."'";
$sql.= ",tva_tx='".price2num($this->tva_tx)."'";
$sql.= ",localtax1_tx='".price2num($this->total_localtax1)."'";
$sql.= ",localtax2_tx='".price2num($this->total_localtax2)."'";
$sql.= ",localtax1_type='".$this->localtax1_type."'";
$sql.= ",localtax2_type='".$this->localtax2_type."'";
$sql.= ",qty='".price2num($this->qty)."'";
$sql.= ",date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= ",date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ",info_bits='".$this->info_bits."'";
$sql.= ",total_ht='".price2num($this->total_ht)."'";
$sql.= ",total_tva='".price2num($this->total_tva)."'";
$sql.= ",total_localtax1='".price2num($this->total_localtax1)."'";
$sql.= ",total_localtax2='".price2num($this->total_localtax2)."'";
$sql.= ",total_ttc='".price2num($this->total_ttc)."'";
$sql.= ",product_type=".$this->product_type;
$sql.= ($this->fk_unit ? ",fk_unit='".$this->db->escape($this->fk_unit)."'":", fk_unit=null");
$sql.= ", remise_percent='".price2num($this->remise_percent)."'";
$sql.= ", vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'";
$sql.= ", tva_tx='".price2num($this->tva_tx)."'";
$sql.= ", localtax1_tx='".price2num($this->total_localtax1)."'";
$sql.= ", localtax2_tx='".price2num($this->total_localtax2)."'";
$sql.= ", localtax1_type='".$this->localtax1_type."'";
$sql.= ", localtax2_type='".$this->localtax2_type."'";
$sql.= ", qty='".price2num($this->qty)."'";
$sql.= ", date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= ", date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ", info_bits='".$this->info_bits."'";
$sql.= ", total_ht='".price2num($this->total_ht)."'";
$sql.= ", total_tva='".price2num($this->total_tva)."'";
$sql.= ", total_localtax1='".price2num($this->total_localtax1)."'";
$sql.= ", total_localtax2='".price2num($this->total_localtax2)."'";
$sql.= ", total_ttc='".price2num($this->total_ttc)."'";
$sql.= ", product_type=".$this->product_type;
$sql.= ($this->fk_unit ? ", fk_unit='".$this->db->escape($this->fk_unit)."'":", fk_unit=null");
// Multicurrency
$sql.= " , multicurrency_subprice=".price2num($this->subprice * $this->multicurrency_tx)."";
$sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= ", multicurrency_subprice=".price2num($this->subprice * $this->multicurrency_tx)."";
$sql.= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
$sql.= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
$sql.= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
$sql.= " WHERE rowid = ".$this->id;

View File

@ -2552,8 +2552,8 @@ class SupplierInvoiceLine extends CommonObjectLine
if (empty($this->tva_tx)) $this->tva_tx=0;
if (empty($this->localtax1_tx)) $this->localtax1_tx=0;
if (empty($this->localtax2_tx)) $this->localtax2_tx=0;
if (empty($this->localtax1_type)) $this->localtax1_type=0;
if (empty($this->localtax2_type)) $this->localtax2_type=0;
if (empty($this->localtax1_type)) $this->localtax1_type='0';
if (empty($this->localtax2_type)) $this->localtax2_type='0';
if (empty($this->total_localtax1)) $this->total_localtax1=0;
if (empty($this->total_localtax2)) $this->total_localtax2=0;
if (empty($this->rang)) $this->rang=0;
@ -2604,6 +2604,7 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
$sql.= " '".$this->db->escape($this->desc)."',";
$sql.= " ".price2num($this->qty).",";
$sql.= " ".(empty($this->vat_src_code)?"''":"'".$this->vat_src_code."'").",";
$sql.= " ".price2num($this->tva_tx).",";
$sql.= " ".price2num($this->localtax1_tx).",";