Better support of vat with code in expense report
This commit is contained in:
parent
b7af0cca63
commit
ba3b6b6aa5
@ -1360,10 +1360,10 @@ class Commande extends CommonOrder
|
||||
|
||||
$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->localtax1_tx=$localtaxes_type[1];
|
||||
$this->line->localtax2_tx=$localtaxes_type[3];
|
||||
$this->line->localtax1_type=$localtaxes_type[0];
|
||||
$this->line->localtax2_type=$localtaxes_type[2];
|
||||
$this->line->fk_product=$fk_product;
|
||||
$this->line->product_type=$product_type;
|
||||
$this->line->fk_remise_except=$fk_remise_except;
|
||||
|
||||
@ -3892,7 +3892,7 @@ function getTaxesFromId($vatrowid)
|
||||
* @param Societe $buyer Company object
|
||||
* @param Societe $seller Company object
|
||||
* @param int $firstparamisid 1 if first param is id into table (use this if you can)
|
||||
* @return array array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type1, rate localtax2, accountancycodecust, accountancycodesupp)
|
||||
* @return array array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type2, rate localtax2, accountancycodecust, accountancycodesupp)
|
||||
*/
|
||||
function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
|
||||
{
|
||||
|
||||
@ -935,7 +935,8 @@ if (empty($reshook))
|
||||
|
||||
$object_ligne = new ExpenseReportLine($db);
|
||||
|
||||
$vatrate = GETPOST('vatrate');
|
||||
$vatrate = GETPOST('vatrate','alpha'); // May be 8.5* (8.5NPROM)
|
||||
|
||||
$object_ligne->comments = GETPOST('comments');
|
||||
$qty = GETPOST('qty','int');
|
||||
if (empty($qty)) $qty=1;
|
||||
@ -998,13 +999,34 @@ if (empty($reshook))
|
||||
$object_ligne->fk_expensereport = $_POST['fk_expensereport'];
|
||||
|
||||
$type = 0; // TODO What if service ?
|
||||
$seller = ''; // seller is unknown
|
||||
$tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller);
|
||||
|
||||
// We don't know seller and buyer for expense reports
|
||||
$seller = $mysoc;
|
||||
$buyer = new Societe($db);
|
||||
|
||||
$localtaxes_type=getLocalTaxesFromRate($vatrate,0,$buyer,$seller);
|
||||
|
||||
// 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.
|
||||
}
|
||||
$vatrate = preg_replace('/\*/','',$vatrate);
|
||||
|
||||
$tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type);
|
||||
|
||||
$object_ligne->vat_src_code = $vat_src_code;
|
||||
$object_ligne->vatrate = price2num($vatrate);
|
||||
$object_ligne->total_ttc = $tmp[2];
|
||||
$object_ligne->total_ht = $tmp[0];
|
||||
$object_ligne->total_tva = $tmp[1];
|
||||
$object_ligne->localtax1_tx = $localtaxes_type[1];
|
||||
$object_ligne->localtax2_tx = $localtaxes_type[3];
|
||||
$object_ligne->localtax1_type = $localtaxes_type[0];
|
||||
$object_ligne->localtax2_type = $localtaxes_type[2];
|
||||
|
||||
$result = $object_ligne->insert();
|
||||
if ($result > 0)
|
||||
@ -1942,7 +1964,9 @@ else
|
||||
|
||||
// VAT
|
||||
print '<td style="text-align:right;">';
|
||||
print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $mysoc, '');
|
||||
$seller=$mysoc;
|
||||
$buyer=new Societe($db);
|
||||
print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $seller, $buyer, 0, 0, '', false, 1);
|
||||
print '</td>';
|
||||
|
||||
// Unit price
|
||||
@ -2028,7 +2052,7 @@ else
|
||||
print '<td align="right">';
|
||||
$defaultvat=-1;
|
||||
if (! empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none';
|
||||
print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false);
|
||||
print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false, 1);
|
||||
print '</td>';
|
||||
|
||||
// Unit price
|
||||
|
||||
@ -1359,7 +1359,7 @@ class ExpenseReport extends CommonObject
|
||||
* @param int $rowid Line to edit
|
||||
* @param int $type_fees_id Type payment
|
||||
* @param int $projet_id Project id
|
||||
* @param double $vatrate Vat rate
|
||||
* @param double $vatrate Vat rate. Can be '8.5* (8.5NPROM...)'
|
||||
* @param string $comments Description
|
||||
* @param real $qty Qty
|
||||
* @param double $value_unit Value init
|
||||
@ -1369,14 +1369,34 @@ class ExpenseReport extends CommonObject
|
||||
*/
|
||||
function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id)
|
||||
{
|
||||
global $user;
|
||||
global $user, $mysoc;
|
||||
|
||||
if ($this->fk_statut==0 || $this->fk_statut==99)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
$type = 0; // TODO What if type is service ?
|
||||
|
||||
// We don't know seller and buyer for expense reports
|
||||
$seller = $mysoc;
|
||||
$buyer = new Societe($this->db);
|
||||
|
||||
$localtaxes_type=getLocalTaxesFromRate($vatrate,0,$buyer,$seller);
|
||||
|
||||
// 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.
|
||||
}
|
||||
$vatrate = preg_replace('/\*/','',$vatrate);
|
||||
|
||||
$tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type);
|
||||
|
||||
// calcul de tous les totaux de la ligne
|
||||
$total_ttc = price2num($qty*$value_unit, 'MT');
|
||||
//$total_ttc = price2num($qty*$value_unit, 'MT');
|
||||
|
||||
$tx_tva = $vatrate / 100;
|
||||
$tx_tva = $tx_tva + 1;
|
||||
@ -1386,6 +1406,9 @@ class ExpenseReport extends CommonObject
|
||||
// fin calculs
|
||||
|
||||
$ligne = new ExpenseReportLine($this->db);
|
||||
|
||||
$ligne->rowid = $rowid;
|
||||
|
||||
$ligne->comments = $comments;
|
||||
$ligne->qty = $qty;
|
||||
$ligne->value_unit = $value_unit;
|
||||
@ -1395,11 +1418,21 @@ class ExpenseReport extends CommonObject
|
||||
$ligne->fk_c_type_fees = $type_fees_id;
|
||||
$ligne->fk_projet = $projet_id;
|
||||
|
||||
$ligne->total_ht = $total_ht;
|
||||
$ligne->total_tva = $total_tva;
|
||||
$ligne->total_ttc = $total_ttc;
|
||||
$ligne->vatrate = price2num($vatrate);
|
||||
$ligne->rowid = $rowid;
|
||||
//$ligne->total_ht = $total_ht;
|
||||
//$ligne->total_tva = $total_tva;
|
||||
//$ligne->total_ttc = $total_ttc;
|
||||
//$ligne->vatrate = price2num($vatrate);
|
||||
|
||||
$ligne->vat_src_code = $vat_src_code;
|
||||
$ligne->vatrate = price2num($vatrate);
|
||||
$ligne->total_ttc = $tmp[2];
|
||||
$ligne->total_ht = $tmp[0];
|
||||
$ligne->total_tva = $tmp[1];
|
||||
$ligne->localtax1_tx = $localtaxes_type[1];
|
||||
$ligne->localtax2_tx = $localtaxes_type[3];
|
||||
$ligne->localtax1_type = $localtaxes_type[0];
|
||||
$ligne->localtax2_type = $localtaxes_type[2];
|
||||
|
||||
|
||||
// Select des infos sur le type fees
|
||||
$sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user