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