list.php 27 KB

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