dolibarr 19.0.3
payments.php
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-2022 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
31// Load Dolibarr environment
32require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
34require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
37require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
41if (isModEnabled('accounting')) {
42 include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
43}
44
45$hookmanager = new HookManager($db);
46
47// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
48$hookmanager->initHooks(array('specialexpensesindex'));
49
50// Load translation files required by the page
51$langs->loadLangs(array('compta', 'bills', 'hrm'));
52
53$year = GETPOST("year", 'int');
54$search_sc_type = GETPOST('search_sc_type', 'int');
55$optioncss = GETPOST('optioncss', 'alpha');
56
57$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
58$sortfield = GETPOST('sortfield', 'aZ09comma');
59$sortorder = GETPOST('sortorder', 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61if (empty($page) || $page < 0) {
62 $page = 0;
63} // If $page is not defined, or '' or -1
64$offset = $limit * $page;
65$pageprev = $page - 1;
66$pagenext = $page + 1;
67if (!$sortfield) {
68 $sortfield = "cs.date_ech";
69}
70if (!$sortorder) {
71 $sortorder = "DESC";
72}
73
74// Security check
75if ($user->socid) {
76 $socid = $user->socid;
77}
78$result = restrictedArea($user, 'tax', '', 'chargesociales', 'charges');
79
80
81/*
82 * Actions
83 */
84
85// Purge search criteria
86if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
87 $search_sc_type = '';
88 //$toselect = array();
89 //$search_array_options = array();
90}
91
92
93/*
94 * View
95 */
96
97$tva_static = new Tva($db);
98$socialcontrib = new ChargeSociales($db);
99$payment_sc_static = new PaymentSocialContribution($db);
100$userstatic = new User($db);
101$sal_static = new Salary($db);
102$accountstatic = new Account($db);
103$accountlinestatic = new AccountLine($db);
104$formsocialcontrib = new FormSocialContrib($db);
105
106$title = $langs->trans("SocialContributionsPayments");
107$help_url = '';
108
109llxHeader('', $title, $help_url);
110
111
112$param = '';
113if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
114 $param .= '&contextpage='.urlencode($contextpage);
115}
116if ($limit > 0 && $limit != $conf->liste_limit) {
117 $param .= '&limit='.((int) $limit);
118}
119if ($sortfield) {
120 $param .= '&sortfield='.urlencode($sortfield);
121}
122if ($sortorder) {
123 $param .= '&sortorder='.urlencode($sortorder);
124}
125if ($year) {
126 $param .= '&year='.urlencode($year);
127}
128if ($search_sc_type) {
129 $param .= '&search_sc_type='.urlencode($search_sc_type);
130}
131if ($optioncss != '') {
132 $param .= '&optioncss='.urlencode($optioncss);
133}
134$num = 0;
135
136print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
137if ($optioncss != '') {
138 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
139}
140print '<input type="hidden" name="token" value="'.newToken().'">';
141print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
142print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
143print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
144print '<input type="hidden" name="page" value="'.$page.'">';
145
146$sql = "SELECT c.id, c.libelle as type_label,";
147$sql .= " cs.rowid, cs.libelle as label_sc, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total, cs.paye,";
148$sql .= " pc.rowid as pid, pc.datep, pc.amount as totalpaid, pc.num_paiement as num_payment, pc.fk_bank,";
149$sql .= " pct.code as payment_code,";
150$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.login, u.admin, u.statut,";
151$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,";
152$sql .= " aj.label as account_journal";
153$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
154$sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
155$sql .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
156$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id";
157$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid";
158$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
159$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_journal as aj ON ba.fk_accountancy_journal = aj.rowid";
160$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = cs.fk_user";
161$sql .= " WHERE cs.fk_type = c.id";
162$sql .= " AND cs.entity IN (".getEntity("tax").")";
163if ($search_sc_type > 0) {
164 $sql .= " AND cs.fk_type = ".((int) $search_sc_type);
165}
166if ($year > 0) {
167 $sql .= " AND (";
168 // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
169 // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
170 $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))."')";
171 $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))."')";
172 $sql .= ")";
173}
174if (preg_match('/^cs\./', $sortfield)
175 || preg_match('/^c\./', $sortfield)
176 || preg_match('/^pc\./', $sortfield)
177 || preg_match('/^pct\./', $sortfield)
178 || preg_match('/^u\./', $sortfield)
179 || preg_match('/^ba\./', $sortfield)) {
180 $sql .= $db->order($sortfield, $sortorder);
181}
182
183// Count total nb of records
184$nbtotalofrecords = '';
185if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
186 $resql = $db->query($sql);
187 $nbtotalofrecords = $db->num_rows($resql);
188 if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
189 $page = 0;
190 $offset = 0;
191 }
192}
193// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
194if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
195 $num = $nbtotalofrecords;
196} else {
197 if ($limit) {
198 $sql .= $db->plimit($limit + 1, $offset);
199 }
200
201 $resql = $db->query($sql);
202 if (!$resql) {
203 dol_print_error($db);
204 exit;
205 }
206
207 $num = $db->num_rows($resql);
208}
209//$sql.= $db->plimit($limit+1,$offset);
210//print $sql;
211
212$nav = '';
213print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $nav, '', $limit, 0);
214
215print '<table class="noborder centpercent">';
216
217print '<tr class="liste_titre">';
218print '<td class="liste_titre"></td>';
219print '<td class="liste_titre"></td>';
220print '<td class="liste_titre">';
221$formsocialcontrib->select_type_socialcontrib(GETPOSTISSET("search_sc_type") ? $search_sc_type : '', 'search_sc_type', 1, 0, 0, 'minwidth200 maxwidth300');
222print '</td>';
223print '<td class="liste_titre"></td>';
224print '<td class="liste_titre"></td>';
225print '<td class="liste_titre"></td>';
226print '<td class="liste_titre"></td>';
227print '<td class="liste_titre"></td>';
228print '<td class="liste_titre"></td>';
229if (isModEnabled("banque")) {
230 print '<td class="liste_titre"></td>';
231 print '<td class="liste_titre"></td>';
232}
233print '<td class="liste_titre"></td>';
234print '<td class="liste_titre center">';
235$searchpicto = $form->showFilterButtons();
236print $searchpicto;
237print '</td>';
238print "</tr>\n";
239
240print '<tr class="liste_titre">';
241print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder);
242print_liste_field_titre("SocialContribution", $_SERVER["PHP_SELF"], "c.libelle", "", $param, '', $sortfield, $sortorder);
243print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "cs.fk_type", "", $param, '', $sortfield, $sortorder);
244print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.periode", "", $param, '', $sortfield, $sortorder, 'center ');
245print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, '', $sortfield, $sortorder, 'center ');
246print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder);
247print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
248print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "pc.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
249if (isModEnabled("banque")) {
250 print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "pc.fk_bank", "", $param, '', $sortfield, $sortorder);
251 print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
252}
253print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "cs.amount", "", $param, 'class="right"', $sortfield, $sortorder);
254print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
256print "</tr>\n";
257
258if (!$resql) {
259 dol_print_error($db);
260 exit;
261}
262
263$i = 0;
264$total = 0;
265$totalnb = 0;
266$totalpaid = 0;
267
268while ($i < min($num, $limit)) {
269 $obj = $db->fetch_object($resql);
270
271 $payment_sc_static->id = $obj->pid;
272 $payment_sc_static->ref = $obj->pid;
273 $payment_sc_static->datep = $db->jdate($obj->datep);
274
275 $socialcontrib->id = $obj->rowid;
276 $socialcontrib->ref = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc;
277 $socialcontrib->paye = $obj->paye;
278 // $obj->label_sc is label of social contribution (may be empty)
279 // $obj->type_label is label of type of social contribution
280 $socialcontrib->label = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc;
281 $socialcontrib->type_label = $obj->type_label;
282
283 print '<tr class="oddeven">';
284 // Ref payment
285 print '<td class="nowraponall">'.$payment_sc_static->getNomUrl(1)."</td>\n";
286 // Label
287 print '<td class="tdoverflowmax250">';
288 print $socialcontrib->getNomUrl(1, '');
289 print '</td>';
290 // Type
291 print '<td title="'.dol_escape_htmltag($obj->type_label).'" class="tdoverflowmax300">'.$obj->type_label.'</td>';
292 // Date
293 $date = $obj->periode;
294 if (empty($date)) {
295 $date = $obj->date_ech;
296 }
297 print '<td class="center">'.dol_print_date($date, 'day').'</td>';
298 // Date payment
299 print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day').'</td>';
300
301 // Employee
302 print "<td>";
303 if (!empty($obj->uid)) {
304 $userstatic->id = $obj->uid;
305 $userstatic->lastname = $obj->lastname;
306 $userstatic->firstname = $obj->firstname;
307 $userstatic->admin = $obj->admin;
308 $userstatic->login = $obj->login;
309 $userstatic->email = $obj->email;
310 $userstatic->statut = $obj->statut;
311 print $userstatic->getNomUrl(1);
312 print "</td>\n";
313 }
314
315 // Type payment
316 $labelpayment = '';
317 if ($obj->payment_code) {
318 $labelpayment = $langs->trans("PaymentTypeShort".$obj->payment_code);
319 }
320 print '<td class="tdoverflowmax150" title="'.$labelpayment.'">';
321 print $labelpayment;
322 print '</td>';
323
324 print '<td>'.$obj->num_payment.'</td>';
325
326 // Account
327 if (isModEnabled("banque")) {
328 // Bank transaction
329 print '<td class="nowraponall">';
330 $accountlinestatic->id = $obj->fk_bank;
331 print $accountlinestatic->getNomUrl(1);
332 print '</td>';
333
334 print '<td class="nowraponall">';
335 if ($obj->bid > 0) {
336 $accountstatic->id = $obj->bid;
337 $accountstatic->ref = $obj->bref;
338 $accountstatic->number = $obj->bnumber;
339 $accountstatic->label = $obj->blabel;
340 $accountstatic->iban = $obj->iban;
341 $accountstatic->bic = $obj->bic;
342 $accountstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
343 $accountstatic->clos = $obj->clos;
344
345 if (isModEnabled('accounting')) {
346 $accountstatic->account_number = $obj->account_number;
347 $accountstatic->accountancy_journal = $obj->account_journal;
348 }
349 print $accountstatic->getNomUrl(1);
350 } else {
351 print '&nbsp;';
352 }
353 print '</td>';
354 }
355
356 // Expected to pay
357 print '<td class="right"><span class="amount">'.price($obj->total).'</span></td>';
358
359 // Paid
360 print '<td class="right">';
361 if ($obj->totalpaid) {
362 print '<span class="amount">'.price($obj->totalpaid).'</span>';
363 }
364 print '</td>';
365
366 print '<td></td>';
367
368 print '</tr>';
369
370 $total = $total + $obj->total;
371 $totalpaid = $totalpaid + $obj->totalpaid;
372 $i++;
373}
374
375// Total
376print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
377print '<td class="liste_total right"></td>'; // A total here has no sense
378print '<td align="center" class="liste_total">&nbsp;</td>';
379print '<td align="center" class="liste_total">&nbsp;</td>';
380print '<td align="center" class="liste_total">&nbsp;</td>';
381print '<td align="center" class="liste_total">&nbsp;</td>';
382print '<td align="center" class="liste_total">&nbsp;</td>';
383if (isModEnabled("banque")) {
384 print '<td></td>';
385 print '<td></td>';
386}
387print '<td class="liste_total right">'.price($totalpaid)."</td>";
388print '<td></td>';
389print "</tr>";
390
391print '</table>';
392
393
394print '</form>';
395
396$parameters = array('user' => $user);
397$reshook = $hookmanager->executeHooks('dashboardSpecialBills', $parameters, $object); // Note that $action and $object may have been modified by hook
398
399// End of page
400llxFooter();
401$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage bank accounts.
Class to manage bank transaction lines.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Class to manage generation of HTML components for social contributions management.
Class to manage hooks.
Class to manage payments of social contributions.
Class to manage salary payments.
Put here description of your class.
Definition tva.class.php:36
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:593
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:612
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.