payments.php 29 KB

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