dolibarr 25.0.0-alpha
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24// Load Dolibarr environment
25require '../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35
36// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
37$hookmanager->initHooks(['bankindex']);
38
39// Load translation files required by the page
40$langs->loadLangs(['banks', 'bills', 'compta']);
41
42// Security check
43$result = restrictedArea($user, 'banque');
44
45$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
46
47
48/*
49 * Actions
50 */
51
52// Add box (when submit is done from a form when ajax disabled)
53include DOL_DOCUMENT_ROOT.'/core/actions_addbox.inc.php';
54
55
56/*
57 * View
58 */
59
60$accountstatic = new Account($db);
61$accountlinestatic = new AccountLine($db);
62
63$title = $langs->trans('MenuBankCash');
64$help_url = 'EN:Module_Banks_and_Cash|FR:Module_Banques_et_Caisses|ES:Módulo_Bancos_y_Cajas|DE:Modul_Banken_und_Barvermögen';
65
66// Load $resultboxes
67$resultboxes = FormOther::getBoxesArea($user, "29");
68
69llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-bank page-index');
70
71print load_fiche_titre($langs->trans("BankArea"), $resultboxes['selectboxlist'], 'bank_account');
72
73
74print '<div class="fichecenter">';
75
76print '<div class="twocolumns">';
77
78print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
79
80
81/*
82 * Open accounts with their balance
83 */
84
85$sql = "SELECT b.rowid, b.ref, b.label, b.number, b.courant, b.currency_code, b.account_number";
86$sql .= ", SUM(bl.amount) as solde";
87$sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
88$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as bl ON bl.fk_account = b.rowid";
89$sql .= " WHERE b.entity IN (".getEntity('bank_account').")";
90$sql .= " AND b.clos = 0";
91$sql .= " GROUP BY b.rowid, b.ref, b.label, b.number, b.courant, b.currency_code, b.account_number";
92$sql .= $db->order("b.label", "ASC");
93
94$resql = $db->query($sql);
95if ($resql) {
96 print '<div class="div-table-responsive-no-min">';
97 print '<table class="noborder centpercent">';
98 print '<tr class="liste_titre">';
99 print '<th colspan="2">'.$langs->trans("BankAccounts");
100 $lastmodified = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/compta/bank/list.php', ['search_status' => 'opened']).'" title="'.$langs->trans("FullList").'">';
101 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
102 $lastmodified .= '</a>';
103 print $lastmodified;
104 print '</th>';
105 print '<th class="right">'.$langs->trans("Balance").'</th>';
106 print '</tr>';
107
108 $num = $db->num_rows($resql);
109 if ($num) {
110 $solde_total = [];
111 $solde_others = [];
112 $i = 0;
113 while ($i < $num) {
114 $obj = $db->fetch_object($resql);
115
116 $currency_code = ($obj->currency_code ? $obj->currency_code : $conf->currency);
117 $solde = (float) price2num($obj->solde, 'MU');
118 if (!array_key_exists($currency_code, $solde_total)) {
119 $solde_total[$currency_code] = 0;
120 }
121 $solde_total[$currency_code] += $solde;
122
123 // Accounts after the short list limit are summed into a line "Others"
124 if ($i >= $max) {
125 if (!array_key_exists($currency_code, $solde_others)) {
126 $solde_others[$currency_code] = 0;
127 }
128 $solde_others[$currency_code] += $solde;
129 $i++;
130 continue;
131 }
132
133 $accountstatic->id = $obj->rowid;
134 $accountstatic->ref = $obj->ref;
135 $accountstatic->label = $obj->label;
136 $accountstatic->number = $obj->number;
137 $accountstatic->account_number = $obj->account_number;
138 $accountstatic->currency_code = $obj->currency_code;
139 $accountstatic->type = $obj->courant;
140
141 print '<tr class="oddeven">';
142 print '<td>'.$accountstatic->getNomUrl(1).'</td>';
143 print '<td>'.dol_escape_htmltag($obj->number).'</td>';
144 print '<td class="nowraponall right amount">';
145 print '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/compta/bank/bankentries_list.php', ['id' => (int) $obj->rowid]).'">';
146 print '<span class="amount">';
147 print price($solde, 0, $langs, 1, -1, -1, $currency_code);
148 print '</span>';
149 print '</a>';
150 print '</td>';
151 print '</tr>';
152 $i++;
153 }
154
155 // Line "Others" (one per currency, because amounts in different currencies can't be added)
156 foreach ($solde_others as $currency_code => $total) {
157 print '<tr class="oddeven">';
158 print '<td colspan="2"><span class="opacitymedium">'.$langs->trans("Others").'...'.(count($solde_others) > 1 ? ' ('.dol_escape_htmltag((string) $currency_code).')' : '').'</span></td>';
159 print '<td class="nowraponall right amount">';
160 print '<span class="amount">'.price($total, 0, $langs, 1, -1, -1, $currency_code).'</span>';
161 print '</td>';
162 print '</tr>';
163 }
164
165 // Total per currency
166 foreach ($solde_total as $currency_code => $total) {
167 print '<tr class="liste_total">';
168 print '<td class="liste_total" colspan="2">'.$langs->trans("Total").' ('.dol_escape_htmltag((string) $currency_code).')</td>';
169 print '<td class="liste_total nowraponall right amount">'.price($total, 0, $langs, 1, -1, -1, $currency_code).'</td>';
170 print '</tr>';
171 }
172 } else {
173 print '<tr class="oddeven">';
174 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
175 print '</tr>';
176 }
177 print '</table>';
178 print '</div>';
179 print '<br>';
180 $db->free($resql);
181} else {
182 dol_print_error($db);
183}
184
185
186print $resultboxes['boxlista'];
187
188print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
189
190
191/*
192 * Last modified bank transactions
193 */
194
195$sql = "SELECT bl.rowid, bl.label, bl.amount, bl.dateo, bl.datev, bl.tms as datem, bl.fk_account";
196$sql .= ", b.rowid as bankid, b.ref as bankref, b.label as banklabel, b.currency_code";
197$sql .= " FROM ".MAIN_DB_PREFIX."bank as bl";
198$sql .= " INNER JOIN ".MAIN_DB_PREFIX."bank_account as b ON b.rowid = bl.fk_account";
199$sql .= " WHERE b.entity IN (".getEntity('bank_account').")";
200$sql .= $db->order("bl.tms", "DESC");
201$sql .= $db->plimit($max, 0);
202
203$resql = $db->query($sql);
204if ($resql) {
205 print '<div class="div-table-responsive-no-min">';
206 print '<table class="noborder centpercent">';
207 print '<tr class="liste_titre">';
208 print '<th colspan="3">'.$langs->trans("LatestBankTransactionsModified", $max);
209 $lastmodified = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/compta/bank/bankentries_list.php', ['sortfield' => 'b.tms', 'sortorder' => 'DESC']).'" title="'.$langs->trans("FullList").'">';
210 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
211 $lastmodified .= '</a>';
212 print $lastmodified;
213 print '</th>';
214 print '<th class="right">'.$langs->trans("Amount").'</th>';
215 print '</tr>';
216
217 $num = $db->num_rows($resql);
218 if ($num) {
219 $i = 0;
220 while ($i < $num) {
221 $obj = $db->fetch_object($resql);
222
223 $accountlinestatic->id = $obj->rowid;
224 $accountlinestatic->ref = (string) $obj->rowid;
225 $accountlinestatic->label = $obj->label;
226 $accountlinestatic->amount = $obj->amount;
227
228 $accountstatic->id = $obj->bankid;
229 $accountstatic->ref = $obj->bankref;
230 $accountstatic->label = $obj->banklabel;
231 $accountstatic->currency_code = $obj->currency_code;
232
233 print '<tr class="oddeven">';
234 print '<td class="nowraponall">'.$accountlinestatic->getNomUrl(1).'</td>';
235 // Translate label when it is a translation key between parenthesis (e.g. '(SupplierInvoicePayment)')
236 $labeltoshow = $obj->label;
237 $reg = array();
238 if (preg_match('/^\‍((.+)\‍)$/i', (string) $obj->label, $reg)) {
239 if ($reg[1] == 'payment_salary') {
240 $reg[1] = 'SalaryPayment';
241 }
242 if ($langs->transnoentitiesnoconv($reg[1]) != $reg[1]) {
243 $labeltoshow = $langs->transnoentitiesnoconv($reg[1]);
244 }
245 }
246 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($labeltoshow).'">'.dol_escape_htmltag($labeltoshow).'</td>';
247 print '<td class="nowraponall">'.$accountstatic->getNomUrl(1).'</td>';
248 print '<td class="nowraponall right amount">'.price($obj->amount, 0, $langs, 1, -1, -1, $obj->currency_code).'</td>';
249 print '</tr>';
250 $i++;
251 }
252 } else {
253 print '<tr class="oddeven">';
254 print '<td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
255 print '</tr>';
256 }
257 print '</table>';
258 print '</div>';
259 print '<br>';
260 $db->free($resql);
261} else {
262 dol_print_error($db);
263}
264
265
266print $resultboxes['boxlistb'];
267
268print '</div></div></div>';
269
270$object = new stdClass();
271$parameters = [
272 'user' => $user,
273];
274$reshook = $hookmanager->executeHooks('dashboardBank', $parameters, $object);
275
276// End of page
277llxFooter();
278$db->close();
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage bank transaction lines.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of us...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.