dolibarr 24.0.0-beta
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-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.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// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
34require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
38require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
39require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
40require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
41
50// Load translation files required by the page
51$langs->loadLangs(array('banks', 'bills', 'categories', 'companies', 'salaries'));
52
53$id = 0;
54
55// Security check
56if (GETPOSTISSET("account") || GETPOSTISSET("ref")) {
57 $id = GETPOSTISSET("account") ? GETPOST("account") : (GETPOSTISSET("ref") ? GETPOST("ref") : '');
58}
59$fieldid = GETPOSTISSET("ref") ? 'ref' : 'rowid';
60if ($user->socid) {
61 $socid = $user->socid;
62}
63
64// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
65$hookmanager->initHooks(array('banktreso', 'globalcard'));
66
67$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
68
69$vline = GETPOST('vline');
70$page = GETPOSTISSET("page") ? GETPOST("page") : 0;
71
72/*
73 * View
74 */
75$societestatic = new Societe($db);
76$userstatic = new User($db);
77$facturestatic = new Facture($db);
78$facturefournstatic = new FactureFournisseur($db);
79$socialcontribstatic = new ChargeSociales($db);
80$salarystatic = new Salary($db);
81$vatstatic = new Tva($db);
82
83$form = new Form($db);
84
85if (GETPOST("account") || GETPOST("ref")) {
86 if ($vline) {
87 $viewline = $vline;
88 } else {
89 $viewline = 20;
90 }
91
92 $object = new Account($db);
93 if (GETPOSTINT("account")) {
94 $result = $object->fetch(GETPOSTINT("account"));
95 }
96 if (GETPOST("ref")) {
97 $result = $object->fetch(0, GETPOST("ref"));
98 $id = $object->id;
99 }
100
101 $title = $object->ref.' - '.$langs->trans("PlannedTransactions");
102 $helpurl = "";
103 llxHeader('', $title, $helpurl);
104
105 // Onglets
106 $head = bank_prepare_head($object);
107 print dol_get_fiche_head($head, 'cash', $langs->trans("FinancialAccount"), 0, 'account');
108
109 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
110
111 $morehtmlref = '';
112
113 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
114
115 print dol_get_fiche_end();
116
117
118 // Remainder to pay in future
119 $sqls = array();
120
121 // Customer invoices
122 $sql = "SELECT 'invoice' as family, f.rowid as objid, f.ref as ref, f.total_ttc, f.type, f.date_lim_reglement as dlr,";
123 $sql .= " s.rowid as socid, s.nom as name, s.fournisseur";
124 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
125 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
126 $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
127 $sql .= " AND f.paye = 0 AND f.fk_statut = 1"; // Not paid
128 $sql .= " AND (f.fk_account IN (0, ".$object->id.") OR f.fk_account IS NULL)"; // Id bank account of invoice
129 $sql .= " ORDER BY dlr ASC";
130 $sqls[] = $sql;
131
132 // Supplier invoices
133 $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,";
134 $sql .= " s.rowid as socid, s.nom as name, s.fournisseur";
135 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
136 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid";
137 $sql .= " WHERE ff.entity = ".$conf->entity;
138 $sql .= " AND ff.paye = 0 AND fk_statut = 1"; // Not paid
139 $sql .= " AND (ff.fk_account IN (0, ".$object->id.") OR ff.fk_account IS NULL)"; // Id bank account of supplier invoice
140 $sql .= " ORDER BY dlr ASC";
141 $sqls[] = $sql;
142
143 // Social contributions
144 $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,";
145 $sql .= " 0 as socid, 'noname' as name, 0 as fournisseur";
146 $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs";
147 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id";
148 $sql .= " WHERE cs.entity = ".$conf->entity;
149 $sql .= " AND cs.paye = 0"; // Not paid
150 $sql .= " AND (cs.fk_account IN (0, ".$object->id.") OR cs.fk_account IS NULL)"; // Id bank account of social contribution
151 $sql .= " ORDER BY dlr ASC";
152 $sqls[] = $sql;
153
154 // Salaries
155 $sql = " SELECT 'salary' as family, sa.rowid as objid, sa.label as ref, (-1*sa.amount) as total_ttc, sa.dateep as dlr,";
156 $sql .= " s.rowid as socid, CONCAT(s.firstname, ' ', s.lastname) as name, 0 as fournisseur";
157 $sql .= " FROM ".MAIN_DB_PREFIX."salary as sa";
158 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as s ON sa.fk_user = s.rowid";
159 $sql .= " WHERE sa.entity = ".$conf->entity;
160 $sql .= " AND sa.paye = 0"; // Not paid
161 $sql .= " AND (sa.fk_account IN (0, ".$object->id.") OR sa.fk_account IS NULL)"; // Id bank account of salary
162 $sql .= " ORDER BY dlr ASC";
163 $sqls[] = $sql;
164
165 // VAT
166 $sql = " SELECT 'vat' as family, t.rowid as objid, t.label as ref, (-1*t.amount) as total_ttc, t.datev as dlr,";
167 $sql .= " 0 as socid, 'noname' as name, 0 as fournisseur";
168 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
169 $sql .= " WHERE t.entity = ".$conf->entity;
170 $sql .= " AND t.paye = 0"; // Not paid
171 $sql .= " AND (t.fk_account IN (-1, 0, ".$object->id.") OR t.fk_account IS NULL)"; // Id bank account of vat
172 $sql .= " ORDER BY dlr ASC";
173 $sqls[] = $sql;
174
175 // others sql
176 $parameters = array();
177 $reshook = $hookmanager->executeHooks('addMoreSQL', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
178 if (empty($reshook) and isset($hookmanager->resArray['sql'])) {
179 $sqls[] = $hookmanager->resArray['sql'];
180 }
181
182 $error = 0;
183 $tab_sqlobjOrder = array();
184 $tab_sqlobj = array();
185 $nbtotalofrecords = 0;
186
187 foreach ($sqls as $sql) {
188 $resql = $db->query($sql);
189 if ($resql) {
190 $nbtotalofrecords += $db->num_rows($resql);
191 while ($sqlobj = $db->fetch_object($resql)) {
192 $tmpobj = new stdClass();
193 $tmpobj->family = $sqlobj->family;
194 $tmpobj->objid = $sqlobj->objid;
195 $tmpobj->ref = $sqlobj->ref;
196 $tmpobj->total_ttc = $sqlobj->total_ttc;
197 $tmpobj->type = $sqlobj->type;
198 $tmpobj->dlr = $db->jdate($sqlobj->dlr);
199 $tmpobj->socid = $sqlobj->socid;
200 $tmpobj->name = $sqlobj->name;
201 $tmpobj->fournisseur = $sqlobj->fournisseur;
202
203 $tab_sqlobj[] = $tmpobj;
204 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dlr);
205 }
206 $db->free($resql);
207 } else {
208 $error++;
209 }
210 }
211
212 $param = '';
213 $sortfield = '';
214 $sortorder = '';
215 $massactionbutton = '';
216 $num = 0;
217 $picto = '';
218 $morehtml = '';
219 $limit = 0;
220
221 print_barre_liste($langs->trans("PlannedTransactions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $morehtml, '', $limit, 0, 0, 1);
222
223
224 $solde = $object->solde(0);
225 if (getDolGlobalInt('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
226 $colspan = 6;
227 } else {
228 $colspan = 5;
229 }
230
231 // Show next coming entries
232 print '<div class="div-table-responsive">';
233 print '<table class="noborder centpercent">';
234
235 // Line of title for bank transactions
236 print '<tr class="liste_titre">';
237 print '<td>'.$langs->trans("DateDue").'</td>';
238 print '<td>'.$langs->trans("Description").'</td>';
239 if (getDolGlobalInt('MULTICOMPANY_INVOICE_SHARING_ENABLED')) {
240 print '<td>'.$langs->trans("Entity").'</td>';
241 }
242 print '<td>'.$langs->trans("ThirdParty").'</td>';
243 print '<td class="right">'.$langs->trans("Debit").'</td>';
244 print '<td class="right">'.$langs->trans("Credit").'</td>';
245 print '<td class="right" width="80">'.$langs->trans("BankBalance").'</td>';
246 print '</tr>';
247
248 // Current balance
249 print '<tr class="liste_total">';
250 print '<td class="left" colspan="5">'.$langs->trans("CurrentBalance").'</td>';
251 print '<td class="nowrap right">'.price($solde).'</td>';
252 print '</tr>';
253
254 // Sort array
255 if (!$error) {
256 array_multisort($tab_sqlobjOrder, $tab_sqlobj);
257
258 $num = count($tab_sqlobj);
259
260 $i = 0;
261 while ($i < $num) {
262 $ref = '';
263 $refcomp = '';
264 $totalpayment = '';
265
266 $tmpobj = array_shift($tab_sqlobj);
267
268 if ($tmpobj->family == 'invoice_supplier') {
269 $showline = 1;
270 // Uncomment this line to avoid to count suppliers credit note (ff.type = 2)
271 //$showline=(($tmpobj->total_ttc < 0 && $tmpobj->type != 2) || ($tmpobj->total_ttc > 0 && $tmpobj->type == 2))
272 if ($showline) {
273 $ref = $tmpobj->ref;
274 $facturefournstatic->ref = $ref;
275 $facturefournstatic->id = $tmpobj->objid;
276 $facturefournstatic->type = $tmpobj->type;
277 $ref = $facturefournstatic->getNomUrl(1, '');
278
279 $societestatic->id = $tmpobj->socid;
280 $societestatic->name = $tmpobj->name;
281 $refcomp = $societestatic->getNomUrl(1, '', 24);
282
283 $totalpayment = -1 * $facturefournstatic->getSommePaiement(); // Payment already done
284 }
285 }
286 if ($tmpobj->family == 'invoice') {
287 $facturestatic->ref = $tmpobj->ref;
288 $facturestatic->id = $tmpobj->objid;
289 $facturestatic->type = (int) $tmpobj->type;
290 $ref = $facturestatic->getNomUrl(1, '');
291
292 $societestatic->id = $tmpobj->socid;
293 $societestatic->name = $tmpobj->name;
294 $refcomp = $societestatic->getNomUrl(1, '', 24);
295
296 $totalpayment = $facturestatic->getSommePaiement(); // Payment already done
297 $totalpayment += $facturestatic->getSumDepositsUsed();
298 $totalpayment += $facturestatic->getSumCreditNotesUsed();
299 }
300 if ($tmpobj->family == 'social_contribution') {
301 $socialcontribstatic->ref = $tmpobj->ref;
302 $socialcontribstatic->id = $tmpobj->objid;
303 $socialcontribstatic->label = $tmpobj->type;
304 $ref = $socialcontribstatic->getNomUrl(1, '24');
305
306 $totalpayment = -1 * $socialcontribstatic->getSommePaiement(); // Payment already done
307 }
308 if ($tmpobj->family == 'salary') {
309 $salarystatic->ref = $tmpobj->ref;
310 $salarystatic->id = $tmpobj->objid;
311 $salarystatic->label = $langs->trans("SalaryPayment");
312 $ref = $salarystatic->getNomUrl(1, '');
313
314 $userstatic->id = $tmpobj->socid;
315 $userstatic->name = $tmpobj->name;
316 $refcomp = $userstatic->getNomUrl(1);
317
318 $totalpayment = -1 * $salarystatic->getSommePaiement(); // Payment already done
319 }
320 if ($tmpobj->family == 'vat') {
321 $vatstatic->ref = $tmpobj->ref;
322 $vatstatic->id = $tmpobj->objid;
323 $vatstatic->type = $tmpobj->type;
324 $ref = $vatstatic->getNomUrl(1, '');
325
326 $totalpayment = -1 * $vatstatic->getSommePaiement(); // Payment already done
327 }
328
329 $parameters = array('obj' => $tmpobj, 'ref' => $ref, 'refcomp' => $refcomp, 'totalpayment' => $totalpayment);
330 $reshook = $hookmanager->executeHooks('moreFamily', $parameters, $tmpobject, $action); // Note that $action and $tmpobject may have been modified by hook
331 if (empty($reshook)) {
332 $ref = isset($hookmanager->resArray['ref']) ? $hookmanager->resArray['ref'] : $ref;
333 $refcomp = isset($hookmanager->resArray['refcomp']) ? $hookmanager->resArray['refcomp'] : $refcomp;
334 $totalpayment = isset($hookmanager->resArray['totalpayment']) ? $hookmanager->resArray['totalpayment'] : $totalpayment;
335 }
336
337 $total_ttc = $tmpobj->total_ttc;
338 if ($totalpayment) {
339 $total_ttc = $tmpobj->total_ttc - $totalpayment;
340 }
341 $solde += $total_ttc;
342
343 // We discard lines with a remainder to pay to 0
344 if (price2num($total_ttc) != 0) {
345 // Show line
346 print '<tr class="oddeven">';
347 print '<td>';
348 if ($tmpobj->dlr) {
349 print dol_print_date($tmpobj->dlr, "day");
350 } else {
351 print $langs->trans("NotDefined");
352 }
353 print "</td>";
354 print "<td>".$ref."</td>";
355 if (isModEnabled('multicompany') && isset($mc) && getDolGlobalString("MULTICOMPANY_INVOICE_SHARING_ENABLED")) {
356 if ($tmpobj->family == 'invoice') {
357 $mc->getInfo($tmpobj->entity);
358 print "<td>".$mc->label."</td>";
359 } else {
360 print "<td></td>";
361 }
362 }
363 print "<td>".$refcomp."</td>";
364 if ($tmpobj->total_ttc < 0) {
365 print '<td class="nowrap right">'.price(abs($total_ttc))."</td><td>&nbsp;</td>";
366 }
367 if ($tmpobj->total_ttc >= 0) {
368 print '<td>&nbsp;</td><td class="nowrap right">'.price($total_ttc)."</td>";
369 }
370 print '<td class="nowraponall right"><span class="'.($solde >= 0 ? ' amount' : ' amountneg').'">'.price($solde).'</span></td>';
371 print "</tr>";
372 }
373
374 $i++;
375 }
376 } else {
378 }
379
380 // Other lines
381 $parameters = array('solde' => $solde);
382 $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
383 if (empty($reshook)) {
384 print $hookmanager->resPrint;
385 $solde = isset($hookmanager->resArray['solde']) ? $hookmanager->resArray['solde'] : $solde;
386 }
387
388 // solde
389 print '<tr class="liste_total">';
390 print '<td class="left" colspan="'.$colspan.'">'.$langs->trans("FutureBalance").' ('.$object->currency_code.')</td>';
391 print '<td class="nowrap right">'.price($solde, 0, $langs, 0, 0, -1, $object->currency_code).'</td>';
392 print '</tr>';
393
394 print "</table>";
395 print "</div>";
396} else {
397 print $langs->trans("ErrorBankAccountNotFound");
398}
399
400// End of page
401llxFooter();
402$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
bank_prepare_head(Account $object)
Prepare array with list of tabs.
Definition bank.lib.php:40
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)
Definition tva.class.php:39
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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, $morecssdiv='')
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.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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.