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 ''; 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/card.php b/htdocs/product/card.php index 77f511c6e48df..bf905a1b9dda6 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1748,7 +1748,7 @@ print '
'; if (!getDolGlobalString('PRODUCT_DISABLE_PRICES')) { - if (getDolGlobalString('PRODUIT_MULTIPRICES')) { + if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { // We do no show price array on create when multiprices enabled. // We must set them on prices tab. 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 '
'; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b526c465d7904..53431f38463d3 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 9f993cb92719a..8e1bd9f562a48 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 '
'; // 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); @@ -1375,7 +1375,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 +1383,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 +1391,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 +1399,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 +1442,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 +1559,7 @@ function on_change() { print $form->buttonsSaveCancel(); print ''; - } else { + } elseif ($action == 'edit_level_price' && $object->getRights()->creer) { print ''."\n"; ?>