Skip to content

Commit

Permalink
New: Add hidden option MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS
Browse files Browse the repository at this point in the history
Conflicts:
	ChangeLog
  • Loading branch information
eldy committed Sep 28, 2013
1 parent 9fedc42 commit 836aa08
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -2,6 +2,7 @@
English Dolibarr ChangeLog
--------------------------------------------------------------


***** ChangeLog for 3.3.4 compared to 3.3.3 *****

- Fix: [ bug #1001 ] Social Contribution : State not correct
Expand Down
6 changes: 4 additions & 2 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -3246,12 +3246,14 @@ function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $
// Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
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=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').'"';
$disabled=true;
}
Expand Down
41 changes: 22 additions & 19 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -2771,17 +2771,15 @@ function getLocalTaxesFromRate($vatrate, $local, $thirdparty)
*
* @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 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
* @see get_product_localtax_for_country
*/
function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice=0)
{
global $db,$mysoc;
global $db,$conf,$mysoc;

if (! class_exists('Product')) {
require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
}
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';

$ret=0;
$found=0;
Expand All @@ -2794,7 +2792,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 ($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);
$ret=$product->vatrate_supplier;
Expand All @@ -2815,23 +2813,28 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr

if (! $found)
{
// If vat of product for the country not found or not defined, we return higher vat of country.
$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)
if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS))
{
$obj=$db->fetch_object($resql);
if ($obj)
// If vat of product for the country not found or not defined, we return higher vat of country.
$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);
Expand Down
12 changes: 7 additions & 5 deletions htdocs/product/class/product.class.php
Expand Up @@ -875,7 +875,7 @@ function log_price_delete($user,$rowid)

/**
* 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 double $qty Quantity asked
Expand All @@ -886,6 +886,8 @@ function log_price_delete($user,$rowid)
function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=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.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc, pfp.tva_tx";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
Expand All @@ -897,7 +899,7 @@ function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
if ($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->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
Expand All @@ -908,7 +910,7 @@ function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
}
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.= " pfp.fk_product, pfp.ref_fourn, pfp.tva_tx";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
Expand All @@ -923,7 +925,7 @@ function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
if ($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->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
Expand All @@ -934,7 +936,7 @@ function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=0)
}
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
Expand Down

0 comments on commit 836aa08

Please sign in to comment.