reassort.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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 (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
  83. || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
  84. || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
  85. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
  86. || !empty($conf->global->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) { print '<span class="warning">'; }
  120. $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
  121. $sql .= ' p.fk_product_type, p.tms as datem,';
  122. $sql .= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
  123. $sql .= ' SUM(s.reel) as stock_physique';
  124. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  125. $sql .= ', u.short_label as unit_short';
  126. }
  127. // Add fields from hooks
  128. $parameters = array();
  129. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  130. $sql .= $hookmanager->resPrint;
  131. $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
  132. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product';
  133. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  134. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_units as u on p.fk_unit = u.rowid';
  135. }
  136. // Add table from hooks
  137. $parameters = array();
  138. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  139. $sql .= $hookmanager->resPrint;
  140. $sql .= " WHERE p.entity IN (".getEntity('product').")";
  141. if (!empty($search_categ) && $search_categ != '-1') {
  142. $sql .= " AND ";
  143. if ($search_categ == -2) {
  144. $sql .= " NOT EXISTS ";
  145. } else {
  146. $sql .= " EXISTS ";
  147. }
  148. $sql .= "(";
  149. $sql .= " SELECT cp.fk_categorie, cp.fk_product";
  150. $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_product as cp";
  151. $sql .= " WHERE cp.fk_product = p.rowid"; // Join for the needed table to filter by categ
  152. if ($search_categ > 0) {
  153. $sql .= " AND cp.fk_categorie = " . ((int) $search_categ);
  154. }
  155. $sql .= ")";
  156. }
  157. if (empty($conf->global->PRODUCT_STOCK_LIST_SHOW_VIRTUAL_WITH_NO_PHYSICAL)) {
  158. $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')."))";
  159. } else {
  160. $sql .= " AND
  161. (
  162. EXISTS
  163. (SELECT e.rowid
  164. FROM ".MAIN_DB_PREFIX."entrepot as e
  165. WHERE e.rowid = s.fk_entrepot AND e.entity IN (".getEntity('stock')."))
  166. OR (
  167. SELECT SUM(cd1.qty) as qty
  168. FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd1
  169. LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c1
  170. ON c1.rowid = cd1.fk_commande
  171. WHERE c1.entity IN (1) AND cd1.fk_product = p.rowid AND c1.fk_statut in (3,4) AND cd1.qty <> 0
  172. ) IS NOT NULL
  173. OR (
  174. SELECT SUM(cd2.qty) as qty
  175. FROM ".MAIN_DB_PREFIX."commandedet as cd2
  176. LEFT JOIN ".MAIN_DB_PREFIX."commande as c2 ON c2.rowid = cd2.fk_commande
  177. WHERE c2.entity IN (1) AND cd2.fk_product = p.rowid AND c2.fk_statut in (1,2) AND cd2.qty <> 0
  178. ) IS NOT NULL
  179. OR (
  180. SELECT SUM(ed3.qty) as qty
  181. FROM ".MAIN_DB_PREFIX."expeditiondet as ed3
  182. LEFT JOIN ".MAIN_DB_PREFIX."expedition as e3 ON e3.rowid = ed3.fk_expedition
  183. LEFT JOIN ".MAIN_DB_PREFIX."commandedet as cd3 ON ed3.fk_origin_line = cd3.rowid
  184. LEFT JOIN ".MAIN_DB_PREFIX."commande as c3 ON c3.rowid = cd3.fk_commande
  185. 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
  186. ) IS NOT NULL
  187. OR (
  188. SELECT SUM(mp4.qty) as qty
  189. FROM ".MAIN_DB_PREFIX."mrp_production as mp4
  190. 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)
  191. WHERE mp4.fk_product = p.rowid AND mp4.qty <> 0
  192. ) IS NOT NULL
  193. ) ";
  194. }
  195. if ($sall) {
  196. $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall);
  197. }
  198. // if the type is not 1, we show all products (type = 0,2,3)
  199. if (dol_strlen($type)) {
  200. if ($type == 1) {
  201. $sql .= " AND p.fk_product_type = '1'";
  202. } else {
  203. $sql .= " AND p.fk_product_type <> '1'";
  204. }
  205. }
  206. if ($sref) {
  207. $sql .= natural_search('p.ref', $sref);
  208. }
  209. if ($search_barcode) {
  210. $sql .= natural_search('p.barcode', $search_barcode);
  211. }
  212. if ($snom) {
  213. $sql .= natural_search('p.label', $snom);
  214. }
  215. if (!empty($tosell)) {
  216. $sql .= " AND p.tosell = ".((int) $tosell);
  217. }
  218. if (!empty($tobuy)) {
  219. $sql .= " AND p.tobuy = ".((int) $tobuy);
  220. }
  221. if (!empty($canvas)) {
  222. $sql .= " AND p.canvas = '".$db->escape($canvas)."'";
  223. }
  224. if ($fourn_id > 0) {
  225. $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
  226. }
  227. // Add where from hooks
  228. $parameters = array();
  229. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  230. $sql .= $hookmanager->resPrint;
  231. $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
  232. $sql .= " p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
  233. // Add GROUP BY from hooks
  234. $parameters = array();
  235. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  236. $sql .= $hookmanager->resPrint;
  237. $sql_having = '';
  238. if ($search_toolowstock) {
  239. $sql_having .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte";
  240. }
  241. if ($search_stock_physique != '') {
  242. //$natural_search_physique = natural_search('HAVING SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
  243. $natural_search_physique = natural_search('SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
  244. $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters
  245. if (!empty($sql_having)) {
  246. $sql_having .= " AND";
  247. } else {
  248. $sql_having .= " HAVING";
  249. }
  250. $sql_having .= $natural_search_physique;
  251. }
  252. // Add HAVING from hooks
  253. $parameters = array();
  254. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  255. if (!empty($hookmanager->resPrint)) {
  256. if (!empty($sql_having)) {
  257. $sql_having .= " AND";
  258. } else {
  259. $sql_having .= " HAVING";
  260. }
  261. $sql_having .= $hookmanager->resPrint;
  262. }
  263. if (!empty($sql_having)) {
  264. $sql .= $sql_having;
  265. }
  266. $sql .= $db->order($sortfield, $sortorder);
  267. // Count total nb of records
  268. $nbtotalofrecords = '';
  269. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  270. $result = $db->query($sql);
  271. $nbtotalofrecords = $db->num_rows($result);
  272. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  273. $page = 0;
  274. $offset = 0;
  275. }
  276. }
  277. $sql .= $db->plimit($limit + 1, $offset);
  278. $resql = $db->query($sql);
  279. if ($resql) {
  280. $num = $db->num_rows($resql);
  281. $i = 0;
  282. if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall || $snom || $sref)) {
  283. $objp = $db->fetch_object($resql);
  284. header("Location: card.php?id=$objp->rowid");
  285. exit;
  286. }
  287. if (isset($type)) {
  288. if ($type == 1) {
  289. $texte = $langs->trans("Services");
  290. } else {
  291. $texte = $langs->trans("Products");
  292. }
  293. } else {
  294. $texte = $langs->trans("ProductsAndServices");
  295. }
  296. $texte .= ' ('.$langs->trans("MenuStocks").')';
  297. $param = '';
  298. if ($limit > 0 && $limit != $conf->liste_limit) {
  299. $param .= '&limit='.((int) $limit);
  300. }
  301. if ($sall) {
  302. $param .= "&sall=".urlencode($sall);
  303. }
  304. if ($tosell) {
  305. $param .= "&tosell=".urlencode($tosell);
  306. }
  307. if ($tobuy) {
  308. $param .= "&tobuy=".urlencode($tobuy);
  309. }
  310. if ($type != '') {
  311. $param .= "&type=".urlencode($type);
  312. }
  313. if ($fourn_id) {
  314. $param .= "&fourn_id=".urlencode($fourn_id);
  315. }
  316. if ($snom) {
  317. $param .= "&snom=".urlencode($snom);
  318. }
  319. if ($sref) {
  320. $param .= "&sref=".urlencode($sref);
  321. }
  322. if ($search_sale) {
  323. $param .= "&search_sale=".urlencode($search_sale);
  324. }
  325. if ($search_categ > 0) {
  326. $param .= "&search_categ=".urlencode($search_categ);
  327. }
  328. if ($search_toolowstock) {
  329. $param .= "&search_toolowstock=".urlencode($search_toolowstock);
  330. }
  331. if ($sbarcode) {
  332. $param .= "&sbarcode=".urlencode($sbarcode);
  333. }
  334. if ($search_stock_physique) {
  335. $param .= '&search_stock_physique=' . urlencode($search_stock_physique);
  336. }
  337. llxHeader("", $texte, $helpurl);
  338. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
  339. print '<input type="hidden" name="token" value="'.newToken().'">';
  340. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  341. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  342. print '<input type="hidden" name="page" value="'.$page.'">';
  343. print '<input type="hidden" name="type" value="'.$type.'">';
  344. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit);
  345. if ($search_categ > 0) {
  346. print "<div id='ways'>";
  347. $c = new Categorie($db);
  348. $c->fetch($search_categ);
  349. $ways = $c->print_all_ways(' &gt; ', 'product/reassort.php');
  350. print " &gt; ".$ways[0]."<br>\n";
  351. print "</div><br>";
  352. }
  353. // Filter on categories
  354. $moreforfilter = '';
  355. if (isModEnabled('categorie')) {
  356. $moreforfilter .= '<div class="divsearchfield">';
  357. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
  358. $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ', 1);
  359. $moreforfilter .= '</div>';
  360. }
  361. $moreforfilter .= '<div class="divsearchfield">';
  362. $moreforfilter .= '<label for="search_toolowstock">'.$langs->trans("StockTooLow").' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ? ' checked' : '').'>';
  363. $moreforfilter .= '</div>';
  364. if (!empty($moreforfilter)) {
  365. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  366. print $moreforfilter;
  367. $parameters = array();
  368. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  369. print $hookmanager->resPrint;
  370. print '</div>';
  371. }
  372. $formProduct = new FormProduct($db);
  373. $formProduct->loadWarehouses();
  374. $warehouses_list = $formProduct->cache_warehouses;
  375. $nb_warehouse = count($warehouses_list);
  376. $colspan_warehouse = 1;
  377. if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) {
  378. $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
  379. }
  380. print '<div class="div-table-responsive">';
  381. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  382. // Fields title search
  383. print '<tr class="liste_titre_filter">';
  384. // Action column
  385. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  386. print '<td class="liste_titre maxwidthsearch">';
  387. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  388. print $searchpicto;
  389. print '</td>';
  390. }
  391. print '<td class="liste_titre">';
  392. print '<input class="flat" type="text" name="sref" size="6" value="'.$sref.'">';
  393. print '</td>';
  394. print '<td class="liste_titre">';
  395. print '<input class="flat" type="text" name="snom" size="8" value="'.$snom.'">';
  396. print '</td>';
  397. // Duration
  398. if (isModEnabled("service") && $type == 1) {
  399. print '<td class="liste_titre">';
  400. print '&nbsp;';
  401. print '</td>';
  402. }
  403. // Stock limit
  404. print '<td class="liste_titre">&nbsp;</td>';
  405. print '<td class="liste_titre right">&nbsp;</td>';
  406. // Physical stock
  407. print '<td class="liste_titre right">';
  408. print '<input class="flat" type="text" size="5" name="search_stock_physique" value="'.dol_escape_htmltag($search_stock_physique).'">';
  409. print '</td>';
  410. if ($virtualdiffersfromphysical) {
  411. print '<td class="liste_titre">&nbsp;</td>';
  412. }
  413. print '<td class="liste_titre">&nbsp;</td>';
  414. print '<td class="liste_titre" colspan="'.$colspan_warehouse.'">&nbsp;</td>';
  415. print '<td class="liste_titre"></td>';
  416. $parameters = array();
  417. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  418. print $hookmanager->resPrint;
  419. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  420. print '<td class="liste_titre maxwidthsearch">';
  421. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  422. print $searchpicto;
  423. print '</td>';
  424. }
  425. print '</tr>';
  426. // Line for column titles
  427. print '<tr class="liste_titre">';
  428. // Action column
  429. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  430. print_liste_field_titre('');
  431. }
  432. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", '', $param, "", $sortfield, $sortorder);
  433. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", '', $param, "", $sortfield, $sortorder);
  434. if (isModEnabled("service") && $type == 1) {
  435. print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", '', $param, "", $sortfield, $sortorder, 'center ');
  436. }
  437. print_liste_field_titre("StockLimit", $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", '', $param, "", $sortfield, $sortorder, 'right ');
  438. print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock", '', $param, "", $sortfield, $sortorder, 'right ');
  439. print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right ');
  440. // Details per warehouse
  441. if (!empty($conf->global->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)
  442. if ($nb_warehouse > 1) {
  443. foreach ($warehouses_list as &$wh) {
  444. print_liste_field_titre($wh['label'], '', '', '', '', '', '', '', 'right ');
  445. }
  446. }
  447. }
  448. if ($virtualdiffersfromphysical) {
  449. print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", '', $param, "", $sortfield, $sortorder, 'right ', 'VirtualStockDesc');
  450. }
  451. // Units
  452. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  453. print_liste_field_titre("Unit", $_SERVER["PHP_SELF"], "unit_short", '', $param, 'align="right"', $sortfield, $sortorder);
  454. }
  455. print_liste_field_titre('');
  456. print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", '', $param, "", $sortfield, $sortorder, 'right ');
  457. print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", '', $param, "", $sortfield, $sortorder, 'right ');
  458. // Hook fields
  459. $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  460. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  461. print $hookmanager->resPrint;
  462. // Action column
  463. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  464. print_liste_field_titre('');
  465. }
  466. print "</tr>\n";
  467. while ($i < min($num, $limit)) {
  468. $objp = $db->fetch_object($resql);
  469. $product = new Product($db);
  470. $product->fetch($objp->rowid);
  471. $product->load_stock();
  472. print '<tr>';
  473. // Action column
  474. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  475. print '<td></td>';
  476. }
  477. print '<td class="nowrap">';
  478. print $product->getNomUrl(1, '', 16);
  479. //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow"));
  480. print '</td>';
  481. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).'">'.dol_escape_htmltag($product->label).'</td>';
  482. if (isModEnabled("service") && $type == 1) {
  483. print '<td class="center">';
  484. if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
  485. print $regs[1].' '.$langs->trans("DurationYear");
  486. } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
  487. print $regs[1].' '.$langs->trans("DurationMonth");
  488. } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
  489. print $regs[1].' '.$langs->trans("DurationDay");
  490. } else {
  491. print $objp->duration;
  492. }
  493. print '</td>';
  494. }
  495. //print '<td class="right">'.$objp->stock_theorique.'</td>';
  496. print '<td class="right">';
  497. print $objp->seuil_stock_alerte;
  498. print '</td>';
  499. print '<td class="right">';
  500. print $objp->desiredstock;
  501. print '</td>';
  502. // Real stock
  503. print '<td class="right">';
  504. if ($objp->seuil_stock_alerte != '' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
  505. print img_warning($langs->trans("StockLowerThanLimit", $objp->seuil_stock_alerte)).' ';
  506. }
  507. if ($objp->stock_physique < 0) { print '<span class="warning">'; }
  508. print price(price2num($objp->stock_physique, 'MS'), 0, $langs, 1, 0);
  509. if ($objp->stock_physique < 0) { print '</span>'; }
  510. print '</td>';
  511. // Details per warehouse
  512. if (!empty($conf->global->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)
  513. if ($nb_warehouse > 1) {
  514. foreach ($warehouses_list as &$wh) {
  515. print '<td class="right">';
  516. print price(empty($product->stock_warehouse[$wh['id']]->real) ? 0 : price2num($product->stock_warehouse[$wh['id']]->real, 'MS'), 0, $langs, 1, 0);
  517. print '</td>';
  518. }
  519. }
  520. }
  521. // Virtual stock
  522. if ($virtualdiffersfromphysical) {
  523. print '<td class="right">';
  524. if ($objp->seuil_stock_alerte != '' && ($product->stock_theorique < (float) $objp->seuil_stock_alerte)) {
  525. print img_warning($langs->trans("StockLowerThanLimit", $objp->seuil_stock_alerte)).' ';
  526. }
  527. if ($objp->stock_physique < 0) { print '<span class="warning">'; }
  528. print price(price2num($product->stock_theorique, 'MS'), 0, $langs, 1, 0);
  529. if ($objp->stock_physique < 0) { print '</span>'; }
  530. print '</td>';
  531. }
  532. // Units
  533. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  534. print '<td class="left">'.dol_escape_htmltag($objp->unit_short).'</td>';
  535. }
  536. print '<td class="center nowraponall">';
  537. print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
  538. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$product->id.'">'.$langs->trans("Movements").'</a>';
  539. print '</td>';
  540. print '<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).'</td>';
  541. print '<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).'</td>';
  542. // Fields from hook
  543. $parameters = array('obj'=>$objp);
  544. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $product); // Note that $action and $object may have been modified by hook
  545. print $hookmanager->resPrint;
  546. // Action column
  547. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  548. print '<td></td>';
  549. }
  550. print "</tr>\n";
  551. $i++;
  552. }
  553. print "</table>";
  554. print '</div>';
  555. print '</form>';
  556. $db->free($resql);
  557. } else {
  558. dol_print_error($db);
  559. }
  560. // End of page
  561. llxFooter();
  562. $db->close();