reassort.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. *
  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/product/reassort.php
  24. * \ingroup produit
  25. * \brief Page to list stocks
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array('products', 'stocks'));
  35. $action = GETPOST('action', 'aZ09');
  36. $sref = GETPOST("sref", 'alpha');
  37. $snom = GETPOST("snom", 'alpha');
  38. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  39. $type = GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT;
  40. $search_barcode = GETPOST("search_barcode", 'alpha');
  41. $search_toolowstock = GETPOST('search_toolowstock');
  42. $tosell = GETPOST("tosell");
  43. $tobuy = GETPOST("tobuy");
  44. $fourn_id = GETPOST("fourn_id", 'int');
  45. $sbarcode = GETPOST("sbarcode", 'int');
  46. $search_stock_physique = GETPOST('search_stock_physique', 'alpha');
  47. $sortfield = GETPOST('sortfield', 'aZ09comma');
  48. $sortorder = GETPOST('sortorder', 'aZ09comma');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. if (empty($page) || $page < 0) {
  51. $page = 0;
  52. }
  53. if (!$sortfield) {
  54. $sortfield = "p.ref";
  55. }
  56. if (!$sortorder) {
  57. $sortorder = "ASC";
  58. }
  59. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  60. if (empty($page) || $page == -1) {
  61. $page = 0;
  62. } // If $page is not defined, or '' or -1
  63. $offset = $limit * $page;
  64. // Load sale and categ filters
  65. $search_sale = GETPOST("search_sale");
  66. if (GETPOSTISSET('catid')) {
  67. $search_categ = GETPOST('catid', 'int');
  68. } else {
  69. $search_categ = GETPOST('search_categ', 'int');
  70. }
  71. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  72. $canvas = GETPOST("canvas");
  73. $objcanvas = null;
  74. if (!empty($canvas)) {
  75. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  76. $objcanvas = new Canvas($db, $action);
  77. $objcanvas->getCanvas('product', 'list', $canvas);
  78. }
  79. // Define virtualdiffersfromphysical
  80. $virtualdiffersfromphysical = 0;
  81. if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
  82. || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
  83. || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
  84. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
  85. || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
  86. || isModEnabled('mrp')) {
  87. $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
  88. }
  89. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  90. $hookmanager->initHooks(array('productreassortlist'));
  91. if ($user->socid) {
  92. $socid = $user->socid;
  93. }
  94. $result = restrictedArea($user, 'produit|service', 0, 'product&product');
  95. $object = new Product($db);
  96. /*
  97. * Actions
  98. */
  99. 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
  100. $sref = "";
  101. $snom = "";
  102. $sall = "";
  103. $tosell = "";
  104. $tobuy = "";
  105. $search_sale = "";
  106. $search_categ = "";
  107. $search_toolowstock = '';
  108. $fourn_id = '';
  109. $sbarcode = '';
  110. $search_stock_physique = '';
  111. }
  112. /*
  113. * View
  114. */
  115. $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  116. $form = new Form($db);
  117. $htmlother = new FormOther($db);
  118. $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
  119. $sql .= ' p.fk_product_type, p.tms as datem,';
  120. $sql .= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
  121. $sql .= ' SUM(s.reel) as stock_physique';
  122. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  123. $sql .= ', u.short_label as unit_short';
  124. }
  125. // Add fields from hooks
  126. $parameters = array();
  127. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  128. $sql .= $hookmanager->resPrint;
  129. $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
  130. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s ON p.rowid = s.fk_product';
  131. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  132. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_units as u on p.fk_unit = u.rowid';
  133. }
  134. $sql .= " WHERE p.entity IN (".getEntity('product').")";
  135. if (!empty($search_categ) && $search_categ != '-1') {
  136. $sql .= " AND ";
  137. if ($search_categ == -2) {
  138. $sql .= " NOT EXISTS ";
  139. } else {
  140. $sql .= " EXISTS ";
  141. }
  142. $sql .= "(";
  143. $sql .= " SELECT cp.fk_categorie, cp.fk_product";
  144. $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_product as cp";
  145. $sql .= " WHERE cp.fk_product = p.rowid"; // Join for the needed table to filter by categ
  146. if ($search_categ > 0) {
  147. $sql .= " AND cp.fk_categorie = " . ((int) $search_categ);
  148. }
  149. $sql .= ")";
  150. }
  151. $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')."))";
  152. if ($sall) {
  153. $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall);
  154. }
  155. // if the type is not 1, we show all products (type = 0,2,3)
  156. if (dol_strlen($type)) {
  157. if ($type == 1) {
  158. $sql .= " AND p.fk_product_type = '1'";
  159. } else {
  160. $sql .= " AND p.fk_product_type <> '1'";
  161. }
  162. }
  163. if ($sref) {
  164. $sql .= natural_search('p.ref', $sref);
  165. }
  166. if ($search_barcode) {
  167. $sql .= natural_search('p.barcode', $search_barcode);
  168. }
  169. if ($snom) {
  170. $sql .= natural_search('p.label', $snom);
  171. }
  172. if (!empty($tosell)) {
  173. $sql .= " AND p.tosell = ".((int) $tosell);
  174. }
  175. if (!empty($tobuy)) {
  176. $sql .= " AND p.tobuy = ".((int) $tobuy);
  177. }
  178. if (!empty($canvas)) {
  179. $sql .= " AND p.canvas = '".$db->escape($canvas)."'";
  180. }
  181. if ($fourn_id > 0) {
  182. $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
  183. }
  184. // Add where from hooks
  185. $parameters = array();
  186. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  187. $sql .= $hookmanager->resPrint;
  188. $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
  189. $sql .= " p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
  190. // Add fields from hooks
  191. $parameters = array();
  192. $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  193. $sql .= $hookmanager->resPrint;
  194. $sql_having = '';
  195. if ($search_toolowstock) {
  196. $sql_having .= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte";
  197. }
  198. if ($search_stock_physique != '') {
  199. //$natural_search_physique = natural_search('HAVING SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
  200. $natural_search_physique = natural_search('SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
  201. $natural_search_physique = " " . substr($natural_search_physique, 1, -1); // remove first "(" and last ")" characters
  202. if (!empty($sql_having)) {
  203. $sql_having .= " AND";
  204. } else {
  205. $sql_having .= " HAVING";
  206. }
  207. $sql_having .= $natural_search_physique;
  208. }
  209. if (!empty($sql_having)) {
  210. $sql .= $sql_having;
  211. }
  212. $sql .= $db->order($sortfield, $sortorder);
  213. // Count total nb of records
  214. $nbtotalofrecords = '';
  215. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  216. $result = $db->query($sql);
  217. $nbtotalofrecords = $db->num_rows($result);
  218. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  219. $page = 0;
  220. $offset = 0;
  221. }
  222. }
  223. $sql .= $db->plimit($limit + 1, $offset);
  224. $resql = $db->query($sql);
  225. if ($resql) {
  226. $num = $db->num_rows($resql);
  227. $i = 0;
  228. if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall || $snom || $sref)) {
  229. $objp = $db->fetch_object($resql);
  230. header("Location: card.php?id=$objp->rowid");
  231. exit;
  232. }
  233. if (isset($type)) {
  234. if ($type == 1) {
  235. $texte = $langs->trans("Services");
  236. } else {
  237. $texte = $langs->trans("Products");
  238. }
  239. } else {
  240. $texte = $langs->trans("ProductsAndServices");
  241. }
  242. $texte .= ' ('.$langs->trans("MenuStocks").')';
  243. $param = '';
  244. if ($limit > 0 && $limit != $conf->liste_limit) {
  245. $param .= '&limit='.urlencode($limit);
  246. }
  247. if ($sall) {
  248. $param .= "&sall=".urlencode($sall);
  249. }
  250. if ($tosell) {
  251. $param .= "&tosell=".urlencode($tosell);
  252. }
  253. if ($tobuy) {
  254. $param .= "&tobuy=".urlencode($tobuy);
  255. }
  256. if ($type != '') {
  257. $param .= "&type=".urlencode($type);
  258. }
  259. if ($fourn_id) {
  260. $param .= "&fourn_id=".urlencode($fourn_id);
  261. }
  262. if ($snom) {
  263. $param .= "&snom=".urlencode($snom);
  264. }
  265. if ($sref) {
  266. $param .= "&sref=".urlencode($sref);
  267. }
  268. if ($search_sale) {
  269. $param .= "&search_sale=".urlencode($search_sale);
  270. }
  271. if ($search_categ > 0) {
  272. $param .= "&search_categ=".urlencode($search_categ);
  273. }
  274. if ($search_toolowstock) {
  275. $param .= "&search_toolowstock=".urlencode($search_toolowstock);
  276. }
  277. if ($sbarcode) {
  278. $param .= "&sbarcode=".urlencode($sbarcode);
  279. }
  280. if ($search_stock_physique) {
  281. $param .= '&search_stock_physique=' . urlencode($search_stock_physique);
  282. }
  283. llxHeader("", $texte, $helpurl);
  284. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
  285. print '<input type="hidden" name="token" value="'.newToken().'">';
  286. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  287. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  288. print '<input type="hidden" name="page" value="'.$page.'">';
  289. print '<input type="hidden" name="type" value="'.$type.'">';
  290. print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'product', 0, '', '', $limit);
  291. if ($search_categ > 0) {
  292. print "<div id='ways'>";
  293. $c = new Categorie($db);
  294. $c->fetch($search_categ);
  295. $ways = $c->print_all_ways(' &gt; ', 'product/reassort.php');
  296. print " &gt; ".$ways[0]."<br>\n";
  297. print "</div><br>";
  298. }
  299. // Filter on categories
  300. $moreforfilter = '';
  301. if (isModEnabled('categorie')) {
  302. $moreforfilter .= '<div class="divsearchfield">';
  303. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
  304. $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ', 1);
  305. $moreforfilter .= '</div>';
  306. }
  307. $moreforfilter .= '<div class="divsearchfield">';
  308. $moreforfilter .= '<label for="search_toolowstock">'.$langs->trans("StockTooLow").' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ? ' checked' : '').'>';
  309. $moreforfilter .= '</div>';
  310. if (!empty($moreforfilter)) {
  311. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  312. print $moreforfilter;
  313. $parameters = array();
  314. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  315. print $hookmanager->resPrint;
  316. print '</div>';
  317. }
  318. $formProduct = new FormProduct($db);
  319. $formProduct->loadWarehouses();
  320. $warehouses_list = $formProduct->cache_warehouses;
  321. $nb_warehouse = count($warehouses_list);
  322. $colspan_warehouse = 1;
  323. if (!empty($conf->global->STOCK_DETAIL_ON_WAREHOUSE)) {
  324. $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
  325. }
  326. print '<div class="div-table-responsive">';
  327. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  328. // Fields title search
  329. print '<tr class="liste_titre_filter">';
  330. // Action column
  331. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  332. print '<td class="liste_titre maxwidthsearch">';
  333. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  334. print $searchpicto;
  335. print '</td>';
  336. }
  337. print '<td class="liste_titre">';
  338. print '<input class="flat" type="text" name="sref" size="6" value="'.$sref.'">';
  339. print '</td>';
  340. print '<td class="liste_titre">';
  341. print '<input class="flat" type="text" name="snom" size="8" value="'.$snom.'">';
  342. print '</td>';
  343. // Duration
  344. if (isModEnabled("service") && $type == 1) {
  345. print '<td class="liste_titre">';
  346. print '&nbsp;';
  347. print '</td>';
  348. }
  349. // Stock limit
  350. print '<td class="liste_titre">&nbsp;</td>';
  351. print '<td class="liste_titre right">&nbsp;</td>';
  352. // Physical stock
  353. print '<td class="liste_titre right">';
  354. print '<input class="flat" type="text" size="5" name="search_stock_physique" value="'.dol_escape_htmltag($search_stock_physique).'">';
  355. print '</td>';
  356. if ($virtualdiffersfromphysical) {
  357. print '<td class="liste_titre">&nbsp;</td>';
  358. }
  359. print '<td class="liste_titre">&nbsp;</td>';
  360. print '<td class="liste_titre" colspan="'.$colspan_warehouse.'">&nbsp;</td>';
  361. print '<td class="liste_titre"></td>';
  362. $parameters = array();
  363. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  364. print $hookmanager->resPrint;
  365. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  366. print '<td class="liste_titre maxwidthsearch">';
  367. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  368. print $searchpicto;
  369. print '</td>';
  370. }
  371. print '</tr>';
  372. //Line for column titles
  373. print "<tr class=\"liste_titre\">";
  374. // Action column
  375. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  376. print_liste_field_titre('');
  377. }
  378. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", '', $param, "", $sortfield, $sortorder);
  379. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", '', $param, "", $sortfield, $sortorder);
  380. if (isModEnabled("service") && $type == 1) {
  381. print_liste_field_titre("Duration", $_SERVER["PHP_SELF"], "p.duration", '', $param, "", $sortfield, $sortorder, 'center ');
  382. }
  383. print_liste_field_titre("StockLimit", $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", '', $param, "", $sortfield, $sortorder, 'right ');
  384. print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock", '', $param, "", $sortfield, $sortorder, 'right ');
  385. print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right ');
  386. // Details per warehouse
  387. 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)
  388. if ($nb_warehouse > 1) {
  389. foreach ($warehouses_list as &$wh) {
  390. print_liste_field_titre($wh['label'], '', '', '', '', '', '', '', 'right ');
  391. }
  392. }
  393. }
  394. if ($virtualdiffersfromphysical) {
  395. print_liste_field_titre("VirtualStock", $_SERVER["PHP_SELF"], "", '', $param, "", $sortfield, $sortorder, 'right ', 'VirtualStockDesc');
  396. }
  397. // Units
  398. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  399. print_liste_field_titre("Unit", $_SERVER["PHP_SELF"], "unit_short", '', $param, 'align="right"', $sortfield, $sortorder);
  400. }
  401. print_liste_field_titre('');
  402. print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", '', $param, "", $sortfield, $sortorder, 'right ');
  403. print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", '', $param, "", $sortfield, $sortorder, 'right ');
  404. // Hook fields
  405. $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  406. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  407. print $hookmanager->resPrint;
  408. // Action column
  409. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  410. print_liste_field_titre('');
  411. }
  412. print "</tr>\n";
  413. while ($i < min($num, $limit)) {
  414. $objp = $db->fetch_object($resql);
  415. $product = new Product($db);
  416. $product->fetch($objp->rowid);
  417. $product->load_stock();
  418. print '<tr>';
  419. // Action column
  420. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  421. print '<td></td>';
  422. }
  423. print '<td class="nowrap">';
  424. print $product->getNomUrl(1, '', 16);
  425. //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow"));
  426. print '</td>';
  427. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).'">'.dol_escape_htmltag($product->label).'</td>';
  428. if (isModEnabled("service") && $type == 1) {
  429. print '<td class="center">';
  430. if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
  431. print $regs[1].' '.$langs->trans("DurationYear");
  432. } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
  433. print $regs[1].' '.$langs->trans("DurationMonth");
  434. } elseif (preg_match('/([0-9]+)d/i', $objp->duration, $regs)) {
  435. print $regs[1].' '.$langs->trans("DurationDay");
  436. } else {
  437. print $objp->duration;
  438. }
  439. print '</td>';
  440. }
  441. //print '<td class="right">'.$objp->stock_theorique.'</td>';
  442. print '<td class="right">'.$objp->seuil_stock_alerte.'</td>';
  443. print '<td class="right">'.$objp->desiredstock.'</td>';
  444. // Real stock
  445. print '<td class="right">';
  446. if ($objp->seuil_stock_alerte != '' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
  447. print img_warning($langs->trans("StockTooLow")).' ';
  448. }
  449. print price(price2num($objp->stock_physique, 'MS'), 0, $langs, 1, 0);
  450. print '</td>';
  451. // Details per warehouse
  452. 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)
  453. if ($nb_warehouse > 1) {
  454. foreach ($warehouses_list as &$wh) {
  455. print '<td class="right">';
  456. print price(empty($product->stock_warehouse[$wh['id']]->real) ? 0 : price2num($product->stock_warehouse[$wh['id']]->real, 'MS'), 0, $langs, 1, 0);
  457. print '</td>';
  458. }
  459. }
  460. }
  461. // Virtual stock
  462. if ($virtualdiffersfromphysical) {
  463. print '<td class="right">';
  464. if ($objp->seuil_stock_alerte != '' && ($product->stock_theorique < (float) $objp->seuil_stock_alerte)) {
  465. print img_warning($langs->trans("StockTooLow")).' ';
  466. }
  467. print price(price2num($product->stock_theorique, 'MS'), 0, $langs, 1, 0);
  468. print '</td>';
  469. }
  470. // Units
  471. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  472. print '<td class="left">'.$objp->unit_short.'</td>';
  473. }
  474. print '<td class="center nowraponall">';
  475. print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
  476. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?idproduct='.$product->id.'">'.$langs->trans("Movements").'</a>';
  477. print '</td>';
  478. print '<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).'</td>';
  479. print '<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).'</td>';
  480. // Fields from hook
  481. $parameters = array('obj'=>$objp);
  482. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $product); // Note that $action and $object may have been modified by hook
  483. print $hookmanager->resPrint;
  484. // Action column
  485. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  486. print '<td></td>';
  487. }
  488. print "</tr>\n";
  489. $i++;
  490. }
  491. print "</table>";
  492. print '</div>';
  493. print '</form>';
  494. $db->free($resql);
  495. } else {
  496. dol_print_error($db);
  497. }
  498. // End of page
  499. llxFooter();
  500. $db->close();