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