';
// Delete link
@@ -1479,7 +1479,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
} // For state page, we do not show the country input (we link to region, not country)
print '
';
}
elseif ($fieldlist[$field] == 'country_id')
diff --git a/htdocs/comm/askpricesupplier/class/askpricesupplier.class.php b/htdocs/comm/askpricesupplier/class/askpricesupplier.class.php
index 2f563a17b1b..1cb2e72f292 100644
--- a/htdocs/comm/askpricesupplier/class/askpricesupplier.class.php
+++ b/htdocs/comm/askpricesupplier/class/askpricesupplier.class.php
@@ -369,7 +369,8 @@ class AskPriceSupplier 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, '', $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@@ -528,7 +529,8 @@ class AskPriceSupplier 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,'', $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php
index fcac4ba9de1..fd3964406c5 100644
--- a/htdocs/comm/propal/class/propal.class.php
+++ b/htdocs/comm/propal/class/propal.class.php
@@ -439,7 +439,8 @@ 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
@@ -600,7 +601,8 @@ 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 922e695339a..fa195680a36 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -1220,7 +1220,8 @@ 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.
+
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type,'', $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@@ -2442,7 +2443,8 @@ 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index af3d600756e..0a453db92db 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1401,12 +1401,12 @@ if (empty($reshook))
// Margin
$fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
- $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we muste keep this value
+ $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value
// Local Taxes
- $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
- $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);
-
+ $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc);
+ $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc);
+
$info_bits = 0;
if ($tva_npr)
$info_bits |= 0x01;
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 5f92fc95785..f6e6d108be8 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -2045,8 +2045,8 @@ class Facture extends CommonInvoice
* @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 $txlocaltax1 Local tax 1 rate
- * @param double $txlocaltax2 Local tax 2 rate
+ * @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
* @param double $remise_percent Percent of discount on line
* @param int $date_start Date start of service
@@ -2141,6 +2141,7 @@ 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.
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent);
@@ -2299,7 +2300,8 @@ 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent);
$total_ht = $tabprice[0];
diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php
index e38bb254f79..27fcee1dbeb 100644
--- a/htdocs/contrat/class/contrat.class.php
+++ b/htdocs/contrat/class/contrat.class.php
@@ -1260,7 +1260,8 @@ class Contrat 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->societe, $mysoc);
-
+ $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);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@@ -1441,7 +1442,8 @@ class Contrat extends CommonObject
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($tvatx, 0, $this->societe, $mysoc);
-
+ $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 555b44423e1..49d5265e0f8 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3857,12 +3857,12 @@ class Form
dol_syslog(__METHOD__, LOG_DEBUG);
- $sql = "SELECT DISTINCT t.taux, t.recuperableonly";
+ $sql = "SELECT DISTINCT t.code, t.taux, t.recuperableonly";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
$sql.= " WHERE t.fk_pays = c.rowid";
$sql.= " AND t.active > 0";
$sql.= " AND c.code IN (".$country_code.")";
- $sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC";
+ $sql.= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC";
$resql=$this->db->query($sql);
if ($resql)
@@ -3873,8 +3873,9 @@ class Form
for ($i = 0; $i < $num; $i++)
{
$obj = $this->db->fetch_object($resql);
+ $this->cache_vatrates[$i]['code'] = $obj->code;
$this->cache_vatrates[$i]['txtva'] = $obj->taux;
- $this->cache_vatrates[$i]['libtva'] = $obj->taux.'%';
+ $this->cache_vatrates[$i]['libtva'] = $obj->taux.'%'.($obj->code?' ('.$obj->code.')':''); // Label must contains only 0-9 , . % or *
$this->cache_vatrates[$i]['nprtva'] = $obj->recuperableonly;
}
@@ -3897,7 +3898,7 @@ 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 string $htmlname Name of HTML select field
* @param float $selectedrate Force preselected vat rate. Use '' for no forcing.
* @param Societe $societe_vendeuse Thirdparty seller
* @param Societe $societe_acheteuse Thirdparty buyer
@@ -3910,10 +3911,11 @@ class Form
* 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 options only (for ajax treatment)
+ * @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)
+ function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='', $options_only=false, $addcode=0)
{
global $langs,$conf,$mysoc;
@@ -4016,13 +4018,16 @@ class Form
$return.= '';
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index daa96d76775..4a94863e8c4 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3088,12 +3088,18 @@ function print_fleche_navigation($page, $file, $options='', $nextpage=0, $betwee
*/
function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
{
- // Test for compatibility
- if (preg_match('/%/',$rate))
+ $morelabel='';
+
+ if (preg_match('/%/',$rate))
{
$rate=str_replace('%','',$rate);
$addpercent=true;
}
+ if (preg_match('/\((.*)\)/',$rate,$reg))
+ {
+ $morelabel=' ('.$reg[1].')';
+ $rate=preg_replace('/'.preg_quote($morelabel,'/').'/','',$rate);
+ }
if (preg_match('/\*/',$rate) || preg_match('/'.constant('MAIN_LABEL_MENTION_NPR').'/i',$rate))
{
$rate=str_replace('*','',$rate);
@@ -3102,6 +3108,7 @@ function vatrate($rate,$addpercent=false,$info_bits=0,$usestarfornpr=0)
$ret=price($rate,0,'',0,0).($addpercent?'%':'');
if ($info_bits & 1) $ret.=' '.($usestarfornpr?'*':constant('MAIN_LABEL_MENTION_NPR'));
+ $ret.=$morelabel;
return $ret;
}
@@ -3283,35 +3290,43 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
}
/**
- * Return localtax rate for a particular vat, when selling a product with vat $tva, from a $thirdparty_buyer to a $thirdparty_seller
+ * Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller
* Note: This function applies same rules than get_default_tva
*
- * @param float $tva Vat taxe
+ * @param float $vatrate Vat rate
* @param int $local Local tax to search and return (1 or 2 return only tax rate 1 or tax rate 2)
* @param Societe $thirdparty_buyer Object of buying third party
* @param Societe $thirdparty_seller Object of selling third party
- * @return mixed 0 if not found, localtax if found
+ * @return mixed 0 if not found, localtax rate if found
* @see get_default_tva
*/
-function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
+function get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="")
{
global $db, $conf, $mysoc;
if (empty($thirdparty_seller) || ! is_object($thirdparty_seller)) $thirdparty_seller=$mysoc;
- dol_syslog("get_localtax tva=".$tva." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer)?$thirdparty_buyer->id:'')."/country_code=".(is_object($thirdparty_buyer)?$thirdparty_buyer->country_code:'')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj." thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
+ dol_syslog("get_localtax tva=".$vatrate." local=".$local." thirdparty_buyer id=".(is_object($thirdparty_buyer)?$thirdparty_buyer->id:'')."/country_code=".(is_object($thirdparty_buyer)?$thirdparty_buyer->country_code:'')." thirdparty_seller id=".$thirdparty_seller->id."/country_code=".$thirdparty_seller->country_code." thirdparty_seller localtax1_assuj=".$thirdparty_seller->localtax1_assuj." thirdparty_seller localtax2_assuj=".$thirdparty_seller->localtax2_assuj);
- if($thirdparty_buyer->country_code!=$thirdparty_seller->country_code)
+ $vatratecleaned = $vatrate;
+ if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) // If vat is "xx (yy)"
+ {
+ $vatratecleaned = $reg[1];
+ $vatratecode = $reg[2];
+ }
+
+ /*if ($thirdparty_buyer->country_code != $thirdparty_seller->country_code)
{
return 0;
- }
+ }*/
+
// Some test to guess with no need to make database access
if ($mysoc->country_code == 'ES') // For spain localtaxes 1 and 2, tax is qualified if buyer use local taxe
{
if ($local == 1)
{
- if(! $mysoc->localtax1_assuj) return 0;
- if ($thirdparty_seller->id==$mysoc->id)
+ if (! $mysoc->localtax1_assuj) return 0;
+ if ($thirdparty_seller->id == $mysoc->id)
{
if (! $thirdparty_buyer->localtax1_assuj) return 0;
}
@@ -3323,8 +3338,8 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
if ($local == 2)
{
- if(! $mysoc->localtax2_assuj) return 0;
- if ($thirdparty_seller->id==$mysoc->id )
+ if (! $mysoc->localtax2_assuj) return 0;
+ if ($thirdparty_seller->id == $mysoc->id)
{
if (! $thirdparty_buyer->localtax2_assuj) return 0;
}
@@ -3350,63 +3365,72 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="")
}*/
// Search local taxes
- if ($local==1)
+ if ($mysoc->country_code == 'ES' || ! empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY))
{
- if($thirdparty_seller!=$mysoc )
- {
- if(!isOnlyOneLocalTax($local))
- {
- return $thirdparty_seller->localtax1_value;
- }
- }
- else
- {
- if(!isOnlyOneLocalTax($local))
- {
- return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
- }
- }
- }
- if ($local==2)
- {
- if($thirdparty_seller!=$mysoc)
- {
- if(!isOnlyOneLocalTax($local))
- {
- return $thirdparty_seller->localtax2_value;
- }
- }
- else
- {
- if(!isOnlyOneLocalTax($local))
- {
- return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
- }
- }
+ if ($local==1)
+ {
+ if ($thirdparty_seller != $mysoc)
+ {
+ if (!isOnlyOneLocalTax($local)) // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
+ {
+ return $thirdparty_seller->localtax1_value;
+ }
+ }
+ else // i am the seller
+ {
+ if (!isOnlyOneLocalTax($local)) // TODO If seller is me, why not always returning this, even if there is only one locatax vat.
+ {
+ return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
+ }
+ }
+ }
+ if ($local==2)
+ {
+ if ($thirdparty_seller != $mysoc)
+ {
+ if (!isOnlyOneLocalTax($local)) // TODO We should provide $vatrate to search on correct line and not always on line with highest vat rate
+ // TODO We should also return value defined on thirdparty only if defined
+ {
+ return $thirdparty_seller->localtax2_value;
+ }
+ }
+ else // i am the seller
+ {
+ if (!isOnlyOneLocalTax($local)) // This is for spain only, we don't return value found into datbase even if there is only one locatax vat.
+ {
+ return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
+ }
+ }
+ }
}
+ // By default, search value of local tax on line of common tax
$sql = "SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
- $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
- $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$thirdparty_seller->country_code."'";
- $sql .= " AND t.taux = ".((float) $tva)." AND t.active = 1";
- dol_syslog("get_localtax", LOG_DEBUG);
- $resql=$db->query($sql);
- if ($resql)
- {
- $obj = $db->fetch_object($resql);
- if ($local==1) return $obj->localtax1;
- elseif ($local==2) return $obj->localtax2;
- }
+ $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
+ $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$thirdparty_seller->country_code."'";
+ $sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
+ if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";
+ dol_syslog("get_localtax", LOG_DEBUG);
+ $resql=$db->query($sql);
+ if ($resql)
+ {
+ $obj = $db->fetch_object($resql);
+ if ($local==1) return $obj->localtax1;
+ elseif ($local==2) return $obj->localtax2;
+ }
+
return 0;
}
/**
- * Return true if LocalTax is unique
+ * Return true if LocalTax (1 or 2) is unique.
+ * Example: If localtax1 is 5 on line with highest common vat rate, return true
+ * Example: If localtax1 is 5:8:15 on line with highest common vat rate, return false
*
- * @param int $local Local taxt to test
- * @return boolean True if LocalTax have multiple values, False if not
+ * @param int $local Local tax to test (1 or 2)
+ * @return boolean True if LocalTax have multiple values, False if not
*/
function isOnlyOneLocalTax($local)
{
@@ -3414,7 +3438,7 @@ function isOnlyOneLocalTax($local)
$valors=explode(":", $tax);
- if(count($valors)>1)
+ if (count($valors)>1)
{
return false;
}
@@ -3425,7 +3449,7 @@ function isOnlyOneLocalTax($local)
}
/**
- * Get values of localtaxes
+ * Get values of localtaxes (1 or 2) for company country for the common vat with the highest value
*
* @param int $local LocalTax to get
* @return number Values of localtax
@@ -3435,9 +3459,10 @@ function get_localtax_by_third($local)
global $db, $mysoc;
$sql ="SELECT t.localtax1, t.localtax2 ";
$sql.=" FROM ".MAIN_DB_PREFIX."c_tva as t inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=t.fk_pays";
- $sql.=" WHERE c.code = '".$mysoc->country_code."' AND t.taux=(SELECT max(tt.taux)";
- $sql.=" FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays";
- $sql.=" WHERE c.code = '".$mysoc->country_code."')";
+ $sql.=" WHERE c.code = '".$mysoc->country_code."' AND t.active = 1 AND t.taux=(";
+ $sql.=" SELECT max(tt.taux) FROM ".MAIN_DB_PREFIX."c_tva as tt inner join ".MAIN_DB_PREFIX."c_country as c ON c.rowid=tt.fk_pays";
+ $sql.=" WHERE c.code = '".$mysoc->country_code."' AND tt.active = 1";
+ $sql.=" )";
$resql=$db->query($sql);
if ($resql)
@@ -3456,7 +3481,7 @@ function get_localtax_by_third($local)
* Get type and rate of localtaxes for a particular vat rate/country fo thirdparty
* TODO
* This function is also called to retrieve type for building PDF. Such call of function must be removed.
- * Instead this function must be called when adding a line to get (array of localtax and type) and
+ * Instead this function must be called when adding a line to get the array of localtax and type, and then
* provide it to the function calcul_price_total.
*
* @param float $vatrate VAT Rate
@@ -3467,15 +3492,24 @@ function get_localtax_by_third($local)
*/
function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller)
{
- global $db;
+ global $db, $mysoc;
dol_syslog("getLocalTaxesFromRate vatrate=".$vatrate." local=".$local);
+ $vatratecleaned = $vatrate;
+ if (preg_match('/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) // If vat is "xx (yy)"
+ {
+ $vatratecleaned = $reg[1];
+ $vatratecode = $reg[2];
+ }
+
// Search local taxes
$sql = "SELECT t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.accountancy_code_sell, t.accountancy_code_buy";
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
- $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";
- $sql .= " AND t.taux = ".((float) $vatrate)." AND t.active = 1";
+ if ($mysoc->country_code == 'ES') $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$buyer->country_code."'";
+ else $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$seller->country_code."'";
+ $sql .= " AND t.taux = ".((float) $vatratecleaned)." AND t.active = 1";
+ if ($vatratecode) $sql.= " AND t.code ='".$vatratecode."'";
$resql=$db->query($sql);
if ($resql)
@@ -5057,8 +5091,9 @@ function printCommonFooter($zone='private')
print ''."\n";
print 'jQuery(".reposition").click(function() {
var page_y = $(document).scrollTop();
+ /* alert(page_y); */
this.href=this.href+\'&page_y=\'+page_y;
- });';
+ });'."\n";
print '});'."\n";
print ''."\n";
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index c757efa23b4..3338585e65b 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -217,7 +217,7 @@ else {
';
}
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index e988893dbb4..d116b668b09 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -1314,7 +1314,8 @@ 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.
+
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@@ -2072,7 +2073,8 @@ 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.
+
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 05330fa2319..16cf3f7dee2 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -1269,7 +1269,8 @@ class FactureFournisseur extends CommonInvoice
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
$localtaxes_type=getLocalTaxesFromRate($vatrate,0,$mysoc, $this->thirdparty);
-
+ $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
+
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
diff --git a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
index 20ec018ad28..71186936e61 100755
--- a/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
+++ b/htdocs/install/mysql/migration/3.8.0-3.9.0.sql
@@ -305,6 +305,8 @@ ALTER TABLE llx_categorie_project ADD CONSTRAINT fk_categorie_project_categorie_
ALTER TABLE llx_categorie_project ADD CONSTRAINT fk_categorie_project_fk_project FOREIGN KEY (fk_project) REFERENCES llx_projet (rowid);
-
+ALTER TABLE llx_c_tva ADD COLUMN code varchar(10) DEFAULT '' after fk_pays;
+DROP INDEX uk_c_tva_id ON llx_c_tva;
+ALTER TABLE llx_c_tva ADD UNIQUE INDEX uk_c_tva_id (fk_pays, code, taux, recuperableonly);
diff --git a/htdocs/install/mysql/tables/llx_c_tva.key.sql b/htdocs/install/mysql/tables/llx_c_tva.key.sql
index e1ea6d37dab..7911284fdb1 100644
--- a/htdocs/install/mysql/tables/llx_c_tva.key.sql
+++ b/htdocs/install/mysql/tables/llx_c_tva.key.sql
@@ -1,5 +1,5 @@
-- ========================================================================
--- Copyright (C) 2014 Laurent Destailleur
+-- Copyright (C) 2014-2015 Laurent Destailleur
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@@ -16,4 +16,6 @@
--
-- ========================================================================
-ALTER TABLE llx_c_tva ADD UNIQUE INDEX uk_c_tva_id (fk_pays, taux, recuperableonly);
+ALTER TABLE llx_c_tva ADD UNIQUE INDEX uk_c_tva_id (fk_pays, code, taux, recuperableonly);
+
+-- ALTER TABLE llx_c_tva ADD UNIQUE INDEX uk_c_tva_id (fk_pays, code, recuperableonly); -- Not yet possible for compatibility reason, where old code is ''
diff --git a/htdocs/install/mysql/tables/llx_c_tva.sql b/htdocs/install/mysql/tables/llx_c_tva.sql
index dec81d43ed3..91e141ad4d1 100644
--- a/htdocs/install/mysql/tables/llx_c_tva.sql
+++ b/htdocs/install/mysql/tables/llx_c_tva.sql
@@ -22,6 +22,7 @@ create table llx_c_tva
(
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
fk_pays integer NOT NULL,
+ code varchar(10) DEFAULT '', -- a key to describe vat entry, for example FR20
taux double NOT NULL,
localtax1 varchar(20) NOT NULL DEFAULT '0',
localtax1_type varchar(10) NOT NULL DEFAULT '0',