diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 260f4ea73414e..9936beaae5ff2 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -530,7 +530,7 @@ // Multiprice level - if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { + if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { print '
';
print $langs->trans("PriceLevel");
diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index d6a78f296c735..18e118a614e78 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -1137,8 +1137,51 @@
$price_min_ttc = $prod->price_min_ttc;
$price_base_type = $prod->price_base_type;
- // If price per segment
- if (getDolGlobalString('PRODUIT_MULTIPRICES') && $object->thirdparty->price_level) {
+ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
+ // If price per customer
+ require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
+ $prodcustprice = new ProductCustomerPrice($db);
+ $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
+
+ // If a price per customer exist
+ $pricebycustomerexist = false;
+ $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
+ if ($result) {
+ // If there is some prices specific to the customer
+ if (count($prodcustprice->lines) > 0) {
+ $pricebycustomerexist = true;
+ $pu_ht = price($prodcustprice->lines[0]->price);
+ $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
+ $price_min = price($prodcustprice->lines[0]->price_min);
+ $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
+ $price_base_type = $prodcustprice->lines[0]->price_base_type;
+ /*$tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
+ if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
+ $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
+ }
+ $tva_npr = $prodcustprice->lines[0]->recuperableonly;
+ if (empty($tva_tx)) {
+ $tva_npr = 0;
+ }*/
+ }
+ }
+
+ if ( !$pricebycustomerexist && $object->thirdparty->price_level) { // If price per segment
+ $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
+ $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
+ $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
+ $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
+ if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility
+ if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
+ $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
+ }
+ if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
+ $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
+ }
+ }
+ }
+ } elseif (getDolGlobalString('PRODUIT_MULTIPRICES') && $object->thirdparty->price_level) { // If price per segment
$pu_ht = $prod->multiprices[$object->thirdparty->price_level];
$pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
$price_min = $prod->multiprices_min[$object->thirdparty->price_level];
@@ -1549,11 +1592,11 @@
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
$price_min = $product->price_min;
- if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
+ if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
}
$price_min_ttc = $product->price_min_ttc;
- if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
+ if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
$price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
}
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index d314b3b046865..fa7e4d46e8668 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -839,6 +839,54 @@
$price_min_ttc = $prod->price_min_ttc;
$price_base_type = $prod->price_base_type;
+ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
+ // If price per customer
+ require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
+
+ $prodcustprice = new ProductCustomerPrice($db);
+
+ $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
+
+ // If a price per customer exist
+ $pricebycustomerexist = false;
+ $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
+ if ($result >= 0) {
+ if (count($prodcustprice->lines) > 0) {
+ $pricebycustomerexist = true;
+ $pu_ht = price($prodcustprice->lines[0]->price);
+ $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
+ $price_min = price($prodcustprice->lines[0]->price_min);
+ $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
+ $price_base_type = $prodcustprice->lines[0]->price_base_type;
+ $tva_tx = $prodcustprice->lines[0]->tva_tx;
+ if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
+ $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
+ }
+ $tva_npr = $prodcustprice->lines[0]->recuperableonly;
+ if (empty($tva_tx)) {
+ $tva_npr = 0;
+ }
+ }
+ } else {
+ setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
+ }
+
+ if ( !$pricebycustomerexist && !empty($object->thirdparty->price_level)) { //// If price per segment
+ $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
+ $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
+ $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
+ $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
+ if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility
+ if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
+ $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
+ }
+ if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
+ $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
+ }
+ }
+ }
+ }
// If price per segment
if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
$pu_ht = $prod->multiprices[$object->thirdparty->price_level];
@@ -1241,11 +1289,11 @@
$type = $product->type;
$price_min = $product->price_min;
- if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
+ if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
}
$price_min_ttc = $product->price_min_ttc;
- if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
+ if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
$price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
}
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index c14310395da47..9cd0807bc4330 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1893,7 +1893,7 @@ public function fetch_thirdparty($force_thirdparty_id = 0)
$this->thirdparty = $thirdparty;
// Use first price level if level not defined for third party
- if (getDolGlobalString('PRODUIT_MULTIPRICES') && empty($this->thirdparty->price_level)) {
+ if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && empty($this->thirdparty->price_level)) {
$this->thirdparty->price_level = 1;
}
diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php
index e69628e64e095..961fa9f686e7d 100644
--- a/htdocs/core/class/conf.class.php
+++ b/htdocs/core/class/conf.class.php
@@ -1041,7 +1041,7 @@ public function setValues($db)
$this->holiday->approve->warning_delay = (isset($this->global->MAIN_DELAY_HOLIDAYS) ? (int) $this->global->MAIN_DELAY_HOLIDAYS : 0) * 86400;
}
- if (!empty($this->global->PRODUIT_MULTIPRICES) && empty($this->global->PRODUIT_MULTIPRICES_LIMIT)) {
+ if ((!empty($this->global->PRODUIT_MULTIPRICES) || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && empty($this->global->PRODUIT_MULTIPRICES_LIMIT)) {
$this->global->PRODUIT_MULTIPRICES_LIMIT = 5;
}
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 3c9266c1fdc14..b165a237df166 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -2949,7 +2949,7 @@ public function select_produits_list($selected = 0, $htmlname = 'productid', $fi
}
//Price by customer
- if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && !empty($socid)) {
+ if ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($socid)) {
$sql .= ', pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
$sql .= ' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx, pcp.default_vat_code as custdefault_vat_code, pcp.ref_customer as custref';
$selectFields .= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx, custdefault_vat_code, custref";
@@ -3007,7 +3007,7 @@ public function select_produits_list($selected = 0, $htmlname = 'productid', $fi
}
//Price by customer
- if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && !empty($socid)) {
+ if ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($socid)) {
$sql .= " LEFT JOIN " . $this->db->prefix() . "product_customer_price as pcp ON pcp.fk_soc=" . ((int) $socid) . " AND pcp.fk_product=p.rowid";
}
// Units
@@ -3087,7 +3087,7 @@ public function select_produits_list($selected = 0, $htmlname = 'productid', $fi
if (getDolGlobalInt('MAIN_MULTILANGS')) {
$sql .= " OR pl.label LIKE '" . $this->db->escape($prefix . $crit) . "%'";
}
- if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && !empty($socid)) {
+ if ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($socid)) {
$sql .= " OR pcp.ref_customer LIKE '" . $this->db->escape($prefix . $crit) . "%'";
}
if (getDolGlobalString('PRODUCT_AJAX_SEARCH_ON_DESCRIPTION')) {
@@ -3223,7 +3223,9 @@ public function select_produits_list($selected = 0, $htmlname = 'productid', $fi
$objp->price_ttc = price2num($objp->price_ttc, 'MU');
}
}
-
+ if (getDolGlobalInt('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($objp->custprice)) {
+ $price_level = '';
+ }
$this->constructProductListOption($objp, $opt, $optJson, $price_level, $selected, $hidepriceinlabel, $filterkey);
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
@@ -3445,7 +3447,7 @@ protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_l
$labeltoshowprice = '';
$labeltoshowhtmlprice = '';
// If we need a particular price level (from 1 to n)
- if (empty($hidepriceinlabel) && $price_level >= 1 && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
+ if (empty($hidepriceinlabel) && $price_level >= 1 && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES'))) {
$sql = "SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code";
$sql .= " FROM " . $this->db->prefix() . "product_price";
$sql .= " WHERE fk_product = " . ((int) $objp->rowid);
@@ -3516,7 +3518,7 @@ protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_l
}
// Price by customer
- if (empty($hidepriceinlabel) && getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
+ if (empty($hidepriceinlabel) && (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES'))) {
if (!empty($objp->idprodcustprice)) {
$found = 1;
diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php
index 076c4de211748..209fe840a4c1d 100644
--- a/htdocs/core/lib/company.lib.php
+++ b/htdocs/core/lib/company.lib.php
@@ -121,7 +121,7 @@ function societe_prepare_head(Societe $object)
$head[$h][2] = 'customer';
$h++;
- if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
+ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
$langs->load("products");
// price
$head[$h][0] = DOL_URL_ROOT.'/societe/price.php?socid='.$object->id;
diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php
index ae6a8e40d997b..fc6e704ce7406 100644
--- a/htdocs/core/lib/pdf.lib.php
+++ b/htdocs/core/lib/pdf.lib.php
@@ -1508,7 +1508,7 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0,
include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$prodser = new Product($db);
- if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
+ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
include_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
}
}
@@ -1687,7 +1687,7 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0,
} else {
$ref_prodserv = $prodser->ref; // Show local ref only
- if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
+ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) {
$productCustomerPriceStatic = new ProductCustomerPrice($db);
$filter = array('fk_product' => $idprod, 'fk_soc' => $object->socid);
diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang
index 7181b24d39b76..0b8825cf058b3 100644
--- a/htdocs/langs/en_US/products.lang
+++ b/htdocs/langs/en_US/products.lang
@@ -437,3 +437,4 @@ AllowStockMovementVariantParentHelp=By default, a parent of a variant is a virtu
ConfirmSetToDraftInventory=Are you sure you want to go back to Draft status? The quantities currently set in the inventory will be reset. WarningLineProductNotToSell=Product or service "%s" is not to sell and was cloned PriceLabel=Price label +PriceByCustomeAndMultiPricesAbility=Different prices for each customer + Multiple price segments per product/service (each customer is in one price segment) diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 3a1c8f85c41fe..dc4f4dce330d3 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -437,3 +437,4 @@ AllowStockMovementVariantParentHelp=Par défaut, un parent d'une variante est un ConfirmSetToDraftInventory=Êtes-vous sûr de vouloir revenir à l'état de brouillon ? Les quantités actuellement définies dans l'inventaire seront réinitialisées. WarningLineProductNotToSell=Le produit ou le service "%s" n'est pas à vendre et a été cloné. PriceLabel=Libellé du prix +PriceByCustomeAndMultiPricesAbility=Prix différents pour chaque client + Plusieurs niveaux de prix par produit/service (chaque client est dans un et un seul niveau) diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 7608a84cbe10b..c3f56c1e2b982 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -59,6 +59,7 @@ 'PRODUCT_PRICE_UNIQ' => $langs->trans('PriceCatalogue'), // Unique price 'PRODUIT_MULTIPRICES' => $langs->trans('MultiPricesAbility'), // Several prices according to a customer level 'PRODUIT_CUSTOMER_PRICES' => $langs->trans('PriceByCustomer'), // Different price for each customer + 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES'=>$langs->trans('PriceByCustomeAndMultiPricesAbility'), // Different price for each customer and several prices according to a customer level ); $keyforparam = 'PRODUIT_CUSTOMER_PRICES_BY_QTY'; if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 1 || getDolGlobalString($keyforparam)) { @@ -113,6 +114,7 @@ $res = dolibarr_set_const($db, 'PRODUIT_MULTIPRICES', 0, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES_BY_QTY', 0, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES', 0, 'chaine', 0, '', $conf->entity); + $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES', 0, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'PRODUCT_PRICE_UNIQ', 1, 'chaine', 0, '', $conf->entity); } else { $multirule = explode('&', $princingrules); @@ -587,6 +589,9 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { $current_rule = 'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'; } +if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { + $current_rule = 'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES'; +} print $form->selectarray("princingrule", $select_pricing_rules, $current_rule, 0, 0, 0, '', 1, 0, 0, '', 'maxwidth400', 1); print ' | ';
print '