list.php 32 KB

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