list.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
  6. * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
  7. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  8. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  9. * Copyright (C) 2021-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/compta/sociales/list.php
  26. * \ingroup tax
  27. * \brief Page to list all social contributions
  28. */
  29. // Load Dolibarr environment
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. if (isModEnabled('project')) {
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. }
  39. // Load translation files required by the page
  40. $langs->loadLangs(array('compta', 'banks', 'bills', 'hrm', 'projects'));
  41. $action = GETPOST('action', 'aZ09');
  42. $massaction = GETPOST('massaction', 'alpha');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $optioncss = GETPOST('optioncss', 'alpha');
  45. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'sclist';
  46. $search_ref = GETPOST('search_ref', 'int');
  47. $search_label = GETPOST('search_label', 'alpha');
  48. $search_typeid = GETPOST('search_typeid', 'int');
  49. $search_amount = GETPOST('search_amount', 'alpha');
  50. $search_status = GETPOST('search_status', 'int');
  51. $search_date_startday = GETPOST('search_date_startday', 'int');
  52. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  53. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  54. $search_date_endday = GETPOST('search_date_endday', 'int');
  55. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  56. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  57. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  58. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  59. $search_date_limit_startday = GETPOST('search_date_limit_startday', 'int');
  60. $search_date_limit_startmonth = GETPOST('search_date_limit_startmonth', 'int');
  61. $search_date_limit_startyear = GETPOST('search_date_limit_startyear', 'int');
  62. $search_date_limit_endday = GETPOST('search_date_limit_endday', 'int');
  63. $search_date_limit_endmonth = GETPOST('search_date_limit_endmonth', 'int');
  64. $search_date_limit_endyear = GETPOST('search_date_limit_endyear', 'int');
  65. $search_date_limit_start = dol_mktime(0, 0, 0, $search_date_limit_startmonth, $search_date_limit_startday, $search_date_limit_startyear);
  66. $search_date_limit_end = dol_mktime(23, 59, 59, $search_date_limit_endmonth, $search_date_limit_endday, $search_date_limit_endyear);
  67. $search_project_ref = GETPOST('search_project_ref', 'alpha');
  68. $search_users = GETPOST('search_users');
  69. $search_type = GETPOST('search_type', 'int');
  70. $search_account = GETPOST('search_account', 'int');
  71. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  72. $sortfield = GETPOST('sortfield', 'aZ09comma');
  73. $sortorder = GETPOST("sortorder", 'aZ09comma');
  74. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  75. if (empty($page) || $page == -1) {
  76. $page = 0; // If $page is not defined, or '' or -1
  77. }
  78. $offset = $limit * $page;
  79. $pageprev = $page - 1;
  80. $pagenext = $page + 1;
  81. if (!$sortfield) {
  82. $sortfield = "cs.date_ech";
  83. }
  84. if (!$sortorder) {
  85. $sortorder = "DESC";
  86. }
  87. $filtre = GETPOST("filtre", 'int');
  88. $arrayfields = array(
  89. 'cs.rowid' =>array('label'=>"Ref", 'checked'=>1, 'position'=>10),
  90. 'cs.libelle' =>array('label'=>"Label", 'checked'=>1, 'position'=>20),
  91. 'cs.fk_type' =>array('label'=>"Type", 'checked'=>1, 'position'=>30),
  92. 'cs.date_ech' =>array('label'=>"Date", 'checked'=>1, 'position'=>40),
  93. 'cs.periode' =>array('label'=>"PeriodEndDate", 'checked'=>1, 'position'=>50),
  94. 'p.ref' =>array('label'=>"ProjectRef", 'checked'=>1, 'position'=>60, 'enable'=>(isModEnabled('project'))),
  95. 'cs.fk_user' =>array('label'=>"Employee", 'checked'=>1, 'position'=>70),
  96. 'cs.fk_mode_reglement' =>array('checked'=>-1, 'position'=>80, 'label'=>"DefaultPaymentMode"),
  97. 'cs.amount' =>array('label'=>"Amount", 'checked'=>1, 'position'=>100),
  98. 'cs.paye' =>array('label'=>"Status", 'checked'=>1, 'position'=>110),
  99. );
  100. if (isModEnabled("banque")) {
  101. $arrayfields['cs.fk_account'] = array('checked'=>-1, 'position'=>90, 'label'=>"DefaultBankAccount");
  102. }
  103. $arrayfields = dol_sort_array($arrayfields, 'position');
  104. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  105. $hookmanager->initHooks(array('sclist'));
  106. $object = new ChargeSociales($db);
  107. // Security check
  108. $socid = GETPOST("socid", 'int');
  109. if ($user->socid) {
  110. $socid = $user->socid;
  111. }
  112. $result = restrictedArea($user, 'tax', '', 'chargesociales', 'charges');
  113. /*
  114. * Actions
  115. */
  116. $parameters = array('socid'=>$socid);
  117. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  118. if ($reshook < 0) {
  119. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  120. }
  121. if (empty($reshook)) {
  122. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  123. // All tests are required to be compatible with all browsers
  124. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  125. $search_ref = '';
  126. $search_label = '';
  127. $search_amount = '';
  128. $search_status = '';
  129. $search_typeid = '';
  130. $search_date_startday = '';
  131. $search_date_startmonth = '';
  132. $search_date_startyear = '';
  133. $search_date_endday = '';
  134. $search_date_endmonth = '';
  135. $search_date_endyear = '';
  136. $search_date_start = '';
  137. $search_date_end = '';
  138. $search_date_limit_startday = '';
  139. $search_date_limit_startmonth = '';
  140. $search_date_limit_startyear = '';
  141. $search_date_limit_endday = '';
  142. $search_date_limit_endmonth = '';
  143. $search_date_limit_endyear = '';
  144. $search_date_limit_start = '';
  145. $search_date_limit_end = '';
  146. $search_project_ref = '';
  147. $search_users = '';
  148. $search_type = '';
  149. $search_account = '';
  150. $search_array_options = array();
  151. }
  152. }
  153. /*
  154. * View
  155. */
  156. $form = new Form($db);
  157. $formother = new FormOther($db);
  158. $bankstatic = new Account($db);
  159. $formsocialcontrib = new FormSocialContrib($db);
  160. $chargesociale_static = new ChargeSociales($db);
  161. if (isModEnabled('project')) {
  162. $projectstatic = new Project($db);
  163. }
  164. llxHeader('', $langs->trans("SocialContributions"));
  165. $sql = "SELECT cs.rowid, cs.fk_type as type, cs.fk_user,";
  166. $sql .= " cs.amount, cs.date_ech, cs.libelle as label, cs.paye, cs.periode, cs.fk_account,";
  167. if (isModEnabled('project')) {
  168. $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
  169. }
  170. $sql .= " c.libelle as type_label, c.accountancy_code as type_accountancy_code,";
  171. $sql .= " ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,";
  172. $sql .= " SUM(pc.amount) as alreadypayed, pay.code as payment_code";
  173. $sqlfields = $sql; // $sql fields to remove for count total
  174. $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
  175. $sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
  176. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (cs.fk_account = ba.rowid)";
  177. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pay ON (cs.fk_mode_reglement = pay.id)';
  178. if (isModEnabled('project')) {
  179. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cs.fk_projet";
  180. }
  181. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
  182. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON (cs.fk_user = u.rowid)";
  183. $sql .= " WHERE cs.fk_type = c.id";
  184. $sql .= " AND cs.entity = ".((int) $conf->entity);
  185. // Search criteria
  186. if ($search_ref) {
  187. $sql .= " AND cs.ref = '".$db->escape($search_ref)."'";
  188. }
  189. if ($search_label) {
  190. $sql .= natural_search("cs.libelle", $search_label);
  191. }
  192. if (isModEnabled('project')) {
  193. if ($search_project_ref != '') {
  194. $sql .= natural_search("p.ref", $search_project_ref);
  195. }
  196. }
  197. if (!empty($search_users)) {
  198. $sql .= ' AND cs.fk_user IN ('.$db->sanitize(implode(', ', $search_users)).')';
  199. }
  200. if (!empty($search_type) && $search_type > 0) {
  201. $sql .= ' AND cs.fk_mode_reglement='.((int) $search_type);
  202. }
  203. if (!empty($search_account) && $search_account > 0) {
  204. $sql .= ' AND cs.fk_account='.((int) $search_account);
  205. }
  206. if ($search_amount) {
  207. $sql .= natural_search("cs.amount", $search_amount, 1);
  208. }
  209. if ($search_status != '' && $search_status >= 0) {
  210. $sql .= " AND cs.paye = ".((int) $search_status);
  211. }
  212. if ($search_date_start) {
  213. $sql .= " AND cs.date_ech >= '".$db->idate($search_date_start)."'";
  214. }
  215. if ($search_date_end) {
  216. $sql .= " AND cs.date_ech <= '".$db->idate($search_date_end)."'";
  217. }
  218. if ($search_date_limit_start) {
  219. $sql .= " AND cs.periode >= '".$db->idate($search_date_limit_start)."'";
  220. }
  221. if ($search_date_limit_end) {
  222. $sql .= " AND cs.periode <= '".$db->idate($search_date_limit_end)."'";
  223. }
  224. if ($search_typeid > 0) {
  225. $sql .= " AND cs.fk_type = ".((int) $search_typeid);
  226. }
  227. $sql .= " GROUP BY cs.rowid, cs.fk_type, cs.fk_user, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, cs.fk_account, c.libelle, c.accountancy_code, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, pay.code, u.lastname";
  228. if (isModEnabled('project')) {
  229. $sql .= ", p.rowid, p.ref, p.title";
  230. }
  231. // Count total nb of records
  232. $nbtotalofrecords = '';
  233. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  234. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  235. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  236. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  237. $resql = $db->query($sqlforcount);
  238. if ($resql) {
  239. $objforcount = $db->fetch_object($resql);
  240. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  241. } else {
  242. dol_print_error($db);
  243. }
  244. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  245. $page = 0;
  246. $offset = 0;
  247. }
  248. $db->free($resql);
  249. }
  250. // Complete request and execute it with limit
  251. $sql .= $db->order($sortfield, $sortorder);
  252. if ($limit) {
  253. $sql .= $db->plimit($limit + 1, $offset);
  254. }
  255. $resql = $db->query($sql);
  256. if (!$resql) {
  257. dol_print_error($db);
  258. llxFooter();
  259. $db->close();
  260. exit;
  261. }
  262. $num = $db->num_rows($resql);
  263. $i = 0;
  264. $param = '';
  265. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  266. $param .= '&contextpage='.urlencode($contextpage);
  267. }
  268. if ($limit > 0 && $limit != $conf->liste_limit) {
  269. $param .= '&limit='.urlencode($limit);
  270. }
  271. if ($search_ref) {
  272. $param .= '&search_ref='.urlencode($search_ref);
  273. }
  274. if ($search_label) {
  275. $param .= '&search_label='.urlencode($search_label);
  276. }
  277. if ($search_project_ref >= 0) {
  278. $param .= "&search_project_ref=".urlencode($search_project_ref);
  279. }
  280. if ($search_amount) {
  281. $param .= '&search_amount='.urlencode($search_amount);
  282. }
  283. if ($search_typeid) {
  284. $param .= '&search_typeid='.urlencode($search_typeid);
  285. }
  286. if ($search_users) {
  287. foreach ($search_users as $id_user) {
  288. $param .= '&search_users[]='.urlencode($id_user);
  289. }
  290. }
  291. if ($search_type) {
  292. $param .= '&search_type='.urlencode($search_type);
  293. }
  294. if ($search_account) {
  295. $param .= '&search_account='.$search_account;
  296. }
  297. if ($search_status != '' && $search_status != '-1') {
  298. $param .= '&search_status='.urlencode($search_status);
  299. }
  300. if ($search_date_startday) {
  301. $param .= '&search_date_startday='.urlencode($search_date_startday);
  302. }
  303. if ($search_date_startmonth) {
  304. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  305. }
  306. if ($search_date_startyear) {
  307. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  308. }
  309. if ($search_date_endday) {
  310. $param .= '&search_date_endday='.urlencode($search_date_endday);
  311. }
  312. if ($search_date_endmonth) {
  313. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  314. }
  315. if ($search_date_endyear) {
  316. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  317. }
  318. if ($search_date_limit_startday) {
  319. $param .= '&search_date_limit_startday='.urlencode($search_date_limit_startday);
  320. }
  321. if ($search_date_limit_startmonth) {
  322. $param .= '&search_date_limit_startmonth='.urlencode($search_date_limit_startmonth);
  323. }
  324. if ($search_date_limit_startyear) {
  325. $param .= '&search_date_limit_startyear='.urlencode($search_date_limit_startyear);
  326. }
  327. if ($search_date_limit_endday) {
  328. $param .= '&search_date_limit_endday='.urlencode($search_date_limit_endday);
  329. }
  330. if ($search_date_limit_endmonth) {
  331. $param .= '&search_date_limit_endmonth='.urlencode($search_date_limit_endmonth);
  332. }
  333. if ($search_date_limit_endyear) {
  334. $param .= '&search_date_limit_endyear='.urlencode($search_date_limit_endyear);
  335. }
  336. $newcardbutton = '';
  337. if ($user->rights->tax->charges->creer) {
  338. $newcardbutton .= dolGetButtonTitle($langs->trans('MenuNewSocialContribution'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/sociales/card.php?action=create');
  339. }
  340. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  341. if ($optioncss != '') {
  342. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  343. }
  344. print '<input type="hidden" name="token" value="'.newToken().'">';
  345. print '<input type="hidden" name="action" value="list">';
  346. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  347. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  348. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  349. print '<input type="hidden" name="search_status" value="'.$search_status.'">';
  350. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  351. $center = '';
  352. print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
  353. if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
  354. print '<div class="error">';
  355. $langs->load("errors");
  356. $countrynotdefined = $langs->trans("ErrorSetACountryFirst");
  357. print $countrynotdefined;
  358. print '</div>';
  359. print '</form>';
  360. llxFooter();
  361. $db->close();
  362. }
  363. $moreforfilter = '';
  364. $massactionbutton = '';
  365. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  366. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  367. if ($massactionbutton) {
  368. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  369. }
  370. print '<div class="div-table-responsive">';
  371. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : '').'">'."\n";
  372. print '<tr class="liste_titre_filter">';
  373. // Filters: Line number (placeholder)
  374. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  375. print '<td class="liste_titre">';
  376. print '</td>';
  377. }
  378. // Filter: Ref
  379. if (!empty($arrayfields['cs.rowid']['checked'])) {
  380. print '<td class="liste_titre">';
  381. print '<input class="flat maxwidth75" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  382. print '</td>';
  383. }
  384. // Filter: Label
  385. if (!empty($arrayfields['cs.rowid']['checked'])) {
  386. print '<td class="liste_titre">';
  387. print '<input type="text" class="flat maxwidth100" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  388. print '</td>';
  389. }
  390. // Filter: Type
  391. if (!empty($arrayfields['cs.fk_type']['checked'])) {
  392. print '<td class="liste_titre">';
  393. $formsocialcontrib->select_type_socialcontrib($search_typeid, 'search_typeid', 1, 0, 0, 'maxwidth150', 1);
  394. print '</td>';
  395. }
  396. // Filter: Date (placeholder)
  397. if (!empty($arrayfields['cs.date_ech']['checked'])) {
  398. print '<td class="liste_titre center">';
  399. print '<div class="nowrap">';
  400. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  401. print '</div>';
  402. print '<div class="nowrap">';
  403. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  404. print '</div>';
  405. print '</td>';
  406. }
  407. // Filter: Period end date
  408. if (!empty($arrayfields['cs.periode']['checked'])) {
  409. print '<td class="liste_titre center">';
  410. print '<div class="nowrap">';
  411. print $form->selectDate($search_date_limit_start ? $search_date_limit_start : -1, 'search_date_limit_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  412. print '</div>';
  413. print '<div class="nowrap">';
  414. print $form->selectDate($search_date_limit_end ? $search_date_limit_end : -1, 'search_date_limit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  415. print '</div>';
  416. print '</td>';
  417. }
  418. // Filter: Project ref
  419. if (!empty($arrayfields['p.ref']['checked'])) {
  420. print '<td class="liste_titre">';
  421. print '<input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'">';
  422. print '</td>';
  423. }
  424. if (!empty($arrayfields['cs.fk_user']['checked'])) {
  425. // Employee
  426. print '<td class="liste_titre">';
  427. print $form->select_dolusers($search_users, 'search_users', 1, null, 0, '', '', '0', 0, 0, '', 0, '', 'maxwidth150', 0, 0, true);
  428. print '</td>';
  429. }
  430. // Filter: Type
  431. if (!empty($arrayfields['cs.fk_mode_reglement']['checked'])) {
  432. print '<td class="liste_titre">';
  433. print $form->select_types_paiements($search_type, 'search_type', '', 0, 1, 1, 0, 1, 'maxwidth150', 1);
  434. print '</td>';
  435. }
  436. // Filter: Bank Account
  437. if (!empty($arrayfields['cs.fk_account']['checked'])) {
  438. print '<td class="liste_titre">';
  439. $form->select_comptes($search_account, 'search_account', 0, '', 1, '', 0, 'maxwidth150');
  440. print '</td>';
  441. }
  442. // Filter: Amount
  443. if (!empty($arrayfields['cs.amount']['checked'])) {
  444. print '<td class="liste_titre right">';
  445. print '<input class="flat maxwidth75" type="text" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
  446. print '</td>';
  447. }
  448. // Filter: Status
  449. if (!empty($arrayfields['cs.paye']['checked'])) {
  450. print '<td class="liste_titre maxwidthonsmartphone right">';
  451. $liststatus = array('0'=>$langs->trans("Unpaid"), '1'=>$langs->trans("Paid"));
  452. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100 onrightofpage', 1);
  453. print '</td>';
  454. }
  455. // Fields from hook
  456. $parameters = array('arrayfields'=>$arrayfields);
  457. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  458. print $hookmanager->resPrint;
  459. // Filter: Buttons
  460. print '<td class="liste_titre maxwidthsearch">';
  461. print $form->showFilterAndCheckAddButtons(0);
  462. print '</td>';
  463. print '</tr>';
  464. print '<tr class="liste_titre">';
  465. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  466. print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  467. }
  468. if (!empty($arrayfields['cs.rowid']['checked'])) {
  469. print_liste_field_titre($arrayfields['cs.rowid']['label'], $_SERVER["PHP_SELF"], "cs.rowid", '', $param, '', $sortfield, $sortorder);
  470. }
  471. if (!empty($arrayfields['cs.libelle']['checked'])) {
  472. print_liste_field_titre($arrayfields['cs.libelle']['label'], $_SERVER["PHP_SELF"], "cs.libelle,cs.periode", '', $param, '', $sortfield, $sortorder);
  473. }
  474. if (!empty($arrayfields['cs.fk_type']['checked'])) {
  475. print_liste_field_titre($arrayfields['cs.fk_type']['label'], $_SERVER["PHP_SELF"], "cs.fk_type,cs.periode", '', $param, '', $sortfield, $sortorder);
  476. }
  477. if (!empty($arrayfields['cs.date_ech']['checked'])) {
  478. print_liste_field_titre($arrayfields['cs.date_ech']['label'], $_SERVER["PHP_SELF"], "cs.date_ech,cs.periode", '', $param, '', $sortfield, $sortorder, 'center ');
  479. }
  480. if (!empty($arrayfields['cs.periode']['checked'])) {
  481. print_liste_field_titre($arrayfields['cs.periode']['label'], $_SERVER["PHP_SELF"], "cs.periode", '', $param, '', $sortfield, $sortorder, 'center ');
  482. }
  483. if (!empty($arrayfields['p.ref']['checked'])) {
  484. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", '', $param, '', $sortfield, $sortorder);
  485. }
  486. if (!empty($arrayfields['cs.fk_user']['checked'])) {
  487. print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.lastname,cs.periode", "", $param, 'class="left"', $sortfield, $sortorder);
  488. }
  489. if (!empty($arrayfields['cs.fk_mode_reglement']['checked'])) {
  490. print_liste_field_titre($arrayfields['cs.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "cs.fk_mode_reglement,cs.periode", '', $param, '', $sortfield, $sortorder);
  491. }
  492. if (!empty($arrayfields['cs.fk_account']['checked'])) {
  493. print_liste_field_titre($arrayfields['cs.fk_account']['label'], $_SERVER["PHP_SELF"], "cs.fk_account,cs.periode", '', $param, '', $sortfield, $sortorder);
  494. }
  495. if (!empty($arrayfields['cs.amount']['checked'])) {
  496. print_liste_field_titre($arrayfields['cs.amount']['label'], $_SERVER["PHP_SELF"], "cs.amount,cs.periode", '', $param, 'class="right"', $sortfield, $sortorder);
  497. }
  498. if (!empty($arrayfields['cs.paye']['checked'])) {
  499. print_liste_field_titre($arrayfields['cs.paye']['label'], $_SERVER["PHP_SELF"], "cs.paye,cs.periode", '', $param, 'class="right"', $sortfield, $sortorder);
  500. }
  501. // Hook fields
  502. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  503. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  504. print $hookmanager->resPrint;
  505. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
  506. print '</tr>';
  507. $i = 0;
  508. $totalarray = $TLoadedUsers = array();
  509. $totalarray['nbfield'] = 0;
  510. $totalarray['val']['totalttcfield'] = 0;
  511. while ($i < min($num, $limit)) {
  512. $obj = $db->fetch_object($resql);
  513. $chargesociale_static->id = $obj->rowid;
  514. $chargesociale_static->ref = $obj->rowid;
  515. $chargesociale_static->label = $obj->label;
  516. $chargesociale_static->type_label = $obj->type_label;
  517. if (isModEnabled('project')) {
  518. $projectstatic->id = $obj->project_id;
  519. $projectstatic->ref = $obj->project_ref;
  520. $projectstatic->title = $obj->project_label;
  521. }
  522. print '<tr class="oddeven">';
  523. // Line number
  524. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  525. print '<td>'.(($offset * $limit) + $i).'</td>';
  526. if (!$i) {
  527. $totalarray['nbfield']++;
  528. }
  529. }
  530. // Ref
  531. if (!empty($arrayfields['cs.rowid']['checked'])) {
  532. print '<td>'.$chargesociale_static->getNomUrl(1, '20').'</td>';
  533. if (!$i) {
  534. $totalarray['nbfield']++;
  535. }
  536. }
  537. // Label
  538. if (!empty($arrayfields['cs.libelle']['checked'])) {
  539. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->label).'">'.dol_escape_htmltag($obj->label).'</td>';
  540. if (!$i) {
  541. $totalarray['nbfield']++;
  542. }
  543. }
  544. // Type
  545. if (!empty($arrayfields['cs.fk_type']['checked'])) {
  546. $typelabeltoshow = $obj->type_label;
  547. $typelabelpopup = $obj->type_label;
  548. if (isModEnabled('accounting')) {
  549. $typelabelpopup .= ' - '.$langs->trans("AccountancyCode").': '.$obj->type_accountancy_code;
  550. }
  551. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($typelabelpopup).'">'.dol_escape_htmltag($typelabeltoshow).'</td>';
  552. if (!$i) {
  553. $totalarray['nbfield']++;
  554. }
  555. }
  556. // Date
  557. if (!empty($arrayfields['cs.date_ech']['checked'])) {
  558. print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
  559. if (!$i) {
  560. $totalarray['nbfield']++;
  561. }
  562. }
  563. // Date end period
  564. if (!empty($arrayfields['cs.periode']['checked'])) {
  565. print '<td class="center nowraponall">'.dol_print_date($db->jdate($obj->periode), 'day').'</td>';
  566. if (!$i) {
  567. $totalarray['nbfield']++;
  568. }
  569. }
  570. // Project ref
  571. if (!empty($arrayfields['p.ref']['checked'])) {
  572. print '<td class="nowraponall">';
  573. if ($obj->project_id > 0) {
  574. print $projectstatic->getNomUrl(1);
  575. }
  576. print '</td>';
  577. if (!$i) {
  578. $totalarray['nbfield']++;
  579. }
  580. }
  581. if (!empty($arrayfields['cs.fk_user']['checked'])) {
  582. // Employee
  583. print '<td class="tdoverflowmax150">';
  584. if (!empty($obj->fk_user)) {
  585. if (!empty($TLoadedUsers[$obj->fk_user])) {
  586. $ustatic = $TLoadedUsers[$obj->fk_user];
  587. } else {
  588. $ustatic = new User($db);
  589. $ustatic->fetch($obj->fk_user);
  590. $TLoadedUsers[$obj->fk_user] = $ustatic;
  591. }
  592. print $ustatic->getNomUrl(-1);
  593. }
  594. print "</td>\n";
  595. if (!$i) {
  596. $totalarray['nbfield']++;
  597. }
  598. }
  599. // Type
  600. if (!empty($arrayfields['cs.fk_mode_reglement']['checked'])) {
  601. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans("PaymentTypeShort".$obj->payment_code)).'">';
  602. if (!empty($obj->payment_code)) {
  603. print $langs->trans("PaymentTypeShort".$obj->payment_code);
  604. }
  605. print '</td>';
  606. if (!$i) {
  607. $totalarray['nbfield']++;
  608. }
  609. }
  610. // Account
  611. if (!empty($arrayfields['cs.fk_account']['checked'])) {
  612. print '<td class="toverflowmax150">';
  613. if ($obj->fk_account > 0) {
  614. $bankstatic->id = $obj->fk_account;
  615. $bankstatic->ref = $obj->bref;
  616. $bankstatic->number = $obj->bnumber;
  617. $bankstatic->iban = $obj->iban;
  618. $bankstatic->bic = $obj->bic;
  619. $bankstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
  620. $bankstatic->account_number = $obj->account_number;
  621. $bankstatic->clos = $obj->clos;
  622. //$accountingjournal->fetch($obj->fk_accountancy_journal);
  623. //$bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  624. $bankstatic->label = $obj->blabel;
  625. print $bankstatic->getNomUrl(1);
  626. }
  627. print '</td>';
  628. if (!$i) $totalarray['nbfield']++;
  629. }
  630. // Amount
  631. if (!empty($arrayfields['cs.amount']['checked'])) {
  632. print '<td class="nowraponall amount right">'.price($obj->amount).'</td>';
  633. if (!$i) {
  634. $totalarray['nbfield']++;
  635. }
  636. if (!$i) {
  637. $totalarray['pos'][$totalarray['nbfield']] = 'totalttcfield';
  638. }
  639. $totalarray['val']['totalttcfield'] += $obj->amount;
  640. }
  641. // Status
  642. if (!empty($arrayfields['cs.paye']['checked'])) {
  643. print '<td class="nowraponall right">'.$chargesociale_static->LibStatut($obj->paye, 5, $obj->alreadypayed).'</td>';
  644. if (!$i) {
  645. $totalarray['nbfield']++;
  646. }
  647. }
  648. // Buttons
  649. print '<td></td>';
  650. if (!$i) {
  651. $totalarray['nbfield']++;
  652. }
  653. print '</tr>'."\n";
  654. $i++;
  655. }
  656. // Show total line
  657. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  658. // If no record found
  659. if ($num == 0) {
  660. $colspan = 1;
  661. foreach ($arrayfields as $key => $val) {
  662. if (!empty($val['checked'])) {
  663. $colspan++;
  664. }
  665. }
  666. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  667. }
  668. $db->free($resql);
  669. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  670. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  671. print $hookmanager->resPrint;
  672. print '</table>'."\n";
  673. print '</div>'."\n";
  674. print '</form>'."\n";
  675. // End of page
  676. llxFooter();
  677. $db->close();