list.php 27 KB

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