28require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
39 public $element =
'societe_rib';
44 public $table_element =
'societe_rib';
90 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>10,
'notnull'=>1,
'visible'=>-1,),
91 'type' => array(
'type'=>
'varchar(32)',
'label'=>
'Type',
'enabled'=>
'1',
'position'=>15,
'notnull'=>1,
'visible'=>-1,),
92 'fk_soc' => array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'picto'=>
'company',
'enabled'=>
'1',
'position'=>20,
'notnull'=>1,
'visible'=>-1,
'css'=>
'maxwidth500 widthcentpercentminusxx',
'csslist'=>
'tdoverflowmax150',),
93 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>25,
'notnull'=>0,
'visible'=>-1,),
94 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>
'1',
'position'=>30,
'notnull'=>1,
'visible'=>-1,),
95 'label' => array(
'type'=>
'varchar(200)',
'label'=>
'Label',
'enabled'=>
'1',
'position'=>35,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',
'css'=>
'minwidth300',
'cssview'=>
'wordbreak',
'csslist'=>
'tdoverflowmax150',),
96 'bank' => array(
'type'=>
'varchar(255)',
'label'=>
'Bank',
'enabled'=>
'1',
'position'=>40,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
97 'code_banque' => array(
'type'=>
'varchar(128)',
'label'=>
'Codebanque',
'enabled'=>
'1',
'position'=>45,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
98 'code_guichet' => array(
'type'=>
'varchar(6)',
'label'=>
'Codeguichet',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
99 'number' => array(
'type'=>
'varchar(255)',
'label'=>
'Number',
'enabled'=>
'1',
'position'=>55,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
100 'cle_rib' => array(
'type'=>
'varchar(5)',
'label'=>
'Clerib',
'enabled'=>
'1',
'position'=>60,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
101 'bic' => array(
'type'=>
'varchar(20)',
'label'=>
'Bic',
'enabled'=>
'1',
'position'=>65,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
102 'iban_prefix' => array(
'type'=>
'varchar(34)',
'label'=>
'Ibanprefix',
'enabled'=>
'1',
'position'=>70,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
103 'domiciliation' => array(
'type'=>
'varchar(255)',
'label'=>
'Domiciliation',
'enabled'=>
'1',
'position'=>75,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
104 'proprio' => array(
'type'=>
'varchar(60)',
'label'=>
'Proprio',
'enabled'=>
'1',
'position'=>80,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
105 'owner_address' => array(
'type'=>
'varchar(255)',
'label'=>
'Owneraddress',
'enabled'=>
'1',
'position'=>85,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
106 'default_rib' => array(
'type'=>
'smallint(6)',
'label'=>
'Defaultrib',
'enabled'=>
'1',
'position'=>90,
'notnull'=>1,
'visible'=>-1,
'alwayseditable'=>
'1',),
107 'state_id' => array(
'type'=>
'integer',
'label'=>
'Stateid',
'enabled'=>
'1',
'position'=>95,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
108 'fk_country' => array(
'type'=>
'integer',
'label'=>
'Fkcountry',
'enabled'=>
'1',
'position'=>100,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',
'css'=>
'maxwidth500 widthcentpercentminusxx',),
109 'currency_code' => array(
'type'=>
'varchar(3)',
'label'=>
'Currencycode',
'enabled'=>
'1',
'position'=>105,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
110 'rum' => array(
'type'=>
'varchar(32)',
'label'=>
'Rum',
'enabled'=>
'1',
'position'=>110,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
111 'date_rum' => array(
'type'=>
'date',
'label'=>
'Daterum',
'enabled'=>
'1',
'position'=>115,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
112 'frstrecur' => array(
'type'=>
'varchar(16)',
'label'=>
'Frstrecur',
'enabled'=>
'1',
'position'=>120,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
113 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>
'1',
'position'=>900,
'notnull'=>0,
'visible'=>-2,
'alwayseditable'=>
'1',),
114 'last_four' => array(
'type'=>
'varchar(4)',
'label'=>
'Lastfour',
'enabled'=>
'1',
'position'=>130,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
115 'card_type' => array(
'type'=>
'varchar(255)',
'label'=>
'Cardtype',
'enabled'=>
'1',
'position'=>135,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
116 'cvn' => array(
'type'=>
'varchar(255)',
'label'=>
'Cvn',
'enabled'=>
'1',
'position'=>140,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
117 'exp_date_month' => array(
'type'=>
'integer',
'label'=>
'Expdatemonth',
'enabled'=>
'1',
'position'=>145,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
118 'exp_date_year' => array(
'type'=>
'integer',
'label'=>
'Expdateyear',
'enabled'=>
'1',
'position'=>150,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
119 'country_code' => array(
'type'=>
'varchar(10)',
'label'=>
'Countrycode',
'enabled'=>
'1',
'position'=>155,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
120 'approved' => array(
'type'=>
'integer',
'label'=>
'Approved',
'enabled'=>
'1',
'position'=>160,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
121 'email' => array(
'type'=>
'varchar(255)',
'label'=>
'Email',
'enabled'=>
'1',
'position'=>165,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
122 'ending_date' => array(
'type'=>
'date',
'label'=>
'Endingdate',
'enabled'=>
'1',
'position'=>170,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
123 'max_total_amount_of_all_payments' => array(
'type'=>
'double(24,8)',
'label'=>
'Maxtotalamountofallpayments',
'enabled'=>
'1',
'position'=>175,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
124 'preapproval_key' => array(
'type'=>
'varchar(255)',
'label'=>
'Preapprovalkey',
'enabled'=>
'1',
'position'=>180,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
125 'starting_date' => array(
'type'=>
'date',
'label'=>
'Startingdate',
'enabled'=>
'1',
'position'=>185,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
126 'total_amount_of_all_payments' => array(
'type'=>
'double(24,8)',
'label'=>
'Totalamountofallpayments',
'enabled'=>
'1',
'position'=>190,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
127 'stripe_card_ref' => array(
'type'=>
'varchar(128)',
'label'=>
'Stripecardref',
'enabled'=>
'1',
'position'=>195,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
128 'status' => array(
'type'=>
'integer',
'label'=>
'Status',
'enabled'=>
'1',
'position'=>500,
'notnull'=>1,
'visible'=>-1,
'alwayseditable'=>
'1',),
129 'comment' => array(
'type'=>
'varchar(255)',
'label'=>
'Comment',
'enabled'=>
'1',
'position'=>205,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
130 'ipaddress' => array(
'type'=>
'varchar(68)',
'label'=>
'Ipaddress',
'enabled'=>
'1',
'position'=>210,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
131 'stripe_account' => array(
'type'=>
'varchar(128)',
'label'=>
'Stripeaccount',
'enabled'=>
'1',
'position'=>215,
'notnull'=>0,
'visible'=>-1,
'alwayseditable'=>
'1',),
132 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>0,
'position'=>230),
155 public $code_guichet;
160 public $domiciliation;
162 public $owner_address;
170 public $currency_code;
184 public $exp_date_month;
185 public $exp_date_year;
186 public $country_code;
190 public $max_total_amount_of_all_payments;
191 public $preapproval_key;
192 public $starting_date;
193 public $total_amount_of_all_payments;
196 public $ext_payment_site;
206 public $stripe_account;
213 public $stripe_card_ref;
233 const TRIGGER_PREFIX =
'COMPANY_RIB';
247 $this->default_rib = 0;
266 if (empty($this->socid)) {
267 $this->
error =
'BadValueForParameter';
268 $this->errors[] = $this->error;
272 if (empty($this->datec)) {
278 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib where fk_soc = ".((int) $this->socid).
" AND default_rib = 1 AND type = 'ban'";
279 $result = $this->db->query($sql);
281 $numrows = $this->db->num_rows($result);
282 if ($this->default_rib && $numrows > 0) {
283 $this->default_rib = 0;
285 if (empty($this->default_rib) && $numrows == 0) {
286 $this->default_rib = 1;
293 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_rib (fk_soc, type, datec, model_pdf)";
294 $sql .=
" VALUES (".((int) $this->socid).
", '".$this->
type.
"', '".$this->db->idate($this->datec).
"',";
297 $resql = $this->db->query($sql);
299 if ($this->db->affected_rows($resql)) {
300 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe_rib");
304 $result = $this->
call_trigger(
'COMPANY_RIB_CREATE', $user);
313 $this->
error = $this->db->lasterror();
314 $this->errors[] = $this->error;
321 $this->db->rollback();
344 $this->domiciliation =
dol_trunc($this->domiciliation, 254,
'right',
'UTF-8', 1);
347 $this->owner_address =
dol_trunc($this->owner_address, 254,
'right',
'UTF-8', 1);
350 if (isset($this->model_pdf)) {
351 $this->model_pdf = trim($this->model_pdf);
356 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET";
357 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
358 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
359 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
360 $sql .=
",number='".$this->db->escape($this->number).
"'";
361 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
362 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
363 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
364 $sql .=
",domiciliation = '".$this->db->escape($this->domiciliation).
"'";
365 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
366 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
367 $sql .=
",default_rib = ".((int) $this->default_rib);
368 if (isModEnabled(
'prelevement')) {
369 $sql .=
",frstrecur = '".$this->db->escape($this->frstrecur).
"'";
370 $sql .=
",rum = '".$this->db->escape($this->rum).
"'";
371 $sql .=
",date_rum = ".($this->date_rum ?
"'".$this->db->idate($this->date_rum).
"'" :
"null");
373 if (trim($this->label) !=
'') {
374 $sql .=
",label = '".$this->db->escape($this->label).
"'";
376 $sql .=
",label = NULL";
378 $sql .=
",stripe_card_ref = '".$this->db->escape($this->stripe_card_ref).
"'";
379 $sql .=
",stripe_account = '".$this->db->escape($this->stripe_account).
"'";
380 $sql .=
",model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
381 $sql .=
" WHERE rowid = ".((int) $this->
id);
383 $result = $this->db->query($sql);
387 $result = $this->
call_trigger(
'COMPANY_RIB_MODIFY', $user);
395 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
396 $this->
error = $langs->trans(
'ErrorDuplicateField');
398 $this->
error = $this->db->lasterror();
400 $this->errors[] = $this->error;
407 $this->db->rollback();
421 public function fetch($id, $socid = 0, $default = 1, $type =
'ban')
423 if (empty($id) && empty($socid)) {
427 $sql =
"SELECT rowid, type, fk_soc as socid, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
428 $sql .=
" owner_address, default_rib, label, datec, tms as datem, rum, frstrecur, date_rum,";
429 $sql .=
" stripe_card_ref, stripe_account, ext_payment_site";
430 $sql .=
" ,last_main_doc";
431 $sql .=
" ,model_pdf";
433 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
435 $sql .=
" WHERE rowid = ".((int) $id);
436 } elseif ($socid > 0) {
437 $sql .=
" WHERE fk_soc = ".((int) $socid);
439 $sql .=
" AND default_rib = ".((int) $default);
442 $sql .=
" AND type = '".$this->db->escape($type).
"'";
446 $resql = $this->db->query($sql);
448 if ($this->db->num_rows($resql)) {
449 $obj = $this->db->fetch_object($resql);
451 $this->
ref = $obj->socid.
'-'.$obj->label;
453 $this->
id = $obj->rowid;
454 $this->
type = $obj->type;
455 $this->socid = $obj->socid;
456 $this->bank = $obj->bank;
457 $this->code_banque = $obj->code_banque;
458 $this->code_guichet = $obj->code_guichet;
459 $this->number = $obj->number;
460 $this->cle_rib = $obj->cle_rib;
461 $this->bic = $obj->bic;
462 $this->iban = $obj->iban;
463 $this->domiciliation = $obj->domiciliation;
464 $this->proprio = $obj->proprio;
465 $this->owner_address = $obj->owner_address;
466 $this->label = $obj->label;
467 $this->default_rib = $obj->default_rib;
468 $this->datec = $this->db->jdate($obj->datec);
469 $this->datem = $this->db->jdate($obj->datem);
470 $this->rum = $obj->rum;
471 $this->frstrecur = $obj->frstrecur;
472 $this->date_rum = $this->db->jdate($obj->date_rum);
473 $this->stripe_card_ref = $obj->stripe_card_ref;
474 $this->stripe_account = $obj->stripe_account;
475 $this->ext_payment_site= $obj->ext_payment_site;
476 $this->last_main_doc = $obj->last_main_doc;
477 $this->model_pdf = $obj->model_pdf;
479 $this->db->free($resql);
495 public function delete(
User $user =
null, $notrigger = 0)
499 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
503 if (!$error && !$notrigger) {
505 $result = $this->
call_trigger(
'COMPANY_RIB_DELETE', $user);
513 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
514 $sql .=
" WHERE rowid = ".((int) $this->
id);
516 if (!$this->db->query($sql)) {
518 $this->errors[] = $this->db->lasterror();
526 $this->db->rollback();
541 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
542 if ($this->label && $displayriblabel) {
543 $rib = $this->label.
" : ";
561 $sql1 =
"SELECT rowid as id, fk_soc as socid FROM ".MAIN_DB_PREFIX.
"societe_rib";
562 $sql1 .=
" WHERE rowid = ".($rib ? $rib : $this->id);
564 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
565 $result1 = $this->db->query($sql1);
567 if ($this->db->num_rows($result1) == 0) {
570 $obj = $this->db->fetch_object($result1);
574 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
575 $sql2 .=
" WHERE fk_soc = ".((int) $obj->socid);
576 if ($resetolddefaultfor) {
577 $sql2 .=
" AND type = '".$this->db->escape($resetolddefaultfor).
"'";
579 $result2 = $this->db->query($sql2);
581 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
582 $sql3 .=
" WHERE rowid = ".((int) $obj->id);
583 $result3 = $this->db->query($sql3);
585 if (!$result2 || !$result3) {
587 $this->db->rollback();
611 $this->label =
'CustomerCorp Bank account';
612 $this->bank =
'CustomerCorp Bank';
614 $this->clos = Account::STATUS_OPEN;
615 $this->code_banque =
'123';
616 $this->code_guichet =
'456';
617 $this->number =
'CUST12345';
620 $this->iban =
'FR999999999';
621 $this->domiciliation =
'Bank address of customer corp';
622 $this->proprio =
'Owner';
623 $this->owner_address =
'Owner address';
624 $this->country_id = 1;
626 $this->rum =
'UMR-CU1212-0007-5-1475405262';
627 $this->date_rum =
dol_now() - 10000;
628 $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.
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.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type