stock.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. $langs->load("productbatch");
  155. $disabled = ' disabled';
  156. print info_admin($langs->trans("WhenProductBatchModuleOnOptionAreForced"));
  157. }
  158. //if (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
  159. //{
  160. print info_admin($langs->trans("IfYouUsePointOfSaleCheckModule"));
  161. print '<br>';
  162. //}
  163. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  164. print '<input type="hidden" name="token" value="'.newToken().'">';
  165. print '<input type="hidden" name="action" value="warehouse">';
  166. // Title rule for stock decrease
  167. print '<table class="noborder centpercent">';
  168. print '<tr class="liste_titre">';
  169. print "<td>".$langs->trans("RuleForStockManagementDecrease")."</td>\n";
  170. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  171. print '</tr>'."\n";
  172. $found = 0;
  173. print '<tr class="oddeven">';
  174. print '<td>'.$langs->trans("DeStockOnBill").'</td>';
  175. print '<td class="right">';
  176. if (isModEnabled('facture')) {
  177. if ($conf->use_javascript_ajax) {
  178. print ajax_constantonoff('STOCK_CALCULATE_ON_BILL', array(), null, 0, 0, 0, 2, 1);
  179. } else {
  180. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  181. print $form->selectarray("STOCK_CALCULATE_ON_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_BILL);
  182. }
  183. } else {
  184. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name"));
  185. }
  186. print "</td>\n</tr>\n";
  187. $found++;
  188. print '<tr class="oddeven">';
  189. print '<td>'.$langs->trans("DeStockOnValidateOrder").'</td>';
  190. print '<td class="right">';
  191. if (isModEnabled('commande')) {
  192. if ($conf->use_javascript_ajax) {
  193. print ajax_constantonoff('STOCK_CALCULATE_ON_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1);
  194. } else {
  195. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  196. print $form->selectarray("STOCK_CALCULATE_ON_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER);
  197. }
  198. } else {
  199. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name"));
  200. }
  201. print "</td>\n</tr>\n";
  202. $found++;
  203. //if (!empty($conf->expedition->enabled))
  204. //{
  205. print '<tr class="oddeven">';
  206. print '<td>'.$langs->trans("DeStockOnShipment").'</td>';
  207. print '<td class="right">';
  208. if (isModEnabled("expedition")) {
  209. if ($conf->use_javascript_ajax) {
  210. print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT', array(), null, 0, 0, 0, 2, 1);
  211. } else {
  212. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  213. print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT);
  214. }
  215. } else {
  216. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
  217. }
  218. print "</td>\n</tr>\n";
  219. $found++;
  220. print '<tr class="oddeven">';
  221. print '<td>'.$langs->trans("DeStockOnShipmentOnClosing").'</td>';
  222. print '<td class="right">';
  223. if (isModEnabled("expedition")) {
  224. if ($conf->use_javascript_ajax) {
  225. print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', array(), null, 0, 0, 0, 2, 1);
  226. } else {
  227. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  228. print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE);
  229. }
  230. } else {
  231. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
  232. }
  233. print "</td>\n</tr>\n";
  234. $found++;
  235. print '</table>';
  236. print '<br>';
  237. // Title rule for stock increase
  238. print '<table class="noborder centpercent">';
  239. print '<tr class="liste_titre">';
  240. print "<td>".$langs->trans("RuleForStockManagementIncrease")."</td>\n";
  241. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  242. print '</tr>'."\n";
  243. $found = 0;
  244. print '<tr class="oddeven">';
  245. print '<td>'.$langs->trans("ReStockOnBill").'</td>';
  246. print '<td class="right">';
  247. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
  248. if ($conf->use_javascript_ajax) {
  249. print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_BILL', array(), null, 0, 0, 0, 2, 1);
  250. } else {
  251. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  252. print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_BILL", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL);
  253. }
  254. } else {
  255. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
  256. }
  257. print "</td>\n</tr>\n";
  258. $found++;
  259. print '<tr class="oddeven">';
  260. print '<td>'.$langs->trans("ReStockOnValidateOrder").'</td>';
  261. print '<td class="right">';
  262. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
  263. if ($conf->use_javascript_ajax) {
  264. print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1);
  265. } else {
  266. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  267. print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER);
  268. }
  269. } else {
  270. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
  271. }
  272. print "</td>\n</tr>\n";
  273. $found++;
  274. if (isModEnabled("reception")) {
  275. print '<tr class="oddeven">';
  276. print '<td>'.$langs->trans("StockOnReception").'</td>';
  277. print '<td class="right">';
  278. if ($conf->use_javascript_ajax) {
  279. print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION', array(), null, 0, 0, 0, 2, 1);
  280. } else {
  281. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  282. print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION);
  283. }
  284. print "</td>\n</tr>\n";
  285. $found++;
  286. print '<tr class="oddeven">';
  287. print '<td>'.$langs->trans("StockOnReceptionOnClosing").'</td>';
  288. print '<td class="right">';
  289. if ($conf->use_javascript_ajax) {
  290. print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION_CLOSE', array(), null, 0, 0, 0, 2, 1);
  291. } else {
  292. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  293. print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE);
  294. }
  295. print "</td>\n</tr>\n";
  296. $found++;
  297. } else {
  298. print '<tr class="oddeven">';
  299. print '<td>'.$langs->trans("ReStockOnDispatchOrder").'</td>';
  300. print '<td class="right">';
  301. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order")) {
  302. if ($conf->use_javascript_ajax) {
  303. print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', array(), null, 0, 0, 0, 2, 1);
  304. } else {
  305. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  306. print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER);
  307. }
  308. } else {
  309. print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
  310. }
  311. print "</td>\n</tr>\n";
  312. $found++;
  313. }
  314. print '</table>';
  315. print '<br>';
  316. print '<table class="noborder centpercent">';
  317. print '<tr class="liste_titre">';
  318. print "<td>".$langs->trans("RuleForStockAvailability")."</td>\n";
  319. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  320. print '</tr>'."\n";
  321. print '<tr class="oddeven">';
  322. print '<td>'.$langs->trans("WarehouseAllowNegativeTransfer").'</td>';
  323. print '<td class="right">';
  324. if ($conf->use_javascript_ajax) {
  325. print ajax_constantonoff('STOCK_ALLOW_NEGATIVE_TRANSFER');
  326. } else {
  327. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  328. print $form->selectarray("STOCK_ALLOW_NEGATIVE_TRANSFER", $arrval, $conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER);
  329. }
  330. print "</td>\n";
  331. print "</tr>\n";
  332. // Option to force stock to be enough before adding a line into document
  333. if (isModEnabled('facture')) {
  334. print '<tr class="oddeven">';
  335. print '<td>'.$langs->trans("StockMustBeEnoughForInvoice").'</td>';
  336. print '<td class="right">';
  337. if ($conf->use_javascript_ajax) {
  338. print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_INVOICE');
  339. } else {
  340. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  341. print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_INVOICE", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE);
  342. }
  343. print "</td>\n";
  344. print "</tr>\n";
  345. }
  346. if (isModEnabled('commande')) {
  347. print '<tr class="oddeven">';
  348. print '<td>'.$langs->trans("StockMustBeEnoughForOrder").'</td>';
  349. print '<td class="right">';
  350. if ($conf->use_javascript_ajax) {
  351. print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_ORDER');
  352. } else {
  353. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  354. print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_ORDER", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER);
  355. }
  356. print "</td>\n";
  357. print "</tr>\n";
  358. }
  359. if (isModEnabled("expedition")) {
  360. print '<tr class="oddeven">';
  361. print '<td>'.$langs->trans("StockMustBeEnoughForShipment").'</td>';
  362. print '<td class="right">';
  363. if ($conf->use_javascript_ajax) {
  364. print ajax_constantonoff('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT');
  365. } else {
  366. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  367. print $form->selectarray("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", $arrval, $conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT);
  368. }
  369. print "</td>\n";
  370. print "</tr>\n";
  371. }
  372. print '</table>';
  373. print '<br>';
  374. $virtualdiffersfromphysical = 0;
  375. if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
  376. || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
  377. || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
  378. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
  379. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
  380. || isModEnabled('mrp')) {
  381. $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
  382. }
  383. if ($virtualdiffersfromphysical) {
  384. print '<table class="noborder centpercent">';
  385. print '<tr class="liste_titre">';
  386. print "<td>".$langs->trans("RuleForStockReplenishment")." ".img_help('help', $langs->trans("VirtualDiffersFromPhysical"))."</td>\n";
  387. print '<td class="right">'.$langs->trans("Status").'</td>'."\n";
  388. print '</tr>'."\n";
  389. print '<tr class="oddeven">';
  390. print '<td>';
  391. print $form->textwithpicto($langs->trans("UseRealStockByDefault"), $langs->trans("ReplenishmentCalculation"));
  392. print '</td>';
  393. print '<td class="right">';
  394. if ($conf->use_javascript_ajax) {
  395. print ajax_constantonoff('STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT');
  396. } else {
  397. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  398. print $form->selectarray("STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT", $arrval, $conf->global->STOCK_USE_REAL_STOCK_BY_DEFAULT_FOR_REPLENISHMENT);
  399. }
  400. print "</td>\n";
  401. print "</tr>\n";
  402. print '</table>';
  403. print '<br>';
  404. }
  405. print '<form>';
  406. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  407. print '<input type="hidden" name="token" value="'.newToken().'">';
  408. print '<input type="hidden" name="action" value="warehouse">';
  409. /*
  410. * Document templates generators
  411. */
  412. print load_fiche_titre($langs->trans("WarehouseModelModules"), '', '');
  413. // Load array def with activated templates
  414. $def = array();
  415. $sql = "SELECT nom";
  416. $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
  417. $sql .= " WHERE type = '".$db->escape($type)."'";
  418. $sql .= " AND entity = ".$conf->entity;
  419. $resql = $db->query($sql);
  420. if ($resql) {
  421. $i = 0;
  422. $num_rows = $db->num_rows($resql);
  423. while ($i < $num_rows) {
  424. $array = $db->fetch_array($resql);
  425. array_push($def, $array[0]);
  426. $i++;
  427. }
  428. } else {
  429. dol_print_error($db);
  430. }
  431. print "<table class=\"noborder\" width=\"100%\">\n";
  432. print "<tr class=\"liste_titre\">\n";
  433. print '<td>'.$langs->trans("Name").'</td>';
  434. print '<td>'.$langs->trans("Description").'</td>';
  435. print '<td class="center" width="60">'.$langs->trans("Status")."</td>\n";
  436. print '<td class="center" width="60">'.$langs->trans("Default")."</td>\n";
  437. print '<td class="center" width="38">'.$langs->trans("ShortInfo").'</td>';
  438. print '<td class="center" width="38">'.$langs->trans("Preview").'</td>';
  439. print "</tr>\n";
  440. clearstatcache();
  441. foreach ($dirmodels as $reldir) {
  442. foreach (array('', '/doc') as $valdir) {
  443. $realpath = $reldir."core/modules/stock".$valdir;
  444. $dir = dol_buildpath($realpath);
  445. if (is_dir($dir)) {
  446. $handle = opendir($dir);
  447. if (is_resource($handle)) {
  448. while (($file = readdir($handle)) !== false) {
  449. $filelist[] = $file;
  450. }
  451. closedir($handle);
  452. arsort($filelist);
  453. foreach ($filelist as $file) {
  454. if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
  455. if (file_exists($dir.'/'.$file)) {
  456. $name = substr($file, 4, dol_strlen($file) - 16);
  457. $classname = substr($file, 0, dol_strlen($file) - 12);
  458. require_once $dir.'/'.$file;
  459. $module = new $classname($db);
  460. $modulequalified = 1;
  461. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
  462. $modulequalified = 0;
  463. }
  464. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
  465. $modulequalified = 0;
  466. }
  467. if ($modulequalified) {
  468. print '<tr class="oddeven"><td width="100">';
  469. print (empty($module->name) ? $name : $module->name);
  470. print "</td><td>\n";
  471. if (method_exists($module, 'info')) {
  472. print $module->info($langs);
  473. } else {
  474. print $module->description;
  475. }
  476. print '</td>';
  477. // Active
  478. if (in_array($name, $def)) {
  479. print '<td class="center">'."\n";
  480. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'">';
  481. print img_picto($langs->trans("Enabled"), 'switch_on');
  482. print '</a>';
  483. print '</td>';
  484. } else {
  485. print '<td class="center">'."\n";
  486. 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>';
  487. print "</td>";
  488. }
  489. // Default
  490. print '<td class="center">';
  491. if ($conf->global->STOCK_ADDON_PDF == $name) {
  492. print img_picto($langs->trans("Default"), 'on');
  493. } else {
  494. 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>';
  495. }
  496. print '</td>';
  497. // Info
  498. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  499. $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
  500. if ($module->type == 'pdf') {
  501. $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  502. }
  503. $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
  504. $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  505. $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
  506. $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
  507. print '<td class="center">';
  508. print $form->textwithpicto('', $htmltooltip, 1, 0);
  509. print '</td>';
  510. // Preview
  511. print '<td class="center">';
  512. if ($module->type == 'pdf') {
  513. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
  514. } else {
  515. print img_object($langs->trans("PreviewNotAvailable"), 'generic');
  516. }
  517. print '</td>';
  518. print "</tr>\n";
  519. }
  520. }
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. print '</table>';
  528. print '</form>';
  529. // Other
  530. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  531. print '<input type="hidden" name="token" value="'.newToken().'">';
  532. print '<input type="hidden" name="action" value="warehouse">';
  533. print load_fiche_titre($langs->trans("Other"), '', '');
  534. print '<table class="noborder centpercent">';
  535. print '<tr class="liste_titre">';
  536. print "<td>".$langs->trans("Parameter")."</td>\n";
  537. print '<td class="right">'.$langs->trans("Value").'</td>'."\n";
  538. print '</tr>'."\n";
  539. print '<tr class="oddeven">';
  540. print '<td>'.$langs->trans("MainDefaultWarehouse").'</td>';
  541. print '<td class="right">';
  542. 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');
  543. print '<input type="submit" class="button button-edit small" value="'.$langs->trans("Modify").'">';
  544. print "</td>";
  545. print "</tr>\n";
  546. print '<tr class="oddeven">';
  547. print '<td>'.$langs->trans("UserDefaultWarehouse").'</td>';
  548. print '<td class="right">';
  549. if ($conf->use_javascript_ajax) {
  550. print ajax_constantonoff('MAIN_DEFAULT_WAREHOUSE_USER', array(), null, 0, 0, 1);
  551. } else {
  552. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  553. print $form->selectarray("MAIN_DEFAULT_WAREHOUSE_USER", $arrval, $conf->global->MAIN_DEFAULT_WAREHOUSE_USER);
  554. }
  555. print "</td>\n";
  556. print "</tr>\n";
  557. if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
  558. print '<tr class="oddeven">';
  559. print '<td>'.$langs->trans("UserWarehouseAutoCreate").'</td>';
  560. print '<td class="right">';
  561. if ($conf->use_javascript_ajax) {
  562. print ajax_constantonoff('STOCK_USERSTOCK_AUTOCREATE');
  563. } else {
  564. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  565. print $form->selectarray("STOCK_USERSTOCK_AUTOCREATE", $arrval, $conf->global->STOCK_USERSTOCK_AUTOCREATE);
  566. }
  567. print "</td>\n";
  568. print "</tr>\n";
  569. }
  570. print '<tr class="oddeven">';
  571. print '<td>'.$langs->trans("WarehouseAskWarehouseOnThirparty").'</td>';
  572. print '<td class="right">';
  573. if ($conf->use_javascript_ajax) {
  574. print ajax_constantonoff('SOCIETE_ASK_FOR_WAREHOUSE');
  575. } else {
  576. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  577. print $form->selectarray("SOCIETE_ASK_FOR_WAREHOUSE", $arrval, $conf->global->SOCIETE_ASK_FOR_WAREHOUSE);
  578. }
  579. print "</td>";
  580. print "</tr>\n";
  581. print '<tr class="oddeven">';
  582. print '<td>'.$langs->trans("WarehouseAskWarehouseDuringPropal").'</td>';
  583. print '<td class="right">';
  584. if ($conf->use_javascript_ajax) {
  585. print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL');
  586. } else {
  587. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  588. print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL);
  589. }
  590. print "</td>";
  591. print "</tr>\n";
  592. print '<tr class="oddeven">';
  593. print '<td>'.$langs->trans("WarehouseAskWarehouseDuringOrder").'</td>';
  594. print '<td class="right">';
  595. if ($conf->use_javascript_ajax) {
  596. print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER');
  597. } else {
  598. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  599. print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER);
  600. }
  601. print '</td>';
  602. print "</tr>\n";
  603. /*
  604. print '<tr class="oddeven">';
  605. print '<td>'.$langs->trans("WarehouseAskWarehouseDuringProject").'</td>';
  606. print '<td class="right">';
  607. if ($conf->use_javascript_ajax) {
  608. print ajax_constantonoff('WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT');
  609. } else {
  610. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  611. print $form->selectarray("WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT", $arrval, $conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROJECT);
  612. }
  613. print '</td>';
  614. print "</tr>\n";
  615. */
  616. print '<tr class="oddeven">';
  617. print '<td>';
  618. print $form->textwithpicto($langs->trans("StockSupportServices"), $langs->trans("StockSupportServicesDesc"));
  619. print '</td>';
  620. print '<td class="right">';
  621. if ($conf->use_javascript_ajax) {
  622. print ajax_constantonoff('STOCK_SUPPORTS_SERVICES');
  623. } else {
  624. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  625. print $form->selectarray("STOCK_SUPPORTS_SERVICES", $arrval, $conf->global->STOCK_SUPPORTS_SERVICES);
  626. }
  627. print "</td>\n";
  628. print "</tr>\n";
  629. print '<tr class="oddeven">';
  630. print '<td>'.$langs->trans("AllowAddLimitStockByWarehouse").'</td>';
  631. print '<td class="right">';
  632. if ($conf->use_javascript_ajax) {
  633. print ajax_constantonoff('STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE');
  634. } else {
  635. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  636. print $form->selectarray("STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE", $arrval, $conf->global->STOCK_ALLOW_ADD_LIMIT_STOCK_BY_WAREHOUSE);
  637. }
  638. print "</td>\n";
  639. print "</tr>\n";
  640. print '<tr class="oddeven">';
  641. print '<td>'.$langs->trans("AlwaysShowFullArbo").'</td>';
  642. print '<td class="right">';
  643. if ($conf->use_javascript_ajax) {
  644. print ajax_constantonoff('STOCK_ALWAYS_SHOW_FULL_ARBO');
  645. } else {
  646. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  647. print $form->selectarray("STOCK_ALWAYS_SHOW_FULL_ARBO", $arrval, $conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO);
  648. }
  649. print "</td>\n";
  650. print "</tr>\n";
  651. /* Disabled. Would be better to be managed with a user cookie
  652. if (isModEnabled('productbatch')) {
  653. print '<tr class="oddeven">';
  654. print '<td>' . $langs->trans("ShowAllBatchByDefault") . '</td>';
  655. print '<td class="right">';
  656. if ($conf->use_javascript_ajax) {
  657. print ajax_constantonoff('STOCK_SHOW_ALL_BATCH_BY_DEFAULT');
  658. } else {
  659. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  660. print $form->selectarray("STOCK_SHOW_ALL_BATCH_BY_DEFAULT", $arrval, $conf->global->STOCK_SHOW_ALL_BATCH_BY_DEFAULT);
  661. }
  662. print "</td>\n";
  663. print "</tr>\n";
  664. }
  665. */
  666. print '</table>';
  667. print '</form>';
  668. // End of page
  669. llxFooter();
  670. $db->close();