dolibarr  13.0.2
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 
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  public $boxcode = "currentaccounts";
37  public $boximg = "object_bill";
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)) $this->enabled = 0; // disabled for external users
68 
69  $this->hidden = !($user->rights->banque->lire);
70  }
71 
78  public function loadBox($max = 5)
79  {
80  global $user, $langs, $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 .= $this->db->plimit($max, 0);
101 
102  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
103  $result = $this->db->query($sql);
104  if ($result) {
105  $num = $this->db->num_rows($result);
106 
107  $line = 0;
108  $solde_total = array();
109 
110  $account_static = new Account($this->db);
111  while ($line < $num) {
112  $objp = $this->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 nowraponall"',
138  'text' => price($solde, 0, $langs, 1, -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' => 'class="liste_total left"',
149  'text' => $langs->trans('Total').' '.$key,
150  );
151  $this->info_box_contents[$line][] = array(
152  'td' => 'class="liste_total right"',
153  'text' => '&nbsp;'
154  );
155 
156  $this->info_box_contents[$line][] = array(
157  'td' => 'class="liste_total right nowraponall"',
158  'text' => price($solde, 0, $langs, 0, -1, -1, $key)
159  );
160  $line++;
161  }
162 
163  $this->db->free($result);
164  } else {
165  $this->info_box_contents[0][0] = array(
166  'td' => '',
167  'maxlength'=>500,
168  'text' => ($this->db->error().' sql='.$sql),
169  );
170  }
171  } else {
172  $this->info_box_contents[0][0] = array(
173  'td' => 'class="nohover opacitymedium left"',
174  'text' => $langs->trans("ReadPermissionNotAllowed")
175  );
176  }
177  }
178 
187  public function showBox($head = null, $contents = null, $nooutput = 0)
188  {
189  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
190  }
191 }
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage bank accounts.
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.
__construct($db, $param= '')
Constructor.
Definition: box_comptes.php:59
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