New: Add hidden option MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS

This commit is contained in:
Laurent Destailleur 2013-09-28 13:24:58 +02:00
parent 9b36df85dd
commit 4cf84c4ea8
4 changed files with 34 additions and 26 deletions

View File

@ -56,6 +56,7 @@ For users:
- New: [ task #1060 ] Register fields localtax(1|2)_type into details tables. - New: [ task #1060 ] Register fields localtax(1|2)_type into details tables.
- New: [ task #923 ] Localtax support for ODT templates. - New: [ task #923 ] Localtax support for ODT templates.
- New: [ task #90 ] Barcode search. - New: [ task #90 ] Barcode search.
- New: Add hidden option MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS.
For translators: For translators:
- Qual: Normalized sort order of all languages files with english reference files. - Qual: Normalized sort order of all languages files with english reference files.

View File

@ -3370,12 +3370,14 @@ class Form
// Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
if ($defaulttx < 0 || dol_strlen($defaulttx) == 0) if ($defaulttx < 0 || dol_strlen($defaulttx) == 0)
{ {
$defaulttx = $this->cache_vatrates[$num-1]['txtva']; if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) $defaulttx = $this->cache_vatrates[$num-1]['txtva'];
else $defaulttx=$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
} }
// Disabled if seller is not subject to VAT // Disabled if seller is not subject to VAT
$disabled=false; $title=''; $disabled=false; $title='';
if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == "0") { if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == "0")
{
$title=' title="'.$langs->trans('VATIsNotUsed').'"'; $title=' title="'.$langs->trans('VATIsNotUsed').'"';
$disabled=true; $disabled=true;
} }

View File

@ -2908,17 +2908,15 @@ function getLocalTaxesFromRate($vatrate, $local, $thirdparty)
* *
* @param int $idprod Id of product or 0 if not a predefined product * @param int $idprod Id of product or 0 if not a predefined product
* @param Societe $thirdparty_seller Thirdparty with a ->country_code defined (FR, US, IT, ...) * @param Societe $thirdparty_seller Thirdparty with a ->country_code defined (FR, US, IT, ...)
* @param int $idprodfournprice Id product_fournisseur_price (for supplier order/invoice) * @param int $idprodfournprice Id product_fournisseur_price (for "supplier" order/invoice)
* @return int <0 if KO, Vat rate if OK * @return int <0 if KO, Vat rate if OK
* @see get_product_localtax_for_country * @see get_product_localtax_for_country
*/ */
function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice=0) function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice=0)
{ {
global $db,$mysoc; global $db,$conf,$mysoc;
if (! class_exists('Product')) { require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
}
$ret=0; $ret=0;
$found=0; $found=0;
@ -2931,7 +2929,7 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr
if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours if ($mysoc->country_code == $thirdparty_seller->country_code) // If selling country is ours
{ {
if ($idprodfournprice > 0) // We want vat for product for a supplier order or invoice if ($idprodfournprice > 0) // We want vat for product for a "supplier" order or invoice
{ {
$product->get_buyprice($idprodfournprice,0,0,0); $product->get_buyprice($idprodfournprice,0,0,0);
$ret=$product->vatrate_supplier; $ret=$product->vatrate_supplier;
@ -2952,23 +2950,28 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr
if (! $found) if (! $found)
{ {
// If vat of product for the country not found or not defined, we return higher vat of country. if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS))
$sql = "SELECT taux as vat_rate";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql.= " WHERE t.active=1 AND t.fk_pays = p.rowid AND p.code='".$thirdparty_seller->country_code."'";
$sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
$sql.= $db->plimit(1);
$resql=$db->query($sql);
if ($resql)
{ {
$obj=$db->fetch_object($resql); // If vat of product for the country not found or not defined, we return higher vat of country.
if ($obj) $sql = "SELECT taux as vat_rate";
$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
$sql.= " WHERE t.active=1 AND t.fk_pays = p.rowid AND p.code='".$thirdparty_seller->country_code."'";
$sql.= " ORDER BY t.taux DESC, t.recuperableonly ASC";
$sql.= $db->plimit(1);
$resql=$db->query($sql);
if ($resql)
{ {
$ret=$obj->vat_rate; $obj=$db->fetch_object($resql);
if ($obj)
{
$ret=$obj->vat_rate;
}
$db->free($sql);
} }
else dol_print_error($db);
} }
else dol_print_error($db); else $ret=$conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
} }
dol_syslog("get_product_vat_for_country: ret=".$ret); dol_syslog("get_product_vat_for_country: ret=".$ret);

View File

@ -893,7 +893,7 @@ class Product extends CommonObject
/** /**
* Lit le prix pratique par un fournisseur * Lit le prix pratique par un fournisseur
* On renseigne le couple prodfournprice/qty ou le triplet qty/product_id/fourn_ref) * On renseigne le couple prodfournprice/qty ou le triplet qty/product_id/fourn_ref
* *
* @param int $prodfournprice Id du tarif = rowid table product_fournisseur_price * @param int $prodfournprice Id du tarif = rowid table product_fournisseur_price
* @param double $qty Quantity asked * @param double $qty Quantity asked
@ -904,6 +904,8 @@ class Product extends CommonObject
function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0) function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
{ {
$result = 0; $result = 0;
// We do select by searching with qty and prodfournprice
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity,"; $sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity,";
$sql.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc, pfp.tva_tx"; $sql.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc, pfp.tva_tx";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
@ -915,7 +917,7 @@ class Product extends CommonObject
if ($resql) if ($resql)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj && $obj->quantity > 0) if ($obj && $obj->quantity > 0) // If found
{ {
$this->buyprice = $obj->price; // \deprecated $this->buyprice = $obj->price; // \deprecated
$this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
@ -926,7 +928,7 @@ class Product extends CommonObject
} }
else else
{ {
// On refait le meme select sur la ref et l'id du produit // We do same select again but searching with qty, ref and id product
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,"; $sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,";
$sql.= " pfp.fk_product, pfp.ref_fourn, pfp.tva_tx"; $sql.= " pfp.fk_product, pfp.ref_fourn, pfp.tva_tx";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
@ -941,7 +943,7 @@ class Product extends CommonObject
if ($resql) if ($resql)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($obj && $obj->quantity > 0) if ($obj && $obj->quantity > 0) // If found
{ {
$this->buyprice = $obj->price; // \deprecated $this->buyprice = $obj->price; // \deprecated
$this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
@ -952,7 +954,7 @@ class Product extends CommonObject
} }
else else
{ {
return -1; // Ce produit existe chez ce fournisseur mais qte insuffisante return -1; // Ce produit n'existe pas avec cette ref fournisseur ou existe mais qte insuffisante
} }
} }
else else