New: Support NPR in customer product prices

This commit is contained in:
Laurent Destailleur 2010-08-09 19:08:22 +00:00
parent b067b85c67
commit 688bdf8b1d
8 changed files with 42 additions and 21 deletions

View File

@ -358,7 +358,8 @@ else
array('from'=>'2.5.0', 'to'=>'2.6.0'), array('from'=>'2.5.0', 'to'=>'2.6.0'),
array('from'=>'2.6.0', 'to'=>'2.7.0'), array('from'=>'2.6.0', 'to'=>'2.7.0'),
array('from'=>'2.7.0', 'to'=>'2.8.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; $count=0;

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* 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
@ -25,7 +25,7 @@
* \version $Id$ * \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('../core/class/translate.class.php');
require_once('../lib/functions.lib.php'); require_once('../lib/functions.lib.php');

View File

@ -5,3 +5,11 @@
-- This file must be loaded by calling /install/index.php page -- This file must be loaded by calling /install/index.php page
-- when current version is 2.8.0 or higher. -- 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;

View File

@ -39,8 +39,9 @@ create table llx_product
price_min_ttc double(24,8) DEFAULT 0, price_min_ttc double(24,8) DEFAULT 0,
price_base_type varchar(3) DEFAULT 'HT', price_base_type varchar(3) DEFAULT 'HT',
tva_tx double(6,3), tva_tx double(6,3),
localtax1_tx double(6,3) DEFAULT 0, recuperableonly integer NOT NULL DEFAULT '0', -- Franch NPR VAT
localtax2_tx double(6,3) DEFAULT 0, 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, fk_user_author integer,
envente tinyint DEFAULT 1, envente tinyint DEFAULT 1,
fk_product_type integer DEFAULT 0, -- Type 0 for regular product, 1 for service fk_product_type integer DEFAULT 0, -- Type 0 for regular product, 1 for service

View File

@ -32,6 +32,7 @@ create table llx_product_price
price_min_ttc double(24,8) default NULL, price_min_ttc double(24,8) default NULL,
price_base_type varchar(3) DEFAULT 'HT', price_base_type varchar(3) DEFAULT 'HT',
tva_tx double(6,3) NOT NULL, tva_tx double(6,3) NOT NULL,
recuperableonly integer NOT NULL DEFAULT '0',
localtax1_tx double(6,3) DEFAULT 0, localtax1_tx double(6,3) DEFAULT 0,
localtax2_tx double(6,3) DEFAULT 0, localtax2_tx double(6,3) DEFAULT 0,
fk_user_author integer, fk_user_author integer,

View File

@ -32,7 +32,7 @@
* \version $Id$ * \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)); define('EURO',chr(128));
// Definition des constantes syslog // Definition des constantes syslog

View File

@ -65,7 +65,9 @@ class Product extends CommonObject
var $multiprices_tva_tx=array(); var $multiprices_tva_tx=array();
//! Taux de TVA //! Taux de TVA
var $tva_tx; var $tva_tx;
// Local taxes //! French VAT NPR
var $tva_npr=0;
//! Spanish local taxes
var $localtax1_tx; var $localtax1_tx;
var $localtax2_tx; var $localtax2_tx;
//! Type 0 for regular product, 1 for service (Advanced feature: 2 for assembly kit, 3 for stock kit) //! 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) function _log_price($user,$level=0)
{ {
$now=dol_now();
// Add new price // 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.= " 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.= " ".$this->localtax1_tx.",".$this->localtax2_tx.",".$this->price_min.",".$this->price_min_ttc;
$sql.= ")"; $sql.= ")";
@ -837,16 +841,18 @@ class Product extends CommonObject
* \param newvat New VAT Rate * \param newvat New VAT Rate
* \param newminprice New price min * \param newminprice New price min
* \param level 0=standard, >0 = level if multilevel prices * \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 * \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; 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 // 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 // Check parameters
if ($newvat == '') $newvat=$this->tva_tx; if ($newvat == '') $newvat=$this->tva_tx;
@ -908,7 +914,8 @@ class Product extends CommonObject
$sql.= " price_min_ttc=".$price_min_ttc.","; $sql.= " price_min_ttc=".$price_min_ttc.",";
$sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').","; $sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').",";
$sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').","; $sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').",";
$sql.= " tva_tx='".price2num($newvat)."'"; $sql.= " tva_tx='".price2num($newvat)."',";
$sql.= " recuperableonly='".$newnpr."'";
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
dol_syslog("Product::update_price sql=".$sql, LOG_DEBUG); dol_syslog("Product::update_price sql=".$sql, LOG_DEBUG);
@ -921,6 +928,7 @@ 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;
$this->tva_npr = $newnpr;
//Local taxes //Local taxes
$this->localtax1_tx = $localtax1; $this->localtax1_tx = $localtax1;
$this->localtax2_tx = $localtax2; $this->localtax2_tx = $localtax2;
@ -959,7 +967,7 @@ class Product extends CommonObject
} }
$sql = "SELECT rowid, ref, label, description, note, price, price_ttc,"; $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.= " 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.= " 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,"; $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_min_ttc = $result["price_min_ttc"];
$this->price_base_type = $result["price_base_type"]; $this->price_base_type = $result["price_base_type"];
$this->tva_tx = $result["tva_tx"]; $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->localtax1_tx = $result["localtax1_tx"];
$this->localtax2_tx = $result["localtax2_tx"]; $this->localtax2_tx = $result["localtax2_tx"];

View File

@ -86,7 +86,7 @@ if ($_POST["action"] == 'update_price' && ! $_POST["cancel"] && ($user->rights->
$newvat=str_replace('*','',$_POST["tva_tx"]); $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"] = ''; $_GET["action"] = '';
$mesg = '<div class="ok">'.$langs->trans("RecordSaved").'</div>'; $mesg = '<div class="ok">'.$langs->trans("RecordSaved").'</div>';
@ -425,7 +425,7 @@ if ($_GET["action"] == 'edit_price' && ($user->rights->produit->creer || $user->
// Liste des evolutions du prix // 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.price_level, p.price_min, p.price_min_ttc,";
$sql.= " p.date_price as dp, u.rowid as user_id, u.login"; $sql.= " p.date_price as dp, u.rowid as user_id, u.login";
$sql.= " FROM ".MAIN_DB_PREFIX."product_price as p,"; $sql.= " FROM ".MAIN_DB_PREFIX."product_price as p,";
@ -494,7 +494,7 @@ if ($result)
} }
print '<td align="center">'.$langs->trans($objp->price_base_type)."</td>"; print '<td align="center">'.$langs->trans($objp->price_base_type)."</td>";
print '<td align="right">'.vatrate($objp->tva_tx,true)."</td>"; print '<td align="right">'.vatrate($objp->tva_tx,true,$objp->recuperableonly)."</td>";
print '<td align="right">'.price($objp->price)."</td>"; print '<td align="right">'.price($objp->price)."</td>";
print '<td align="right">'.price($objp->price_ttc)."</td>"; print '<td align="right">'.price($objp->price_ttc)."</td>";
print '<td align="right">'.price($objp->price_min).'</td>'; print '<td align="right">'.price($objp->price_min).'</td>';