30require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
42 public $TRIGGER_PREFIX =
'COMPANY_RIB';
47 public $element =
'societe_rib';
52 public $table_element =
'societe_rib';
97 public $fields = array(
98 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => -1,),
99 'type' => array(
'type' =>
'varchar(32)',
'label' =>
'Type',
'enabled' => 1,
'position' => 15,
'notnull' => 1,
'visible' => -1,),
100 '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',),
101 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
102 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 30,
'notnull' => 1,
'visible' => -1,),
103 'label' => array(
'type' =>
'varchar(200)',
'label' =>
'Label',
'enabled' => 1,
'position' => 35,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'csslist' =>
'tdoverflowmax150',),
104 'bank' => array(
'type' =>
'varchar(255)',
'label' =>
'Bank',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
105 'code_banque' => array(
'type' =>
'varchar(128)',
'label' =>
'Codebanque',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
106 'code_guichet' => array(
'type' =>
'varchar(6)',
'label' =>
'Codeguichet',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
107 'number' => array(
'type' =>
'varchar(255)',
'label' =>
'Number',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
108 'cle_rib' => array(
'type' =>
'varchar(5)',
'label' =>
'Clerib',
'enabled' => 1,
'position' => 60,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
109 'bic' => array(
'type' =>
'varchar(20)',
'label' =>
'Bic',
'enabled' => 1,
'position' => 65,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
110 'iban_prefix' => array(
'type' =>
'varchar(34)',
'label' =>
'Ibanprefix',
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
111 'domiciliation' => array(
'type' =>
'varchar(255)',
'label' =>
'Domiciliation',
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
112 'proprio' => array(
'type' =>
'varchar(60)',
'label' =>
'Proprio',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
113 'owner_address' => array(
'type' =>
'varchar(255)',
'label' =>
'Owneraddress',
'enabled' => 1,
'position' => 85,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
114 'default_rib' => array(
'type' =>
'smallint(6)',
'label' =>
'Defaultrib',
'enabled' => 1,
'position' => 90,
'notnull' => 1,
'visible' => -1,
'alwayseditable' => 1,),
115 'state_id' => array(
'type' =>
'integer',
'label' =>
'Stateid',
'enabled' => 1,
'position' => 95,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
116 'fk_country' => array(
'type' =>
'integer',
'label' =>
'Fkcountry',
'enabled' => 1,
'position' => 100,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
117 'currency_code' => array(
'type' =>
'varchar(3)',
'label' =>
'Currencycode',
'enabled' => 1,
'position' => 105,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
118 'rum' => array(
'type' =>
'varchar(32)',
'label' =>
'Rum',
'enabled' => 1,
'position' => 110,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
119 'date_rum' => array(
'type' =>
'date',
'label' =>
'Daterum',
'enabled' => 1,
'position' => 115,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
120 'frstrecur' => array(
'type' =>
'varchar(16)',
'label' =>
'Frstrecur',
'enabled' => 1,
'position' => 120,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
121 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'position' => 900,
'notnull' => 0,
'visible' => -2,
'alwayseditable' => 1,),
122 'last_four' => array(
'type' =>
'varchar(4)',
'label' =>
'Lastfour',
'enabled' => 1,
'position' => 130,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
123 'card_type' => array(
'type' =>
'varchar(255)',
'label' =>
'Cardtype',
'enabled' => 1,
'position' => 135,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
124 'cvn' => array(
'type' =>
'varchar(255)',
'label' =>
'Cvn',
'enabled' => 1,
'position' => 140,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
125 'exp_date_month' => array(
'type' =>
'integer',
'label' =>
'Expdatemonth',
'enabled' => 1,
'position' => 145,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
126 'exp_date_year' => array(
'type' =>
'integer',
'label' =>
'Expdateyear',
'enabled' => 1,
'position' => 150,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
127 'country_code' => array(
'type' =>
'varchar(10)',
'label' =>
'Countrycode',
'enabled' => 1,
'position' => 155,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
128 'approved' => array(
'type' =>
'integer',
'label' =>
'Approved',
'enabled' => 1,
'position' => 160,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
129 'email' => array(
'type' =>
'varchar(255)',
'label' =>
'Email',
'enabled' => 1,
'position' => 165,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
130 'ending_date' => array(
'type' =>
'date',
'label' =>
'Endingdate',
'enabled' => 1,
'position' => 170,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
131 'max_total_amount_of_all_payments' => array(
'type' =>
'double(24,8)',
'label' =>
'Maxtotalamountofallpayments',
'enabled' => 1,
'position' => 175,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
132 'preapproval_key' => array(
'type' =>
'varchar(255)',
'label' =>
'Preapprovalkey',
'enabled' => 1,
'position' => 180,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
133 'starting_date' => array(
'type' =>
'date',
'label' =>
'Startingdate',
'enabled' => 1,
'position' => 185,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
134 'total_amount_of_all_payments' => array(
'type' =>
'double(24,8)',
'label' =>
'Totalamountofallpayments',
'enabled' => 1,
'position' => 190,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
135 'stripe_card_ref' => array(
'type' =>
'varchar(128)',
'label' =>
'Stripecardref',
'enabled' => 1,
'position' => 195,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
136 'status' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'position' => 500,
'notnull' => 1,
'visible' => -1,
'alwayseditable' => 1,),
137 'comment' => array(
'type' =>
'varchar(255)',
'label' =>
'Comment',
'enabled' => 1,
'position' => 205,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
138 'ipaddress' => array(
'type' =>
'varchar(68)',
'label' =>
'Ipaddress',
'enabled' => 1,
'position' => 210,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
139 'stripe_account' => array(
'type' =>
'varchar(128)',
'label' =>
'Stripeaccount',
'enabled' => 1,
'position' => 215,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
140 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 230),
182 public $code_guichet;
218 public $country_code;
228 public $currency_code;
265 public $exp_date_month;
269 public $exp_date_year;
286 public $max_total_amount_of_all_payments;
290 public $preapproval_key;
294 public $starting_date;
298 public $total_amount_of_all_payments;
304 public $ext_payment_site;
322 public $stripe_account;
329 public $stripe_card_ref;
338 const STATUS_OPEN = 0;
339 const STATUS_CLOSED = 1;
355 $this->default_rib = 0;
358 $this->labelStatus = array(
359 self::STATUS_OPEN => $langs->transnoentitiesnoconv(
"StatusAccountOpened"),
360 self::STATUS_CLOSED => $langs->transnoentitiesnoconv(
"StatusAccountClosed")
372 public function create($user, $notrigger = 0)
379 if (empty($this->socid)) {
380 $this->
error =
'BadValueForParameter';
381 $this->errors[] = $this->error;
385 if (empty($this->datec)) {
391 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib";
392 $sql .=
" WHERE fk_soc = ".((int) $this->socid).
" AND default_rib = 1 AND type = 'ban'";
393 $result = $this->db->query($sql);
395 $numrows = $this->db->num_rows($result);
396 if ($this->default_rib && $numrows > 0) {
397 $this->default_rib = 0;
399 if (empty($this->default_rib) && $numrows == 0) {
400 $this->default_rib = 1;
407 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_rib (fk_soc, type, datec, model_pdf)";
408 $sql .=
" VALUES (".((int) $this->socid).
", '".$this->
type.
"', '".$this->db->idate($this->datec).
"',";
411 $resql = $this->db->query($sql);
413 if ($this->db->affected_rows($resql)) {
414 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"societe_rib");
418 $result = $this->call_trigger(
'COMPANY_RIB_CREATE', $user);
427 $this->
error = $this->db->lasterror();
428 $this->errors[] = $this->error;
435 $this->db->rollback();
447 public function update($user, $notrigger = 0)
461 $this->owner_address =
dol_trunc($this->owner_address, 254,
'right',
'UTF-8', 1);
464 if (isset($this->model_pdf)) {
465 $this->model_pdf = trim($this->model_pdf);
470 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET";
471 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
472 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
473 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
474 $sql .=
",number='".$this->db->escape($this->number).
"'";
475 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
476 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
477 $sql .=
",iban_prefix = '".$this->db->escape(
dolEncrypt($this->iban)).
"'";
478 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
479 $sql .=
",fk_country = '".((int) $this->fk_country).
"'";
480 $sql .=
",state_id = '".((int) $this->state_id).
"'";
481 $sql .=
",status = '".((int) $this->
status).
"'";
482 $sql .=
",domiciliation = '".$this->db->escape($this->
address).
"'";
483 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
484 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
485 $sql .=
",default_rib = ".((int) $this->default_rib);
487 $sql .=
",frstrecur = '".$this->db->escape($this->frstrecur).
"'";
488 $sql .=
",rum = '".$this->db->escape($this->rum).
"'";
489 $sql .=
",date_rum = ".($this->date_rum ?
"'".$this->db->idate($this->date_rum).
"'" :
"null");
491 if (trim($this->label) !=
'') {
492 $sql .=
",label = '".$this->db->escape($this->label).
"'";
494 $sql .=
",label = NULL";
496 $sql .=
",stripe_card_ref = '".$this->db->escape($this->stripe_card_ref).
"'";
497 $sql .=
",stripe_account = '".$this->db->escape($this->stripe_account).
"'";
498 $sql .=
",model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null");
499 $sql .=
" WHERE rowid = ".((int) $this->
id);
501 $result = $this->db->query($sql);
505 $result = $this->call_trigger(
'COMPANY_RIB_MODIFY', $user);
513 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
514 $this->
error = $langs->trans(
'ErrorDuplicateField');
516 $this->
error = $this->db->lasterror();
518 $this->errors[] = $this->error;
525 $this->db->rollback();
540 public function fetch($id, $ref =
'', $socid = 0, $default = 1, $type =
'ban')
542 if (empty($id) && empty($ref) && empty($socid)) {
546 $sql =
"SELECT rowid, label, type, fk_soc as socid, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban,";
547 $sql .=
" currency_code, fk_country, state_id, status, domiciliation as address,";
548 $sql .=
" proprio as owner_name, owner_address, default_rib, datec, tms as datem, rum, frstrecur, date_rum,";
549 $sql .=
" stripe_card_ref, stripe_account, ext_payment_site,";
550 $sql .=
" last_main_doc, model_pdf";
551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
554 $sql .=
" WHERE rowid = ".((int) $id);
556 $sql .=
" WHERE rowid = ".((int) $ref);
557 } elseif ($socid > 0) {
558 $sql .=
" WHERE fk_soc = ".((int) $socid);
560 $sql .=
" AND default_rib = ".((int) $default);
563 $sql .=
" AND type = '".$this->db->escape($type).
"'";
567 $resql = $this->db->query($sql);
569 if ($this->db->num_rows($resql)) {
570 $obj = $this->db->fetch_object($resql);
572 $this->
ref = $obj->socid.
'-'.$obj->label;
574 $this->
id = $obj->rowid;
575 $this->
type = $obj->type;
576 $this->socid = $obj->socid;
577 $this->bank = $obj->bank;
578 $this->code_banque = $obj->code_banque;
579 $this->code_guichet = $obj->code_guichet;
580 $this->number = $obj->number;
581 $this->cle_rib = $obj->cle_rib;
582 $this->bic = $obj->bic;
585 $this->currency_code = $obj->currency_code;
586 $this->fk_country = $obj->fk_country;
587 $this->state_id = $obj->state_id;
588 $this->
status = $obj->status;
589 $this->
address = $obj->address;
591 $this->owner_name = $obj->owner_name;
592 $this->proprio = $obj->owner_name;
593 $this->owner_address = $obj->owner_address;
594 $this->label = $obj->label;
595 $this->default_rib = $obj->default_rib;
596 $this->datec = $this->db->jdate($obj->datec);
597 $this->datem = $this->db->jdate($obj->datem);
598 $this->rum = $obj->rum;
599 $this->frstrecur = $obj->frstrecur;
600 $this->date_rum = $this->db->jdate($obj->date_rum);
601 $this->stripe_card_ref = $obj->stripe_card_ref;
602 $this->stripe_account = $obj->stripe_account;
603 $this->ext_payment_site = $obj->ext_payment_site;
604 $this->last_main_doc = $obj->last_main_doc;
605 $this->model_pdf = $obj->model_pdf;
607 $this->db->free($resql);
623 public function delete($user, $notrigger = 0)
627 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
631 if (!$error && !$notrigger) {
633 $result = $this->call_trigger(
'COMPANY_RIB_DELETE', $user);
641 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
642 $sql .=
" WHERE rowid = ".((int) $this->
id);
644 if (!$this->db->query($sql)) {
646 $this->errors[] = $this->db->lasterror();
654 $this->db->rollback();
669 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
670 if ($this->label && $displayriblabel) {
671 $rib = $this->label.
" : ";
689 $sql1 =
"SELECT rowid as id, fk_soc as socid FROM ".MAIN_DB_PREFIX.
"societe_rib";
690 $sql1 .=
" WHERE rowid = ".((int) ($rib ? $rib : $this->id));
692 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
693 $result1 = $this->db->query($sql1);
695 if ($this->db->num_rows($result1) == 0) {
698 $obj = $this->db->fetch_object($result1);
702 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
703 $sql2 .=
" WHERE fk_soc = ".((int) $obj->socid);
704 if ($resetolddefaultfor) {
705 $sql2 .=
" AND type = '".$this->db->escape($resetolddefaultfor).
"'";
707 $result2 = $this->db->query($sql2);
709 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
710 $sql3 .=
" WHERE rowid = ".((int) $obj->id);
711 $result3 = $this->db->query($sql3);
713 if (!$result2 || !$result3) {
714 $this->errors[] = $this->db->lasterror();
715 $this->db->rollback();
723 $this->errors[] = $this->db->lasterror();
740 $this->label =
'CustomerCorp Bank account';
741 $this->bank =
'CustomerCorp Bank';
743 $this->
status = Account::STATUS_OPEN;
744 $this->code_banque =
'123';
745 $this->code_guichet =
'456';
746 $this->number =
'CUST12345';
747 $this->cle_rib =
'50';
749 $this->iban =
'FR999999999';
751 $this->
address =
'Rue de Paris';
752 $this->country_id = 1;
754 $this->owner_name =
'Owner';
755 $this->owner_address =
'Owner address';
756 $this->owner_country_id = 1;
758 $this->rum =
'UMR-CU1212-0007-5-1475405262';
759 $this->date_rum =
dol_now() - 10000;
760 $this->frstrecur =
'FRST';
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current balance.
Class to manage bank accounts description of third parties.
setAsDefault($rib=0, $resetolddefaultfor='ban')
Set a BAN as Default.
fetch($id, $ref='', $socid=0, $default=1, $type='ban')
Load record from database.
getRibLabel($displayriblabel=true)
Return RIB.
update($user, $notrigger=0)
Update bank account.
create($user, $notrigger=0)
Create bank information record.
initAsSpecimen()
Initialise an instance with random values.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.