reassort.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2023 Vincent de Grandpré <vincent@de-grandpre.quebec>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/product/reassort.php
  25. * \ingroup produit
  26. * \brief Page to list stocks
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('products', 'stocks'));
  36. $action = GETPOST('action', 'aZ09');
  37. $sref = GETPOST("sref", 'alpha');
  38. $snom = GETPOST("snom", 'alpha');
  39. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  40. $type = GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT;
  41. $search_barcode = GETPOST("search_barcode", 'alpha');
  42. $search_toolowstock = GETPOST('search_toolowstock');
  43. $tosell = GETPOST("tosell");
  44. $tobuy = GETPOST("tobuy");
  45. $fourn_id = GETPOST("fourn_id", 'int');
  46. $sbarcode = GETPOST("sbarcode", 'int');
  47. $search_stock_physique = GETPOST('search_stock_physique', 'alpha');
  48. $sortfield = GETPOST('sortfield', 'aZ09comma');
  49. $sortorder = GETPOST('sortorder', 'aZ09comma');
  50. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  51. if (empty($page) || $page < 0) {
  52. $page = 0;
  53. }
  54. if (!$sortfield) {
  55. $sortfield = "p.ref";
  56. }
  57. if (!$sortorder) {
  58. $sortorder = "ASC";
  59. }
  60. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  61. if (empty($page) || $page == -1) {
  62. $page = 0;
  63. } // If $page is not defined, or '' or -1
  64. $offset = $limit * $page;
  65. // Load sale and categ filters
  66. $search_sale = GETPOST("search_sale");
  67. if (GETPOSTISSET('catid')) {
  68. $search_categ = GETPOST('catid', 'int');
  69. } else {
  70. $search_categ = GETPOST('search_categ', 'int');
  71. }
  72. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  73. $canvas = GETPOST("canvas");
  74. $objcanvas = null;
  75. if (!empty($canvas)) {
  76. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  77. $objcanvas = new Canvas($db, $action);
  78. $objcanvas->getCanvas('product', 'list', $canvas);
  79. }
  80. // Define virtualdiffersfromphysical
  81. $virtualdiffersfromphysical = 0;
  82. if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')
  83. || getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')
  84. || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')
  85. || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION')
  86. || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')
  87. || isModEnabled('mrp')) {
  88. $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
  89. }
  90. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  91. $hookmanager->initHooks(array('productreassortlist'));
  92. if ($user->socid) {
  93. $socid = $user->socid;
  94. }
  95. $result = restrictedArea($user, 'produit|service', 0, 'product&product');
  96. $object = new Product($db);
  97. /*
  98. * Actions
  99. */
  100. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  101. $sref = "";
  102. $snom = "";
  103. $sall = "";
  104. $tosell = "";
  105. $tobuy = "";
  106. $search_sale = "";
  107. $search_categ = "";
  108. $search_toolowstock = '';
  109. $fourn_id = '';
  110. $sbarcode = '';
  111. $search_stock_physique = '';
  112. }
  113. /*
  114. * View
  115. */
  116. $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  117. $form = new Form($db);
  118. $htmlother = new FormOther($db);
  119. if (!empty($objp->stock_physique) && $objp->stock_physique < 0) {
  120. print '<span class="warning">';
  121. }
  122. $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
  123. $sql .= ' p.fk_product_type, p.tms as datem,';
  124. $sql .= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
  125. $sql .= ' SUM(s.reel) as stock_physique';
  126. if (getDolGlobalString('PRODUCT_USE_UNITS')) {
  127. $sql .= ', u.short_label as unit_short';
  128. }
  129. // Add fields from hooks
  130. $parameters = array();
  131. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  132. $sql .= $hookmanager->resPrint;
  133. $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
  134. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product';
  135. if (getDolGlobalString('PRODUCT_USE_UNITS')) {
  136. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_units as u on p.fk_unit = u.rowid';
  137. }
  138. // Add table from hooks
  139. $parameters = array();
  140. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  141. $sql .= $hookmanager->resPrint;
  142. $sql .= " WHERE p.entity IN (".getEntity('product').")";
  143. if (!empty($search_categ) && $search_categ != '-1') {
  144. $sql .= " AND ";
  145. if ($search_categ == -2) {
  146. $sql .= " NOT EXISTS ";
  147. } else {
  148. $sql .= " EXISTS ";
  149. }
  150. $sql .= "(";
  151. $sql .= " SELECT cp.fk_categorie, cp.fk_product";
  152. $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_product as cp";
  153. $sql .= " WHERE cp.fk_product = p.rowid"; // Join for the needed table to filter by categ
  154. if ($search_categ > 0) {
  155. $sql .= " AND cp.fk_categorie = " . ((int) $search_categ);
  156. }
  157. $sql .= ")";
  158. }
  159. if (!getDolGlobalString('PRODUCT_STOCK_LIST_SHOW_VIRTUAL_WITH_NO_PHYSICAL')) {
  160. $sql .= " AND EXISTS (SELECT e.rowid FROM ".MAIN_DB_PREFIX."entrepot as e WHERE e.rowid = s.fk_entrepot AND e.entity IN (".getEntity('stock')."))";
  161. } else {
  162. $sql .= " AND
  163. (
  164. EXISTS
  165. (SELECT e.rowid
  166. FROM ".MAIN_DB_PREFIX."entrepot as e
  167. WHERE e.rowid = s.fk_entrepot AND e.entity IN (".getEntity('stock')."))
  168. OR (
  169. SELECT SUM(cd1.qty) as qty
  170. FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd1
  171. LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c1
  172. ON c1.rowid = cd1.fk_commande
  173. WHERE c1.entity IN (1) AND cd1.fk_product = p.rowid AND c1.fk_statut in (3,4) AND cd1.qty <> 0
  174. ) IS NOT NULL
  175. OR (
  176. SELECT SUM(cd2.qty) as qty
  177. FROM ".MAIN_DB_PREFIX."commandedet as cd2
  178. LEFT JOIN ".MAIN_DB_PREFIX."commande as c2 ON c2.rowid = cd2.fk_commande
  179. WHERE c2.entity IN (1) AND cd2.fk_product = p.rowid AND c2.fk_statut in (1,2) AND cd2.qty <> 0
  180. ) IS NOT NULL
  181. OR (
  182. SELECT SUM(ed3.qty) as qty
  183. FROM ".MAIN_DB_PREFIX."expeditiondet as ed3
  184. LEFT JOIN ".MAIN_DB_PREFIX."expedition as e3 ON e3.rowid = ed3.fk_expedition
  185. LEFT JOIN ".MAIN_DB_PREFIX."commandedet as cd3 ON ed3.fk_origin_line = cd3.rowid
  186. LEFT JOIN ".MAIN_DB_PREFIX."commande as c3 ON c3.rowid = cd3.fk_commande
  187. WHERE e3.entity IN (1) AND cd3.fk_product = p.rowid AND c3.fk_statut IN (1,2) AND e3.fk_statut IN (1,2) AND ed3.qty <> 0
  188. ) IS NOT NULL
  189. OR (
  190. SELECT SUM(mp4.qty) as qty
  191. FROM ".MAIN_DB_PREFIX."mrp_production as mp4
  192. LEFT JOIN ".MAIN_DB_PREFIX."mrp_mo as m4 ON m4.rowid = mp4.fk_mo AND m4.entity IN (1) AND m4.status IN (1,2)
  193. WHERE mp4.fk_product = p.rowid AND mp4.qty <> 0
  194. ) IS NOT NULL
  195. ) ";
  196. }
  197. if ($sall) {
  198. $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall);
  199. }
  200. // if the type is not 1, we show all products (type = 0,2,3)
  201. if (dol_strlen($type)) {
  202. if ($type == 1) {
  203. $sql .= " AND p.fk_product_type = '1'";
  204. } else {
  205. $sql .= " AND p.fk_product_type <> '1'";
  206. }
  207. }
  208. if ($sref) {
  209. $sql .= natural_search('p.ref', $sref);
  210. }
  211. if ($search_barcode) {
  212. $sql .= natural_search('p.barcode', $search_barcode);
  213. }
  214. if ($snom) {
  215. $sql .= natural_search('p.label', $snom);
  216. }
  217. if (!empty($tosell)) {
  218. $sql .= " AND p.tosell = ".((int) $tosell);
  219. }
  220. if (!empty($tobuy)) {
  221. $sql .= " AND p.tobuy = ".((int) $tobuy);
  222. }
  223. if (!empty($canvas)) {
  224. $sql .= " AND p.canvas = '".$db->escape($canvas)."'";
  225. }
  226. if ($fourn_id > 0) {
  227. $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
  228. }
  229. // Add where from hooks
  230. $parameters = array();
  231. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  232. $sql .= $hookmanager->resPrint;
  233. $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
  234. $sql .= " p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
  235. // Add GROUP BY from hooks
  236. $parameters = array();
  237. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  238. $sql .= $hookmanager->resPrint;
  239. $sql_having = '';
  240. if ($search_toolowstock) {
  241. $sql_having .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte";
  242. }
  243. if ($search_stock_physique != '') {
  244. //$natural_search_physique = natural_search('HAVING SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
  245. $natural_search_physique = natural_search('SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
  246. $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters
  247. if (!empty($sql_having)) {
  248. $sql_having .= " AND";
  249. } else {
  250. $sql_having .= " HAVING";
  251. }
  252. $sql_having .= $natural_search_physique;
  253. }
  254. // Add HAVING from hooks
  255. $parameters = array();
  256. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  257. if (!empty($hookmanager->resPrint)) {
  258. if (!empty($sql_having)) {
  259. $sql_having .= " AND";
  260. } else {
  261. $sql_having .= " HAVING";
  262. }
  263. $sql_having .= $hookmanager->resPrint;
  264. }
  265. if (!empty($sql_having)) {
  266. $sql .= $sql_having;
  267. }
  268. $sql .= $db->order($sortfield, $sortorder);
  269. // Count total nb of records
  270. $nbtotalofrecords = '';
  271. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  272. $result = $db->query($sql);
  273. $nbtotalofrecords = $db->num_rows($result);
  274. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  275. $page = 0;
  276. $offset = 0;
  277. }
  278. }
  279. $sql .= $db->plimit($limit + 1, $offset);
  280. $resql = $db->query($sql);
  281. if ($resql) {
  282. $num = $db->num_rows($resql);
  283. $i = 0;
  284. if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall || $snom || $sref)) {
  285. $objp = $db->fetch_object($resql);
  286. header("Location: card.php?id=$objp->rowid");
  287. exit;
  288. }
  289. if (isset($type)) {
  290. if ($type == 1) {
  291. $texte = $langs->trans("Services");
  292. } else {
  293. $texte = $langs->trans("Products");
  294. }
  295. } else {
  296. $texte = $langs->trans("ProductsAndServices");
  297. }
  298. $texte .= ' ('.$langs->trans("MenuStocks").')';
  299. $param = '';
  300. if ($limit > 0 && $limit != $conf->liste_limit) {
  301. $param .= '&limit='.((int) $limit);
  302. }
  303. if ($sall) {
  304. $param .= "&sall=".urlencode($sall);
  305. }
  306. if ($tosell) {
  307. $param .= "&tosell=".urlencode($tosell);
  308. }
  309. if ($tobuy) {
  310. $param .= "&tobuy=".urlencode($tobuy);
  311. }
  312. if ($type != '') {
  313. $param .= "&type=".urlencode($type);
  314. }
  315. if ($fourn_id) {
  316. $param .= "&fourn_id=".urlencode($fourn_id);
  317. }
  318. if ($snom) {
  319. $param .= "&snom=".urlencode($snom);
  320. }
  321. if ($sref) {
  322. $param .= "&sref=".urlencode($sref);
  323. }
  324. if ($search_sale) {
  325. $param .= "&search_sale=".urlencode($search_sale);
  326. }
  327. if ($search_categ > 0) {
  328. $param .= "&search_categ=".urlencode($search_categ);
  329. }
  330. if ($search_toolowstock) {
  331. $param .= "&search_toolowstock=".urlencode($search_toolowstock);
  332. }
  333. if ($sbarcode) {
  334. $param .= "&sbarcode=".urlencode($sbarcode);
  335. }
  336. if ($search_stock_physique) {
  337. $param .= '&search_stock_physique=' . urlencode($search_stock_physique);
  338. }
  339. llxHeader("", $texte, $helpurl);
  340. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
  341. print '<input type="hidden" name="token" value="'.newToken().'">';
  342. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  343. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  344. print '<input type="hidden" name="page" value="'.$page.'">';
  345. print '<input type="hidden" name="type" value="'.$type.'">';
  346. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit);
  347. if ($search_categ > 0) {
  348. print "<div id='ways'>";
  349. $c = new Categorie($db);
  350. $c->fetch($search_categ);
  351. $ways = $c->print_all_ways(' &gt; ', 'product/reassort.php');
  352. print " &gt; ".$ways[0]."<br>\n";
  353. print "</div><br>";
  354. }
  355. // Filter on categories
  356. $moreforfilter = '';
  357. if (isModEnabled('categorie')) {
  358. $moreforfilter .= '<div class="divsearchfield">';
  359. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
  360. $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ', 1);
  361. $moreforfilter .= '</div>';
  362. }
  363. $moreforfilter .= '<div class="divsearchfield">';
  364. $moreforfilter .= '<label for="search_toolowstock">'.$langs->trans("StockTooLow").' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ? ' checked' : '').'>';
  365. $moreforfilter .= '</div>';
  366. if (!empty($moreforfilter)) {
  367. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  368. print $moreforfilter;
  369. $parameters = array();
  370. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  371. print $hookmanager->resPrint;
  372. print '</div>';
  373. }
  374. $formProduct = new FormProduct($db);
  375. $formProduct->loadWarehouses();
  376. $warehouses_list = $formProduct->cache_warehouses;
  377. $nb_warehouse = count($warehouses_list);
  378. $colspan_warehouse = 1;
  379. if (getDolGlobalString('STOCK_DETAIL_ON_WAREHOUSE')) {
  380. $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
  381. }
  382. print '<div class="div-table-responsive">';
  383. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  384. // Fields title search
  385. print '<tr class="liste_titre_filter">';
  386. // Action column
  387. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  388. print '<td class="liste_titre maxwidthsearch">';
  389. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  390. print $searchpicto;
  391. print '</td>';
  392. }
  393. print '<td class="liste_titre">';
  394. print '<input class="flat" type="text" name="sref" size="6" value="'.$sref.'">';
  395. print '</td>';
  396. print '<td class="liste_titre">';
  397. print '<input class="flat" type="text" name="snom" size="8" value="'.$snom.'">';
  398. print '</td>';
  399. // Duration
  400. if (isModEnabled("service") && $type == 1) {
  401. print '<td class="liste_titre">';
  402. print '&nbsp;';
  403. print '</td>';
  404. }
  405. // Stock limit
  406. print '<td class="liste_titre">&nbsp;</td>';
  407. print '<td class="liste_titre right">&nbsp;</td>';
  408. // Physical stock
  409. print '<td class="liste_titre right">';
  410. print '<input class="flat" type="text" size="5" name="search_stock_physique" value="'.dol_escape_htmltag($search_stock_physique).'">';
  411. print '</td>';
  412. if ($virtualdiffersfromphysical) {
  413. print '<td class="liste_titre">&nbsp;</td>';
  414. }
  415. print '<td class="liste_titre">&nbsp;</td>';
  416. print '<td class="liste_titre" colspan="'.$colspan_warehouse.'">&nbsp;</td>';
  417. print '<td class="liste_titre"></td>';
  418. $parameters = array();
  419. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  420. print $hookmanager->resPrint;
  421. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  422. print '<td class="liste_titre maxwidthsearch">';
  423. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  424. print $searchpicto;
  425. print '</td>';
  426. }
  427. print '</tr>';
  428. // Line for column titles
  429. print '<tr class="liste_titre">';
  430. // Action column
  431. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  432. print_liste_field_titre('');
  433. }
  434. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", '', $param, "", $sortfield, $sortorder);
  435. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", '', $param, "", $sortfield, $sortorder);
  436. if (isModEnabled("service") && $type == 1) {
  437. print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", '', $param, "", $sortfield, $sortorder, 'center ');
  438. }
  439. print_liste_field_titre("StockLimit", $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", '', $param, "", $sortfield, $sortorder, 'right ');
  440. print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock", '', $param, "", $sortfield, $sortorder, 'right ');
  441. print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right ');
  442. // Details per warehouse
  443. if (getDolGlobalString('STOCK_DETAIL_ON_WAREHOUSE')) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context)
  444. if ($nb_warehouse > 1) {
  445. foreach ($warehouses_list as &$wh) {
  446. print_liste_field_titre($wh['label'], '', '', '', '', '', '', '', 'right ');
  447. }
  448. }
  449. }
  450. if ($virtualdiffersfromphysical) {
  451. print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", '', $param, "", $sortfield, $sortorder, 'right ', 'VirtualStockDesc');
  452. }
  453. // Units
  454. if (getDolGlobalString('PRODUCT_USE_UNITS')) {
  455. print_liste_field_titre("Unit", $_SERVER["PHP_SELF"], "unit_short", '', $param, 'align="right"', $sortfield, $sortorder);
  456. }
  457. print_liste_field_titre('');
  458. print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", '', $param, "", $sortfield, $sortorder, 'right ');
  459. print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", '', $param, "", $sortfield, $sortorder, 'right ');
  460. // Hook fields
  461. $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  462. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  463. print $hookmanager->resPrint;
  464. // Action column
  465. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  466. print_liste_field_titre('');
  467. }
  468. print "</tr>\n";
  469. while ($i < min($num, $limit)) {
  470. $objp = $db->fetch_object($resql);
  471. $product = new Product($db);
  472. $product->fetch($objp->rowid);
  473. $product->load_stock();
  474. print '<tr>';
  475. // Action column
  476. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  477. print '<td></td>';
  478. }
  479. print '<td class="nowrap">';
  480. print $product->getNomUrl(1, '', 16);
  481. //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow"));
  482. print '</td>';
  483. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).'">'.dol_escape_htmltag($product->label).'</td>';
  484. if (isModEnabled("service") && $type == 1) {
  485. print '<td class="center">';
  486. if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
  487. print $regs[1].' '.$langs->trans("DurationYear");
  488. } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
  489. print $regs[1].' '.$langs->trans("DurationMonth");
  490. } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
  491. print $regs[1].' '.$langs->trans("DurationDay");
  492. } else {
  493. print $objp->duration;
  494. }
  495. print '</td>';
  496. }
  497. //print '<td class="right">'.$objp->stock_theorique.'</td>';
  498. print '<td class="right">';
  499. print $objp->seuil_stock_alerte;
  500. print '</td>';
  501. print '<td class="right">';
  502. print $objp->desiredstock;
  503. print '</td>';
  504. // Real stock
  505. print '<td class="right">';
  506. if ($objp->seuil_stock_alerte != '' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
  507. print img_warning($langs->trans("StockLowerThanLimit", $objp->seuil_stock_alerte)).' ';
  508. }
  509. if ($objp->stock_physique < 0) {
  510. print '<span class="warning">';
  511. }
  512. print price(price2num($objp->stock_physique, 'MS'), 0, $langs, 1, 0);
  513. if ($objp->stock_physique < 0) {
  514. print '</span>';
  515. }
  516. print '</td>';
  517. // Details per warehouse
  518. if (getDolGlobalString('STOCK_DETAIL_ON_WAREHOUSE')) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context)
  519. if ($nb_warehouse > 1) {
  520. foreach ($warehouses_list as &$wh) {
  521. print '<td class="right">';
  522. print price(empty($product->stock_warehouse[$wh['id']]->real) ? 0 : price2num($product->stock_warehouse[$wh['id']]->real, 'MS'), 0, $langs, 1, 0);
  523. print '</td>';
  524. }
  525. }
  526. }
  527. // Virtual stock
  528. if ($virtualdiffersfromphysical) {
  529. print '<td class="right">';
  530. if ($objp->seuil_stock_alerte != '' && ($product->stock_theorique < (float) $objp->seuil_stock_alerte)) {
  531. print img_warning($langs->trans("StockLowerThanLimit", $objp->seuil_stock_alerte)).' ';
  532. }
  533. if ($objp->stock_physique < 0) {
  534. print '<span class="warning">';
  535. }
  536. print price(price2num($product->stock_theorique, 'MS'), 0, $langs, 1, 0);
  537. if ($objp->stock_physique < 0) {
  538. print '</span>';
  539. }
  540. print '</td>';
  541. }
  542. // Units
  543. if (getDolGlobalString('PRODUCT_USE_UNITS')) {
  544. print '<td class="left">'.dol_escape_htmltag($objp->unit_short).'</td>';
  545. }
  546. print '<td class="center nowraponall">';
  547. print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
  548. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$product->id.'">'.$langs->trans("Movements").'</a>';
  549. print '</td>';
  550. print '<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).'</td>';
  551. print '<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).'</td>';
  552. // Fields from hook
  553. $parameters = array('obj'=>$objp);
  554. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $product); // Note that $action and $object may have been modified by hook
  555. print $hookmanager->resPrint;
  556. // Action column
  557. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  558. print '<td></td>';
  559. }
  560. print "</tr>\n";
  561. $i++;
  562. }
  563. print "</table>";
  564. print '</div>';
  565. print '</form>';
  566. $db->free($resql);
  567. } else {
  568. dol_print_error($db);
  569. }
  570. // End of page
  571. llxFooter();
  572. $db->close();