Skip to content

Commit

Permalink
Fix vat_src_code propagation.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed May 2, 2017
1 parent cc8e66d commit 3917bdf
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
5 changes: 4 additions & 1 deletion htdocs/comm/propal/card.php
Expand Up @@ -492,7 +492,10 @@
$array_options = $lines[$i]->array_options;
}

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
$tva_tx = $lines[$i]->tva_tx;
if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);

if ($result > 0) {
$lineid = $result;
Expand Down
14 changes: 10 additions & 4 deletions htdocs/comm/propal/class/propal.class.php
Expand Up @@ -253,6 +253,8 @@ function add_product($idproduct, $qty, $remise_percent=0)
$tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id);
$tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id);
if (empty($tva_tx)) $tva_npr=0;
$vat_src_code = ''; // May be defined into tva_tx

$localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr);
$localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr);

Expand All @@ -273,6 +275,7 @@ function add_product($idproduct, $qty, $remise_percent=0)
$line->qty=$qty;
$line->subprice=$price;
$line->remise_percent=$remise_percent;
$line->vat_src_code=$vat_src_code;
$line->tva_tx=$tva_tx;
$line->fk_unit=$prod->fk_unit;
if ($tva_npr) $line->info_bits = 1;
Expand Down Expand Up @@ -315,6 +318,7 @@ function insert_discount($idremise)
$line->fk_propal=$this->id;
$line->fk_remise_except=$remise->id;
$line->desc=$remise->description; // Description ligne
$line->vat_src_code=$remise->vat_src_code;
$line->tva_tx=$remise->tva_tx;
$line->subprice=-$remise->amount_ht;
$line->fk_product=0; // Id produit predefined
Expand Down Expand Up @@ -698,7 +702,8 @@ function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0
$this->line->label = $label;
$this->line->desc = $desc;
$this->line->qty = $qty;
$this->line->product_type = $type;
$this->line->product_type = $type;
$this->line->vat_src_code = $vat_src_code;
$this->line->tva_tx = $txtva;
$this->line->localtax1_tx = $txlocaltax1;
$this->line->localtax2_tx = $txlocaltax2;
Expand All @@ -708,7 +713,6 @@ function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0
$this->line->subprice = $pu_ht;
$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;
Expand Down Expand Up @@ -1368,7 +1372,7 @@ function fetch($rowid,$ref='')
/*
* Lignes propales liees a un produit ou non
*/
$sql = "SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
$sql = "SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
$sql.= " d.fk_unit,";
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
Expand Down Expand Up @@ -1404,6 +1408,7 @@ function fetch($rowid,$ref='')
$line->label = $objp->custom_label;
$line->desc = $objp->description; // Description ligne
$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;
Expand Down Expand Up @@ -3591,7 +3596,7 @@ function __construct($db)
*/
function fetch($rowid)
{
$sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
$sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.vat_src_code, pd.tva_tx,';
$sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
$sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
$sql.= ' pd.fk_unit,';
Expand All @@ -3617,6 +3622,7 @@ function fetch($rowid)
$this->qty = $objp->qty;
$this->price = $objp->price; // deprecated
$this->subprice = $objp->subprice;
$this->vat_src_code = $objp->vat_src_code;
$this->tva_tx = $objp->tva_tx;
$this->remise = $objp->remise; // deprecated
$this->remise_percent = $objp->remise_percent;
Expand Down
5 changes: 4 additions & 1 deletion htdocs/commande/card.php
Expand Up @@ -373,7 +373,10 @@
$array_options = $lines[$i]->array_options;
}

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->fk_unit, $object->origin, $lines[$i]->rowid);
$tva_tx = $lines[$i]->tva_tx;
if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->fk_unit, $object->origin, $lines[$i]->rowid);

if ($result < 0) {
$error++;
Expand Down
8 changes: 7 additions & 1 deletion htdocs/commande/class/commande.class.php
Expand Up @@ -1103,6 +1103,7 @@ function createFromProposal($object)
$line->desc = $object->lines[$i]->desc;
$line->price = $object->lines[$i]->price;
$line->subprice = $object->lines[$i]->subprice;
$line->vat_src_code = $object->lines[$i]->vat_src_code;
$line->tva_tx = $object->lines[$i]->tva_tx;
$line->localtax1_tx = $object->lines[$i]->localtax1_tx;
$line->localtax2_tx = $object->lines[$i]->localtax2_tx;
Expand Down Expand Up @@ -1466,7 +1467,8 @@ function add_product($idproduct, $qty, $remise_percent=0.0, $date_start='', $dat
$tva_tx = get_default_tva($mysoc,$this->thirdparty,$prod->id);
$tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id);
if (empty($tva_tx)) $tva_npr=0;

$vat_src_code = ''; // May be defined into tva_tx

$localtax1_tx=get_localtax($tva_tx,1,$this->thirdparty,$mysoc,$tva_npr);
$localtax2_tx=get_localtax($tva_tx,2,$this->thirdparty,$mysoc,$tva_npr);

Expand All @@ -1485,6 +1487,7 @@ function add_product($idproduct, $qty, $remise_percent=0.0, $date_start='', $dat
$line->qty=$qty;
$line->subprice=$price;
$line->remise_percent=$remise_percent;
$line->vat_src_code=$vat_src_code;
$line->tva_tx=$tva_tx;
$line->localtax1_tx=$localtax1_tx;
$line->localtax2_tx=$localtax2_tx;
Expand Down Expand Up @@ -1703,6 +1706,7 @@ function insert_discount($idremise)
$line->fk_commande=$this->id;
$line->fk_remise_except=$remise->id;
$line->desc=$remise->description; // Description ligne
$line->vat_src_code=$remise->vat_src_code;
$line->tva_tx=$remise->tva_tx;
$line->subprice=-$remise->amount_ht;
$line->price=-$remise->amount_ht;
Expand Down Expand Up @@ -3809,6 +3813,7 @@ function fetch($rowid)
$this->qty = $objp->qty;
$this->price = $objp->price;
$this->subprice = $objp->subprice;
$this->vat_src_code = $objp->vat_src_code;
$this->tva_tx = $objp->tva_tx;
$this->localtax1_tx = $objp->localtax1_tx;
$this->localtax2_tx = $objp->localtax2_tx;
Expand Down Expand Up @@ -4120,6 +4125,7 @@ function update($user=null, $notrigger=0)
$sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
$sql.= " description='".$this->db->escape($this->desc)."'";
$sql.= " , label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= " , vat_src_code=".(! empty($this->vat_src_code)?"'".$this->db->escape($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);
Expand Down
17 changes: 12 additions & 5 deletions htdocs/compta/facture.php
Expand Up @@ -1050,11 +1050,14 @@
}
}

$tva_tx = $lines[$i]->tva_tx;
if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';

$result = $object->addline(
$langs->trans('Deposit'),
$amountdeposit, // subprice
1, // quantity
$lines[$i]->tva_tx, // vat rate
$tva_tx, // vat rate
0, // localtax1_tx
0, // localtax2_tx
(empty($conf->global->INVOICE_PRODUCTID_DEPOSIT)?0:$conf->global->INVOICE_PRODUCTID_DEPOSIT), // fk_product
Expand Down Expand Up @@ -1150,11 +1153,15 @@
$array_options = $lines[$i]->array_options;
}

// View third's localtaxes for now
$localtax1_tx = get_localtax($lines[$i]->tva_tx, 1, $object->thirdparty);
$localtax2_tx = get_localtax($lines[$i]->tva_tx, 2, $object->thirdparty);
$tva_tx = $lines[$i]->tva_tx;
if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';

// View third's localtaxes for NOW and do not use value from origin.
// TODO Is this really what we want ? Yes if source if template invoice but what if proposal or order ?
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);

$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->situation_percent, $lines[$i]->fk_prev_id, $lines[$i]->fk_unit);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->situation_percent, $lines[$i]->fk_prev_id, $lines[$i]->fk_unit);

if ($result > 0) {
$lineid = $result;
Expand Down
7 changes: 5 additions & 2 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -952,6 +952,7 @@ function createFromOrder($object)
$line->total_ht = $object->lines[$i]->total_ht;
$line->total_tva = $object->lines[$i]->total_tva;
$line->total_ttc = $object->lines[$i]->total_ttc;
$line->vat_src_code = $object->lines[$i]->vat_src_code;
$line->tva_tx = $object->lines[$i]->tva_tx;
$line->localtax1_tx = $object->lines[$i]->localtax1_tx;
$line->localtax2_tx = $object->lines[$i]->localtax2_tx;
Expand Down Expand Up @@ -1551,6 +1552,7 @@ function insert_discount($idremise)
$facligne->fk_facture=$this->id;
$facligne->fk_remise_except=$remise->id;
$facligne->desc=$remise->description; // Description ligne
$facligne->vat_src_code=$remise->vat_src_code;
$facligne->tva_tx=$remise->tva_tx;
$facligne->subprice=-$remise->amount_ht;
$facligne->fk_product=0; // Id produit predefini
Expand Down Expand Up @@ -2399,7 +2401,7 @@ function set_draft($user,$idwarehouse=-1)
* @param string $desc Description of line
* @param double $pu_ht Unit price without tax (> 0 even for credit note)
* @param double $qty Quantity
* @param double $txtva Force Vat rate, -1 for auto
* @param double $txtva Force Vat rate, -1 for auto (Can contain the vat_src_code too with syntax '9.9 (CODE)')
* @param double $txlocaltax1 Local tax 1 rate (deprecated)
* @param double $txlocaltax2 Local tax 2 rate (deprecated)
* @param int $fk_product Id of predefined product/service
Expand Down Expand Up @@ -4276,7 +4278,7 @@ class FactureLigne extends CommonInvoiceLine
*/
function fetch($rowid)
{
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.tva_tx,';
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.vat_src_code, fd.tva_tx,';
$sql.= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,';
$sql.= ' fd.date_start as date_start, fd.date_end as date_end, fd.fk_product_fournisseur_price as fk_fournprice, fd.buy_price_ht as pa_ht,';
$sql.= ' fd.info_bits, fd.special_code, fd.total_ht, fd.total_tva, fd.total_ttc, fd.total_localtax1, fd.total_localtax2, fd.rang,';
Expand Down Expand Up @@ -4304,6 +4306,7 @@ function fetch($rowid)
$this->desc = $objp->description;
$this->qty = $objp->qty;
$this->subprice = $objp->subprice;
$this->vat_src_code = $objp->vat_src_code;
$this->tva_tx = $objp->tva_tx;
$this->localtax1_tx = $objp->localtax1_tx;
$this->localtax2_tx = $objp->localtax2_tx;
Expand Down
6 changes: 6 additions & 0 deletions htdocs/core/class/commoninvoice.class.php
Expand Up @@ -471,6 +471,12 @@ abstract class CommonInvoiceLine extends CommonObjectLine
*/
public $fk_product;

/**
* VAT code
* @var string
*/
public $vat_src_code;

/**
* VAT %
* @var float
Expand Down
5 changes: 4 additions & 1 deletion htdocs/core/class/commonobject.class.php
Expand Up @@ -3567,7 +3567,7 @@ function printOriginLinesList()
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Ref').'</td>';
print '<td>'.$langs->trans('Description').'</td>';
print '<td align="right">'.$langs->trans('VAT').'</td>';
print '<td align="right">'.$langs->trans('VATRate').'</td>';
print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
print '<td align="right">'.$langs->trans('Qty').'</td>';
Expand Down Expand Up @@ -3698,7 +3698,10 @@ function printOriginLine($line,$var)
$this->tpl['description'] = '&nbsp;';
}

// VAT Rate
$this->tpl['vat_rate'] = vatrate($line->tva_tx, true);
if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';

$this->tpl['price'] = price($line->subprice);
$this->tpl['multicurrency_price'] = price($line->multicurrency_subprice);
$this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
Expand Down
4 changes: 2 additions & 2 deletions htdocs/societe/soc.php
Expand Up @@ -1743,7 +1743,7 @@
//TODO: Place into a function to control showing by country or study better option
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
{
print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td colspan="3">';
print '<tr><td>'.fieldLabel($langs->transcountry("LocalTax1IsUsed",$mysoc->country_code),'localtax1assuj_value').'</td><td>';
print $form->selectyesno('localtax1assuj_value',$object->localtax1_assuj,1);
if(! isOnlyOneLocalTax(1))
{
Expand All @@ -1752,7 +1752,7 @@
print '</span>';
}

print '</td><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td colspan="3">';
print '</td><td>'.fieldLabel($langs->transcountry("LocalTax2IsUsed",$mysoc->country_code),'localtax2assuj_value').'</td><td>';
print $form->selectyesno('localtax2assuj_value',$object->localtax2_assuj,1);
if (! isOnlyOneLocalTax(2))
{
Expand Down

0 comments on commit 3917bdf

Please sign in to comment.