dolibarr  13.0.2
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 ".MAIN_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  {
101  if ($this->db->affected_rows($resql))
102  {
103  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user_rib");
104 
105  return $this->update($user);
106  }
107  } else {
108  print $this->db->error();
109  return 0;
110  }
111  }
112 
120  public function update(User $user = null, $notrigger = 0)
121  {
122  global $conf;
123 
124  if (!$this->id)
125  {
126  $this->create();
127  }
128 
129  $sql = "UPDATE ".MAIN_DB_PREFIX."user_rib SET";
130  $sql .= " bank = '".$this->db->escape($this->bank)."'";
131  $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
132  $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
133  $sql .= ",number='".$this->db->escape($this->number)."'";
134  $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
135  $sql .= ",bic='".$this->db->escape($this->bic)."'";
136  $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
137  $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
138  $sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
139  $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
140 
141  if (trim($this->label) != '')
142  $sql .= ",label = '".$this->db->escape($this->label)."'";
143  else $sql .= ",label = NULL";
144  $sql .= " WHERE rowid = ".$this->id;
145 
146  $result = $this->db->query($sql);
147  if ($result)
148  {
149  return 1;
150  } else {
151  dol_print_error($this->db);
152  return 0;
153  }
154  }
155 
164  public function fetch($id, $ref = '', $userid = 0)
165  {
166  if (empty($id) && empty($ref) && empty($userid)) return -1;
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 ".MAIN_DB_PREFIX."user_rib";
171  if ($id) $sql .= " WHERE rowid = ".$id;
172  if ($ref) $sql .= " WHERE label = '".$this->db->escape($ref)."'";
173  if ($userid) $sql .= " WHERE fk_user = ".((int) $userid);
174 
175  $resql = $this->db->query($sql);
176  if ($resql)
177  {
178  if ($this->db->num_rows($resql))
179  {
180  $obj = $this->db->fetch_object($resql);
181 
182  $this->id = $obj->rowid;
183  $this->userid = $obj->fk_soc;
184  $this->bank = $obj->bank;
185  $this->code_banque = $obj->code_banque;
186  $this->code_guichet = $obj->code_guichet;
187  $this->number = $obj->number;
188  $this->cle_rib = $obj->cle_rib;
189  $this->bic = $obj->bic;
190  $this->iban = $obj->iban;
191  $this->domiciliation = $obj->domiciliation;
192  $this->proprio = $obj->proprio;
193  $this->owner_address = $obj->owner_address;
194  $this->label = $obj->label;
195  $this->datec = $this->db->jdate($obj->datec);
196  $this->datem = $this->db->jdate($obj->datem);
197  }
198  $this->db->free($resql);
199 
200  return 1;
201  } else {
202  dol_print_error($this->db);
203  return -1;
204  }
205  }
206 
213  public function getRibLabel($displayriblabel = true)
214  {
215  $rib = '';
216 
217  if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) {
218  if ($this->label && $displayriblabel) {
219  $rib = $this->label." : ";
220  }
221 
222  $rib .= (string) $this;
223  }
224 
225  return $rib;
226  }
227 }
Class to manage bank accounts description of users.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
fetch($id, $ref= '', $userid=0)
Load record from database.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage bank accounts.
__construct(DoliDB $db)
Constructor.
create(User $user=null, $notrigger=0)
Create bank information record.
getRibLabel($displayriblabel=true)
Return RIB.
update(User $user=null, $notrigger=0)
Update bank account.
print
Draft customers invoices.
Definition: index.php:89
solde($option=0)
Return current sold.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...