dolibarr 25.0.0-alpha
product_lot.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2021 Christophe Battarel <christophe.battarel@altairis.fr>
3 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
39
40// Load translation files required by the page
41$langs->loadLangs(array("admin", "products", "productbatch"));
42
43// Security check
44if (!$user->admin || (!isModEnabled('productbatch'))) {
46}
47
48$action = GETPOST('action', 'alpha');
49$value = GETPOST('value', 'alpha');
50$label = GETPOST('label', 'alpha');
51$scandir = GETPOST('scan_dir', 'alpha');
52$type = 'product_batch';
53
54$error = 0;
55
56
57/*
58 * Actions
59 */
60
61include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
62
63if ($action == 'updateMaskLot') {
64 $maskconstbatch = GETPOST('maskconstLot', 'aZ09');
65 $maskbatch = GETPOST('maskLot', '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) {
70 $error++;
71 }
72 }
73
74 if (!$error) {
75 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
76 } else {
77 setEventMessages($langs->trans("Error"), null, 'errors');
78 }
79} elseif ($action == 'updateMaskSN') {
80 $maskconstbatch = GETPOST('maskconstSN', 'aZ09');
81 $maskbatch = GETPOST('maskSN', 'alpha');
82
83 if ($maskconstbatch && preg_match('/_MASK$/', $maskconstbatch)) {
84 $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
85 if ($res <= 0) {
86 $error++;
87 }
88 }
89
90 if (!$error) {
91 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
92 } else {
93 setEventMessages($langs->trans("Error"), null, 'errors');
94 }
95} elseif ($action == 'setmodlot') {
96 dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", $value, 'chaine', 0, '', $conf->entity);
97} elseif ($action == 'setmodsn') {
98 dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", $value, 'chaine', 0, '', $conf->entity);
99} elseif ($action == 'setmaskslot') {
100 dolibarr_set_const($db, "PRODUCTBATCH_LOT_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
101 if ($value == '1' && getDolGlobalString('PRODUCTBATCH_LOT_ADDONS') !== 'mod_lot_advanced') {
102 dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", 'mod_lot_advanced', 'chaine', 0, '', $conf->entity);
103 }
104} elseif ($action == 'setmaskssn') {
105 dolibarr_set_const($db, "PRODUCTBATCH_SN_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
106 if ($value == '1' && getDolGlobalString('PRODUCTBATCH_SN_ADDONS') !== 'mod_sn_advanced') {
107 dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", 'mod_sn_advanced', 'chaine', 0, '', $conf->entity);
108 }
109} elseif ($action == 'set') {
110 // Activate a model
111 $ret = addDocumentModel($value, $type, $label, $scandir);
112} elseif ($action == 'del') {
113 $ret = delDocumentModel($value, $type);
114 if ($ret > 0) {
115 if (getDolGlobalString('FACTURE_ADDON_PDF') == "$value") {
116 dolibarr_del_const($db, 'FACTURE_ADDON_PDF', $conf->entity);
117 }
118 }
119} elseif ($action == 'specimen') {
120 $modele = GETPOST('module', 'alpha');
121
122 $product_batch = new Productlot($db);
123 $product_batch->initAsSpecimen();
124
125 // Search template files
126 $file = '';
127 $classname = '';
128 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
129 foreach ($dirmodels as $reldir) {
130 $file = dol_buildpath($reldir . "core/modules/product_batch/doc/pdf_" . $modele . ".modules.php", 0);
131 if (file_exists($file)) {
132 $classname = "pdf_" . $modele;
133 break;
134 }
135 }
136
137 if ($classname !== '') {
138 require_once $file;
139
140 $module = new $classname($db);
141
142 '@phan-var-force ModelePDFProductBatch $module';
143
144 if ($module->write_file($product_batch, $langs) > 0) {
145 header("Location: " . DOL_URL_ROOT . "/document.php?modulepart=product_batch&file=SPECIMEN.pdf");
146 return;
147 } else {
148 setEventMessages($module->error, $module->errors, 'errors');
149 dol_syslog($module->error, LOG_ERR);
150 }
151 } else {
152 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
153 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
154 }
155} elseif ($action == 'setdoc') {
156 // Set default model
157 if (dolibarr_set_const($db, "PRODUCT_BATCH_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
158 // The constant that was read before the new set
159 // so we go through a variable to get a consistent display
160 $conf->global->PRODUCT_BATCH_ADDON_PDF = $value;
161 }
162
163 // On active le modele
164 $ret = delDocumentModel($value, $type);
165 if ($ret > 0) {
166 $ret = addDocumentModel($value, $type, $label, $scandir);
167 }
168}
169
170/*
171 * View
172 */
173
174$form = new Form($db);
175
176$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
177
178llxHeader("", $langs->trans("ProductLotSetup"), '', '', 0, 0, '', '', '', 'mod-product page-admin_product_lot');
179
180$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
181print load_fiche_titre($langs->trans("ProductLotSetup"), $linkback, 'title_setup');
182
184
185print dol_get_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'lot');
186
187
188if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
189 /*
190 * Lot Numbering models
191 */
192
193 $batch = new Productlot($db);
194 $batch->initAsSpecimen();
195
196 printNumberingModuleList('product_batch', 'mod_lot_', 'PRODUCTBATCH_LOT_ADDON', $langs->trans("BatchLotNumberingModules"), $batch, 'setmodlot');
197
198 print '<br>';
199
200 /*
201 * Serials Numbering models
202 */
203
204 $batch = new Productlot($db);
205 $batch->initAsSpecimen();
206
207 printNumberingModuleList('product_batch', 'mod_sn_', 'PRODUCTBATCH_SN_ADDON', $langs->trans("BatchSerialNumberingModules"), $batch, 'setmodsn');
208
209 print '<br>';
210}
211
212// Module to build doc
213$def = array();
214// TODO Replace with $def = getListOfModels($db, $type);
215$sql = "SELECT nom";
216$sql .= " FROM " . MAIN_DB_PREFIX . "document_model";
217$sql .= " WHERE type = '" . $db->escape($type) . "'";
218$sql .= " AND entity = " . ((int) $conf->entity);
219$resql = $db->query($sql);
220if ($resql) {
221 $i = 0;
222 $num_rows = $db->num_rows($resql);
223 while ($i < $num_rows) {
224 $array = $db->fetch_array($resql);
225 if (is_array($array)) {
226 array_push($def, $array[0]);
227 }
228 $i++;
229 }
230} else {
231 dol_print_error($db);
232}
233
234
235if (!empty($def)) {
236 print '<br>';
237
238 printDocumentModelList($type, 'product_batch', 'PRODUCT_BATCH_ADDON_PDF', $langs->trans("ProductBatchDocumentTemplates"), array(
239 'Logo' => 'option_logo',
240 'MultiLanguage' => 'option_multilang',
241 ));
242}
243
244
245if (empty($def) && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
246 // The feature to define the numbering module of lot or serial is no enabled because it is not used anywhere in Dolibarr code: You can set it
247 // but the numbering module is not used.
248 // 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
249 // to the selected product.
250 print $langs->trans("NothingToSetup");
251}
252
253
254// End of page
255llxFooter();
256$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.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class with list of lots and properties.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
product_lot_admin_prepare_head()
Return array head with list of tabs to view object information.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.