list.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  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/list.php
  23. * \ingroup stock
  24. * \brief Page with warehouse and stock value
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  29. if (isModEnabled('categorie')) {
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. }
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("stocks", "other"));
  35. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
  36. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  37. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  38. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  39. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  40. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  41. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'stocklist'; // To manage different context of search
  42. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  43. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  44. $toselect = GETPOST('toselect', 'array');
  45. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  46. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  47. $search_ref = GETPOST("sref", "alpha") ? GETPOST("sref", "alpha") : GETPOST("search_ref", "alpha");
  48. $search_label = GETPOST("snom", "alpha") ? GETPOST("snom", "alpha") : GETPOST("search_label", "alpha");
  49. $search_status = GETPOST("search_status", "int");
  50. if (isModEnabled('categorie')) {
  51. $search_category_list = GETPOST("search_category_".Categorie::TYPE_WAREHOUSE."_list", "array");
  52. }
  53. // Load variable for pagination
  54. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  55. $sortfield = GETPOST('sortfield', 'aZ09comma');
  56. $sortorder = GETPOST('sortorder', 'aZ09comma');
  57. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  58. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  59. // If $page is not defined, or '' or -1 or if we click on clear filters
  60. $page = 0;
  61. }
  62. // Initialize technical objects
  63. $offset = $limit * $page;
  64. $pageprev = $page - 1;
  65. $pagenext = $page + 1;
  66. if (!$sortfield) {
  67. $sortfield = "t.ref";
  68. }
  69. if (!$sortorder) {
  70. $sortorder = "ASC";
  71. }
  72. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  73. $object = new Entrepot($db);
  74. $extrafields = new ExtraFields($db);
  75. $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
  76. $hookmanager->initHooks(array($contextpage));
  77. // Fetch optionals attributes and labels
  78. $extrafields->fetch_name_optionals_label($object->table_element);
  79. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  80. // Initialize array of search criterias
  81. $search_all = GETPOST("search_all", 'alphanohtml');
  82. $search = array();
  83. foreach ($object->fields as $key => $val) {
  84. $search_key = $key;
  85. if ($search_key == 'statut') {
  86. $search_key = 'status'; // remove this after refactor entrepot.class property statut to status
  87. }
  88. if (GETPOST('search_'.$search_key, 'alpha') !== '') {
  89. $search[$search_key] = GETPOST('search_'.$search_key, 'alpha');
  90. }
  91. }
  92. // List of fields to search into when doing a "search in all"
  93. $fieldstosearchall = array();
  94. foreach ($object->fields as $key => $val) {
  95. if (!empty($val['searchall'])) {
  96. $fieldstosearchall['t.'.$key] = $val['label'];
  97. }
  98. }
  99. // Definition of array of fields for columns
  100. $arrayfields = array(
  101. 'stockqty'=>array('type'=>'float', 'label'=>'PhysicalStock', 'enabled'=>1, 'visible'=>-2, 'checked'=>0, 'position'=>170),
  102. 'estimatedvalue'=>array('type'=>'float', 'label'=>'EstimatedStockValue', 'enabled'=>1, 'visible'=>1, 'checked'=>1, 'position'=>171),
  103. 'estimatedstockvaluesell'=>array('type'=>'float', 'label'=>'EstimatedStockValueSell', 'enabled'=>1, 'checked'=>1, 'visible'=>2, 'position'=>172),
  104. );
  105. foreach ($object->fields as $key => $val) {
  106. // If $val['visible']==0, then we never show the field
  107. if (!empty($val['visible'])) {
  108. $visible = (int) dol_eval($val['visible'], 1);
  109. $arrayfields['t.'.$key] = array(
  110. 'label'=>$val['label'],
  111. 'checked'=>(($visible < 0) ? 0 : 1),
  112. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  113. 'position'=>$val['position'],
  114. 'help'=> isset($val['help']) ? $val['help'] : ''
  115. );
  116. }
  117. }
  118. // Extra fields
  119. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  120. $object->fields = dol_sort_array($object->fields, 'position');
  121. $arrayfields = dol_sort_array($arrayfields, 'position');
  122. $permissiontoread = $user->rights->stock->lire;
  123. $permissiontodelete = $user->rights->stock->supprimer;
  124. $permissiontoadd = $user->rights->stock->creer;
  125. // Security check
  126. $result = restrictedArea($user, 'stock');
  127. /*
  128. * Actions
  129. */
  130. if (GETPOST('cancel', 'alpha')) {
  131. $action = 'list';
  132. $massaction = '';
  133. }
  134. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  135. $massaction = '';
  136. }
  137. $parameters = array();
  138. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  139. if ($reshook < 0) {
  140. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  141. }
  142. if (empty($reshook)) {
  143. // Selection of new fields
  144. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  145. // Purge search criteria
  146. 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
  147. foreach ($object->fields as $key => $val) {
  148. $search[$key] = '';
  149. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  150. $search[$key.'_dtstart'] = '';
  151. $search[$key.'_dtend'] = '';
  152. }
  153. }
  154. $toselect = array();
  155. $search_array_options = array();
  156. $search_category_list = array();
  157. }
  158. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  159. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  160. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  161. }
  162. // Mass actions
  163. $objectclass = 'Entrepot';
  164. $objectlabel = 'Warehouse';
  165. $uploaddir = $conf->stock->dir_output;
  166. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  167. }
  168. /*
  169. * View
  170. */
  171. $form = new Form($db);
  172. $warehouse = new Entrepot($db);
  173. $now = dol_now();
  174. $title = $langs->trans("Warehouses");
  175. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  176. // Build and execute select
  177. // --------------------------------------------------------------------
  178. $sql = 'SELECT ';
  179. $sql .= $object->getFieldList('t');
  180. // Add fields from extrafields
  181. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  182. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  183. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  184. }
  185. }
  186. //For Multicompany PMP per entity
  187. $separatedPMP = false;
  188. if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
  189. $separatedPMP = true;
  190. $sql .= ", SUM(pa.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
  191. } else {
  192. $sql .= ", SUM(p.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue, SUM(ps.reel) as stockqty";
  193. }
  194. // Add fields from hooks
  195. $parameters = array();
  196. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  197. $sql .= $hookmanager->resPrint;
  198. $sql = preg_replace('/,\s*$/', '', $sql);
  199. $sqlfields = $sql; // $sql fields to remove for count total
  200. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  201. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  202. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  203. }
  204. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON t.rowid = ps.fk_entrepot";
  205. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
  206. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as c_dep ON c_dep.rowid = t.fk_departement";
  207. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as ccount ON ccount.rowid = t.fk_pays";
  208. if ($separatedPMP) {
  209. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_perentity as pa ON pa.fk_product = p.rowid AND pa.fk_product = ps.fk_product AND pa.entity = ". (int) $conf->entity;
  210. }
  211. $sql .= " WHERE t.entity IN (".getEntity('stock').")";
  212. foreach ($search as $key => $val) {
  213. if (array_key_exists($key, $object->fields)) {
  214. $class_key = $key;
  215. if ($class_key == 'status') {
  216. $class_key = 'statut'; // remove this after refactoring entrepot.class property statut to status
  217. }
  218. if (($key == 'status' && $search[$key] == -1) || $key == 'entity') {
  219. continue;
  220. }
  221. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  222. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  223. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  224. $search[$key] = '';
  225. }
  226. $mode_search = 2;
  227. }
  228. if ($search[$key] != '') {
  229. $sql .= natural_search((($key == "ref") ? "t.ref" : "t.".$class_key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  230. }
  231. } else {
  232. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  233. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  234. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  235. if (preg_match('/_dtstart$/', $key)) {
  236. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  237. }
  238. if (preg_match('/_dtend$/', $key)) {
  239. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  240. }
  241. }
  242. }
  243. }
  244. }
  245. if ($search_all) {
  246. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  247. }
  248. // Search for tag/category ($searchCategoryWarehouseList is an array of ID)
  249. $searchCategoryWarehouseList = $search_category_list;
  250. $searchCategoryWarehouseOperator = 0;
  251. if (!empty($searchCategoryWarehouseList)) {
  252. $searchCategoryWarehouseSqlList = array();
  253. $listofcategoryid = '';
  254. foreach ($searchCategoryWarehouseList as $searchCategoryWarehouse) {
  255. if (intval($searchCategoryWarehouse) == -2) {
  256. $searchCategoryWarehouseSqlList[] = " NOT EXISTS (SELECT ck.fk_warehouse FROM ".MAIN_DB_PREFIX."categorie_warehouse as ck WHERE t.rowid = ck.fk_warehouse)";
  257. } elseif (intval($searchCategoryWarehouse) > 0) {
  258. if ($searchCategoryWarehouseOperator == 0) {
  259. $searchCategoryWarehouseSqlList[] = " EXISTS (SELECT ck.fk_warehouse FROM ".MAIN_DB_PREFIX."categorie_warehouse as ck WHERE t.rowid = ck.fk_warehouse AND ck.fk_categorie = ".((int) $searchCategoryWarehouse).")";
  260. } else {
  261. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryWarehouse);
  262. }
  263. }
  264. }
  265. if ($listofcategoryid) {
  266. $searchCategoryWarehouseSqlList[] = " EXISTS (SELECT ck.fk_warehouse FROM ".MAIN_DB_PREFIX."categorie_warehouse as ck WHERE t.rowid = ck.fk_warehouse AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  267. }
  268. if ($searchCategoryWarehouseOperator == 1) {
  269. if (!empty($searchCategoryWarehouseSqlList)) {
  270. $sql .= " AND (".implode(' OR ', $searchCategoryWarehouseSqlList).")";
  271. }
  272. } else {
  273. if (!empty($searchCategoryWarehouseSqlList)) {
  274. $sql .= " AND (".implode(' AND ', $searchCategoryWarehouseSqlList).")";
  275. }
  276. }
  277. }
  278. // Add where from extra fields
  279. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  280. // Add where from hooks
  281. $parameters = array();
  282. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  283. $sql .= $hookmanager->resPrint;
  284. $sql .= " GROUP BY ";
  285. foreach ($object->fields as $key => $val) {
  286. $sql .= "t.".$db->escape($key).", ";
  287. }
  288. // Add fields from extrafields
  289. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  290. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  291. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  292. }
  293. }
  294. // Add groupby from hooks
  295. $parameters = array();
  296. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters); // Note that $action and $object may have been modified by hook
  297. $sql .= $hookmanager->resPrint;
  298. $sql = preg_replace('/,\s*$/', '', $sql);
  299. $result = $db->query($sql);
  300. if ($result) {
  301. $totalnboflines = $db->num_rows($result);
  302. // fetch totals
  303. $line = $total = $totalsell = $totalStock = 0;
  304. while ($line < $totalnboflines) {
  305. $objp = $db->fetch_object($result);
  306. $total += $objp->estimatedvalue;
  307. $totalsell += $objp->sellvalue;
  308. $totalStock += $objp->stockqty;
  309. $line++;
  310. }
  311. $totalarray['val']['stockqty'] = price2num($totalStock, 'MS');
  312. $totalarray['val']['estimatedvalue'] = price2num($total, 'MT');
  313. $totalarray['val']['estimatedstockvaluesell'] = price2num($totalsell, 'MT');
  314. }
  315. // Count total nb of records
  316. $nbtotalofrecords = '';
  317. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  318. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  319. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  320. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  321. $resql = $db->query($sqlforcount);
  322. if ($resql) {
  323. $objforcount = $db->fetch_object($resql);
  324. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  325. } else {
  326. dol_print_error($db);
  327. }
  328. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  329. $page = 0;
  330. $offset = 0;
  331. }
  332. $db->free($resql);
  333. }
  334. // Complete request and execute it with limit
  335. $sql .= $db->order($sortfield, $sortorder);
  336. if ($limit) {
  337. $sql .= $db->plimit($limit + 1, $offset);
  338. }
  339. $resql = $db->query($sql);
  340. if (!$resql) {
  341. dol_print_error($db);
  342. exit;
  343. }
  344. $num = $db->num_rows($resql);
  345. // Direct jump if only one record found
  346. if ($num == 1 && !getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  347. $obj = $db->fetch_object($resql);
  348. $id = $obj->rowid;
  349. header("Location: ".DOL_URL_ROOT.'/product/stock/card.php?id='.$id);
  350. exit;
  351. }
  352. // Output page
  353. // --------------------------------------------------------------------
  354. llxHeader('', $title, $help_url);
  355. $arrayofselected = is_array($toselect) ? $toselect : array();
  356. $param = '';
  357. if (!empty($mode)) {
  358. $param .= '&mode='.urlencode($mode);
  359. }
  360. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  361. $param .= '&contextpage='.urlencode($contextpage);
  362. }
  363. if ($limit > 0 && $limit != $conf->liste_limit) {
  364. $param .= '&limit='.((int) $limit);
  365. }
  366. if ($optioncss != '') {
  367. $param .= '&optioncss='.urlencode($optioncss);
  368. }
  369. foreach ($search as $key => $val) {
  370. if (is_array($search[$key])) {
  371. foreach ($search[$key] as $skey) {
  372. if ($skey != '') {
  373. $param .= '&search_'.$key.'[]='.urlencode($skey);
  374. }
  375. }
  376. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  377. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  378. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  379. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  380. } elseif ($search[$key] != '') {
  381. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  382. }
  383. }
  384. // Add $param from extra fields
  385. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  386. // Add $param from hooks
  387. $parameters = array();
  388. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  389. $param .= $hookmanager->resPrint;
  390. // List of mass actions available
  391. $arrayofmassactions = array(
  392. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  393. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  394. );
  395. //if ($user->rights->stock->supprimer) $arrayofmassactions['predelete']=img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  396. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  397. $arrayofmassactions = array();
  398. }
  399. if (isModEnabled('category') && $user->hasRight('stock', 'creer')) {
  400. $arrayofmassactions['preaffecttag'] = img_picto('', 'label', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  401. }
  402. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  403. print '<form action="'.$_SERVER["PHP_SELF"].'" id="searchFormList" method="POST" name="formulaire">';
  404. if ($optioncss != '') {
  405. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  406. }
  407. print '<input type="hidden" name="token" value="'.newToken().'">';
  408. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  409. print '<input type="hidden" name="action" value="list">';
  410. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  411. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  412. print '<input type="hidden" name="page" value="'.$page.'">';
  413. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  414. print '<input type="hidden" name="page_y" value="">';
  415. print '<input type="hidden" name="mode" value="'.$mode.'">';
  416. $newcardbutton = '';
  417. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  418. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  419. $newcardbutton .= dolGetButtonTitleSeparator();
  420. $newcardbutton .= dolGetButtonTitle($langs->trans('MenuNewWarehouse'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/stock/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->hasRight('stock', 'creer'));
  421. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'stock', 0, $newcardbutton, '', $limit, 0, 0, 1);
  422. // Add code for pre mass action (confirmation or email presend form)
  423. $topicmail = "Information";
  424. $modelmail = "warehouse";
  425. $objecttmp = new Entrepot($db);
  426. $trackid = 'ware'.$object->id;
  427. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  428. if ($search_all) {
  429. $setupstring = '';
  430. foreach ($fieldstosearchall as $key => $val) {
  431. $fieldstosearchall[$key] = $langs->trans($val);
  432. $setupstring .= $key."=".$val.";";
  433. }
  434. print '<!-- Search done like if STOCK_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  435. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  436. }
  437. $moreforfilter = '';
  438. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  439. $formcategory = new FormCategory($db);
  440. $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_WAREHOUSE, $search_category_list);
  441. }
  442. /*$moreforfilter.='<div class="divsearchfield">';
  443. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  444. $moreforfilter.= '</div>';*/
  445. $parameters = array();
  446. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  447. if (empty($reshook)) {
  448. $moreforfilter .= $hookmanager->resPrint;
  449. } else {
  450. $moreforfilter = $hookmanager->resPrint;
  451. }
  452. if (!empty($moreforfilter)) {
  453. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  454. print $moreforfilter;
  455. $parameters = array();
  456. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  457. print $hookmanager->resPrint;
  458. print '</div>';
  459. }
  460. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  461. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  462. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  463. print '<div class="div-table-responsive">';
  464. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  465. // Fields title search
  466. // --------------------------------------------------------------------
  467. print '<tr class="liste_titre_filter">';
  468. // Action column
  469. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  470. print '<td class="liste_titre center maxwidthsearch">';
  471. $searchpicto = $form->showFilterButtons('left');
  472. print $searchpicto;
  473. print '</td>';
  474. }
  475. foreach ($object->fields as $key => $val) {
  476. if ($key == 'statut') {
  477. continue;
  478. }
  479. $searchkey = empty($search[$key]) ? '' : $search[$key];
  480. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  481. if ($key == 'status') {
  482. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  483. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  484. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  485. } elseif (in_array($val['type'], array('timestamp'))) {
  486. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  487. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  488. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  489. }
  490. if (!empty($arrayfields['t.'.$key]['checked'])) {
  491. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
  492. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  493. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), (isset($val['notnull']) ? $val['notnull'] : 0), 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
  494. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  495. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  496. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  497. print '<div class="nowrap">';
  498. print $form->selectDate(isset($search[$key.'_dtstart']) ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  499. print '</div>';
  500. print '<div class="nowrap">';
  501. print $form->selectDate(isset($search[$key.'_dtend']) ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  502. print '</div>';
  503. } elseif ($key == 'lang') {
  504. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  505. $formadmin = new FormAdmin($db);
  506. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  507. } else {
  508. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  509. }
  510. print '</td>';
  511. }
  512. }
  513. if (!empty($arrayfields["stockqty"]['checked'])) {
  514. print '<td class="liste_titre"></td>';
  515. }
  516. if (!empty($arrayfields["estimatedvalue"]['checked'])) {
  517. print '<td class="liste_titre"></td>';
  518. }
  519. if (!empty($arrayfields["estimatedstockvaluesell"]['checked'])) {
  520. print '<td class="liste_titre"></td>';
  521. }
  522. // Extra fields
  523. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  524. // Fields from hook
  525. $parameters = array('arrayfields'=>$arrayfields);
  526. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  527. print $hookmanager->resPrint;
  528. // Status
  529. if (!empty($arrayfields['t.statut']['checked'])) {
  530. print '<td class="liste_titre center parentonrightofpage">';
  531. print $form->selectarray('search_status', $warehouse->labelStatus, $search_status, 1, 0, 0, '', 1, 0, 0, '', 'search_status width100 onrightofpage');
  532. print '</td>';
  533. }
  534. // Action column
  535. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  536. print '<td class="liste_titre center maxwidthsearch">';
  537. $searchpicto = $form->showFilterButtons();
  538. print $searchpicto;
  539. print '</td>';
  540. }
  541. print '</tr>'."\n";
  542. $totalarray['nbfield'] = 0;
  543. // Fields title label
  544. // --------------------------------------------------------------------
  545. print '<tr class="liste_titre">';
  546. // Action column
  547. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  548. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  549. $totalarray['nbfield']++;
  550. }
  551. foreach ($object->fields as $key => $val) {
  552. if ($key == 'statut') {
  553. continue;
  554. }
  555. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  556. if ($key == 'status') {
  557. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  558. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  559. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  560. } elseif (in_array($val['type'], array('timestamp'))) {
  561. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  562. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  563. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  564. }
  565. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  566. if (!empty($arrayfields['t.'.$key]['checked'])) {
  567. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
  568. $totalarray['nbfield']++;
  569. }
  570. }
  571. if (!empty($arrayfields["stockqty"]['checked'])) {
  572. print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stockqty", '', $param, '', $sortfield, $sortorder, 'right ');
  573. $totalarray['nbfield']++;
  574. $totalarray['type'][$totalarray['nbfield']] = 'stock';
  575. }
  576. if (!empty($arrayfields["estimatedvalue"]['checked'])) {
  577. print_liste_field_titre("EstimatedStockValue", $_SERVER["PHP_SELF"], "estimatedvalue", '', $param, '', $sortfield, $sortorder, 'right ');
  578. $totalarray['nbfield']++;
  579. $totalarray['type'][$totalarray['nbfield']] = 'price';
  580. }
  581. if (!empty($arrayfields["estimatedstockvaluesell"]['checked'])) {
  582. print_liste_field_titre("EstimatedStockValueSell", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
  583. $totalarray['nbfield']++;
  584. $totalarray['type'][$totalarray['nbfield']] = 'price';
  585. }
  586. // Extra fields
  587. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  588. // Hook fields
  589. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  590. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  591. print $hookmanager->resPrint;
  592. if (!empty($arrayfields['t.statut']['checked'])) {
  593. print_liste_field_titre($arrayfields['t.statut']['label'], $_SERVER["PHP_SELF"], "t.statut", '', $param, '', $sortfield, $sortorder, 'center ');
  594. $totalarray['nbfield']++;
  595. }
  596. // Action column
  597. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  598. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  599. $totalarray['nbfield']++;
  600. }
  601. print '</tr>'."\n";
  602. $warehouse = new Entrepot($db);
  603. // Loop on record
  604. // --------------------------------------------------------------------
  605. $i = 0;
  606. $savnbfield = $totalarray['nbfield'];
  607. $totalarray['nbfield'] = 0;
  608. $imaxinloop = ($limit ? min($num, $limit) : $num);
  609. while ($i < $imaxinloop) {
  610. $obj = $db->fetch_object($resql);
  611. if (empty($obj)) {
  612. break; // Should not happen
  613. }
  614. // Store properties in $object
  615. $warehouse->setVarsFromFetchObj($obj);
  616. $warehouse->label = $warehouse->ref;
  617. $warehouse->sellvalue = $obj->sellvalue;
  618. $object = $warehouse;
  619. if ($mode == 'kanban') {
  620. if ($i == 0) {
  621. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  622. print '<div class="box-flex-container kanban">';
  623. }
  624. // Output Kanban
  625. $selected = -1;
  626. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  627. $selected = 0;
  628. if (in_array($object->id, $arrayofselected)) {
  629. $selected = 1;
  630. }
  631. }
  632. print $object->getKanbanView('', array('selected' => $selected));
  633. if ($i == ($imaxinloop - 1)) {
  634. print '</div>';
  635. print '</td></tr>';
  636. }
  637. } else {
  638. // Show line of result
  639. $j = 0;
  640. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  641. // Action column
  642. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  643. print '<td class="nowrap center">';
  644. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  645. $selected = 0;
  646. if (in_array($object->id, $arrayofselected)) {
  647. $selected = 1;
  648. }
  649. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  650. }
  651. print '</td>';
  652. if (!$i) {
  653. $totalarray['nbfield']++;
  654. }
  655. }
  656. foreach ($object->fields as $key => $val) {
  657. if ($key == 'statut') {
  658. continue;
  659. }
  660. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  661. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  662. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  663. } elseif ($key == 'status') {
  664. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  665. }
  666. if (in_array($val['type'], array('timestamp'))) {
  667. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  668. } elseif ($key == 'ref') {
  669. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  670. }
  671. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
  672. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  673. }
  674. if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) {
  675. $cssforfield = 'tdoverflowmax100';
  676. }
  677. if (!empty($arrayfields['t.'.$key]['checked'])) {
  678. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  679. if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
  680. print ' title="'.dol_escape_htmltag($object->$key).'"';
  681. }
  682. print '>';
  683. if ($key == 'statut') {
  684. print $object->getLibStatut(5);
  685. }
  686. if ($key == 'phone') {
  687. print dol_print_phone($object->phone, '', 0, $object->id, 'AC_TEL');
  688. } elseif ($key == 'fax') {
  689. print dol_print_phone($object->fax, '', 0, $object->id, 'AC_FAX');
  690. } else {
  691. print $warehouse->showOutputField($val, $key, $object->$key, '');
  692. }
  693. print '</td>';
  694. if (!$i) {
  695. $totalarray['nbfield']++;
  696. }
  697. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  698. if (!$i) {
  699. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  700. }
  701. if (!isset($totalarray['val'])) {
  702. $totalarray['val'] = array();
  703. }
  704. if (!isset($totalarray['val']['t.'.$key])) {
  705. $totalarray['val']['t.'.$key] = 0;
  706. }
  707. $totalarray['val']['t.'.$key] += $object->$key;
  708. }
  709. }
  710. }
  711. // Stock qty
  712. if (!empty($arrayfields["stockqty"]['checked'])) {
  713. print '<td class="right">'.price(price2num($obj->stockqty, 'MS')).'</td>';
  714. if (!$i) {
  715. $totalarray['nbfield']++;
  716. }
  717. if (!$i) {
  718. $totalarray['pos'][$totalarray['nbfield']] = 'stockqty';
  719. }
  720. }
  721. // PMP value
  722. if (!empty($arrayfields["estimatedvalue"]['checked'])) {
  723. print '<td class="right">';
  724. if (price2num($obj->estimatedvalue, 'MT')) {
  725. print '<span class="amount">'.price(price2num($obj->estimatedvalue, 'MT'), 1).'</span>';
  726. } else {
  727. print '';
  728. }
  729. print '</td>';
  730. if (!$i) {
  731. $totalarray['nbfield']++;
  732. }
  733. if (!$i) {
  734. $totalarray['pos'][$totalarray['nbfield']] = 'estimatedvalue';
  735. }
  736. }
  737. // Selling value
  738. if (!empty($arrayfields["estimatedstockvaluesell"]['checked'])) {
  739. print '<td class="right">';
  740. if (!getDolGlobalString('PRODUIT_MULTIPRICES')) {
  741. if ($obj->sellvalue) {
  742. print '<span class="amount">'.price(price2num($obj->sellvalue, 'MT'), 1).'</span>';
  743. }
  744. } else {
  745. $htmltext = $langs->trans("OptionMULTIPRICESIsOn");
  746. print $form->textwithtooltip('<span class="opacitymedium">'.$langs->trans("Variable").'</span>', $htmltext);
  747. }
  748. print '</td>';
  749. if (!$i) {
  750. $totalarray['nbfield']++;
  751. }
  752. if (!$i) {
  753. $totalarray['pos'][$totalarray['nbfield']] = 'estimatedstockvaluesell';
  754. }
  755. }
  756. // Extra fields
  757. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  758. // Fields from hook
  759. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  760. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  761. print $hookmanager->resPrint;
  762. // Status
  763. if (!empty($arrayfields['t.statut']['checked'])) {
  764. print '<td class="center">'.$warehouse->LibStatut($obj->statut, 5).'</td>';
  765. if (!$i) {
  766. $totalarray['nbfield']++;
  767. }
  768. }
  769. // Action column
  770. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  771. print '<td class="nowrap center">';
  772. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  773. $selected = 0;
  774. if (in_array($object->id, $arrayofselected)) {
  775. $selected = 1;
  776. }
  777. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  778. }
  779. print '</td>';
  780. if (!$i) {
  781. $totalarray['nbfield']++;
  782. }
  783. }
  784. print '</tr>'."\n";
  785. }
  786. $i++;
  787. }
  788. if ($totalnboflines - $offset <= $limit) {
  789. // Show total line
  790. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  791. }
  792. // If no record found
  793. if ($num == 0) {
  794. $colspan = 1;
  795. foreach ($arrayfields as $key => $val) {
  796. if (!empty($val['checked'])) {
  797. $colspan++;
  798. }
  799. }
  800. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  801. }
  802. $db->free($resql);
  803. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  804. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  805. print $hookmanager->resPrint;
  806. print '</table>'."\n";
  807. print '</div>'."\n";
  808. print '</form>'."\n";
  809. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  810. $hidegeneratedfilelistifempty = 1;
  811. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  812. $hidegeneratedfilelistifempty = 0;
  813. }
  814. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  815. $formfile = new FormFile($db);
  816. // Show list of available documents
  817. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  818. $urlsource .= str_replace('&amp;', '&', $param);
  819. $filedir = $diroutputmassaction;
  820. $genallowed = $user->rights->stock->lire;
  821. $delallowed = $user->rights->stock->creer;
  822. print $formfile->showdocuments('massfilesarea_stock', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  823. }
  824. // End of page
  825. llxFooter();
  826. $db->close();