dolibarr  20.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@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 = "bank_account";
38  public $boxlabel = "BoxCurrentAccounts";
39  public $depends = array("banque"); // Box active if module banque active
40 
41  public $enabled = 1;
42 
49  public function __construct($db, $param = '')
50  {
51  global $conf, $user;
52 
53  $this->db = $db;
54 
55  // disable module for such cases
56  $listofmodulesforexternal = explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL'));
57  if (!in_array('banque', $listofmodulesforexternal) && !empty($user->socid)) {
58  $this->enabled = 0; // disabled for external users
59  }
60 
61  $this->hidden = !$user->hasRight('banque', 'lire');
62  }
63 
70  public function loadBox($max = 5)
71  {
72  global $user, $langs, $conf;
73 
74  $this->max = $max;
75 
76  $this->info_box_head = array('text' => $langs->trans("BoxTitleCurrentAccounts"));
77 
78  if ($user->hasRight('banque', 'lire')) {
79  $sql = "SELECT b.rowid, b.ref, b.label, b.bank, b.number, b.courant, b.clos, b.rappro, b.url";
80  $sql .= ", b.code_banque, b.code_guichet, b.cle_rib, b.bic, b.iban_prefix as iban";
81  $sql .= ", b.domiciliation as address, b.proprio, b.owner_address";
82  $sql .= ", b.account_number, b.currency_code";
83  $sql .= ", b.min_allowed, b.min_desired, comment";
84  $sql .= ', b.fk_accountancy_journal';
85  $sql .= ', aj.code as accountancy_journal';
86  $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as b";
87  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid = b.fk_accountancy_journal';
88  $sql .= " WHERE b.entity = ".$conf->entity;
89  $sql .= " AND clos = 0";
90  $sql .= " ORDER BY label";
91 
92  $sql .= $this->db->plimit($max, 0);
93 
94  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
95 
96  $result = $this->db->query($sql);
97  if ($result) {
98  $num = $this->db->num_rows($result);
99 
100  $line = 0;
101  $solde_total = array();
102 
103  $account_static = new Account($this->db);
104  while ($line < $num) {
105  $objp = $this->db->fetch_object($result);
106 
107  $account_static->id = $objp->rowid;
108  $account_static->ref = $objp->ref;
109  $account_static->label = $objp->label;
110  $account_static->number = $objp->number;
111  $account_static->account_number = $objp->account_number;
112  $account_static->currency_code = $objp->currency_code;
113  $account_static->accountancy_journal = $objp->accountancy_journal;
114  $solde = $account_static->solde(0);
115 
116  if (!array_key_exists($objp->currency_code, $solde_total)) {
117  $solde_total[$objp->currency_code] = $solde;
118  } else {
119  $solde_total[$objp->currency_code] += $solde;
120  }
121 
122 
123  $this->info_box_contents[$line][] = array(
124  'td' => '',
125  'text' => $account_static->getNomUrl(1),
126  'asis' => 1,
127  );
128 
129  $this->info_box_contents[$line][] = array(
130  'td' => '',
131  'text' => $objp->number,
132  );
133 
134  $this->info_box_contents[$line][] = array(
135  'td' => 'class="nowraponall right amount"',
136  'text' => '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$account_static->id.'">'
137  .price($solde, 0, $langs, 1, -1, -1, $objp->currency_code)
138  .'</a>',
139  'asis' => 1,
140  );
141 
142  $line++;
143  }
144 
145  // Total
146  foreach ($solde_total as $key => $solde) {
147  $this->info_box_contents[$line][] = array(
148  'tr' => 'class="liste_total"',
149  'td' => 'class="liste_total left"',
150  'text' => $langs->trans('Total').' '.$key,
151  );
152  $this->info_box_contents[$line][] = array(
153  'td' => 'class="liste_total right"',
154  'text' => '&nbsp;'
155  );
156 
157  $this->info_box_contents[$line][] = array(
158  'td' => 'class="liste_total nowraponall right amount"',
159  'text' => '<span class="amount">'.price($solde, 0, $langs, 0, -1, -1, $key).'</span>'
160  );
161  $line++;
162  }
163 
164  $this->db->free($result);
165  } else {
166  $this->info_box_contents[0][0] = array(
167  'td' => '',
168  'maxlength'=>500,
169  'text' => ($this->db->error().' sql='.$sql),
170  );
171  }
172  } else {
173  $this->info_box_contents[0][0] = array(
174  'td' => 'class="nohover left"',
175  'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
176  );
177  }
178  }
179 
188  public function showBox($head = null, $contents = null, $nooutput = 0)
189  {
190  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
191  }
192 }
Class to manage bank accounts.
Class ModeleBoxes.
Class to manage the box to show bank accounts.
Definition: box_comptes.php:35
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_comptes.php:70
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
Definition: box_comptes.php:49
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.