lines.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  5. * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/expensereport/lines.php
  23. * \ingroup Advanced accountancy
  24. * \brief Page of detail of the lines of ventilation of expense reports
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("compta","bills","other","accountancy","trips","productbatch"));
  35. $account_parent = GETPOST('account_parent','int');
  36. $changeaccount = GETPOST('changeaccount');
  37. // Search Getpost
  38. $search_expensereport = GETPOST('search_expensereport', 'alpha');
  39. $search_label = GETPOST('search_label', 'alpha');
  40. $search_desc = GETPOST('search_desc', 'alpha');
  41. $search_amount = GETPOST('search_amount', 'alpha');
  42. $search_account = GETPOST('search_account', 'alpha');
  43. $search_vat = GETPOST('search_vat', 'alpha');
  44. $search_day=GETPOST("search_day","int");
  45. $search_month=GETPOST("search_month","int");
  46. $search_year=GETPOST("search_year","int");
  47. // Load variable for pagination
  48. $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  49. $sortfield = GETPOST('sortfield', 'alpha');
  50. $sortorder = GETPOST('sortorder', 'alpha');
  51. $page = GETPOST('page', 'int');
  52. if (empty($page) || $page < 0) $page = 0;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. $offset = $limit * $page;
  56. if (! $sortfield)
  57. $sortfield = "erd.date, erd.rowid";
  58. if (! $sortorder) {
  59. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
  60. $sortorder = "DESC";
  61. }
  62. }
  63. // Security check
  64. if ($user->societe_id > 0)
  65. accessforbidden();
  66. if (! $user->rights->accounting->bind->write)
  67. accessforbidden();
  68. $formaccounting = new FormAccounting($db);
  69. /*
  70. * Actions
  71. */
  72. // Purge search criteria
  73. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
  74. {
  75. $search_expensereport = '';
  76. $search_label = '';
  77. $search_desc = '';
  78. $search_amount = '';
  79. $search_account = '';
  80. $search_vat = '';
  81. $search_day = '';
  82. $search_month = '';
  83. $search_year = '';
  84. }
  85. if (is_array($changeaccount) && count($changeaccount) > 0) {
  86. $error = 0;
  87. if (! (GETPOST('account_parent','int') >= 0))
  88. {
  89. $error++;
  90. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
  91. }
  92. if (! $error)
  93. {
  94. $db->begin();
  95. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
  96. $sql1 .= " SET erd.fk_code_ventilation=" . (GETPOST('account_parent','int') > 0 ? GETPOST('account_parent','int') : '0');
  97. $sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')';
  98. dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1);
  99. $resql1 = $db->query($sql1);
  100. if (! $resql1) {
  101. $error ++;
  102. setEventMessages($db->lasterror(), null, 'errors');
  103. }
  104. if (! $error) {
  105. $db->commit();
  106. setEventMessages($langs->trans('Save'), null, 'mesgs');
  107. } else {
  108. $db->rollback();
  109. setEventMessages($db->lasterror(), null, 'errors');
  110. }
  111. $account_parent = ''; // Protection to avoid to mass apply it a second time
  112. }
  113. }
  114. /*
  115. * View
  116. */
  117. $form = new Form($db);
  118. $formother = new FormOther($db);
  119. llxHeader('', $langs->trans("ExpenseReportsVentilation") . ' - ' . $langs->trans("Dispatched"));
  120. print '<script type="text/javascript">
  121. $(function () {
  122. $(\'#select-all\').click(function(event) {
  123. // Iterate each checkbox
  124. $(\':checkbox\').each(function() {
  125. this.checked = true;
  126. });
  127. });
  128. $(\'#unselect-all\').click(function(event) {
  129. // Iterate each checkbox
  130. $(\':checkbox\').each(function() {
  131. this.checked = false;
  132. });
  133. });
  134. });
  135. </script>';
  136. /*
  137. * Expense reports lines
  138. */
  139. $sql = "SELECT er.ref, er.rowid as erid,";
  140. $sql .= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht, erd.fk_code_ventilation, erd.tva_tx, erd.vat_src_code, erd.date,";
  141. $sql .= " aa.label, aa.account_number,";
  142. $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label";
  143. $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
  144. $sql .= " , " . MAIN_DB_PREFIX . "accounting_account as aa";
  145. $sql .= " , " . MAIN_DB_PREFIX . "expensereport_det as erd";
  146. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
  147. $sql .= " WHERE er.rowid = erd.fk_expensereport and er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <> 0 ";
  148. $sql .= " AND aa.rowid = erd.fk_code_ventilation";
  149. if (strlen(trim($search_expensereport))) {
  150. $sql .= natural_search("er.ref", $search_expensereport);
  151. }
  152. if (strlen(trim($search_label))) {
  153. $sql .= natural_search("f.label", $search_label);
  154. }
  155. if (strlen(trim($search_desc))) {
  156. $sql .= natural_search("er.comments", $search_desc);
  157. }
  158. if (strlen(trim($search_amount))) {
  159. $sql .= natural_search("erd.total_ht", $search_amount, 1);
  160. }
  161. if (strlen(trim($search_account))) {
  162. $sql .= natural_search("aa.account_number", $search_account);
  163. }
  164. if (strlen(trim($search_vat))) {
  165. $sql .= natural_search("erd.tva_tx", price2num($search_vat), 1);
  166. }
  167. if ($search_month > 0)
  168. {
  169. if ($search_year > 0 && empty($search_day))
  170. $sql.= " AND erd.date BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
  171. elseif ($search_year > 0 && ! empty($search_day))
  172. $sql.= " AND erd.date BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
  173. else
  174. $sql.= " AND date_format(erd.date, '%m') = '".$db->escape($search_month)."'";
  175. }
  176. elseif ($search_year > 0)
  177. {
  178. $sql.= " AND erd.date BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
  179. }
  180. $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy
  181. $sql .= $db->order($sortfield, $sortorder);
  182. // Count total nb of records
  183. $nbtotalofrecords = '';
  184. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  185. {
  186. $result = $db->query($sql);
  187. $nbtotalofrecords = $db->num_rows($result);
  188. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  189. {
  190. $page = 0;
  191. $offset = 0;
  192. }
  193. }
  194. $sql .= $db->plimit($limit + 1, $offset);
  195. dol_syslog('accountancy/expensereport/lines.php::list');
  196. $result = $db->query($sql);
  197. if ($result) {
  198. $num_lines = $db->num_rows($result);
  199. $i = 0;
  200. $param='';
  201. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
  202. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
  203. if ($search_expensereport) $param .= "&search_expensereport=" . urlencode($search_expensereport);
  204. if ($search_label) $param .= "&search_label=" . urlencode($search_label);
  205. if ($search_desc) $param .= "&search_desc=" . urlencode($search_desc);
  206. if ($search_account) $param .= "&search_account=" . urlencode($search_account);
  207. if ($search_vat) $param .= "&search_vat=" . urlencode($search_vat);
  208. if ($search_day) $param .= '&search_day='.urlencode($search_day);
  209. if ($search_month) $param .= '&search_month='.urlencode($search_month);
  210. if ($search_year) $param .= '&search_year='.urlencode($search_year);
  211. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
  212. print '<input type="hidden" name="action" value="ventil">';
  213. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  214. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  215. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  216. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  217. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  218. print '<input type="hidden" name="page" value="'.$page.'">';
  219. print_barre_liste($langs->trans("ExpenseReportLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  220. print $langs->trans("DescVentilDoneExpenseReport") . '<br>';
  221. print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
  222. print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
  223. print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
  224. $moreforfilter = '';
  225. print '<div class="div-table-responsive">';
  226. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  227. print '<tr class="liste_titre_filter">';
  228. print '<td class="liste_titre"></td>';
  229. print '<td><input type="text" class="flat maxwidth50" name="search_expensereport" value="' . dol_escape_htmltag($search_expensereport) . '"></td>';
  230. print '<td class="liste_titre center">';
  231. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
  232. print '<input class="flat" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
  233. $formother->select_year($search_year,'search_year',1, 20, 5);
  234. print '</td>';
  235. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  236. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  237. print '<td class="liste_titre" align="right"><input type="text" class="flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
  238. print '<td class="liste_titre" align="center"><input type="text" class="flat maxwidth50" name="search_vat" size="1" placeholder="%" value="' . dol_escape_htmltag($search_vat) . '"></td>';
  239. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="' . dol_escape_htmltag($search_account) . '"></td>';
  240. print '<td class="liste_titre" align="right"></td>';
  241. print '<td class="liste_titre" align="right">';
  242. $searchpicto=$form->showFilterButtons();
  243. print $searchpicto;
  244. print '</td>';
  245. print "</tr>\n";
  246. print '<tr class="liste_titre">';
  247. print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
  248. print_liste_field_titre("ExpenseReport", $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
  249. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  250. print_liste_field_titre("TypeFees", $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
  251. print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
  252. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
  253. print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
  254. print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
  255. print_liste_field_titre('');
  256. $checkpicto=$form->showCheckAddButtons();
  257. print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
  258. print "</tr>\n";
  259. $expensereport_static = new ExpenseReport($db);
  260. while ( $i < min($num_lines, $limit) ) {
  261. $objp = $db->fetch_object($result);
  262. $codeCompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
  263. $expensereport_static->ref = $objp->ref;
  264. $expensereport_static->id = $objp->erid;
  265. print '<tr class="oddeven">';
  266. print '<td>' . $objp->rowid . '</td>';
  267. // Ref Invoice
  268. print '<td>' . $expensereport_static->getNomUrl(1) . '</td>';
  269. print '<td align="center">' . dol_print_date($db->jdate($objp->date), 'day') . '</td>';
  270. print '<td class="tdoverflow">' . ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code))) . '</td>';
  271. print '<td>';
  272. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
  273. $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
  274. print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
  275. print '</td>';
  276. print '<td class="right">' . price($objp->total_ht) . '</td>';
  277. print '<td align="center">' . vatrate($objp->tva_tx.($objp->vat_src_code?' ('.$objp->vat_src_code.')':'')) . '</td>';
  278. print '<td>' . $codeCompta . '</td>';
  279. print '<td class="left"><a href="./card.php?id=' . $objp->rowid . '&backtopage='.urlencode($_SERVER["PHP_SELF"].($param?'?'.$param:'')). '">';
  280. print img_edit();
  281. print '</a></td>';
  282. print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
  283. print "</tr>";
  284. $i ++;
  285. }
  286. print "</table>";
  287. print "</div>";
  288. if ($nbtotalofrecords > $limit) {
  289. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
  290. }
  291. print '</form>';
  292. } else {
  293. print $db->lasterror();
  294. }
  295. // End of page
  296. llxFooter();
  297. $db->close();