28 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
50 public $stripe_card_ref;
51 public $stripe_account;
79 $this->error_number = 0;
80 $this->default_rib = 0;
91 public function create(
User $user =
null, $notrigger = 0)
98 if (empty($this->socid)) {
99 $this->
error =
'BadValueForParameter';
105 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib where fk_soc = ".((int) $this->socid).
" AND default_rib = 1 AND type = 'ban'";
106 $result = $this->
db->query($sql);
108 $numrows = $this->
db->num_rows($result);
109 if ($this->default_rib && $numrows > 0) {
110 $this->default_rib = 0;
112 if (empty($this->default_rib) && $numrows == 0) {
113 $this->default_rib = 1;
117 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_rib (fk_soc, type, datec)";
118 $sql .=
" VALUES (".((int) $this->socid).
", 'ban', '".$this->
db->idate($now).
"')";
121 if ($this->
db->affected_rows(
$resql)) {
122 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"societe_rib");
126 $result = $this->
call_trigger(
'COMPANY_RIB_CREATE', $user);
142 $this->
error = $this->
db->lasterror();
156 global $conf, $langs;
165 $this->domiciliation =
dol_trunc($this->domiciliation, 254,
'right',
'UTF-8', 1);
168 $this->owner_address =
dol_trunc($this->owner_address, 254,
'right',
'UTF-8', 1);
171 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET";
172 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
173 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
174 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
175 $sql .=
",number='".$this->db->escape($this->number).
"'";
176 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
177 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
178 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
179 $sql .=
",domiciliation = '".$this->db->escape($this->domiciliation).
"'";
180 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
181 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
182 $sql .=
",default_rib = ".((int) $this->default_rib);
183 if (!empty($conf->prelevement->enabled)) {
184 $sql .=
",frstrecur = '".$this->db->escape($this->frstrecur).
"'";
185 $sql .=
",rum = '".$this->db->escape($this->rum).
"'";
186 $sql .=
",date_rum = ".($this->date_rum ?
"'".$this->db->idate($this->date_rum).
"'" :
"null");
188 if (trim($this->label) !=
'') {
189 $sql .=
",label = '".$this->db->escape($this->label).
"'";
191 $sql .=
",label = NULL";
193 $sql .=
",stripe_card_ref = '".$this->db->escape($this->stripe_card_ref).
"'";
194 $sql .=
",stripe_account = '".$this->db->escape($this->stripe_account).
"'";
195 $sql .=
" WHERE rowid = ".((int) $this->
id);
197 $result = $this->
db->query($sql);
201 $result = $this->
call_trigger(
'COMPANY_RIB_MODIFY', $user);
215 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
216 $this->
error = $langs->trans(
'ErrorDuplicateField');
218 $this->
error = $this->
db->lasterror();
233 public function fetch($id, $socid = 0, $default = 1, $type =
'ban')
235 if (empty($id) && empty($socid)) {
239 $sql =
"SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
240 $sql .=
" owner_address, default_rib, label, datec, tms as datem, rum, frstrecur, date_rum,";
241 $sql .=
" stripe_card_ref, stripe_account";
242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
244 $sql .=
" WHERE rowid = ".((int) $id);
245 } elseif ($socid > 0) {
246 $sql .=
" WHERE fk_soc = ".((int) $socid);
248 $sql .=
" AND default_rib = ".((int) $default);
251 $sql .=
" AND type = '".$this->db->escape($type).
"'";
258 $obj = $this->
db->fetch_object(
$resql);
260 $this->
ref = $obj->fk_soc.
'-'.$obj->label;
262 $this->
id = $obj->rowid;
263 $this->
type = $obj->type;
264 $this->socid = $obj->fk_soc;
265 $this->bank = $obj->bank;
266 $this->code_banque = $obj->code_banque;
267 $this->code_guichet = $obj->code_guichet;
268 $this->number = $obj->number;
269 $this->cle_rib = $obj->cle_rib;
270 $this->bic = $obj->bic;
271 $this->iban = $obj->iban;
272 $this->domiciliation = $obj->domiciliation;
273 $this->proprio = $obj->proprio;
274 $this->owner_address = $obj->owner_address;
275 $this->label = $obj->label;
276 $this->default_rib = $obj->default_rib;
277 $this->datec = $this->
db->jdate($obj->datec);
278 $this->datem = $this->
db->jdate($obj->datem);
279 $this->rum = $obj->rum;
280 $this->frstrecur = $obj->frstrecur;
281 $this->date_rum = $this->
db->jdate($obj->date_rum);
282 $this->stripe_card_ref = $obj->stripe_card_ref;
283 $this->stripe_account = $obj->stripe_account;
301 public function delete(
User $user =
null, $notrigger = 0)
305 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
309 if (!$error && !$notrigger) {
311 $result = $this->
call_trigger(
'COMPANY_RIB_DELETE', $user);
319 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
320 $sql .=
" WHERE rowid = ".((int) $this->
id);
322 if (!$this->
db->query($sql)) {
324 $this->errors[] = $this->
db->lasterror();
332 $this->
db->rollback();
347 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
348 if ($this->label && $displayriblabel) {
349 $rib = $this->label.
" : ";
367 $sql1 =
"SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX.
"societe_rib";
368 $sql1 .=
" WHERE rowid = ".($rib ? $rib : $this->id);
370 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
371 $result1 = $this->
db->query($sql1);
373 if ($this->
db->num_rows($result1) == 0) {
376 $obj = $this->
db->fetch_object($result1);
380 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
381 $sql2 .=
" WHERE fk_soc = ".((int) $obj->fk_soc);
382 if ($resetolddefaultfor) {
383 $sql2 .=
" AND type = '".$this->db->escape($resetolddefaultfor).
"'";
385 $result2 = $this->
db->query($sql2);
387 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
388 $sql3 .=
" WHERE rowid = ".((int) $obj->id);
389 $result3 = $this->
db->query($sql3);
391 if (!$result2 || !$result3) {
393 $this->
db->rollback();
417 $this->label =
'CustomerCorp Bank account';
418 $this->bank =
'CustomerCorp Bank';
420 $this->clos = Account::STATUS_OPEN;
421 $this->code_banque =
'123';
422 $this->code_guichet =
'456';
423 $this->number =
'CUST12345';
426 $this->iban =
'FR999999999';
427 $this->domiciliation =
'Bank address of customer corp';
428 $this->proprio =
'Owner';
429 $this->owner_address =
'Owner address';
430 $this->country_id = 1;
432 $this->rum =
'UMR-CU1212-0007-5-1475405262';
433 $this->date_rum =
dol_now() - 10000;
434 $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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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
$conf db
API class for accounts.