list.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  5. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>s
  7. * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
  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 <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/accountancy/expensereport/list.php
  24. * \ingroup Accountancy (Double entries)
  25. * \brief Ventilation page from expense reports
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("bills", "companies", "compta", "accountancy", "other", "trips", "productbatch", "hrm"));
  37. $action = GETPOST('action', 'aZ09');
  38. $massaction = GETPOST('massaction', 'alpha');
  39. $confirm = GETPOST('confirm', 'alpha');
  40. $toselect = GETPOST('toselect', 'array');
  41. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountancyexpensereportlist'; // To manage different context of search
  42. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  43. // Select Box
  44. $mesCasesCochees = GETPOST('toselect', 'array');
  45. // Search Getpost
  46. $search_login = GETPOST('search_login', 'alpha');
  47. $search_lineid = GETPOST('search_lineid', 'alpha');
  48. $search_expensereport = GETPOST('search_expensereport', 'alpha');
  49. $search_label = GETPOST('search_label', 'alpha');
  50. $search_desc = GETPOST('search_desc', 'alpha');
  51. $search_amount = GETPOST('search_amount', 'alpha');
  52. $search_account = GETPOST('search_account', 'alpha');
  53. $search_vat = GETPOST('search_vat', 'alpha');
  54. $search_date_startday = GETPOST('search_date_startday', 'int');
  55. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  56. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  57. $search_date_endday = GETPOST('search_date_endday', 'int');
  58. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  59. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  60. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  61. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  62. // Load variable for pagination
  63. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  64. $sortfield = GETPOST('sortfield', 'aZ09comma');
  65. $sortorder = GETPOST('sortorder', 'aZ09comma');
  66. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  67. if (empty($page) || $page < 0) {
  68. $page = 0;
  69. }
  70. $offset = $limit * $page;
  71. $pageprev = $page - 1;
  72. $pagenext = $page + 1;
  73. if (!$sortfield) {
  74. $sortfield = "erd.date, erd.rowid";
  75. }
  76. if (!$sortorder) {
  77. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
  78. $sortorder = "DESC";
  79. }
  80. }
  81. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  82. $hookmanager->initHooks(array('accountancyexpensereportlist'));
  83. $formaccounting = new FormAccounting($db);
  84. $accounting = new AccountingAccount($db);
  85. $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
  86. // Security check
  87. if (!isModEnabled('accounting')) {
  88. accessforbidden();
  89. }
  90. if ($user->socid > 0) {
  91. accessforbidden();
  92. }
  93. if (empty($user->rights->accounting->mouvements->lire)) {
  94. accessforbidden();
  95. }
  96. /*
  97. * Actions
  98. */
  99. if (GETPOST('cancel', 'alpha')) {
  100. $action = 'list'; $massaction = '';
  101. }
  102. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  103. $massaction = '';
  104. }
  105. $parameters = array();
  106. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  107. if ($reshook < 0) {
  108. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  109. }
  110. if (empty($reshook)) {
  111. // Purge search criteria
  112. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
  113. $search_login = '';
  114. $search_expensereport = '';
  115. $search_label = '';
  116. $search_desc = '';
  117. $search_amount = '';
  118. $search_account = '';
  119. $search_vat = '';
  120. $search_date_startday = '';
  121. $search_date_startmonth = '';
  122. $search_date_startyear = '';
  123. $search_date_endday = '';
  124. $search_date_endmonth = '';
  125. $search_date_endyear = '';
  126. $search_date_start = '';
  127. $search_date_end = '';
  128. $search_country = '';
  129. $search_tvaintra = '';
  130. }
  131. // Mass actions
  132. $objectclass = 'ExpenseReport';
  133. $objectlabel = 'ExpenseReport';
  134. $permissiontoread = $user->hasRight('accounting', 'read');
  135. $permissiontodelete = $user->hasRight('accounting', 'delete');
  136. $uploaddir = $conf->expensereport->dir_output;
  137. include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
  138. }
  139. if ($massaction == 'ventil' && $user->rights->accounting->bind->write) {
  140. $msg = '';
  141. //print '<div><span style="color:red">' . $langs->trans("Processing") . '...</span></div>';
  142. if (!empty($mesCasesCochees)) {
  143. $msg = '<div>'.$langs->trans("SelectedLines").': '.count($mesCasesCochees).'</div>';
  144. $msg .= '<div class="detail">';
  145. $cpt = 0;
  146. $ok = 0;
  147. $ko = 0;
  148. foreach ($mesCasesCochees as $maLigneCochee) {
  149. $maLigneCourante = explode("_", $maLigneCochee);
  150. $monId = $maLigneCourante[0];
  151. $monCompte = GETPOST('codeventil'.$monId);
  152. if ($monCompte <= 0) {
  153. $msg .= '<div><span style="color:red">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NoAccountSelected").'</span></div>';
  154. $ko++;
  155. } else {
  156. $sql = " UPDATE ".MAIN_DB_PREFIX."expensereport_det";
  157. $sql .= " SET fk_code_ventilation = ".((int) $monCompte);
  158. $sql .= " WHERE rowid = ".((int) $monId);
  159. $accountventilated = new AccountingAccount($db);
  160. $accountventilated->fetch($monCompte, '', 1);
  161. dol_syslog('accountancy/expensereport/list.php:: sql='.$sql, LOG_DEBUG);
  162. if ($db->query($sql)) {
  163. $msg .= '<div><span style="color:green">'.$langs->trans("LineOfExpenseReport").' '.$monId.' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
  164. $ok++;
  165. } else {
  166. $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NotVentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'<br> <pre>'.$sql.'</pre></span></div>';
  167. $ko++;
  168. }
  169. }
  170. $cpt++;
  171. }
  172. $msg .= '</div>';
  173. $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
  174. }
  175. }
  176. /*
  177. * View
  178. */
  179. $form = new Form($db);
  180. $formother = new FormOther($db);
  181. llxHeader('', $langs->trans("ExpenseReportsVentilation"));
  182. if (empty($chartaccountcode)) {
  183. print $langs->trans("ErrorChartOfAccountSystemNotSelected");
  184. // End of page
  185. llxFooter();
  186. $db->close();
  187. exit;
  188. }
  189. // Expense report lines
  190. $sql = "SELECT er.ref, er.rowid as erid, er.date_debut, er.date_valid,";
  191. $sql .= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht as price, erd.fk_code_ventilation, erd.tva_tx as tva_tx_line, erd.vat_src_code, erd.date,";
  192. $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label, f.accountancy_code as code_buy,";
  193. $sql .= " u.rowid as userid, u.login, u.lastname, u.firstname, u.email, u.gender, u.employee, u.photo, u.statut,";
  194. $sql .= " aa.rowid as aarowid";
  195. $parameters = array();
  196. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  197. $sql .= $hookmanager->resPrint;
  198. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as er";
  199. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport_det as erd ON er.rowid = erd.fk_expensereport";
  200. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f ON f.id = erd.fk_c_type_fees";
  201. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = er.fk_user_author";
  202. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON f.accountancy_code = aa.account_number AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
  203. $sql .= " WHERE er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <= 0";
  204. // Define begin binding date
  205. if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
  206. $sql .= " AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
  207. }
  208. // Add search filter like
  209. if (strlen(trim($search_login))) {
  210. $sql .= natural_search("u.login", $search_login);
  211. }
  212. if (strlen(trim($search_expensereport))) {
  213. $sql .= natural_search("er.ref", $search_expensereport);
  214. }
  215. if (strlen(trim($search_label))) {
  216. $sql .= natural_search("f.label", $search_label);
  217. }
  218. if (strlen(trim($search_desc))) {
  219. $sql .= natural_search("erd.comments", $search_desc);
  220. }
  221. if (strlen(trim($search_amount))) {
  222. $sql .= natural_search("erd.total_ht", $search_amount, 1);
  223. }
  224. if (strlen(trim($search_account))) {
  225. $sql .= natural_search("aa.account_number", $search_account);
  226. }
  227. if (strlen(trim($search_vat))) {
  228. $sql .= natural_search("erd.tva_tx", $search_vat, 1);
  229. }
  230. if ($search_date_start) {
  231. $sql .= " AND erd.date >= '".$db->idate($search_date_start)."'";
  232. }
  233. if ($search_date_end) {
  234. $sql .= " AND erd.date <= '".$db->idate($search_date_end)."'";
  235. }
  236. $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
  237. // Add where from hooks
  238. $parameters = array();
  239. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  240. $sql .= $hookmanager->resPrint;
  241. $sql .= $db->order($sortfield, $sortorder);
  242. // Count total nb of records
  243. $nbtotalofrecords = '';
  244. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  245. $result = $db->query($sql);
  246. $nbtotalofrecords = $db->num_rows($result);
  247. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  248. $page = 0;
  249. $offset = 0;
  250. }
  251. }
  252. $sql .= $db->plimit($limit + 1, $offset);
  253. dol_syslog("accountancy/expensereport/list.php", LOG_DEBUG);
  254. // MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
  255. // This big SELECT command may exceed the MAX_JOIN_SIZE limit => Therefore we use SQL_BIG_SELECTS=1 to disable the MAX_JOIN_SIZE security
  256. if ($db->type == 'mysqli') {
  257. $db->query("SET SQL_BIG_SELECTS=1");
  258. }
  259. $result = $db->query($sql);
  260. if ($result) {
  261. $num_lines = $db->num_rows($result);
  262. $i = 0;
  263. $arrayofselected = is_array($toselect) ? $toselect : array();
  264. $param = '';
  265. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  266. $param .= '&contextpage='.urlencode($contextpage);
  267. }
  268. if ($limit > 0 && $limit != $conf->liste_limit) {
  269. $param .= '&limit='.urlencode($limit);
  270. }
  271. if ($search_login) {
  272. $param .= '&search_login='.urlencode($search_login);
  273. }
  274. if ($search_lineid) {
  275. $param .= '&search_lineid='.urlencode($search_lineid);
  276. }
  277. if ($search_date_startday) {
  278. $param .= '&search_date_startday='.urlencode($search_date_startday);
  279. }
  280. if ($search_date_startmonth) {
  281. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  282. }
  283. if ($search_date_startyear) {
  284. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  285. }
  286. if ($search_date_endday) {
  287. $param .= '&search_date_endday='.urlencode($search_date_endday);
  288. }
  289. if ($search_date_endmonth) {
  290. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  291. }
  292. if ($search_date_endyear) {
  293. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  294. }
  295. if ($search_expensereport) {
  296. $param .= '&search_expensereport='.urlencode($search_expensereport);
  297. }
  298. if ($search_label) {
  299. $param .= '&search_label='.urlencode($search_label);
  300. }
  301. if ($search_desc) {
  302. $param .= '&search_desc='.urlencode($search_desc);
  303. }
  304. if ($search_amount) {
  305. $param .= '&search_amount='.urlencode($search_amount);
  306. }
  307. if ($search_vat) {
  308. $param .= '&search_vat='.urlencode($search_vat);
  309. }
  310. $arrayofmassactions = array(
  311. 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
  312. );
  313. $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1);
  314. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
  315. print '<input type="hidden" name="action" value="ventil">';
  316. if ($optioncss != '') {
  317. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  318. }
  319. print '<input type="hidden" name="token" value="'.newToken().'">';
  320. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  321. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  322. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  323. print '<input type="hidden" name="page" value="'.$page.'">';
  324. print_barre_liste($langs->trans("ExpenseReportLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  325. print '<span class="opacitymedium">'.$langs->trans("DescVentilTodoExpenseReport").'</span></br><br>';
  326. if (!empty($msg)) {
  327. print $msg.'<br>';
  328. }
  329. $moreforfilter = '';
  330. print '<div class="div-table-responsive">';
  331. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  332. // We add search filter
  333. print '<tr class="liste_titre_filter">';
  334. print '<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="'.$search_login.'"></td>';
  335. print '<td class="liste_titre"></td>';
  336. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_expensereport" value="'.dol_escape_htmltag($search_expensereport).'"></td>';
  337. if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
  338. print '<td class="liste_titre"></td>';
  339. }
  340. print '<td class="liste_titre center">';
  341. print '<div class="nowrap">';
  342. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  343. print '</div>';
  344. print '<div class="nowrap">';
  345. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  346. print '</div>';
  347. print '</td>';
  348. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
  349. print '<td class="liste_titre"><input type="text" class="flat maxwidthonsmartphone" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
  350. print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
  351. print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="'.dol_escape_htmltag($search_vat).'"></td>';
  352. print '<td class="liste_titre"></td>';
  353. print '<td class="liste_titre"></td>';
  354. print '<td class="center liste_titre">';
  355. $searchpicto = $form->showFilterButtons();
  356. print $searchpicto;
  357. print '</td>';
  358. print '</tr>';
  359. print '<tr class="liste_titre">';
  360. print_liste_field_titre("Employee", $_SERVER['PHP_SELF'], "u.login", $param, "", "", $sortfield, $sortorder);
  361. print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
  362. print_liste_field_titre("ExpenseReport", $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
  363. if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
  364. print_liste_field_titre("DateValidation", $_SERVER["PHP_SELF"], "er.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
  365. }
  366. print_liste_field_titre("DateOfLine", $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  367. print_liste_field_titre("TypeFees", $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
  368. print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
  369. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, '', $sortfield, $sortorder, 'right maxwidth50 ');
  370. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
  371. print_liste_field_titre("DataUsedToSuggestAccount", '', '', '', '', '', '', '', 'nowraponall ');
  372. print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', '', '', '', '');
  373. $checkpicto = '';
  374. if ($massactionbutton) {
  375. $checkpicto = $form->showCheckAddButtons('checkforselect', 1);
  376. }
  377. print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
  378. print "</tr>\n";
  379. $expensereport_static = new ExpenseReport($db);
  380. $userstatic = new User($db);
  381. $form = new Form($db);
  382. while ($i < min($num_lines, $limit)) {
  383. $objp = $db->fetch_object($result);
  384. $objp->aarowid_suggest = '';
  385. $objp->aarowid_suggest = $objp->aarowid;
  386. $expensereport_static->ref = $objp->ref;
  387. $expensereport_static->id = $objp->erid;
  388. $userstatic->id = $objp->userid;
  389. $userstatic->login = $objp->login;
  390. $userstatic->statut = $objp->statut;
  391. $userstatic->email = $objp->email;
  392. $userstatic->gender = $objp->gender;
  393. $userstatic->firstname = $objp->firstname;
  394. $userstatic->lastname = $objp->lastname;
  395. $userstatic->employee = $objp->employee;
  396. $userstatic->photo = $objp->photo;
  397. print '<tr class="oddeven">';
  398. // Login
  399. print '<td class="nowraponall">';
  400. print $userstatic->getNomUrl(-1, '', 0, 0, 24, 1, 'login', '', 1);
  401. print '</td>';
  402. // Line id
  403. print '<td>'.$objp->rowid.'</td>';
  404. // Ref Expense report
  405. print '<td>'.$expensereport_static->getNomUrl(1).'</td>';
  406. // Date validation
  407. if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
  408. print '<td class="center">'.dol_print_date($db->jdate($objp->date_valid), 'day').'</td>';
  409. }
  410. // Date
  411. print '<td class="center">'.dol_print_date($db->jdate($objp->date), 'day').'</td>';
  412. // Fees label
  413. print '<td>';
  414. print ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code)));
  415. print '</td>';
  416. // Fees description -- Can be null
  417. print '<td>';
  418. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments, 1));
  419. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  420. print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->comments);
  421. print '</td>';
  422. // Amount without taxes
  423. print '<td class="right nowraponall amount">';
  424. print price($objp->price);
  425. print '</td>';
  426. // Vat rate
  427. print '<td class="right">';
  428. print vatrate($objp->tva_tx_line.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : ''));
  429. print '</td>';
  430. // Current account
  431. print '<td>';
  432. print length_accountg(html_entity_decode($objp->code_buy));
  433. print '</td>';
  434. // Suggested accounting account
  435. print '<td>';
  436. print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
  437. print '</td>';
  438. print '<td class="center">';
  439. print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="'.$objp->rowid."_".$i.'"'.($objp->aarowid ? "checked" : "").'/>';
  440. print '</td>';
  441. print "</tr>";
  442. $i++;
  443. }
  444. if ($num_lines == 0) {
  445. print '<tr><td colspan="13"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  446. }
  447. print '</table>';
  448. print "</div>";
  449. print '</form>';
  450. } else {
  451. print $db->error();
  452. }
  453. if ($db->type == 'mysqli') {
  454. $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
  455. }
  456. // Add code to auto check the box when we select an account
  457. print '<script type="text/javascript">
  458. jQuery(document).ready(function() {
  459. jQuery(".codeventil").change(function() {
  460. var s=$(this).attr("id").replace("codeventil", "")
  461. console.log(s+" "+$(this).val());
  462. if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
  463. else jQuery(".checkforselect"+s).prop("checked", true);
  464. });
  465. });
  466. </script>';
  467. // End of page
  468. llxFooter();
  469. $db->close();