payments.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. <?php
  2. /* Copyright (C) 2011-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2015-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  5. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  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/salaries/list.php
  22. * \ingroup salaries
  23. * \brief List of salaries payments
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. if (isModEnabled('accounting')) {
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("compta", "salaries", "bills", "hrm"));
  34. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  35. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  36. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  37. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  38. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  39. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  40. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomlist'; // To manage different context of search
  41. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  42. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (!$sortfield) {
  53. $sortfield = "s.datep,s.rowid";
  54. }
  55. if (!$sortorder) {
  56. $sortorder = "DESC,DESC";
  57. }
  58. // Initialize technical objects
  59. $object = new PaymentSalary($db);
  60. $extrafields = new ExtraFields($db);
  61. $diroutputmassaction = $conf->user->dir_output.'/temp/massgeneration/'.$user->id;
  62. $hookmanager->initHooks(array('salarieslist')); // Note that conf->hooks_modules contains array
  63. // Fetch optionals attributes and labels
  64. $extrafields->fetch_name_optionals_label($object->table_element);
  65. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  66. if (!$sortfield) {
  67. $sortfield = "s.datep,s.rowid";
  68. }
  69. if (!$sortorder) {
  70. $sortorder = "DESC,DESC";
  71. }
  72. $search_ref = GETPOST('search_ref', 'int');
  73. $search_ref_salary = GETPOST('search_ref_salary', 'int');
  74. $search_user = GETPOST('search_user', 'alpha');
  75. $search_label = GETPOST('search_label', 'alpha');
  76. $search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int'));
  77. $search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int'));
  78. $search_dateep_start = dol_mktime(0, 0, 0, GETPOST('search_dateep_startmonth', 'int'), GETPOST('search_dateep_startday', 'int'), GETPOST('search_dateep_startyear', 'int'));
  79. $search_dateep_end = dol_mktime(23, 59, 59, GETPOST('search_dateep_endmonth', 'int'), GETPOST('search_dateep_endday', 'int'), GETPOST('search_dateep_endyear', 'int'));
  80. $search_amount = GETPOST('search_amount', 'alpha');
  81. $search_account = GETPOST('search_account', 'int');
  82. $search_fk_bank = GETPOST('search_fk_bank', 'int');
  83. $search_chq_number = GETPOST('search_chq_number', 'int');
  84. $filtre = GETPOST("filtre", 'restricthtml');
  85. if (!GETPOST('search_type_id', 'int')) {
  86. $newfiltre = str_replace('filtre=', '', $filtre);
  87. $filterarray = explode('-', $newfiltre);
  88. foreach ($filterarray as $val) {
  89. $part = explode(':', $val);
  90. if ($part[0] == 's.fk_typepayment') {
  91. $search_type_id = $part[1];
  92. }
  93. }
  94. } else {
  95. $search_type_id = GETPOST('search_type_id', 'int');
  96. }
  97. $childids = $user->getAllChildIds(1);
  98. // Initialize array of search criterias
  99. $search_all = GETPOST("search_all", 'alpha');
  100. $search = array();
  101. foreach ($object->fields as $key => $val) {
  102. if (GETPOST('search_'.$key, 'alpha') !== '') $search[$key] = GETPOST('search_'.$key, 'alpha');
  103. }
  104. // List of fields to search into when doing a "search in all"
  105. $fieldstosearchall = array();
  106. foreach ($object->fields as $key => $val) {
  107. if (!empty($val['searchall'])) {
  108. $fieldstosearchall['t.'.$key] = $val['label'];
  109. }
  110. }
  111. // Definition of array of fields for columns
  112. $arrayfields = array();
  113. foreach ($object->fields as $key => $val) {
  114. // If $val['visible']==0, then we never show the field
  115. if (!empty($val['visible'])) {
  116. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  117. $arrayfields['t.'.$key] = array(
  118. 'label'=>$val['label'],
  119. 'checked'=>(($visible < 0) ? 0 : 1),
  120. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  121. 'position'=>$val['position'],
  122. 'help'=> isset($val['help']) ? $val['help'] : ''
  123. );
  124. }
  125. }
  126. $permissiontoread = $user->rights->salaries->read;
  127. $permissiontoadd = $user->rights->salaries->write;
  128. $permissiontodelete = $user->rights->salaries->delete;
  129. // Security check
  130. $socid = GETPOST("socid", "int");
  131. if ($user->socid > 0) {
  132. $socid = $user->socid;
  133. }
  134. restrictedArea($user, 'salaries', 0, 'salary', '');
  135. /*
  136. * Actions
  137. */
  138. if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
  139. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
  140. $parameters = array();
  141. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  142. if ($reshook < 0) {
  143. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  144. }
  145. if (empty($reshook)) {
  146. // Selection of new fields
  147. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  148. // Purge search criteria
  149. 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
  150. $search_ref = "";
  151. $search_ref_salary = "";
  152. $search_user = "";
  153. $search_label = "";
  154. $search_date_start = '';
  155. $search_date_end = '';
  156. $search_dateep_start = '';
  157. $search_dateep_end = '';
  158. $search_amount = "";
  159. $search_account = '';
  160. $search_fk_bank = '';
  161. $search_chq_number = '';
  162. $search_type_id = "";
  163. }
  164. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  165. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  166. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  167. }
  168. // Mass actions
  169. $objectclass = 'PaymentSalary';
  170. $objectlabel = 'SalariesPayments';
  171. $uploaddir = $conf->salaries->dir_output;
  172. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  173. // Validate records
  174. if (!$error && $massaction == 'buildsepa' && $permissiontoadd) {
  175. $objecttmp = new $objectclass($db);
  176. // TODO
  177. }
  178. }
  179. /*
  180. * View
  181. */
  182. $form = new Form($db);
  183. $salstatic = new Salary($db);
  184. $paymentsalstatic = new PaymentSalary($db);
  185. $userstatic = new User($db);
  186. $accountstatic = new Account($db);
  187. $accountlinestatic = new AccountLine($db);
  188. $now = dol_now();
  189. //$help_url="EN:Module_BillOfMaterials|FR:Module_BillOfMaterials_FR|ES:Módulo_BillOfMaterials";
  190. $help_url = '';
  191. $title = $langs->trans('SalariesPayments');
  192. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.admin, u.salary as current_salary, u.fk_soc as fk_soc, u.statut as status,";
  193. $sql .= " s.rowid, s.fk_user, s.amount, s.salary, sal.rowid as id_salary, sal.label, s.datep as datep, sal.dateep, b.datev as datev, s.fk_typepayment as type, s.num_payment, s.fk_bank,";
  194. $sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,";
  195. $sql .= " pst.code as payment_code";
  196. $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
  197. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as sal ON (sal.rowid = s.fk_salary)";
  198. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON s.fk_typepayment = pst.id";
  199. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
  200. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid,";
  201. $sql .= " ".MAIN_DB_PREFIX."user as u";
  202. $sql .= " WHERE u.rowid = sal.fk_user";
  203. $sql .= " AND s.entity IN (".getEntity('payment_salaries').")";
  204. if (empty($user->rights->salaries->readall)) {
  205. $sql .= " AND sal.fk_user IN (".$db->sanitize(join(',', $childids)).")";
  206. }
  207. // Search criteria
  208. if ($search_ref) {
  209. $sql .= " AND s.rowid=".((int) $search_ref);
  210. }
  211. if ($search_ref_salary) {
  212. $sql .= " AND sal.rowid=".((int) $search_ref_salary);
  213. }
  214. if ($search_user) {
  215. $sql .= natural_search(array('u.login', 'u.lastname', 'u.firstname', 'u.email'), $search_user);
  216. }
  217. if ($search_label) {
  218. $sql .= natural_search(array('sal.label'), $search_label);
  219. }
  220. if ($search_date_start) {
  221. $sql .= " AND s.datep >= '".$db->idate($search_date_start)."'";
  222. }
  223. if ($search_date_end) {
  224. $sql .= " AND s.datep <= '".$db->idate($search_date_end)."'";
  225. }
  226. if ($search_dateep_start) {
  227. $sql .= " AND sal.dateep >= '".$db->idate($search_dateep_start)."'";
  228. }
  229. if ($search_dateep_end) {
  230. $sql .= " AND sal.dateep <= '".$db->idate($search_dateep_end)."'";
  231. }
  232. if ($search_amount) {
  233. $sql .= natural_search("s.amount", $search_amount, 1);
  234. }
  235. if ($search_account > 0) {
  236. $sql .= " AND b.fk_account=".((int) $search_account);
  237. }
  238. if ($search_fk_bank) {
  239. $sql .= " AND s.fk_bank=".((int) $search_fk_bank);
  240. }
  241. if ($search_chq_number) {
  242. $sql .= natural_search(array('s.num_payment'), $search_chq_number);
  243. }
  244. if ($search_type_id > 0) {
  245. $sql .= " AND s.fk_typepayment=".((int) $search_type_id);
  246. }
  247. $sql .= $db->order($sortfield, $sortorder);
  248. // Count total nb of records
  249. $nbtotalofrecords = '';
  250. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  251. $resql = $db->query($sql);
  252. $nbtotalofrecords = $db->num_rows($resql);
  253. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  254. $page = 0;
  255. $offset = 0;
  256. }
  257. }
  258. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  259. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  260. $num = $nbtotalofrecords;
  261. } else {
  262. if ($limit) {
  263. $sql .= $db->plimit($limit + 1, $offset);
  264. }
  265. $resql = $db->query($sql);
  266. if (!$resql) {
  267. dol_print_error($db);
  268. exit;
  269. }
  270. $num = $db->num_rows($resql);
  271. }
  272. // Output page
  273. // --------------------------------------------------------------------
  274. llxHeader('', $title, $help_url);
  275. $arrayofselected = is_array($toselect) ? $toselect : array();
  276. $param = '';
  277. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  278. $param .= '&contextpage='.urlencode($contextpage);
  279. }
  280. if ($limit > 0 && $limit != $conf->liste_limit) {
  281. $param .= '&limit='.urlencode($limit);
  282. }
  283. if ($search_type_id) {
  284. $param .= '&search_type_id='.urlencode($search_type_id);
  285. }
  286. if ($optioncss != '') {
  287. $param .= '&optioncss='.urlencode($optioncss);
  288. }
  289. if ($search_ref) {
  290. $param .= '&search_ref='.urlencode($search_ref);
  291. }
  292. if ($search_ref_salary) {
  293. $param .= '&search_ref_salary='.urlencode($search_ref_salary);
  294. }
  295. if ($search_user) {
  296. $param .= '&search_user='.urlencode($search_user);
  297. }
  298. if ($search_label) {
  299. $param .= '&search_label='.urlencode($search_label);
  300. }
  301. if ($search_fk_bank) {
  302. $param .= '&search_fk_bank='.urlencode($search_fk_bank);
  303. }
  304. if ($search_chq_number) {
  305. $param .= '&search_chq_number='.urlencode($search_chq_number);
  306. }
  307. if ($search_account) {
  308. $param .= '&search_account='.urlencode($search_account);
  309. }
  310. if ($search_date_start) {
  311. $param .= '&search_date_startday='.urlencode(GETPOST('search_date_startday', 'int')).'&search_date_startmonth='.urlencode(GETPOST('search_date_startmonth', 'int')).'&search_date_startyear='.urlencode(GETPOST('search_date_startyear', 'int'));
  312. }
  313. if ($search_dateep_start) {
  314. $param .= '&search_dateep_startday='.urlencode(GETPOST('search_dateep_startday', 'int')).'&search_dateep_startmonth='.urlencode(GETPOST('search_dateep_startmonth', 'int')).'&search_dateep_startyear='.urlencode(GETPOST('search_dateep_startyear', 'int'));
  315. }
  316. if ($search_date_end) {
  317. $param .= '&search_date_endday='.urlencode(GETPOST('search_date_endday', 'int')).'&search_date_endmonth='.urlencode(GETPOST('search_date_endmonth', 'int')).'&search_date_endyear='.urlencode(GETPOST('search_date_endyear', 'int'));
  318. }
  319. if ($search_dateep_end) {
  320. $param .= '&search_dateep_endday='.urlencode(GETPOST('search_dateep_endday', 'int')).'&search_dateep_endmonth='.urlencode(GETPOST('search_dateep_endmonth', 'int')).'&search_dateep_endyear='.urlencode(GETPOST('search_dateep_endyear', 'int'));
  321. }
  322. // Add $param from extra fields
  323. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  324. // List of mass actions available
  325. $arrayofmassactions = array(
  326. //'presend'=>$langs->trans("SendByMail"),
  327. //'buildsepa'=>$langs->trans("BuildSepa"), // TODO
  328. );
  329. //if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  330. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  331. $arrayofmassactions = array();
  332. }
  333. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  334. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  335. if ($optioncss != '') {
  336. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  337. }
  338. print '<input type="hidden" name="token" value="'.newToken().'">';
  339. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  340. print '<input type="hidden" name="action" value="list">';
  341. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  342. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  343. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  344. $url = DOL_URL_ROOT.'/salaries/card.php?action=create';
  345. if (!empty($socid)) {
  346. $url .= '&socid='.$socid;
  347. }
  348. $newcardbutton = dolGetButtonTitle($langs->trans('NewSalaryPayment'), '', 'fa fa-plus-circle', $url, '', $user->rights->salaries->write);
  349. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
  350. $moreforfilter = '';
  351. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  352. //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  353. $selectedfields = '';
  354. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  355. print '<div class="div-table-responsive">';
  356. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  357. // Fields title search
  358. // --------------------------------------------------------------------
  359. print '<tr class="liste_titre_filter">';
  360. // Ref
  361. print '<td class="liste_titre left">';
  362. print '<input class="flat" type="text" size="3" name="search_ref" value="'.$db->escape($search_ref).'">';
  363. print '</td>';
  364. // Salary
  365. print '<td class="liste_titre center">';
  366. print '<input class="flat" type="text" size="3" name="search_ref_salary" value="'.$db->escape($search_ref_salary).'">';
  367. print '</td>';
  368. // Label
  369. print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$db->escape($search_label).'"></td>';
  370. // Date end period
  371. print '<td class="liste_titre center">';
  372. print '<div class="nowrap">';
  373. print $form->selectDate($search_dateep_start ? $search_dateep_start : -1, 'search_dateep_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  374. print '</div>';
  375. print '<div class="nowrap">';
  376. print $form->selectDate($search_dateep_end ? $search_dateep_end : -1, 'search_dateep_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  377. print '</div>';
  378. print '</td>';
  379. // Date payment
  380. print '<td class="liste_titre center">';
  381. print '<div class="nowrap">';
  382. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  383. print '</div>';
  384. print '<div class="nowrap">';
  385. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  386. print '</div>';
  387. print '</td>';
  388. // Date value
  389. /*print '<td class="liste_titre center">';
  390. print '</td>';*/
  391. // Employee
  392. print '<td class="liste_titre">';
  393. print '<input class="flat" type="text" size="6" name="search_user" value="'.$db->escape($search_user).'">';
  394. print '</td>';
  395. // Type
  396. print '<td class="liste_titre left">';
  397. $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16);
  398. print '</td>';
  399. // Chq number
  400. print '<td class="liste_titre right"><input name="search_chq_number" class="flat" type="text" size="8" value="'.$db->escape($search_chq_number).'"></td>';
  401. if (isModEnabled('banque')) {
  402. // Bank transaction
  403. print '<td class="liste_titre center">';
  404. print '<input class="flat" type="text" size="3" name="search_fk_bank" value="'.$db->escape($search_fk_bank).'">';
  405. print '</td>';
  406. // Account
  407. print '<td class="liste_titre">';
  408. $form->select_comptes($search_account, 'search_account', 0, '', 1);
  409. print '</td>';
  410. }
  411. // Amount
  412. print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$db->escape($search_amount).'"></td>';
  413. // Extra fields
  414. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  415. // Fields from hook
  416. $parameters = array('arrayfields'=>$arrayfields);
  417. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  418. print $hookmanager->resPrint;
  419. // Action column
  420. print '<td class="liste_titre maxwidthsearch">';
  421. $searchpicto = $form->showFilterButtons();
  422. print $searchpicto;
  423. print '</td>';
  424. print '</tr>'."\n";
  425. // Fields title label
  426. // --------------------------------------------------------------------
  427. print '<tr class="liste_titre">';
  428. print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, "", $sortfield, $sortorder);
  429. print_liste_field_titre("Salary", $_SERVER["PHP_SELF"], "sal.rowid", "", $param, '', $sortfield, $sortorder);
  430. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, 'class="left"', $sortfield, $sortorder);
  431. print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "sal.dateep", "", $param, '', $sortfield, $sortorder, 'center ');
  432. print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep,s.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  433. //print_liste_field_titre("DateValue", $_SERVER["PHP_SELF"], "b.datev,s.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  434. print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder);
  435. print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pst.code", "", $param, 'class="left"', $sortfield, $sortorder);
  436. print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "s.num_payment", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
  437. if (isModEnabled('banque')) {
  438. print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "s.fk_bank", "", $param, '', $sortfield, $sortorder);
  439. print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
  440. }
  441. print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder);
  442. // Extra fields
  443. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  444. // Hook fields
  445. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  446. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  447. print $hookmanager->resPrint;
  448. // Action column
  449. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  450. print '</tr>'."\n";
  451. // Detect if we need a fetch on each output line
  452. $needToFetchEachLine = 0;
  453. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  454. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  455. if (preg_match('/\$object/', $val)) {
  456. $needToFetchEachLine++;
  457. }
  458. // There is at least one compute field that use $object
  459. }
  460. }
  461. // Loop on record
  462. // --------------------------------------------------------------------
  463. $i = 0;
  464. $total = 0;
  465. $totalarray = array();
  466. while ($i < ($limit ? min($num, $limit) : $num)) {
  467. $obj = $db->fetch_object($resql);
  468. if (empty($obj)) {
  469. break;
  470. }
  471. // Should not happen
  472. // Store properties in $object
  473. $object->setVarsFromFetchObj($obj);
  474. // Show here line of result
  475. print '<tr class="oddeven">';
  476. $userstatic->id = $obj->uid;
  477. $userstatic->lastname = $obj->lastname;
  478. $userstatic->firstname = $obj->firstname;
  479. $userstatic->admin = $obj->admin;
  480. $userstatic->login = $obj->login;
  481. $userstatic->email = $obj->email;
  482. $userstatic->socid = $obj->fk_soc;
  483. $userstatic->statut = $obj->status;
  484. $salstatic->id = $obj->id_salary;
  485. $salstatic->ref = $obj->id_salary;
  486. $paymentsalstatic->id = $obj->rowid;
  487. $paymentsalstatic->ref = $obj->rowid;
  488. // Ref
  489. print "<td>".$paymentsalstatic->getNomUrl(1)."</td>\n";
  490. if (!$i) {
  491. $totalarray['nbfield']++;
  492. }
  493. // Ref salary
  494. print "<td>".$salstatic->getNomUrl(1)."</td>\n";
  495. if (!$i) {
  496. $totalarray['nbfield']++;
  497. }
  498. // Label payment
  499. print "<td>".dol_trunc($obj->label, 40)."</td>\n";
  500. if (!$i) {
  501. $totalarray['nbfield']++;
  502. }
  503. // Date end period
  504. print '<td class="center">'.dol_print_date($db->jdate($obj->dateep), 'day')."</td>\n";
  505. if (!$i) {
  506. $totalarray['nbfield']++;
  507. }
  508. // Date payment
  509. print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>\n";
  510. if (!$i) {
  511. $totalarray['nbfield']++;
  512. }
  513. // Date value
  514. /*print '<td class="center">'.dol_print_date($db->jdate($obj->datev), 'day')."</td>\n";
  515. if (!$i) $totalarray['nbfield']++;*/
  516. // Employee
  517. print "<td>".$userstatic->getNomUrl(1)."</td>\n";
  518. if (!$i) {
  519. $totalarray['nbfield']++;
  520. }
  521. // Type
  522. print '<td>';
  523. print $langs->trans("PaymentTypeShort".$obj->payment_code);
  524. print '</td>';
  525. if (!$i) {
  526. $totalarray['nbfield']++;
  527. }
  528. // Chq number
  529. print '<td>'.$obj->num_payment.'</td>';
  530. if (!$i) {
  531. $totalarray['nbfield']++;
  532. }
  533. // Account
  534. if (isModEnabled('banque')) {
  535. // Bank transaction
  536. print '<td>';
  537. $accountlinestatic->id = $obj->fk_bank;
  538. print $accountlinestatic->getNomUrl(1);
  539. print '</td>';
  540. if (!$i) {
  541. $totalarray['nbfield']++;
  542. }
  543. print '<td>';
  544. if ($obj->fk_bank > 0) {
  545. //$accountstatic->fetch($obj->fk_bank);
  546. $accountstatic->id = $obj->bid;
  547. $accountstatic->ref = $obj->bref;
  548. $accountstatic->number = $obj->bnumber;
  549. $accountstatic->iban = $obj->iban;
  550. $accountstatic->bic = $obj->bic;
  551. $accountstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
  552. $accountstatic->clos = $obj->clos;
  553. if (isModEnabled('accounting')) {
  554. $accountstatic->account_number = $obj->account_number;
  555. $accountingjournal = new AccountingJournal($db);
  556. $accountingjournal->fetch($obj->fk_accountancy_journal);
  557. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  558. }
  559. $accountstatic->label = $obj->blabel;
  560. if ($accountstatic->id > 0) {
  561. print $accountstatic->getNomUrl(1);
  562. }
  563. } else {
  564. print '&nbsp;';
  565. }
  566. print '</td>';
  567. if (!$i) {
  568. $totalarray['nbfield']++;
  569. }
  570. }
  571. // Amount
  572. print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
  573. if (!$i) {
  574. $totalarray['nbfield']++;
  575. }
  576. if (!$i) {
  577. $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield';
  578. }
  579. $totalarray['val']['totalttcfield'] += $obj->amount;
  580. // Extra fields
  581. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  582. // Fields from hook
  583. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  584. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  585. print $hookmanager->resPrint;
  586. // Action column
  587. print '<td class="nowrap center">';
  588. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  589. $selected = 0;
  590. if (in_array($object->id, $arrayofselected)) {
  591. $selected = 1;
  592. }
  593. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  594. }
  595. print '</td>';
  596. if (!$i) {
  597. $totalarray['nbfield']++;
  598. }
  599. print '</tr>'."\n";
  600. $i++;
  601. }
  602. // Show total line
  603. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  604. // If no record found
  605. if ($num == 0) {
  606. /*$colspan = 1;
  607. foreach ($arrayfields as $key => $val) {
  608. if (!empty($val['checked'])) {
  609. $colspan++;
  610. }
  611. }*/
  612. $colspan = 12;
  613. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  614. }
  615. $db->free($resql);
  616. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  617. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  618. print $hookmanager->resPrint;
  619. print '</table>'."\n";
  620. print '</div>'."\n";
  621. print '</form>'."\n";
  622. // End of page
  623. llxFooter();
  624. $db->close();