22 require
'../../main.inc.php';
23 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
24 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
27 $langs->loadLangs(array(
'admin',
'products'));
29 $action =
GETPOST(
'action',
'aZ09');
32 if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled)))
42 if ($action ==
'update') {
43 $var_percent =
GETPOST(
'var_percent',
'array');
44 $var_min_percent =
GETPOST(
'var_min_percent',
'array');
45 $fk_level =
GETPOST(
'fk_level',
'array');
47 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
48 $check = isset($var_min_percent[$i]);
51 $check = $check && isset($var_percent[$i]) && isset($fk_level[$i]);
66 $i_fk_level = (int) $fk_level[$i];
70 $check2 = $i_var_min_percent;
72 $check1 = $i_fk_level >= 1 && $i_fk_level <= $conf->global->PRODUIT_MULTIPRICES_LIMIT;
73 $check2 = $i_var_percent && ($i_var_min_percent || (string) $i_var_min_percent ===
'0');
76 if (empty($i_var_percent) && empty($i_var_min_percent)) {
78 $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"product_pricerules WHERE level = ".((
int) $i));
82 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_pricerules (level, fk_level, var_percent, var_min_percent) VALUES (";
83 $sql .= ((int) $i).
", ".$db->escape($i_fk_level).
", ".$i_var_percent.
", ".$i_var_min_percent.
")";
85 if (!$db->query($sql)) {
87 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_pricerules";
88 $sql .=
" SET fk_level = ".$db->escape($i_fk_level).
", var_percent = ".$i_var_percent.
", var_min_percent = ".$i_var_min_percent.
" WHERE level = ".$i;
90 if (!$db->query($sql)) {
107 $sql =
"SELECT rowid, level, fk_level, var_percent, var_min_percent";
108 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_pricerules";
109 $query = $db->query($sql);
113 while ($result = $db->fetch_object($query)) {
114 $rules[$result->level] = $result;
117 $title = $langs->trans(
'ProductServiceSetup');
118 $tab = $langs->trans(
"ProductsAndServices");
120 if (empty($conf->product->enabled)) {
121 $title = $langs->trans(
'ServiceSetup');
122 $tab = $langs->trans(
'Services');
123 } elseif (empty($conf->service->enabled)) {
124 $title = $langs->trans(
'ProductSetup');
125 $tab = $langs->trans(
'Products');
128 llxHeader(
'', $langs->trans(
'MultipriceRules'));
130 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
134 print '<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
135 print '<input type="hidden" name="token" value="'.newToken().
'">';
136 print '<input type="hidden" name="action" value="update">';
141 print '<span class="opacitymedium">'.$langs->trans(
"MultiPriceRuleDesc").
'</span><br><br>';
144 $price_options = array();
146 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
147 $price_options[$i] = $langs->trans(
'SellingPrice').
' '.$i;
151 <table
class=
"noborder centpercent">
152 <tr
class=
"liste_titre">
153 <td style=
"text-align: center"><?php echo $langs->trans(
'PriceLevel') ?></td>
154 <td style=
"text-align: center"><?php echo $langs->trans(
'Price') ?></td>
155 <td style=
"text-align: center"><?php echo $langs->trans(
'MinPrice') ?></td></tr>
157 <td
class=
"fieldrequired" style=
"text-align: center"><?php echo $langs->trans(
'SellingPrice') ?> 1</td>
159 <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, 2) ?>"> <?php echo $langs->trans(
'PercentDiscountOver', $langs->trans(
'SellingPrice').
' 1') ?></td>
161 <?php
for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++): ?>
163 <td
class=
"fieldrequired" style=
"text-align: center"><?php
164 echo $langs->trans(
'SellingPrice').
' '.$i;
166 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
167 if (!empty($conf->global->$keyforlabel)) {
168 print ' - '.$langs->trans($conf->global->$keyforlabel);
172 <td style=
"text-align: center">
173 <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, 2) ?>">
176 for ($j = 1; $j < $i; $j++) {
177 $return[$j] = $price_options[$j];
179 $texttoshow = $langs->trans(
'PercentVariationOver',
'{s1}');
180 $texttoshow = str_replace(
'{s1}',
Form::selectarray(
"fk_level[$i]", $return, (isset($rules[$i]) ? $rules[$i]->fk_level : null)), $texttoshow);
184 <td style=
"text-align: center">
185 <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, 2) ?>">
186 <?php echo $langs->trans(
'PercentDiscountOver', $langs->transnoentitiesnoconv(
'SellingPrice').
' '.$i) ?>
196 print '<div style="text-align: center">
197 <input type="submit" value="'.$langs->trans(
"Save").
'" class="button button-save">
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
$conf db name
Only used if Module[ID]Name translation string is not found.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
div float
Buy price without taxes.
print
Draft customers invoices.
product_admin_prepare_head()
Return array head with list of tabs to view object informations.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type