dolibarr  19.0.0-dev
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
32 require '../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
41 if (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');
61 if (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;
67 if (!$sortfield) {
68  $sortfield = "cs.date_ech";
69 }
70 if (!$sortorder) {
71  $sortorder = "DESC";
72 }
73 
74 // Security check
75 if ($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
86 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
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 
109 llxHeader('', $title, $help_url);
110 
111 
112 $param = '';
113 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
114  $param .= '&contextpage='.urlencode($contextpage);
115 }
116 if ($limit > 0 && $limit != $conf->liste_limit) {
117  $param .= '&limit='.((int) $limit);
118 }
119 if ($sortfield) {
120  $param .= '&sortfield='.urlencode($sortfield);
121 }
122 if ($sortorder) {
123  $param .= '&sortorder='.urlencode($sortorder);
124 }
125 if ($year) {
126  $param .= '&year='.urlencode($year);
127 }
128 if ($search_sc_type) {
129  $param .= '&search_sc_type='.urlencode($search_sc_type);
130 }
131 if ($optioncss != '') {
132  $param .= '&optioncss='.urlencode($optioncss);
133 }
134 $num = 0;
135 
136 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
137 if ($optioncss != '') {
138  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
139 }
140 print '<input type="hidden" name="token" value="'.newToken().'">';
141 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
142 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
143 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
144 print '<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").")";
163 if ($search_sc_type > 0) {
164  $sql .= " AND cs.fk_type = ".((int) $search_sc_type);
165 }
166 if ($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 }
174 if (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 = '';
185 if (!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.
194 if (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 = '';
213 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $nav, '', $limit, 0);
214 
215 print '<table class="noborder centpercent">';
216 
217 print '<tr class="liste_titre">';
218 print '<td class="liste_titre"></td>';
219 print '<td class="liste_titre"></td>';
220 print '<td class="liste_titre">';
221 $formsocialcontrib->select_type_socialcontrib(GETPOSTISSET("search_sc_type") ? $search_sc_type : '', 'search_sc_type', 1, 0, 0, 'minwidth200 maxwidth300');
222 print '</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 print '<td class="liste_titre"></td>';
229 if (isModEnabled("banque")) {
230  print '<td class="liste_titre"></td>';
231  print '<td class="liste_titre"></td>';
232 }
233 print '<td class="liste_titre"></td>';
234 print '<td class="liste_titre center">';
235 $searchpicto = $form->showFilterButtons();
236 print $searchpicto;
237 print '</td>';
238 print "</tr>\n";
239 
240 print '<tr class="liste_titre">';
241 print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder);
242 print_liste_field_titre("SocialContribution", $_SERVER["PHP_SELF"], "c.libelle", "", $param, '', $sortfield, $sortorder);
243 print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "cs.fk_type", "", $param, '', $sortfield, $sortorder);
244 print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.periode", "", $param, '', $sortfield, $sortorder, 'center ');
245 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, '', $sortfield, $sortorder, 'center ');
246 print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder);
247 print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
248 print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "pc.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber');
249 if (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 }
253 print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "cs.amount", "", $param, 'class="right"', $sortfield, $sortorder);
254 print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
256 print "</tr>\n";
257 
258 if (!$resql) {
259  dol_print_error($db);
260  exit;
261 }
262 
263 $i = 0;
264 $total = 0;
265 $totalnb = 0;
266 $totalpaid = 0;
267 
268 while ($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->label_sc).'" class="tdoverflowmax300">'.$obj->label_sc.'</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
376 print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
377 print '<td class="liste_total right"></td>'; // A total here has no sense
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 print '<td align="center" class="liste_total">&nbsp;</td>';
383 if (isModEnabled("banque")) {
384  print '<td></td>';
385  print '<td></td>';
386 }
387 print '<td class="liste_total right">'.price($totalpaid)."</td>";
388 print '<td></td>';
389 print "</tr>";
390 
391 print '</table>';
392 
393 
394 print '</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
400 llxFooter();
401 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
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:609
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:5107
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:118
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
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:5530
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:576
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->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') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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:595
restrictedArea
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.
Definition: security.lib.php:353
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
User
Class to manage Dolibarr users.
Definition: user.class.php:47
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:509
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:5295
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1874
Salary
Class to manage salary payments.
Definition: salary.class.php:33
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156
Account
Class to manage bank accounts.
Definition: account.class.php:40
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
Tva
Put here description of your class.
Definition: tva.class.php:35