index.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  6. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/product/stock/index.php
  23. * \ingroup stock
  24. * \brief Home page of stock area
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  31. $hookmanager = new HookManager($db);
  32. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  33. $hookmanager->initHooks(array('stockindex'));
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('stocks', 'productbatch'));
  36. // Security check
  37. $result = restrictedArea($user, 'stock');
  38. /*
  39. * View
  40. */
  41. $producttmp = new Product($db);
  42. $warehouse = new Entrepot($db);
  43. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  44. llxHeader("", $langs->trans("Stocks"), $help_url);
  45. print load_fiche_titre($langs->trans("StocksArea"), '', 'stock');
  46. //print '<table border="0" width="100%" class="notopnoleftnoright">';
  47. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  48. print '<div class="fichecenter"><div class="fichethirdleft">';
  49. if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This may be useless due to the global search combo
  50. print '<form method="post" action="'.DOL_URL_ROOT.'/product/stock/list.php">';
  51. print '<input type="hidden" name="token" value="'.newToken().'">';
  52. print '<div class="div-table-responsive-no-min">';
  53. print '<table class="noborder nohover centpercent">';
  54. print "<tr class=\"liste_titre\">";
  55. print '<td colspan="3">'.$langs->trans("Search").'</td></tr>';
  56. print '<tr class="oddevene"><td>';
  57. print $langs->trans("Warehouse").':</td><td><input class="flat" type="text" size="18" name="sall"></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  58. print "</table></div></form><br>";
  59. }
  60. $max = 15;
  61. $sql = "SELECT e.rowid, e.ref as label, e.lieu, e.statut as status";
  62. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
  63. $sql .= " WHERE e.statut in (".Entrepot::STATUS_CLOSED.",".Entrepot::STATUS_OPEN_ALL.")";
  64. $sql .= " AND e.entity IN (".getEntity('stock').")";
  65. $sql .= $db->order('e.statut', 'DESC');
  66. $sql .= $db->plimit($max + 1, 0);
  67. $result = $db->query($sql);
  68. if ($result) {
  69. $num = $db->num_rows($result);
  70. print '<div class="div-table-responsive-no-min">';
  71. print '<table class="noborder centpercent">';
  72. print '<tr class="liste_titre">';
  73. print '<th colspan="2">';
  74. print $langs->trans("Warehouses").' ';
  75. print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php">';
  76. // TODO: "search_status" on "/product/stock/list.php" currently only accept a single integer value
  77. //print '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?search_status='.Entrepot::STATUS_CLOSED.','.Entrepot::STATUS_OPEN_ALL.'">';
  78. print '<span class="badge">'.$num.'</span>';
  79. print '</a>';
  80. print '</th>';
  81. print '</tr>';
  82. $i = 0;
  83. if ($num) {
  84. while ($i < min($max, $num)) {
  85. $objp = $db->fetch_object($result);
  86. $warehouse->id = $objp->rowid;
  87. $warehouse->statut = $objp->status;
  88. $warehouse->label = $objp->label;
  89. $warehouse->lieu = $objp->lieu;
  90. print '<tr class="oddeven">';
  91. print '<td>';
  92. print $warehouse->getNomUrl(1);
  93. print '</td>'."\n";
  94. print '<td class="right">';
  95. print $warehouse->getLibStatut(5);
  96. print '</td>';
  97. print "</tr>\n";
  98. $i++;
  99. }
  100. $db->free($result);
  101. } else {
  102. print '<tr><td>'.$langs->trans("None").'</td><td></td></tr>';
  103. }
  104. if ($num > $max) {
  105. print '<tr><td><span class="opacitymedium">'.$langs->trans("More").'...</span></td><td></td></tr>';
  106. }
  107. print "</table>";
  108. print '</div>';
  109. } else {
  110. dol_print_error($db);
  111. }
  112. print '</div><div class="fichetwothirdright">';
  113. // Latest movements
  114. $max = 10;
  115. $sql = "SELECT p.rowid, p.label as produit, p.tobatch, p.tosell, p.tobuy,";
  116. $sql .= " e.ref as warehouse_ref, e.rowid as warehouse_id, e.ref as warehouse_label, e.lieu, e.statut as warehouse_status,";
  117. $sql .= " m.rowid as mid, m.value as qty, m.datem, m.batch, m.eatby, m.sellby";
  118. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
  119. $sql .= ", ".MAIN_DB_PREFIX."stock_mouvement as m";
  120. $sql .= ", ".MAIN_DB_PREFIX."product as p";
  121. $sql .= " WHERE m.fk_product = p.rowid";
  122. $sql .= " AND m.fk_entrepot = e.rowid";
  123. $sql .= " AND e.entity IN (".getEntity('stock').")";
  124. if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  125. $sql .= " AND p.fk_product_type = ".Product::TYPE_PRODUCT;
  126. }
  127. $sql .= $db->order("datem", "DESC");
  128. $sql .= $db->plimit($max, 0);
  129. dol_syslog("Index:list stock movements", LOG_DEBUG);
  130. $resql = $db->query($sql);
  131. if ($resql) {
  132. $num = $db->num_rows($resql);
  133. print '<div class="div-table-responsive-no-min">';
  134. print '<table class="noborder centpercent">';
  135. print '<tr class="liste_titre">';
  136. print '<th>'.$langs->trans("LastMovements", min($num, $max)).'</th>';
  137. print '<th>'.$langs->trans("Product").'</th>';
  138. if (isModEnabled('productbatch')) {
  139. print '<th>'.$langs->trans("Batch").'</th>';
  140. /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  141. print '<th>'.$langs->trans("SellByDate").'</th>';
  142. }
  143. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  144. print '<th>'.$langs->trans("EatByDate").'</th>';
  145. }*/
  146. }
  147. print '<th>'.$langs->trans("Warehouse").'</th>';
  148. print '<th class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/product/stock/movement_list.php">'.$langs->trans("FullList").'</a></th>';
  149. print "</tr>\n";
  150. $tmplotstatic = new Productlot($db);
  151. $i = 0;
  152. while ($i < min($num, $max)) {
  153. $objp = $db->fetch_object($resql);
  154. $producttmp->id = $objp->rowid;
  155. $producttmp->ref = $objp->produit;
  156. $producttmp->status_batch = $objp->tobatch;
  157. $producttmp->status_sell = $objp->tosell;
  158. $producttmp->status_buy = $objp->tobuy;
  159. $warehouse->id = $objp->warehouse_id;
  160. $warehouse->ref = $objp->warehouse_ref;
  161. $warehouse->statut = $objp->warehouse_status;
  162. $warehouse->label = $objp->warehouse_label;
  163. $warehouse->lieu = $objp->lieu;
  164. $tmplotstatic->batch = $objp->batch;
  165. $tmplotstatic->sellby = $objp->sellby;
  166. $tmplotstatic->eatby = $objp->eatby;
  167. print '<tr class="oddeven">';
  168. print '<td class="nowraponall">'.img_picto($langs->trans("Ref").' '.$objp->mid, 'movement', 'class="pictofixedwidth"').dol_print_date($db->jdate($objp->datem), 'dayhour').'</td>';
  169. print '<td class="tdoverflowmax150">';
  170. print $producttmp->getNomUrl(1);
  171. print "</td>\n";
  172. if (isModEnabled('productbatch')) {
  173. print '<td>';
  174. print $tmplotstatic->getNomUrl(0, 'nolink');
  175. print '</td>';
  176. /*if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  177. print '<td>'.dol_print_date($db->jdate($objp->sellby), 'day').'</td>';
  178. }
  179. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  180. print '<td>'.dol_print_date($db->jdate($objp->eatby), 'day').'</td>';
  181. }*/
  182. }
  183. print '<td class="tdoverflowmax150">';
  184. print $warehouse->getNomUrl(1);
  185. print "</td>\n";
  186. print '<td class="right">';
  187. if ($objp->qty > 0) {
  188. print '+';
  189. }
  190. print $objp->qty.'</td>';
  191. print "</tr>\n";
  192. $i++;
  193. }
  194. $db->free($resql);
  195. print "</table>";
  196. print '</div>';
  197. } else {
  198. dol_print_error($db);
  199. }
  200. print '</div></div>';
  201. $parameters = array('user' => $user);
  202. $reshook = $hookmanager->executeHooks('dashboardWarehouse', $parameters, $object); // Note that $action and $object may have been modified by hook
  203. // End of page
  204. llxFooter();
  205. $db->close();