dolibarr  7.0.0-beta
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@capnetworks.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 <http://www.gnu.org/licenses/>.
20  */
21 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 
30 
34 class box_comptes extends ModeleBoxes
35 {
36  var $boxcode="currentaccounts";
37  var $boximg="object_bill";
38  var $boxlabel="BoxCurrentAccounts";
39  var $depends = array("banque"); // Box active if module banque active
40 
41  var $db;
42  var $param;
43  var $enabled = 1;
44 
45  var $info_box_head = array();
46  var $info_box_contents = array();
47 
48 
55  function __construct($db,$param='')
56  {
57  global $conf, $user;
58 
59  $this->db = $db;
60 
61  // disable module for such cases
62  $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL);
63  if (! in_array('banque',$listofmodulesforexternal) && ! empty($user->societe_id)) $this->enabled=0; // disabled for external users
64 
65  $this->hidden = ! ($user->rights->banque->lire);
66  }
67 
74  function loadBox($max=5)
75  {
76  global $user, $langs, $db, $conf;
77 
78  $this->max=$max;
79 
80  $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts"));
81 
82  if ($user->rights->banque->lire) {
83  $sql = "SELECT b.rowid, b.ref, b.label, b.bank,b.number, b.courant, b.clos, b.rappro, b.url";
84  $sql.= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban";
85  $sql.= ", b.domiciliation, b.proprio, b.owner_address";
86  $sql.= ", b.account_number, b.currency_code";
87  $sql.= ", b.min_allowed, b.min_desired, comment";
88  $sql.= ', b.fk_accountancy_journal';
89  $sql.= ', aj.code as accountancy_journal';
90  $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as b";
91  $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'accounting_journal as aj ON aj.rowid=b.fk_accountancy_journal';
92  $sql.= " WHERE b.entity = ".$conf->entity;
93  $sql.= " AND clos = 0";
94  //$sql.= " AND courant = 1";
95  $sql.= " ORDER BY label";
96  $sql.= $db->plimit($max, 0);
97 
98  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
99  $result = $db->query($sql);
100  if ($result) {
101  $num = $db->num_rows($result);
102 
103  $line = 0;
104  $solde_total = array();
105 
106  $account_static = new Account($db);
107  while ($line < $num) {
108  $objp = $db->fetch_object($result);
109 
110  $account_static->id = $objp->rowid;
111  $account_static->ref = $objp->ref;
112  $account_static->label = $objp->label;
113  $account_static->number = $objp->number;
114  $account_static->account_number = $objp->account_number;
115  $account_static->currency_code = $objp->currency_code;
116  $account_static->accountancy_journal = $objp->accountancy_journal;
117  $solde=$account_static->solde(0);
118 
119  $solde_total[$objp->currency_code] += $solde;
120 
121  $this->info_box_contents[$line][] = array(
122  'td' => '',
123  'text' => $account_static->getNomUrl(1),
124  'asis' => 1,
125  );
126 
127  $this->info_box_contents[$line][] = array(
128  'td' => '',
129  'text' => $objp->number,
130  );
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => 'class="right"',
134  'text' => price($solde, 0, $langs, 0, -1, -1, $objp->currency_code)
135  );
136 
137  $line++;
138  }
139 
140  // Total
141  foreach ($solde_total as $key=>$solde) {
142  $this->info_box_contents[$line][] = array(
143  'tr' => 'class="liste_total"',
144  'td' => 'align="left" class="liste_total"',
145  'text' => $langs->trans('Total').' '.$key,
146  );
147  $this->info_box_contents[$line][] = array(
148  'td' => 'align="right" class="liste_total"',
149  'text' => '&nbsp;'
150  );
151 
152  $this->info_box_contents[$line][] = array(
153  'td' => 'align="right" class="liste_total"',
154  'text' => price($solde, 0, $langs, 0, -1, -1, $key)
155  );
156  $line++;
157  }
158 
159  $db->free($result);
160  } else {
161  $this->info_box_contents[0][0] = array(
162  'td' => '',
163  'maxlength'=>500,
164  'text' => ($db->error().' sql='.$sql),
165  );
166  }
167  } else {
168  $this->info_box_contents[0][0] = array(
169  'td' => 'align="left" class="nohover opacitymedium"',
170  'text' => $langs->trans("ReadPermissionNotAllowed")
171  );
172  }
173 
174  }
175 
184  function showBox($head = null, $contents = null, $nooutput=0)
185  {
186  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
187  }
188 
189 }
190 
__construct($db, $param='')
Constructor.
Definition: box_comptes.php:55
Class ModeleBoxes.
Class to manage bank accounts.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
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...
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_comptes.php:74
Class to manage the box to show last users.
Definition: box_comptes.php:34