From 8e333c3feba03210dc0d3ec8ac94282311709a20 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 4 Dec 2018 14:54:58 +0100 Subject: [PATCH] Standardize code --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 10 +++---- htdocs/contrat/class/contrat.class.php | 20 +++++++------- .../class/expensereport.class.php | 8 ++++-- .../class/fournisseur.commande.class.php | 14 +++++----- .../fourn/class/fournisseur.facture.class.php | 27 ++++++++++--------- 7 files changed, 45 insertions(+), 38 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index bf5c5af836a..a00dec50288 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -422,7 +422,7 @@ class Propal extends CommonObject $pu_ht_devise=price2num($pu_ht_devise); $pu_ttc=price2num($pu_ttc); if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + $txtva = price2num($txtva); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' } $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 447b61ce433..f7f534dbc71 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1289,7 +1289,7 @@ class Commande extends CommonOrder $pu_ttc=price2num($pu_ttc); $pa_ht=price2num($pa_ht); if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + $txtva = price2num($txtva); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index dc26c9ce6ab..a6e979cdd10 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2648,11 +2648,6 @@ class Facture extends CommonInvoice } } - // Calcul du total TTC et de la TVA pour la ligne a partir de - // qty, pu, remise_percent et txtva - // 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. - $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); // Clean vat code @@ -2663,6 +2658,11 @@ class Facture extends CommonInvoice $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // 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. + $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]; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index b5ce710061e..dc94d57809f 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1357,16 +1357,6 @@ class Contrat extends CommonObject { $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 $pu_ht=price2num($pu_ht); $pu_ttc=price2num($pu_ttc); @@ -1398,6 +1388,16 @@ class Contrat extends CommonObject // Check parameters if (empty($remise_percent)) $remise_percent=0; + $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. + } + // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index f4737b3dcc9..3f5029c4ef6 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1670,7 +1670,7 @@ class ExpenseReport extends CommonObject */ function addline($qty=0, $up=0, $fk_c_type_fees=0, $vatrate=0, $date='', $comments='', $fk_project=0, $fk_c_exp_tax_cat=0, $type=0) { - global $conf,$langs; + global $conf,$langs,$mysoc; 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); @@ -1693,6 +1693,9 @@ class ExpenseReport extends CommonObject $this->line = new ExpenseReportLine($this->db); + $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$mysoc,$this->thirdparty); + + $vat_src_code = ''; if (preg_match('/\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; @@ -1701,7 +1704,8 @@ class ExpenseReport extends CommonObject $vatrate = preg_replace('/\*/','',$vatrate); $seller = ''; // seller is unknown - $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); + + $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); $this->line->value_unit = $up; $this->line->vatrate = price2num($vatrate); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 6e393e77253..d6b1b719263 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1558,10 +1558,9 @@ class CommandeFournisseur extends CommonOrder $product_type = $type; } - // Calcul du total TTC et de la TVA pour la ligne a partir de - // qty, pu, remise_percent et txtva - // 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. + if ($conf->multicurrency->enabled && $pu_ht_devise > 0) { + $pu = 0; + } $localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc,$this->thirdparty); @@ -1573,9 +1572,10 @@ class CommandeFournisseur extends CommonOrder $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - if ($conf->multicurrency->enabled && $pu_ht_devise > 0) { - $pu = 0; - } + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // 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. $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); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 9e7373f9932..72bd20fc25c 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1522,6 +1522,15 @@ class FactureFournisseur extends CommonInvoice if (empty($txlocaltax1)) $txlocaltax1=0; if (empty($txlocaltax2)) $txlocaltax2=0; + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + $pu=price2num($pu); + $txlocaltax1=price2num($txlocaltax1); + $txlocaltax2=price2num($txlocaltax2); + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' + } + $this->db->begin(); if ($fk_product > 0) @@ -1587,8 +1596,8 @@ class FactureFournisseur extends CommonInvoice $product_type = $type; } - if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1' + if ($conf->multicurrency->enabled && $pu_ht_devise > 0) { + $pu = 0; } $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty); @@ -1601,16 +1610,10 @@ class FactureFournisseur extends CommonInvoice $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); - - if ($conf->multicurrency->enabled && $pu_ht_devise > 0) { - $pu = 0; - } + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // 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. $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];