Continue debug of PRODUIT_MULTIPRICES option.

Introduce option PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL to have
relative caculation of multiprice not yet visible.
This commit is contained in:
Laurent Destailleur 2015-11-02 10:02:09 +01:00
parent 6fe43cbbeb
commit a161e6d47a
6 changed files with 51 additions and 31 deletions

View File

@ -155,7 +155,8 @@ function product_admin_prepare_head()
$head[$h][2] = 'general';
$h++;
if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
if (!empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($conf->global->PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL))
{
$head[$h] = array(
0 => DOL_URL_ROOT."/product/admin/price_rules.php",
1 => $langs->trans('MultipriceRules'),

View File

@ -1708,3 +1708,4 @@ TitleExampleForMajorRelease=Example of message you can use to announce this majo
TitleExampleForMaintenanceRelease=Example of message you can use to announce this maintenance release (feel free to use it on your web sites)
ExampleOfNewsMessageForMajorRelease=Dolibarr ERP & CRM %s is available. Version %s is a major release with a lot of new features for both users and developers. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read <a href="https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog">ChangeLog</a> for complete list of changes.
ExampleOfNewsMessageForMaintenanceRelease=Dolibarr ERP & CRM %s is available. Version %s is a maintenance version, so it contains only fixes of bugs. We recommend everybody using an older version to upgrade to this one. As any maintenance release, no new features, nor data structure change is present into this version. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read <a href="https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog">ChangeLog</a> for complete list of changes.
MultiPriceRuleDesc=When option "Several level of prices per product/service" is on, you can define different prices (one per price level) for each product. To save you time, you can enter here rule to have price for each level autocalculated according to price of first level, so you will have to enter only price for first level on each product. This page is here to save you time and can be usefull only if your prices for each leve are relative to first level. You can ignore this page in most cases.

View File

@ -69,6 +69,7 @@ ProductStatusNotOnBuyShort=Not for purchase
UpdatePrice=Update price
UpdateVAT=Update vat
UpdateDefaultPrice=Update default price
UpdateLevelPrices=Update prices for each level
AppliedPricesFrom=Applied prices from
SellingPrice=Selling price
SellingPriceHT=Selling price (net of tax)
@ -236,7 +237,7 @@ ProductsDashboard=Products/Services summary
UpdateOriginalProductLabel=Modify original label
HelpUpdateOriginalProductLabel=Allows to edit the name of the product
MultipriceRules=Price level rules
UseMultipriceRules=Use price level rules
UseMultipriceRules=Use price level rules (defined into product module setup) to autocalculate prices of all other level according to first level
PercentVariationOver=%% variation over %s
PercentDiscountOver=%% discount over %s
### composition fabrication

View File

@ -1,6 +1,5 @@
<?php
/*
/**
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com
*
* This program is free software; you can redistribute it and/or modify
@ -15,6 +14,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Page to set how to autocalculate price for each level when option
* PRODUCT_MULTIPRICE is on.
*/
require '../../main.inc.php';
@ -125,10 +127,16 @@ llxHeader('', $langs->trans('MultipriceRules'));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($title,$linkback,'title_setup');
print '<form method="POST">';
$head = product_admin_prepare_head();
dol_fiche_head($head, 'generator', $tab, 0, 'product');
print load_fiche_titre($langs->trans('MultipriceRules'));
print $langs->trans("MultiPriceRuleDesc").'<br><br>';
print load_fiche_titre($langs->trans('MultipriceRules'), '', '');
//Array that contains the number of prices available
$price_options = array();
@ -150,8 +158,6 @@ $genPriceOptions = function($level) use ($price_options) {
?>
<form method="post">
<table class="noborder">
<tr class="liste_titre">
<td style="text-align: center"><?php echo $langs->trans('PriceLevel') ?></td>
@ -184,13 +190,16 @@ $genPriceOptions = function($level) use ($price_options) {
<?php endfor ?>
</table>
<br>
<?php
<div style="text-align: center">
<input type="submit" value="<?php echo $langs->trans('Save') ?>" class="button">
</div>
</form>
dol_fiche_end();
<?php
print '<div style="text-align: center">
<input type="submit" value="'.$langs->trans('Save').'" class="button">
</div>';
print '</form>';
llxFooter();
llxFooter();
$db->close();

View File

@ -1344,10 +1344,10 @@ class Product extends CommonObject
* @param int $level 0=standard, >0 = level if multilevel prices
* @param int $newnpr 0=Standard vat rate, 1=Special vat rate for French NPR VAT
* @param int $newpsq 1 if it has price by quantity
* @param int $ignore_autogen Used to avoid infinite loops
* @param int $ignore_autogen Used to avoid infinite loops
* @return int <0 if KO, >0 if OK
*/
function updatePrice($newprice, $newpricebase, $user, $newvat='',$newminprice='', $level=0, $newnpr=0, $newpsq=0, $ignore_autogen = 0)
function updatePrice($newprice, $newpricebase, $user, $newvat='',$newminprice='', $level=0, $newnpr=0, $newpsq=0, $ignore_autogen=0)
{
global $conf,$langs;
@ -1362,9 +1362,10 @@ class Product extends CommonObject
// Check parameters
if ($newvat == '') $newvat=$this->tva_tx;
//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 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))
{
return $this->generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpsq);
}
@ -4024,6 +4025,7 @@ class Product extends CommonObject
{
global $conf, $db;
// FIXME USing * into select is forbidden
$sql = "SELECT * FROM ".MAIN_DB_PREFIX."product_pricerules";
$query = $db->query($sql);

View File

@ -716,28 +716,30 @@ if (! $action || $action == 'delete' || $action == 'showlog_customer_price' || $
{
print "\n" . '<div class="tabsAction">' . "\n";
if (empty($conf->global->PRODUIT_MULTIPRICES))
if (empty($conf->global->PRODUIT_MULTIPRICES)) // For everyone, except multiprices
{
if ($user->rights->produit->creer || $user->rights->service->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&amp;id=' . $object->id . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
}
}
else
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
{
if ($user->rights->produit->creer || $user->rights->service->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=add_customer_price&amp;id=' . $object->id . '">' . $langs->trans("AddCustomerPrice") . '</a></div>';
}
}
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
if ($user->rights->produit->creer || $user->rights->service->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_vat&amp;id=' . $object->id . '">' . $langs->trans("UpdateVAT") . '</a></div>';
}
if ($user->rights->produit->creer || $user->rights->service->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&amp;id=' . $object->id . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&amp;id=' . $object->id . '">' . $langs->trans("UpdateLevelPrices") . '</a></div>';
}
}
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
{
if ($user->rights->produit->creer || $user->rights->service->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=add_customer_price&amp;id=' . $object->id . '">' . $langs->trans("AddCustomerPrice") . '</a></div>';
}
}
print "\n</div>\n";
}
@ -912,11 +914,16 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->
</script>
<?php
if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($conf->global->PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL))
{
print $langs->trans('UseMultipriceRules'). ' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.($object->price_autogen ? 'checked' : '').'><br><br>';
}
for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++)
{
if ($i > 1) print '<br>';
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">';
if ($i > 1) print '<br>';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="update_price">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
@ -928,9 +935,8 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->
print '<table class="border" width="100%">';
// VAT
if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL))
if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // This option is kept for backward compatibility but has no sense
{
print '<tr><td>' . $langs->trans('UseMultipriceRules'). '</td><td><input type="checkbox" id="usePriceRules" name="usePriceRules" '.($object->price_autogen ? 'checked' : '').'></td></tr>';
print '<tr><td>' . $langs->trans("VATRate") . '</td><td>';
print $form->load_tva("tva_tx_" . $i, $object->multiprices_tva_tx["$i"], $mysoc, '', $object->id);
print '</td></tr>';