stock.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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@capnetworks.com>
  5. * Copyright (C) 2012-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/stock.php
  24. * \ingroup stock
  25. * \brief Page d'administration/configuration du module gestion de stock
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. $langs->load("admin");
  30. $langs->load("stocks");
  31. // Securit check
  32. if (!$user->admin) accessforbidden();
  33. $action = GETPOST('action','alpha');
  34. /*
  35. * Actions
  36. */
  37. if ($action == 'STOCK_USERSTOCK_AUTOCREATE')
  38. {
  39. $db->begin();
  40. $res = dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", GETPOST('STOCK_USERSTOCK_AUTOCREATE','alpha'),'chaine',0,'',$conf->entity);
  41. }
  42. // Mode of stock decrease
  43. if ($action == 'STOCK_CALCULATE_ON_BILL'
  44. || $action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER'
  45. || $action == 'STOCK_CALCULATE_ON_SHIPMENT')
  46. {
  47. $db->begin();
  48. $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", '','chaine',0,'',$conf->entity);
  49. $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", '','chaine',0,'',$conf->entity);
  50. $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", '','chaine',0,'',$conf->entity);
  51. if ($action == 'STOCK_CALCULATE_ON_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", GETPOST('STOCK_CALCULATE_ON_BILL','alpha'),'chaine',0,'',$conf->entity);
  52. if ($action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity);
  53. if ($action == 'STOCK_CALCULATE_ON_SHIPMENT') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", GETPOST('STOCK_CALCULATE_ON_SHIPMENT','alpha'),'chaine',0,'',$conf->entity);
  54. }
  55. // Mode of stock increase
  56. if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL'
  57. || $action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER'
  58. || $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')
  59. {
  60. $db->begin();
  61. $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity);
  62. $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity);
  63. $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity);
  64. if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity);
  65. if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity);
  66. if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity);
  67. }
  68. if($action == 'USE_VIRTUAL_STOCK') {
  69. $db->begin();
  70. $res = dolibarr_set_const($db, "USE_VIRTUAL_STOCK", GETPOST('USE_VIRTUAL_STOCK','alpha'),'chaine',0,'',$conf->entity);
  71. }
  72. if($action)
  73. {
  74. if (! $res > 0) $error++;
  75. if (! $error)
  76. {
  77. $db->commit();
  78. setEventMessage($langs->trans("SetupSaved"));
  79. }
  80. else
  81. {
  82. $db->rollback();
  83. setEventMessage($langs->trans("Error"),'errors');
  84. }
  85. }
  86. /*
  87. * View
  88. */
  89. llxHeader('',$langs->trans("StockSetup"));
  90. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  91. print_fiche_titre($langs->trans("StockSetup"),$linkback,'setup');
  92. $form=new Form($db);
  93. $var=true;
  94. print '<table class="noborder" width="100%">';
  95. print '<tr class="liste_titre">';
  96. print " <td>".$langs->trans("Parameters")."</td>\n";
  97. print " <td align=\"right\" width=\"160\">&nbsp;</td>\n";
  98. print '</tr>'."\n";
  99. /*
  100. * Formulaire parametres divers
  101. */
  102. $var=!$var;
  103. print "<tr ".$bc[$var].">";
  104. print '<td width="60%">'.$langs->trans("UserWarehouseAutoCreate").'</td>';
  105. print '<td width="160" align="right">';
  106. print "<form method=\"post\" action=\"stock.php\">";
  107. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  108. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_USERSTOCK_AUTOCREATE\">";
  109. print $form->selectyesno("STOCK_USERSTOCK_AUTOCREATE",$conf->global->STOCK_USERSTOCK_AUTOCREATE,1);
  110. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  111. print '</form>';
  112. print "</td>\n";
  113. print "</tr>\n";
  114. print '<br>';
  115. print '</table>';
  116. print '<br>';
  117. // Title rule for stock decrease
  118. print '<table class="noborder" width="100%">';
  119. print '<tr class="liste_titre">';
  120. print " <td>".$langs->trans("RuleForStockManagementDecrease")."</td>\n";
  121. print " <td align=\"right\" width=\"160\">&nbsp;</td>\n";
  122. print '</tr>'."\n";
  123. $var=true;
  124. if (! empty($conf->facture->enabled))
  125. {
  126. $var=!$var;
  127. print "<tr ".$bc[$var].">";
  128. print '<td width="60%">'.$langs->trans("DeStockOnBill").'</td>';
  129. print '<td width="160" align="right">';
  130. print "<form method=\"post\" action=\"stock.php\">";
  131. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  132. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_BILL\">";
  133. print $form->selectyesno("STOCK_CALCULATE_ON_BILL",$conf->global->STOCK_CALCULATE_ON_BILL,1);
  134. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  135. print "</form>\n</td>\n</tr>\n";
  136. }
  137. if (! empty($conf->commande->enabled))
  138. {
  139. $var=!$var;
  140. print "<tr ".$bc[$var].">";
  141. print '<td width="60%">'.$langs->trans("DeStockOnValidateOrder").'</td>';
  142. print '<td width="160" align="right">';
  143. print "<form method=\"post\" action=\"stock.php\">";
  144. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  145. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_VALIDATE_ORDER\">";
  146. print $form->selectyesno("STOCK_CALCULATE_ON_VALIDATE_ORDER",$conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER,1);
  147. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  148. print "</form>\n</td>\n</tr>\n";
  149. }
  150. if (! empty($conf->expedition->enabled))
  151. {
  152. $var=!$var;
  153. print "<tr ".$bc[$var].">";
  154. print '<td width="60%">'.$langs->trans("DeStockOnShipment").'</td>';
  155. print '<td width="160" align="right">';
  156. print "<form method=\"post\" action=\"stock.php\">";
  157. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  158. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_SHIPMENT\">";
  159. print $form->selectyesno("STOCK_CALCULATE_ON_SHIPMENT",$conf->global->STOCK_CALCULATE_ON_SHIPMENT,1);
  160. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  161. print "</form>\n</td>\n</tr>\n";
  162. }
  163. print '</table>';
  164. print '<br>';
  165. // Title rule for stock increase
  166. print '<table class="noborder" width="100%">';
  167. print '<tr class="liste_titre">';
  168. print " <td>".$langs->trans("RuleForStockManagementIncrease")."</td>\n";
  169. print " <td align=\"right\" width=\"160\">&nbsp;</td>\n";
  170. print '</tr>'."\n";
  171. $var=true;
  172. if (! empty($conf->fournisseur->enabled))
  173. {
  174. $var=!$var;
  175. print "<tr ".$bc[$var].">";
  176. print '<td width="60%">'.$langs->trans("ReStockOnBill").'</td>';
  177. print '<td width="160" align="right">';
  178. print "<form method=\"post\" action=\"stock.php\">";
  179. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  180. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_SUPPLIER_BILL\">";
  181. print $form->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_BILL",$conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL,1);
  182. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  183. print "</form>\n</td>\n</tr>\n";
  184. }
  185. if (! empty($conf->fournisseur->enabled))
  186. {
  187. $var=!$var;
  188. print "<tr ".$bc[$var].">";
  189. print '<td width="60%">'.$langs->trans("ReStockOnValidateOrder").'</td>';
  190. print '<td width="160" align="right">';
  191. print "<form method=\"post\" action=\"stock.php\">";
  192. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  193. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER\">";
  194. print $form->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER",$conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER,1);
  195. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  196. print "</form>\n</td>\n</tr>\n";
  197. }
  198. if (! empty($conf->fournisseur->enabled))
  199. {
  200. $var=!$var;
  201. print "<tr ".$bc[$var].">";
  202. print '<td width="60%">'.$langs->trans("ReStockOnDispatchOrder").'</td>';
  203. print '<td width="160" align="right">';
  204. print "<form method=\"post\" action=\"stock.php\">";
  205. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  206. print "<input type=\"hidden\" name=\"action\" value=\"STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER\">";
  207. print $form->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER",$conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER,1);
  208. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  209. print "</form>\n</td>\n</tr>\n";
  210. }
  211. print '</table>';
  212. print '<br>';
  213. print '<table class="noborder" width="100%">';
  214. print '<tr class="liste_titre">';
  215. print " <td>".$langs->trans("RuleForStockReplenishment")."</td>\n";
  216. print " <td align=\"right\" width=\"160\">&nbsp;</td>\n";
  217. print '</tr>'."\n";
  218. $var = !$var;
  219. print "<tr ".$bc[$var].">";
  220. print '<td width="60%">'.$langs->trans("UseVirtualStock").'</td>';
  221. print '<td width="160" align="right">';
  222. print "<form method=\"post\" action=\"stock.php\">";
  223. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  224. print "<input type=\"hidden\" name=\"action\" value=\"USE_VIRTUAL_STOCK\">";
  225. print $form->selectyesno("USE_VIRTUAL_STOCK",$conf->global->USE_VIRTUAL_STOCK,1);
  226. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  227. print '</form>';
  228. print "</td>\n";
  229. print "</tr>\n";
  230. print '</table>';
  231. $db->close();
  232. llxFooter();
  233. ?>