stock.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
  7. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/stock.php
  24. * \ingroup stock
  25. * \brief Page to setup module stock
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "stocks"));
  33. // Securit check
  34. if (!$user->admin) {
  35. accessforbidden();
  36. }
  37. $action = GETPOST('action', 'aZ09');
  38. $value = GETPOST('value', 'alpha');
  39. $label = GETPOST('label', 'alpha');
  40. $scandir = GETPOST('scan_dir', 'alpha');
  41. $type = 'stock';
  42. /*
  43. * Action
  44. */
  45. $reg = array();
  46. if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
  47. $code = $reg[1];
  48. // If constant is for a unique choice, delete other choices
  49. if (in_array($code, array('STOCK_CALCULATE_ON_BILL', 'STOCK_CALCULATE_ON_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_SHIPMENT', 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE'))) {
  50. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_BILL', $conf->entity);
  51. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_VALIDATE_ORDER', $conf->entity);
  52. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SHIPMENT', $conf->entity);
  53. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE', $conf->entity);
  54. }
  55. if (in_array($code, array('STOCK_CALCULATE_ON_SUPPLIER_BILL', 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_RECEPTION', 'STOCK_CALCULATE_ON_RECEPTION_CLOSE', 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER'))) {
  56. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_BILL', $conf->entity);
  57. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', $conf->entity);
  58. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_RECEPTION', $conf->entity);
  59. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_RECEPTION_CLOSE', $conf->entity);
  60. dolibarr_del_const($db, 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', $conf->entity);
  61. }
  62. if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
  63. header("Location: ".$_SERVER["PHP_SELF"]);
  64. exit;
  65. } else {
  66. dol_print_error($db);
  67. }
  68. }
  69. if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
  70. $code = $reg[1];
  71. if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
  72. header("Location: ".$_SERVER["PHP_SELF"]);
  73. exit;
  74. } else {
  75. dol_print_error($db);
  76. }
  77. }
  78. if ($action == 'warehouse') {
  79. $value = GETPOST('default_warehouse', 'alpha');
  80. $res = dolibarr_set_const($db, "MAIN_DEFAULT_WAREHOUSE", $value, 'chaine', 0, '', $conf->entity);
  81. if ($value == -1 || empty($value) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
  82. $res = dolibarr_del_const($db, "MAIN_DEFAULT_WAREHOUSE", $conf->entity);
  83. }
  84. if (!($res > 0)) {
  85. $error++;
  86. }
  87. }
  88. if ($action == 'specimen') {
  89. $modele = GETPOST('module', 'alpha');
  90. $object = new Entrepot($db);
  91. $object->initAsSpecimen();
  92. // Search template files
  93. $file = ''; $classname = ''; $filefound = 0;
  94. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  95. foreach ($dirmodels as $reldir) {
  96. $file = dol_buildpath($reldir."core/modules/stock/doc/pdf_".$modele.".modules.php", 0);
  97. if (file_exists($file)) {
  98. $filefound = 1;
  99. $classname = "pdf_".$modele;
  100. break;
  101. }
  102. }
  103. if ($filefound) {
  104. require_once $file;
  105. $module = new $classname($db);
  106. if ($module->write_file($object, $langs) > 0) {
  107. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=stock&file=SPECIMEN.pdf");
  108. return;
  109. } else {
  110. setEventMessages($module->error, null, 'errors');
  111. dol_syslog($module->error, LOG_ERR);
  112. }
  113. } else {
  114. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  115. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  116. }
  117. } elseif ($action == 'set') {
  118. // Activate a model
  119. $ret = addDocumentModel($value, $type, $label, $scandir);
  120. } elseif ($action == 'del') {
  121. $ret = delDocumentModel($value, $type);
  122. if ($ret > 0) {
  123. if ($conf->global->STOCK_ADDON_PDF == "$value") {
  124. dolibarr_del_const($db, 'STOCK_ADDON_PDF', $conf->entity);
  125. }
  126. }
  127. } elseif ($action == 'setdoc') {
  128. // Set default model
  129. if (dolibarr_set_const($db, "STOCK_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
  130. // The constant that was read before the new set
  131. // We therefore requires a variable to have a coherent view
  132. $conf->global->STOCK_ADDON_PDF = $value;
  133. }
  134. // On active le modele
  135. $ret = delDocumentModel($value, $type);
  136. if ($ret > 0) {
  137. $ret = addDocumentModel($value, $type, $label, $scandir);
  138. }
  139. }
  140. /*
  141. * View
  142. */
  143. $form = new Form($db);
  144. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  145. llxHeader('', $langs->trans("StockSetup"));
  146. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  147. print load_fiche_titre($langs->trans("StockSetup"), $linkback, 'title_setup');
  148. $head = stock_admin_prepare_head();
  149. print dol_get_fiche_head($head, 'general', $langs->trans("StockSetup"), -1, 'stock');
  150. $form = new Form($db);
  151. $formproduct = new FormProduct($db);
  152. $disabled = '';
  153. if (isModEnabled('productbatch')) {
  154. // If module lot/serial enabled, we force the inc/dec mode to STOCK_CALCULATE_ON_SHIPMENT_CLOSE and STOCK_CALCULATE_ON_RECEPTION_CLOSE
  155. $langs->load("productbatch");
  156. $disabled = ' disabled';
  157. // STOCK_CALCULATE_ON_SHIPMENT_CLOSE
  158. $descmode = $langs->trans('DeStockOnShipmentOnClosing');
  159. if (!isModEnabled('reception')) {
  160. // STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER
  161. $incmode = $langs->trans('ReStockOnDispatchOrder');
  162. } else {
  163. // STOCK_CALCULATE_ON_RECEPTION_CLOSE
  164. $incmode = $langs->trans('StockOnReceptionOnClosing');
  165. }
  166. print info_admin($langs->trans("WhenProductBatchModuleOnOptionAreForced", $descmode, $incmode));
  167. }
  168. print info_admin($langs->trans("IfYouUsePointOfSaleCheckModule"));
  169. print '<br>';
  170. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  171. print '<input type="hidden" name="token" value="'.newToken().'">';
  172. print '<input type="hidden" name="action" value="warehouse">';
  173. // Title rule for stock decrease
  174. print '<table class="noborder centpercent">';
  175. print '<tr class="liste_titre">';
  176. print "<td>".$langs->trans("RuleForStockManagementDecrease")."</td>\n";
  177. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  178. print '</tr>'."\n";
  179. $found = 0;
  180. print '<tr class="oddeven">';
  181. print '<td>'.$langs->trans("DeStockOnBill").'</td>';
  182. print '<td class="right">';
  183. if (isModEnabled('facture')) {
  184. if ($conf->use_javascript_ajax) {
  185. if ($disabled) {
  186. print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
  187. } else {
  188. print ajax_constantonoff('STOCK_CALCULATE_ON_BILL', array(), null, 0, 0, 0, 2, 1, 0, '', '', 'reposition');
  189. }
  190. } else {
  191. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  192. print $form->selectarray("STOCK_CALCULATE_ON_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_BILL);
  193. }
  194. } else {
  195. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name")).'</span>';
  196. }
  197. print "</td>\n</tr>\n";
  198. $found++;
  199. print '<tr class="oddeven">';
  200. print '<td>'.$langs->trans("DeStockOnValidateOrder").'</td>';
  201. print '<td class="right">';
  202. if (isModEnabled('commande')) {
  203. if ($conf->use_javascript_ajax) {
  204. if ($disabled) {
  205. print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
  206. } else {
  207. print ajax_constantonoff('STOCK_CALCULATE_ON_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  208. }
  209. } else {
  210. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  211. print $form->selectarray("STOCK_CALCULATE_ON_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER);
  212. }
  213. } else {
  214. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name")).'</span>';
  215. }
  216. print "</td>\n</tr>\n";
  217. $found++;
  218. //if (isModEnabled('expedition'))
  219. //{
  220. print '<tr class="oddeven">';
  221. print '<td>'.$langs->trans("DeStockOnShipment").'</td>';
  222. print '<td class="right">';
  223. if (isModEnabled("expedition")) {
  224. if ($conf->use_javascript_ajax) {
  225. print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  226. } else {
  227. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  228. print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT);
  229. }
  230. } else {
  231. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name")).'</span>';
  232. }
  233. print "</td>\n</tr>\n";
  234. $found++;
  235. print '<tr class="oddeven">';
  236. print '<td>'.$langs->trans("DeStockOnShipmentOnClosing").'</td>';
  237. print '<td class="right">';
  238. if (isModEnabled("expedition")) {
  239. if ($conf->use_javascript_ajax) {
  240. print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  241. } else {
  242. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  243. print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE);
  244. }
  245. } else {
  246. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name")).'</span>';
  247. }
  248. print "</td>\n</tr>\n";
  249. $found++;
  250. print '</table>';
  251. print '<br>';
  252. // Title rule for stock increase
  253. print '<table class="noborder centpercent">';
  254. print '<tr class="liste_titre">';
  255. print "<td>".$langs->trans("RuleForStockManagementIncrease")."</td>\n";
  256. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  257. print '</tr>'."\n";
  258. $found = 0;
  259. print '<tr class="oddeven">';
  260. print '<td>'.$langs->trans("ReStockOnBill").'</td>';
  261. print '<td class="right">';
  262. if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
  263. if ($conf->use_javascript_ajax) {
  264. if ($disabled) {
  265. print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
  266. } else {
  267. print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_BILL', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  268. }
  269. } else {
  270. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  271. print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL);
  272. }
  273. } else {
  274. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")).'</span>';
  275. }
  276. print "</td>\n</tr>\n";
  277. $found++;
  278. print '<tr class="oddeven">';
  279. print '<td>'.$langs->trans("ReStockOnValidateOrder").'</td>';
  280. print '<td class="right">';
  281. if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
  282. if ($conf->use_javascript_ajax) {
  283. if ($disabled) {
  284. print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
  285. } else {
  286. print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  287. }
  288. } else {
  289. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  290. print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER);
  291. }
  292. } else {
  293. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")).'</span>';
  294. }
  295. print "</td>\n</tr>\n";
  296. $found++;
  297. if (isModEnabled("reception")) {
  298. print '<tr class="oddeven">';
  299. print '<td>'.$langs->trans("StockOnReception").'</td>';
  300. print '<td class="right">';
  301. if ($conf->use_javascript_ajax) {
  302. print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  303. } else {
  304. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  305. print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION);
  306. }
  307. print "</td>\n</tr>\n";
  308. $found++;
  309. print '<tr class="oddeven">';
  310. print '<td>'.$langs->trans("StockOnReceptionOnClosing").'</td>';
  311. print '<td class="right">';
  312. if ($conf->use_javascript_ajax) {
  313. print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION_CLOSE', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  314. } else {
  315. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  316. print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE);
  317. }
  318. print "</td>\n</tr>\n";
  319. $found++;
  320. } else {
  321. print '<tr class="oddeven">';
  322. print '<td>'.$langs->trans("ReStockOnDispatchOrder").'</td>';
  323. print '<td class="right">';
  324. if (isModEnabled("supplier_order")) {
  325. if ($conf->use_javascript_ajax) {
  326. print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
  327. } else {
  328. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  329. print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER);
  330. }
  331. } else {
  332. print '<span class="opacitymedium">'.$langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")).'</span>';
  333. }
  334. print "</td>\n</tr>\n";
  335. $found++;
  336. }
  337. print '</table>';
  338. print '<br>';
  339. print '<table class="noborder centpercent">';
  340. print '<tr class="liste_titre">';
  341. print "<td>".$langs->trans("RuleForStockAvailability")."</td>\n";
  342. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  343. print '</tr>'."\n";
  344. print '<tr class="oddeven">';
  345. print '<td>'.$langs->trans("WarehouseAllowNegativeTransfer").'</td>';
  346. print '<td class="right">';
  347. if ($conf->use_javascript_ajax) {
  348. print ajax_constantonoff('STOCK_ALLOW_NEGATIVE_TRANSFER');
  349. } else {
  350. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  351. print $form->selectarray("STOCK_ALLOW_NEGATIVE_TRANSFER", $arrval, $conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER);
  352. }
  353. print "</td>\n";
  354. print "</tr>\n";
  355. // Option to force stock to be enough before adding a line into document
  356. if (isModEnabled('facture')) {
  357. print '<tr class="oddeven">';
  358. print '<td>'.$langs->trans("StockMustBeEnoughForInvoice").'</td>';
  359. print '<td class="right">';
  360. if ($conf->use_javascript_ajax) {
  361. print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_INVOICE');
  362. } else {
  363. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  364. print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_INVOICE", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE);
  365. }
  366. print "</td>\n";
  367. print "</tr>\n";
  368. }
  369. if (isModEnabled('commande')) {
  370. print '<tr class="oddeven">';
  371. print '<td>'.$langs->trans("StockMustBeEnoughForOrder").'</td>';
  372. print '<td class="right">';
  373. if ($conf->use_javascript_ajax) {
  374. print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_ORDER');
  375. } else {
  376. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  377. print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_ORDER", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER);
  378. }
  379. print "</td>\n";
  380. print "</tr>\n";
  381. }
  382. if (isModEnabled("expedition")) {
  383. print '<tr class="oddeven">';
  384. print '<td>'.$langs->trans("StockMustBeEnoughForShipment").'</td>';
  385. print '<td class="right">';
  386. if ($conf->use_javascript_ajax) {
  387. print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT');
  388. } else {
  389. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  390. print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT);
  391. }
  392. print "</td>\n";
  393. print "</tr>\n";
  394. }
  395. print '</table>';
  396. print '<br>';
  397. $virtualdiffersfromphysical = 0;
  398. if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
  399. || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
  400. || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
  401. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
  402. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
  403. || isModEnabled('mrp')) {
  404. $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
  405. }
  406. if ($virtualdiffersfromphysical) {
  407. print '<table class="noborder centpercent">';
  408. print '<tr class="liste_titre">';
  409. print "<td>".$langs->trans("RuleForStockReplenishment")." ".img_help('help', $langs->trans("VirtualDiffersFromPhysical"))."</td>\n";
  410. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  411. print '</tr>'."\n";
  412. print '<tr class="oddeven">';
  413. print '<td>';
  414. print $form->textwithpicto($langs->trans("UseRealStockByDefault"), $langs->trans("ReplenishmentCalculation"));
  415. print '</td>';
  416. print '<td class="right">';
  417. if ($conf->use_javascript_ajax) {
  418. print ajax_constantonoff('STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT');
  419. } else {
  420. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  421. print $form->selectarray("STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT", $arrval, $conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT);
  422. }
  423. print "</td>\n";
  424. print "</tr>\n";
  425. print '</table>';
  426. print '<br>';
  427. }
  428. print '<form>';
  429. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  430. print '<input type="hidden" name="token" value="'.newToken().'">';
  431. print '<input type="hidden" name="action" value="warehouse">';
  432. /*
  433. * Document templates generators
  434. */
  435. print load_fiche_titre($langs->trans("WarehouseModelModules"), '', '');
  436. // Load array def with activated templates
  437. $def = array();
  438. $sql = "SELECT nom";
  439. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  440. $sql .= " WHERE type = '".$db->escape($type)."'";
  441. $sql .= " AND entity = ".$conf->entity;
  442. $resql = $db->query($sql);
  443. if ($resql) {
  444. $i = 0;
  445. $num_rows = $db->num_rows($resql);
  446. while ($i < $num_rows) {
  447. $array = $db->fetch_array($resql);
  448. array_push($def, $array[0]);
  449. $i++;
  450. }
  451. } else {
  452. dol_print_error($db);
  453. }
  454. print "<table class=\"noborder\" width=\"100%\">\n";
  455. print "<tr class=\"liste_titre\">\n";
  456. print '<td>'.$langs->trans("Name").'</td>';
  457. print '<td>'.$langs->trans("Description").'</td>';
  458. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  459. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  460. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  461. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  462. print "</tr>\n";
  463. clearstatcache();
  464. foreach ($dirmodels as $reldir) {
  465. foreach (array('', '/doc') as $valdir) {
  466. $realpath = $reldir."core/modules/stock".$valdir;
  467. $dir = dol_buildpath($realpath);
  468. if (is_dir($dir)) {
  469. $handle = opendir($dir);
  470. if (is_resource($handle)) {
  471. while (($file = readdir($handle)) !== false) {
  472. $filelist[] = $file;
  473. }
  474. closedir($handle);
  475. arsort($filelist);
  476. foreach ($filelist as $file) {
  477. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  478. if (file_exists($dir.'/'.$file)) {
  479. $name = substr($file, 4, dol_strlen($file) - 16);
  480. $classname = substr($file, 0, dol_strlen($file) - 12);
  481. require_once $dir.'/'.$file;
  482. $module = new $classname($db);
  483. $modulequalified = 1;
  484. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  485. $modulequalified = 0;
  486. }
  487. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  488. $modulequalified = 0;
  489. }
  490. if ($modulequalified) {
  491. print '<tr class="oddeven"><td width="100">';
  492. print (empty($module->name) ? $name : $module->name);
  493. print "</td><td>\n";
  494. if (method_exists($module, 'info')) {
  495. print $module->info($langs);
  496. } else {
  497. print $module->description;
  498. }
  499. print '</td>';
  500. // Active
  501. if (in_array($name, $def)) {
  502. print '<td class="center">'."\n";
  503. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  504. print img_picto($langs->trans("Enabled"), 'switch_on');
  505. print '</a>';
  506. print '</td>';
  507. } else {
  508. print '<td class="center">'."\n";
  509. print '<a class="reposition" 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>';
  510. print "</td>";
  511. }
  512. // Default
  513. print '<td class="center">';
  514. if ($conf->global->STOCK_ADDON_PDF == $name) {
  515. print img_picto($langs->trans("Default"), 'on');
  516. } else {
  517. print '<a class="reposition" 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>';
  518. }
  519. print '</td>';
  520. // Info
  521. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  522. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  523. if ($module->type == 'pdf') {
  524. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  525. }
  526. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  527. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  528. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  529. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  530. print '<td class="center">';
  531. print $form->textwithpicto('', $htmltooltip, 1, 0);
  532. print '</td>';
  533. // Preview
  534. print '<td class="center">';
  535. if ($module->type == 'pdf') {
  536. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  537. } else {
  538. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  539. }
  540. print '</td>';
  541. print "</tr>\n";
  542. }
  543. }
  544. }
  545. }
  546. }
  547. }
  548. }
  549. }
  550. print '</table>';
  551. print '</form>';
  552. // Other
  553. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  554. print '<input type="hidden" name="token" value="'.newToken().'">';
  555. print '<input type="hidden" name="action" value="warehouse">';
  556. print load_fiche_titre($langs->trans("Other"), '', '');
  557. print '<table class="noborder centpercent">';
  558. print '<tr class="liste_titre">';
  559. print "<td>".$langs->trans("Parameter")."</td>\n";
  560. print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
  561. print '</tr>'."\n";
  562. print '<tr class="oddeven">';
  563. print '<td>'.$langs->trans("MainDefaultWarehouse").'</td>';
  564. print '<td class="right">';
  565. print $formproduct->selectWarehouses(!empty($conf->global->MAIN_DEFAULT_WAREHOUSE) ? $conf->global->MAIN_DEFAULT_WAREHOUSE : -1, 'default_warehouse', '', 1, 0, 0, '', 0, 0, array(), 'left reposition');
  566. print '<input type="submit" class="button button-edit small" value="'.$langs->trans("Modify").'">';
  567. print "</td>";
  568. print "</tr>\n";
  569. print '<tr class="oddeven">';
  570. print '<td>'.$langs->trans("UserDefaultWarehouse").'</td>';
  571. print '<td class="right">';
  572. if ($conf->use_javascript_ajax) {
  573. print ajax_constantonoff('MAIN_DEFAULT_WAREHOUSE_USER', array(), null, 0, 0, 1);
  574. } else {
  575. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  576. print $form->selectarray("MAIN_DEFAULT_WAREHOUSE_USER", $arrval, $conf->global->MAIN_DEFAULT_WAREHOUSE_USER);
  577. }
  578. print "</td>\n";
  579. print "</tr>\n";
  580. if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
  581. print '<tr class="oddeven">';
  582. print '<td>'.$langs->trans("UserWarehouseAutoCreate").'</td>';
  583. print '<td class="right">';
  584. if ($conf->use_javascript_ajax) {
  585. print ajax_constantonoff('STOCK_USERSTOCK_AUTOCREATE');
  586. } else {
  587. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  588. print $form->selectarray("STOCK_USERSTOCK_AUTOCREATE", $arrval, $conf->global->STOCK_USERSTOCK_AUTOCREATE);
  589. }
  590. print "</td>\n";
  591. print "</tr>\n";
  592. }
  593. print '<tr class="oddeven">';
  594. print '<td>'.$langs->trans("WarehouseAskWarehouseOnThirparty").'</td>';
  595. print '<td class="right">';
  596. if ($conf->use_javascript_ajax) {
  597. print ajax_constantonoff('SOCIETE_ASK_FOR_WAREHOUSE');
  598. } else {
  599. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  600. print $form->selectarray("SOCIETE_ASK_FOR_WAREHOUSE", $arrval, $conf->global->SOCIETE_ASK_FOR_WAREHOUSE);
  601. }
  602. print "</td>";
  603. print "</tr>\n";
  604. print '<tr class="oddeven">';
  605. print '<td>'.$langs->trans("WarehouseAskWarehouseDuringPropal").'</td>';
  606. print '<td class="right">';
  607. if ($conf->use_javascript_ajax) {
  608. print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL');
  609. } else {
  610. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  611. print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL);
  612. }
  613. print "</td>";
  614. print "</tr>\n";
  615. print '<tr class="oddeven">';
  616. print '<td>'.$langs->trans("WarehouseAskWarehouseDuringOrder").'</td>';
  617. print '<td class="right">';
  618. if ($conf->use_javascript_ajax) {
  619. print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER');
  620. } else {
  621. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  622. print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER);
  623. }
  624. print '</td>';
  625. print "</tr>\n";
  626. /*
  627. print '<tr class="oddeven">';
  628. print '<td>'.$langs->trans("WarehouseAskWarehouseDuringProject").'</td>';
  629. print '<td class="right">';
  630. if ($conf->use_javascript_ajax) {
  631. print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT');
  632. } else {
  633. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  634. print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT);
  635. }
  636. print '</td>';
  637. print "</tr>\n";
  638. */
  639. print '<tr class="oddeven">';
  640. print '<td>';
  641. print $form->textwithpicto($langs->trans("StockSupportServices"), $langs->trans("StockSupportServicesDesc"));
  642. print '</td>';
  643. print '<td class="right">';
  644. if ($conf->use_javascript_ajax) {
  645. print ajax_constantonoff('STOCK_SUPPORTS_SERVICES');
  646. } else {
  647. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  648. print $form->selectarray("STOCK_SUPPORTS_SERVICES", $arrval, $conf->global->STOCK_SUPPORTS_SERVICES);
  649. }
  650. print "</td>\n";
  651. print "</tr>\n";
  652. print '<tr class="oddeven">';
  653. print '<td>'.$langs->trans("AllowAddLimitStockByWarehouse").'</td>';
  654. print '<td class="right">';
  655. if ($conf->use_javascript_ajax) {
  656. print ajax_constantonoff('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE');
  657. } else {
  658. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  659. print $form->selectarray("STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE", $arrval, $conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE);
  660. }
  661. print "</td>\n";
  662. print "</tr>\n";
  663. print '<tr class="oddeven">';
  664. print '<td>'.$langs->trans("AlwaysShowFullArbo").'</td>';
  665. print '<td class="right">';
  666. if ($conf->use_javascript_ajax) {
  667. print ajax_constantonoff('STOCK_ALWAYS_SHOW_FULL_ARBO');
  668. } else {
  669. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  670. print $form->selectarray("STOCK_ALWAYS_SHOW_FULL_ARBO", $arrval, $conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO);
  671. }
  672. print "</td>\n";
  673. print "</tr>\n";
  674. /* Disabled. Would be better to be managed with a user cookie
  675. if (isModEnabled('productbatch')) {
  676. print '<tr class="oddeven">';
  677. print '<td>' . $langs->trans("ShowAllBatchByDefault") . '</td>';
  678. print '<td class="right">';
  679. if ($conf->use_javascript_ajax) {
  680. print ajax_constantonoff('STOCK_SHOW_ALL_BATCH_BY_DEFAULT');
  681. } else {
  682. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  683. print $form->selectarray("STOCK_SHOW_ALL_BATCH_BY_DEFAULT", $arrval, $conf->global->STOCK_SHOW_ALL_BATCH_BY_DEFAULT);
  684. }
  685. print "</td>\n";
  686. print "</tr>\n";
  687. }
  688. */
  689. print '</table>';
  690. print '</form>';
  691. // End of page
  692. llxFooter();
  693. $db->close();