list.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  44. // Load variable for pagination
  45. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  46. $sortfield = GETPOST('sortfield', 'aZ09comma');
  47. $sortorder = GETPOST('sortorder', 'aZ09comma');
  48. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  49. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  50. // If $page is not defined, or '' or -1 or if we click on clear filters
  51. $page = 0;
  52. }
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (!$sortfield) {
  57. $sortfield = "s.datep,s.rowid";
  58. }
  59. if (!$sortorder) {
  60. $sortorder = "DESC,DESC";
  61. }
  62. // Initialize technical objects
  63. $object = new PaymentSalary($db);
  64. $extrafields = new ExtraFields($db);
  65. $diroutputmassaction = $conf->user->dir_output.'/temp/massgeneration/'.$user->id;
  66. $hookmanager->initHooks(array('salarieslist')); // Note that conf->hooks_modules contains array
  67. // Fetch optionals attributes and labels
  68. $extrafields->fetch_name_optionals_label($object->table_element);
  69. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  70. if (!$sortfield) {
  71. $sortfield = "s.datep,s.rowid";
  72. }
  73. if (!$sortorder) {
  74. $sortorder = "DESC,DESC";
  75. }
  76. $search_ref = GETPOST('search_ref', 'int');
  77. $search_user = GETPOST('search_user', 'alpha');
  78. $search_label = GETPOST('search_label', 'alpha');
  79. $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'));
  80. $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'));
  81. $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'));
  82. $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'));
  83. $search_amount = GETPOST('search_amount', 'alpha');
  84. $search_account = GETPOST('search_account', 'int');
  85. $search_status = GETPOST('search_status', 'int');
  86. $search_type_id = GETPOST('search_type_id', 'int');
  87. $filtre = GETPOST("filtre", 'restricthtml');
  88. $childids = $user->getAllChildIds(1);
  89. // Initialize array of search criterias
  90. $search_all = GETPOST("search_all", 'alpha');
  91. $search = array();
  92. foreach ($object->fields as $key => $val) {
  93. if (GETPOST('search_'.$key, 'alpha') !== '') {
  94. $search[$key] = GETPOST('search_'.$key, 'alpha');
  95. }
  96. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  97. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  98. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  99. }
  100. }
  101. // List of fields to search into when doing a "search in all"
  102. $fieldstosearchall = array();
  103. foreach ($object->fields as $key => $val) {
  104. if (!empty($val['searchall'])) {
  105. $fieldstosearchall['t.'.$key] = $val['label'];
  106. }
  107. }
  108. // Definition of array of fields for columns
  109. $arrayfields = array();
  110. foreach ($object->fields as $key => $val) {
  111. // If $val['visible']==0, then we never show the field
  112. if (!empty($val['visible'])) {
  113. $visible = (int) dol_eval($val['visible'], 1);
  114. $arrayfields['t.'.$key] = array(
  115. 'label'=>$val['label'],
  116. 'checked'=>(($visible < 0) ? 0 : 1),
  117. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  118. 'position'=>$val['position'],
  119. 'help'=> isset($val['help']) ? $val['help'] : ''
  120. );
  121. }
  122. }
  123. // Extra fields
  124. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  125. $object->fields = dol_sort_array($object->fields, 'position');
  126. $arrayfields = dol_sort_array($arrayfields, 'position');
  127. $permissiontoread = $user->rights->salaries->read;
  128. $permissiontoadd = $user->rights->salaries->write;
  129. $permissiontodelete = $user->rights->salaries->delete;
  130. // Security check
  131. $socid = GETPOST("socid", "int");
  132. if ($user->socid) {
  133. $socid = $user->socid;
  134. }
  135. restrictedArea($user, 'salaries', '', 'salary', '');
  136. /*
  137. * Actions
  138. */
  139. if (GETPOST('cancel', 'alpha')) {
  140. $action = 'list';
  141. $massaction = '';
  142. }
  143. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  144. $massaction = '';
  145. }
  146. $parameters = array();
  147. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  148. if ($reshook < 0) {
  149. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  150. }
  151. if (empty($reshook)) {
  152. // Selection of new fields
  153. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  154. // Purge search criteria
  155. 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
  156. $search_ref = "";
  157. $search_user = "";
  158. $search_label = "";
  159. $search_date_start_from = '';
  160. $search_date_start_to = '';
  161. $search_date_end_from = '';
  162. $search_date_end_to = '';
  163. $search_date_end = '';
  164. $search_amount = "";
  165. $search_account = '';
  166. $search_status = '';
  167. $search_type_id = "";
  168. }
  169. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  170. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  171. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  172. }
  173. // Mass actions
  174. $objectclass = 'Salary';
  175. $objectlabel = 'Salaries';
  176. $uploaddir = $conf->salaries->dir_output;
  177. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  178. // Validate records
  179. if (!$error && $massaction == 'buildsepa' && $permissiontoadd) {
  180. $objecttmp = new $objectclass($db);
  181. // TODO
  182. }
  183. }
  184. /*
  185. * View
  186. */
  187. $form = new Form($db);
  188. $salstatic = new Salary($db);
  189. $userstatic = new User($db);
  190. $accountstatic = new Account($db);
  191. $now = dol_now();
  192. $title = $langs->trans('Salaries');
  193. //$help_url="EN:Module_BillOfMaterials|FR:Module_BillOfMaterials_FR|ES:Módulo_BillOfMaterials";
  194. $help_url = '';
  195. $morejs = array();
  196. $morecss = array();
  197. // Build and execute select
  198. // --------------------------------------------------------------------
  199. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.admin, u.photo, u.salary as current_salary, u.fk_soc as fk_soc, u.statut as status,";
  200. $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, ";
  201. $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,";
  202. $sql .= " pst.code as payment_code,";
  203. $sql .= " SUM(ps.amount) as alreadypayed";
  204. // Add fields from extrafields
  205. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  206. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  207. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  208. }
  209. }
  210. // Add fields from hooks
  211. $parameters = array();
  212. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  213. $sql .= $hookmanager->resPrint;
  214. $sql = preg_replace('/,\s*$/', '', $sql);
  215. //$sql .= ", COUNT(rc.rowid) as anotherfield";
  216. $sqlfields = $sql; // $sql fields to remove for count total
  217. $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
  218. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON (ps.fk_salary = s.rowid) ";
  219. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON (s.fk_typepayment = pst.id) ";
  220. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account ba ON (ba.rowid = s.fk_account), ";
  221. //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON ps.fk_salary = s.rowid, ";
  222. $sql .= " ".MAIN_DB_PREFIX."user as u";
  223. $sql .= " WHERE u.rowid = s.fk_user";
  224. $sql .= " AND s.entity IN (".getEntity('salaries').")";
  225. if (!$user->hasRight('salaries', 'readall')) {
  226. $sql .= " AND s.fk_user IN (".$db->sanitize(join(',', $childids)).")";
  227. }
  228. //print $sql;
  229. // Search criteria
  230. if ($search_ref) {
  231. $sql .= " AND s.rowid=".((int) $search_ref);
  232. }
  233. if ($search_user) {
  234. $sql .= natural_search(array('u.login', 'u.lastname', 'u.firstname', 'u.email'), $search_user);
  235. }
  236. if ($search_label) {
  237. $sql .= natural_search(array('s.label'), $search_label);
  238. }
  239. if (!empty($search_date_start_from)) {
  240. $sql .= " AND s.datesp >= '".$db->idate($search_date_start_from)."'";
  241. }
  242. if (!empty($search_date_end_from)) {
  243. $sql .= " AND s.dateep >= '".$db->idate($search_date_end_from)."'";
  244. }
  245. if (!empty($search_date_start_to)) {
  246. $sql .= " AND s.datesp <= '".$db->idate($search_date_start_to)."'";
  247. }
  248. if (!empty($search_date_end_to)) {
  249. $sql .= " AND s.dateep <= '".$db->idate($search_date_end_to)."'";
  250. }
  251. if ($search_amount) {
  252. $sql .= natural_search("s.amount", $search_amount, 1);
  253. }
  254. if ($search_account > 0) {
  255. $sql .= " AND s.fk_account=".((int) $search_account);
  256. }
  257. if ($search_status != '' && $search_status >= 0) {
  258. $sql .= " AND s.paye = ".((int) $search_status);
  259. }
  260. if ($search_type_id) {
  261. $sql .= " AND s.fk_typepayment=".((int) $search_type_id);
  262. }
  263. $sql .= " GROUP BY u.rowid, u.lastname, u.firstname, u.login, u.email, u.admin, u.photo, u.salary, u.fk_soc, u.statut,";
  264. $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,";
  265. $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,";
  266. $sql .= " pst.code";
  267. // Count total nb of records
  268. $nbtotalofrecords = '';
  269. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  270. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  271. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  272. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  273. $resql = $db->query($sqlforcount);
  274. if ($resql) {
  275. $objforcount = $db->fetch_object($resql);
  276. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  277. } else {
  278. dol_print_error($db);
  279. }
  280. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  281. $page = 0;
  282. $offset = 0;
  283. }
  284. $db->free($resql);
  285. }
  286. // Complete request and execute it with limit
  287. $sql .= $db->order($sortfield, $sortorder);
  288. if ($limit) {
  289. $sql .= $db->plimit($limit + 1, $offset);
  290. }
  291. $resql = $db->query($sql);
  292. if (!$resql) {
  293. dol_print_error($db);
  294. exit;
  295. }
  296. $num = $db->num_rows($resql);
  297. // Direct jump if only one record found
  298. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  299. $obj = $db->fetch_object($resql);
  300. $id = $obj->rowid;
  301. header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id);
  302. exit;
  303. }
  304. // Output page
  305. // --------------------------------------------------------------------
  306. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
  307. $arrayofselected = is_array($toselect) ? $toselect : array();
  308. $param = '';
  309. if (!empty($mode)) {
  310. $param .= '&mode='.urlencode($mode);
  311. }
  312. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  313. $param .= '&contextpage='.urlencode($contextpage);
  314. }
  315. if ($limit > 0 && $limit != $conf->liste_limit) {
  316. $param .= '&limit='.((int) $limit);
  317. }
  318. if ($search_type_id) {
  319. $param .= '&search_type_id='.urlencode($search_type_id);
  320. }
  321. if ($optioncss != '') {
  322. $param .= '&optioncss='.urlencode($optioncss);
  323. }
  324. if ($search_ref) {
  325. $param .= '&search_ref='.urlencode($search_ref);
  326. }
  327. if ($search_user > 0) {
  328. $param .= '&search_user='.urlencode($search_user);
  329. }
  330. if ($search_label) {
  331. $param .= '&search_label='.urlencode($search_label);
  332. }
  333. if ($search_account) {
  334. $param .= '&search_account='.urlencode($search_account);
  335. }
  336. if ($search_status != '' && $search_status != '-1') {
  337. $param .= '&search_status='.urlencode($search_status);
  338. }
  339. if (!empty($search_date_start_from)) {
  340. $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'));
  341. }
  342. if (!empty($search_date_start_to)) {
  343. $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'));
  344. }
  345. if (!empty($search_date_end_from)) {
  346. $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'));
  347. }
  348. if (!empty($search_date_end_to)) {
  349. $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'));
  350. }
  351. // Add $param from extra fields
  352. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  353. // Add $param from hooks
  354. $parameters = array();
  355. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  356. $param .= $hookmanager->resPrint;
  357. // List of mass actions available
  358. $arrayofmassactions = array(
  359. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  360. //'buildsepa'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("BuildSepa"), // TODO
  361. );
  362. if (!empty($permissiontodelete)) {
  363. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  364. }
  365. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  366. $arrayofmassactions = array();
  367. }
  368. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  369. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  370. if ($optioncss != '') {
  371. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  372. }
  373. print '<input type="hidden" name="token" value="'.newToken().'">';
  374. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  375. print '<input type="hidden" name="action" value="list">';
  376. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  377. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  378. print '<input type="hidden" name="page" value="'.$page.'">';
  379. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  380. print '<input type="hidden" name="page_y" value="">';
  381. print '<input type="hidden" name="mode" value="'.$mode.'">';
  382. $url = DOL_URL_ROOT.'/salaries/card.php?action=create';
  383. if (!empty($socid)) {
  384. $url .= '&socid='.$socid;
  385. }
  386. $newcardbutton = '';
  387. $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'));
  388. $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'));
  389. $newcardbutton .= dolGetButtonTitleSeparator();
  390. $newcardbutton .= dolGetButtonTitle($langs->trans('NewSalary'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
  391. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  392. // Add code for pre mass action (confirmation or email presend form)
  393. $topicmail = "SendSalaryRef";
  394. $modelmail = "salary";
  395. $objecttmp = new Salary($db);
  396. $trackid = 'sal'.$object->id;
  397. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  398. $moreforfilter = '';
  399. $parameters = array();
  400. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  401. if (empty($reshook)) {
  402. $moreforfilter .= $hookmanager->resPrint;
  403. } else {
  404. $moreforfilter = $hookmanager->resPrint;
  405. }
  406. if (!empty($moreforfilter)) {
  407. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  408. print $moreforfilter;
  409. $parameters = array();
  410. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  411. print $hookmanager->resPrint;
  412. print '</div>';
  413. }
  414. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  415. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  416. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  417. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  418. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  419. // Fields title search
  420. // --------------------------------------------------------------------
  421. print '<tr class="liste_titre_filter">';
  422. // Action column
  423. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  424. print '<td class="liste_titre center maxwidthsearch">';
  425. $searchpicto = $form->showFilterButtons('left');
  426. print $searchpicto;
  427. print '</td>';
  428. }
  429. // Ref
  430. print '<td class="liste_titre left">';
  431. print '<input class="flat width50" type="text" name="search_ref" value="'.$db->escape($search_ref).'">';
  432. print '</td>';
  433. // Label
  434. print '<td class="liste_titre"><input type="text" class="flat width100" name="search_label" value="'.$db->escape($search_label).'"></td>';
  435. // Date start
  436. print '<td class="liste_titre center">';
  437. print '<div class="nowrap">';
  438. 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'));
  439. print '</div>';
  440. print '<div class="nowrap">';
  441. 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'));
  442. print '</div>';
  443. print '</td>';
  444. // Date End
  445. print '<td class="liste_titre center">';
  446. print '<div class="nowrap">';
  447. 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'));
  448. print '</div>';
  449. print '<div class="nowrap">';
  450. 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'));
  451. print '</div>';
  452. print '</td>';
  453. // Employee
  454. print '<td class="liste_titre">';
  455. print '<input class="flat" type="text" size="6" name="search_user" value="'.$db->escape($search_user).'">';
  456. print '</td>';
  457. // Type
  458. print '<td class="liste_titre left">';
  459. print $form->select_types_paiements($search_type_id, 'search_type_id', '', 0, 1, 1, 16, 1, 'maxwidth125', 1);
  460. print '</td>';
  461. // Bank account
  462. if (isModEnabled("banque")) {
  463. print '<td class="liste_titre">';
  464. print $form->select_comptes($search_account, 'search_account', 0, '', 1, '', 0, 'maxwidth125', 1);
  465. print '</td>';
  466. }
  467. // Amount
  468. print '<td class="liste_titre right"><input name="search_amount" class="flat" type="text" size="8" value="'.$db->escape($search_amount).'"></td>';
  469. // Status
  470. print '<td class="liste_titre right parentonrightofpage">';
  471. $liststatus = array('0' => $langs->trans("Unpaid"), '1' => $langs->trans("Paid"));
  472. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
  473. print '</td>';
  474. // Extra fields
  475. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  476. // Fields from hook
  477. $parameters = array('arrayfields'=>$arrayfields);
  478. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  479. print $hookmanager->resPrint;
  480. // Action column
  481. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  482. print '<td class="liste_titre center maxwidthsearch">';
  483. $searchpicto = $form->showFilterButtons();
  484. print $searchpicto;
  485. print '</td>';
  486. }
  487. print '</tr>'."\n";
  488. $totalarray = array();
  489. $totalarray['nbfield'] = 0;
  490. // Fields title label
  491. // --------------------------------------------------------------------
  492. print '<tr class="liste_titre">';
  493. // Action column
  494. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  495. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  496. $totalarray['nbfield']++;
  497. }
  498. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $param, "", $sortfield, $sortorder);
  499. $totalarray['nbfield']++;
  500. print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, 'class="left"', $sortfield, $sortorder);
  501. $totalarray['nbfield']++;
  502. print_liste_field_titre("DateStart", $_SERVER["PHP_SELF"], "s.datesp,s.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  503. $totalarray['nbfield']++;
  504. print_liste_field_titre("DateEnd", $_SERVER["PHP_SELF"], "s.dateep,s.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
  505. $totalarray['nbfield']++;
  506. print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.lastname", "", $param, "", $sortfield, $sortorder);
  507. $totalarray['nbfield']++;
  508. print_liste_field_titre("DefaultPaymentMode", $_SERVER["PHP_SELF"], "type", "", $param, 'class="left"', $sortfield, $sortorder);
  509. $totalarray['nbfield']++;
  510. if (isModEnabled("banque")) {
  511. print_liste_field_titre("DefaultBankAccount", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
  512. $totalarray['nbfield']++;
  513. }
  514. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder);
  515. $totalarray['nbfield']++;
  516. print_liste_field_titre('Status', $_SERVER["PHP_SELF"], "s.paye", '', $param, 'class="right"', $sortfield, $sortorder);
  517. $totalarray['nbfield']++;
  518. // Extra fields
  519. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  520. // Hook fields
  521. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  522. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  523. print $hookmanager->resPrint;
  524. // Action column
  525. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  526. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  527. $totalarray['nbfield']++;
  528. }
  529. print '</tr>'."\n";
  530. // Detect if we need a fetch on each output line
  531. $needToFetchEachLine = 0;
  532. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  533. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  534. if (!is_null($val) && preg_match('/\$object/', $val)) {
  535. $needToFetchEachLine++; // There is at least one compute field that use $object
  536. }
  537. }
  538. }
  539. // Loop on record
  540. // --------------------------------------------------------------------
  541. $i = 0;
  542. $savnbfield = $totalarray['nbfield'];
  543. $totalarray = array();
  544. $totalarray['nbfield'] = 0;
  545. $totalarray['val'] = array();
  546. $totalarray['val']['totalttcfield'] = 0;
  547. $imaxinloop = ($limit ? min($num, $limit) : $num);
  548. while ($i < $imaxinloop) {
  549. $obj = $db->fetch_object($resql);
  550. if (empty($obj)) {
  551. break; // Should not happen
  552. }
  553. // Store properties in $object
  554. $object->setVarsFromFetchObj($obj);
  555. $userstatic->id = $obj->uid;
  556. $userstatic->lastname = $obj->lastname;
  557. $userstatic->firstname = $obj->firstname;
  558. $userstatic->admin = $obj->admin;
  559. $userstatic->login = $obj->login;
  560. $userstatic->email = $obj->email;
  561. $userstatic->socid = $obj->fk_soc;
  562. $userstatic->statut = $obj->status; // deprecated
  563. $userstatic->status = $obj->status;
  564. $userstatic->photo = $obj->photo;
  565. $salstatic->id = $obj->rowid;
  566. $salstatic->ref = $obj->rowid;
  567. $salstatic->label = $obj->label;
  568. $salstatic->paye = $obj->paye;
  569. $salstatic->datesp = $obj->datesp;
  570. $salstatic->dateep = $obj->dateep;
  571. $salstatic->amount = $obj->amount;
  572. $salstatic->type_payment = $obj->payment_code;
  573. if ($mode == 'kanban') {
  574. if ($i == 0) {
  575. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  576. print '<div class="box-flex-container kanban">';
  577. }
  578. // Output Kanban
  579. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  580. $selected = 0;
  581. if (in_array($object->id, $arrayofselected)) {
  582. $selected = 1;
  583. }
  584. }
  585. print $salstatic->getKanbanView('', array('user' => $userstatic, 'selected' => $selected));
  586. if ($i == ($imaxinloop - 1)) {
  587. print '</div>';
  588. print '</td></tr>';
  589. }
  590. } else {
  591. // Show here line of result
  592. $j = 0;
  593. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  594. // Action column
  595. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  596. print '<td class="nowrap center">';
  597. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  598. $selected = 0;
  599. if (in_array($object->id, $arrayofselected)) {
  600. $selected = 1;
  601. }
  602. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  603. }
  604. print '</td>';
  605. if (!$i) {
  606. $totalarray['nbfield']++;
  607. }
  608. }
  609. // Ref
  610. print "<td>".$salstatic->getNomUrl(1)."</td>\n";
  611. if (!$i) {
  612. $totalarray['nbfield']++;
  613. }
  614. // Label payment
  615. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->label).'">'.dol_escape_htmltag($obj->label)."</td>\n";
  616. if (!$i) {
  617. $totalarray['nbfield']++;
  618. }
  619. // Date Start
  620. print '<td class="center">'.dol_print_date($db->jdate($obj->datesp), 'day')."</td>\n";
  621. if (!$i) {
  622. $totalarray['nbfield']++;
  623. }
  624. // Date End
  625. print '<td class="center">'.dol_print_date($db->jdate($obj->dateep), 'day')."</td>\n";
  626. if (!$i) {
  627. $totalarray['nbfield']++;
  628. }
  629. // Employee
  630. print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1)."</td>\n";
  631. if (!$i) {
  632. $totalarray['nbfield']++;
  633. }
  634. // Payment mode
  635. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans("PaymentTypeShort".$obj->payment_code)).'">';
  636. if (!empty($obj->payment_code)) print $langs->trans("PaymentTypeShort".$obj->payment_code);
  637. print '</td>';
  638. if (!$i) {
  639. $totalarray['nbfield']++;
  640. }
  641. // Account
  642. if (isModEnabled("banque")) {
  643. print '<td>';
  644. if ($obj->fk_account > 0) {
  645. //$accountstatic->fetch($obj->fk_bank);
  646. $accountstatic->id = $obj->bid;
  647. $accountstatic->ref = $obj->bref;
  648. $accountstatic->label = $obj->blabel;
  649. $accountstatic->number = $obj->bnumber;
  650. $accountstatic->iban = $obj->iban;
  651. $accountstatic->bic = $obj->bic;
  652. $accountstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
  653. $accountstatic->account_number = $obj->account_number;
  654. $accountstatic->clos = $obj->clos;
  655. if (isModEnabled('accounting')) {
  656. $accountstatic->account_number = $obj->account_number;
  657. $accountingjournal = new AccountingJournal($db);
  658. $accountingjournal->fetch($obj->fk_accountancy_journal);
  659. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  660. }
  661. //$accountstatic->label = $obj->blabel;
  662. print $accountstatic->getNomUrl(1);
  663. } else {
  664. print '&nbsp;';
  665. }
  666. print '</td>';
  667. if (!$i) {
  668. $totalarray['nbfield']++;
  669. }
  670. }
  671. // if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield';
  672. // Amount
  673. print '<td class="nowraponall right"><span class="amount">'.price($obj->amount).'</span></td>';
  674. if (!$i) {
  675. $totalarray['nbfield']++;
  676. }
  677. if (!$i) {
  678. $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield';
  679. }
  680. $totalarray['val']['totalttcfield'] += $obj->amount;
  681. print '<td class="nowraponall right">'.$salstatic->LibStatut($obj->paye, 5, $obj->alreadypayed).'</td>';
  682. if (!$i) {
  683. $totalarray['nbfield']++;
  684. }
  685. // Extra fields
  686. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  687. // Fields from hook
  688. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  689. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  690. print $hookmanager->resPrint;
  691. // Action column
  692. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  693. print '<td class="nowrap center">';
  694. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  695. $selected = 0;
  696. if (in_array($object->id, $arrayofselected)) {
  697. $selected = 1;
  698. }
  699. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  700. }
  701. print '</td>';
  702. if (!$i) {
  703. $totalarray['nbfield']++;
  704. }
  705. }
  706. print '</tr>'."\n";
  707. }
  708. $i++;
  709. }
  710. // Show total line
  711. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  712. // If no record found
  713. if ($num == 0) {
  714. /*$colspan = 1;
  715. foreach ($arrayfields as $key => $val) {
  716. if (!empty($val['checked'])) {
  717. $colspan++;
  718. }
  719. }*/
  720. $colspan = 9;
  721. if (isModEnabled("banque")) { $colspan++; }
  722. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  723. }
  724. $db->free($resql);
  725. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  726. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  727. print $hookmanager->resPrint;
  728. print '</table>'."\n";
  729. print '</div>'."\n";
  730. print '</form>'."\n";
  731. // End of page
  732. llxFooter();
  733. $db->close();