dolibarr  13.0.2
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-2016 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  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
38 
39 
40 $hookmanager = new HookManager($db);
41 
42 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
43 $hookmanager->initHooks(array('specialexpensesindex'));
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array('compta', 'bills'));
47 
48 // Security check
49 if ($user->socid) $socid = $user->socid;
50 $result = restrictedArea($user, 'tax|salaries', '', '', 'charges|');
51 
52 $year = GETPOST("year", 'int');
53 $search_sc_type = GETPOST('search_sc_type', 'int');
54 
55 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
56 $sortfield = GETPOST("sortfield", 'alpha');
57 $sortorder = GETPOST("sortorder", 'alpha');
58 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
59 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
60 $offset = $limit * $page;
61 $pageprev = $page - 1;
62 $pagenext = $page + 1;
63 if (!$sortfield) $sortfield = "cs.date_ech";
64 if (!$sortorder) $sortorder = "DESC";
65 
66 if (empty($conf->tax->enabled) || empty($user->rights->tax->charges->lire))
67 {
69 }
70 
71 
72 /*
73  * Actions
74  */
75 
76 // Purge search criteria
77 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
78 {
79  $search_sc_type = '';
80  //$toselect = '';
81  //$search_array_options = array();
82 }
83 
84 
85 /*
86  * View
87  */
88 
89 $tva_static = new Tva($db);
90 $socialcontrib = new ChargeSociales($db);
91 $payment_sc_static = new PaymentSocialContribution($db);
92 $sal_static = new PaymentSalary($db);
93 $accountstatic = new Account($db);
94 $formsocialcontrib = new FormSocialContrib($db);
95 
96 $title = $langs->trans("SocialContributionsPayments");
97 
98 llxHeader('', $title);
99 
100 
101 $param = '';
102 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
103 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
104 if ($sortfield) $param .= '&sortfield='.urlencode($sortfield);
105 if ($sortorder) $param .= '&sortorder='.urlencode($sortorder);
106 if ($year) $param .= '&year='.urlencode($year);
107 if ($search_sc_type) $param .= '&search_sc_type='.urlencode($search_sc_type);
108 $num = 0;
109 
110 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
111 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
112 print '<input type="hidden" name="token" value="'.newToken().'">';
113 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
114 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
115 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
116 print '<input type="hidden" name="page" value="'.$page.'">';
117 
118 $sql = "SELECT c.id, c.libelle as label,";
119 $sql .= " cs.rowid, cs.libelle, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total,";
120 $sql .= " pc.rowid as pid, pc.datep, pc.amount as totalpaye, pc.num_paiement as num_payment, pc.fk_bank,";
121 $sql .= " pct.code as payment_code,";
122 $sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel";
123 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
124 $sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
125 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid";
126 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON pc.fk_typepaiement = pct.id";
127 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON pc.fk_bank = b.rowid";
128 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
129 $sql .= " WHERE cs.fk_type = c.id";
130 $sql .= " AND cs.entity IN (".getEntity("tax").")";
131 if ($search_sc_type > 0) {
132  $sql .= " AND cs.fk_type = ".((int) $search_sc_type);
133 }
134 if ($year > 0) {
135  $sql .= " AND (";
136  // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance,
137  // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire
138  $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))."')";
139  $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))."')";
140  $sql .= ")";
141 }
142 if (preg_match('/^cs\./', $sortfield) || preg_match('/^c\./', $sortfield) || preg_match('/^pc\./', $sortfield) || preg_match('/^pct\./', $sortfield)) {
143  $sql .= $db->order($sortfield, $sortorder);
144 }
145 
146 // Count total nb of records
147 $nbtotalofrecords = '';
148 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
149  $resql = $db->query($sql);
150  $nbtotalofrecords = $db->num_rows($resql);
151  if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
152  $page = 0;
153  $offset = 0;
154  }
155 }
156 // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
157 if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
158  $num = $nbtotalofrecords;
159 } else {
160  if ($limit) $sql .= $db->plimit($limit + 1, $offset);
161 
162  $resql = $db->query($sql);
163  if (!$resql) {
164  dol_print_error($db);
165  exit;
166  }
167 
168  $num = $db->num_rows($resql);
169 }
170 //$sql.= $db->plimit($limit+1,$offset);
171 //print $sql;
172 
173 $nav = '';
174 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $nav, '', $limit, 0);
175 
176 print '<table class="noborder centpercent">';
177 
178 print '<tr class="liste_titre">';
179 print '<td class="liste_titre"></td>';
180 print '<td class="liste_titre"></td>';
181 print '<td class="liste_titre">';
182 $formsocialcontrib->select_type_socialcontrib(GETPOSTISSET("search_sc_type") ? $search_sc_type : '', 'search_sc_type', 1, 0, 0, 'minwidth200 maxwidth300');
183 print '</td>';
184 print '<td class="liste_titre"></td>';
185 print '<td class="liste_titre"></td>';
186 print '<td class="liste_titre"></td>';
187 print '<td class="liste_titre"></td>';
188 if (!empty($conf->banque->enabled)) print '<td class="liste_titre"></td>';
189 print '<td class="liste_titre"></td>';
190 print '<td class="liste_titre center">';
191 $searchpicto = $form->showFilterButtons();
192 print $searchpicto;
193 print '</td>';
194 print "</tr>\n";
195 
196 print '<tr class="liste_titre">';
197 print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.date_ech", "", $param, 'width="140px"', $sortfield, $sortorder);
198 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "c.libelle", "", $param, '', $sortfield, $sortorder);
199 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "cs.fk_type", "", $param, '', $sortfield, $sortorder);
200 print_liste_field_titre("ExpectedToPay", $_SERVER["PHP_SELF"], "cs.amount", "", $param, 'class="right"', $sortfield, $sortorder);
201 print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder);
202 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, 'align="center"', $sortfield, $sortorder);
203 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
204 if (!empty($conf->banque->enabled)) print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
205 print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "pc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
207 print "</tr>\n";
208 
209 if (!$resql)
210 {
211  dol_print_error($db);
212  exit;
213 }
214 
215 $i = 0;
216 $total = 0;
217 $totalnb = 0;
218 $totalpaye = 0;
219 
220 while ($i < min($num, $limit)) {
221  $obj = $db->fetch_object($resql);
222  print '<tr class="oddeven">';
223  // Date
224  $date = $obj->periode;
225  if (empty($date)) $date = $obj->date_ech;
226  print '<td>'.dol_print_date($date, 'day').'</td>';
227  // Label
228  print '<td>';
229  $socialcontrib->id = $obj->rowid;
230  $socialcontrib->ref = $obj->label;
231  $socialcontrib->label = $obj->label;
232  print $socialcontrib->getNomUrl(1, '20');
233  print '</td>';
234  // Type
235  print '<td title="'.dol_escape_htmltag($obj->label).'" class="tdmaxoverflow300">'.$obj->label.'</td>';
236  // Expected to pay
237  print '<td class="right">'.price($obj->total).'</td>';
238  // Ref payment
239  $payment_sc_static->id = $obj->pid;
240  $payment_sc_static->ref = $obj->pid;
241  print '<td>'.$payment_sc_static->getNomUrl(1)."</td>\n";
242  // Date payment
243  print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day').'</td>';
244  // Type payment
245  print '<td>';
246  if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
247  print $obj->num_payment.'</td>';
248  // Account
249  if (!empty($conf->banque->enabled))
250  {
251  print '<td>';
252  if ($obj->fk_bank > 0)
253  {
254  //$accountstatic->fetch($obj->fk_bank);
255  $accountstatic->id = $obj->bid;
256  $accountstatic->ref = $obj->bref;
257  $accountstatic->number = $obj->bnumber;
258  $accountstatic->accountancy_number = $obj->account_number;
259  $accountstatic->accountancy_journal = $obj->accountancy_journal;
260  $accountstatic->label = $obj->blabel;
261  print $accountstatic->getNomUrl(1);
262  } else print '&nbsp;';
263  print '</td>';
264  }
265  // Paid
266  print '<td class="right">';
267  if ($obj->totalpaye) print price($obj->totalpaye);
268  print '</td>';
269 
270  print '<td></td>';
271 
272  print '</tr>';
273 
274  $total = $total + $obj->total;
275  $totalnb = $totalnb + $obj->nb;
276  $totalpaye = $totalpaye + $obj->totalpaye;
277  $i++;
278 }
279 
280 // Total
281 print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
282 print '<td class="liste_total right"></td>'; // A total here has no sense
283 print '<td align="center" class="liste_total">&nbsp;</td>';
284 print '<td align="center" class="liste_total">&nbsp;</td>';
285 print '<td align="center" class="liste_total">&nbsp;</td>';
286 if (!empty($conf->banque->enabled)) print '<td></td>';
287 print '<td class="liste_total right">'.price($totalpaye)."</td>";
288 print '<td></td>';
289 print "</tr>";
290 
291 print '</table>';
292 
293 
294 print '</form>';
295 
296 $parameters = array('user' => $user);
297 $reshook = $hookmanager->executeHooks('dashboardSpecialBills', $parameters, $object); // Note that $action and $object may have been modified by hook
298 
299 // End of page
300 llxFooter();
301 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage salary payments.
Class to manage payments of social contributions.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
Class to manage bank accounts.
Put here description of your class.
Definition: tva.class.php:34
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage generation of HTML components for social contributions management.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...