diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index eee4d529751..f74f9d777e8 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -436,7 +436,7 @@ if ($object->id > 0)
// Multiprice level
- if (! empty($conf->global->PRODUIT_MULTIPRICES))
+ if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
print '
';
print '
';
diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index 004b32a83fc..a2f4dcd1f5d 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -848,7 +848,28 @@ if (empty($reshook))
// If price per quantity and customer
elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
- // TODO Same than PRODUIT_CUSTOMER_PRICES_BY_QTY but using $object->thirdparty->price_level
+ if ($prod->prices_by_qty[$object->thirdparty->price_level]) // yes, this product has some prices per quantity
+ {
+ // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
+ $pqp = GETPOST('pbq','int');
+
+ // Search price into product_price_by_qty from $prod->id
+ foreach($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray)
+ {
+ if ($priceforthequantityarray['rowid'] != $pqp) continue;
+ // We found the price
+ if ($priceforthequantityarray['price_base_type'] == 'HT')
+ {
+ $pu_ht = $priceforthequantityarray['unitprice'];
+ }
+ else
+ {
+ $pu_ttc = $priceforthequantityarray['unitprice'];
+ }
+ // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
+ break;
+ }
+ }
}
$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index 76a290a79cd..075f174e355 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -797,7 +797,27 @@ if (empty($reshook))
// If price per quantity and customer
elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
- // TODO Same than PRODUIT_CUSTOMER_PRICES_BY_QTY but using $object->thirdparty->price_level
+ if ($prod->prices_by_qty[$object->thirdparty->price_level]) // yes, this product has some prices per quantity
+ {
+ // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
+ $pqp = GETPOST('pbq','int');
+ // Search price into product_price_by_qty from $prod->id
+ foreach($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray)
+ {
+ if ($priceforthequantityarray['rowid'] != $pqp) continue;
+ // We found the price
+ if ($priceforthequantityarray['price_base_type'] == 'HT')
+ {
+ $pu_ht = $priceforthequantityarray['unitprice'];
+ }
+ else
+ {
+ $pu_ttc = $priceforthequantityarray['unitprice'];
+ }
+ // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
+ break;
+ }
+ }
}
$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
@@ -1018,8 +1038,8 @@ if (empty($reshook))
$type = $product->type;
$price_min = $product->price_min;
- if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
- $price_min = $product->multiprices_min [$object->thirdparty->price_level];
+ if ((! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && ! empty($object->thirdparty->price_level))
+ $price_min = $product->multiprices_min[$object->thirdparty->price_level];
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index dbce9c2e76d..a9769c04442 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -1729,7 +1729,28 @@ if (empty($reshook))
// If price per quantity and customer
elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
- // TODO Same than PRODUIT_CUSTOMER_PRICES_BY_QTY but using $object->thirdparty->price_level
+ if ($prod->prices_by_qty[$object->thirdparty->price_level]) // yes, this product has some prices per quantity
+ {
+ // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
+ $pqp = GETPOST('pbq','int');
+
+ // Search price into product_price_by_qty from $prod->id
+ foreach($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray)
+ {
+ if ($priceforthequantityarray['rowid'] != $pqp) continue;
+ // We found the price
+ if ($priceforthequantityarray['price_base_type'] == 'HT')
+ {
+ $pu_ht = $priceforthequantityarray['unitprice'];
+ }
+ else
+ {
+ $pu_ttc = $priceforthequantityarray['unitprice'];
+ }
+ // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
+ break;
+ }
+ }
}
$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
@@ -1978,7 +1999,7 @@ if (empty($reshook))
$type = $product->type;
$price_min = $product->price_min;
- if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
+ if ((! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && ! empty($object->thirdparty->price_level))
$price_min = $product->multiprices_min [$object->thirdparty->price_level];
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index c02ada175fd..dddb5201f06 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -1942,7 +1942,7 @@ class Form
$selectFields.= ", label_translated";
}
// Price by quantity
- if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
+ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
$sql.= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid";
if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
@@ -2063,7 +2063,7 @@ class Form
$optJson = array();
$objp = $this->db->fetch_object($result);
- if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1)
+ if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1)
{ // Price by quantity will return many prices for the same product
$sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type";
$sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
@@ -2212,7 +2212,8 @@ class Form
$found=0;
// Multiprice
- if (empty($hidepriceinlabel) && $price_level >= 1 && $conf->global->PRODUIT_MULTIPRICES) // If we need a particular price level (from 1 to 6)
+ // If we need a particular price level (from 1 to 6)
+ if (empty($hidepriceinlabel) && $price_level >= 1 && (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)))
{
$sql = "SELECT price, price_ttc, price_base_type, tva_tx";
$sql.= " FROM ".MAIN_DB_PREFIX."product_price";
@@ -2253,7 +2254,7 @@ class Form
}
// Price by quantity
- if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
+ if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1 && (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)))
{
$found = 1;
$outqty=$objp->quantity;
diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php
index 3ff76dd1f82..63f10296212 100644
--- a/htdocs/product/admin/product.php
+++ b/htdocs/product/admin/product.php
@@ -541,7 +541,7 @@ print '
'."\n";
*/
$rowspan = 4;
-if (! empty($conf->global->PRODUIT_MULTIPRICES)) $rowspan++;
+if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $rowspan++;
if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) $rowspan++;
if (! empty($conf->global->MAIN_MULTILANGS)) $rowspan++;
@@ -553,7 +553,7 @@ $current_rule = 'PRODUCT_PRICE_UNIQ';
if (!empty($conf->global->PRODUIT_MULTIPRICES)) $current_rule='PRODUIT_MULTIPRICES';
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) $current_rule='PRODUIT_CUSTOMER_PRICES_BY_QTY';
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $current_rule='PRODUIT_CUSTOMER_PRICES';
-if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) && (!empty($conf->global->PRODUIT_MULTIPRICES))) $current_rule='PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES';
+if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $current_rule='PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES';
print $form->selectarray("princingrule",$select_pricing_rules,$current_rule);
if ( empty($conf->multicompany->enabled))
{
@@ -566,7 +566,7 @@ print '';
// multiprix nombre de prix a proposer
-if (! empty($conf->global->PRODUIT_MULTIPRICES))
+if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
print '
';
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 2f36fd59035..291182ba475 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -1665,7 +1665,7 @@ class Product extends CommonObject
// If multiprices are enabled, then we check if the current product is subject to price autogeneration
// Price will be modified ONLY when the first one is the one that is being modified
- if (!empty($conf->global->PRODUIT_MULTIPRICES) && !$ignore_autogen && $this->price_autogen && ($level == 1))
+ if ((!empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !$ignore_autogen && $this->price_autogen && ($level == 1))
{
return $this->generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpbq);
}
@@ -2088,7 +2088,71 @@ class Product extends CommonObject
}
else if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // prices per customer and quantity
{
- // Not yet implemented
+ for ($i=1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++)
+ {
+ $sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
+ $sql.= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product_price";
+ $sql.= " WHERE entity IN (".getEntity('productprice').")";
+ $sql.= " AND price_level=".$i;
+ $sql.= " AND fk_product = ".$this->id;
+ $sql.= " ORDER BY date_price DESC, rowid DESC";
+ $sql.= " LIMIT 1";
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $result = $this->db->fetch_array($resql);
+
+ $this->multiprices[$i]=$result["price"];
+ $this->multiprices_ttc[$i]=$result["price_ttc"];
+ $this->multiprices_min[$i]=$result["price_min"];
+ $this->multiprices_min_ttc[$i]=$result["price_min_ttc"];
+ $this->multiprices_base_type[$i]=$result["price_base_type"];
+ // Next two fields are used only if PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL is on
+ $this->multiprices_tva_tx[$i]=$result["tva_tx"]; // TODO Add ' ('.$result['default_vat_code'].')'
+ $this->multiprices_recuperableonly[$i]=$result["recuperableonly"];
+
+ // Price by quantity
+ $this->prices_by_qty[$i]=$result["price_by_qty"];
+ $this->prices_by_qty_id[$i]=$result["rowid"];
+ // Récuperation de la liste des prix selon qty si flag positionné
+ if ($this->prices_by_qty[$i] == 1)
+ {
+ $sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type";
+ $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
+ $sql.= " WHERE fk_product_price = ".$this->prices_by_qty_id[$i];
+ $sql.= " ORDER BY quantity ASC";
+ $resultat=array();
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $ii=0;
+ while ($result= $this->db->fetch_array($resql)) {
+ $resultat[$ii]=array();
+ $resultat[$ii]["rowid"]=$result["rowid"];
+ $resultat[$ii]["price"]= $result["price"];
+ $resultat[$ii]["unitprice"]= $result["unitprice"];
+ $resultat[$ii]["quantity"]= $result["quantity"];
+ $resultat[$ii]["remise_percent"]= $result["remise_percent"];
+ $resultat[$ii]["remise"]= $result["remise"]; // deprecated
+ $resultat[$ii]["price_base_type"]= $result["price_base_type"];
+ $ii++;
+ }
+ $this->prices_by_qty_list[$i]=$resultat;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
}
if (!empty($conf->dynamicprices->enabled) && !empty($this->fk_price_expression) && empty($ignore_expression))
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index 61b6316ca01..672eede5552 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -72,7 +72,7 @@ if ($id > 0 || ! empty($ref))
}
// Clean param
-if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
+if ((! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('productpricecard','globalcard'));
@@ -202,7 +202,7 @@ if (empty($reshook))
}
// Multiprices
- if (! $error && ! empty($conf->global->PRODUIT_MULTIPRICES)) {
+ if (! $error && (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
$newprice = GETPOST('price', 'array');
$newprice_min = GETPOST('price_min', 'array');
@@ -717,7 +717,7 @@ print '';
print '
';
// Price per customer segment/level
-if (! empty($conf->global->PRODUIT_MULTIPRICES))
+if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))
{
// Price and min price are variable (depends on level of company).
if (! empty($socid))
@@ -880,10 +880,11 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
print '';
// Price by quantity
- if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) // TODO Fix the form included into a tr instead of a td
+ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // TODO Fix the form included into a tr instead of a td
{
print '
';
@@ -935,9 +936,9 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
print ''; // id in product_price
print '
';
print '
';
- print '
' . $object->price_base_type . '
';
- // print '
';
- print '
%
';
+ print '
' . $object->price_base_type . '
';
+ print '
';
+ print '
%
';
print '
';
print '
';
print '';
@@ -991,7 +992,7 @@ else
print '';
// Price by quantity
- if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) // TODO Fix the form inside tr instead of td
+ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) // TODO Fix the form inside tr instead of td
{
print '