list.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. /* Copyright (C) 2017-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  5. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/bank/various_payment/list.php
  22. * \ingroup bank
  23. * \brief List of various payments
  24. */
  25. // Load Dolibarr environment
  26. require '../../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("compta", "banks", "bills", "accountancy"));
  35. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'directdebitcredittransferlist'; // To manage different context of search
  36. // Security check
  37. $socid = GETPOST("socid", "int");
  38. if ($user->socid) {
  39. $socid = $user->socid;
  40. }
  41. $optioncss = GETPOST('optioncss', 'alpha');
  42. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  43. $search_ref = GETPOST('search_ref', 'int');
  44. $search_user = GETPOST('search_user', 'alpha');
  45. $search_label = GETPOST('search_label', 'alpha');
  46. $search_datep_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
  47. $search_datep_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
  48. $search_datev_start = dol_mktime(0, 0, 0, GETPOST('search_date_value_startmonth', 'int'), GETPOST('search_date_value_startday', 'int'), GETPOST('search_date_value_startyear', 'int'));
  49. $search_datev_end = dol_mktime(23, 59, 59, GETPOST('search_date_value_endmonth', 'int'), GETPOST('search_date_value_endday', 'int'), GETPOST('search_date_value_endyear', 'int'));
  50. $search_amount_deb = GETPOST('search_amount_deb', 'alpha');
  51. $search_amount_cred = GETPOST('search_amount_cred', 'alpha');
  52. $search_bank_account = GETPOST('search_account', 'int');
  53. $search_bank_entry = GETPOST('search_bank_entry', 'int');
  54. $search_accountancy_account = GETPOST("search_accountancy_account");
  55. if ($search_accountancy_account == - 1) {
  56. $search_accountancy_account = '';
  57. }
  58. $search_accountancy_subledger = GETPOST("search_accountancy_subledger");
  59. if ($search_accountancy_subledger == - 1) {
  60. $search_accountancy_subledger = '';
  61. }
  62. if (empty($search_datep_start)) {
  63. $search_datep_start = GETPOST("search_datep_start", 'int');
  64. }
  65. if (empty($search_datep_end)) {
  66. $search_datep_end = GETPOST("search_datep_end", 'int');
  67. }
  68. if (empty($search_datev_start)) {
  69. $search_datev_start = GETPOST("search_datev_start", 'int');
  70. }
  71. if (empty($search_datev_end)) {
  72. $search_datev_end = GETPOST("search_datev_end", 'int');
  73. }
  74. $search_type_id = GETPOST('search_type_id', 'int');
  75. $sortfield = GETPOST('sortfield', 'aZ09comma');
  76. $sortorder = GETPOST('sortorder', 'aZ09comma');
  77. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  78. if (empty($page) || $page == -1) {
  79. $page = 0;
  80. } // If $page is not defined, or '' or -1
  81. $offset = $limit * $page;
  82. $pageprev = $page - 1;
  83. $pagenext = $page + 1;
  84. if (!$sortfield) {
  85. $sortfield = "v.datep,v.rowid";
  86. }
  87. if (!$sortorder) {
  88. $sortorder = "DESC,DESC";
  89. }
  90. $filtre = GETPOST("filtre", 'alpha');
  91. 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
  92. $search_ref = '';
  93. $search_label = '';
  94. $search_datep_start = '';
  95. $search_datep_end = '';
  96. $search_datev_start = '';
  97. $search_datev_end = '';
  98. $search_amount_deb = '';
  99. $search_amount_cred = '';
  100. $search_bank_account = '';
  101. $search_bank_entry = '';
  102. $search_accountancy_account = '';
  103. $search_accountancy_subledger = '';
  104. $search_type_id = '';
  105. }
  106. $search_all = GETPOSTISSET("search_all") ? trim(GETPOST("search_all", 'alpha')) : trim(GETPOST('sall'));
  107. /*
  108. * TODO: fill array "$fields" in "/compta/bank/class/paymentvarious.class.php" and use
  109. *
  110. *
  111. * $object = new PaymentVarious($db);
  112. *
  113. * $search = array();
  114. * foreach ($object->fields as $key => $val)
  115. * {
  116. * if (GETPOST('search_'.$key, 'alpha')) $search[$key] = GETPOST('search_'.$key, 'alpha');
  117. * }
  118. * $fieldstosearchall = array();
  119. * foreach ($object->fields as $key => $val)
  120. * {
  121. * if ($val['searchall']) $fieldstosearchall['t.'.$key] = $val['label'];
  122. * }
  123. *
  124. */
  125. // List of fields to search into when doing a "search in all"
  126. $fieldstosearchall = array(
  127. 'v.rowid'=>"Ref",
  128. 'v.label'=>"Label",
  129. 'v.datep'=>"DatePayment",
  130. 'v.datev'=>"DateValue",
  131. 'v.amount'=>$langs->trans("Debit").", ".$langs->trans("Credit"),
  132. );
  133. // Definition of fields for lists
  134. $arrayfields = array(
  135. 'ref' =>array('label'=>"Ref", 'checked'=>1, 'position'=>100),
  136. 'label' =>array('label'=>"Label", 'checked'=>1, 'position'=>110),
  137. 'datep' =>array('label'=>"DatePayment", 'checked'=>1, 'position'=>120),
  138. 'datev' =>array('label'=>"DateValue", 'checked'=>-1, 'position'=>130),
  139. 'type' =>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>140),
  140. 'project' =>array('label'=>"Project", 'checked'=>1, 'position'=>200, "enabled"=>isModEnabled('project')),
  141. 'bank' =>array('label'=>"BankAccount", 'checked'=>1, 'position'=>300, "enabled"=>isModEnabled("banque")),
  142. 'entry' =>array('label'=>"BankTransactionLine", 'checked'=>1, 'position'=>310, "enabled"=>isModEnabled("banque")),
  143. 'account' =>array('label'=>"AccountAccountingShort", 'checked'=>1, 'position'=>400, "enabled"=>isModEnabled('accounting')),
  144. 'subledger' =>array('label'=>"SubledgerAccount", 'checked'=>1, 'position'=>410, "enabled"=>isModEnabled('accounting')),
  145. 'debit' =>array('label'=>"Debit", 'checked'=>1, 'position'=>500),
  146. 'credit' =>array('label'=>"Credit", 'checked'=>1, 'position'=>510),
  147. );
  148. $arrayfields = dol_sort_array($arrayfields, 'position');
  149. $object = new PaymentVarious($db);
  150. $result = restrictedArea($user, 'banque', '', '', '');
  151. /*
  152. * Actions
  153. */
  154. $parameters = array();
  155. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  156. if ($reshook < 0) {
  157. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  158. }
  159. if (empty($reshook)) {
  160. // Selection of new fields
  161. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  162. }
  163. /*
  164. * View
  165. */
  166. $form = new Form($db);
  167. if ($arrayfields['account']['checked'] || $arrayfields['subledger']['checked']) {
  168. $formaccounting = new FormAccounting($db);
  169. }
  170. if ($arrayfields['bank']['checked'] && isModEnabled('accounting')) {
  171. $accountingjournal = new AccountingJournal($db);
  172. }
  173. if ($arrayfields['ref']['checked']) {
  174. $variousstatic = new PaymentVarious($db);
  175. }
  176. if ($arrayfields['bank']['checked']) {
  177. $accountstatic = new Account($db);
  178. }
  179. if ($arrayfields['project']['checked']) {
  180. $proj = new Project($db);
  181. }
  182. if ($arrayfields['entry']['checked']) {
  183. $bankline = new AccountLine($db);
  184. }
  185. if ($arrayfields['account']['checked']) {
  186. $accountingaccount = new AccountingAccount($db);
  187. }
  188. $sql = "SELECT v.rowid, v.sens, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank, v.accountancy_code, v.subledger_account, v.fk_projet as fk_project,";
  189. $sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
  190. $sql .= " pst.code as payment_code";
  191. $sqlfields = $sql; // $sql fields to remove for count total
  192. $sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
  193. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
  194. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
  195. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  196. $sql .= " WHERE v.entity IN (".getEntity('payment_various').")";
  197. // Search criteria
  198. if ($search_ref) {
  199. $sql .= " AND v.rowid = ".((int) $search_ref);
  200. }
  201. if ($search_label) {
  202. $sql .= natural_search(array('v.label'), $search_label);
  203. }
  204. if ($search_datep_start) {
  205. $sql .= " AND v.datep >= '".$db->idate($search_datep_start)."'";
  206. }
  207. if ($search_datep_end) {
  208. $sql .= " AND v.datep <= '".$db->idate($search_datep_end)."'";
  209. }
  210. if ($search_datev_start) {
  211. $sql .= " AND v.datev >= '".$db->idate($search_datev_start)."'";
  212. }
  213. if ($search_datev_end) {
  214. $sql .= " AND v.datev <= '".$db->idate($search_datev_end)."'";
  215. }
  216. if ($search_amount_deb) {
  217. $sql .= natural_search("v.amount", $search_amount_deb, 1);
  218. }
  219. if ($search_amount_cred) {
  220. $sql .= natural_search("v.amount", $search_amount_cred, 1);
  221. }
  222. if ($search_bank_account > 0) {
  223. $sql .= " AND b.fk_account = ".((int) $search_bank_account);
  224. }
  225. if ($search_bank_entry > 0) {
  226. $sql .= " AND b.fk_account = ".((int) $search_bank_account);
  227. }
  228. if ($search_accountancy_account > 0) {
  229. $sql .= " AND v.accountancy_code = ".((int) $search_accountancy_account);
  230. }
  231. if ($search_accountancy_subledger > 0) {
  232. $sql .= " AND v.subledger_account = ".((int) $search_accountancy_subledger);
  233. }
  234. if ($search_type_id > 0) {
  235. $sql .= " AND v.fk_typepayment=".((int) $search_type_id);
  236. }
  237. if ($search_all) {
  238. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  239. }
  240. // Count total nb of records
  241. $nbtotalofrecords = '';
  242. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  243. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  244. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  245. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  246. $resql = $db->query($sqlforcount);
  247. if ($resql) {
  248. $objforcount = $db->fetch_object($resql);
  249. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  250. } else {
  251. dol_print_error($db);
  252. }
  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. $db->free($resql);
  258. }
  259. // Complete request and execute it with limit
  260. $sql .= $db->order($sortfield, $sortorder);
  261. if ($limit) {
  262. $sql .= $db->plimit($limit + 1, $offset);
  263. }
  264. $resql = $db->query($sql);
  265. if ($resql) {
  266. $num = $db->num_rows($resql);
  267. // Direct jump if only one record found
  268. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) {
  269. $obj = $db->fetch_object($resql);
  270. $id = $obj->rowid;
  271. header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/card.php?id='.$id);
  272. exit;
  273. }
  274. // must be place behind the last "header(...)" call
  275. llxHeader('', $langs->trans("VariousPayments"));
  276. $i = 0;
  277. $total = 0;
  278. $param = '';
  279. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  280. $param .= '&contextpage='.urlencode($contextpage);
  281. }
  282. if ($limit > 0 && $limit != $conf->liste_limit) {
  283. $param .= '&limit='.urlencode($limit);
  284. }
  285. if ($search_ref) {
  286. $param .= '&search_ref='.urlencode($search_ref);
  287. }
  288. if ($search_label) {
  289. $param .= '&search_label='.urlencode($search_label);
  290. }
  291. if ($search_datep_start) {
  292. $param .= '&search_datep_start='.urlencode($search_datep_start);
  293. }
  294. if ($search_datep_end) {
  295. $param .= '&search_datep_end='.urlencode($search_datep_end);
  296. }
  297. if ($search_datev_start) {
  298. $param .= '&search_datev_start='.urlencode($search_datev_start);
  299. }
  300. if ($search_datev_end) {
  301. $param .= '&search_datev_end='.urlencode($search_datev_end);
  302. }
  303. if ($search_type_id > 0) {
  304. $param .= '&search_type_id='.urlencode($search_type_id);
  305. }
  306. if ($search_amount_deb) {
  307. $param .= '&search_amount_deb='.urlencode($search_amount_deb);
  308. }
  309. if ($search_amount_cred) {
  310. $param .= '&search_amount_cred='.urlencode($search_amount_cred);
  311. }
  312. if ($search_bank_account > 0) {
  313. $param .= '&search_account='.urlencode($search_bank_account);
  314. }
  315. if ($search_accountancy_account > 0) {
  316. $param .= '&search_accountancy_account='.urlencode($search_accountancy_account);
  317. }
  318. if ($search_accountancy_subledger > 0) {
  319. $param .= '&search_accountancy_subledger='.urlencode($search_accountancy_subledger);
  320. }
  321. if ($optioncss != '') {
  322. $param .= '&optioncss='.urlencode($optioncss);
  323. }
  324. $url = DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create';
  325. if (!empty($socid)) {
  326. $url .= '&socid='.urlencode($socid);
  327. }
  328. $newcardbutton = dolGetButtonTitle($langs->trans('MenuNewVariousPayment'), '', 'fa fa-plus-circle', $url, '', $user->rights->banque->modifier);
  329. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  330. if ($optioncss != '') {
  331. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  332. }
  333. print '<input type="hidden" name="token" value="'.newToken().'">';
  334. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  335. print '<input type="hidden" name="action" value="list">';
  336. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  337. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  338. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  339. print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
  340. if ($search_all) {
  341. foreach ($fieldstosearchall as $key => $val) {
  342. $fieldstosearchall[$key] = $langs->trans($val);
  343. }
  344. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  345. }
  346. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  347. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  348. $moreforfilter= '';
  349. print '<div class="div-table-responsive">';
  350. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
  351. print '<tr class="liste_titre">';
  352. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  353. print '<td class="liste_titre">';
  354. print '</td>';
  355. }
  356. // Ref
  357. if ($arrayfields['ref']['checked']) {
  358. print '<td class="liste_titre left">';
  359. print '<input class="flat" type="text" size="3" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  360. print '</td>';
  361. }
  362. // Label
  363. if ($arrayfields['label']['checked']) {
  364. print '<td class="liste_titre">';
  365. print '<input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  366. print '</td>';
  367. }
  368. // Payment date
  369. if ($arrayfields['datep']['checked']) {
  370. print '<td class="liste_titre center">';
  371. print '<div class="nowrap">';
  372. print $form->selectDate($search_datep_start ? $search_datep_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  373. print '</div>';
  374. print '<div class="nowrap">';
  375. print $form->selectDate($search_datep_end ? $search_datep_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  376. print '</div>';
  377. print '</td>';
  378. }
  379. // Value date
  380. if ($arrayfields['datev']['checked']) {
  381. print '<td class="liste_titre center">';
  382. print '<div class="nowrap">';
  383. print $form->selectDate($search_datev_start ? $search_datev_start : -1, 'search_date_value_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  384. print '</div>';
  385. print '<div class="nowrap">';
  386. print $form->selectDate($search_datev_end ? $search_datev_end : -1, 'search_date_value_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  387. print '</div>';
  388. print '</td>';
  389. }
  390. // Payment type
  391. if ($arrayfields['type']['checked']) {
  392. print '<td class="liste_titre center">';
  393. print $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16, 1, 'maxwidth100', 1);
  394. print '</td>';
  395. }
  396. // Project
  397. if ($arrayfields['project']['checked']) {
  398. print '<td class="liste_titre">';
  399. // TODO
  400. print '</td>';
  401. }
  402. // Bank account
  403. if ($arrayfields['bank']['checked']) {
  404. print '<td class="liste_titre">';
  405. $form->select_comptes($search_bank_account, 'search_account', 0, '', 1, '', 0, 'maxwidth100');
  406. print '</td>';
  407. }
  408. // Bank entry
  409. if ($arrayfields['entry']['checked']) {
  410. print '<td class="liste_titre left">';
  411. print '<input name="search_bank_entry" class="flat maxwidth50" type="text" value="'.dol_escape_htmltag($search_bank_entry).'">';
  412. print '</td>';
  413. }
  414. // Accounting account
  415. if ($arrayfields['account']['checked']) {
  416. print '<td class="liste_titre">';
  417. print '<div class="nowrap">';
  418. print $formaccounting->select_account($search_accountancy_account, 'search_accountancy_account', 1, array(), 1, 1, 'maxwidth200');
  419. print '</div>';
  420. print '</td>';
  421. }
  422. // Subledger account
  423. if ($arrayfields['subledger']['checked']) {
  424. print '<td class="liste_titre">';
  425. print '<div class="nowrap">';
  426. print $formaccounting->select_auxaccount($search_accountancy_subledger, 'search_accountancy_subledger', 1, 'maxwidth200');
  427. print '</div>';
  428. print '</td>';
  429. }
  430. // Debit
  431. if ($arrayfields['debit']['checked']) {
  432. print '<td class="liste_titre right">';
  433. print '<input name="search_amount_deb" class="flat maxwidth50" type="text" value="'.dol_escape_htmltag($search_amount_deb).'">';
  434. print '</td>';
  435. }
  436. // Credit
  437. if ($arrayfields['credit']['checked']) {
  438. print '<td class="liste_titre right">';
  439. print '<input name="search_amount_cred" class="flat maxwidth50" type="text" size="8" value="'.dol_escape_htmltag($search_amount_cred).'">';
  440. print '</td>';
  441. }
  442. print '<td class="liste_titre maxwidthsearch">';
  443. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  444. print $searchpicto;
  445. print '</td>';
  446. print '</tr>';
  447. print '<tr class="liste_titre">';
  448. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  449. print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  450. }
  451. if ($arrayfields['ref']['checked']) {
  452. print_liste_field_titre($arrayfields['ref']['label'], $_SERVER["PHP_SELF"], 'v.rowid', '', $param, '', $sortfield, $sortorder);
  453. }
  454. if ($arrayfields['label']['checked']) {
  455. print_liste_field_titre($arrayfields['label']['label'], $_SERVER["PHP_SELF"], 'v.label', '', $param, '', $sortfield, $sortorder);
  456. }
  457. if ($arrayfields['datep']['checked']) {
  458. print_liste_field_titre($arrayfields['datep']['label'], $_SERVER["PHP_SELF"], 'v.datep,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  459. }
  460. if ($arrayfields['datev']['checked']) {
  461. print_liste_field_titre($arrayfields['datev']['label'], $_SERVER["PHP_SELF"], 'v.datev,v.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  462. }
  463. if ($arrayfields['type']['checked']) {
  464. print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], 'type', '', $param, '', $sortfield, $sortorder, 'center ');
  465. }
  466. if ($arrayfields['project']['checked']) {
  467. print_liste_field_titre($arrayfields['project']['label'], $_SERVER["PHP_SELF"], 'fk_project', '', $param, '', $sortfield, $sortorder);
  468. }
  469. if ($arrayfields['bank']['checked']) {
  470. print_liste_field_titre($arrayfields['bank']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
  471. }
  472. if ($arrayfields['entry']['checked']) {
  473. print_liste_field_titre($arrayfields['entry']['label'], $_SERVER["PHP_SELF"], 'ba.label', '', $param, '', $sortfield, $sortorder);
  474. }
  475. if ($arrayfields['account']['checked']) {
  476. print_liste_field_titre($arrayfields['account']['label'], $_SERVER["PHP_SELF"], 'v.accountancy_code', '', $param, '', $sortfield, $sortorder, 'left ');
  477. }
  478. if ($arrayfields['subledger']['checked']) {
  479. print_liste_field_titre($arrayfields['subledger']['label'], $_SERVER["PHP_SELF"], 'v.subledger_account', '', $param, '', $sortfield, $sortorder, 'left ');
  480. }
  481. if ($arrayfields['debit']['checked']) {
  482. print_liste_field_titre($arrayfields['debit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
  483. }
  484. if ($arrayfields['credit']['checked']) {
  485. print_liste_field_titre($arrayfields['credit']['label'], $_SERVER["PHP_SELF"], 'v.amount', '', $param, '', $sortfield, $sortorder, 'right ');
  486. }
  487. // Fields from hook
  488. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  489. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  490. print $hookmanager->resPrint;
  491. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ');
  492. print '</tr>';
  493. $totalarray = array();
  494. $totalarray['nbfield'] = 0;
  495. $totalarray['val']['total_cred'] = 0;
  496. $totalarray['val']['total_deb'] = 0;
  497. while ($i < min($num, $limit)) {
  498. $obj = $db->fetch_object($resql);
  499. $variousstatic->id = $obj->rowid;
  500. $variousstatic->ref = $obj->rowid;
  501. $variousstatic->label = $obj->label;
  502. print '<tr class="oddeven">';
  503. // No
  504. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  505. print '<td>'.(($offset * $limit) + $i).'</td>';
  506. }
  507. // Ref
  508. if ($arrayfields['ref']['checked']) {
  509. print '<td>'.$variousstatic->getNomUrl(1)."</td>";
  510. if (!$i) {
  511. $totalarray['nbfield']++;
  512. }
  513. }
  514. // Label payment
  515. if ($arrayfields['label']['checked']) {
  516. print '<td class="tdoverflowmax150" title="'.$variousstatic->label.'">'.$variousstatic->label."</td>";
  517. if (!$i) {
  518. $totalarray['nbfield']++;
  519. }
  520. }
  521. // Date payment
  522. if ($arrayfields['datep']['checked']) {
  523. print '<td class="center">'.dol_print_date($obj->datep, 'day')."</td>";
  524. if (!$i) {
  525. $totalarray['nbfield']++;
  526. }
  527. }
  528. // Date value
  529. if ($arrayfields['datev']['checked']) {
  530. print '<td class="center">'.dol_print_date($obj->datev, 'day')."</td>";
  531. if (!$i) {
  532. $totalarray['nbfield']++;
  533. }
  534. }
  535. // Type
  536. if ($arrayfields['type']['checked']) {
  537. print '<td class="center">';
  538. if ($obj->payment_code) {
  539. print $langs->trans("PaymentTypeShort".$obj->payment_code);
  540. print ' ';
  541. }
  542. print $obj->num_payment;
  543. print '</td>';
  544. if (!$i) {
  545. $totalarray['nbfield']++;
  546. }
  547. }
  548. // Project
  549. if ($arrayfields['project']['checked']) {
  550. print '<td class="nowraponall">';
  551. if ($obj->fk_project > 0) {
  552. $proj->fetch($obj->fk_project);
  553. print $proj->getNomUrl(1);
  554. }
  555. print '</td>';
  556. if (!$i) {
  557. $totalarray['nbfield']++;
  558. }
  559. }
  560. // Bank account
  561. if ($arrayfields['bank']['checked']) {
  562. print '<td class="nowraponall">';
  563. if ($obj->bid > 0) {
  564. $accountstatic->id = $obj->bid;
  565. $accountstatic->ref = $obj->bref;
  566. $accountstatic->number = $obj->bnumber;
  567. if (isModEnabled('accounting')) {
  568. $accountstatic->account_number = $obj->bank_account_number;
  569. $accountingjournal->fetch($obj->accountancy_journal);
  570. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  571. }
  572. $accountstatic->label = $obj->blabel;
  573. print $accountstatic->getNomUrl(1);
  574. } else {
  575. print '&nbsp;';
  576. }
  577. print '</td>';
  578. if (!$i) {
  579. $totalarray['nbfield']++;
  580. }
  581. }
  582. // Bank entry
  583. if ($arrayfields['entry']['checked']) {
  584. $bankline->fetch($obj->fk_bank);
  585. print '<td>'.$bankline->getNomUrl(1).'</td>';
  586. if (!$i) {
  587. $totalarray['nbfield']++;
  588. }
  589. }
  590. // Accounting account
  591. if ($arrayfields['account']['checked']) {
  592. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  593. $accountingaccount->fetch('', $obj->accountancy_code, 1);
  594. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->accountancy_code.' '.$accountingaccount->label).'">'.$accountingaccount->getNomUrl(0, 1, 1, '', 1).'</td>';
  595. if (!$i) {
  596. $totalarray['nbfield']++;
  597. }
  598. }
  599. // Accounting subledger account
  600. if ($arrayfields['subledger']['checked']) {
  601. print '<td class="tdoverflowmax150">'.length_accounta($obj->subledger_account).'</td>';
  602. if (!$i) {
  603. $totalarray['nbfield']++;
  604. }
  605. }
  606. // Debit
  607. if ($arrayfields['debit']['checked']) {
  608. print '<td class="nowrap right">';
  609. if ($obj->sens == 0) {
  610. print '<span class="amount">'.price($obj->amount).'</span>';
  611. $totalarray['val']['total_deb'] += $obj->amount;
  612. }
  613. if (!$i) {
  614. $totalarray['nbfield']++;
  615. }
  616. if (!$i) {
  617. $totalarray['pos'][$totalarray['nbfield']] = 'total_deb';
  618. }
  619. print '</td>';
  620. }
  621. // Credit
  622. if ($arrayfields['credit']['checked']) {
  623. print '<td class="nowrap right">';
  624. if ($obj->sens == 1) {
  625. print '<span class="amount">'.price($obj->amount).'</span>';
  626. $totalarray['val']['total_cred'] += $obj->amount;
  627. }
  628. if (!$i) {
  629. $totalarray['nbfield']++;
  630. }
  631. if (!$i) {
  632. $totalarray['pos'][$totalarray['nbfield']] = 'total_cred';
  633. }
  634. print '</td>';
  635. }
  636. print '<td></td>';
  637. if (!$i) {
  638. $totalarray['nbfield']++;
  639. }
  640. print '</tr>'."\n";
  641. $i++;
  642. }
  643. // Show total line
  644. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  645. // If no record found
  646. if ($num == 0) {
  647. $colspan = 1;
  648. foreach ($arrayfields as $key => $val) {
  649. if (!empty($val['checked'])) {
  650. $colspan++;
  651. }
  652. }
  653. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  654. }
  655. $db->free($resql);
  656. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  657. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  658. print $hookmanager->resPrint;
  659. print '</table>'."\n";
  660. print '</div>'."\n";
  661. print '</form>'."\n";
  662. } else {
  663. dol_print_error($db);
  664. }
  665. // End of page
  666. llxFooter();
  667. $db->close();