From 688bdf8b1d7ff51fea0f0b526854c0f1cbc01c4c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 9 Aug 2010 19:08:22 +0000 Subject: [PATCH] New: Support NPR in customer product prices --- htdocs/install/check.php | 3 +- htdocs/install/inc.php | 4 +-- .../install/mysql/migration/2.9.0-3.0.0.sql | 8 +++++ htdocs/install/mysql/tables/llx_product.sql | 5 ++-- .../mysql/tables/llx_product_price.sql | 5 ++-- htdocs/master.inc.php | 2 +- htdocs/product/class/product.class.php | 30 ++++++++++++------- htdocs/product/price.php | 6 ++-- 8 files changed, 42 insertions(+), 21 deletions(-) diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 51f98df52c8..b3a55bba4d4 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -358,7 +358,8 @@ else array('from'=>'2.5.0', 'to'=>'2.6.0'), array('from'=>'2.6.0', 'to'=>'2.7.0'), array('from'=>'2.7.0', 'to'=>'2.8.0'), - array('from'=>'2.8.0', 'to'=>'2.9.0') + array('from'=>'2.8.0', 'to'=>'2.9.0'), + array('from'=>'2.9.0', 'to'=>'3.0.0') ); $count=0; diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 6a07902ee35..9f335166a0c 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Sebastien DiCintio - * Copyright (C) 2007-2009 Laurent Destailleur + * Copyright (C) 2007-2010 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 @@ -25,7 +25,7 @@ * \version $Id$ */ -define('DOL_VERSION','2.9.0'); // Also defined in htdocs/master.inc.php +define('DOL_VERSION','3.0.0-alpha'); // Also defined in htdocs/master.inc.php (Ex: x.y.z-alpha, x.y.z) require_once('../core/class/translate.class.php'); require_once('../lib/functions.lib.php'); diff --git a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql index c3f69fedf5a..5af8870dc2e 100644 --- a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql +++ b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql @@ -5,3 +5,11 @@ -- This file must be loaded by calling /install/index.php page -- when current version is 2.8.0 or higher. -- + + +alter table llx_product add column recuperableonly integer NOT NULL DEFAULT '0' after tva_tx; + +alter table llx_product_price add column recuperableonly integer NOT NULL DEFAULT '0' after tva_tx; + + + \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index efd71defb31..bb3008ddff1 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -39,8 +39,9 @@ create table llx_product price_min_ttc double(24,8) DEFAULT 0, price_base_type varchar(3) DEFAULT 'HT', tva_tx double(6,3), - localtax1_tx double(6,3) DEFAULT 0, - localtax2_tx double(6,3) DEFAULT 0, + recuperableonly integer NOT NULL DEFAULT '0', -- Franch NPR VAT + localtax1_tx double(6,3) DEFAULT 0, -- Spanish local VAT 1 + localtax2_tx double(6,3) DEFAULT 0, -- Spanish local VAT 2 fk_user_author integer, envente tinyint DEFAULT 1, fk_product_type integer DEFAULT 0, -- Type 0 for regular product, 1 for service diff --git a/htdocs/install/mysql/tables/llx_product_price.sql b/htdocs/install/mysql/tables/llx_product_price.sql index eda64ddcc65..961ac477bb2 100644 --- a/htdocs/install/mysql/tables/llx_product_price.sql +++ b/htdocs/install/mysql/tables/llx_product_price.sql @@ -30,8 +30,9 @@ create table llx_product_price price_ttc double(24,8) DEFAULT NULL, price_min double(24,8) default NULL, price_min_ttc double(24,8) default NULL, - price_base_type varchar(3) DEFAULT 'HT', - tva_tx double(6,3) NOT NULL, + price_base_type varchar(3) DEFAULT 'HT', + tva_tx double(6,3) NOT NULL, + recuperableonly integer NOT NULL DEFAULT '0', localtax1_tx double(6,3) DEFAULT 0, localtax2_tx double(6,3) DEFAULT 0, fk_user_author integer, diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 2be58369962..71ebf563414 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -32,7 +32,7 @@ * \version $Id$ */ -define('DOL_VERSION','2.9.0'); // Also defined in htdocs/install/inc.php +define('DOL_VERSION','3.0.0-alpha'); // Also defined in htdocs/install/inc.php (Ex: x.y.z-alpha, x.y.z) define('EURO',chr(128)); // Definition des constantes syslog diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e25f35a66a0..383eb385980 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -65,7 +65,9 @@ class Product extends CommonObject var $multiprices_tva_tx=array(); //! Taux de TVA var $tva_tx; - // Local taxes + //! French VAT NPR + var $tva_npr=0; + //! Spanish local taxes var $localtax1_tx; var $localtax2_tx; //! Type 0 for regular product, 1 for service (Advanced feature: 2 for assembly kit, 3 for stock kit) @@ -699,10 +701,12 @@ class Product extends CommonObject */ function _log_price($user,$level=0) { + $now=dol_now(); + // Add new price - $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,recuperableonly,"; $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($now).",".$this->id.",".$user->id.",".$this->price.",".$this->price_ttc.",'".$this->price_base_type."',".$this->status.",".$this->tva_tx.",".$this->tva_npr.","; $sql.= " ".$this->localtax1_tx.",".$this->localtax2_tx.",".$this->price_min.",".$this->price_min_ttc; $sql.= ")"; @@ -837,16 +841,18 @@ class Product extends CommonObject * \param newvat New VAT Rate * \param newminprice New price min * \param level 0=standard, >0 = level if multilevel prices + * \param newnpr 0=Standard vat rate, 1=Special vat rate for French NPR VAT * \return int <0 if KO, >0 if OK */ - function update_price($id, $newprice, $newpricebase, $user, $newvat='',$newminprice='', $level=0) + function update_price($id, $newprice, $newpricebase, $user, $newvat='',$newminprice='', $level=0, $newnpr=0) { global $conf,$langs; - dol_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level); + dol_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr); // Clean parameters - if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($newnpr)) $newnpr=0; // Check parameters if ($newvat == '') $newvat=$this->tva_tx; @@ -908,8 +914,9 @@ class Product extends CommonObject $sql.= " price_min_ttc=".$price_min_ttc.","; $sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').","; $sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').","; - $sql.= " tva_tx='".price2num($newvat)."'"; - $sql.= " WHERE rowid = " . $id; + $sql.= " tva_tx='".price2num($newvat)."',"; + $sql.= " recuperableonly='".$newnpr."'"; + $sql.= " WHERE rowid = ".$id; dol_syslog("Product::update_price sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); @@ -921,6 +928,7 @@ class Product extends CommonObject $this->price_min_ttc = $price_min_ttc; $this->price_base_type = $newpricebase; $this->tva_tx = $newvat; + $this->tva_npr = $newnpr; //Local taxes $this->localtax1_tx = $localtax1; $this->localtax2_tx = $localtax2; @@ -959,7 +967,7 @@ class Product extends CommonObject } $sql = "SELECT rowid, ref, label, description, note, price, price_ttc,"; - $sql.= " price_min, price_min_ttc, price_base_type, tva_tx, localtax1_tx, localtax2_tx, envente,"; + $sql.= " price_min, price_min_ttc, price_base_type, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, envente,"; $sql.= " fk_product_type, duration, seuil_stock_alerte, canvas,"; $sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished, hidden,"; $sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,"; @@ -985,7 +993,9 @@ class Product extends CommonObject $this->price_min_ttc = $result["price_min_ttc"]; $this->price_base_type = $result["price_base_type"]; $this->tva_tx = $result["tva_tx"]; - //Local taxes + //! French VAT NPR + $this->tva_npr = $result["tva_npr"]; + //! Spanish local taxes $this->localtax1_tx = $result["localtax1_tx"]; $this->localtax2_tx = $result["localtax2_tx"]; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 220a7b27365..3f3302e55ca 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -86,7 +86,7 @@ if ($_POST["action"] == 'update_price' && ! $_POST["cancel"] && ($user->rights-> $newvat=str_replace('*','',$_POST["tva_tx"]); } - if ($product->update_price($product->id, $newprice, $newpricebase, $user, $newvat, $newprice_min, $level) > 0) + if ($product->update_price($product->id, $newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr) > 0) { $_GET["action"] = ''; $mesg = '
'.$langs->trans("RecordSaved").'
'; @@ -425,7 +425,7 @@ if ($_GET["action"] == 'edit_price' && ($user->rights->produit->creer || $user-> // Liste des evolutions du prix -$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,"; +$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.recuperableonly,"; $sql.= " p.price_level, p.price_min, p.price_min_ttc,"; $sql.= " p.date_price as dp, u.rowid as user_id, u.login"; $sql.= " FROM ".MAIN_DB_PREFIX."product_price as p,"; @@ -494,7 +494,7 @@ if ($result) } print ''.$langs->trans($objp->price_base_type).""; - print ''.vatrate($objp->tva_tx,true).""; + print ''.vatrate($objp->tva_tx,true,$objp->recuperableonly).""; print ''.price($objp->price).""; print ''.price($objp->price_ttc).""; print ''.price($objp->price_min).'';