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