lines.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  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. // Class
  28. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  29. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  32. // Langs
  33. $langs->load("compta");
  34. $langs->load("bills");
  35. $langs->load("other");
  36. $langs->load("main");
  37. $langs->load("accountancy");
  38. $langs->load("trips");
  39. $langs->load("productbatch");
  40. $account_parent = GETPOST('account_parent');
  41. $changeaccount = GETPOST('changeaccount');
  42. // Search Getpost
  43. $search_expensereport = GETPOST('search_expensereport', 'alpha');
  44. $search_label = GETPOST('search_label', 'alpha');
  45. $search_desc = GETPOST('search_desc', 'alpha');
  46. $search_amount = GETPOST('search_amount', 'alpha');
  47. $search_account = GETPOST('search_account', 'alpha');
  48. $search_vat = GETPOST('search_vat', 'alpha');
  49. // Load variable for pagination
  50. $limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  51. $sortfield = GETPOST('sortfield', 'alpha');
  52. $sortorder = GETPOST('sortorder', 'alpha');
  53. $page = GETPOST('page', 'int');
  54. if ($page < 0) $page = 0;
  55. $offset = $conf->liste_limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (! $sortfield)
  59. $sortfield = "erd.date, erd.rowid";
  60. if (! $sortorder) {
  61. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
  62. $sortorder = "DESC";
  63. }
  64. }
  65. // Security check
  66. if ($user->societe_id > 0)
  67. accessforbidden();
  68. if (! $user->rights->accounting->bind->write)
  69. accessforbidden();
  70. $formaccounting = new FormAccounting($db);
  71. /*
  72. * Actions
  73. */
  74. // Purge search criteria
  75. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  76. {
  77. $search_expensereport = '';
  78. $search_label = '';
  79. $search_desc = '';
  80. $search_amount = '';
  81. $search_account = '';
  82. $search_vat = '';
  83. }
  84. if (is_array($changeaccount) && count($changeaccount) > 0) {
  85. $error = 0;
  86. $db->begin();
  87. $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
  88. $sql1 .= " SET erd.fk_code_ventilation=" . GETPOST('account_parent');
  89. $sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')';
  90. dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1);
  91. $resql1 = $db->query($sql1);
  92. if (! $resql1) {
  93. $error ++;
  94. setEventMessages($db->lasterror(), null, 'errors');
  95. }
  96. if (! $error) {
  97. $db->commit();
  98. setEventMessages($langs->trans('Save'), null, 'mesgs');
  99. } else {
  100. $db->rollback();
  101. setEventMessages($db->lasterror(), null, 'errors');
  102. }
  103. $account_parent = ''; // Protection to avoid to mass apply it a second time
  104. }
  105. /*
  106. * View
  107. */
  108. llxHeader('', $langs->trans("ExpenseReportsVentilation") . ' - ' . $langs->trans("Dispatched"));
  109. print '<script type="text/javascript">
  110. $(function () {
  111. $(\'#select-all\').click(function(event) {
  112. // Iterate each checkbox
  113. $(\':checkbox\').each(function() {
  114. this.checked = true;
  115. });
  116. });
  117. $(\'#unselect-all\').click(function(event) {
  118. // Iterate each checkbox
  119. $(\':checkbox\').each(function() {
  120. this.checked = false;
  121. });
  122. });
  123. });
  124. </script>';
  125. /*
  126. * Expense reports lines
  127. */
  128. $sql = "SELECT er.ref, er.rowid as erid,";
  129. $sql .= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht, erd.fk_code_ventilation, erd.tva_tx, erd.date,";
  130. $sql .= " aa.label, aa.account_number,";
  131. $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label";
  132. $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
  133. $sql .= " , " . MAIN_DB_PREFIX . "accounting_account as aa";
  134. $sql .= " , " . MAIN_DB_PREFIX . "expensereport_det as erd";
  135. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
  136. $sql .= " WHERE er.rowid = erd.fk_expensereport and er.fk_statut >= 5 AND erd.fk_code_ventilation <> 0 ";
  137. $sql .= " AND aa.rowid = erd.fk_code_ventilation";
  138. if (strlen(trim($search_expensereport))) {
  139. $sql .= " AND er.ref like '%" . $search_expensereport . "%'";
  140. }
  141. if (strlen(trim($search_label))) {
  142. $sql .= " AND f.label like '%" . $search_label . "%'";
  143. }
  144. if (strlen(trim($search_desc))) {
  145. $sql .= " AND er.comments like '%" . $search_desc . "%'";
  146. }
  147. if (strlen(trim($search_amount))) {
  148. $sql .= " AND erd.total_ht like '%" . $search_amount . "%'";
  149. }
  150. if (strlen(trim($search_account))) {
  151. $sql .= " AND aa.account_number like '%" . $search_account . "%'";
  152. }
  153. if (strlen(trim($search_vat))) {
  154. $sql .= " AND (erd.tva_tx like '" . $search_vat . "%')";
  155. }
  156. $sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy
  157. $sql .= $db->order($sortfield, $sortorder);
  158. // Count total nb of records
  159. $nbtotalofrecords = '';
  160. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  161. {
  162. $result = $db->query($sql);
  163. $nbtotalofrecords = $db->num_rows($result);
  164. }
  165. $sql .= $db->plimit($limit + 1, $offset);
  166. dol_syslog('accountancy/expensereport/lines.php::list');
  167. $result = $db->query($sql);
  168. if ($result) {
  169. $num_lines = $db->num_rows($result);
  170. $i = 0;
  171. $param='';
  172. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  173. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  174. if ($search_expensereport)
  175. $param .= "&search_expensereport=" . $search_expensereport;
  176. if ($search_label)
  177. $param .= "&search_label=" . $search_label;
  178. if ($search_desc)
  179. $param .= "&search_desc=" . $search_desc;
  180. if ($search_account)
  181. $param .= "&search_account=" . $search_account;
  182. if ($search_vat)
  183. $param .= "&search_vat=" . $search_vat;
  184. if ($search_country)
  185. $param .= "&search_country=" . $search_country;
  186. if ($search_tvaintra)
  187. $param .= "&search_tvaintra=" . $search_tvaintra;
  188. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
  189. print '<input type="hidden" name="action" value="ventil">';
  190. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  191. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  192. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  193. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  194. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  195. print '<input type="hidden" name="page" value="'.$page.'">';
  196. print_barre_liste($langs->trans("ExpenseReportLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  197. print $langs->trans("DescVentilDoneExpenseReport") . '<br>';
  198. print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
  199. print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
  200. print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
  201. $moreforfilter = '';
  202. print '<div class="div-table-responsive">';
  203. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  204. print '<tr class="liste_titre_filter">';
  205. print '<td class="liste_titre"></td>';
  206. print '<td><input type="text" class="flat maxwidth50" name="search_expensereport" value="' . dol_escape_htmltag($search_expensereport) . '"></td>';
  207. print '<td class="liste_titre" align="right"></td>';
  208. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  209. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  210. print '<td class="liste_titre" align="right"><input type="text" class="flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
  211. print '<td class="liste_titre" align="center"><input type="text" class="right flat maxwidth50" name="search_vat" size="1" placeholder="%" value="' . dol_escape_htmltag($search_vat) . '"></td>';
  212. print '<td class="liste_titre" align="center"><input type="text" class="right flat maxwidth50" name="search_account" value="' . dol_escape_htmltag($search_account) . '"></td>';
  213. print '<td class="liste_titre" align="right"></td>';
  214. print '<td class="liste_titre" align="right">';
  215. $searchpicto=$form->showFilterButtons();
  216. print $searchpicto;
  217. print '</td>';
  218. print "</tr>\n";
  219. print '<tr class="liste_titre">';
  220. print_liste_field_titre($langs->trans("LineId"), $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
  221. print_liste_field_titre($langs->trans("ExpenseReport"), $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
  222. print_liste_field_titre($langs->trans("Date"), $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  223. print_liste_field_titre($langs->trans("TypeFees"), $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
  224. print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
  225. print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
  226. print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
  227. print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"], "aa.account_number", "", $param, 'align="center"', $sortfield, $sortorder);
  228. print_liste_field_titre('');
  229. $checkpicto=$form->showCheckAddButtons();
  230. print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
  231. print "</tr>\n";
  232. $expensereport_static = new ExpenseReport($db);
  233. $var = True;
  234. while ( $i < min($num_lines, $limit) ) {
  235. $objp = $db->fetch_object($result);
  236. $codeCompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
  237. $expensereport_static->ref = $objp->ref;
  238. $expensereport_static->id = $objp->erid;
  239. print '<tr class="oddeven">';
  240. print '<td>' . $objp->rowid . '</td>';
  241. // Ref Invoice
  242. print '<td>' . $expensereport_static->getNomUrl(1) . '</td>';
  243. print '<td align="center">' . dol_print_date($db->jdate($objp->date), 'day') . '</td>';
  244. 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>';
  245. print '<td>';
  246. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
  247. $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
  248. print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
  249. print '</td>';
  250. print '<td align="right">' . price($objp->total_ht) . '</td>';
  251. print '<td align="center">' . price($objp->tva_tx) . '</td>';
  252. print '<td>' . $codeCompta . '</td>';
  253. print '<td align="left"><a href="./card.php?id=' . $objp->rowid . '">';
  254. print img_edit();
  255. print '</a></td>';
  256. print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
  257. print "</tr>";
  258. $i ++;
  259. }
  260. print "</table>";
  261. print "</div>";
  262. if ($nbtotalofrecords > $limit) {
  263. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
  264. }
  265. print '</form>';
  266. } else {
  267. print $db->error();
  268. }
  269. llxFooter();
  270. $db->close();