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