Skip to content

Commit

Permalink
Merge pull request #457 from atm-maxime/mko559
Browse files Browse the repository at this point in the history
Task # 559 : price by quantity
  • Loading branch information
hregis committed Dec 5, 2012
2 parents f1b4d60 + 954a578 commit 644a05f
Show file tree
Hide file tree
Showing 12 changed files with 707 additions and 156 deletions.
356 changes: 225 additions & 131 deletions htdocs/core/class/html.form.class.php

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions htdocs/core/tpl/objectline_add.tpl.php
Expand Up @@ -79,7 +79,9 @@
'price_ht' => 'price_ht',
'origin_price_ht_cache' => 'price_ht',
'origin_tva_tx_cache' => 'tva_tx',
'origin_price_ttc_cache' => 'price_ttc'
'origin_price_ttc_cache' => 'price_ttc',
'qty' => 'qty',
'remise_percent' => 'discount'
),
'update_textarea' => array(
'product_desc' => 'desc'
Expand Down Expand Up @@ -158,7 +160,7 @@
<input type="hidden" id="origin_price_ttc_cache" name="origin_price_ttc_cache" value="" />
</td>
<td align="right"><input type="text" size="3" id="qty" name="qty" value="<?php echo (GETPOST('qty')?GETPOST('qty'):1); ?>"></td>
<td align="right" nowrap="nowrap"><input type="text" size="1" value="<?php echo $buyer->remise_client; ?>" name="remise_percent">%</td>
<td align="right" nowrap="nowrap"><input type="text" size="1" value="<?php echo $buyer->remise_client; ?>" id="remise_percent" name="remise_percent">%</td>
<?php
$colspan = 4;
if (! empty($conf->margin->enabled)) {
Expand Down Expand Up @@ -225,7 +227,9 @@
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php', {
'action': 'fetch',
'id': $(this).val(),
'price_level': <?php echo empty($buyer->price_level)?1:$buyer->price_level; ?>},
'price_level': <?php echo empty($buyer->price_level)?1:$buyer->price_level; ?>,
'pbq': $("option:selected", this).attr('pbq')
},
function(data) {
if (typeof data != 'undefined') {
$('#product_ref').val(data.ref);
Expand All @@ -237,6 +241,8 @@ function(data) {
$('#origin_tva_tx_cache').val(data.tva_tx);
$('#select_type').val(data.type).attr('disabled','disabled').trigger('change');
//$('#price_base_type_area').show();
$('#qty').val(data.qty);
$('#remise_percent').val(data.discount);

if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined" && CKEDITOR.instances['product_desc'] != "undefined") {
CKEDITOR.instances['product_desc'].setData(data.desc).focus();
Expand Down
29 changes: 23 additions & 6 deletions htdocs/install/mysql/migration/3.2.0-3.3.0.sql
Expand Up @@ -801,6 +801,28 @@ ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref (entity, fk_parent,
ALTER TABLE llx_categorie ADD INDEX idx_categorie_type (type);
ALTER TABLE llx_categorie ADD INDEX idx_categorie_label (label);

-- [ task #559 ] Price by quantity management
CREATE TABLE llx_product_price_by_qty
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_product_price integer NOT NULL,
date_price timestamp,
price double (24,8) DEFAULT 0,
price_ttc double (24,8) DEFAULT 0,
qty_min real DEFAULT 0
)ENGINE=innodb;

ALTER TABLE llx_product_price ADD price_by_qty INT NOT NULL DEFAULT 0;

ALTER TABLE llx_product_price_by_qty ADD UNIQUE INDEX uk_product_price_by_qty_level (fk_product_price, qty_min);

ALTER TABLE llx_product_price_by_qty ADD INDEX idx_product_price_by_qty_fk_product_price (fk_product_price);

ALTER TABLE llx_product_price_by_qty ADD CONSTRAINT fk_product_price_by_qty_fk_product_price FOREIGN KEY (fk_product_price) REFERENCES llx_product_price (rowid);

ALTER TABLE `llx_product_price_by_qty` ADD `remise_percent` DOUBLE NOT NULL DEFAULT '0' AFTER `price_ttc` ,
ADD `remise` DOUBLE NOT NULL DEFAULT '0' AFTER `remise_percent`;

-- Change index name to be compliant with SQL standard, index name must be unique in database schema
ALTER TABLE llx_c_actioncomm DROP INDEX code, ADD UNIQUE uk_c_actioncomm (code);
ALTER TABLE llx_c_civilite DROP INDEX code, ADD UNIQUE uk_c_civilite (code);
Expand All @@ -811,13 +833,11 @@ ALTER TABLE llx_c_typent DROP INDEX code, ADD UNIQUE uk_c_typent (code);
ALTER TABLE llx_c_effectif DROP INDEX code, ADD UNIQUE uk_c_effectif (code);
ALTER TABLE llx_c_paiement DROP INDEX code, ADD UNIQUE uk_c_paiement (code);


delete from llx_c_actioncomm where id = 40;
INSERT INTO llx_c_actioncomm (id, code, type, libelle, module, position) values ( 40, 'AC_OTH_AUTO','systemauto', 'Other (automatically inserted events)' ,NULL, 20);
UPDATE llx_c_actioncomm SET libelle = 'Other (manually inserted events)' WHERE code = 'AC_OTH';
UPDATE llx_c_actioncomm SET active = 0 WHERE code in ('AC_PROP', 'AC_COM', 'AC_FAC', 'AC_SHIP', 'AC_SUP_ORD', 'AC_SUP_INV');


-- Update dictionnary of table llx_c_paper_format
DELETE FROM llx_c_paper_format;

Expand Down Expand Up @@ -850,8 +870,6 @@ INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active)
-- increase field size
ALTER TABLE llx_bank_account MODIFY COLUMN code_banque varchar(8);



create table llx_user_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
Expand All @@ -860,5 +878,4 @@ create table llx_user_extrafields
import_key varchar(14) -- import key
)ENGINE=innodb;

ALTER TABLE llx_user_extrafields ADD INDEX idx_user_extrafields (fk_object);

ALTER TABLE llx_user_extrafields ADD INDEX idx_user_extrafields (fk_object);
2 changes: 2 additions & 0 deletions htdocs/install/mysql/tables/llx_product_fournisseur_price.sql
Expand Up @@ -31,6 +31,8 @@ create table llx_product_fournisseur_price
fk_availability integer,
price double(24,8) DEFAULT 0,
quantity double,
remise_percent double NOT NULL DEFAULT 0,
remise double NOT NULL DEFAULT 0,
unitprice double(24,8) DEFAULT 0,
charges double(24,8) DEFAULT 0,
unitcharges double(24,8) DEFAULT 0,
Expand Down
3 changes: 2 additions & 1 deletion htdocs/install/mysql/tables/llx_product_price.sql
Expand Up @@ -36,6 +36,7 @@ create table llx_product_price
localtax1_tx double(6,3) DEFAULT 0,
localtax2_tx double(6,3) DEFAULT 0,
fk_user_author integer,
tosell tinyint DEFAULT 1
tosell tinyint DEFAULT 1,
price_by_qty integer NOT NULL DEFAULT 0
)ENGINE=innodb;

26 changes: 26 additions & 0 deletions htdocs/install/mysql/tables/llx_product_price_by_qty.key.sql
@@ -0,0 +1,26 @@
-- ============================================================================
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2012 Maxime Kohlhaas <maxime.kohlhaas@atm-consulting.fr>
--
-- 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
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================

ALTER TABLE llx_product_price_by_qty ADD UNIQUE INDEX uk_product_price_by_qty_level (fk_product_price, quantity);

ALTER TABLE llx_product_price_by_qty ADD INDEX idx_product_price_by_qty_fk_product_price (fk_product_price);

ALTER TABLE llx_product_price_by_qty ADD CONSTRAINT fk_product_price_by_qty_fk_product_price FOREIGN KEY (fk_product_price) REFERENCES llx_product_price (rowid);
32 changes: 32 additions & 0 deletions htdocs/install/mysql/tables/llx_product_price_by_qty.sql
@@ -0,0 +1,32 @@
-- ============================================================================
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2012 Maxime Kohlhaas <maxime.kohlhaas@atm-consulting.fr>
--
-- 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
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================

create table llx_product_price_by_qty
(
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
fk_product_price integer NOT NULL,
date_price timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
price double(24,8) DEFAULT 0,
quantity double DEFAULT NULL,
remise_percent double NOT NULL DEFAULT 0,
remise double NOT NULL DEFAULT 0,
unitprice double(24,8) DEFAULT 0
)ENGINE=innodb;
4 changes: 3 additions & 1 deletion htdocs/langs/en_US/products.lang
Expand Up @@ -180,4 +180,6 @@ AddThisServiceCard=Create service card
HelpAddThisServiceCard=This option allows you to create or clone a service if it does not exist.
CurrentProductPrice=Current price
AlwaysUseNewPrice=Always use current price of product/service
AlwaysUseFixedPrice=Use the fixed price
AlwaysUseFixedPrice=Use the fixed price
PriceByQuantity=Price by quantity
PriceByQuantityRange=Quantity range
4 changes: 3 additions & 1 deletion htdocs/langs/fr_FR/products.lang
Expand Up @@ -180,4 +180,6 @@ AddThisServiceCard=Créer fiche service
HelpAddThisServiceCard=Cette option permet de créer ou de cloner une fiche service si elle n'existe pas.
CurrentProductPrice=Prix actuel
AlwaysUseNewPrice=Toujours utiliser le prix du jour
AlwaysUseFixedPrice=Utiliser le prix fixé
AlwaysUseFixedPrice=Utiliser le prix fixé
PriceByQuantity=Prix par quantité
PriceByQuantityRange=Grille de quantités
37 changes: 32 additions & 5 deletions htdocs/product/ajax/products.php
Expand Up @@ -38,9 +38,10 @@
$mode=GETPOST('mode','int');
$status=((GETPOST('status','int') >= 0) ? GETPOST('status','int') : -1);
$outjson=(GETPOST('outjson','int') ? GETPOST('outjson','int') : 0);
$pricelevel=GETPOST('price_level','int');
$price_level=GETPOST('price_level','int');
$action=GETPOST('action', 'alpha');
$id=GETPOST('id', 'int');
$price_by_qty_rowid=GETPOST('pbq', 'int');

/*
* View
Expand All @@ -65,11 +66,37 @@
$outlabel=$object->label;
$outdesc=$object->description;
$outtype=$object->type;
$outqty=1;
$outdiscount=0;

$found=false;

// Price by qty
if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1) // If we need a particular price related to qty
{
$sql = "SELECT price, unitprice, quantity, remise_percent";
$sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty ";
$sql.= " WHERE rowid=".$price_by_qty_rowid."";

$result = $db->query($sql);
if ($result)
{
$objp = $db->fetch_object($result);
if ($objp)
{
$found=true;
$outprice_ht=price($objp->unitprice);
$outprice_ttc=price($objp->unitprice * (1 + ($object->tva_tx / 100)));
$outpricebasetype=$object->price_base_type;
$outtva_tx=$object->tva_tx;
$outqty=$objp->quantity;
$outdiscount=$objp->remise_percent;
}
}
}

// Multiprice
if (isset($price_level) && $price_level >= 1) // If we need a particular price level (from 1 to 6)
if (! $found && isset($price_level) && $price_level >= 1) // If we need a particular price level (from 1 to 6)
{
$sql = "SELECT price, price_ttc, price_base_type, tva_tx";
$sql.= " FROM ".MAIN_DB_PREFIX."product_price ";
Expand All @@ -78,10 +105,10 @@
$sql.= " ORDER BY date_price";
$sql.= " DESC LIMIT 1";

$result = $this->db->query($sql);
$result = $db->query($sql);
if ($result)
{
$objp = $this->db->fetch_object($result);
$objp = $db->fetch_object($result);
if ($objp)
{
$found=true;
Expand All @@ -101,7 +128,7 @@
$outtva_tx=$object->tva_tx;
}

$outjson = array('ref'=>$outref, 'label'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx);
$outjson = array('ref'=>$outref, 'label'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype, 'tva_tx'=>$outtva_tx, 'qty'=>$outqty, 'discount'=>$outdiscount);
}

echo json_encode($outjson);
Expand Down

0 comments on commit 644a05f

Please sign in to comment.