product_lot.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. /**
  18. * \file htdocs/product/admin/product_lot.php
  19. * \ingroup produit
  20. * \brief Setup page of product lot module
  21. */
  22. // Load Dolibarr environment
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("admin", "products", "productbatch"));
  29. // Security check
  30. if (!$user->admin || (empty($conf->productbatch->enabled)))
  31. accessforbidden();
  32. $action = GETPOST('action', 'alpha');
  33. $value = GETPOST('value', 'alpha');
  34. $error = 0;
  35. /*
  36. * Actions
  37. */
  38. include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
  39. if ($action == 'updateMaskLot') {
  40. $maskconstbatch = GETPOST('maskconstLot', 'aZ09');
  41. $maskbatch = GETPOST('maskLot', 'alpha');
  42. if ($maskconstbatch && preg_match('/_MASK$/', $maskconstbatch)) {
  43. $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
  44. if ($res <= 0) $error++;
  45. }
  46. if (!$error) {
  47. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  48. } else {
  49. setEventMessages($langs->trans("Error"), null, 'errors');
  50. }
  51. } elseif ($action == 'updateMaskSN') {
  52. $maskconstbatch = GETPOST('maskconstSN', 'aZ09');
  53. $maskbatch = GETPOST('maskSN', 'alpha');
  54. if ($maskconstbatch && preg_match('/_MASK$/', $maskconstbatch)) {
  55. $res = dolibarr_set_const($db, $maskconstbatch, $maskbatch, 'chaine', 0, '', $conf->entity);
  56. if ($res <= 0) $error++;
  57. }
  58. if (!$error) {
  59. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  60. } else {
  61. setEventMessages($langs->trans("Error"), null, 'errors');
  62. }
  63. } elseif ($action == 'setmodlot') {
  64. dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", $value, 'chaine', 0, '', $conf->entity);
  65. } elseif ($action == 'setmodsn') {
  66. dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", $value, 'chaine', 0, '', $conf->entity);
  67. } elseif ($action == 'setmaskslot') {
  68. dolibarr_set_const($db, "PRODUCTBATCH_LOT_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
  69. if ($value == '1' && $conf->global->PRODUCTBATCH_LOT_ADDONS !== 'mod_lot_advanced') {
  70. dolibarr_set_const($db, "PRODUCTBATCH_LOT_ADDON", 'mod_lot_advanced', 'chaine', 0, '', $conf->entity);
  71. }
  72. } elseif ($action == 'setmaskssn') {
  73. dolibarr_set_const($db, "PRODUCTBATCH_SN_USE_PRODUCT_MASKS", $value, 'bool', 0, '', $conf->entity);
  74. if ($value == '1' && $conf->global->PRODUCTBATCH_SN_ADDONS !== 'mod_sn_advanced') {
  75. dolibarr_set_const($db, "PRODUCTBATCH_SN_ADDON", 'mod_sn_advanced', 'chaine', 0, '', $conf->entity);
  76. }
  77. }
  78. /*
  79. * View
  80. */
  81. $form = new Form($db);
  82. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  83. llxHeader("", $langs->trans("ProductLotSetup"));
  84. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  85. print load_fiche_titre($langs->trans("ProductLotSetup"), $linkback, 'title_setup');
  86. $head = product_lot_admin_prepare_head();
  87. print dol_get_fiche_head($head, 'settings', $langs->trans("Batch"), -1, 'lot');
  88. if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
  89. // 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
  90. // but the numbering module is not used.
  91. // 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
  92. // to the selected product.
  93. print $langs->trans("NothingToSetup");
  94. } else {
  95. /*
  96. * Lot Numbering models
  97. */
  98. print load_fiche_titre($langs->trans("BatchLotNumberingModules"), '', '');
  99. print '<table class="noborder centpercent">';
  100. print '<tr class="liste_titre">';
  101. print '<td>'.$langs->trans("Name").'</td>';
  102. print '<td>'.$langs->trans("Description").'</td>';
  103. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  104. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  105. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  106. print '</tr>'."\n";
  107. clearstatcache();
  108. foreach ($dirmodels as $reldir) {
  109. $dir = dol_buildpath($reldir."core/modules/product_batch/");
  110. if (is_dir($dir)) {
  111. $handle = opendir($dir);
  112. if (is_resource($handle)) {
  113. while (($file = readdir($handle)) !== false) {
  114. if (substr($file, 0, 8) == 'mod_lot_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  115. $file = substr($file, 0, dol_strlen($file) - 4);
  116. require_once $dir.$file.'.php';
  117. $module = new $file($db);
  118. // Show modules according to features level
  119. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  120. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  121. if ($module->isEnabled()) {
  122. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  123. print $module->info();
  124. print '</td>';
  125. // Show example of numbering model
  126. print '<td class="nowrap">';
  127. $tmp = $module->getExample();
  128. if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  129. elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
  130. else print $tmp;
  131. print '</td>'."\n";
  132. print '<td class="center">';
  133. if ($conf->global->PRODUCTBATCH_LOT_ADDON == $file) {
  134. print img_picto($langs->trans("Activated"), 'switch_on');
  135. } else {
  136. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodlot&token='.newToken().'&value='.urlencode($file).'">';
  137. print img_picto($langs->trans("Disabled"), 'switch_off');
  138. print '</a>';
  139. }
  140. print '</td>';
  141. $batch = new Productlot($db);
  142. $batch->initAsSpecimen();
  143. // Info
  144. $htmltooltip = '';
  145. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  146. $nextval = $module->getNextValue($mysoc, $batch);
  147. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  148. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  149. if ($nextval) {
  150. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
  151. $nextval = $langs->trans($nextval);
  152. $htmltooltip .= $nextval.'<br>';
  153. } else {
  154. $htmltooltip .= $langs->trans($module->error).'<br>';
  155. }
  156. }
  157. print '<td class="center">';
  158. print $form->textwithpicto('', $htmltooltip, 1, 0);
  159. print '</td>';
  160. print "</tr>\n";
  161. }
  162. }
  163. }
  164. closedir($handle);
  165. }
  166. }
  167. }
  168. print "</table><br>\n";
  169. /*
  170. * Serials Numbering models
  171. */
  172. print load_fiche_titre($langs->trans("BatchSerialNumberingModules"), '', '');
  173. print '<table class="noborder centpercent">';
  174. print '<tr class="liste_titre">';
  175. print '<td>'.$langs->trans("Name").'</td>';
  176. print '<td>'.$langs->trans("Description").'</td>';
  177. print '<td class="nowrap">'.$langs->trans("Example").'</td>';
  178. print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
  179. print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  180. print '</tr>'."\n";
  181. clearstatcache();
  182. foreach ($dirmodels as $reldir) {
  183. $dir = dol_buildpath($reldir."core/modules/product_batch/");
  184. if (is_dir($dir)) {
  185. $handle = opendir($dir);
  186. if (is_resource($handle)) {
  187. while (($file = readdir($handle)) !== false) {
  188. if (substr($file, 0, 7) == 'mod_sn_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
  189. $file = substr($file, 0, dol_strlen($file) - 4);
  190. require_once $dir.$file.'.php';
  191. $module = new $file($db);
  192. // Show modules according to features level
  193. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  194. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  195. if ($module->isEnabled()) {
  196. print '<tr class="oddeven"><td>'.$module->name."</td><td>\n";
  197. print $module->info();
  198. print '</td>';
  199. // Show example of numbering model
  200. print '<td class="nowrap">';
  201. $tmp = $module->getExample();
  202. if (preg_match('/^Error/', $tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
  203. elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
  204. else print $tmp;
  205. print '</td>'."\n";
  206. print '<td class="center">';
  207. if ($conf->global->PRODUCTBATCH_SN_ADDON == $file) {
  208. print img_picto($langs->trans("Activated"), 'switch_on');
  209. } else {
  210. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmodsn&token='.newToken().'&value='.urlencode($file).'">';
  211. print img_picto($langs->trans("Disabled"), 'switch_off');
  212. print '</a>';
  213. }
  214. print '</td>';
  215. $batch = new Productlot($db);
  216. $batch->initAsSpecimen();
  217. // Info
  218. $htmltooltip = '';
  219. $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  220. $nextval = $module->getNextValue($mysoc, $batch);
  221. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  222. $htmltooltip .= ''.$langs->trans("NextValue").': ';
  223. if ($nextval) {
  224. if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
  225. $nextval = $langs->trans($nextval);
  226. $htmltooltip .= $nextval.'<br>';
  227. } else {
  228. $htmltooltip .= $langs->trans($module->error).'<br>';
  229. }
  230. }
  231. print '<td class="center">';
  232. print $form->textwithpicto('', $htmltooltip, 1, 0);
  233. print '</td>';
  234. print "</tr>\n";
  235. }
  236. }
  237. }
  238. closedir($handle);
  239. }
  240. }
  241. }
  242. print "</table><br>\n";
  243. }
  244. // End of page
  245. llxFooter();
  246. $db->close();