dolibarr  16.0.5
userbankaccount.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2010-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
6  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
7  * Copyright (C) 2016 Marcos GarcĂ­a <marcosgdf@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30 
31 
35 class UserBankAccount extends Account
36 {
40  public $element = 'user_bank_account';
41 
45  public $table_element = 'user_rib';
46 
47 
53  public $datec;
54 
60  public $datem;
61 
67  public $userid;
68 
69 
75  public function __construct(DoliDB $db)
76  {
77  $this->db = $db;
78 
79  $this->userid = 0;
80  $this->solde = 0;
81  $this->error_number = 0;
82  }
83 
84 
92  public function create(User $user = null, $notrigger = 0)
93  {
94  $now = dol_now();
95 
96  $sql = "INSERT INTO ".$this->db->prefix()."user_rib (fk_user, datec)";
97  $sql .= " VALUES (".$this->userid.", '".$this->db->idate($now)."')";
98  $resql = $this->db->query($sql);
99  if ($resql) {
100  if ($this->db->affected_rows($resql)) {
101  $this->id = $this->db->last_insert_id($this->db->prefix()."user_rib");
102 
103  return $this->update($user);
104  }
105  } else {
106  print $this->db->error();
107  return 0;
108  }
109  }
110 
118  public function update(User $user = null, $notrigger = 0)
119  {
120  global $conf;
121 
122  if (!$this->id) {
123  $this->create();
124  }
125 
126  $sql = "UPDATE ".$this->db->prefix()."user_rib SET";
127  $sql .= " bank = '".$this->db->escape($this->bank)."'";
128  $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
129  $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
130  $sql .= ",number='".$this->db->escape($this->number)."'";
131  $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
132  $sql .= ",bic='".$this->db->escape($this->bic)."'";
133  $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
134  $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
135  $sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
136  $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
137 
138  if (trim($this->label) != '') {
139  $sql .= ",label = '".$this->db->escape($this->label)."'";
140  } else {
141  $sql .= ",label = NULL";
142  }
143  $sql .= " WHERE rowid = ".((int) $this->id);
144 
145  $result = $this->db->query($sql);
146  if ($result) {
147  return 1;
148  } else {
149  dol_print_error($this->db);
150  return 0;
151  }
152  }
153 
162  public function fetch($id, $ref = '', $userid = 0)
163  {
164  if (empty($id) && empty($ref) && empty($userid)) {
165  return -1;
166  }
167 
168  $sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
169  $sql .= " owner_address, label, datec, tms as datem";
170  $sql .= " FROM ".$this->db->prefix()."user_rib";
171  if ($id) {
172  $sql .= " WHERE rowid = ".((int) $id);
173  }
174  if ($ref) {
175  $sql .= " WHERE label = '".$this->db->escape($ref)."'";
176  }
177  if ($userid) {
178  $sql .= " WHERE fk_user = ".((int) $userid);
179  }
180 
181  $resql = $this->db->query($sql);
182  if ($resql) {
183  if ($this->db->num_rows($resql)) {
184  $obj = $this->db->fetch_object($resql);
185 
186  $this->id = $obj->rowid;
187  $this->userid = $obj->fk_soc;
188  $this->bank = $obj->bank;
189  $this->code_banque = $obj->code_banque;
190  $this->code_guichet = $obj->code_guichet;
191  $this->number = $obj->number;
192  $this->cle_rib = $obj->cle_rib;
193  $this->bic = $obj->bic;
194  $this->iban = $obj->iban;
195  $this->domiciliation = $obj->domiciliation;
196  $this->proprio = $obj->proprio;
197  $this->owner_address = $obj->owner_address;
198  $this->label = $obj->label;
199  $this->datec = $this->db->jdate($obj->datec);
200  $this->datem = $this->db->jdate($obj->datem);
201  }
202  $this->db->free($resql);
203 
204  return 1;
205  } else {
206  dol_print_error($this->db);
207  return -1;
208  }
209  }
210 
217  public function getRibLabel($displayriblabel = true)
218  {
219  $rib = '';
220 
221  if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) {
222  if ($this->label && $displayriblabel) {
223  $rib = $this->label." : ";
224  }
225 
226  $rib .= (string) $this;
227  }
228 
229  return $rib;
230  }
231 }
db
$conf db
API class for accounts.
Definition: inc.php:41
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
UserBankAccount
Class to manage bank accounts description of users.
Definition: userbankaccount.class.php:35
UserBankAccount\__construct
__construct(DoliDB $db)
Constructor.
Definition: userbankaccount.class.php:75
UserBankAccount\fetch
fetch($id, $ref='', $userid=0)
Load record from database.
Definition: userbankaccount.class.php:162
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Account\solde
solde($option=0, $date_end='', $field='dateo')
Return current sold.
Definition: account.class.php:1237
UserBankAccount\create
create(User $user=null, $notrigger=0)
Create bank information record.
Definition: userbankaccount.class.php:92
UserBankAccount\update
update(User $user=null, $notrigger=0)
Update bank account.
Definition: userbankaccount.class.php:118
UserBankAccount\getRibLabel
getRibLabel($displayriblabel=true)
Return RIB.
Definition: userbankaccount.class.php:217
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Account
Class to manage bank accounts.
Definition: account.class.php:38