list.php 36 KB

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