list.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  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 (!empty($user->rights->expensereport->readall)) {
  65. $canread = 1;
  66. }
  67. if (!empty($user->rights->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'; $massaction = '';
  163. }
  164. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  165. $massaction = '';
  166. }
  167. $parameters = array('socid'=>$socid);
  168. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  169. if ($reshook < 0) {
  170. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  171. }
  172. if (empty($reshook)) {
  173. // Selection of new fields
  174. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  175. // Purge search criteria
  176. 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
  177. $search_ref = "";
  178. $search_user = "";
  179. $search_amount_ht = "";
  180. $search_amount_vat = "";
  181. $search_amount_ttc = "";
  182. $search_status = "";
  183. $search_date_startday = '';
  184. $search_date_startmonth = '';
  185. $search_date_startyear = '';
  186. $search_date_startendday = '';
  187. $search_date_startendmonth = '';
  188. $search_date_startendyear = '';
  189. $search_date_start = '';
  190. $search_date_startend = '';
  191. $search_date_endday = '';
  192. $search_date_endmonth = '';
  193. $search_date_endyear = '';
  194. $search_date_endendday = '';
  195. $search_date_endendmonth = '';
  196. $search_date_endendyear = '';
  197. $search_date_end = '';
  198. $search_date_endend = '';
  199. $toselect = array();
  200. $search_array_options = array();
  201. }
  202. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  203. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  204. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  205. }
  206. // Mass actions
  207. $objectclass = 'ExpenseReport';
  208. $objectlabel = 'ExpenseReport';
  209. $permissiontoread = $user->rights->expensereport->lire;
  210. $permissiontodelete = $user->rights->expensereport->supprimer;
  211. $uploaddir = $conf->expensereport->dir_output;
  212. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  213. }
  214. /*
  215. * View
  216. */
  217. $form = new Form($db);
  218. $formother = new FormOther($db);
  219. $formfile = new FormFile($db);
  220. $formexpensereport = new FormExpenseReport($db);
  221. $fuser = new User($db);
  222. $title = $langs->trans("TripsAndExpenses");
  223. llxHeader('', $title);
  224. $max_year = 5;
  225. $min_year = 10;
  226. // Get current user id
  227. $user_id = $user->id;
  228. if ($id > 0) {
  229. // Charge utilisateur edite
  230. $fuser->fetch($id, '', '', 1);
  231. $fuser->getrights();
  232. $user_id = $fuser->id;
  233. $search_user = $user_id;
  234. }
  235. $sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,";
  236. $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,";
  237. $sql .= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut, u.photo";
  238. // Add fields from extrafields
  239. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  240. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  241. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  242. }
  243. }
  244. // Add fields from hooks
  245. $parameters = array();
  246. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  247. $sql .= $hookmanager->resPrint;
  248. $sqlfields = $sql; // $sql fields to remove for count total
  249. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d";
  250. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  251. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
  252. }
  253. $sql .= ", ".MAIN_DB_PREFIX."user as u";
  254. $sql .= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")";
  255. // Search all
  256. if (!empty($sall)) {
  257. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  258. }
  259. // Ref
  260. if (!empty($search_ref)) {
  261. $sql .= natural_search('d.ref', $search_ref);
  262. }
  263. // Date Start
  264. if ($search_date_start) {
  265. $sql .= " AND d.date_debut >= '".$db->idate($search_date_start)."'";
  266. }
  267. if ($search_date_startend) {
  268. $sql .= " AND d.date_debut <= '".$db->idate($search_date_startend)."'";
  269. }
  270. // Date End
  271. if ($search_date_end) {
  272. $sql .= " AND d.date_fin >= '".$db->idate($search_date_end)."'";
  273. }
  274. if ($search_date_endend) {
  275. $sql .= " AND d.date_fin <= '".$db->idate($search_date_endend)."'";
  276. }
  277. if ($search_amount_ht != '') {
  278. $sql .= natural_search('d.total_ht', $search_amount_ht, 1);
  279. }
  280. if ($search_amount_ttc != '') {
  281. $sql .= natural_search('d.total_ttc', $search_amount_ttc, 1);
  282. }
  283. // User
  284. if ($search_user != '' && $search_user >= 0) {
  285. $sql .= " AND u.rowid = '".$db->escape($search_user)."'";
  286. }
  287. // Status
  288. if ($search_status != '' && $search_status >= 0) {
  289. $sql .= " AND d.fk_statut IN (".$db->sanitize($search_status).")";
  290. }
  291. // RESTRICT RIGHTS
  292. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
  293. && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
  294. $sql .= " AND d.fk_user_author IN (".$db->sanitize(join(',', $childids)).")\n";
  295. }
  296. // Add where from extra fields
  297. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  298. // Add where from hooks
  299. $parameters = array();
  300. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  301. $sql .= $hookmanager->resPrint;
  302. // Count total nb of records
  303. $nbtotalofrecords = '';
  304. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  305. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  306. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  307. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  308. $resql = $db->query($sqlforcount);
  309. if ($resql) {
  310. $objforcount = $db->fetch_object($resql);
  311. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  312. } else {
  313. dol_print_error($db);
  314. }
  315. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  316. $page = 0;
  317. $offset = 0;
  318. }
  319. $db->free($resql);
  320. }
  321. // Complete request and execute it with limit
  322. $sql .= $db->order($sortfield, $sortorder);
  323. if ($limit) {
  324. $sql .= $db->plimit($limit + 1, $offset);
  325. }
  326. //print $sql;
  327. $resql = $db->query($sql);
  328. if ($resql) {
  329. $num = $db->num_rows($resql);
  330. $arrayofselected = is_array($toselect) ? $toselect : array();
  331. $param = '';
  332. if (!empty($mode)) {
  333. $param .= '&mode='.urlencode($mode);
  334. }
  335. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  336. $param .= '&contextpage='.urlencode($contextpage);
  337. }
  338. if ($limit > 0 && $limit != $conf->liste_limit) {
  339. $param .= '&limit='.((int) $limit);
  340. }
  341. if ($sall) {
  342. $param .= "&sall=".urlencode($sall);
  343. }
  344. if ($search_ref) {
  345. $param .= "&search_ref=".urlencode($search_ref);
  346. }
  347. // Start date
  348. if ($search_date_startday) {
  349. $param .= '&search_date_startday='.urlencode($search_date_startday);
  350. }
  351. if ($search_date_startmonth) {
  352. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  353. }
  354. if ($search_date_startyear) {
  355. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  356. }
  357. if ($search_date_startendday) {
  358. $param .= '&search_date_startendday='.urlencode($search_date_startendday);
  359. }
  360. if ($search_date_startendmonth) {
  361. $param .= '&search_date_startendmonth='.urlencode($search_date_startendmonth);
  362. }
  363. if ($search_date_startendyear) {
  364. $param .= '&search_date_startendyear='.urlencode($search_date_startendyear);
  365. }
  366. // End date
  367. if ($search_date_endday) {
  368. $param .= '&search_date_endday='.urlencode($search_date_endday);
  369. }
  370. if ($search_date_endmonth) {
  371. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  372. }
  373. if ($search_date_endyear) {
  374. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  375. }
  376. if ($search_date_endendday) {
  377. $param .= '&search_date_endendday='.urlencode($search_date_endendday);
  378. }
  379. if ($search_date_endendmonth) {
  380. $param .= '&search_date_endendmonth='.urlencode($search_date_endendmonth);
  381. }
  382. if ($search_date_endendyear) {
  383. $param .= '&search_date_endendyear='.urlencode($search_date_endendyear);
  384. }
  385. if ($search_user) {
  386. $param .= "&search_user=".urlencode($search_user);
  387. }
  388. if ($search_amount_ht) {
  389. $param .= "&search_amount_ht=".urlencode($search_amount_ht);
  390. }
  391. if ($search_amount_ttc) {
  392. $param .= "&search_amount_ttc=".urlencode($search_amount_ttc);
  393. }
  394. if ($search_status >= 0) {
  395. $param .= "&search_status=".urlencode($search_status);
  396. }
  397. if ($optioncss != '') {
  398. $param .= '&optioncss='.urlencode($optioncss);
  399. }
  400. // Add $param from extra fields
  401. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  402. // List of mass actions available
  403. $arrayofmassactions = array(
  404. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  405. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  406. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  407. );
  408. if ($user->rights->expensereport->supprimer) {
  409. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  410. }
  411. if (in_array($massaction, array('presend', 'predelete'))) {
  412. $arrayofmassactions = array();
  413. }
  414. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  415. // Lines of title fields
  416. print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  417. if ($optioncss != '') {
  418. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  419. }
  420. print '<input type="hidden" name="token" value="'.newToken().'">';
  421. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  422. print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">';
  423. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  424. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  425. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  426. print '<input type="hidden" name="mode" value="'.$mode.'">';
  427. if ($id > 0) {
  428. print '<input type="hidden" name="id" value="'.$id.'">';
  429. }
  430. if ($id > 0) { // For user tab
  431. $title = $langs->trans("User");
  432. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  433. $head = user_prepare_head($fuser);
  434. print dol_get_fiche_head($head, 'expensereport', $title, -1, 'user');
  435. dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
  436. print dol_get_fiche_end();
  437. if ($action != 'edit') {
  438. print '<div class="tabsAction">';
  439. $childids = $user->getAllChildIds(1);
  440. $canedit = ((in_array($user_id, $childids) && $user->rights->expensereport->creer)
  441. || ($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->expensereport->writeall_advance));
  442. // Buttons for actions
  443. if ($canedit) {
  444. print '<a href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create&fk_user_author='.$fuser->id.'" class="butAction">'.$langs->trans("AddTrip").'</a>';
  445. } else {
  446. print '<a href="#" class="butActionRefused" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddTrip").'</a>';
  447. }
  448. print '</div>';
  449. } else {
  450. print $form->buttonsSaveCancel("Save", '');
  451. }
  452. } else {
  453. $title = $langs->trans("ListTripsAndExpenses");
  454. $url = DOL_URL_ROOT.'/expensereport/card.php?action=create';
  455. if (!empty($socid)) {
  456. $url .= '&socid='.$socid;
  457. }
  458. $newcardbutton = '';
  459. $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'));
  460. $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'));
  461. $newcardbutton .= dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', $url, '', $user->rights->expensereport->creer);
  462. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'trip', 0, $newcardbutton, '', $limit, 0, 0, 1);
  463. }
  464. $topicmail = "SendExpenseReport";
  465. $modelmail = "expensereport";
  466. $objecttmp = new ExpenseReport($db);
  467. $trackid = 'exp'.$object->id;
  468. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  469. if ($sall) {
  470. foreach ($fieldstosearchall as $key => $val) {
  471. $fieldstosearchall[$key] = $langs->trans($val);
  472. }
  473. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  474. }
  475. $moreforfilter = '';
  476. $parameters = array();
  477. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  478. if (empty($reshook)) {
  479. $moreforfilter .= $hookmanager->resPrint;
  480. } else {
  481. $moreforfilter = $hookmanager->resPrint;
  482. }
  483. if (!empty($moreforfilter)) {
  484. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  485. print $moreforfilter;
  486. print '</div>';
  487. }
  488. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  489. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  490. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  491. print '<div class="div-table-responsive">';
  492. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  493. // Filters
  494. print '<tr class="liste_titre_filter">';
  495. // Action column
  496. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  497. print '<td class="liste_titre maxwidthsearch">';
  498. $searchpicto = $form->showFilterButtons('left');
  499. print $searchpicto;
  500. print '</td>';
  501. }
  502. if (!empty($arrayfields['d.ref']['checked'])) {
  503. print '<td class="liste_titre" align="left">';
  504. print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
  505. print '</td>';
  506. }
  507. // User
  508. if (!empty($arrayfields['user']['checked'])) {
  509. if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) {
  510. print '<td class="liste_titre maxwidthonspartphone" align="left">';
  511. print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  512. print '</td>';
  513. } else {
  514. print '<td class="liste_titre">&nbsp;</td>';
  515. }
  516. }
  517. // Date start
  518. if (!empty($arrayfields['d.date_debut']['checked'])) {
  519. print '<td class="liste_titre" align="center">';
  520. print '<div class="nowrap">';
  521. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  522. print '</div>';
  523. print '<div class="nowrap">';
  524. print $form->selectDate($search_date_startend ? $search_date_startend : -1, 'search_date_startend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  525. print '</div>';
  526. print '</td>';
  527. }
  528. // Date end
  529. if (!empty($arrayfields['d.date_fin']['checked'])) {
  530. print '<td class="liste_titre" align="center">';
  531. print '<div class="nowrap">';
  532. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  533. print '</div>';
  534. print '<div class="nowrap">';
  535. print $form->selectDate($search_date_endend ? $search_date_endend : -1, 'search_date_endend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  536. print '</div>';
  537. print '</td>';
  538. }
  539. // Date valid
  540. if (!empty($arrayfields['d.date_valid']['checked'])) {
  541. print '<td class="liste_titre" align="center">';
  542. //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  543. //print $formother->selectyear($year_end,'year_end',1, $min_year, $max_year);
  544. print '</td>';
  545. }
  546. // Date approve
  547. if (!empty($arrayfields['d.date_approve']['checked'])) {
  548. print '<td class="liste_titre" align="center">';
  549. //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  550. //print $formother->selectyear($year_end,'year_end',1, $min_year, $max_year);
  551. print '</td>';
  552. }
  553. // Amount with no tax
  554. if (!empty($arrayfields['d.total_ht']['checked'])) {
  555. print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ht" value="'.$search_amount_ht.'"></td>';
  556. }
  557. if (!empty($arrayfields['d.total_vat']['checked'])) {
  558. print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_vat" value="'.$search_amount_vat.'"></td>';
  559. }
  560. // Amount with all taxes
  561. if (!empty($arrayfields['d.total_ttc']['checked'])) {
  562. print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>';
  563. }
  564. // Extra fields
  565. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  566. // Fields from hook
  567. $parameters = array('arrayfields'=>$arrayfields);
  568. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  569. print $hookmanager->resPrint;
  570. // Date creation
  571. if (!empty($arrayfields['d.date_create']['checked'])) {
  572. print '<td class="liste_titre">';
  573. print '</td>';
  574. }
  575. // Date modification
  576. if (!empty($arrayfields['d.tms']['checked'])) {
  577. print '<td class="liste_titre">';
  578. print '</td>';
  579. }
  580. // Status
  581. if (!empty($arrayfields['d.fk_statut']['checked'])) {
  582. print '<td class="liste_titre right">';
  583. $formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1);
  584. print '</td>';
  585. }
  586. // Action column
  587. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  588. print '<td class="liste_titre maxwidthsearch">';
  589. $searchpicto = $form->showFilterButtons();
  590. print $searchpicto;
  591. print '</td>';
  592. }
  593. print "</tr>\n";
  594. print '<tr class="liste_titre">';
  595. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  596. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  597. }
  598. if (!empty($arrayfields['d.ref']['checked'])) {
  599. print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], "d.ref", "", $param, '', $sortfield, $sortorder);
  600. }
  601. if (!empty($arrayfields['user']['checked'])) {
  602. print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder);
  603. }
  604. if (!empty($arrayfields['d.date_debut']['checked'])) {
  605. print_liste_field_titre($arrayfields['d.date_debut']['label'], $_SERVER["PHP_SELF"], "d.date_debut", "", $param, 'align="center"', $sortfield, $sortorder);
  606. }
  607. if (!empty($arrayfields['d.date_fin']['checked'])) {
  608. print_liste_field_titre($arrayfields['d.date_fin']['label'], $_SERVER["PHP_SELF"], "d.date_fin", "", $param, 'align="center"', $sortfield, $sortorder);
  609. }
  610. if (!empty($arrayfields['d.date_valid']['checked'])) {
  611. print_liste_field_titre($arrayfields['d.date_valid']['label'], $_SERVER["PHP_SELF"], "d.date_valid", "", $param, 'align="center"', $sortfield, $sortorder);
  612. }
  613. if (!empty($arrayfields['d.date_approve']['checked'])) {
  614. print_liste_field_titre($arrayfields['d.date_approve']['label'], $_SERVER["PHP_SELF"], "d.date_approve", "", $param, 'align="center"', $sortfield, $sortorder);
  615. }
  616. if (!empty($arrayfields['d.total_ht']['checked'])) {
  617. print_liste_field_titre($arrayfields['d.total_ht']['label'], $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
  618. }
  619. if (!empty($arrayfields['d.total_vat']['checked'])) {
  620. print_liste_field_titre($arrayfields['d.total_vat']['label'], $_SERVER["PHP_SELF"], "d.total_tva", "", $param, 'align="right"', $sortfield, $sortorder);
  621. }
  622. if (!empty($arrayfields['d.total_ttc']['checked'])) {
  623. print_liste_field_titre($arrayfields['d.total_ttc']['label'], $_SERVER["PHP_SELF"], "d.total_ttc", "", $param, 'align="right"', $sortfield, $sortorder);
  624. }
  625. // Extra fields
  626. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  627. // Hook fields
  628. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  629. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  630. print $hookmanager->resPrint;
  631. if (!empty($arrayfields['d.date_create']['checked'])) {
  632. print_liste_field_titre($arrayfields['d.date_create']['label'], $_SERVER["PHP_SELF"], "d.date_create", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  633. }
  634. if (!empty($arrayfields['d.tms']['checked'])) {
  635. print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  636. }
  637. if (!empty($arrayfields['d.fk_statut']['checked'])) {
  638. print_liste_field_titre($arrayfields['d.fk_statut']['label'], $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder);
  639. }
  640. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  641. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  642. }
  643. print "</tr>\n";
  644. $total_total_ht = 0;
  645. $total_total_ttc = 0;
  646. $total_total_tva = 0;
  647. $expensereportstatic = new ExpenseReport($db);
  648. $usertmp = new User($db);
  649. if ($num > 0) {
  650. $i = 0;
  651. $totalarray = array();
  652. $totalarray['nbfield'] = 0;
  653. $totalarray['val'] = array();
  654. $totalarray['val']['d.total_ht'] = 0;
  655. $totalarray['val']['d.total_tva'] = 0;
  656. $totalarray['val']['d.total_ttc'] = 0;
  657. $totalarray['totalizable'] = array();
  658. $imaxinloop = ($limit ? min($num, $limit) : $num);
  659. while ($i < min($num, $limit)) {
  660. $obj = $db->fetch_object($resql);
  661. $expensereportstatic->id = $obj->rowid;
  662. $expensereportstatic->ref = $obj->ref;
  663. $expensereportstatic->status = $obj->status;
  664. $expensereportstatic->date_debut = $db->jdate($obj->date_debut);
  665. $expensereportstatic->date_fin = $db->jdate($obj->date_fin);
  666. $expensereportstatic->date_create = $db->jdate($obj->date_create);
  667. $expensereportstatic->date_modif = $db->jdate($obj->date_modif);
  668. $expensereportstatic->date_valid = $db->jdate($obj->date_valid);
  669. $expensereportstatic->date_approve = $db->jdate($obj->date_approve);
  670. $expensereportstatic->note_private = $obj->note_private;
  671. $expensereportstatic->note_public = $obj->note_public;
  672. if ($mode == 'kanban') {
  673. if ($i == 0) {
  674. print '<tr><td colspan="12">';
  675. print '<div class="box-flex-container kanban">';
  676. }
  677. // TODO Use a cache on user
  678. $usertmp->fetch($obj->id_user);
  679. // Output Kanban
  680. if ($massactionbutton || $massaction) {
  681. $selected = 0;
  682. print $expensereportstatic->getKanbanView('', array('userauthor' => $usertmp->getNomUrl(1), 'selected' => in_array($expensereportstatic->id, $arrayofselected)));
  683. }
  684. if ($i == ($imaxinloop - 1)) {
  685. print '</div>';
  686. print '</td></tr>';
  687. }
  688. } else {
  689. print '<tr class="oddeven">';
  690. // Action column
  691. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  692. print '<td class="nowrap center">';
  693. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  694. $selected = 0;
  695. if (in_array($obj->rowid, $arrayofselected)) {
  696. $selected = 1;
  697. }
  698. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  699. }
  700. print '</td>';
  701. }
  702. // Ref
  703. if (!empty($arrayfields['d.ref']['checked'])) {
  704. print '<td>';
  705. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  706. print '<td class="nobordernopadding nowrap">';
  707. print $expensereportstatic->getNomUrl(1);
  708. print '</td>';
  709. // Warning late icon and note
  710. print '<td class="nobordernopadding nowrap">';
  711. if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) {
  712. print img_warning($langs->trans("Late"));
  713. }
  714. if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) {
  715. print img_warning($langs->trans("Late"));
  716. }
  717. if (!empty($obj->note_private) || !empty($obj->note_public)) {
  718. print ' <span class="note">';
  719. print '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
  720. print '</span>';
  721. }
  722. print '</td>';
  723. print '<td width="16" class="nobordernopadding hideonsmartphone right">';
  724. $filename = dol_sanitizeFileName($obj->ref);
  725. $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  726. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  727. print $formfile->getDocumentsLink($expensereportstatic->element, $filename, $filedir);
  728. print '</td>';
  729. print '</tr></table>';
  730. print '</td>';
  731. if (!$i) {
  732. $totalarray['nbfield']++;
  733. }
  734. }
  735. // User
  736. if (!empty($arrayfields['user']['checked'])) {
  737. print '<td class="left">';
  738. $usertmp->id = $obj->id_user;
  739. $usertmp->lastname = $obj->lastname;
  740. $usertmp->firstname = $obj->firstname;
  741. $usertmp->login = $obj->login;
  742. $usertmp->statut = $obj->statut;
  743. $usertmp->photo = $obj->photo;
  744. $usertmp->email = $obj->email;
  745. print $usertmp->getNomUrl(-1);
  746. print '</td>';
  747. if (!$i) {
  748. $totalarray['nbfield']++;
  749. }
  750. }
  751. // Start date
  752. if (!empty($arrayfields['d.date_debut']['checked'])) {
  753. print '<td class="center">'.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').'</td>';
  754. if (!$i) {
  755. $totalarray['nbfield']++;
  756. }
  757. }
  758. // End date
  759. if (!empty($arrayfields['d.date_fin']['checked'])) {
  760. print '<td class="center">'.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').'</td>';
  761. if (!$i) {
  762. $totalarray['nbfield']++;
  763. }
  764. }
  765. // Date validation
  766. if (!empty($arrayfields['d.date_valid']['checked'])) {
  767. print '<td class="center">'.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').'</td>';
  768. if (!$i) {
  769. $totalarray['nbfield']++;
  770. }
  771. }
  772. // Date approval
  773. if (!empty($arrayfields['d.date_approve']['checked'])) {
  774. print '<td class="center">'.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').'</td>';
  775. if (!$i) {
  776. $totalarray['nbfield']++;
  777. }
  778. }
  779. // Amount HT
  780. if (!empty($arrayfields['d.total_ht']['checked'])) {
  781. print '<td class="right">'.price($obj->total_ht)."</td>\n";
  782. if (!$i) {
  783. $totalarray['nbfield']++;
  784. }
  785. if (!$i) {
  786. $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht';
  787. }
  788. $totalarray['val']['d.total_ht'] += $obj->total_ht;
  789. }
  790. // Amount VAT
  791. if (!empty($arrayfields['d.total_vat']['checked'])) {
  792. print '<td class="right">'.price($obj->total_tva)."</td>\n";
  793. if (!$i) {
  794. $totalarray['nbfield']++;
  795. }
  796. if (!$i) {
  797. $totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva';
  798. }
  799. $totalarray['val']['d.total_tva'] += $obj->total_tva;
  800. }
  801. // Amount TTC
  802. if (!empty($arrayfields['d.total_ttc']['checked'])) {
  803. print '<td class="right">'.price($obj->total_ttc)."</td>\n";
  804. if (!$i) {
  805. $totalarray['nbfield']++;
  806. }
  807. if (!$i) {
  808. $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc';
  809. }
  810. $totalarray['val']['d.total_ttc'] += $obj->total_ttc;
  811. }
  812. // Extra fields
  813. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  814. // Fields from hook
  815. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  816. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  817. print $hookmanager->resPrint;
  818. // Date creation
  819. if (!empty($arrayfields['d.date_create']['checked'])) {
  820. print '<td class="nowrap center">';
  821. print dol_print_date($db->jdate($obj->date_create), 'dayhour');
  822. print '</td>';
  823. if (!$i) {
  824. $totalarray['nbfield']++;
  825. }
  826. }
  827. // Date modification
  828. if (!empty($arrayfields['d.tms']['checked'])) {
  829. print '<td class="nowrap center">';
  830. print dol_print_date($db->jdate($obj->date_modif), 'dayhour');
  831. print '</td>';
  832. if (!$i) {
  833. $totalarray['nbfield']++;
  834. }
  835. }
  836. // Status
  837. if (!empty($arrayfields['d.fk_statut']['checked'])) {
  838. print '<td class="nowrap right">'.$expensereportstatic->getLibStatut(5).'</td>';
  839. if (!$i) {
  840. $totalarray['nbfield']++;
  841. }
  842. }
  843. // Action column
  844. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  845. print '<td class="nowrap center">';
  846. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  847. $selected = 0;
  848. if (in_array($obj->rowid, $arrayofselected)) {
  849. $selected = 1;
  850. }
  851. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  852. }
  853. print '</td>';
  854. }
  855. if (!$i) {
  856. $totalarray['nbfield']++;
  857. }
  858. print "</tr>\n";
  859. }
  860. $total_total_ht = $total_total_ht + $obj->total_ht;
  861. $total_total_tva = $total_total_tva + $obj->total_tva;
  862. $total_total_ttc = $total_total_ttc + $obj->total_ttc;
  863. $i++;
  864. }
  865. } else {
  866. $colspan = 1;
  867. foreach ($arrayfields as $key => $val) {
  868. if (!empty($val['checked'])) {
  869. $colspan++;
  870. }
  871. }
  872. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  873. }
  874. // Show total line
  875. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  876. $db->free($resql);
  877. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  878. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  879. print $hookmanager->resPrint;
  880. print '</table>'."\n";
  881. print '</div>';
  882. print '</form>'."\n";
  883. if (empty($id)) {
  884. $hidegeneratedfilelistifempty = 1;
  885. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  886. $hidegeneratedfilelistifempty = 0;
  887. }
  888. // Show list of available documents
  889. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  890. $urlsource .= str_replace('&amp;', '&', $param);
  891. $filedir = $diroutputmassaction;
  892. $genallowed = $user->rights->expensereport->lire;
  893. $delallowed = $user->rights->expensereport->creer;
  894. print $formfile->showdocuments('massfilesarea_expensereport', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  895. }
  896. } else {
  897. dol_print_error($db);
  898. }
  899. // End of page
  900. llxFooter();
  901. $db->close();