Prepare 3.8 dev

Fix bad test.
Renamed table for dynamic prices.
This commit is contained in:
Laurent Destailleur 2014-12-03 17:06:44 +01:00
parent cdba9b8972
commit 1e8e4e7fda
14 changed files with 52 additions and 56 deletions

View File

@ -1990,7 +1990,7 @@ class Form
$outdiscount=$objp->remise_percent;
if (!empty($objp->fk_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parse_product_supplier($objp->fk_product, $objp->fk_price_expression, $objp->quantity, $objp->tva_tx);
$price_result = $priceparser->parseProductSupplier($objp->fk_product, $objp->fk_price_expression, $objp->quantity, $objp->tva_tx);
if ($price_result >= 0) {
$objp->fprice = $price_result;
if ($objp->quantity >= 1)
@ -2129,7 +2129,7 @@ class Form
if (!empty($objp->fk_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parse_product_supplier($objp->fk_product, $objp->fk_price_expression, $objp->quantity, $objp->tva_tx);
$price_result = $priceparser->parseProductSupplier($objp->fk_product, $objp->fk_price_expression, $objp->quantity, $objp->tva_tx);
if ($price_result >= 0) {
$objp->fprice = $price_result;
if ($objp->quantity >= 1)

View File

@ -29,7 +29,7 @@
* \brief File that include conf.php file and commons lib like functions.lib.php
*/
if (! defined('DOL_VERSION')) define('DOL_VERSION','3.7.0-beta');
if (! defined('DOL_VERSION')) define('DOL_VERSION','3.8.0-alpha');
if (! defined('EURO')) define('EURO',chr(128));
// Define syslog constants

View File

@ -74,7 +74,7 @@ if (! empty($idprod))
if (!empty($objp->fk_price_expression)) {
$priceparser = new PriceParser($db);
$price_result = $priceparser->parse_product_supplier($idprod, $objp->fk_price_expression, $objp->quantity, $objp->tva_tx);
$price_result = $priceparser->parseProductSupplier($idprod, $objp->fk_price_expression, $objp->quantity, $objp->tva_tx);
if ($price_result >= 0) {
$objp->fprice = $price_result;
if ($objp->quantity >= 1)

View File

@ -359,7 +359,7 @@ class ProductFournisseur extends Product
if (empty($ignore_expression) && !empty($this->fk_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parse_product_supplier($this->fk_product, $this->fk_price_expression, $this->fourn_qty, $this->fourn_tva_tx);
$price_result = $priceparser->parseProductSupplier($this->fk_product, $this->fk_price_expression, $this->fourn_qty, $this->fourn_tva_tx);
if ($price_result >= 0) {
$this->fourn_price = $price_result;
//recalculation of unitprice, as probably the price changed...
@ -443,7 +443,7 @@ class ProductFournisseur extends Product
if (!empty($prodfourn->fk_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parse_product_supplier($prodid, $prodfourn->fk_price_expression, $prodfourn->fourn_qty, $prodfourn->fourn_tva_tx);
$price_result = $priceparser->parseProductSupplier($prodid, $prodfourn->fk_price_expression, $prodfourn->fourn_qty, $prodfourn->fourn_tva_tx);
if ($price_result >= 0) {
$prodfourn->fourn_price = $price_result;
$prodfourn->fourn_unitprice = null; //force recalculation of unitprice, as probably the price changed...

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013-2014 Juanjo Menent <jmenent@2byte.es>
@ -380,22 +380,14 @@ else
$allowupgrade=false;
}
if (defined("MAIN_NOT_INSTALLED")) $allowupgrade=false;
$migrationscript=array( //array('from'=>'2.0.0', 'to'=>'2.1.0'),
//array('from'=>'2.1.0', 'to'=>'2.2.0'),
//array('from'=>'2.2.0', 'to'=>'2.4.0'),
//array('from'=>'2.4.0', 'to'=>'2.5.0'),
//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.9.0', 'to'=>'3.0.0'),
array('from'=>'3.0.0', 'to'=>'3.1.0'),
$migrationscript=array( array('from'=>'3.0.0', 'to'=>'3.1.0'),
array('from'=>'3.1.0', 'to'=>'3.2.0'),
array('from'=>'3.2.0', 'to'=>'3.3.0'),
array('from'=>'3.3.0', 'to'=>'3.4.0'),
array('from'=>'3.4.0', 'to'=>'3.5.0'),
array('from'=>'3.5.0', 'to'=>'3.6.0'),
array('from'=>'3.6.0', 'to'=>'3.7.0')
array('from'=>'3.6.0', 'to'=>'3.7.0'),
array('from'=>'3.7.0', 'to'=>'3.8.0')
);
$count=0;

View File

@ -296,3 +296,7 @@ background-color: #dfd;
background-repeat: repeat-x;
background-position: top left;
}
.center {
text-align: center;
}

View File

@ -19,11 +19,11 @@
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
--create table for price expressions and add column in product supplier
create table llx_price_expression
create table llx_c_price_expression
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
title varchar(20) NOT NULL,
expression varchar(80) NOT NULL
)ENGINE=innodb;
ALTER TABLE llx_product_fournisseur_price ADD fk_price_expression integer DEFAULT NULL;
ALTER TABLE llx_product_fournisseur_price ADD fk_price_expression integer DEFAULT NULL;

View File

@ -16,7 +16,7 @@
--
-- ============================================================================
create table llx_price_expression
create table llx_c_price_expression
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
title varchar(20) NOT NULL,

View File

@ -39,6 +39,6 @@ create table llx_product_fournisseur_price
tva_tx double(6,3) NOT NULL,
info_bits integer NOT NULL DEFAULT 0,
fk_user integer,
fk_price_expression integer,
fk_price_expression integer, -- Link to the rule for dynamic amount calculation
import_key varchar(14) -- Import key
)ENGINE=innodb;

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
/* Copyright (C) 2014 Ion Agorria <ion@agorria.com>
/* Copyright (C) 2014 Ion Agorria <ion@agorria.com>
*
* 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
@ -18,7 +18,7 @@
*/
/**
* \file htdocs/product/class/priceexpresion.class.php
* \file htdocs/product/class/priceexpression.class.php
* \ingroup product
* \brief Class for accesing price expression table
*/
@ -59,12 +59,12 @@ class PriceExpression
{
$error=0;
// Clean parameters
// Clean parameters
if (isset($this->title)) $this->title=trim($this->title);
if (isset($this->expression)) $this->expression=trim($this->expression);
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."price_expression (";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_price_expression (";
$sql.= "title, expression";
$sql.= ") VALUES (";
$sql.= " ".(isset($this->title)?"'".$this->db->escape($this->title)."'":"''").",";
@ -121,7 +121,7 @@ class PriceExpression
function fetch($id)
{
$sql = "SELECT title, expression";
$sql.= " FROM ".MAIN_DB_PREFIX."price_expression";
$sql.= " FROM ".MAIN_DB_PREFIX."c_price_expression";
$sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::fetch");
@ -156,7 +156,7 @@ class PriceExpression
function list_price_expression()
{
$sql = "SELECT rowid, title, expression";
$sql.= " FROM ".MAIN_DB_PREFIX."price_expression";
$sql.= " FROM ".MAIN_DB_PREFIX."c_price_expression";
$sql.= " ORDER BY title";
dol_syslog(get_class($this)."::list_price_expression");
@ -194,7 +194,7 @@ class PriceExpression
function find_title($title)
{
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."price_expression";
$sql.= " FROM ".MAIN_DB_PREFIX."c_price_expression";
$sql.= " WHERE title = '".$this->db->escape($title)."'";
dol_syslog(get_class($this)."::find_title");
@ -230,12 +230,12 @@ class PriceExpression
{
$error=0;
// Clean parameters
// Clean parameters
if (isset($this->title)) $this->title=trim($this->title);
if (isset($this->expression)) $this->expression=trim($this->expression);
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."price_expression SET";
$sql = "UPDATE ".MAIN_DB_PREFIX."c_price_expression SET";
$sql.= " title = ".(isset($this->title)?"'".$this->db->escape($this->title)."'":"''").",";
$sql.= " expression = ".(isset($this->expression)?"'".$this->db->escape($this->expression)."'":"''")."";
$sql.= " WHERE rowid = ".$this->id;
@ -309,7 +309,7 @@ class PriceExpression
if (! $error)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."price_expression";
$sql = "DELETE FROM ".MAIN_DB_PREFIX."c_price_expression";
$sql.= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::delete");

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2014 Ion Agorria <ion@agorria.com>
/* Copyright (C) 2014 Ion Agorria <ion@agorria.com>
*
* 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
@ -57,7 +57,7 @@ class PriceParser
*
* @return string Translated error
*/
public function translated_error()
public function translatedError()
{
global $langs;
$langs->load("errors");
@ -94,20 +94,20 @@ class PriceParser
*/
if (empty($this->error)) {
return $langs->trans("ErrorPriceExpressionUnknown", 0); //this is not supposed to happen
}
}
list($code, $info) = $this->error;
if (in_array($code, array(9, 14, 19, 20))) //Errors which have 0 arg
{
return $langs->trans("ErrorPriceExpression".$code);
}
}
else if (in_array($code, array(1, 2, 3, 4, 5, 8, 10, 11, 17, 21, 22))) //Errors which have 1 arg
{
return $langs->trans("ErrorPriceExpression".$code, $info);
}
}
else if (in_array($code, array(6))) //Errors which have 2 args
{
return $langs->trans("ErrorPriceExpression".$code, $info[0], $info[1]);
}
}
else if (in_array($code, array(7, 12, 13, 15, 16, 18))) //Internal errors
{
return $langs->trans("ErrorPriceExpressionInternal", $code);
@ -125,11 +125,11 @@ class PriceParser
* @param String $expression The expression to parse
* @return int > 0 if OK, < 1 if KO
*/
public function parse_expression($values, $expression)
public function parseExpression($values, $expression)
{
//Check if empty
$expression = trim($expression);
if (empty($expression))
if (empty($expression))
{
$this->error = array(20, null);
return -1;
@ -169,12 +169,12 @@ class PriceParser
if (empty($vars["price"])) {
$vars["price"] = $last_result;
}
if ($vars["price"] === null)
if ($vars["price"] === null)
{
$this->error = array(21, $expression);
return -3;
}
if ($vars["price"] < 0)
if ($vars["price"] < 0)
{
$this->error = array(22, $expression);
return -4;
@ -185,14 +185,14 @@ class PriceParser
/**
* Calculates supplier product price based on product id and string expression
*
* @param int $product The Product id to get information
* @param int $product_id The Product id to get information
* @param string $expression The expression to parse
* @param int $quantity Min quantity
* @param int $tva_tx VAT rate
* @param array $extra_values Any aditional values for expression
* @return int > 0 if OK, < 1 if KO
*/
public function parse_product_supplier_expression($product_id, $expression, $quantity = null, $tva_tx = null, $extra_values = array())
public function parseProductSupplierExpression($product_id, $expression, $quantity = null, $tva_tx = null, $extra_values = array())
{
//Accessible values by expressions
$expression_values = array(
@ -212,20 +212,20 @@ class PriceParser
}
//Parse the expression and return the price
return $this->parse_expression($expression_values, $expression);
return $this->parseExpression($expression_values, $expression);
}
/**
* Calculates supplier product price based on product id and expression id
*
* @param int $product The Product id to get information
* @param int $product_id The Product id to get information
* @param int $expression_id The expression to parse
* @param int $quantity Min quantity
* @param int $tva_tx VAT rate
* @param array $extra_values Any aditional values for expression
* @return int > 0 if OK, < 1 if KO
*/
public function parse_product_supplier($product_id, $expression_id, $quantity = null, $tva_tx = null, $extra_values = array())
public function parseProductSupplier($product_id, $expression_id, $quantity = null, $tva_tx = null, $extra_values = array())
{
$price_expression = new PriceExpression($this->db);
$res = $price_expression->fetch($expression_id);
@ -235,6 +235,6 @@ class PriceParser
}
//Parse the expression and return the price
return $this->parse_product_supplier_expression($product_id, $price_expression->expression, $quantity, $tva_tx, $extra_values);
return $this->parseProductSupplierExpression($product_id, $price_expression->expression, $quantity, $tva_tx, $extra_values);
}
}

View File

@ -1185,7 +1185,7 @@ class Product extends CommonObject
{
if (!empty($obj->fk_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parse_product_supplier($obj->fk_product, $obj->fk_price_expression, $obj->quantity, $obj->tva_tx);
$price_result = $priceparser->parseProductSupplier($obj->fk_product, $obj->fk_price_expression, $obj->quantity, $obj->tva_tx);
if ($price_result >= 0) {
$obj->price = $price_result;
}
@ -1218,7 +1218,7 @@ class Product extends CommonObject
{
if (!empty($obj->fk_price_expression)) {
$priceparser = new PriceParser($this->db);
$price_result = $priceparser->parse_product_supplier($obj->fk_product, $obj->fk_price_expression, $obj->quantity, $obj->tva_tx);
$price_result = $priceparser->parseProductSupplier($obj->fk_product, $obj->fk_price_expression, $obj->quantity, $obj->tva_tx);
if ($result >= 0) {
$obj->price = $price_result;
}

View File

@ -70,9 +70,9 @@ if ($action == 'add')
{
//Check the expression validity by parsing it
$priceparser = new PriceParser($db);
$price_result = $priceparser->parse_product_supplier_expression($id, $expression, 0, 0);
$price_result = $priceparser->parseProductSupplierExpression($id, $expression, 0, 0);
if ($price_result < 0) { //Expression is not valid
setEventMessage($priceparser->translated_error(), 'errors');
setEventMessage($priceparser->translatedError(), 'errors');
}
else
{
@ -109,9 +109,9 @@ if ($action == 'update')
{
//Check the expression validity by parsing it
$priceparser = new PriceParser($db);
$price_result = $priceparser->parse_product_supplier_expression($id, $expression, 0, 0);
$price_result = $priceparser->parseProductSupplierExpression($id, $expression, 0, 0);
if ($price_result < 0) { //Expression is not valid
setEventMessage($priceparser->translated_error(), 'errors');
setEventMessage($priceparser->translatedError(), 'errors');
}
else
{

View File

@ -189,10 +189,10 @@ if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel"))
if ($price_expression != 'NULL') {
//Check the expression validity by parsing it
$priceparser = new PriceParser($db);
$price_result = $priceparser->parse_product_supplier($id, $price_expression, $quantity, $tva_tx);
$price_result = $priceparser->parseProductSupplier($id, $price_expression, $quantity, $tva_tx);
if ($price_result < 0) { //Expression is not valid
$error++;
setEventMessage($priceparser->translated_error(), 'errors');
setEventMessage($priceparser->translatedError(), 'errors');
}
}
if (! $error && ! empty($conf->dynamicprices->enabled)) {