dolibarr 21.0.0-alpha
treso.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2008-2009 Laurent Destailleur (Eldy) <eldy@users.sourceforge.net>
4 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
5 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com
6 * Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
37require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
40
41// Load translation files required by the page
42$langs->loadLangs(array('banks', 'bills', 'categories', 'companies', 'salaries'));
43
44// Security check
45if (GETPOSTISSET("account") || GETPOSTISSET("ref")) {
46 $id = GETPOSTISSET("account") ? GETPOST("account") : (GETPOSTISSET("ref") ? GETPOST("ref") : '');
47}
48$fieldid = GETPOSTISSET("ref") ? 'ref' : 'rowid';
49if ($user->socid) {
50 $socid = $user->socid;
51}
52
53// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
54$hookmanager->initHooks(array('banktreso', 'globalcard'));
55
56$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
57
58$vline = GETPOST('vline');
59$page = GETPOSTISSET("page") ? GETPOST("page") : 0;
60
61/*
62 * View
63 */
64$societestatic = new Societe($db);
65$userstatic = new User($db);
66$facturestatic = new Facture($db);
67$facturefournstatic = new FactureFournisseur($db);
68$socialcontribstatic = new ChargeSociales($db);
69$salarystatic = new Salary($db);
70$vatstatic = new Tva($db);
71
72$form = new Form($db);
73
74if (GETPOST("account") || GETPOST("ref")) {
75 if ($vline) {
76 $viewline = $vline;
77 } else {
78 $viewline = 20;
79 }
80
81 $object = new Account($db);
82 if (GETPOSTINT("account")) {
83 $result = $object->fetch(GETPOSTINT("account"));
84 }
85 if (GETPOST("ref")) {
86 $result = $object->fetch(0, GETPOST("ref"));
87 $id = $object->id;
88 }
89
90 $title = $object->ref.' - '.$langs->trans("PlannedTransactions");
91 $helpurl = "";
92 llxHeader('', $title, $helpurl);
93
94 // Onglets
96 print dol_get_fiche_head($head, 'cash', $langs->trans("FinancialAccount"), 0, 'account');
97
98 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
99
100 $morehtmlref = '';
101
102 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
103
104 print dol_get_fiche_end();
105
106
107 // Remainder to pay in future
108 $sqls = array();
109
110 // Customer invoices
111 $sql = "SELECT 'invoice' as family, f.rowid as objid, f.ref as ref, f.total_ttc, f.type, f.date_lim_reglement as dlr,";
112 $sql .= " s.rowid as socid, s.nom as name, s.fournisseur";
113 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
114 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
115 $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
116 $sql .= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid
117 $sql .= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice
118 $sql .= " ORDER BY dlr ASC";
119 $sqls[] = $sql;
120
121 // Supplier invoices
122 $sql = " SELECT 'invoice_supplier' as family, ff.rowid as objid, ff.ref as ref, ff.ref_supplier as ref_supplier, (-1*ff.total_ttc) as total_ttc, ff.type, ff.date_lim_reglement as dlr,";
123 $sql .= " s.rowid as socid, s.nom as name, s.fournisseur";
124 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
125 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid";
126 $sql .= " WHERE ff.entity = ".$conf->entity;
127 $sql .= " AND ff.paye = 0 AND fk_statut = 1"; // Not paid
128 $sql .= " AND (ff.fk_account IN (0, ".$object->id.") OR ff.fk_account IS NULL)"; // Id bank account of supplier invoice
129 $sql .= " ORDER BY dlr ASC";
130 $sqls[] = $sql;
131
132 // Social contributions
133 $sql = " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, cs.date_ech as dlr,";
134 $sql .= " 0 as socid, 'noname' as name, 0 as fournisseur";
135 $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
136 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id";
137 $sql .= " WHERE cs.entity = ".$conf->entity;
138 $sql .= " AND cs.paye = 0"; // Not paid
139 $sql .= " AND (cs.fk_account IN (0, ".$object->id.") OR cs.fk_account IS NULL)"; // Id bank account of social contribution
140 $sql .= " ORDER BY dlr ASC";
141 $sqls[] = $sql;
142
143 // Salaries
144 $sql = " SELECT 'salary' as family, sa.rowid as objid, sa.label as ref, (-1*sa.amount) as total_ttc, sa.dateep as dlr,";
145 $sql .= " s.rowid as socid, CONCAT(s.firstname, ' ', s.lastname) as name, 0 as fournisseur";
146 $sql .= " FROM ".MAIN_DB_PREFIX."salary as sa";
147 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as s ON sa.fk_user = s.rowid";
148 $sql .= " WHERE sa.entity = ".$conf->entity;
149 $sql .= " AND sa.paye = 0"; // Not paid
150 $sql .= " AND (sa.fk_account IN (0, ".$object->id.") OR sa.fk_account IS NULL)"; // Id bank account of salary
151 $sql .= " ORDER BY dlr ASC";
152 $sqls[] = $sql;
153
154 // VAT
155 $sql = " SELECT 'vat' as family, t.rowid as objid, t.label as ref, (-1*t.amount) as total_ttc, t.datev as dlr,";
156 $sql .= " 0 as socid, 'noname' as name, 0 as fournisseur";
157 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
158 $sql .= " WHERE t.entity = ".$conf->entity;
159 $sql .= " AND t.paye = 0"; // Not paid
160 $sql .= " AND (t.fk_account IN (-1, 0, ".$object->id.") OR t.fk_account IS NULL)"; // Id bank account of vat
161 $sql .= " ORDER BY dlr ASC";
162 $sqls[] = $sql;
163
164 // others sql
165 $parameters = array();
166 $reshook = $hookmanager->executeHooks('addMoreSQL', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
167 if (empty($reshook) and isset($hookmanager->resArray['sql'])) {
168 $sqls[] = $hookmanager->resArray['sql'];
169 }
170
171 $error = 0;
172 $tab_sqlobjOrder = array();
173 $tab_sqlobj = array();
174 $nbtotalofrecords = 0;
175
176 foreach ($sqls as $sql) {
177 $resql = $db->query($sql);
178 if ($resql) {
179 $nbtotalofrecords += $db->num_rows($resql);
180 while ($sqlobj = $db->fetch_object($resql)) {
181 $tmpobj = new stdClass();
182 $tmpobj->family = $sqlobj->family;
183 $tmpobj->objid = $sqlobj->objid;
184 $tmpobj->ref = $sqlobj->ref;
185 $tmpobj->total_ttc = $sqlobj->total_ttc;
186 $tmpobj->type = $sqlobj->type;
187 $tmpobj->dlr = $db->jdate($sqlobj->dlr);
188 $tmpobj->socid = $sqlobj->socid;
189 $tmpobj->name = $sqlobj->name;
190 $tmpobj->fournisseur = $sqlobj->fournisseur;
191
192 $tab_sqlobj[] = $tmpobj;
193 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dlr);
194 }
195 $db->free($resql);
196 } else {
197 $error++;
198 }
199 }
200
201 $param = '';
202 $sortfield = '';
203 $sortorder = '';
204 $massactionbutton = '';
205 $num = 0;
206 $picto = '';
207 $morehtml = '';
208 $limit = 0;
209
210 print_barre_liste($langs->trans("RemainderToPay"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1);
211
212
213 $solde = $object->solde(0);
214 if (getDolGlobalInt('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
215 $colspan = 6;
216 } else {
217 $colspan = 5;
218 }
219
220 // Show next coming entries
221 print '<div class="div-table-responsive">';
222 print '<table class="noborder centpercent">';
223
224 // Ligne de titre tableau des ecritures
225 print '<tr class="liste_titre">';
226 print '<td>'.$langs->trans("DateDue").'</td>';
227 print '<td>'.$langs->trans("Description").'</td>';
228 if (getDolGlobalInt('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
229 print '<td>'.$langs->trans("Entity").'</td>';
230 }
231 print '<td>'.$langs->trans("ThirdParty").'</td>';
232 print '<td class="right">'.$langs->trans("Debit").'</td>';
233 print '<td class="right">'.$langs->trans("Credit").'</td>';
234 print '<td class="right" width="80">'.$langs->trans("BankBalance").'</td>';
235 print '</tr>';
236
237 // Current balance
238 print '<tr class="liste_total">';
239 print '<td class="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
240 print '<td class="nowrap right">'.price($solde).'</td>';
241 print '</tr>';
242
243 // Sort array
244 if (!$error) {
245 array_multisort($tab_sqlobjOrder, $tab_sqlobj);
246
247 $num = count($tab_sqlobj);
248
249 $i = 0;
250 while ($i < $num) {
251 $ref = '';
252 $refcomp = '';
253 $totalpayment = '';
254
255 $tmpobj = array_shift($tab_sqlobj);
256
257 if ($tmpobj->family == 'invoice_supplier') {
258 $showline = 1;
259 // Uncomment this line to avoid to count suppliers credit note (ff.type = 2)
260 //$showline=(($tmpobj->total_ttc < 0 && $tmpobj->type != 2) || ($tmpobj->total_ttc > 0 && $tmpobj->type == 2))
261 if ($showline) {
262 $ref = $tmpobj->ref;
263 $facturefournstatic->ref = $ref;
264 $facturefournstatic->id = $tmpobj->objid;
265 $facturefournstatic->type = $tmpobj->type;
266 $ref = $facturefournstatic->getNomUrl(1, '');
267
268 $societestatic->id = $tmpobj->socid;
269 $societestatic->name = $tmpobj->name;
270 $refcomp = $societestatic->getNomUrl(1, '', 24);
271
272 $totalpayment = -1 * $facturefournstatic->getSommePaiement(); // Payment already done
273 }
274 }
275 if ($tmpobj->family == 'invoice') {
276 $facturestatic->ref = $tmpobj->ref;
277 $facturestatic->id = $tmpobj->objid;
278 $facturestatic->type = $tmpobj->type;
279 $ref = $facturestatic->getNomUrl(1, '');
280
281 $societestatic->id = $tmpobj->socid;
282 $societestatic->name = $tmpobj->name;
283 $refcomp = $societestatic->getNomUrl(1, '', 24);
284
285 $totalpayment = $facturestatic->getSommePaiement(); // Payment already done
286 $totalpayment += $facturestatic->getSumDepositsUsed();
287 $totalpayment += $facturestatic->getSumCreditNotesUsed();
288 }
289 if ($tmpobj->family == 'social_contribution') {
290 $socialcontribstatic->ref = $tmpobj->ref;
291 $socialcontribstatic->id = $tmpobj->objid;
292 $socialcontribstatic->label = $tmpobj->type;
293 $ref = $socialcontribstatic->getNomUrl(1, 24);
294
295 $totalpayment = -1 * $socialcontribstatic->getSommePaiement(); // Payment already done
296 }
297 if ($tmpobj->family == 'salary') {
298 $salarystatic->ref = $tmpobj->ref;
299 $salarystatic->id = $tmpobj->objid;
300 $salarystatic->label = $langs->trans("SalaryPayment");
301 $ref = $salarystatic->getNomUrl(1, '');
302
303 $userstatic->id = $tmpobj->socid;
304 $userstatic->name = $tmpobj->name;
305 $refcomp = $userstatic->getNomUrl(1);
306
307 $totalpayment = -1 * $salarystatic->getSommePaiement(); // Payment already done
308 }
309 if ($tmpobj->family == 'vat') {
310 $vatstatic->ref = $tmpobj->ref;
311 $vatstatic->id = $tmpobj->objid;
312 $vatstatic->type = $tmpobj->type;
313 $ref = $vatstatic->getNomUrl(1, '');
314
315 $totalpayment = -1 * $vatstatic->getSommePaiement(); // Payment already done
316 }
317
318 $parameters = array('obj' => $tmpobj, 'ref' => $ref, 'refcomp' => $refcomp, 'totalpayment' => $totalpayment);
319 $reshook = $hookmanager->executeHooks('moreFamily', $parameters, $tmpobject, $action); // Note that $action and $tmpobject may have been modified by hook
320 if (empty($reshook)) {
321 $ref = isset($hookmanager->resArray['ref']) ? $hookmanager->resArray['ref'] : $ref;
322 $refcomp = isset($hookmanager->resArray['refcomp']) ? $hookmanager->resArray['refcomp'] : $refcomp;
323 $totalpayment = isset($hookmanager->resArray['totalpayment']) ? $hookmanager->resArray['totalpayment'] : $totalpayment;
324 }
325
326 $total_ttc = $tmpobj->total_ttc;
327 if ($totalpayment) {
328 $total_ttc = $tmpobj->total_ttc - $totalpayment;
329 }
330 $solde += $total_ttc;
331
332 // We discard lines with a remainder to pay to 0
333 if (price2num($total_ttc) != 0) {
334 // Show line
335 print '<tr class="oddeven">';
336 print '<td>';
337 if ($tmpobj->dlr) {
338 print dol_print_date($tmpobj->dlr, "day");
339 } else {
340 print $langs->trans("NotDefined");
341 }
342 print "</td>";
343 print "<td>".$ref."</td>";
344 if (getDolGlobalString("MULTICOMPANY_INVOICE_SHARING_ENABLED")) {
345 if ($tmpobj->family == 'invoice') {
346 $mc->getInfo($tmpobj->entity);
347 print "<td>".$mc->label."</td>";
348 } else {
349 print "<td></td>";
350 }
351 }
352 print "<td>".$refcomp."</td>";
353 if ($tmpobj->total_ttc < 0) {
354 print '<td class="nowrap right">'.price(abs($total_ttc))."</td><td>&nbsp;</td>";
355 }
356 if ($tmpobj->total_ttc >= 0) {
357 print '<td>&nbsp;</td><td class="nowrap right">'.price($total_ttc)."</td>";
358 }
359 print '<td class="nowrap right">'.price($solde).'</td>';
360 print "</tr>";
361 }
362
363 $i++;
364 }
365 } else {
366 dol_print_error($db);
367 }
368
369 // Other lines
370 $parameters = array('solde' => $solde);
371 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
372 if (empty($reshook)) {
373 print $hookmanager->resPrint;
374 $solde = isset($hookmanager->resArray['solde']) ? $hookmanager->resArray['solde'] : $solde;
375 }
376
377 // solde
378 print '<tr class="liste_total">';
379 print '<td class="left" colspan="'.$colspan.'">'.$langs->trans("FutureBalance").' ('.$object->currency_code.')</td>';
380 print '<td class="nowrap right">'.price($solde, 0, $langs, 0, 0, -1, $object->currency_code).'</td>';
381 print '</tr>';
382
383 print "</table>";
384 print "</div>";
385} else {
386 print $langs->trans("ErrorBankAccountNotFound");
387}
388
389// End of page
390llxFooter();
391$db->close();
$id
Definition account.php:39
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition bank.lib.php:39
Class to manage bank accounts.
Class for managing the social charges.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
llxFooter()
Footer empty.
Definition document.php:107
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.