payments.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. * Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  9. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.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/charges/index.php
  26. * \ingroup compta
  27. * \brief Page to list payments of special expenses
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
  38. $hookmanager = new HookManager($db);
  39. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  40. $hookmanager->initHooks(array('specialexpensesindex'));
  41. // Load translation files required by the page
  42. $langs->loadLangs(array('compta', 'bills', 'hrm'));
  43. $year = GETPOST("year", 'int');
  44. $search_sc_type = GETPOST('search_sc_type', 'int');
  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) {
  50. $page = 0;
  51. } // If $page is not defined, or '' or -1
  52. $offset = $limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. if (!$sortfield) {
  56. $sortfield = "cs.date_ech";
  57. }
  58. if (!$sortorder) {
  59. $sortorder = "DESC";
  60. }
  61. // Security check140px
  62. if ($user->socid) {
  63. $socid = $user->socid;
  64. }
  65. $result = restrictedArea($user, 'tax', '', 'chargesociales', 'charges');
  66. /*
  67. * Actions
  68. */
  69. // Purge search criteria
  70. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  71. $search_sc_type = '';
  72. //$toselect = '';
  73. //$search_array_options = array();
  74. }
  75. /*
  76. * View
  77. */
  78. $tva_static = new Tva($db);
  79. $socialcontrib = new ChargeSociales($db);
  80. $payment_sc_static = new PaymentSocialContribution($db);
  81. $userstatic = new User($db);
  82. $sal_static = new Salary($db);
  83. $accountstatic = new Account($db);
  84. $accountlinestatic = new AccountLine($db);
  85. $formsocialcontrib = new FormSocialContrib($db);
  86. $title = $langs->trans("SocialContributionsPayments");
  87. $help_url = '';
  88. llxHeader('', $title, $help_url);
  89. $param = '';
  90. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  91. $param .= '&contextpage='.urlencode($contextpage);
  92. }
  93. if ($limit > 0 && $limit != $conf->liste_limit) {
  94. $param .= '&limit='.urlencode($limit);
  95. }
  96. if ($sortfield) {
  97. $param .= '&sortfield='.urlencode($sortfield);
  98. }
  99. if ($sortorder) {
  100. $param .= '&sortorder='.urlencode($sortorder);
  101. }
  102. if ($year) {
  103. $param .= '&year='.urlencode($year);
  104. }
  105. if ($search_sc_type) {
  106. $param .= '&search_sc_type='.urlencode($search_sc_type);
  107. }
  108. $num = 0;
  109. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  110. if ($optioncss != '') {
  111. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  112. }
  113. print '<input type="hidden" name="token" value="'.newToken().'">';
  114. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  115. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  116. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  117. print '<input type="hidden" name="page" value="'.$page.'">';
  118. $sql = "SELECT c.id, c.libelle as type_label,";
  119. $sql .= " cs.rowid, cs.libelle as label_sc, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total, cs.paye,";
  120. $sql .= " pc.rowid as pid, pc.datep, pc.amount as totalpaye, pc.num_paiement as num_payment, pc.fk_bank,";
  121. $sql .= " pct.code as payment_code,";
  122. $sql .= " u.rowid uid, u.lastname, u.firstname, u.email, u.login, u.admin,";
  123. $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";
  124. $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
  125. $sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
  126. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
  127. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id";
  128. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid";
  129. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  130. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = cs.fk_user";
  131. $sql .= " WHERE cs.fk_type = c.id";
  132. $sql .= " AND cs.entity IN (".getEntity("tax").")";
  133. if ($search_sc_type > 0) {
  134. $sql .= " AND cs.fk_type = ".((int) $search_sc_type);
  135. }
  136. if ($year > 0) {
  137. $sql .= " AND (";
  138. // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
  139. // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
  140. $sql .= " (cs.periode IS NOT NULL AND cs.periode between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
  141. $sql .= " OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')";
  142. $sql .= ")";
  143. }
  144. if (preg_match('/^cs\./', $sortfield)
  145. || preg_match('/^c\./', $sortfield)
  146. || preg_match('/^pc\./', $sortfield)
  147. || preg_match('/^pct\./', $sortfield)
  148. || preg_match('/^u\./', $sortfield)
  149. || preg_match('/^ba\./', $sortfield)) {
  150. $sql .= $db->order($sortfield, $sortorder);
  151. }
  152. // Count total nb of records
  153. $nbtotalofrecords = '';
  154. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  155. $resql = $db->query($sql);
  156. $nbtotalofrecords = $db->num_rows($resql);
  157. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  158. $page = 0;
  159. $offset = 0;
  160. }
  161. }
  162. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  163. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  164. $num = $nbtotalofrecords;
  165. } else {
  166. if ($limit) {
  167. $sql .= $db->plimit($limit + 1, $offset);
  168. }
  169. $resql = $db->query($sql);
  170. if (!$resql) {
  171. dol_print_error($db);
  172. exit;
  173. }
  174. $num = $db->num_rows($resql);
  175. }
  176. //$sql.= $db->plimit($limit+1,$offset);
  177. //print $sql;
  178. $nav = '';
  179. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $nav, '', $limit, 0);
  180. print '<table class="noborder centpercent">';
  181. print '<tr class="liste_titre">';
  182. print '<td class="liste_titre"></td>';
  183. print '<td class="liste_titre"></td>';
  184. print '<td class="liste_titre">';
  185. $formsocialcontrib->select_type_socialcontrib(GETPOSTISSET("search_sc_type") ? $search_sc_type : '', 'search_sc_type', 1, 0, 0, 'minwidth200 maxwidth300');
  186. print '</td>';
  187. print '<td class="liste_titre"></td>';
  188. print '<td class="liste_titre"></td>';
  189. print '<td class="liste_titre"></td>';
  190. print '<td class="liste_titre"></td>';
  191. print '<td class="liste_titre"></td>';
  192. print '<td class="liste_titre"></td>';
  193. if (!empty($conf->banque->enabled)) {
  194. print '<td class="liste_titre"></td>';
  195. print '<td class="liste_titre"></td>';
  196. }
  197. print '<td class="liste_titre"></td>';
  198. print '<td class="liste_titre center">';
  199. $searchpicto = $form->showFilterButtons();
  200. print $searchpicto;
  201. print '</td>';
  202. print "</tr>\n";
  203. print '<tr class="liste_titre">';
  204. print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder);
  205. print_liste_field_titre("SocialContribution", $_SERVER["PHP_SELF"], "c.libelle", "", $param, '', $sortfield, $sortorder);
  206. print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "cs.fk_type", "", $param, '', $sortfield, $sortorder);
  207. print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.periode", "", $param, '', $sortfield, $sortorder, 'center ');
  208. print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, '', $sortfield, $sortorder, 'center ');
  209. print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder);
  210. print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
  211. print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "pc.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
  212. if (!empty($conf->banque->enabled)) {
  213. print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "pc.fk_bank", "", $param, '', $sortfield, $sortorder);
  214. print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
  215. }
  216. print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "cs.amount", "", $param, 'class="right"', $sortfield, $sortorder);
  217. print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
  218. print_liste_field_titre('');
  219. print "</tr>\n";
  220. if (!$resql) {
  221. dol_print_error($db);
  222. exit;
  223. }
  224. $i = 0;
  225. $total = 0;
  226. $totalnb = 0;
  227. $totalpaye = 0;
  228. while ($i < min($num, $limit)) {
  229. $obj = $db->fetch_object($resql);
  230. $payment_sc_static->id = $obj->pid;
  231. $payment_sc_static->ref = $obj->pid;
  232. $payment_sc_static->date = $db->jdate($obj->datep);
  233. $socialcontrib->id = $obj->rowid;
  234. $socialcontrib->ref = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc;
  235. $socialcontrib->paye = $obj->paye;
  236. // $obj->label_sc is label of social contribution (may be empty)
  237. // $obj->type_label is label of type of social contribution
  238. $socialcontrib->label = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc;
  239. $socialcontrib->type_label = $obj->type_label;
  240. print '<tr class="oddeven">';
  241. // Ref payment
  242. print '<td class="nowraponall">'.$payment_sc_static->getNomUrl(1)."</td>\n";
  243. // Label
  244. print '<td class="tdoverflowmax250">';
  245. print $socialcontrib->getNomUrl(1, '');
  246. print '</td>';
  247. // Type
  248. print '<td title="'.dol_escape_htmltag($obj->label).'" class="tdoverflowmax300">'.$obj->label.'</td>';
  249. // Date
  250. $date = $obj->periode;
  251. if (empty($date)) {
  252. $date = $obj->date_ech;
  253. }
  254. print '<td class="center">'.dol_print_date($date, 'day').'</td>';
  255. // Date payment
  256. print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day').'</td>';
  257. // Employee
  258. print "<td>";
  259. if (!empty($obj->uid)) {
  260. $userstatic->id = $obj->uid;
  261. $userstatic->lastname = $obj->lastname;
  262. $userstatic->firstname = $obj->firstname;
  263. $userstatic->admin = $obj->admin;
  264. $userstatic->login = $obj->login;
  265. $userstatic->email = $obj->email;
  266. $userstatic->socid = $obj->fk_soc;
  267. $userstatic->statut = $obj->status;
  268. print $userstatic->getNomUrl(1);
  269. print "</td>\n";
  270. }
  271. // Type payment
  272. $labelpayment = '';
  273. if ($obj->payment_code) {
  274. $labelpayment = $langs->trans("PaymentTypeShort".$obj->payment_code);
  275. }
  276. print '<td class="tdoverflowmax150" title="'.$labelpayment.'">';
  277. print $labelpayment;
  278. print '</td>';
  279. print '<td>'.$obj->num_payment.'</td>';
  280. // Account
  281. if (!empty($conf->banque->enabled)) {
  282. // Bank transaction
  283. print '<td class="nowraponall">';
  284. $accountlinestatic->id = $obj->fk_bank;
  285. print $accountlinestatic->getNomUrl(1);
  286. print '</td>';
  287. print '<td class="nowraponall">';
  288. if ($obj->bid > 0) {
  289. $accountstatic->id = $obj->bid;
  290. $accountstatic->ref = $obj->bref;
  291. $accountstatic->number = $obj->bnumber;
  292. $accountstatic->accountancy_number = $obj->account_number;
  293. $accountstatic->accountancy_journal = $obj->accountancy_journal;
  294. $accountstatic->label = $obj->blabel;
  295. $accountstatic->iban = $obj->iban;
  296. $accountstatic->bic = $obj->bic;
  297. $accountstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
  298. $accountstatic->clos = $obj->clos;
  299. print $accountstatic->getNomUrl(1);
  300. } else {
  301. print '&nbsp;';
  302. }
  303. print '</td>';
  304. }
  305. // Expected to pay
  306. print '<td class="right"><span class="amount">'.price($obj->total).'</span></td>';
  307. // Paid
  308. print '<td class="right">';
  309. if ($obj->totalpaye) {
  310. print '<span class="amount">'.price($obj->totalpaye).'</span>';
  311. }
  312. print '</td>';
  313. print '<td></td>';
  314. print '</tr>';
  315. $total = $total + $obj->total;
  316. $totalnb = $totalnb + $obj->nb;
  317. $totalpaye = $totalpaye + $obj->totalpaye;
  318. $i++;
  319. }
  320. // Total
  321. print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
  322. print '<td class="liste_total right"></td>'; // A total here has no sense
  323. print '<td align="center" class="liste_total">&nbsp;</td>';
  324. print '<td align="center" class="liste_total">&nbsp;</td>';
  325. print '<td align="center" class="liste_total">&nbsp;</td>';
  326. print '<td align="center" class="liste_total">&nbsp;</td>';
  327. print '<td align="center" class="liste_total">&nbsp;</td>';
  328. if (!empty($conf->banque->enabled)) {
  329. print '<td></td>';
  330. print '<td></td>';
  331. }
  332. print '<td class="liste_total right">'.price($totalpaye)."</td>";
  333. print '<td></td>';
  334. print "</tr>";
  335. print '</table>';
  336. print '</form>';
  337. $parameters = array('user' => $user);
  338. $reshook = $hookmanager->executeHooks('dashboardSpecialBills', $parameters, $object); // Note that $action and $object may have been modified by hook
  339. // End of page
  340. llxFooter();
  341. $db->close();