dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../../main.inc.php';
43require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
44require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
45require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
46require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
47require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
51if (isModEnabled('accounting')) {
52 include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
53}
54
55// Load translation files required by the page
56$langs->loadLangs(array('compta', 'bills', 'hrm'));
57
58// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
59$hookmanager->initHooks(array('specialexpensesindex'));
60
61
62$year = GETPOSTINT("year");
63$search_sc_type = GETPOST('search_sc_type', 'intcomma');
64$optioncss = GETPOST('optioncss', 'alpha');
65
66$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
67$sortfield = GETPOST('sortfield', 'aZ09comma');
68$sortorder = GETPOST('sortorder', 'aZ09comma');
69$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
70if (empty($page) || $page < 0) {
71 $page = 0;
72} // If $page is not defined, or '' or -1
73$offset = $limit * $page;
74$pageprev = $page - 1;
75$pagenext = $page + 1;
76if (!$sortfield) {
77 $sortfield = "cs.date_ech";
78}
79if (!$sortorder) {
80 $sortorder = "DESC";
81}
82
83// Security check
84if ($user->socid) {
85 $socid = $user->socid;
86}
87$result = restrictedArea($user, 'tax', '', 'chargesociales', 'charges');
88
89
90/*
91 * Actions
92 */
93
94// Purge search criteria
95if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
96 $search_sc_type = '';
97 //$toselect = array();
98 //$search_array_options = array();
99}
100
101
102/*
103 * View
104 */
105
106$tva_static = new Tva($db);
107$socialcontrib = new ChargeSociales($db);
108$payment_sc_static = new PaymentSocialContribution($db);
109$userstatic = new User($db);
110$sal_static = new Salary($db);
111$accountstatic = new Account($db);
112$accountlinestatic = new AccountLine($db);
113$formsocialcontrib = new FormSocialContrib($db);
114
115$title = $langs->trans("SocialContributionsPayments");
116$help_url = '';
117
118llxHeader('', $title, $help_url);
119
120
121$param = '';
122if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
123 $param .= '&contextpage='.urlencode($contextpage);
124}
125if ($limit > 0 && $limit != $conf->liste_limit) {
126 $param .= '&limit='.((int) $limit);
127}
128if ($sortfield) {
129 $param .= '&sortfield='.urlencode($sortfield);
130}
131if ($sortorder) {
132 $param .= '&sortorder='.urlencode($sortorder);
133}
134if ($year) {
135 $param .= '&year='.urlencode((string) ($year));
136}
137if ($search_sc_type) {
138 $param .= '&search_sc_type='.urlencode((string) ($search_sc_type));
139}
140if ($optioncss != '') {
141 $param .= '&optioncss='.urlencode($optioncss);
142}
143$num = 0;
144
145print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
146if ($optioncss != '') {
147 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
148}
149print '<input type="hidden" name="token" value="'.newToken().'">';
150print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
151print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
152print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
153print '<input type="hidden" name="page" value="'.$page.'">';
154
155$sql = "SELECT c.id, c.libelle as type_label,";
156$sql .= " cs.rowid, cs.libelle as label_sc, cs.fk_type as type, cs.periode as period, cs.date_ech, cs.amount as total, cs.paye,";
157$sql .= " pc.rowid as pid, pc.datep, pc.amount as totalpaid, pc.num_paiement as num_payment, pc.fk_bank,";
158$sql .= " pct.code as payment_code,";
159$sql .= " u.rowid as uid, u.lastname, u.firstname, u.email, u.login, u.admin, u.statut,";
160$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,";
161$sql .= " aj.label as account_journal";
162$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
163$sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
164$sql .= " INNER JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
165$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id";
166$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid";
167$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
168$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_journal as aj ON ba.fk_accountancy_journal = aj.rowid";
169$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = cs.fk_user";
170$sql .= " WHERE cs.fk_type = c.id";
171$sql .= " AND cs.entity IN (".getEntity("tax").")";
172if ($search_sc_type > 0) {
173 $sql .= " AND cs.fk_type = ".((int) $search_sc_type);
174}
175if ($year > 0) {
176 $sql .= " AND (";
177 // If period defined, we use it as a date criteria, elsewe use the dure date,
178 // so we are compatible with case where period is not mandatory.
179 $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))."')";
180 $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))."')";
181 $sql .= ")";
182}
183if ($sortfield && preg_match('/^(cs|c|pc|pct|u|ba)\./', $sortfield)) {
184 $sql .= $db->order($sortfield, (string) $sortorder);
185}
186
187// Count total nb of records
188$nbtotalofrecords = '';
189$resql = null;
190if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
191 $resql = $db->query($sql);
192 $nbtotalofrecords = $db->num_rows($resql);
193 if (($page * $limit) > (int) $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
194 $page = 0;
195 $offset = 0;
196 }
197}
198// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
199if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
200 $num = $nbtotalofrecords;
201} else {
202 if ($limit) {
203 $sql .= $db->plimit($limit + 1, $offset);
204 }
205
206 $resql = $db->query($sql);
207 if (!$resql) {
208 dol_print_error($db);
209 exit;
210 }
211
212 $num = $db->num_rows($resql);
213}
214//$sql.= $db->plimit($limit+1,$offset);
215//print $sql;
216
217$nav = '';
218print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $nav, '', $limit, 0);
219
220print '<table class="noborder centpercent">';
221
222print '<tr class="liste_titre">';
223print '<td class="liste_titre"></td>';
224print '<td class="liste_titre"></td>';
225print '<td class="liste_titre">';
226$formsocialcontrib->select_type_socialcontrib(GETPOSTISSET("search_sc_type") ? (int) $search_sc_type : 0, 'search_sc_type', 1, 0, 0, 'minwidth200 maxwidth300');
227print '</td>';
228print '<td class="liste_titre"></td>';
229print '<td class="liste_titre"></td>';
230print '<td class="liste_titre"></td>';
231print '<td class="liste_titre"></td>';
232print '<td class="liste_titre"></td>';
233print '<td class="liste_titre"></td>';
234if (isModEnabled("bank")) {
235 print '<td class="liste_titre"></td>';
236 print '<td class="liste_titre"></td>';
237}
238print '<td class="liste_titre"></td>';
239print '<td class="liste_titre center">';
240$searchpicto = $form->showFilterButtons();
241print $searchpicto;
242print '</td>';
243print "</tr>\n";
244
245print '<tr class="liste_titre">';
246print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder);
247print_liste_field_titre("SocialContribution", $_SERVER["PHP_SELF"], "c.libelle", "", $param, '', $sortfield, $sortorder);
248print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "cs.fk_type", "", $param, '', $sortfield, $sortorder);
249print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.periode", "", $param, '', $sortfield, $sortorder, 'center ');
250print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, '', $sortfield, $sortorder, 'center ');
251print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder);
252print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
253print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "pc.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
254if (isModEnabled("bank")) {
255 print_liste_field_titre("BankTransactionLine", $_SERVER["PHP_SELF"], "pc.fk_bank", "", $param, '', $sortfield, $sortorder);
256 print_liste_field_titre("BankAccount", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
257}
258print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "cs.amount", "", $param, 'class="right"', $sortfield, $sortorder);
259print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
261print "</tr>\n";
262
263if (!$resql) {
264 dol_print_error($db);
265 exit;
266}
267
268$i = 0;
269$total = 0;
270$totalnb = 0;
271$totalpaid = 0;
272
273while ($i < min($num, $limit)) {
274 $obj = $db->fetch_object($resql);
275
276 $payment_sc_static->id = $obj->pid;
277 $payment_sc_static->ref = $obj->pid;
278 $payment_sc_static->datep = $db->jdate($obj->datep);
279
280 $socialcontrib->id = $obj->rowid;
281 $socialcontrib->ref = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc;
282 $socialcontrib->paye = $obj->paye;
283 // $obj->label_sc is label of social contribution (may be empty)
284 // $obj->type_label is label of type of social contribution
285 $socialcontrib->label = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc;
286 $socialcontrib->type_label = $obj->type_label;
287
288 print '<tr class="oddeven">';
289 // Ref payment
290 print '<td class="nowraponall">'.$payment_sc_static->getNomUrl(1)."</td>\n";
291 // Label
292 print '<td class="tdoverflowmax250">';
293 print $socialcontrib->getNomUrl(1, '');
294 print '</td>';
295 // Type
296 print '<td title="'.dolPrintHTMLForAttribute($obj->type_label).'" class="tdoverflowmax300">'.dolPrintHTML($obj->type_label).'</td>';
297 // Date
298 $date = $obj->period;
299 if (empty($date)) {
300 $date = $obj->date_ech;
301 }
302 print '<td class="center">'.dol_print_date($date, 'day').'</td>';
303 // Date payment
304 print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day').'</td>';
305
306 // Employee
307 print "<td>";
308 if (!empty($obj->uid)) {
309 $userstatic->id = $obj->uid;
310 $userstatic->lastname = $obj->lastname;
311 $userstatic->firstname = $obj->firstname;
312 $userstatic->admin = $obj->admin;
313 $userstatic->login = $obj->login;
314 $userstatic->email = $obj->email;
315 $userstatic->status = $obj->statut;
316 print $userstatic->getNomUrl(1);
317 print "</td>\n";
318 }
319
320 // Type payment
321 $labelpayment = '';
322 if ($obj->payment_code) {
323 $labelpayment = $langs->trans("PaymentTypeShort".$obj->payment_code);
324 }
325 print '<td class="tdoverflowmax150" title="'.$labelpayment.'">';
326 print $labelpayment;
327 print '</td>';
328
329 print '<td>'.$obj->num_payment.'</td>';
330
331 // Account
332 if (isModEnabled("bank")) {
333 // Bank transaction
334 print '<td class="nowraponall">';
335 $accountlinestatic->id = $obj->fk_bank;
336 print $accountlinestatic->getNomUrl(1);
337 print '</td>';
338
339 print '<td class="nowraponall">';
340 if ($obj->bid > 0) {
341 $accountstatic->id = $obj->bid;
342 $accountstatic->ref = $obj->bref;
343 $accountstatic->number = $obj->bnumber;
344 $accountstatic->label = $obj->blabel;
345 $accountstatic->iban = $obj->iban;
346 $accountstatic->bic = $obj->bic;
347 $accountstatic->currency_code = $langs->trans("Currency".$obj->currency_code);
348 $accountstatic->clos = $obj->clos;
349
350 if (isModEnabled('accounting')) {
351 $accountstatic->account_number = $obj->account_number;
352 $accountstatic->accountancy_journal = $obj->account_journal;
353 }
354 print $accountstatic->getNomUrl(1);
355 } else {
356 print '&nbsp;';
357 }
358 print '</td>';
359 }
360
361 // Expected to pay
362 print '<td class="right"><span class="amount">'.price($obj->total).'</span></td>';
363
364 // Paid
365 print '<td class="right">';
366 if ($obj->totalpaid) {
367 print '<span class="amount">'.price($obj->totalpaid).'</span>';
368 }
369 print '</td>';
370
371 print '<td></td>';
372
373 print '</tr>';
374
375 $total += $obj->total;
376 $totalpaid += $obj->totalpaid;
377 $i++;
378}
379
380// Total
381print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
382print '<td class="liste_total right"></td>'; // A total here has no sense
383print '<td align="center" class="liste_total">&nbsp;</td>';
384print '<td align="center" class="liste_total">&nbsp;</td>';
385print '<td align="center" class="liste_total">&nbsp;</td>';
386print '<td align="center" class="liste_total">&nbsp;</td>';
387print '<td align="center" class="liste_total">&nbsp;</td>';
388if (isModEnabled("bank")) {
389 print '<td></td>';
390 print '<td></td>';
391}
392print '<td class="liste_total right">'.price($totalpaid)."</td>";
393print '<td></td>';
394print "</tr>";
395
396print '</table>';
397
398
399print '</form>';
400
401$parameters = array('user' => $user);
402$reshook = $hookmanager->executeHooks('dashboardSpecialBills', $parameters, $object); // Note that $action and $object may have been modified by hook
403
404// End of page
405llxFooter();
406$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage bank transaction lines.
Class for managing the social charges.
Class to manage generation of HTML components for social contributions management.
Class to manage payments of social contributions.
Class to manage salary payments.
Class to manage VAT - Value-added tax (also known in French as TVA)
Definition tva.class.php:39
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:626
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:645
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.