dolibarr 18.0.6
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
25require '../../main.inc.php';
26require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
27require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28require_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
34if (!$user->admin || (empty($conf->productbatch->enabled)))
36
37$action = GETPOST('action', 'alpha');
38$value = GETPOST('value', 'alpha');
39$label = GETPOST('label', 'alpha');
40$scandir = GETPOST('scan_dir', 'alpha');
41$type = 'product_batch';
42
43$error = 0;
44
45
46/*
47 * Actions
48 */
49
50include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
51
52if ($action == 'updateMaskLot') {
53 $maskconstbatch = GETPOST('maskconstLot', 'aZ09');
54 $maskbatch = GETPOST('maskLot', 'alpha');
55
56 if ($maskconstbatch && preg_match('/_MASK$/', $maskconstbatch)) {
57 $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
58 if ($res <= 0) $error++;
59 }
60
61 if (!$error) {
62 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
63 } else {
64 setEventMessages($langs->trans("Error"), null, 'errors');
65 }
66} elseif ($action == 'updateMaskSN') {
67 $maskconstbatch = GETPOST('maskconstSN', 'aZ09');
68 $maskbatch = GETPOST('maskSN', 'alpha');
69
70 if ($maskconstbatch && preg_match('/_MASK$/', $maskconstbatch)) {
71 $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
72 if ($res <= 0) $error++;
73 }
74
75 if (!$error) {
76 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
77 } else {
78 setEventMessages($langs->trans("Error"), null, 'errors');
79 }
80} elseif ($action == 'setmodlot') {
81 dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", $value, 'chaine', 0, '', $conf->entity);
82} elseif ($action == 'setmodsn') {
83 dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", $value, 'chaine', 0, '', $conf->entity);
84} elseif ($action == 'setmaskslot') {
85 dolibarr_set_const($db, "PRODUCTBATCH_LOT_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
86 if ($value == '1' && $conf->global->PRODUCTBATCH_LOT_ADDONS !== 'mod_lot_advanced') {
87 dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", 'mod_lot_advanced', 'chaine', 0, '', $conf->entity);
88 }
89} elseif ($action == 'setmaskssn') {
90 dolibarr_set_const($db, "PRODUCTBATCH_SN_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
91 if ($value == '1' && $conf->global->PRODUCTBATCH_SN_ADDONS !== 'mod_sn_advanced') {
92 dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", 'mod_sn_advanced', 'chaine', 0, '', $conf->entity);
93 }
94} elseif ($action == 'set') {
95 // Activate a model
96 $ret = addDocumentModel($value, $type, $label, $scandir);
97} elseif ($action == 'del') {
98 $ret = delDocumentModel($value, $type);
99 if ($ret > 0) {
100 if ($conf->global->FACTURE_ADDON_PDF == "$value") {
101 dolibarr_del_const($db, 'FACTURE_ADDON_PDF', $conf->entity);
102 }
103 }
104} elseif ($action == 'specimen') {
105 $modele = GETPOST('module', 'alpha');
106
107 $product_batch = new Productlot($db);
108 $product_batch->initAsSpecimen();
109
110 // Search template files
111 $file = '';
112 $classname = '';
113 $filefound = 0;
114 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
115 foreach ($dirmodels as $reldir) {
116 $file = dol_buildpath($reldir . "core/modules/product_batch/doc/pdf_" . $modele . ".modules.php", 0);
117 if (file_exists($file)) {
118 $filefound = 1;
119 $classname = "pdf_" . $modele;
120 break;
121 }
122 }
123
124 if ($filefound) {
125 require_once $file;
126
127 $module = new $classname($db);
128
129 if ($module->write_file($product_batch, $langs) > 0) {
130 header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=product_batch&file=SPECIMEN.pdf");
131 return;
132 } else {
133 setEventMessages($module->error, $module->errors, 'errors');
134 dol_syslog($module->error, LOG_ERR);
135 }
136 } else {
137 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
138 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
139 }
140} elseif ($action == 'setdoc') {
141 // Set default model
142 if (dolibarr_set_const($db, "PRODUCT_BATCH_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
143 // La constante qui a ete lue en avant du nouveau set
144 // on passe donc par une variable pour avoir un affichage coherent
145 $conf->global->PRODUCT_BATCH_ADDON_PDF = $value;
146 }
147
148 // On active le modele
149 $ret = delDocumentModel($value, $type);
150 if ($ret > 0) {
151 $ret = addDocumentModel($value, $type, $label, $scandir);
152 }
153}
154
155/*
156 * View
157 */
158
159$form = new Form($db);
160
161$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
162
163llxHeader("", $langs->trans("ProductLotSetup"));
164
165$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
166print load_fiche_titre($langs->trans("ProductLotSetup"), $linkback, 'title_setup');
167
169
170print dol_get_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'lot');
171
172
173if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
174 // 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
175 // but the numbering module is not used.
176 // 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
177 // to the selected product.
178 print $langs->trans("NothingToSetup");
179} else {
180 /*
181 * Lot Numbering models
182 */
183
184 print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', '');
185
186 print '<table class="noborder centpercent">';
187 print '<tr class="liste_titre">';
188 print '<td>'.$langs->trans("Name").'</td>';
189 print '<td>'.$langs->trans("Description").'</td>';
190 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
191 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
192 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
193 print '</tr>'."\n";
194
195 clearstatcache();
196
197 foreach ($dirmodels as $reldir) {
198 $dir = dol_buildpath($reldir."core/modules/product_batch/");
199
200 if (is_dir($dir)) {
201 $handle = opendir($dir);
202 if (is_resource($handle)) {
203 while (($file = readdir($handle)) !== false) {
204 if (substr($file, 0, 8) == 'mod_lot_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
205 $file = substr($file, 0, dol_strlen($file) - 4);
206
207 require_once $dir.$file.'.php';
208
209 $module = new $file($db);
210
211 // Show modules according to features level
212 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
213 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
214
215 if ($module->isEnabled()) {
216 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
217 print $module->info();
218 print '</td>';
219
220 // Show example of numbering model
221 print '<td class="nowrap">';
222 $tmp = $module->getExample();
223 if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
224 elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
225 else print $tmp;
226 print '</td>'."\n";
227
228 print '<td class="center">';
229 if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) {
230 print img_picto($langs->trans("Activated"), 'switch_on');
231 } else {
232 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodlot&token='.newToken().'&value='.urlencode($file).'">';
233 print img_picto($langs->trans("Disabled"), 'switch_off');
234 print '</a>';
235 }
236 print '</td>';
237
238 $batch = new Productlot($db);
239 $batch->initAsSpecimen();
240
241 // Info
242 $htmltooltip = '';
243 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
244 $nextval = $module->getNextValue($mysoc, $batch);
245 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
246 $htmltooltip .= ''.$langs->trans("NextValue").': ';
247 if ($nextval) {
248 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
249 $nextval = $langs->trans($nextval);
250 $htmltooltip .= $nextval.'<br>';
251 } else {
252 $htmltooltip .= $langs->trans($module->error).'<br>';
253 }
254 }
255
256 print '<td class="center">';
257 print $form->textwithpicto('', $htmltooltip, 1, 0);
258 print '</td>';
259
260 print "</tr>\n";
261 }
262 }
263 }
264 closedir($handle);
265 }
266 }
267 }
268
269 print "</table><br>\n";
270
271
272 /*
273 * Serials Numbering models
274 */
275
276 print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', '');
277
278 print '<table class="noborder centpercent">';
279 print '<tr class="liste_titre">';
280 print '<td>'.$langs->trans("Name").'</td>';
281 print '<td>'.$langs->trans("Description").'</td>';
282 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
283 print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
284 print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
285 print '</tr>'."\n";
286
287 clearstatcache();
288
289 foreach ($dirmodels as $reldir) {
290 $dir = dol_buildpath($reldir."core/modules/product_batch/");
291
292 if (is_dir($dir)) {
293 $handle = opendir($dir);
294 if (is_resource($handle)) {
295 while (($file = readdir($handle)) !== false) {
296 if (substr($file, 0, 7) == 'mod_sn_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
297 $file = substr($file, 0, dol_strlen($file) - 4);
298
299 require_once $dir.$file.'.php';
300
301 $module = new $file($db);
302
303 // Show modules according to features level
304 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
305 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
306
307 if ($module->isEnabled()) {
308 print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
309 print $module->info();
310 print '</td>';
311
312 // Show example of numbering model
313 print '<td class="nowrap">';
314 $tmp = $module->getExample();
315 if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
316 elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
317 else print $tmp;
318 print '</td>'."\n";
319
320 print '<td class="center">';
321 if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) {
322 print img_picto($langs->trans("Activated"), 'switch_on');
323 } else {
324 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodsn&token='.newToken().'&value='.urlencode($file).'">';
325 print img_picto($langs->trans("Disabled"), 'switch_off');
326 print '</a>';
327 }
328 print '</td>';
329
330 $batch = new Productlot($db);
331 $batch->initAsSpecimen();
332
333 // Info
334 $htmltooltip = '';
335 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
336 $nextval = $module->getNextValue($mysoc, $batch);
337 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
338 $htmltooltip .= ''.$langs->trans("NextValue").': ';
339 if ($nextval) {
340 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
341 $nextval = $langs->trans($nextval);
342 $htmltooltip .= $nextval.'<br>';
343 } else {
344 $htmltooltip .= $langs->trans($module->error).'<br>';
345 }
346 }
347
348 print '<td class="center">';
349 print $form->textwithpicto('', $htmltooltip, 1, 0);
350 print '</td>';
351
352 print "</tr>\n";
353 }
354 }
355 }
356 closedir($handle);
357 }
358 }
359 }
360
361 print "</table><br>\n";
362}
363
364// Module to build doc
365$def = array();
366$sql = "SELECT nom";
367$sql .= " FROM " . MAIN_DB_PREFIX . "document_model";
368$sql .= " WHERE type = '" . $db->escape($type) . "'";
369$sql .= " AND entity = " . $conf->entity;
370$resql = $db->query($sql);
371if ($resql) {
372 $i = 0;
373 $num_rows = $db->num_rows($resql);
374 while ($i < $num_rows) {
375 $array = $db->fetch_array($resql);
376 array_push($def, $array[0]);
377 $i++;
378 }
379} else {
380 dol_print_error($db);
381}
382
383print '<br>';
384
385print load_fiche_titre($langs->trans("ProductBatchDocumentTemplates"), '', '');
386
387print '<div class="div-table-responsive-no-min">';
388print '<table class="noborder centpercent">';
389print '<tr class="liste_titre">';
390print '<td>' . $langs->trans("Name") . '</td>';
391print '<td>' . $langs->trans("Description") . '</td>';
392print '<td class="center" width="60">' . $langs->trans("Status") . "</td>\n";
393print '<td class="center" width="60">' . $langs->trans("Default") . "</td>\n";
394print '<td class="center"></td>';
395print '<td class="center" width="80">' . $langs->trans("Preview") . '</td>';
396print "</tr>\n";
397
398clearstatcache();
399
400foreach ($dirmodels as $reldir) {
401 foreach (array('', '/doc') as $valdir) {
402 $dir = dol_buildpath($reldir . "core/modules/product_batch" . $valdir);
403 if (is_dir($dir)) {
404 $handle = opendir($dir);
405 if (is_resource($handle)) {
406 while (($file = readdir($handle)) !== false) {
407 $filelist[] = $file;
408 }
409 closedir($handle);
410 arsort($filelist);
411
412 foreach ($filelist as $file) {
413 if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
414 if (file_exists($dir . '/' . $file)) {
415 $name = substr($file, 4, dol_strlen($file) - 16);
416 $classname = substr($file, 0, dol_strlen($file) - 12);
417
418 require_once $dir . '/' . $file;
419 $module = new $classname($db);
420
421 $modulequalified = 1;
422 if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
423 $modulequalified = 0;
424 }
425 if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
426 $modulequalified = 0;
427 }
428
429 if ($modulequalified) {
430 print '<tr class="oddeven"><td width="100">';
431 print (empty($module->name) ? $name : $module->name);
432 print "</td><td>\n";
433 if (method_exists($module, 'info')) {
434 print $module->info($langs);
435 } else {
436 print $module->description;
437 }
438 print '</td>';
439
440 // Active
441 if (in_array($name, $def)) {
442 print '<td class="center">' . "\n";
443 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=del&token=' . newToken() . '&value=' . urlencode($name) . '">';
444 print img_picto($langs->trans("Enabled"), 'switch_on');
445 print '</a>';
446 print '</td>';
447 } else {
448 print '<td class="center">' . "\n";
449 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=set&token=' . newToken() . '&value=' . urlencode($name) . '&scan_dir=' . urlencode($module->scandir) . '&label=' . urlencode($module->name) . '">' . img_picto($langs->trans("Disabled"), 'switch_off') . '</a>';
450 print "</td>";
451 }
452
453 // Defaut
454 print '<td class="center">';
455 if (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF') == $name) {
456 print img_picto($langs->trans("Default"), 'on');
457 } else {
458 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setdoc&token=' . newToken() . '&value=' . urlencode($name) . '&scan_dir=' . urlencode($module->scandir) . '&label=' . urlencode($module->name) . '" alt="' . $langs->trans("Default") . '">' . img_picto($langs->trans("Disabled"), 'off') . '</a>';
459 }
460 print '</td>';
461
462 // Info
463 $htmltooltip = '' . $langs->trans("Name") . ': ' . $module->name;
464 $htmltooltip .= '<br>' . $langs->trans("Type") . ': ' . ($module->type ? $module->type : $langs->trans("Unknown"));
465 if ($module->type == 'pdf') {
466 $htmltooltip .= '<br>' . $langs->trans("Width") . '/' . $langs->trans("Height") . ': ' . $module->page_largeur . '/' . $module->page_hauteur;
467 }
468 $htmltooltip .= '<br><br><u>' . $langs->trans("FeaturesSupported") . ':</u>';
469 $htmltooltip .= '<br>' . $langs->trans("Logo") . ': ' . yn($module->option_logo, 1, 1);
470 $htmltooltip .= '<br>' . $langs->trans("MultiLanguage") . ': ' . yn($module->option_multilang, 1, 1);
471
472
473 print '<td class="center">';
474 print $form->textwithpicto('', $htmltooltip, 1, 0);
475 print '</td>';
476
477 // Preview
478 print '<td class="center">';
479 if ($module->type == 'pdf') {
480 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=specimen&module=' . $name . '">' . img_object($langs->trans("Preview"), 'contract') . '</a>';
481 } else {
482 print img_object($langs->trans("PreviewNotAvailable"), 'generic');
483 }
484 print '</td>';
485
486 print "</tr>\n";
487 }
488 }
489 }
490 }
491 }
492 }
493 }
494}
495
496print '</table>';
497print '</div>';
498
499// End of page
500llxFooter();
501$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
product_lot_admin_prepare_head()
Return array head with list of tabs to view object informations.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:123
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.