list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/expensereport/list.php
  23. * \ingroup expensereport
  24. * \brief list of expense reports
  25. */
  26. require "../main.inc.php";
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. $langs->load("companies");
  33. $langs->load("users");
  34. $langs->load("trips");
  35. $action=GETPOST('action','alpha');
  36. $massaction=GETPOST('massaction','alpha');
  37. $show_files=GETPOST('show_files','int');
  38. $confirm=GETPOST('confirm','alpha');
  39. $toselect = GETPOST('toselect', 'array');
  40. // Security check
  41. $socid = $_GET["socid"]?$_GET["socid"]:'';
  42. if ($user->societe_id) $socid=$user->societe_id;
  43. $result = restrictedArea($user, 'expensereport','','');
  44. $diroutputmassaction=$conf->expensereport->dir_output . '/temp/massgeneration/'.$user->id;
  45. // Load variable for pagination
  46. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  47. $sortfield = GETPOST('sortfield','alpha');
  48. $sortorder = GETPOST('sortorder','alpha');
  49. $page = GETPOST('page','int');
  50. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) $sortorder="DESC";
  55. if (!$sortfield) $sortfield="d.date_debut";
  56. $sall = GETPOST('sall', 'alphanohtml');
  57. $search_ref = GETPOST('search_ref');
  58. $search_user = GETPOST('search_user','int');
  59. $search_amount_ht = GETPOST('search_amount_ht','alpha');
  60. $search_amount_vat = GETPOST('search_amount_vat','alpha');
  61. $search_amount_ttc = GETPOST('search_amount_ttc','alpha');
  62. $search_status = (GETPOST('search_status','alpha')!=''?GETPOST('search_status','alpha'):GETPOST('statut','alpha'));
  63. $month_start = GETPOST("month_start","int");
  64. $year_start = GETPOST("year_start","int");
  65. $month_end = GETPOST("month_end","int");
  66. $year_end = GETPOST("year_end","int");
  67. $optioncss = GETPOST('optioncss','alpha');
  68. if ($search_status == '') $search_status=-1;
  69. if ($search_user == '') $search_user=-1;
  70. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  71. $contextpage='expensereportlist';
  72. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  73. $hookmanager->initHooks(array('expensereportlist'));
  74. $extrafields = new ExtraFields($db);
  75. // fetch optionals attributes and labels
  76. $extralabels = $extrafields->fetch_name_optionals_label('expensereport');
  77. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  78. // List of fields to search into when doing a "search in all"
  79. $fieldstosearchall = array(
  80. 'd.ref'=>'Ref',
  81. 'd.note_public'=>"NotePublic",
  82. 'u.lastname'=>'Lastname',
  83. 'u.firstname'=>"Firstname",
  84. 'u.login'=>"Login",
  85. );
  86. if (empty($user->socid)) $fieldstosearchall["d.note_private"]="NotePrivate";
  87. $arrayfields=array(
  88. 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  89. 'user'=>array('label'=>$langs->trans("User"), 'checked'=>1),
  90. 'd.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1),
  91. 'd.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1),
  92. 'd.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1),
  93. 'd.date_approve'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1),
  94. 'd.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  95. 'd.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
  96. 'd.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
  97. 'd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  98. 'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  99. 'd.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  100. );
  101. // Extra fields
  102. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  103. {
  104. foreach($extrafields->attribute_label as $key => $val)
  105. {
  106. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  107. }
  108. }
  109. /*
  110. * Actions
  111. */
  112. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  113. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  114. $parameters=array('socid'=>$socid);
  115. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  116. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  117. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  118. // Purge search criteria
  119. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test must be present to be compatible with all browsers
  120. {
  121. $search_ref="";
  122. $search_user="";
  123. $search_amount_ht="";
  124. $search_amount_vat="";
  125. $search_amount_ttc="";
  126. $search_status="";
  127. $month_start="";
  128. $year_start="";
  129. $month_end="";
  130. $year_end="";
  131. $toselect='';
  132. $search_array_options=array();
  133. }
  134. if (empty($reshook))
  135. {
  136. $objectclass='ExpenseReport';
  137. $objectlabel='ExpenseReport';
  138. $permtoread = $user->rights->expensereport->lire;
  139. $permtodelete = $user->rights->expensereport->supprimer;
  140. $uploaddir = $conf->expensereport->dir_output;
  141. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  142. }
  143. /*
  144. * View
  145. */
  146. $form = new Form($db);
  147. $formother = new FormOther($db);
  148. $formfile = new FormFile($db);
  149. llxHeader('', $langs->trans("ListOfTrips"));
  150. $max_year = 5;
  151. $min_year = 5;
  152. $sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,";
  153. $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,";
  154. $sql.= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.statut, u.photo";
  155. // Add fields from extrafields
  156. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  157. // Add fields from hooks
  158. $parameters=array();
  159. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  160. $sql.=$hookmanager->resPrint;
  161. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
  162. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_extrafields as ef on (d.rowid = ef.fk_object)";
  163. $sql.= ", ".MAIN_DB_PREFIX."user as u";
  164. $sql.= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")";
  165. // Search all
  166. if (!empty($sall)) $sql.= natural_search(array_keys($fieldstosearchall), $sall);
  167. // Ref
  168. if (!empty($search_ref)) $sql.= natural_search('d.ref', $search_ref);
  169. // Date Start
  170. if ($month_start > 0)
  171. {
  172. if ($year_start > 0 && empty($day))
  173. $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,$month_start,false))."' AND '".$db->idate(dol_get_last_day($year_start,$month_start,false))."'";
  174. else if ($year_start > 0 && ! empty($day))
  175. $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_start, $day, $year_start))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_start, $day, $year_start))."'";
  176. else
  177. $sql.= " AND date_format(d.date_debut, '%m') = '".$month_start."'";
  178. }
  179. else if ($year_start > 0)
  180. {
  181. $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,1,false))."' AND '".$db->idate(dol_get_last_day($year_start,12,false))."'";
  182. }
  183. // Date Start
  184. if ($month_end > 0)
  185. {
  186. if ($year_end > 0 && empty($day))
  187. $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,$month_end,false))."' AND '".$db->idate(dol_get_last_day($year_end,$month_end,false))."'";
  188. else if ($year_end > 0 && ! empty($day))
  189. $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_end, $day, $year_end))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_end, $day, $year_end))."'";
  190. else
  191. $sql.= " AND date_format(d.date_fin, '%m') = '".$month_end."'";
  192. }
  193. else if ($year_end > 0)
  194. {
  195. $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,false))."' AND '".$db->idate(dol_get_last_day($year_end,12,false))."'";
  196. }
  197. // Amount
  198. if ($search_amount_ht != '') $sql.= natural_search('d.total_ht', $search_amount_ht, 1);
  199. if ($search_amount_ttc != '') $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1);
  200. // User
  201. if ($search_user != '' && $search_user >= 0) $sql.= " AND u.rowid = '".$db->escape($search_user)."'";
  202. // Status
  203. if ($search_status != '' && $search_status >= 0)
  204. {
  205. if (strstr($search_status, ',')) $sql.=" AND d.fk_statut IN (".$db->escape($search_status).")";
  206. else $sql.=" AND d.fk_statut = ".$search_status;
  207. }
  208. // RESTRICT RIGHTS
  209. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
  210. && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
  211. {
  212. $childids = $user->getAllChildIds();
  213. $childids[]=$user->id;
  214. $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
  215. }
  216. // Add where from extra fields
  217. foreach ($search_array_options as $key => $val)
  218. {
  219. $crit=$val;
  220. $tmpkey=preg_replace('/search_options_/','',$key);
  221. $typ=$extrafields->attribute_type[$tmpkey];
  222. $mode=0;
  223. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  224. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  225. {
  226. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  227. }
  228. }
  229. // Add where from hooks
  230. $parameters=array();
  231. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  232. $sql.=$hookmanager->resPrint;
  233. $sql.= $db->order($sortfield,$sortorder);
  234. $nbtotalofrecords = '';
  235. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  236. {
  237. $result = $db->query($sql);
  238. $nbtotalofrecords = $db->num_rows($result);
  239. }
  240. $sql.= $db->plimit($limit+1, $offset);
  241. //print $sql;
  242. $resql=$db->query($sql);
  243. if ($resql)
  244. {
  245. $num = $db->num_rows($resql);
  246. $arrayofselected=is_array($toselect)?$toselect:array();
  247. $param="";
  248. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  249. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  250. if ($sall) $param.="&sall=".$sall;
  251. if ($search_ref) $param.="&search_ref=".$search_ref;
  252. if ($search_user) $param.="&search_user=".$search_user;
  253. if ($search_amount_ht) $param.="&search_amount_ht=".$search_amount_ht;
  254. if ($search_amount_ttc) $param.="&search_amount_ttc=".$search_amount_ttc;
  255. if ($search_status >= 0) $param.="&search_status=".$search_status;
  256. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  257. // Add $param from extra fields
  258. foreach ($search_array_options as $key => $val)
  259. {
  260. $crit=$val;
  261. $tmpkey=preg_replace('/search_options_/','',$key);
  262. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  263. }
  264. // List of mass actions available
  265. $arrayofmassactions = array(
  266. //'presend'=>$langs->trans("SendByMail"),
  267. 'builddoc'=>$langs->trans("PDFMerge"),
  268. );
  269. if ($user->rights->expensereport->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  270. if ($massaction == 'presend') $arrayofmassactions=array();
  271. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  272. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  273. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  274. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  275. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  276. print '<input type="hidden" name="action" value="list">';
  277. print '<input type="hidden" name="page" value="'.$page.'">';
  278. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  279. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  280. $title = $langs->trans("ListTripsAndExpenses");
  281. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_generic.png', 0, '', '', $limit);
  282. if ($sall)
  283. {
  284. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  285. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  286. }
  287. $moreforfilter='';
  288. $parameters=array();
  289. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  290. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  291. else $moreforfilter = $hookmanager->resPrint;
  292. if (! empty($moreforfilter))
  293. {
  294. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  295. print $moreforfilter;
  296. print '</div>';
  297. }
  298. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  299. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  300. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  301. print '<div class="div-table-responsive">';
  302. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  303. // Filters
  304. print '<tr class="liste_titre_filter">';
  305. if (! empty($arrayfields['d.ref']['checked']))
  306. {
  307. print '<td class="liste_titre" align="left">';
  308. print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
  309. print '</td>';
  310. }
  311. // User
  312. if (! empty($arrayfields['user']['checked']))
  313. {
  314. if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous)
  315. {
  316. print '<td class="liste_titre maxwidthonspartphone" align="left">';
  317. print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  318. print '</td>';
  319. } else {
  320. print '<td class="liste_titre">&nbsp;</td>';
  321. }
  322. }
  323. // Date start
  324. if (! empty($arrayfields['d.date_debut']['checked']))
  325. {
  326. print '<td class="liste_titre" align="center">';
  327. print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
  328. $formother->select_year($year_start,'year_start',1, $min_year, $max_year);
  329. print '</td>';
  330. }
  331. // Date end
  332. if (! empty($arrayfields['d.date_fin']['checked']))
  333. {
  334. print '<td class="liste_titre" align="center">';
  335. print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  336. $formother->select_year($year_end,'year_end',1, $min_year, $max_year);
  337. print '</td>';
  338. }
  339. // Date valid
  340. if (! empty($arrayfields['d.date_valid']['checked']))
  341. {
  342. print '<td class="liste_titre" align="center">';
  343. //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  344. //$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
  345. print '</td>';
  346. }
  347. // Date approve
  348. if (! empty($arrayfields['d.date_approve']['checked']))
  349. {
  350. print '<td class="liste_titre" align="center">';
  351. //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  352. //$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
  353. print '</td>';
  354. }
  355. // Amount with no tax
  356. if (! empty($arrayfields['d.total_ht']['checked']))
  357. {
  358. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_ht" value="'.$search_amount_ht.'"></td>';
  359. }
  360. if (! empty($arrayfields['d.total_vat']['checked']))
  361. {
  362. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_vat" value="'.$search_amount_vat.'"></td>';
  363. }
  364. // Amount with all taxes
  365. if (! empty($arrayfields['d.total_ttc']['checked']))
  366. {
  367. print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>';
  368. }
  369. // Extra fields
  370. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  371. {
  372. foreach($extrafields->attribute_label as $key => $val)
  373. {
  374. if (! empty($arrayfields["ef.".$key]['checked']))
  375. {
  376. $align=$extrafields->getAlignFlag($key);
  377. $typeofextrafield=$extrafields->attribute_type[$key];
  378. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  379. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  380. {
  381. $crit=$val;
  382. $tmpkey=preg_replace('/search_options_/','',$key);
  383. $searchclass='';
  384. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  385. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  386. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  387. }
  388. print '</td>';
  389. }
  390. }
  391. }
  392. // Fields from hook
  393. $parameters=array('arrayfields'=>$arrayfields);
  394. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  395. print $hookmanager->resPrint;
  396. // Date creation
  397. if (! empty($arrayfields['d.datec']['checked']))
  398. {
  399. print '<td class="liste_titre">';
  400. print '</td>';
  401. }
  402. // Date modification
  403. if (! empty($arrayfields['d.tms']['checked']))
  404. {
  405. print '<td class="liste_titre">';
  406. print '</td>';
  407. }
  408. // Status
  409. if (! empty($arrayfields['d.fk_statut']['checked']))
  410. {
  411. print '<td class="liste_titre" align="right">';
  412. select_expensereport_statut($search_status,'search_status',1,1);
  413. print '</td>';
  414. }
  415. // Action column
  416. print '<td class="liste_titre" align="middle">';
  417. $searchpicto=$form->showFilterButtons();
  418. print $searchpicto;
  419. print '</td>';
  420. print "</tr>\n";
  421. print '<tr class="liste_titre">';
  422. if (! empty($arrayfields['d.ref']['checked'])) print_liste_field_titre($arrayfields['d.ref']['label'],$_SERVER["PHP_SELF"],"d.ref","",$param,'',$sortfield,$sortorder);
  423. if (! empty($arrayfields['user']['checked'])) print_liste_field_titre($arrayfields['user']['label'],$_SERVER["PHP_SELF"],"u.lastname","",$param,'',$sortfield,$sortorder);
  424. if (! empty($arrayfields['d.date_debut']['checked'])) print_liste_field_titre($arrayfields['d.date_debut']['label'],$_SERVER["PHP_SELF"],"d.date_debut","",$param,'align="center"',$sortfield,$sortorder);
  425. if (! empty($arrayfields['d.date_fin']['checked'])) print_liste_field_titre($arrayfields['d.date_fin']['label'],$_SERVER["PHP_SELF"],"d.date_fin","",$param,'align="center"',$sortfield,$sortorder);
  426. if (! empty($arrayfields['d.date_valid']['checked'])) print_liste_field_titre($arrayfields['d.date_valid']['label'],$_SERVER["PHP_SELF"],"d.date_valid","",$param,'align="center"',$sortfield,$sortorder);
  427. if (! empty($arrayfields['d.date_approve']['checked'])) print_liste_field_titre($arrayfields['d.date_approve']['label'],$_SERVER["PHP_SELF"],"d.date_approve","",$param,'align="center"',$sortfield,$sortorder);
  428. if (! empty($arrayfields['d.total_ht']['checked'])) print_liste_field_titre($arrayfields['d.total_ht']['label'],$_SERVER["PHP_SELF"],"d.total_ht","",$param,'align="right"',$sortfield,$sortorder);
  429. if (! empty($arrayfields['d.total_vat']['checked'])) print_liste_field_titre($arrayfields['d.total_vat']['label'],$_SERVER["PHP_SELF"],"d.total_tva","",$param,'align="right"',$sortfield,$sortorder);
  430. if (! empty($arrayfields['d.total_ttc']['checked'])) print_liste_field_titre($arrayfields['d.total_ttc']['label'],$_SERVER["PHP_SELF"],"d.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
  431. // Extra fields
  432. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  433. {
  434. foreach($extrafields->attribute_label as $key => $val)
  435. {
  436. if (! empty($arrayfields["ef.".$key]['checked']))
  437. {
  438. $align=$extrafields->getAlignFlag($key);
  439. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  440. }
  441. }
  442. }
  443. // Hook fields
  444. $parameters=array('arrayfields'=>$arrayfields);
  445. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  446. print $hookmanager->resPrint;
  447. if (! empty($arrayfields['d.datec']['checked'])) print_liste_field_titre($arrayfields['d.datec']['label'],$_SERVER["PHP_SELF"],"d.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  448. if (! empty($arrayfields['d.tms']['checked'])) print_liste_field_titre($arrayfields['d.tms']['label'],$_SERVER["PHP_SELF"],"d.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  449. if (! empty($arrayfields['d.fk_statut']['checked'])) print_liste_field_titre($arrayfields['d.fk_statut']['label'],$_SERVER["PHP_SELF"],"d.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
  450. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  451. print "</tr>\n";
  452. $total_total_ht = 0;
  453. $total_total_ttc = 0;
  454. $total_total_tva = 0;
  455. $expensereportstatic=new ExpenseReport($db);
  456. $usertmp = new User($db);
  457. if ($num > 0)
  458. {
  459. $i=0;
  460. $var=true;
  461. $totalarray=array();
  462. while ($i < min($num,$limit))
  463. {
  464. $obj = $db->fetch_object($resql);
  465. $expensereportstatic->id=$obj->rowid;
  466. $expensereportstatic->ref=$obj->ref;
  467. $expensereportstatic->status=$obj->status;
  468. $expensereportstatic->date_debut=$db->jdate($obj->date_debut);
  469. $expensereportstatic->date_fin=$db->jdate($obj->date_fin);
  470. $expensereportstatic->date_create=$db->jdate($obj->date_create);
  471. $expensereportstatic->date_modif=$db->jdate($obj->date_modif);
  472. $expensereportstatic->date_valid=$db->jdate($obj->date_valid);
  473. $expensereportstatic->date_approve=$db->jdate($obj->date_approve);
  474. $expensereportstatic->note_private=$obj->note_private;
  475. $expensereportstatic->note_public=$obj->note_public;
  476. print '<tr class="oddeven">';
  477. // Ref
  478. if (! empty($arrayfields['d.ref']['checked'])) {
  479. print '<td>';
  480. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  481. print '<td class="nobordernopadding nowrap">';
  482. print $expensereportstatic->getNomUrl(1);
  483. print '</td>';
  484. // Warning late icon and note
  485. print '<td class="nobordernopadding nowrap">';
  486. if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) print img_warning($langs->trans("Late"));
  487. if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) print img_warning($langs->trans("Late"));
  488. if (!empty($obj->note_private) || !empty($obj->note_public))
  489. {
  490. print ' <span class="note">';
  491. print '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
  492. print '</span>';
  493. }
  494. print '</td>';
  495. print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
  496. $filename=dol_sanitizeFileName($obj->ref);
  497. $filedir=$conf->expensereport->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  498. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  499. print $formfile->getDocumentsLink($expensereportstatic->element, $filename, $filedir);
  500. print '</td>';
  501. print '</tr></table>';
  502. print '</td>';
  503. if (! $i) $totalarray['nbfield']++;
  504. }
  505. // User
  506. if (! empty($arrayfields['user']['checked'])) {
  507. print '<td align="left">';
  508. $usertmp->id=$obj->id_user;
  509. $usertmp->lastname=$obj->lastname;
  510. $usertmp->firstname=$obj->firstname;
  511. $usertmp->login=$obj->login;
  512. $usertmp->statut=$obj->statut;
  513. $usertmp->photo=$obj->photo;
  514. print $usertmp->getNomUrl(-1);
  515. print '</td>';
  516. if (! $i) $totalarray['nbfield']++;
  517. }
  518. // Start date
  519. if (! empty($arrayfields['d.date_debut']['checked'])) {
  520. print '<td align="center">'.($obj->date_debut > 0 ? dol_print_date($obj->date_debut, 'day') : '').'</td>';
  521. if (! $i) $totalarray['nbfield']++;
  522. }
  523. // End date
  524. if (! empty($arrayfields['d.date_fin']['checked'])) {
  525. print '<td align="center">'.($obj->date_fin > 0 ? dol_print_date($obj->date_fin, 'day') : '').'</td>';
  526. if (! $i) $totalarray['nbfield']++;
  527. }
  528. // Date validation
  529. if (! empty($arrayfields['d.date_valid']['checked'])) {
  530. print '<td align="center">'.($obj->date_valid > 0 ? dol_print_date($obj->date_valid, 'day') : '').'</td>';
  531. if (! $i) $totalarray['nbfield']++;
  532. }
  533. // Date approval
  534. if (! empty($arrayfields['d.date_approve']['checked'])) {
  535. print '<td align="center">'.($obj->date_approve > 0 ? dol_print_date($obj->date_approve, 'day') : '').'</td>';
  536. if (! $i) $totalarray['nbfield']++;
  537. }
  538. // Amount HT
  539. if (! empty($arrayfields['d.total_ht']['checked']))
  540. {
  541. print '<td align="right">'.price($obj->total_ht)."</td>\n";
  542. if (! $i) $totalarray['nbfield']++;
  543. if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
  544. $totalarray['totalht'] += $obj->total_ht;
  545. }
  546. // Amount VAT
  547. if (! empty($arrayfields['d.total_vat']['checked']))
  548. {
  549. print '<td align="right">'.price($obj->total_tva)."</td>\n";
  550. if (! $i) $totalarray['nbfield']++;
  551. if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
  552. $totalarray['totalvat'] += $obj->total_tva;
  553. }
  554. // Amount TTC
  555. if (! empty($arrayfields['d.total_ttc']['checked']))
  556. {
  557. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  558. if (! $i) $totalarray['nbfield']++;
  559. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  560. $totalarray['totalttc'] += $obj->total_ttc;
  561. }
  562. // Extra fields
  563. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  564. {
  565. foreach($extrafields->attribute_label as $key => $val)
  566. {
  567. if (! empty($arrayfields["ef.".$key]['checked']))
  568. {
  569. print '<td';
  570. $align=$extrafields->getAlignFlag($key);
  571. if ($align) print ' align="'.$align.'"';
  572. print '>';
  573. $tmpkey='options_'.$key;
  574. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  575. print '</td>';
  576. if (! $i) $totalarray['nbfield']++;
  577. }
  578. }
  579. }
  580. // Fields from hook
  581. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  582. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  583. print $hookmanager->resPrint;
  584. // Date creation
  585. if (! empty($arrayfields['d.datec']['checked']))
  586. {
  587. print '<td align="center" class="nowrap">';
  588. print dol_print_date($db->jdate($obj->date_create), 'dayhour');
  589. print '</td>';
  590. if (! $i) $totalarray['nbfield']++;
  591. }
  592. // Date modification
  593. if (! empty($arrayfields['d.tms']['checked']))
  594. {
  595. print '<td align="center" class="nowrap">';
  596. print dol_print_date($db->jdate($obj->date_modif), 'dayhour');
  597. print '</td>';
  598. if (! $i) $totalarray['nbfield']++;
  599. }
  600. // Status
  601. if (! empty($arrayfields['d.fk_statut']['checked']))
  602. {
  603. print '<td align="right" class="nowrap">'.$expensereportstatic->getLibStatut(5).'</td>';
  604. if (! $i) $totalarray['nbfield']++;
  605. }
  606. // Action column
  607. print '<td class="nowrap" align="center">';
  608. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  609. {
  610. $selected=0;
  611. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  612. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  613. }
  614. print '</td>';
  615. if (! $i) $totalarray['nbfield']++;
  616. print "</tr>\n";
  617. $total_total_ht = $total_total_ht + $obj->total_ht;
  618. $total_total_tva = $total_total_tva + $obj->total_tva;
  619. $total_total_ttc = $total_total_ttc + $obj->total_ttc;
  620. $i++;
  621. }
  622. }
  623. else
  624. {
  625. print '<tr '.$bc[false].'>'.'<td colspan="9" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  626. }
  627. // Show total line
  628. if (isset($totalarray['totalhtfield']))
  629. {
  630. print '<tr class="liste_total">';
  631. $i=0;
  632. while ($i < $totalarray['nbfield'])
  633. {
  634. $i++;
  635. if ($i == 1)
  636. {
  637. if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
  638. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  639. }
  640. elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
  641. elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
  642. elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  643. else print '<td></td>';
  644. }
  645. print '</tr>';
  646. }
  647. $db->free($resql);
  648. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  649. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  650. print $hookmanager->resPrint;
  651. print '</table>'."\n";
  652. print '</div>';
  653. print '</form>'."\n";
  654. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
  655. {
  656. // Show list of available documents
  657. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  658. $urlsource.=str_replace('&amp;','&',$param);
  659. $filedir=$diroutputmassaction;
  660. $genallowed=$user->rights->expensereport->lire;
  661. $delallowed=$user->rights->expensereport->lire;
  662. print $formfile->showdocuments('massfilesarea_expensereport','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
  663. }
  664. else
  665. {
  666. print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
  667. }
  668. }
  669. else
  670. {
  671. dol_print_error($db);
  672. }
  673. llxFooter();
  674. $db->close();