payments.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. /* Copyright (C) 2011-2019 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 (!empty($conf->accounting->enabled)) {
  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, $totalnboflines, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
  350. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  351. //$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  352. $selectedfields = '';
  353. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  354. print '<div class="div-table-responsive">';
  355. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  356. // Fields title search
  357. // --------------------------------------------------------------------
  358. print '<tr class="liste_titre_filter">';
  359. // Ref
  360. print '<td class="liste_titre left">';
  361. print '<input class="flat" type="text" size="3" name="search_ref" value="'.$db->escape($search_ref).'">';
  362. print '</td>';
  363. // Salary
  364. print '<td class="liste_titre center">';
  365. print '<input class="flat" type="text" size="3" name="search_ref_salary" value="'.$db->escape($search_ref_salary).'">';
  366. print '</td>';
  367. // Label
  368. print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$db->escape($search_label).'"></td>';
  369. // Date end period
  370. print '<td class="liste_titre center">';
  371. print '<div class="nowrap">';
  372. print $form->selectDate($search_dateep_start ? $search_dateep_start : -1, 'search_dateep_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  373. print '</div>';
  374. print '<div class="nowrap">';
  375. print $form->selectDate($search_dateep_end ? $search_dateep_end : -1, 'search_dateep_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  376. print '</div>';
  377. print '</td>';
  378. // Date payment
  379. print '<td class="liste_titre center">';
  380. print '<div class="nowrap">';
  381. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  382. print '</div>';
  383. print '<div class="nowrap">';
  384. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  385. print '</div>';
  386. print '</td>';
  387. // Date value
  388. /*print '<td class="liste_titre center">';
  389. print '</td>';*/
  390. // Employee
  391. print '<td class="liste_titre">';
  392. print '<input class="flat" type="text" size="6" name="search_user" value="'.$db->escape($search_user).'">';
  393. print '</td>';
  394. // Type
  395. print '<td class="liste_titre left">';
  396. $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16);
  397. print '</td>';
  398. // Chq number
  399. print '<td class="liste_titre right"><input name="search_chq_number" class="flat" type="text" size="8" value="'.$db->escape($search_chq_number).'"></td>';
  400. if (!empty($conf->banque->enabled)) {
  401. // Bank transaction
  402. print '<td class="liste_titre center">';
  403. print '<input class="flat" type="text" size="3" name="search_fk_bank" value="'.$db->escape($search_fk_bank).'">';
  404. print '</td>';
  405. // Account
  406. print '<td class="liste_titre">';
  407. $form->select_comptes($search_account, 'search_account', 0, '', 1);
  408. print '</td>';
  409. }
  410. // Amount
  411. print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$db->escape($search_amount).'"></td>';
  412. // Extra fields
  413. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  414. // Fields from hook
  415. $parameters = array('arrayfields'=>$arrayfields);
  416. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  417. print $hookmanager->resPrint;
  418. // Action column
  419. print '<td class="liste_titre maxwidthsearch">';
  420. $searchpicto = $form->showFilterButtons();
  421. print $searchpicto;
  422. print '</td>';
  423. print '</tr>'."\n";
  424. // Fields title label
  425. // --------------------------------------------------------------------
  426. print '<tr class="liste_titre">';
  427. print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, "", $sortfield, $sortorder);
  428. print_liste_field_titre("Salary", $_SERVER["PHP_SELF"], "sal.rowid", "", $param, '', $sortfield, $sortorder);
  429. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, 'class="left"', $sortfield, $sortorder);
  430. print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "sal.dateep", "", $param, '', $sortfield, $sortorder, 'center ');
  431. print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep,s.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  432. //print_liste_field_titre("DateValue", $_SERVER["PHP_SELF"], "b.datev,s.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
  433. print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder);
  434. print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pst.code", "", $param, 'class="left"', $sortfield, $sortorder);
  435. print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "s.num_payment", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
  436. if (!empty($conf->banque->enabled)) {
  437. print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "s.fk_bank", "", $param, '', $sortfield, $sortorder);
  438. print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
  439. }
  440. print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder);
  441. // Extra fields
  442. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  443. // Hook fields
  444. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  445. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  446. print $hookmanager->resPrint;
  447. // Action column
  448. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  449. print '</tr>'."\n";
  450. // Detect if we need a fetch on each output line
  451. $needToFetchEachLine = 0;
  452. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  453. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  454. if (preg_match('/\$object/', $val)) {
  455. $needToFetchEachLine++;
  456. }
  457. // There is at least one compute field that use $object
  458. }
  459. }
  460. // Loop on record
  461. // --------------------------------------------------------------------
  462. $i = 0;
  463. $total = 0;
  464. $totalarray = array();
  465. while ($i < ($limit ? min($num, $limit) : $num)) {
  466. $obj = $db->fetch_object($resql);
  467. if (empty($obj)) {
  468. break;
  469. }
  470. // Should not happen
  471. // Store properties in $object
  472. $object->setVarsFromFetchObj($obj);
  473. // Show here line of result
  474. print '<tr class="oddeven">';
  475. $userstatic->id = $obj->uid;
  476. $userstatic->lastname = $obj->lastname;
  477. $userstatic->firstname = $obj->firstname;
  478. $userstatic->admin = $obj->admin;
  479. $userstatic->login = $obj->login;
  480. $userstatic->email = $obj->email;
  481. $userstatic->socid = $obj->fk_soc;
  482. $userstatic->statut = $obj->status;
  483. $salstatic->id = $obj->id_salary;
  484. $salstatic->ref = $obj->id_salary;
  485. $paymentsalstatic->id = $obj->rowid;
  486. $paymentsalstatic->ref = $obj->rowid;
  487. // Ref
  488. print "<td>".$paymentsalstatic->getNomUrl(1)."</td>\n";
  489. if (!$i) {
  490. $totalarray['nbfield']++;
  491. }
  492. // Ref salary
  493. print "<td>".$salstatic->getNomUrl(1)."</td>\n";
  494. if (!$i) {
  495. $totalarray['nbfield']++;
  496. }
  497. // Label payment
  498. print "<td>".dol_trunc($obj->label, 40)."</td>\n";
  499. if (!$i) {
  500. $totalarray['nbfield']++;
  501. }
  502. // Date end period
  503. print '<td class="center">'.dol_print_date($db->jdate($obj->dateep), 'day')."</td>\n";
  504. if (!$i) {
  505. $totalarray['nbfield']++;
  506. }
  507. // Date payment
  508. print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>\n";
  509. if (!$i) {
  510. $totalarray['nbfield']++;
  511. }
  512. // Date value
  513. /*print '<td class="center">'.dol_print_date($db->jdate($obj->datev), 'day')."</td>\n";
  514. if (!$i) $totalarray['nbfield']++;*/
  515. // Employee
  516. print "<td>".$userstatic->getNomUrl(1)."</td>\n";
  517. if (!$i) {
  518. $totalarray['nbfield']++;
  519. }
  520. // Type
  521. print '<td>';
  522. print $langs->trans("PaymentTypeShort".$obj->payment_code);
  523. print '</td>';
  524. if (!$i) {
  525. $totalarray['nbfield']++;
  526. }
  527. // Chq number
  528. print '<td>'.$obj->num_payment.'</td>';
  529. if (!$i) {
  530. $totalarray['nbfield']++;
  531. }
  532. // Account
  533. if (!empty($conf->banque->enabled)) {
  534. // Bank transaction
  535. print '<td>';
  536. $accountlinestatic->id = $obj->fk_bank;
  537. print $accountlinestatic->getNomUrl(1);
  538. print '</td>';
  539. if (!$i) {
  540. $totalarray['nbfield']++;
  541. }
  542. print '<td>';
  543. if ($obj->fk_bank > 0) {
  544. //$accountstatic->fetch($obj->fk_bank);
  545. $accountstatic->id = $obj->bid;
  546. $accountstatic->ref = $obj->bref;
  547. $accountstatic->number = $obj->bnumber;
  548. $accountstatic->iban = $obj->iban;
  549. $accountstatic->bic = $obj->bic;
  550. $accountstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
  551. $accountstatic->clos = $obj->clos;
  552. if (!empty($conf->accounting->enabled)) {
  553. $accountstatic->account_number = $obj->account_number;
  554. $accountingjournal = new AccountingJournal($db);
  555. $accountingjournal->fetch($obj->fk_accountancy_journal);
  556. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  557. }
  558. $accountstatic->label = $obj->blabel;
  559. if ($accountstatic->id > 0) {
  560. print $accountstatic->getNomUrl(1);
  561. }
  562. } else {
  563. print '&nbsp;';
  564. }
  565. print '</td>';
  566. if (!$i) {
  567. $totalarray['nbfield']++;
  568. }
  569. }
  570. // Amount
  571. print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
  572. if (!$i) {
  573. $totalarray['nbfield']++;
  574. }
  575. if (!$i) {
  576. $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield';
  577. }
  578. $totalarray['val']['totalttcfield'] += $obj->amount;
  579. // Extra fields
  580. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  581. // Fields from hook
  582. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  583. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  584. print $hookmanager->resPrint;
  585. // Action column
  586. print '<td class="nowrap center">';
  587. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  588. $selected = 0;
  589. if (in_array($object->id, $arrayofselected)) {
  590. $selected = 1;
  591. }
  592. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  593. }
  594. print '</td>';
  595. if (!$i) {
  596. $totalarray['nbfield']++;
  597. }
  598. print '</tr>'."\n";
  599. $i++;
  600. }
  601. // Show total line
  602. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  603. // If no record found
  604. if ($num == 0) {
  605. /*$colspan = 1;
  606. foreach ($arrayfields as $key => $val) {
  607. if (!empty($val['checked'])) {
  608. $colspan++;
  609. }
  610. }*/
  611. $colspan = 12;
  612. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  613. }
  614. $db->free($resql);
  615. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  616. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  617. print $hookmanager->resPrint;
  618. print '</table>'."\n";
  619. print '</div>'."\n";
  620. print '</form>'."\n";
  621. // End of page
  622. llxFooter();
  623. $db->close();