list.php 22 KB

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