list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <?php
  2. /* Copyright (C) 2013-2014 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-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 <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/accountancy/expensereport/list.php
  24. * \ingroup Advanced accountancy
  25. * \brief Ventilation page from expense reports
  26. */
  27. require '../../main.inc.php';
  28. // Class
  29. require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  31. require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
  32. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  33. // Langs
  34. $langs->load("compta");
  35. $langs->load("bills");
  36. $langs->load("other");
  37. $langs->load("trips");
  38. $langs->load("main");
  39. $langs->load("accountancy");
  40. $langs->load("productbatch");
  41. $action=GETPOST('action','alpha');
  42. $massaction=GETPOST('massaction','alpha');
  43. $show_files=GETPOST('show_files','int');
  44. $confirm=GETPOST('confirm','alpha');
  45. $toselect = GETPOST('toselect', 'array');
  46. // Select Box
  47. $mesCasesCochees = GETPOST('toselect', 'array');
  48. // Search Getpost
  49. $search_expensereport = GETPOST('search_expensereport', 'alpha');
  50. $search_label = GETPOST('search_label', 'alpha');
  51. $search_desc = GETPOST('search_desc', 'alpha');
  52. $search_amount = GETPOST('search_amount', 'alpha');
  53. $search_account = GETPOST('search_account', 'alpha');
  54. $search_vat = GETPOST('search_vat', 'alpha');
  55. $btn_ventil = GETPOST('ventil', 'alpha');
  56. // Load variable for pagination
  57. $limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
  58. $sortfield = GETPOST('sortfield', 'alpha');
  59. $sortorder = GETPOST('sortorder', 'alpha');
  60. $page = GETPOST('page','int');
  61. if ($page < 0) { $page = 0; }
  62. $offset = $limit * $page;
  63. $pageprev = $page - 1;
  64. $pagenext = $page + 1;
  65. if (! $sortfield)
  66. $sortfield = "erd.date, erd.rowid";
  67. if (! $sortorder) {
  68. if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
  69. $sortorder = "DESC";
  70. }
  71. }
  72. // Security check
  73. if ($user->societe_id > 0)
  74. accessforbidden();
  75. if (! $user->rights->accounting->bind->write)
  76. accessforbidden();
  77. $formaccounting = new FormAccounting($db);
  78. $accounting = new AccountingAccount($db);
  79. /*
  80. * Action
  81. */
  82. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  83. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  84. // Purge search criteria
  85. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  86. {
  87. $search_expensereport = '';
  88. $search_label = '';
  89. $search_desc = '';
  90. $search_amount = '';
  91. $search_account = '';
  92. $search_vat = '';
  93. }
  94. // Mass actions
  95. $objectclass='Skeleton';
  96. $objectlabel='Skeleton';
  97. $permtoread = $user->rights->accounting->read;
  98. $permtodelete = $user->rights->accounting->delete;
  99. $uploaddir = $conf->accounting->dir_output;
  100. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  101. if ($massaction == 'ventil') {
  102. $msg='';
  103. //print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
  104. if (! empty($mesCasesCochees)) {
  105. $msg = '<div>' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'</div>';
  106. $msg.='<div class="detail">';
  107. $mesCodesVentilChoisis = $codeventil;
  108. $cpt = 0;
  109. $ok=0;
  110. $ko=0;
  111. foreach ( $mesCasesCochees as $maLigneCochee ) {
  112. $maLigneCourante = explode("_", $maLigneCochee);
  113. $monId = $maLigneCourante[0];
  114. $monCompte = GETPOST('codeventil'.$monId);
  115. if ($monCompte <= 0)
  116. {
  117. $msg.= '<div><font color="red">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NoAccountSelected") . '</font></div>';
  118. $ko++;
  119. }
  120. else
  121. {
  122. $sql = " UPDATE " . MAIN_DB_PREFIX . "expensereport_det";
  123. $sql .= " SET fk_code_ventilation = " . $monCompte;
  124. $sql .= " WHERE rowid = " . $monId;
  125. $accountventilated = new AccountingAccount($db);
  126. $accountventilated->fetch($monCompte, '');
  127. dol_syslog('accountancy/expensereport/list.php:: sql=' . $sql, LOG_DEBUG);
  128. if ($db->query($sql)) {
  129. $msg.= '<div><font color="green">' . $langs->trans("LineOfExpenseReport") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '</font></div>';
  130. $ok++;
  131. } else {
  132. $msg.= '<div><font color="red">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '<br/> <pre>' . $sql . '</pre></font></div>';
  133. $ko++;
  134. }
  135. }
  136. $cpt++;
  137. }
  138. $msg.='</div>';
  139. $msg.= '<div>' . $langs->trans("EndProcessing") . '</div>';
  140. //} else {
  141. // setEventMessages($langs->trans("NoRecordSelected"), null, 'warnings');
  142. }
  143. }
  144. /*
  145. * View
  146. */
  147. $form = new Form($db);
  148. llxHeader('', $langs->trans("ExpenseReportsVentilation"));
  149. // Expense report lines
  150. $sql = "SELECT er.ref, er.rowid as erid, er.date_debut,";
  151. $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.date,";
  152. $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,";
  153. $sql .= " aa.rowid as aarowid";
  154. $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
  155. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "expensereport_det as erd ON er.rowid = erd.fk_expensereport";
  156. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
  157. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON f.accountancy_code = aa.account_number";
  158. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version";
  159. $sql .= " WHERE er.fk_statut > 4 AND erd.fk_code_ventilation <= 0";
  160. $sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR f.accountancy_code IS NULL OR f.accountancy_code ='')";
  161. // Add search filter like
  162. if (strlen(trim($search_expensereport))) {
  163. $sql .= natural_search("er.ref",$search_expensereport);
  164. }
  165. if (strlen(trim($search_label))) {
  166. $sql .= natural_search("f.label",$search_label);
  167. }
  168. if (strlen(trim($search_desc))) {
  169. $sql .= natural_search("erd.comments",$search_desc);
  170. }
  171. if (strlen(trim($search_amount))) {
  172. $sql .= natural_search("erd.total_ht",$search_amount,1);
  173. }
  174. if (strlen(trim($search_account))) {
  175. $sql .= natural_search("aa.account_number",$search_account);
  176. }
  177. if (strlen(trim($search_vat))) {
  178. $sql .= natural_search("erd.tva_tx",$search_vat,1);
  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. }
  189. $sql .= $db->plimit($limit + 1, $offset);
  190. dol_syslog('accountancy/expensereport/list.php');
  191. $result = $db->query($sql);
  192. if ($result) {
  193. $num_lines = $db->num_rows($result);
  194. $i = 0;
  195. $arrayofselected=is_array($toselect)?$toselect:array();
  196. $param='';
  197. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  198. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  199. $arrayofmassactions = array(
  200. 'ventil'=>$langs->trans("Ventilate")
  201. //'presend'=>$langs->trans("SendByMail"),
  202. //'builddoc'=>$langs->trans("PDFMerge"),
  203. );
  204. //if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  205. //if ($massaction == 'presend') $arrayofmassactions=array();
  206. $massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1);
  207. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
  208. print '<input type="hidden" name="action" value="ventil">';
  209. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  210. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  211. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  212. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  213. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  214. print '<input type="hidden" name="page" value="'.$page.'">';
  215. print_barre_liste($langs->trans("ExpenseReportLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
  216. print $langs->trans("DescVentilTodoExpenseReport") . '</br><br>';
  217. if ($msg) print $msg.'<br>';
  218. $moreforfilter = '';
  219. print '<div class="div-table-responsive">';
  220. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  221. // We add search filter
  222. print '<tr class="liste_titre_filter">';
  223. print '<td class="liste_titre"></td>';
  224. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_expensereport" value="' . dol_escape_htmltag($search_expensereport) . '"></td>';
  225. print '<td class="liste_titre"></td>';
  226. print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
  227. print '<td class="liste_titre"><input type="text" class="flat maxwidthonsmartphone" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
  228. print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
  229. print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag($search_vat) . '"></td>';
  230. print '<td class="liste_titre"></td>';
  231. print '<td class="liste_titre"></td>';
  232. print '<td align="center" class="liste_titre">';
  233. $searchpicto=$form->showFilterButtons();
  234. print $searchpicto;
  235. print '</td>';
  236. print '</tr>';
  237. print '<tr class="liste_titre">';
  238. print_liste_field_titre($langs->trans("LineId"), $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
  239. print_liste_field_titre($langs->trans("ExpenseReport"), $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
  240. print_liste_field_titre($langs->trans("Date"), $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  241. print_liste_field_titre($langs->trans("TypeFees"), $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
  242. print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
  243. print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
  244. print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, 'align="right"', $sortfield, $sortorder);
  245. print_liste_field_titre($langs->trans("AccountAccountingSuggest"), '', '', '', '', 'align="center"');
  246. print_liste_field_titre($langs->trans("IntoAccount"), '', '', '', '', 'align="center"');
  247. $checkpicto='';
  248. if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1);
  249. print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
  250. print "</tr>\n";
  251. $expensereport_static = new ExpenseReport($db);
  252. $form = new Form($db);
  253. $var = true;
  254. while ( $i < min($num_lines, $limit) ) {
  255. $objp = $db->fetch_object($result);
  256. $objp->aarowid_suggest = '';
  257. $objp->aarowid_suggest = $objp->aarowid;
  258. $expensereport_static->ref = $objp->ref;
  259. $expensereport_static->id = $objp->erid;
  260. print '<tr class="oddeven">';
  261. // Line id
  262. print '<td>' . $objp->rowid . '</td>';
  263. // Ref Expense report
  264. print '<td>' . $expensereport_static->getNomUrl(1) . '</td>';
  265. print '<td align="center">' . dol_print_date($db->jdate($objp->date), 'day') . '</td>';
  266. // Fees label
  267. print '<td>';
  268. print ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code)));
  269. print '</td>';
  270. // Fees description -- Can be null
  271. print '<td>';
  272. $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
  273. $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
  274. print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
  275. print '</td>';
  276. print '<td align="right">';
  277. print price($objp->price);
  278. print '</td>';
  279. // Vat rate
  280. print '<td align="right">';
  281. print price($objp->tva_tx_line);
  282. print '</td>';
  283. // Current account
  284. print '<td align="center">';
  285. print length_accountg(html_entity_decode($objp->code_buy));
  286. print '</td>';
  287. // Suggested accounting account
  288. print '<td align="center">';
  289. print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
  290. print '</td>';
  291. print '<td align="center">';
  292. print '<input type="checkbox" class="flat checkforselect" name="toselect[]" value="' . $objp->rowid . "_" . $i . '"' . ($objp->aarowid ? "checked" : "") . '/>';
  293. print '</td>';
  294. print "</tr>";
  295. $i ++;
  296. }
  297. print '</table>';
  298. print "</div>";
  299. print '</form>';
  300. } else {
  301. print $db->error();
  302. }
  303. llxFooter();
  304. $db->close();