payments.php 27 KB

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