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