25require
'../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
38$langs->loadLangs(array(
'admin',
'products'));
40$action =
GETPOST(
'action',
'aZ09');
43if (!$user->admin || (!isModEnabled(
"product") && !isModEnabled(
"service"))) {
54if ($action ==
'update') {
55 $var_percent =
GETPOST(
'var_percent',
'array');
56 $var_min_percent =
GETPOST(
'var_min_percent',
'array');
57 $fk_level =
GETPOST(
'fk_level',
'array');
59 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
60 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
61 $check = isset($var_min_percent[$i]);
64 $check = $check && isset($var_percent[$i]) && isset($fk_level[$i]);
75 $i_var_percent = (float)
price2num($var_percent[$i]);
78 $i_var_min_percent = (float)
price2num($var_min_percent[$i]);
79 $i_fk_level = (int) $fk_level[$i];
83 $check2 = $i_var_min_percent;
85 $check1 = $i_fk_level >= 1 && $i_fk_level <= $produit_multiprices_limit;
86 $check2 = $i_var_percent && ($i_var_min_percent || (string) $i_var_min_percent ===
'0');
89 if (empty($i_var_percent) && empty($i_var_min_percent)) {
91 $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"product_pricerules WHERE level = ".((
int) $i));
95 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_pricerules (level, fk_level, var_percent, var_min_percent) VALUES (";
96 $sql .= ((int) $i).
", ".$db->escape($i_fk_level).
", ".$i_var_percent.
", ".$i_var_min_percent.
")";
98 if (!$db->query($sql)) {
100 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_pricerules";
101 $sql .=
" SET fk_level = ".$db->escape($i_fk_level).
", var_percent = ".$i_var_percent.
", var_min_percent = ".$i_var_min_percent.
" WHERE level = ".((int) $i);
103 if (!$db->query($sql)) {
120$sql =
"SELECT rowid, level, fk_level, var_percent, var_min_percent";
121$sql .=
" FROM ".MAIN_DB_PREFIX.
"product_pricerules";
122$query = $db->query($sql);
126while ($result = $db->fetch_object($query)) {
127 $rules[$result->level] = $result;
130$title = $langs->trans(
'ProductServiceSetup');
131$tab = $langs->trans(
"ProductsAndServices");
133if (!isModEnabled(
"product")) {
134 $title = $langs->trans(
'ServiceSetup');
135 $tab = $langs->trans(
'Services');
136} elseif (!isModEnabled(
"service")) {
137 $title = $langs->trans(
'ProductSetup');
138 $tab = $langs->trans(
'Products');
141llxHeader(
'', $langs->trans(
'MultipriceRules'),
'',
'', 0, 0,
'',
'',
'',
'mod-product page-admin_price_rules');
143$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
147print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
148print
'<input type="hidden" name="token" value="'.newToken().
'">';
149print
'<input type="hidden" name="action" value="update">';
154print
'<span class="opacitymedium">'.$langs->trans(
"MultiPriceRuleDesc").
'</span><br><br>';
157$price_options = array();
159$produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
160for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
161 $price_options[$i] = $langs->trans(
'SellingPrice').
' '.$i;
165 <
table class=
"noborder centpercent">
166 <tr
class=
"liste_titre">
167 <td style=
"text-align: center"><?php echo $langs->trans(
'PriceLevel') ?></td>
168 <td style=
"text-align: center"><?php echo $langs->trans(
'Price') ?></td>
169 <td style=
"text-align: center"><?php echo $langs->trans(
'MinPrice') ?></td></tr>
171 <td
class=
"fieldrequired" style=
"text-align: center"><?php echo $langs->trans(
'SellingPrice') ?> 1</td>
173 <td style=
"text-align: center"><input
type=
"text" style=
"text-align: right" name=
"var_min_percent[1]" size=
"5" value=
"<?php echo price(isset($rules[1]) ? $rules[1]->var_min_percent : 0, 1) ?>"> <?php echo $langs->trans(
'PercentDiscountOver', $langs->trans(
'SellingPrice').
' 1') ?></td>
175 <?php
for ($i = 2; $i <= $produit_multiprices_limit; $i++) : ?>
177 <td
class=
"fieldrequired" style=
"text-align: center"><?php
178 echo $langs->trans(
'SellingPrice').
' '.$i;
180 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
186 <td style=
"text-align: center">
187 <input
type=
"text" style=
"text-align: right" name=
"var_percent[<?php echo $i ?>]" size=
"5" value=
"<?php echo price(isset($rules[$i]) ? $rules[$i]->var_percent : 0, 1) ?>">
190 for ($j = 1; $j < $i; $j++) {
191 $return[$j] = $price_options[$j];
193 $texttoshow = $langs->trans(
'PercentVariationOver',
'{s1}');
194 $texttoshow = str_replace(
'{s1}',
Form::selectarray(
"fk_level[$i]", $return, (isset($rules[$i]) ? $rules[$i]->fk_level : null)), $texttoshow);
198 <td style=
"text-align: center">
199 <input
type=
"text" style=
"text-align: right" name=
"var_min_percent[<?php echo $i ?>]" size=
"5" value=
"<?php echo price(isset($rules[$i]) ? $rules[$i]->var_min_percent : 0, 1) ?>">
200 <?php echo $langs->trans(
'PercentDiscountOver', $langs->transnoentitiesnoconv(
'SellingPrice').
' '.$i) ?>
210print
'<div style="text-align: center">
211 <input type="submit" value="'.$langs->trans(
"Save").
'" class="button button-save">
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
treeview li table
No Email.
product_admin_prepare_head()
Return array head with list of tabs to view object information.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.