dolibarr 21.0.0-alpha
box_comptes.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Christophe
3 * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30
31
36{
37 public $boxcode = "currentaccounts";
38 public $boximg = "bank_account";
39 public $boxlabel = "BoxCurrentAccounts";
40 public $depends = array("banque"); // Box active if module banque active
41
42 public $enabled = 1;
43
50 public function __construct($db, $param = '')
51 {
52 global $conf, $user;
53
54 $this->db = $db;
55
56 // disable module for such cases
57 $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
58 if (!in_array('banque', $listofmodulesforexternal) && !empty($user->socid)) {
59 $this->enabled = 0; // disabled for external users
60 }
61
62 $this->hidden = !$user->hasRight('banque', 'lire');
63 $this->urltoaddentry = DOL_URL_ROOT.'/compta/bank/card.php?action=create';
64 $this->msgNoRecords = 'NoRecordedBankAccounts';
65 }
66
73 public function loadBox($max = 5)
74 {
75 global $user, $langs, $conf;
76
77 $this->max = $max;
78
79 $this->info_box_head = array(
80 'text' => $langs->trans("BoxTitleCurrentAccounts").'<a class="paddingleft" href="'.DOL_URL_ROOT.'/compta/bank/list.php?search_status=opened"><span class="badge">...</span></a>'
81 );
82
83 if ($user->hasRight('banque', 'lire')) {
84 $sql = "SELECT b.rowid, b.ref, b.label, b.bank, b.number, b.courant, b.clos, b.rappro, b.url";
85 $sql .= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban";
86 $sql .= ", b.domiciliation as address, b.proprio, b.owner_address";
87 $sql .= ", b.account_number, b.currency_code";
88 $sql .= ", b.min_allowed, b.min_desired, comment";
89 $sql .= ', b.fk_accountancy_journal';
90 $sql .= ', aj.code as accountancy_journal';
91 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
92 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid = b.fk_accountancy_journal';
93 $sql .= " WHERE b.entity = ".$conf->entity;
94 $sql .= " AND clos = 0";
95 $sql .= " ORDER BY label";
96
97 $sql .= $this->db->plimit($max, 0);
98
99 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
100
101 $result = $this->db->query($sql);
102 if ($result) {
103 $num = $this->db->num_rows($result);
104
105 $line = 0;
106 $solde_total = array();
107
108 $account_static = new Account($this->db);
109 while ($line < $num) {
110 $objp = $this->db->fetch_object($result);
111
112 $account_static->id = $objp->rowid;
113 $account_static->ref = $objp->ref;
114 $account_static->label = $objp->label;
115 $account_static->number = $objp->number;
116 $account_static->account_number = $objp->account_number;
117 $account_static->currency_code = $objp->currency_code;
118 $account_static->accountancy_journal = $objp->accountancy_journal;
119 $solde = $account_static->solde(0);
120
121 if (!array_key_exists($objp->currency_code, $solde_total)) {
122 $solde_total[$objp->currency_code] = $solde;
123 } else {
124 $solde_total[$objp->currency_code] += $solde;
125 }
126
127
128 $this->info_box_contents[$line][] = array(
129 'td' => '',
130 'text' => $account_static->getNomUrl(1),
131 'asis' => 1,
132 );
133
134 $this->info_box_contents[$line][] = array(
135 'td' => '',
136 'text' => $objp->number,
137 );
138
139 $this->info_box_contents[$line][] = array(
140 'td' => 'class="nowraponall right amount"',
141 'text' => '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$account_static->id.'">'
142 .price($solde, 0, $langs, 1, -1, -1, $objp->currency_code)
143 .'</a>',
144 'asis' => 1,
145 );
146
147 $line++;
148 }
149
150 // Total
151 foreach ($solde_total as $key => $solde) {
152 $this->info_box_contents[$line][] = array(
153 'tr' => 'class="liste_total"',
154 'td' => 'class="liste_total left"',
155 'text' => $langs->trans('Total').' '.$key,
156 );
157 $this->info_box_contents[$line][] = array(
158 'td' => 'class="liste_total right"',
159 'text' => '&nbsp;'
160 );
161
162 $this->info_box_contents[$line][] = array(
163 'td' => 'class="liste_total nowraponall right amount"',
164 'text' => '<span class="amount">'.price($solde, 0, $langs, 0, -1, -1, $key).'</span>'
165 );
166 $line++;
167 }
168
169
170 $this->db->free($result);
171 } else {
172 $this->info_box_contents[0][0] = array(
173 'td' => '',
174 'maxlength' => 500,
175 'text' => ($this->db->error().' sql='.$sql),
176 );
177 }
178 } else {
179 $this->info_box_contents[0][0] = array(
180 'td' => 'class="nohover left"',
181 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
182 );
183 }
184 }
185
186
187
196 public function showBox($head = null, $contents = null, $nooutput = 0)
197 {
198 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
199 }
200}
Class to manage bank accounts.
Class ModeleBoxes.
Class to manage the box to show bank accounts.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.