dolibarr  16.0.5
product_lot.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 Christophe Battarel <christophe.battarel@altairis.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
28 
29 // Load translation files required by the page
30 $langs->loadLangs(array("admin", "products", "productbatch"));
31 
32 // Security check
33 if (!$user->admin || (empty($conf->productbatch->enabled)))
35 
36 $action = GETPOST('action', 'alpha');
37 $value = GETPOST('value', 'alpha');
38 
39 $error = 0;
40 
41 
42 /*
43  * Actions
44  */
45 
46 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
47 
48 if ($action == 'updateMaskLot') {
49  $maskconstbatch = GETPOST('maskconstLot', 'alpha');
50  $maskbatch = GETPOST('maskLot', 'alpha');
51 
52  if ($maskconstbatch) {
53  $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
54  if ($res <= 0) $error++;
55  }
56 
57  if (!$error) {
58  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
59  } else {
60  setEventMessages($langs->trans("Error"), null, 'errors');
61  }
62 } elseif ($action == 'updateMaskSN') {
63  $maskconstbatch = GETPOST('maskconstSN', 'alpha');
64  $maskbatch = GETPOST('maskSN', 'alpha');
65 
66  if ($maskconstbatch) {
67  $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
68  if ($res <= 0) $error++;
69  }
70 
71  if (!$error) {
72  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
73  } else {
74  setEventMessages($langs->trans("Error"), null, 'errors');
75  }
76 } elseif ($action == 'setmodlot') {
77  dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", $value, 'chaine', 0, '', $conf->entity);
78 } elseif ($action == 'setmodsn') {
79  dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", $value, 'chaine', 0, '', $conf->entity);
80 } elseif ($action == 'setmaskslot') {
81  dolibarr_set_const($db, "PRODUCTBATCH_LOT_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
82  if ($value == '1' && $conf->global->PRODUCTBATCH_LOT_ADDONS !== 'mod_lot_advanced') {
83  dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", 'mod_lot_advanced', 'chaine', 0, '', $conf->entity);
84  }
85 } elseif ($action == 'setmaskssn') {
86  dolibarr_set_const($db, "PRODUCTBATCH_SN_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
87  if ($value == '1' && $conf->global->PRODUCTBATCH_SN_ADDONS !== 'mod_sn_advanced') {
88  dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", 'mod_sn_advanced', 'chaine', 0, '', $conf->entity);
89  }
90 }
91 
92 /*
93  * View
94  */
95 
96 $form = new Form($db);
97 
98 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
99 
100 llxHeader("", $langs->trans("ProductLotSetup"));
101 
102 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
103 print load_fiche_titre($langs->trans("ProductLotSetup"), $linkback, 'title_setup');
104 
106 
107 print dol_get_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'lot');
108 
109 
110 if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
111  // The feature to define the numbering module of lot or serial is no enabled bcause it is not used anywhere in Dolibarr code: You can set it
112  // but the numbering module is not used.
113  // TODO Use it on lot creation page, when you create a lot and when the lot number is kept empty to define the lot according
114  // to the selected product.
115  print $langs->trans("NothingToSetup");
116 } else {
117  /*
118  * Lot Numbering models
119  */
120 
121  print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', '');
122 
123  print '<table class="noborder centpercent">';
124  print '<tr class="liste_titre">';
125  print '<td>'.$langs->trans("Name").'</td>';
126  print '<td>'.$langs->trans("Description").'</td>';
127  print '<td class="nowrap">'.$langs->trans("Example").'</td>';
128  print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
129  print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
130  print '</tr>'."\n";
131 
132  clearstatcache();
133 
134  foreach ($dirmodels as $reldir) {
135  $dir = dol_buildpath($reldir."core/modules/product_batch/");
136 
137  if (is_dir($dir)) {
138  $handle = opendir($dir);
139  if (is_resource($handle)) {
140  while (($file = readdir($handle)) !== false) {
141  if (substr($file, 0, 8) == 'mod_lot_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
142  $file = substr($file, 0, dol_strlen($file) - 4);
143 
144  require_once $dir.$file.'.php';
145 
146  $module = new $file($db);
147 
148  // Show modules according to features level
149  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
150  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
151 
152  if ($module->isEnabled()) {
153  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
154  print $module->info();
155  print '</td>';
156 
157  // Show example of numbering model
158  print '<td class="nowrap">';
159  $tmp = $module->getExample();
160  if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
161  elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
162  else print $tmp;
163  print '</td>'."\n";
164 
165  print '<td class="center">';
166  if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) {
167  print img_picto($langs->trans("Activated"), 'switch_on');
168  } else {
169  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodlot&token='.newToken().'&value='.urlencode($file).'">';
170  print img_picto($langs->trans("Disabled"), 'switch_off');
171  print '</a>';
172  }
173  print '</td>';
174 
175  $batch = new Productlot($db);
176  $batch->initAsSpecimen();
177 
178  // Info
179  $htmltooltip = '';
180  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
181  $nextval = $module->getNextValue($mysoc, $batch);
182  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
183  $htmltooltip .= ''.$langs->trans("NextValue").': ';
184  if ($nextval) {
185  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
186  $nextval = $langs->trans($nextval);
187  $htmltooltip .= $nextval.'<br>';
188  } else {
189  $htmltooltip .= $langs->trans($module->error).'<br>';
190  }
191  }
192 
193  print '<td class="center">';
194  print $form->textwithpicto('', $htmltooltip, 1, 0);
195  print '</td>';
196 
197  print "</tr>\n";
198  }
199  }
200  }
201  closedir($handle);
202  }
203  }
204  }
205 
206  print "</table><br>\n";
207 
208 
209  /*
210  * Serials Numbering models
211  */
212 
213  print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', '');
214 
215  print '<table class="noborder centpercent">';
216  print '<tr class="liste_titre">';
217  print '<td>'.$langs->trans("Name").'</td>';
218  print '<td>'.$langs->trans("Description").'</td>';
219  print '<td class="nowrap">'.$langs->trans("Example").'</td>';
220  print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
221  print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
222  print '</tr>'."\n";
223 
224  clearstatcache();
225 
226  foreach ($dirmodels as $reldir) {
227  $dir = dol_buildpath($reldir."core/modules/product_batch/");
228 
229  if (is_dir($dir)) {
230  $handle = opendir($dir);
231  if (is_resource($handle)) {
232  while (($file = readdir($handle)) !== false) {
233  if (substr($file, 0, 7) == 'mod_sn_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
234  $file = substr($file, 0, dol_strlen($file) - 4);
235 
236  require_once $dir.$file.'.php';
237 
238  $module = new $file($db);
239 
240  // Show modules according to features level
241  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
242  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
243 
244  if ($module->isEnabled()) {
245  print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
246  print $module->info();
247  print '</td>';
248 
249  // Show example of numbering model
250  print '<td class="nowrap">';
251  $tmp = $module->getExample();
252  if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
253  elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
254  else print $tmp;
255  print '</td>'."\n";
256 
257  print '<td class="center">';
258  if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) {
259  print img_picto($langs->trans("Activated"), 'switch_on');
260  } else {
261  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodsn&token='.newToken().'&value='.urlencode($file).'">';
262  print img_picto($langs->trans("Disabled"), 'switch_off');
263  print '</a>';
264  }
265  print '</td>';
266 
267  $batch = new Productlot($db);
268  $batch->initAsSpecimen();
269 
270  // Info
271  $htmltooltip = '';
272  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
273  $nextval = $module->getNextValue($mysoc, $batch);
274  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
275  $htmltooltip .= ''.$langs->trans("NextValue").': ';
276  if ($nextval) {
277  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
278  $nextval = $langs->trans($nextval);
279  $htmltooltip .= $nextval.'<br>';
280  } else {
281  $htmltooltip .= $langs->trans($module->error).'<br>';
282  }
283  }
284 
285  print '<td class="center">';
286  print $form->textwithpicto('', $htmltooltip, 1, 0);
287  print '</td>';
288 
289  print "</tr>\n";
290  }
291  }
292  }
293  closedir($handle);
294  }
295  }
296  }
297 
298  print "</table><br>\n";
299 }
300 
301 // End of page
302 llxFooter();
303 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
else
if(!GETPOST('transkey', 'alphanohtml') &&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:53
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Productlot
Class with list of lots and properties.
Definition: productlot.class.php:36
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
product_lot_admin_prepare_head
product_lot_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: product.lib.php:324
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25