28 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
76 $this->error_number = 0;
77 $this->default_rib = 0;
88 public function create(
User $user = null, $notrigger = 0)
95 if (empty($this->socid)) {
96 $this->
error =
'BadValueForParameter';
102 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib where fk_soc = ".((int) $this->socid).
" AND default_rib = 1 AND type = 'ban'";
103 $result = $this->
db->query($sql);
105 $numrows = $this->
db->num_rows($result);
106 if ($this->default_rib && $numrows > 0) {
107 $this->default_rib = 0;
109 if (empty($this->default_rib) && $numrows == 0) {
110 $this->default_rib = 1;
114 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_rib (fk_soc, type, datec)";
115 $sql .=
" VALUES (".((int) $this->socid).
", 'ban', '".$this->
db->idate($now).
"')";
118 if ($this->
db->affected_rows(
$resql)) {
119 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"societe_rib");
123 $result = $this->
call_trigger(
'COMPANY_RIB_CREATE', $user);
139 print $this->
db->error();
162 $this->domiciliation =
dol_trunc($this->domiciliation, 254,
'right',
'UTF-8', 1);
165 $this->owner_address =
dol_trunc($this->owner_address, 254,
'right',
'UTF-8', 1);
168 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET";
169 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
170 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
171 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
172 $sql .=
",number='".$this->db->escape($this->number).
"'";
173 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
174 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
175 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
176 $sql .=
",domiciliation = '".$this->db->escape($this->domiciliation).
"'";
177 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
178 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
179 $sql .=
",default_rib = ".((int) $this->default_rib);
180 if (!empty($conf->prelevement->enabled)) {
181 $sql .=
",frstrecur = '".$this->db->escape($this->frstrecur).
"'";
182 $sql .=
",rum = '".$this->db->escape($this->rum).
"'";
183 $sql .=
",date_rum = ".($this->date_rum ?
"'".$this->db->idate($this->date_rum).
"'" :
"null");
185 if (trim($this->label) !=
'') {
186 $sql .=
",label = '".$this->db->escape($this->label).
"'";
188 $sql .=
",label = NULL";
190 $sql .=
" WHERE rowid = ".((int) $this->
id);
192 $result = $this->
db->query($sql);
196 $result = $this->
call_trigger(
'COMPANY_RIB_MODIFY', $user);
210 $this->
error = $this->
db->lasterror();
224 public function fetch($id, $socid = 0, $default = 1, $type =
'ban')
226 if (empty($id) && empty($socid)) {
230 $sql =
"SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
231 $sql .=
" owner_address, default_rib, label, datec, tms as datem, rum, frstrecur, date_rum";
232 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
234 $sql .=
" WHERE rowid = ".((int) $id);
237 $sql .=
" WHERE fk_soc = ".((int) $socid);
239 $sql .=
" AND default_rib = ".((int) $default);
242 $sql .=
" AND type = '".$this->db->escape($type).
"'";
249 $obj = $this->
db->fetch_object(
$resql);
251 $this->
ref = $obj->fk_soc.
'-'.$obj->label;
253 $this->
id = $obj->rowid;
254 $this->
type = $obj->type;
255 $this->socid = $obj->fk_soc;
256 $this->bank = $obj->bank;
257 $this->code_banque = $obj->code_banque;
258 $this->code_guichet = $obj->code_guichet;
259 $this->number = $obj->number;
260 $this->cle_rib = $obj->cle_rib;
261 $this->bic = $obj->bic;
262 $this->iban = $obj->iban;
263 $this->domiciliation = $obj->domiciliation;
264 $this->proprio = $obj->proprio;
265 $this->owner_address = $obj->owner_address;
266 $this->label = $obj->label;
267 $this->default_rib = $obj->default_rib;
268 $this->datec = $this->
db->jdate($obj->datec);
269 $this->datem = $this->
db->jdate($obj->datem);
270 $this->rum = $obj->rum;
271 $this->frstrecur = $obj->frstrecur;
272 $this->date_rum = $this->
db->jdate($obj->date_rum);
290 public function delete(
User $user = null, $notrigger = 0)
294 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
298 if (!$error && !$notrigger) {
300 $result = $this->
call_trigger(
'COMPANY_RIB_DELETE', $user);
308 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
309 $sql .=
" WHERE rowid = ".((int) $this->
id);
311 if (!$this->
db->query($sql)) {
313 $this->errors[] = $this->
db->lasterror();
321 $this->
db->rollback();
336 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
337 if ($this->label && $displayriblabel) {
338 $rib = $this->label.
" : ";
341 $rib .= (string) $this;
356 $sql1 =
"SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX.
"societe_rib";
357 $sql1 .=
" WHERE rowid = ".($rib ? $rib : $this->id);
359 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
360 $result1 = $this->
db->query($sql1);
362 if ($this->
db->num_rows($result1) == 0) {
365 $obj = $this->
db->fetch_object($result1);
369 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
370 $sql2 .=
" WHERE fk_soc = ".((int) $obj->fk_soc);
371 if ($resetolddefaultfor) {
372 $sql2 .=
" AND type = '".$this->db->escape($resetolddefaultfor).
"'";
374 $result2 = $this->
db->query($sql2);
376 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
377 $sql3 .=
" WHERE rowid = ".((int) $obj->id);
378 $result3 = $this->
db->query($sql3);
380 if (!$result2 || !$result3) {
382 $this->
db->rollback();
406 $this->label =
'CustomerCorp Bank account';
407 $this->bank =
'CustomerCorp Bank';
409 $this->clos = Account::STATUS_OPEN;
410 $this->code_banque =
'123';
411 $this->code_guichet =
'456';
412 $this->number =
'CUST12345';
415 $this->iban =
'FR999999999';
416 $this->domiciliation =
'Bank address of customer corp';
417 $this->proprio =
'Owner';
418 $this->owner_address =
'Owner address';
419 $this->country_id = 1;
421 $this->rum =
'UMR-CU1212-0007-5-1475405262';
422 $this->date_rum =
dol_now() - 10000;
423 $this->frstrecur =
'FRST';
$conf db
API class for accounts.
setAsDefault($rib=0, $resetolddefaultfor= 'ban')
Set a BAN as Default.
solde($option=0, $date_end= '', $field= 'dateo')
Return current sold.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
Class to manage bank accounts description of third parties.
initAsSpecimen()
Initialise an instance with random values.
const TYPE_CURRENT
Current account.
Class to manage bank accounts.
update(User $user=null, $notrigger=0)
Update bank account.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
fetch($id, $socid=0, $default=1, $type= 'ban')
Load record from database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
__construct(DoliDB $db)
Constructor.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
getRibLabel($displayriblabel=true)
Return RIB.
call_trigger($triggerName, $user)
Call trigger based on this instance.
dol_print_error($db= '', $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. ...
create(User $user=null, $notrigger=0)
Create bank information record.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type