forked from Wavyzz/dolibarr
Works on enhancement of local taxes. First changes to products
This commit is contained in:
@@ -2525,6 +2525,32 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
|
|||||||
return $amount;
|
return $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Return localtaxe rate for a particular tva
|
||||||
|
* \param tva Vat taxe
|
||||||
|
* \param local Local taxe to search and return
|
||||||
|
*/
|
||||||
|
function get_localtax($tva, $local=0)
|
||||||
|
{
|
||||||
|
global $db, $conf, $mysoc;
|
||||||
|
|
||||||
|
$code_pays=$mysoc->pays_code;
|
||||||
|
|
||||||
|
// Search local taxes
|
||||||
|
$sql = "SELECT t.localtax1, t.localtax2";
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
|
||||||
|
$sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$code_pays."'";
|
||||||
|
$sql .= " AND t.taux =".$tva." AND t.active = 1";
|
||||||
|
$sql .= " ORDER BY t.localtax1 ASC, t.localtax2 ASC";
|
||||||
|
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$obj = $db->fetch_object($resql);
|
||||||
|
if ($local==1) return $obj->localtax1;
|
||||||
|
elseif ($local==2) return $obj->localtax2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return vat rate of a product in a particular selling country
|
* \brief Return vat rate of a product in a particular selling country
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
* Copyright (C) 2006 Auguria SARL <info@auguria.org>
|
* Copyright (C) 2006 Auguria SARL <info@auguria.org>
|
||||||
|
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -139,6 +140,11 @@ if ($_POST["action"] == 'add' && ($user->rights->produit->creer || $user->rights
|
|||||||
if ($product->price_base_type == 'TTC') $product->price_min_ttc = $_POST["price_min"];
|
if ($product->price_base_type == 'TTC') $product->price_min_ttc = $_POST["price_min"];
|
||||||
else $product->price_min = $_POST["price_min"];
|
else $product->price_min = $_POST["price_min"];
|
||||||
$product->tva_tx = $_POST["tva_tx"];
|
$product->tva_tx = $_POST["tva_tx"];
|
||||||
|
|
||||||
|
// local taxes.
|
||||||
|
$product->localtax1_tx = get_localtax($product->tva_tx,1);
|
||||||
|
$product->localtax2_tx = get_localtax($product->tva_tx,2);
|
||||||
|
|
||||||
$product->type = $_POST["type"];
|
$product->type = $_POST["type"];
|
||||||
$product->status = $_POST["statut"];
|
$product->status = $_POST["statut"];
|
||||||
$product->description = dol_htmlcleanlastbr($_POST["desc"]);
|
$product->description = dol_htmlcleanlastbr($_POST["desc"]);
|
||||||
|
|||||||
@@ -696,7 +696,7 @@ class Product extends CommonObject
|
|||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price,fk_product,fk_user_author,price,price_ttc,price_base_type,envente,tva_tx,";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price,fk_product,fk_user_author,price,price_ttc,price_base_type,envente,tva_tx,";
|
||||||
$sql.= " localtax1_tx, localtax2_tx, price_min,price_min_ttc) ";
|
$sql.= " localtax1_tx, localtax2_tx, price_min,price_min_ttc) ";
|
||||||
$sql.= " VALUES(".($level?$level:1).", ".$this->db->idate(mktime()).",".$this->id.",".$user->id.",".$this->price.",".$this->price_ttc.",'".$this->price_base_type."',".$this->status.",".$this->tva_tx.",";
|
$sql.= " VALUES(".($level?$level:1).", ".$this->db->idate(mktime()).",".$this->id.",".$user->id.",".$this->price.",".$this->price_ttc.",'".$this->price_base_type."',".$this->status.",".$this->tva_tx.",";
|
||||||
$sql.= " ".$this->localtax1_tx.",".$this->localtax1_tx.",".$this->price_min.",".$this->price_min_ttc;
|
$sql.= " ".$this->localtax1_tx.",".$this->localtax2_tx.",".$this->price_min.",".$this->price_min_ttc;
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
|
|
||||||
dol_syslog("Product::_log_price sql=".$sql);
|
dol_syslog("Product::_log_price sql=".$sql);
|
||||||
@@ -884,7 +884,11 @@ class Product extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//print 'x'.$id.'-'.$newprice.'-'.$newpricebase.'-'.$price.'-'.$price_ttc.'-'.$price_min.'-'.$price_min_ttc;
|
//print 'x'.$id.'-'.$newprice.'-'.$newpricebase.'-'.$price.'-'.$price_ttc.'-'.$price_min.'-'.$price_min_ttc;
|
||||||
|
|
||||||
|
//Local taxes
|
||||||
|
$localtax1=get_localtax($newvat,1);
|
||||||
|
$localtax2=get_localtax($newvat,2);
|
||||||
|
|
||||||
// Ne pas mettre de quote sur le numeriques decimaux.
|
// Ne pas mettre de quote sur le numeriques decimaux.
|
||||||
// Ceci provoque des stockage avec arrondis en base au lieu des valeurs exactes.
|
// Ceci provoque des stockage avec arrondis en base au lieu des valeurs exactes.
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
|
||||||
@@ -893,6 +897,8 @@ class Product extends CommonObject
|
|||||||
$sql.= " price_ttc=".$price_ttc.",";
|
$sql.= " price_ttc=".$price_ttc.",";
|
||||||
$sql.= " price_min=".$price_min.",";
|
$sql.= " price_min=".$price_min.",";
|
||||||
$sql.= " price_min_ttc=".$price_min_ttc.",";
|
$sql.= " price_min_ttc=".$price_min_ttc.",";
|
||||||
|
$sql.= " localtax1_tx=".$localtax1.",";
|
||||||
|
$sql.= " localtax2_tx=".$localtax2.",";
|
||||||
$sql.= " tva_tx='".price2num($newvat)."'";
|
$sql.= " tva_tx='".price2num($newvat)."'";
|
||||||
$sql.= " WHERE rowid = " . $id;
|
$sql.= " WHERE rowid = " . $id;
|
||||||
|
|
||||||
@@ -906,7 +912,10 @@ class Product extends CommonObject
|
|||||||
$this->price_min_ttc = $price_min_ttc;
|
$this->price_min_ttc = $price_min_ttc;
|
||||||
$this->price_base_type = $newpricebase;
|
$this->price_base_type = $newpricebase;
|
||||||
$this->tva_tx = $newvat;
|
$this->tva_tx = $newvat;
|
||||||
|
//Local taxes
|
||||||
|
$this->localtax1_tx = $localtax1;
|
||||||
|
$this->localtax2_tx = $localtax2;
|
||||||
|
|
||||||
$this->_log_price($user,$level);
|
$this->_log_price($user,$level);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user