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