dolibarr  9.0.0
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 <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 
44  public $db;
45 
46  var $param;
47  var $enabled = 1;
48 
49  var $info_box_head = array();
50  var $info_box_contents = array();
51 
52 
59  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->societe_id)) $this->enabled=0; // disabled for external users
68 
69  $this->hidden = ! ($user->rights->banque->lire);
70  }
71 
78  function loadBox($max=5)
79  {
80  global $user, $langs, $db, $conf;
81 
82  $this->max=$max;
83 
84  $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts"));
85 
86  if ($user->rights->banque->lire) {
87  $sql = "SELECT b.rowid, b.ref, b.label, b.bank,b.number, b.courant, b.clos, b.rappro, b.url";
88  $sql.= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban";
89  $sql.= ", b.domiciliation, b.proprio, b.owner_address";
90  $sql.= ", b.account_number, b.currency_code";
91  $sql.= ", b.min_allowed, b.min_desired, comment";
92  $sql.= ', b.fk_accountancy_journal';
93  $sql.= ', aj.code as accountancy_journal';
94  $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as b";
95  $sql.= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'accounting_journal as aj ON aj.rowid=b.fk_accountancy_journal';
96  $sql.= " WHERE b.entity = ".$conf->entity;
97  $sql.= " AND clos = 0";
98  //$sql.= " AND courant = 1";
99  $sql.= " ORDER BY label";
100  $sql.= $db->plimit($max, 0);
101 
102  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
103  $result = $db->query($sql);
104  if ($result) {
105  $num = $db->num_rows($result);
106 
107  $line = 0;
108  $solde_total = array();
109 
110  $account_static = new Account($db);
111  while ($line < $num) {
112  $objp = $db->fetch_object($result);
113 
114  $account_static->id = $objp->rowid;
115  $account_static->ref = $objp->ref;
116  $account_static->label = $objp->label;
117  $account_static->number = $objp->number;
118  $account_static->account_number = $objp->account_number;
119  $account_static->currency_code = $objp->currency_code;
120  $account_static->accountancy_journal = $objp->accountancy_journal;
121  $solde=$account_static->solde(0);
122 
123  $solde_total[$objp->currency_code] += $solde;
124 
125  $this->info_box_contents[$line][] = array(
126  'td' => '',
127  'text' => $account_static->getNomUrl(1),
128  'asis' => 1,
129  );
130 
131  $this->info_box_contents[$line][] = array(
132  'td' => '',
133  'text' => $objp->number,
134  );
135 
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="right"',
138  'text' => price($solde, 0, $langs, 0, -1, -1, $objp->currency_code)
139  );
140 
141  $line++;
142  }
143 
144  // Total
145  foreach ($solde_total as $key=>$solde) {
146  $this->info_box_contents[$line][] = array(
147  'tr' => 'class="liste_total"',
148  'td' => 'align="left" class="liste_total"',
149  'text' => $langs->trans('Total').' '.$key,
150  );
151  $this->info_box_contents[$line][] = array(
152  'td' => 'align="right" class="liste_total"',
153  'text' => '&nbsp;'
154  );
155 
156  $this->info_box_contents[$line][] = array(
157  'td' => 'align="right" class="liste_total"',
158  'text' => price($solde, 0, $langs, 0, -1, -1, $key)
159  );
160  $line++;
161  }
162 
163  $db->free($result);
164  } else {
165  $this->info_box_contents[0][0] = array(
166  'td' => '',
167  'maxlength'=>500,
168  'text' => ($db->error().' sql='.$sql),
169  );
170  }
171  } else {
172  $this->info_box_contents[0][0] = array(
173  'td' => 'align="left" class="nohover opacitymedium"',
174  'text' => $langs->trans("ReadPermissionNotAllowed")
175  );
176  }
177  }
178 
187  function showBox($head = null, $contents = null, $nooutput=0)
188  {
189  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
190  }
191 }
192 
__construct($db, $param='')
Constructor.
Definition: box_comptes.php:59
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:78
Class to manage the box to show last users.
Definition: box_comptes.php:34