28require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
41 public $element =
'societe_rib';
46 public $table_element =
'societe_rib';
61 public $stripe_card_ref;
62 public $stripe_account;
83 const TRIGGER_PREFIX =
'COMPANY_RIB';
98 $this->default_rib = 0;
116 if (empty($this->socid)) {
117 $this->
error =
'BadValueForParameter';
118 $this->errors[] = $this->error;
124 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib where fk_soc = ".((int) $this->socid).
" AND default_rib = 1 AND type = 'ban'";
125 $result = $this->db->query($sql);
127 $numrows = $this->db->num_rows($result);
128 if ($this->default_rib && $numrows > 0) {
129 $this->default_rib = 0;
131 if (empty($this->default_rib) && $numrows == 0) {
132 $this->default_rib = 1;
139 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_rib (fk_soc, type, datec)";
140 $sql .=
" VALUES (".((int) $this->socid).
", 'ban', '".$this->db->idate($now).
"')";
141 $resql = $this->db->query($sql);
143 if ($this->db->affected_rows($resql)) {
144 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe_rib");
148 $result = $this->
call_trigger(
'COMPANY_RIB_CREATE', $user);
157 $this->
error = $this->db->lasterror();
158 $this->errors[] = $this->error;
165 $this->db->rollback();
188 $this->domiciliation =
dol_trunc($this->domiciliation, 254,
'right',
'UTF-8', 1);
191 $this->owner_address =
dol_trunc($this->owner_address, 254,
'right',
'UTF-8', 1);
196 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET";
197 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
198 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
199 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
200 $sql .=
",number='".$this->db->escape($this->number).
"'";
201 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
202 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
203 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
204 $sql .=
",domiciliation = '".$this->db->escape($this->domiciliation).
"'";
205 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
206 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
207 $sql .=
",default_rib = ".((int) $this->default_rib);
208 if (isModEnabled(
'prelevement')) {
209 $sql .=
",frstrecur = '".$this->db->escape($this->frstrecur).
"'";
210 $sql .=
",rum = '".$this->db->escape($this->rum).
"'";
211 $sql .=
",date_rum = ".($this->date_rum ?
"'".$this->db->idate($this->date_rum).
"'" :
"null");
213 if (trim($this->label) !=
'') {
214 $sql .=
",label = '".$this->db->escape($this->label).
"'";
216 $sql .=
",label = NULL";
218 $sql .=
",stripe_card_ref = '".$this->db->escape($this->stripe_card_ref).
"'";
219 $sql .=
",stripe_account = '".$this->db->escape($this->stripe_account).
"'";
220 $sql .=
" WHERE rowid = ".((int) $this->
id);
222 $result = $this->db->query($sql);
226 $result = $this->
call_trigger(
'COMPANY_RIB_MODIFY', $user);
234 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
235 $this->
error = $langs->trans(
'ErrorDuplicateField');
237 $this->
error = $this->db->lasterror();
239 $this->errors[] = $this->error;
246 $this->db->rollback();
260 public function fetch($id, $socid = 0, $default = 1, $type =
'ban')
262 if (empty($id) && empty($socid)) {
266 $sql =
"SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
267 $sql .=
" owner_address, default_rib, label, datec, tms as datem, rum, frstrecur, date_rum,";
268 $sql .=
" stripe_card_ref, stripe_account";
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
271 $sql .=
" WHERE rowid = ".((int) $id);
272 } elseif ($socid > 0) {
273 $sql .=
" WHERE fk_soc = ".((int) $socid);
275 $sql .=
" AND default_rib = ".((int) $default);
278 $sql .=
" AND type = '".$this->db->escape($type).
"'";
282 $resql = $this->db->query($sql);
284 if ($this->db->num_rows($resql)) {
285 $obj = $this->db->fetch_object($resql);
287 $this->
ref = $obj->fk_soc.
'-'.$obj->label;
289 $this->
id = $obj->rowid;
290 $this->
type = $obj->type;
291 $this->socid = $obj->fk_soc;
292 $this->bank = $obj->bank;
293 $this->code_banque = $obj->code_banque;
294 $this->code_guichet = $obj->code_guichet;
295 $this->number = $obj->number;
296 $this->cle_rib = $obj->cle_rib;
297 $this->bic = $obj->bic;
298 $this->iban = $obj->iban;
299 $this->domiciliation = $obj->domiciliation;
300 $this->proprio = $obj->proprio;
301 $this->owner_address = $obj->owner_address;
302 $this->label = $obj->label;
303 $this->default_rib = $obj->default_rib;
304 $this->datec = $this->db->jdate($obj->datec);
305 $this->datem = $this->db->jdate($obj->datem);
306 $this->rum = $obj->rum;
307 $this->frstrecur = $obj->frstrecur;
308 $this->date_rum = $this->db->jdate($obj->date_rum);
309 $this->stripe_card_ref = $obj->stripe_card_ref;
310 $this->stripe_account = $obj->stripe_account;
312 $this->db->free($resql);
328 public function delete(
User $user =
null, $notrigger = 0)
332 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
336 if (!$error && !$notrigger) {
338 $result = $this->
call_trigger(
'COMPANY_RIB_DELETE', $user);
346 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
347 $sql .=
" WHERE rowid = ".((int) $this->
id);
349 if (!$this->db->query($sql)) {
351 $this->errors[] = $this->db->lasterror();
359 $this->db->rollback();
374 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
375 if ($this->label && $displayriblabel) {
376 $rib = $this->label.
" : ";
394 $sql1 =
"SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX.
"societe_rib";
395 $sql1 .=
" WHERE rowid = ".($rib ? $rib : $this->id);
397 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
398 $result1 = $this->db->query($sql1);
400 if ($this->db->num_rows($result1) == 0) {
403 $obj = $this->db->fetch_object($result1);
407 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
408 $sql2 .=
" WHERE fk_soc = ".((int) $obj->fk_soc);
409 if ($resetolddefaultfor) {
410 $sql2 .=
" AND type = '".$this->db->escape($resetolddefaultfor).
"'";
412 $result2 = $this->db->query($sql2);
414 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
415 $sql3 .=
" WHERE rowid = ".((int) $obj->id);
416 $result3 = $this->db->query($sql3);
418 if (!$result2 || !$result3) {
420 $this->db->rollback();
444 $this->label =
'CustomerCorp Bank account';
445 $this->bank =
'CustomerCorp Bank';
447 $this->clos = Account::STATUS_OPEN;
448 $this->code_banque =
'123';
449 $this->code_guichet =
'456';
450 $this->number =
'CUST12345';
453 $this->iban =
'FR999999999';
454 $this->domiciliation =
'Bank address of customer corp';
455 $this->proprio =
'Owner';
456 $this->owner_address =
'Owner address';
457 $this->country_id = 1;
459 $this->rum =
'UMR-CU1212-0007-5-1475405262';
460 $this->date_rum =
dol_now() - 10000;
461 $this->frstrecur =
'FRST';
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current sold.
const TYPE_CURRENT
Current account.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage bank accounts description of third parties.
setAsDefault($rib=0, $resetolddefaultfor='ban')
Set a BAN as Default.
getRibLabel($displayriblabel=true)
Return RIB.
update(User $user=null, $notrigger=0)
Update bank account.
initAsSpecimen()
Initialise an instance with random values.
create(User $user=null, $notrigger=0)
Create bank information record.
__construct(DoliDB $db)
Constructor.
fetch($id, $socid=0, $default=1, $type='ban')
Load record from database.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type