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