list.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  9. * Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2019-2021 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/expensereport/list.php
  27. * \ingroup expensereport
  28. * \brief list of expense reports
  29. */
  30. // Load Dolibarr environment
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formexpensereport.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array('companies', 'users', 'trips'));
  42. $action = GETPOST('action', 'aZ09');
  43. $massaction = GETPOST('massaction', 'alpha');
  44. $show_files = GETPOST('show_files', 'int');
  45. $confirm = GETPOST('confirm', 'alpha');
  46. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  47. $toselect = GETPOST('toselect', 'array');
  48. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'expensereportlist';
  49. $mode = GETPOST('mode', 'alpha');
  50. $childids = $user->getAllChildIds(1);
  51. // Security check
  52. $socid = GETPOST('socid', 'int');
  53. if ($user->socid) {
  54. $socid = $user->socid;
  55. }
  56. $result = restrictedArea($user, 'expensereport', '', '');
  57. $id = GETPOST('id', 'int');
  58. // If we are on the view of a specific user
  59. if ($id > 0) {
  60. $canread = 0;
  61. if ($id == $user->id) {
  62. $canread = 1;
  63. }
  64. if ($user->hasRight('expensereport', 'readall')) {
  65. $canread = 1;
  66. }
  67. if ($user->hasRight('expensereport', 'lire') && in_array($id, $childids)) {
  68. $canread = 1;
  69. }
  70. if (!$canread) {
  71. accessforbidden();
  72. }
  73. }
  74. $diroutputmassaction = $conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id;
  75. // Load variable for pagination
  76. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  77. $sortfield = GETPOST('sortfield', 'aZ09comma');
  78. $sortorder = GETPOST('sortorder', 'aZ09comma');
  79. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  80. if (empty($page) || $page == -1) {
  81. $page = 0;
  82. } // If $page is not defined, or '' or -1
  83. $offset = $limit * $page;
  84. $pageprev = $page - 1;
  85. $pagenext = $page + 1;
  86. if (!$sortorder) {
  87. $sortorder = "DESC";
  88. }
  89. if (!$sortfield) {
  90. $sortfield = "d.date_debut";
  91. }
  92. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  93. $search_ref = GETPOST('search_ref', 'alpha');
  94. $search_user = GETPOST('search_user', 'int');
  95. $search_amount_ht = GETPOST('search_amount_ht', 'alpha');
  96. $search_amount_vat = GETPOST('search_amount_vat', 'alpha');
  97. $search_amount_ttc = GETPOST('search_amount_ttc', 'alpha');
  98. $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : GETPOST('statut', 'intcomma'));
  99. $search_date_startday = GETPOST('search_date_startday', 'int');
  100. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  101. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  102. $search_date_startendday = GETPOST('search_date_startendday', 'int');
  103. $search_date_startendmonth = GETPOST('search_date_startendmonth', 'int');
  104. $search_date_startendyear = GETPOST('search_date_startendyear', 'int');
  105. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  106. $search_date_startend = dol_mktime(23, 59, 59, $search_date_startendmonth, $search_date_startendday, $search_date_startendyear);
  107. $search_date_endday = GETPOST('search_date_endday', 'int');
  108. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  109. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  110. $search_date_endendday = GETPOST('search_date_endendday', 'int');
  111. $search_date_endendmonth = GETPOST('search_date_endendmonth', 'int');
  112. $search_date_endendyear = GETPOST('search_date_endendyear', 'int');
  113. $search_date_end = dol_mktime(0, 0, 0, $search_date_endmonth, $search_date_endday, $search_date_endyear); // Use tzserver
  114. $search_date_endend = dol_mktime(23, 59, 59, $search_date_endendmonth, $search_date_endendday, $search_date_endendyear);
  115. $optioncss = GETPOST('optioncss', 'alpha');
  116. if ($search_status == '') {
  117. $search_status = -1;
  118. }
  119. if ($search_user == '') {
  120. $search_user = -1;
  121. }
  122. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  123. $object = new ExpenseReport($db);
  124. $hookmanager->initHooks(array('expensereportlist'));
  125. $extrafields = new ExtraFields($db);
  126. // fetch optionals attributes and labels
  127. $extrafields->fetch_name_optionals_label($object->table_element);
  128. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  129. // List of fields to search into when doing a "search in all"
  130. $fieldstosearchall = array(
  131. 'd.ref'=>'Ref',
  132. 'd.note_public'=>"NotePublic",
  133. 'u.lastname'=>'EmployeeLastname',
  134. 'u.firstname'=>"EmployeeFirstname",
  135. 'u.login'=>"Login",
  136. );
  137. if (empty($user->socid)) {
  138. $fieldstosearchall["d.note_private"] = "NotePrivate";
  139. }
  140. $arrayfields = array(
  141. 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  142. 'user'=>array('label'=>$langs->trans("User"), 'checked'=>1),
  143. 'd.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1),
  144. 'd.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1),
  145. 'd.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1),
  146. 'd.date_approve'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1),
  147. 'd.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  148. 'd.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
  149. 'd.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
  150. 'd.date_create'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  151. 'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  152. 'd.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  153. );
  154. // Extra fields
  155. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  156. $canedituser = (!empty($user->admin) || $user->hasRight('user', 'user', 'creer'));
  157. $objectuser = new User($db);
  158. /*
  159. * Actions
  160. */
  161. if (GETPOST('cancel', 'alpha')) {
  162. $action = 'list';
  163. $massaction = '';
  164. }
  165. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  166. $massaction = '';
  167. }
  168. $parameters = array('socid'=>$socid);
  169. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  170. if ($reshook < 0) {
  171. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  172. }
  173. if (empty($reshook)) {
  174. // Selection of new fields
  175. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  176. // Purge search criteria
  177. 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
  178. $search_ref = "";
  179. $search_user = "";
  180. $search_amount_ht = "";
  181. $search_amount_vat = "";
  182. $search_amount_ttc = "";
  183. $search_status = "";
  184. $search_date_startday = '';
  185. $search_date_startmonth = '';
  186. $search_date_startyear = '';
  187. $search_date_startendday = '';
  188. $search_date_startendmonth = '';
  189. $search_date_startendyear = '';
  190. $search_date_start = '';
  191. $search_date_startend = '';
  192. $search_date_endday = '';
  193. $search_date_endmonth = '';
  194. $search_date_endyear = '';
  195. $search_date_endendday = '';
  196. $search_date_endendmonth = '';
  197. $search_date_endendyear = '';
  198. $search_date_end = '';
  199. $search_date_endend = '';
  200. $toselect = array();
  201. $search_array_options = array();
  202. }
  203. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  204. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  205. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  206. }
  207. // Mass actions
  208. $objectclass = 'ExpenseReport';
  209. $objectlabel = 'ExpenseReport';
  210. $permissiontoread = $user->rights->expensereport->lire;
  211. $permissiontodelete = $user->rights->expensereport->supprimer;
  212. $uploaddir = $conf->expensereport->dir_output;
  213. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  214. }
  215. /*
  216. * View
  217. */
  218. $form = new Form($db);
  219. $formother = new FormOther($db);
  220. $formfile = new FormFile($db);
  221. $formexpensereport = new FormExpenseReport($db);
  222. $fuser = new User($db);
  223. $title = $langs->trans("TripsAndExpenses");
  224. llxHeader('', $title);
  225. $max_year = 5;
  226. $min_year = 10;
  227. // Get current user id
  228. $user_id = $user->id;
  229. if ($id > 0) {
  230. // Charge utilisateur edite
  231. $fuser->fetch($id, '', '', 1);
  232. $fuser->getrights();
  233. $user_id = $fuser->id;
  234. $search_user = $user_id;
  235. }
  236. $sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,";
  237. $sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve, d.note_private, d.note_public,";
  238. $sql .= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut as user_status, u.photo";
  239. // Add fields from extrafields
  240. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  241. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  242. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  243. }
  244. }
  245. // Add fields from hooks
  246. $parameters = array();
  247. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  248. $sql .= $hookmanager->resPrint;
  249. $sqlfields = $sql; // $sql fields to remove for count total
  250. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d";
  251. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  252. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
  253. }
  254. $sql .= ", ".MAIN_DB_PREFIX."user as u";
  255. $sql .= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")";
  256. // Search all
  257. if (!empty($sall)) {
  258. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  259. }
  260. // Ref
  261. if (!empty($search_ref)) {
  262. $sql .= natural_search('d.ref', $search_ref);
  263. }
  264. // Date Start
  265. if ($search_date_start) {
  266. $sql .= " AND d.date_debut >= '".$db->idate($search_date_start)."'";
  267. }
  268. if ($search_date_startend) {
  269. $sql .= " AND d.date_debut <= '".$db->idate($search_date_startend)."'";
  270. }
  271. // Date End
  272. if ($search_date_end) {
  273. $sql .= " AND d.date_fin >= '".$db->idate($search_date_end)."'";
  274. }
  275. if ($search_date_endend) {
  276. $sql .= " AND d.date_fin <= '".$db->idate($search_date_endend)."'";
  277. }
  278. if ($search_amount_ht != '') {
  279. $sql .= natural_search('d.total_ht', $search_amount_ht, 1);
  280. }
  281. if ($search_amount_ttc != '') {
  282. $sql .= natural_search('d.total_ttc', $search_amount_ttc, 1);
  283. }
  284. // User
  285. if ($search_user != '' && $search_user >= 0) {
  286. $sql .= " AND u.rowid = '".$db->escape($search_user)."'";
  287. }
  288. // Status
  289. if ($search_status != '' && $search_status >= 0) {
  290. $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
  291. }
  292. // RESTRICT RIGHTS
  293. if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
  294. && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
  295. $sql .= " AND d.fk_user_author IN (".$db->sanitize(join(',', $childids)).")\n";
  296. }
  297. // Add where from extra fields
  298. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  299. // Add where from hooks
  300. $parameters = array();
  301. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  302. $sql .= $hookmanager->resPrint;
  303. // Count total nb of records
  304. $nbtotalofrecords = '';
  305. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  306. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  307. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  308. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  309. $resql = $db->query($sqlforcount);
  310. if ($resql) {
  311. $objforcount = $db->fetch_object($resql);
  312. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  313. } else {
  314. dol_print_error($db);
  315. }
  316. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  317. $page = 0;
  318. $offset = 0;
  319. }
  320. $db->free($resql);
  321. }
  322. // Complete request and execute it with limit
  323. $sql .= $db->order($sortfield, $sortorder);
  324. if ($limit) {
  325. $sql .= $db->plimit($limit + 1, $offset);
  326. }
  327. //print $sql;
  328. $resql = $db->query($sql);
  329. if ($resql) {
  330. $num = $db->num_rows($resql);
  331. $arrayofselected = is_array($toselect) ? $toselect : array();
  332. $param = '';
  333. if (!empty($mode)) {
  334. $param .= '&mode='.urlencode($mode);
  335. }
  336. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  337. $param .= '&contextpage='.urlencode($contextpage);
  338. }
  339. if ($limit > 0 && $limit != $conf->liste_limit) {
  340. $param .= '&limit='.((int) $limit);
  341. }
  342. if ($sall) {
  343. $param .= "&sall=".urlencode($sall);
  344. }
  345. if ($search_ref) {
  346. $param .= "&search_ref=".urlencode($search_ref);
  347. }
  348. // Start date
  349. if ($search_date_startday) {
  350. $param .= '&search_date_startday='.urlencode($search_date_startday);
  351. }
  352. if ($search_date_startmonth) {
  353. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  354. }
  355. if ($search_date_startyear) {
  356. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  357. }
  358. if ($search_date_startendday) {
  359. $param .= '&search_date_startendday='.urlencode($search_date_startendday);
  360. }
  361. if ($search_date_startendmonth) {
  362. $param .= '&search_date_startendmonth='.urlencode($search_date_startendmonth);
  363. }
  364. if ($search_date_startendyear) {
  365. $param .= '&search_date_startendyear='.urlencode($search_date_startendyear);
  366. }
  367. // End date
  368. if ($search_date_endday) {
  369. $param .= '&search_date_endday='.urlencode($search_date_endday);
  370. }
  371. if ($search_date_endmonth) {
  372. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  373. }
  374. if ($search_date_endyear) {
  375. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  376. }
  377. if ($search_date_endendday) {
  378. $param .= '&search_date_endendday='.urlencode($search_date_endendday);
  379. }
  380. if ($search_date_endendmonth) {
  381. $param .= '&search_date_endendmonth='.urlencode($search_date_endendmonth);
  382. }
  383. if ($search_date_endendyear) {
  384. $param .= '&search_date_endendyear='.urlencode($search_date_endendyear);
  385. }
  386. if ($search_user) {
  387. $param .= "&search_user=".urlencode($search_user);
  388. }
  389. if ($search_amount_ht) {
  390. $param .= "&search_amount_ht=".urlencode($search_amount_ht);
  391. }
  392. if ($search_amount_ttc) {
  393. $param .= "&search_amount_ttc=".urlencode($search_amount_ttc);
  394. }
  395. if ($search_status >= 0) {
  396. $param .= "&search_status=".urlencode($search_status);
  397. }
  398. if ($optioncss != '') {
  399. $param .= '&optioncss='.urlencode($optioncss);
  400. }
  401. // Add $param from extra fields
  402. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  403. // List of mass actions available
  404. $arrayofmassactions = array(
  405. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  406. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  407. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  408. );
  409. if ($user->hasRight('expensereport', 'supprimer')) {
  410. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  411. }
  412. if (in_array($massaction, array('presend', 'predelete'))) {
  413. $arrayofmassactions = array();
  414. }
  415. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  416. // Lines of title fields
  417. print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  418. if ($optioncss != '') {
  419. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  420. }
  421. print '<input type="hidden" name="token" value="'.newToken().'">';
  422. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  423. print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">';
  424. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  425. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  426. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  427. print '<input type="hidden" name="mode" value="'.$mode.'">';
  428. if ($id > 0) {
  429. print '<input type="hidden" name="id" value="'.$id.'">';
  430. }
  431. if ($id > 0) { // For user tab
  432. $title = $langs->trans("User");
  433. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  434. $head = user_prepare_head($fuser);
  435. print dol_get_fiche_head($head, 'expensereport', $title, -1, 'user');
  436. dol_banner_tab($fuser, 'id', $linkback, $user->hasRight('user', 'user', 'lire') || $user->admin);
  437. print dol_get_fiche_end();
  438. if ($action != 'edit') {
  439. print '<div class="tabsAction">';
  440. $childids = $user->getAllChildIds(1);
  441. $canedit = ((in_array($user_id, $childids) && $user->rights->expensereport->creer)
  442. || ($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->expensereport->writeall_advance));
  443. // Buttons for actions
  444. if ($canedit) {
  445. print '<a href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create&fk_user_author='.$fuser->id.'" class="butAction">'.$langs->trans("AddTrip").'</a>';
  446. } else {
  447. print '<a href="#" class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddTrip").'</a>';
  448. }
  449. print '</div>';
  450. } else {
  451. print $form->buttonsSaveCancel("Save", '');
  452. }
  453. } else {
  454. $title = $langs->trans("ListTripsAndExpenses");
  455. $url = DOL_URL_ROOT.'/expensereport/card.php?action=create';
  456. if (!empty($socid)) {
  457. $url .= '&socid='.$socid;
  458. }
  459. $newcardbutton = '';
  460. $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'));
  461. $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'));
  462. $newcardbutton .= dolGetButtonTitleSeparator();
  463. $newcardbutton .= dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('expensereport', 'creer'));
  464. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'trip', 0, $newcardbutton, '', $limit, 0, 0, 1);
  465. }
  466. $topicmail = "SendExpenseReport";
  467. $modelmail = "expensereport";
  468. $objecttmp = new ExpenseReport($db);
  469. $trackid = 'exp'.$object->id;
  470. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  471. if ($sall) {
  472. foreach ($fieldstosearchall as $key => $val) {
  473. $fieldstosearchall[$key] = $langs->trans($val);
  474. }
  475. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  476. }
  477. $moreforfilter = '';
  478. $parameters = array();
  479. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  480. if (empty($reshook)) {
  481. $moreforfilter .= $hookmanager->resPrint;
  482. } else {
  483. $moreforfilter = $hookmanager->resPrint;
  484. }
  485. if (!empty($moreforfilter)) {
  486. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  487. print $moreforfilter;
  488. print '</div>';
  489. }
  490. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  491. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  492. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  493. print '<div class="div-table-responsive">';
  494. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  495. // Filters
  496. print '<tr class="liste_titre_filter">';
  497. // Action column
  498. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  499. print '<td class="liste_titre maxwidthsearch">';
  500. $searchpicto = $form->showFilterButtons('left');
  501. print $searchpicto;
  502. print '</td>';
  503. }
  504. if (!empty($arrayfields['d.ref']['checked'])) {
  505. print '<td class="liste_titre" align="left">';
  506. print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
  507. print '</td>';
  508. }
  509. // User
  510. if (!empty($arrayfields['user']['checked'])) {
  511. if ($user->hasRight('expensereport', 'readall') || $user->hasRight('expensereport', 'lire_tous')) {
  512. print '<td class="liste_titre maxwidthonspartphone" align="left">';
  513. print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  514. print '</td>';
  515. } else {
  516. print '<td class="liste_titre">&nbsp;</td>';
  517. }
  518. }
  519. // Date start
  520. if (!empty($arrayfields['d.date_debut']['checked'])) {
  521. print '<td class="liste_titre" align="center">';
  522. print '<div class="nowrapfordate">';
  523. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  524. print '</div>';
  525. print '<div class="nowrapfordate">';
  526. print $form->selectDate($search_date_startend ? $search_date_startend : -1, 'search_date_startend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  527. print '</div>';
  528. print '</td>';
  529. }
  530. // Date end
  531. if (!empty($arrayfields['d.date_fin']['checked'])) {
  532. print '<td class="liste_titre" align="center">';
  533. print '<div class="nowrapfordate">';
  534. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  535. print '</div>';
  536. print '<div class="nowrapfordate">';
  537. print $form->selectDate($search_date_endend ? $search_date_endend : -1, 'search_date_endend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  538. print '</div>';
  539. print '</td>';
  540. }
  541. // Date valid
  542. if (!empty($arrayfields['d.date_valid']['checked'])) {
  543. print '<td class="liste_titre" align="center">';
  544. //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  545. //print $formother->selectyear($year_end,'year_end',1, $min_year, $max_year);
  546. print '</td>';
  547. }
  548. // Date approve
  549. if (!empty($arrayfields['d.date_approve']['checked'])) {
  550. print '<td class="liste_titre" align="center">';
  551. //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  552. //print $formother->selectyear($year_end,'year_end',1, $min_year, $max_year);
  553. print '</td>';
  554. }
  555. // Amount with no tax
  556. if (!empty($arrayfields['d.total_ht']['checked'])) {
  557. print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ht" value="'.$search_amount_ht.'"></td>';
  558. }
  559. if (!empty($arrayfields['d.total_vat']['checked'])) {
  560. print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_vat" value="'.$search_amount_vat.'"></td>';
  561. }
  562. // Amount with all taxes
  563. if (!empty($arrayfields['d.total_ttc']['checked'])) {
  564. print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>';
  565. }
  566. // Extra fields
  567. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  568. // Fields from hook
  569. $parameters = array('arrayfields'=>$arrayfields);
  570. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  571. print $hookmanager->resPrint;
  572. // Date creation
  573. if (!empty($arrayfields['d.date_create']['checked'])) {
  574. print '<td class="liste_titre">';
  575. print '</td>';
  576. }
  577. // Date modification
  578. if (!empty($arrayfields['d.tms']['checked'])) {
  579. print '<td class="liste_titre">';
  580. print '</td>';
  581. }
  582. // Status
  583. if (!empty($arrayfields['d.fk_statut']['checked'])) {
  584. print '<td class="liste_titre center parentonrightofpage">';
  585. $formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1);
  586. print '</td>';
  587. }
  588. // Action column
  589. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  590. print '<td class="liste_titre maxwidthsearch">';
  591. $searchpicto = $form->showFilterButtons();
  592. print $searchpicto;
  593. print '</td>';
  594. }
  595. print "</tr>\n";
  596. $totalarray = array();
  597. $totalarray['nbfield'] = 0;
  598. print '<tr class="liste_titre">';
  599. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  600. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
  601. $totalarray['nbfield']++;
  602. }
  603. if (!empty($arrayfields['d.ref']['checked'])) {
  604. print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], "d.ref", "", $param, '', $sortfield, $sortorder);
  605. $totalarray['nbfield']++;
  606. }
  607. if (!empty($arrayfields['user']['checked'])) {
  608. print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder);
  609. $totalarray['nbfield']++;
  610. }
  611. if (!empty($arrayfields['d.date_debut']['checked'])) {
  612. print_liste_field_titre($arrayfields['d.date_debut']['label'], $_SERVER["PHP_SELF"], "d.date_debut", "", $param, '', $sortfield, $sortorder, 'center ');
  613. $totalarray['nbfield']++;
  614. }
  615. if (!empty($arrayfields['d.date_fin']['checked'])) {
  616. print_liste_field_titre($arrayfields['d.date_fin']['label'], $_SERVER["PHP_SELF"], "d.date_fin", "", $param, '', $sortfield, $sortorder, 'center ');
  617. $totalarray['nbfield']++;
  618. }
  619. if (!empty($arrayfields['d.date_valid']['checked'])) {
  620. print_liste_field_titre($arrayfields['d.date_valid']['label'], $_SERVER["PHP_SELF"], "d.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
  621. $totalarray['nbfield']++;
  622. }
  623. if (!empty($arrayfields['d.date_approve']['checked'])) {
  624. print_liste_field_titre($arrayfields['d.date_approve']['label'], $_SERVER["PHP_SELF"], "d.date_approve", "", $param, '', $sortfield, $sortorder, 'center ');
  625. $totalarray['nbfield']++;
  626. }
  627. if (!empty($arrayfields['d.total_ht']['checked'])) {
  628. print_liste_field_titre($arrayfields['d.total_ht']['label'], $_SERVER["PHP_SELF"], "d.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
  629. $totalarray['nbfield']++;
  630. }
  631. if (!empty($arrayfields['d.total_vat']['checked'])) {
  632. print_liste_field_titre($arrayfields['d.total_vat']['label'], $_SERVER["PHP_SELF"], "d.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
  633. $totalarray['nbfield']++;
  634. }
  635. if (!empty($arrayfields['d.total_ttc']['checked'])) {
  636. print_liste_field_titre($arrayfields['d.total_ttc']['label'], $_SERVER["PHP_SELF"], "d.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
  637. $totalarray['nbfield']++;
  638. }
  639. // Extra fields
  640. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  641. // Hook fields
  642. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  643. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  644. print $hookmanager->resPrint;
  645. if (!empty($arrayfields['d.date_create']['checked'])) {
  646. print_liste_field_titre($arrayfields['d.date_create']['label'], $_SERVER["PHP_SELF"], "d.date_create", "", $param, '', $sortfield, $sortorder, 'nowraponall center');
  647. $totalarray['nbfield']++;
  648. }
  649. if (!empty($arrayfields['d.tms']['checked'])) {
  650. print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, '', $sortfield, $sortorder, 'nowraponall center');
  651. $totalarray['nbfield']++;
  652. }
  653. if (!empty($arrayfields['d.fk_statut']['checked'])) {
  654. print_liste_field_titre($arrayfields['d.fk_statut']['label'], $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  655. $totalarray['nbfield']++;
  656. }
  657. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  658. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
  659. $totalarray['nbfield']++;
  660. }
  661. print "</tr>\n";
  662. $total_total_ht = 0;
  663. $total_total_ttc = 0;
  664. $total_total_tva = 0;
  665. $expensereportstatic = new ExpenseReport($db);
  666. $usertmp = new User($db);
  667. if ($num > 0) {
  668. $i = 0;
  669. $savnbfield = $totalarray['nbfield'];
  670. $totalarray = array();
  671. $totalarray['nbfield'] = 0;
  672. $totalarray['val'] = array();
  673. $totalarray['val']['d.total_ht'] = 0;
  674. $totalarray['val']['d.total_tva'] = 0;
  675. $totalarray['val']['d.total_ttc'] = 0;
  676. $totalarray['totalizable'] = array();
  677. $imaxinloop = ($limit ? min($num, $limit) : $num);
  678. while ($i < min($num, $limit)) {
  679. $obj = $db->fetch_object($resql);
  680. $expensereportstatic->id = $obj->rowid;
  681. $expensereportstatic->ref = $obj->ref;
  682. $expensereportstatic->status = $obj->status;
  683. $expensereportstatic->date_debut = $db->jdate($obj->date_debut);
  684. $expensereportstatic->date_fin = $db->jdate($obj->date_fin);
  685. $expensereportstatic->date_create = $db->jdate($obj->date_create);
  686. $expensereportstatic->date_modif = $db->jdate($obj->date_modif);
  687. $expensereportstatic->date_valid = $db->jdate($obj->date_valid);
  688. $expensereportstatic->date_approve = $db->jdate($obj->date_approve);
  689. $expensereportstatic->note_private = $obj->note_private;
  690. $expensereportstatic->note_public = $obj->note_public;
  691. $expensereportstatic->fk_user = $obj->id_user;
  692. $usertmp->id = $obj->id_user;
  693. $usertmp->lastname = $obj->lastname;
  694. $usertmp->firstname = $obj->firstname;
  695. $usertmp->login = $obj->login;
  696. $usertmp->statut = $obj->user_status;
  697. $usertmp->status = $obj->user_status;
  698. $usertmp->photo = $obj->photo;
  699. $usertmp->email = $obj->email;
  700. if ($mode == 'kanban') {
  701. if ($i == 0) {
  702. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  703. print '<div class="box-flex-container kanban">';
  704. }
  705. // TODO Use a cache on user
  706. $usertmp->fetch($obj->id_user);
  707. // Output Kanban
  708. if ($massactionbutton || $massaction) {
  709. $selected = 0;
  710. print $expensereportstatic->getKanbanView('', array('userauthor' => $usertmp, 'selected' => in_array($expensereportstatic->id, $arrayofselected)));
  711. }
  712. if ($i == ($imaxinloop - 1)) {
  713. print '</div>';
  714. print '</td></tr>';
  715. }
  716. } else {
  717. print '<tr class="oddeven">';
  718. // Action column
  719. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  720. print '<td class="nowrap center">';
  721. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  722. $selected = 0;
  723. if (in_array($obj->rowid, $arrayofselected)) {
  724. $selected = 1;
  725. }
  726. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  727. }
  728. print '</td>';
  729. if (!$i) {
  730. $totalarray['nbfield']++;
  731. }
  732. }
  733. // Ref
  734. if (!empty($arrayfields['d.ref']['checked'])) {
  735. print '<td>';
  736. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  737. print '<td class="nobordernopadding nowrap">';
  738. print $expensereportstatic->getNomUrl(1);
  739. print '</td>';
  740. // Warning late icon and note
  741. print '<td class="nobordernopadding nowrap">';
  742. if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) {
  743. print img_warning($langs->trans("Late"));
  744. }
  745. if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) {
  746. print img_warning($langs->trans("Late"));
  747. }
  748. if (!empty($obj->note_private) || !empty($obj->note_public)) {
  749. print ' <span class="note">';
  750. print '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
  751. print '</span>';
  752. }
  753. print '</td>';
  754. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  755. $filename = dol_sanitizeFileName($obj->ref);
  756. $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  757. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  758. print $formfile->getDocumentsLink($expensereportstatic->element, $filename, $filedir);
  759. print '</td>';
  760. print '</tr></table>';
  761. print '</td>';
  762. if (!$i) {
  763. $totalarray['nbfield']++;
  764. }
  765. }
  766. // User
  767. if (!empty($arrayfields['user']['checked'])) {
  768. print '<td class="left">';
  769. print $usertmp->getNomUrl(-1);
  770. print '</td>';
  771. if (!$i) {
  772. $totalarray['nbfield']++;
  773. }
  774. }
  775. // Start date
  776. if (!empty($arrayfields['d.date_debut']['checked'])) {
  777. print '<td class="center">'.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').'</td>';
  778. if (!$i) {
  779. $totalarray['nbfield']++;
  780. }
  781. }
  782. // End date
  783. if (!empty($arrayfields['d.date_fin']['checked'])) {
  784. print '<td class="center">'.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').'</td>';
  785. if (!$i) {
  786. $totalarray['nbfield']++;
  787. }
  788. }
  789. // Date validation
  790. if (!empty($arrayfields['d.date_valid']['checked'])) {
  791. print '<td class="center">'.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').'</td>';
  792. if (!$i) {
  793. $totalarray['nbfield']++;
  794. }
  795. }
  796. // Date approval
  797. if (!empty($arrayfields['d.date_approve']['checked'])) {
  798. print '<td class="center">'.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').'</td>';
  799. if (!$i) {
  800. $totalarray['nbfield']++;
  801. }
  802. }
  803. // Amount HT
  804. if (!empty($arrayfields['d.total_ht']['checked'])) {
  805. print '<td class="right">'.price($obj->total_ht)."</td>\n";
  806. if (!$i) {
  807. $totalarray['nbfield']++;
  808. }
  809. if (!$i) {
  810. $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht';
  811. }
  812. $totalarray['val']['d.total_ht'] += $obj->total_ht;
  813. }
  814. // Amount VAT
  815. if (!empty($arrayfields['d.total_vat']['checked'])) {
  816. print '<td class="right">'.price($obj->total_tva)."</td>\n";
  817. if (!$i) {
  818. $totalarray['nbfield']++;
  819. }
  820. if (!$i) {
  821. $totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva';
  822. }
  823. $totalarray['val']['d.total_tva'] += $obj->total_tva;
  824. }
  825. // Amount TTC
  826. if (!empty($arrayfields['d.total_ttc']['checked'])) {
  827. print '<td class="right">'.price($obj->total_ttc)."</td>\n";
  828. if (!$i) {
  829. $totalarray['nbfield']++;
  830. }
  831. if (!$i) {
  832. $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc';
  833. }
  834. $totalarray['val']['d.total_ttc'] += $obj->total_ttc;
  835. }
  836. // Extra fields
  837. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  838. // Fields from hook
  839. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  840. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  841. print $hookmanager->resPrint;
  842. // Date creation
  843. if (!empty($arrayfields['d.date_create']['checked'])) {
  844. print '<td class="nowrap center">';
  845. print dol_print_date($db->jdate($obj->date_create), 'dayhour');
  846. print '</td>';
  847. if (!$i) {
  848. $totalarray['nbfield']++;
  849. }
  850. }
  851. // Date modification
  852. if (!empty($arrayfields['d.tms']['checked'])) {
  853. print '<td class="nowrap center">';
  854. print dol_print_date($db->jdate($obj->date_modif), 'dayhour');
  855. print '</td>';
  856. if (!$i) {
  857. $totalarray['nbfield']++;
  858. }
  859. }
  860. // Status
  861. if (!empty($arrayfields['d.fk_statut']['checked'])) {
  862. print '<td class="nowrap center">'.$expensereportstatic->getLibStatut(5).'</td>';
  863. if (!$i) {
  864. $totalarray['nbfield']++;
  865. }
  866. }
  867. // Action column
  868. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  869. print '<td class="nowrap center">';
  870. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  871. $selected = 0;
  872. if (in_array($obj->rowid, $arrayofselected)) {
  873. $selected = 1;
  874. }
  875. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  876. }
  877. print '</td>';
  878. if (!$i) {
  879. $totalarray['nbfield']++;
  880. }
  881. }
  882. print "</tr>\n";
  883. }
  884. $total_total_ht = $total_total_ht + $obj->total_ht;
  885. $total_total_tva = $total_total_tva + $obj->total_tva;
  886. $total_total_ttc = $total_total_ttc + $obj->total_ttc;
  887. $i++;
  888. }
  889. } else {
  890. $colspan = 1;
  891. foreach ($arrayfields as $key => $val) {
  892. if (!empty($val['checked'])) {
  893. $colspan++;
  894. }
  895. }
  896. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  897. }
  898. // Show total line
  899. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  900. $db->free($resql);
  901. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  902. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  903. print $hookmanager->resPrint;
  904. print '</table>'."\n";
  905. print '</div>';
  906. print '</form>'."\n";
  907. if (empty($id)) {
  908. $hidegeneratedfilelistifempty = 1;
  909. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  910. $hidegeneratedfilelistifempty = 0;
  911. }
  912. // Show list of available documents
  913. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  914. $urlsource .= str_replace('&amp;', '&', $param);
  915. $filedir = $diroutputmassaction;
  916. $genallowed = $user->rights->expensereport->lire;
  917. $delallowed = $user->rights->expensereport->creer;
  918. print $formfile->showdocuments('massfilesarea_expensereport', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  919. }
  920. } else {
  921. dol_print_error($db);
  922. }
  923. // End of page
  924. llxFooter();
  925. $db->close();