diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 684ee5ef20aad..241746d84700d 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -239,3 +239,5 @@ PricingRule=Pricing Rules AddCustomerPrice=Add price by customers ForceUpdateChildPriceSoc=Set same price on customer subsidiaries PriceByCustomerLog=Price by customer log +MinimumPriceLimit=Minimum price can't be lower that %s +MinimumRecommendedPrice=Minimum recommended price is : %s diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 68ff2cbefbbb2..877a2b55d54f8 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -239,3 +239,5 @@ PricingRule=Règle de prix AddCustomerPrice=Ajouter prix par clients ForceUpdateChildPriceSoc=Définir le même prix sur les filiales des clients PriceByCustomerLog=Trace des prix par clients +MinimumPriceLimit=Le prix minimum ne peut être inférieur à %s +MinimumRecommendedPrice=Le prix minimum conseillé est de : %s \ No newline at end of file diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 134f65b8ff6b0..6e3c8d4401333 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2013 Marcos García * Copyright (C) 2011-2014 Alexandre Spangaro * Copyright (C) 2014 Henry Florian + * Copyright (C) 2014 Philippe Grand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -3513,4 +3514,35 @@ function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='' } } } + + /** + * Return minimum product recommended price + * + * @return void + */ + function min_recommended_price() + { + global $conf; + if ( !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + $product_fourn = new ProductFournisseur($this->db); + $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->id, '', ''); + $maxpricesupplier=0; + + if (is_array($product_fourn_list) && count($product_fourn_list)>0) + { + foreach($product_fourn_list as $productfourn) + { + if ($productfourn->fourn_unitprice>$maxpricesupplier) + { + $maxpricesupplier = $productfourn->fourn_unitprice; + } + } + + $maxpricesupplier*=$conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE; + } + return $maxpricesupplier; + } + } } diff --git a/htdocs/product/price.php b/htdocs/product/price.php index a28fbd8370696..b2f0ba0993736 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -6,6 +6,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Philippe Grand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,6 +53,8 @@ $object = new Product($db); +$error=0; + /* * Actions */ @@ -59,6 +62,9 @@ if ($action == 'update_price' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { $result = $object->fetch($id); + $error=0; + $maxpricesupplier = $object->min_recommended_price(); + // MultiPrix if (! empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -93,6 +99,13 @@ $newpsq = empty($newpsq) ? 0 : $newpsq; } + if ($newprice_min<$maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + setEventMessage($langs->trans("MinimumPriceLimit",price($maxpricesupplier,0,'',1,-1,-1,'auto')),'errors'); + $error++; + $action='edit_price'; + } + if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) { $action = ''; setEventMessage($langs->trans("RecordSaved")); @@ -197,6 +210,9 @@ * **************************************************** */ if ($action == 'add_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { + + $error=0; + $maxpricesupplier = $object->min_recommended_price(); $update_child_soc = GETPOST('updatechildprice'); @@ -211,15 +227,24 @@ $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); - $result = $prodcustprice->create($user, 0, $update_child_soc); + if ($prodcustprice->price_min<$maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + setEventMessage($langs->trans("MinimumPriceLimit",price($maxpricesupplier,0,'',1,-1,-1,'auto')),'errors'); + $error++; + $action='add_customer_price'; + } - if ($result < 0) { - setEventMessage($prodcustprice->error, 'errors'); - } else { - setEventMessage($langs->trans('Save'), 'mesgs'); + if (empty($error)) { + $result = $prodcustprice->create($user, 0, $update_child_soc); + + if ($result < 0) { + setEventMessage($prodcustprice->error, 'errors'); + } else { + setEventMessage($langs->trans('Save'), 'mesgs'); + } + + $action = ''; } - - $action = ''; } if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) { @@ -236,6 +261,11 @@ } if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { + + $result = $object->fetch($id); + + $error=0; + $maxpricesupplier = $object->min_recommended_price(); $update_child_soc = GETPOST('updatechildprice'); @@ -248,15 +278,23 @@ $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); - $result = $prodcustprice->update($user, 0, $update_child_soc); - - if ($result < 0) { - setEventMessage($prodcustprice->error, 'errors'); - } else { - setEventMessage($langs->trans('Save'), 'mesgs'); + if ($prodcustprice->price_min<$maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + setEventMessage($langs->trans("MinimumPriceLimit",price($maxpricesupplier,0,'',1,-1,-1,'auto')),'errors'); + $error++; + $action='update_customer_price'; + } + if (empty($error)) { + $result = $prodcustprice->update($user, 0, $update_child_soc); + + if ($result < 0) { + setEventMessage($prodcustprice->error, 'errors'); + } else { + setEventMessage($langs->trans('Save'), 'mesgs'); + } + + $action = ''; } - - $action = ''; } /* @@ -613,6 +651,10 @@ } else { print ''; } + if ( !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + print ''.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier,0,'',1,-1,-1,'auto')).' '.img_warning().''; + } print ''; print ''; @@ -660,6 +702,10 @@ } else { print ''; } + if ( !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + print ''.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier,0,'',1,-1,-1,'auto')).' '.img_warning().''; + } print ''; print ' '; @@ -806,6 +852,7 @@ if ($action == 'add_customer_price') { // Create mode + $maxpricesupplier = $object->min_recommended_price(); print_fiche_titre($langs->trans('PriceByCustomer')); @@ -856,6 +903,10 @@ } else { print ''; } + if ( !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + print ''.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier,0,'',1,-1,-1,'auto')).' '.img_warning().''; + } print ''; // Update all child soc @@ -876,6 +927,7 @@ } elseif ($action == 'edit_customer_price') { // Edit mode + $maxpricesupplier = $object->min_recommended_price(); print_fiche_titre($langs->trans('PriceByCustomer')); @@ -893,11 +945,11 @@ print '' . $langs->trans('ThirdParty') . ''; $staticsoc = new Societe($db); $staticsoc->fetch($prodcustprice->fk_soc); - print "" . $staticsoc->getNomUrl(1) . ""; + print "" . $staticsoc->getNomUrl(1) . ""; print ''; // VAT - print '' . $langs->trans("VATRate") . ''; + print '' . $langs->trans("VATRate") . ''; print $form->load_tva("tva_tx", $prodcustprice->tva_tx, $mysoc, '', $object->id, $prodcustprice->recuperableonly); print ''; @@ -931,6 +983,10 @@ } else { print ''; } + if ( !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) + { + print ''.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier,0,'',1,-1,-1,'auto')).' '.img_warning().''; + } print ''; // Update all child soc