From 61ef863f7cce6eda7447a2d1fa3920ee4895520c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9lina=20JOUM?= Date: Thu, 19 Sep 2024 16:46:24 +0200 Subject: [PATCH 1/8] NEW: customer price and level price together --- htdocs/comm/card.php | 2 +- htdocs/comm/propal/card.php | 45 +- htdocs/commande/card.php | 49 +- htdocs/commande/class/commande.class.php | 2 +- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/class/conf.class.php | 2 +- htdocs/core/class/html.form.class.php | 10 +- htdocs/core/lib/company.lib.php | 2 +- htdocs/core/lib/pdf.lib.php | 4 +- htdocs/product/admin/product.php | 5 + htdocs/product/ajax/products.php | 8 +- htdocs/product/class/product.class.php | 56 +- htdocs/product/price.php | 806 ++++++++++++----------- htdocs/societe/class/societe.class.php | 4 +- htdocs/societe/list.php | 4 +- htdocs/societe/price.php | 4 +- 16 files changed, 581 insertions(+), 424 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 96b99cc7f0055..81ec074de8be2 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -529,7 +529,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 ''; print ''; diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 7cca33a775f31..a0c379f078a81 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -112,7 +112,7 @@ if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { $needchangeaccordingtothirdparty = 1; } - 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')) { $needchangeaccordingtothirdparty = 1; } if ($needchangeaccordingtothirdparty) { @@ -135,7 +135,7 @@ } //Set price level according to thirdparty - 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')) { $price_level = $thirdpartytemp->price_level; } } @@ -167,7 +167,7 @@ } // Multiprice (1 price per level) - if (!$found && isset($price_level) && $price_level >= 1 && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) { // If we need a particular price level (from 1 to 6) + if (!$found && isset($price_level) && $price_level >= 1 && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES'))) { // If we need a particular price level (from 1 to 6) $sql = "SELECT price, price_ttc, price_base_type,"; $sql .= " tva_tx, default_vat_code"; // Vat rate and code will be used if PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL is on. $sql .= " FROM ".MAIN_DB_PREFIX."product_price "; @@ -200,7 +200,7 @@ } // Price by customer - if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && !empty($socid)) { + if ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($socid)) { require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; $prodcustprice = new ProductCustomerPrice($db); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b526c465d7904..30777be2cbb49 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2276,8 +2276,54 @@ public function getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp = 0) $price_min = $this->price_min; $price_base_type = $this->price_base_type; - // If price per segment - if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($thirdparty_buyer->price_level)) { + // if price by customer / level + if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { + require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; + + $prodcustprice = new ProductCustomerPrice($this->db); + + $filter = array('t.fk_product' => $this->id, 't.fk_soc' => $thirdparty_buyer->id); + + // If a price per customer exist + $pricebycustomerexist = false; + $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); + if ($result) { + if (count($prodcustprice->lines) > 0) { + $pricebycustomerexist = true; + $pu_ht = price($prodcustprice->lines[0]->price); + $price_min = price($prodcustprice->lines[0]->price_min); + $pu_ttc = price($prodcustprice->lines[0]->price_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; + } + } + } + + if ( !$pricebycustomerexist && !empty($thirdparty_buyer->price_level)) { + $pu_ht = $this->multiprices[$thirdparty_buyer->price_level]; + $pu_ttc = $this->multiprices_ttc[$thirdparty_buyer->price_level]; + $price_min = $this->multiprices_min[$thirdparty_buyer->price_level]; + $price_base_type = $this->multiprices_base_type[$thirdparty_buyer->price_level]; + if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { + // using this option is a bug. kept for backward compatibility + if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) { + $tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level]; + } + if (isset($this->multiprices_recuperableonly[$thirdparty_buyer->price_level])) { + $tva_npr = $this->multiprices_recuperableonly[$thirdparty_buyer->price_level]; + } + if (empty($tva_tx)) { + $tva_npr = 0; + } + } + } + } elseif(getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($thirdparty_buyer->price_level)) { // // If price per segment $pu_ht = $this->multiprices[$thirdparty_buyer->price_level]; $pu_ttc = $this->multiprices_ttc[$thirdparty_buyer->price_level]; $price_min = $this->multiprices_min[$thirdparty_buyer->price_level]; @@ -2576,7 +2622,7 @@ public function updatePrice($newprice, $newpricebase, $user, $newvat = null, $ne // 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 ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !$ignore_autogen && $this->price_autogen && ($level == 1)) { + if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !$ignore_autogen && $this->price_autogen && ($level == 1)) { return $this->generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpbq); } @@ -2976,7 +3022,7 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_ } // Load multiprices array - if (getDolGlobalString('PRODUIT_MULTIPRICES') && empty($ignore_price_load)) { // prices per segment + if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && empty($ignore_price_load)) { // prices per segment $produit_multiprices_limit = getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT'); for ($i = 1; $i <= $produit_multiprices_limit; $i++) { $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; @@ -3042,7 +3088,7 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_ return -1; } } - } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') && empty($ignore_price_load)) { // prices per customers + } elseif ((getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && empty($ignore_price_load)) { // prices per customers // Nothing loaded by default. List may be very long. } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') && empty($ignore_price_load)) { // prices per quantity $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 23203912b0ee3..179a84bb2394e 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -43,7 +43,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; -if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) { +if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php'; $prodcustprice = new ProductCustomerPrice($db); @@ -76,7 +76,7 @@ } // Clean param -if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT')) { +if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT')) { $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5; } @@ -204,7 +204,7 @@ } if (!$error) { - 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')) { $produit_multiprices_limit = getDolGlobalInt('PRODUIT_MULTIPRICES_LIMIT'); for ($i = 1; $i <= $produit_multiprices_limit; $i++) { // Force the update of the price of the product using the new VAT @@ -261,7 +261,7 @@ $action = ''; } - if (($action == 'update_price') && !$cancel && $object->getRights()->creer) { + if (($action == 'update_price' || $action == 'update_level_price') && !$cancel && $object->getRights()->creer) { $error = 0; $pricestoupdate = array(); @@ -285,7 +285,7 @@ } // Multiprices - if (!$error && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) { + if (!$error && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') || ($action == 'update_level_price' && getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')))) { $newprice = GETPOST('price', 'array'); $newprice_min = GETPOST('price_min', 'array'); $newpricebase = GETPOST('multiprices_base_type', 'array'); @@ -916,7 +916,7 @@ print '
'; print $langs->trans("PriceLevel"); diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index a6e89c93989b4..867f60319f15e 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1131,8 +1131,45 @@ $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); + $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); + if ($result) { + // If there is some prices specific to the customer + if (count($prodcustprice->lines) > 0) { + $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; + }*/ + } + } elseif ($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]; @@ -1543,11 +1580,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 8b8e5a8dfb462..392bc0433af01 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -820,6 +820,51 @@ $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); + + $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); + if ($result >= 0) { + if (count($prodcustprice->lines) > 0) { + $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 (!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]; @@ -1222,11 +1267,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/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 7723e9e992f91..bd21980ffac8a 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1796,7 +1796,7 @@ public function add_product($idproduct, $qty, $remise_percent = 0.0, $date_start $localtax2_tx = get_localtax($tva_tx, 2, $this->thirdparty, $mysoc, $tva_npr); // multiprix - if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) { + if (($conf->global->PRODUIT_MULTIPRICES) && $this->thirdparty->price_level) { $price = $prod->multiprices[$this->thirdparty->price_level]; } else { $price = $prod->price; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 338a0a73a1ed1..6b63e0ecd0435 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1887,7 +1887,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 6c2148a4b1ef5..d05a5ef485287 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -1039,7 +1039,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 07ca8415b7ea4..2880d1644f5c6 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2935,7 +2935,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"; @@ -2993,7 +2993,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 @@ -3073,7 +3073,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')) { @@ -3431,7 +3431,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); @@ -3502,7 +3502,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 83bf7b3f6539e..3ad3dee44d95f 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 861d632bc64d1..9d6145384859a 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1503,7 +1503,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'; } } @@ -1682,7 +1682,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/product/admin/product.php b/htdocs/product/admin/product.php index d98818b51c901..0336bc47d6322 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); @@ -586,6 +588,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 '
'; // Price per customer segment/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')) { // Price and min price are variable (depends on level of company). if (!empty($socid)) { $soc = new Societe($db); @@ -1059,6 +1059,32 @@ } else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ print ''; + if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { + // Price + print ''; + + // Price minimum + print ''; + } } print '
'.$langs->trans("SellingPrice").''; + if ($object->price_base_type == 'TTC') { + print price($object->price_ttc).' '.$langs->trans($object->price_base_type); + } else { + print price($object->price).' '.$langs->trans($object->price_base_type); + if (getDolGlobalString('PRODUCT_DISPLAY_VAT_INCL_PRICES') && !empty($object->price_ttc)) { + print ' - ' . price($object->price_ttc).' '.$langs->trans('TTC') . ''; + } + } + + print '
'.$langs->trans("MinPrice").''; + if ($object->price_base_type == 'TTC') { + print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type); + } else { + print price($object->price_min).' '.$langs->trans($object->price_base_type); + if (getDolGlobalString('PRODUCT_DISPLAY_VAT_INCL_PRICES') && !empty($object->price_min_ttc)) { + print ' - ' . price($object->price_min_ttc).' '.$langs->trans('TTC') . ''; + } + } + print '
'; @@ -1375,7 +1401,7 @@ print '
' . $langs->trans("UpdateDefaultPrice") . '
'; } } else { - 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')) { if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) { print '
' . $langs->trans("UpdateDefaultPrice") . '
'; } else { @@ -1383,7 +1409,7 @@ } } - if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) { + if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) { print '
id . '">' . $langs->trans("AddCustomerPrice") . '
'; } else { @@ -1391,7 +1417,7 @@ } } - 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')) { if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) { print '
' . $langs->trans("UpdateVAT") . '
'; } else { @@ -1399,7 +1425,7 @@ } if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) { - print '
' . $langs->trans("UpdateLevelPrices") . '
'; + print '
' . $langs->trans("UpdateLevelPrices") . '
'; } else { print '
' . $langs->trans("UpdateLevelPrices") . '
'; } @@ -1442,11 +1468,11 @@ print '

'; } -if ($action == 'edit_price' && $object->getRights()->creer) { +if (($action == 'edit_price' || $action == 'edit_level_price') && $object->getRights()->creer) { print '
'; print load_fiche_titre($langs->trans("NewPrice"), ''); - if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { + if (!getDolGlobalString('PRODUIT_MULTIPRICES') && $action != 'edit_level_price') { print ''."\n"; print '
'; print ''; @@ -1559,7 +1585,7 @@ function on_change() { print $form->buttonsSaveCancel(); print '
'; - } else { + } elseif ($action == 'edit_level_price' && $object->getRights()->creer) { print ''."\n"; ?>