dolibarr 18.0.6
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 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29
30
35{
36 public $boxcode = "currentaccounts";
37 public $boximg = "bank_account";
38 public $boxlabel = "BoxCurrentAccounts";
39 public $depends = array("banque"); // Box active if module banque active
40
44 public $db;
45
46 public $param;
47 public $enabled = 1;
48
49 public $info_box_head = array();
50 public $info_box_contents = array();
51
52
59 public function __construct($db, $param = '')
60 {
61 global $conf, $user;
62
63 $this->db = $db;
64
65 // disable module for such cases
66 $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
67 if (!in_array('banque', $listofmodulesforexternal) && !empty($user->socid)) {
68 $this->enabled = 0; // disabled for external users
69 }
70
71 $this->hidden = empty($user->rights->banque->lire);
72 }
73
80 public function loadBox($max = 5)
81 {
82 global $user, $langs, $conf;
83
84 $this->max = $max;
85
86 $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts"));
87
88 if ($user->rights->banque->lire) {
89 $sql = "SELECT b.rowid, b.ref, b.label, b.bank,b.number, b.courant, b.clos, b.rappro, b.url";
90 $sql .= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban";
91 $sql .= ", b.domiciliation, b.proprio, b.owner_address";
92 $sql .= ", b.account_number, b.currency_code";
93 $sql .= ", b.min_allowed, b.min_desired, comment";
94 $sql .= ', b.fk_accountancy_journal';
95 $sql .= ', aj.code as accountancy_journal';
96 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
97 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=b.fk_accountancy_journal';
98 $sql .= " WHERE b.entity = ".$conf->entity;
99 $sql .= " AND clos = 0";
100 //$sql.= " AND courant = 1";
101 $sql .= " ORDER BY label";
102 $sql .= $this->db->plimit($max, 0);
103
104 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
105 $result = $this->db->query($sql);
106 if ($result) {
107 $num = $this->db->num_rows($result);
108
109 $line = 0;
110 $solde_total = array();
111
112 $account_static = new Account($this->db);
113 while ($line < $num) {
114 $objp = $this->db->fetch_object($result);
115
116 $account_static->id = $objp->rowid;
117 $account_static->ref = $objp->ref;
118 $account_static->label = $objp->label;
119 $account_static->number = $objp->number;
120 $account_static->account_number = $objp->account_number;
121 $account_static->currency_code = $objp->currency_code;
122 $account_static->accountancy_journal = $objp->accountancy_journal;
123 $solde = $account_static->solde(0);
124
125 if (!array_key_exists($objp->currency_code, $solde_total)) {
126 $solde_total[$objp->currency_code] = $solde;
127 } else {
128 $solde_total[$objp->currency_code] += $solde;
129 }
130
131
132 $this->info_box_contents[$line][] = array(
133 'td' => '',
134 'text' => $account_static->getNomUrl(1),
135 'asis' => 1,
136 );
137
138 $this->info_box_contents[$line][] = array(
139 'td' => '',
140 'text' => $objp->number,
141 );
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="nowraponall right amount"',
145 'text' => '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$account_static->id.'">'
146 .price($solde, 0, $langs, 1, -1, -1, $objp->currency_code)
147 .'</a>',
148 'asis' => 1,
149 );
150
151 $line++;
152 }
153
154 // Total
155 foreach ($solde_total as $key => $solde) {
156 $this->info_box_contents[$line][] = array(
157 'tr' => 'class="liste_total"',
158 'td' => 'class="liste_total left"',
159 'text' => $langs->trans('Total').' '.$key,
160 );
161 $this->info_box_contents[$line][] = array(
162 'td' => 'class="liste_total right"',
163 'text' => '&nbsp;'
164 );
165
166 $this->info_box_contents[$line][] = array(
167 'td' => 'class="liste_total nowraponall right amount"',
168 'text' => price($solde, 0, $langs, 0, -1, -1, $key)
169 );
170 $line++;
171 }
172
173 $this->db->free($result);
174 } else {
175 $this->info_box_contents[0][0] = array(
176 'td' => '',
177 'maxlength'=>500,
178 'text' => ($this->db->error().' sql='.$sql),
179 );
180 }
181 } else {
182 $this->info_box_contents[0][0] = array(
183 'td' => 'class="nohover opacitymedium left"',
184 'text' => $langs->trans("ReadPermissionNotAllowed")
185 );
186 }
187 }
188
197 public function showBox($head = null, $contents = null, $nooutput = 0)
198 {
199 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
200 }
201}
Class to manage bank accounts.
Class ModeleBoxes.
Class to manage the box to show last users.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.