28 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
69 $this->error_number = 0;
70 $this->default_rib = 0;
81 public function create(
User $user = null, $notrigger = 0)
86 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe_rib where fk_soc = ".$this->socid.
" AND default_rib = 1 AND type = 'ban'";
87 $result = $this->
db->query($sql);
90 $numrows = $this->
db->num_rows($result);
91 if ($this->default_rib && $numrows > 0) $this->default_rib = 0;
92 if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1;
95 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_rib (fk_soc, type, datec)";
96 $sql .=
" VALUES (".$this->socid.
", 'ban', '".$this->
db->idate($now).
"')";
100 if ($this->
db->affected_rows(
$resql))
102 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"societe_rib");
107 $result = $this->
call_trigger(
'COMPANY_RIB_CREATE', $user);
108 if ($result < 0) $error++;
139 if (!$this->
id)
return -1;
141 if (
dol_strlen($this->domiciliation) > 255) $this->domiciliation =
dol_trunc($this->domiciliation, 254,
'right',
'UTF-8', 1);
142 if (
dol_strlen($this->owner_address) > 255) $this->owner_address =
dol_trunc($this->owner_address, 254,
'right',
'UTF-8', 1);
144 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET";
145 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
146 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
147 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
148 $sql .=
",number='".$this->db->escape($this->number).
"'";
149 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
150 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
151 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
152 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
153 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
154 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
155 $sql .=
",default_rib = ".$this->default_rib;
156 if ($conf->prelevement->enabled)
158 $sql .=
",frstrecur = '".$this->db->escape($this->frstrecur).
"'";
159 $sql .=
",rum = '".$this->db->escape($this->rum).
"'";
160 $sql .=
",date_rum = ".($this->date_rum ?
"'".$this->db->idate($this->date_rum).
"'" :
"null");
162 if (trim($this->label) !=
'')
163 $sql .=
",label = '".$this->
db->escape($this->label).
"'";
164 else $sql .=
",label = NULL";
165 $sql .=
" WHERE rowid = ".$this->id;
167 $result = $this->
db->query($sql);
173 $result = $this->
call_trigger(
'COMPANY_RIB_MODIFY', $user);
174 if ($result < 0) $error++;
200 public function fetch($id, $socid = 0, $default = 1, $type =
'ban')
202 if (empty($id) && empty($socid))
return -1;
204 $sql =
"SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,";
205 $sql .=
" owner_address, default_rib, label, datec, tms as datem, rum, frstrecur, date_rum";
206 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_rib";
207 if ($id) $sql .=
" WHERE rowid = ".$id;
210 $sql .=
" WHERE fk_soc = ".$socid;
211 if ($default > -1) $sql .=
" AND default_rib = ".$this->db->escape($default);
212 if ($type) $sql .=
" AND type ='".$this->db->escape($type).
"'";
220 $obj = $this->
db->fetch_object(
$resql);
222 $this->ref = $obj->fk_soc.
'-'.$obj->label;
224 $this->
id = $obj->rowid;
225 $this->
type = $obj->type;
226 $this->socid = $obj->fk_soc;
227 $this->bank = $obj->bank;
228 $this->code_banque = $obj->code_banque;
229 $this->code_guichet = $obj->code_guichet;
230 $this->number = $obj->number;
231 $this->cle_rib = $obj->cle_rib;
232 $this->bic = $obj->bic;
233 $this->iban = $obj->iban;
234 $this->domiciliation = $obj->domiciliation;
235 $this->proprio = $obj->proprio;
236 $this->owner_address = $obj->owner_address;
237 $this->label = $obj->label;
238 $this->default_rib = $obj->default_rib;
239 $this->datec = $this->
db->jdate($obj->datec);
240 $this->datem = $this->
db->jdate($obj->datem);
241 $this->rum = $obj->rum;
242 $this->frstrecur = $obj->frstrecur;
243 $this->date_rum = $this->
db->jdate($obj->date_rum);
261 public function delete(
User $user = null, $notrigger = 0)
267 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
271 if (!$error && !$notrigger)
274 $result = $this->
call_trigger(
'COMPANY_RIB_DELETE', $user);
275 if ($result < 0) $error++;
281 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
282 $sql .=
" WHERE rowid = ".$this->id;
284 if (!$this->
db->query($sql))
287 $this->errors[] = $this->
db->lasterror();
296 $this->
db->rollback();
311 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
312 if ($this->label && $displayriblabel) {
313 $rib = $this->label.
" : ";
316 $rib .= (string) $this;
330 $sql1 =
"SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX.
"societe_rib";
331 $sql1 .=
" WHERE rowid = ".($rib ? $rib : $this->id);
333 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
334 $result1 = $this->
db->query($sql1);
337 if ($this->
db->num_rows($result1) == 0)
341 $obj = $this->
db->fetch_object($result1);
345 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
346 $sql2 .=
" WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc;
347 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
348 $result2 = $this->
db->query($sql2);
350 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
351 $sql3 .=
" WHERE rowid = ".$obj->id;
352 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
353 $result3 = $this->
db->query($sql3);
355 if (!$result2 || !$result3)
358 $this->
db->rollback();
382 $this->label =
'CustomerCorp Bank account';
383 $this->bank =
'CustomerCorp Bank';
385 $this->clos = Account::STATUS_OPEN;
386 $this->code_banque =
'123';
387 $this->code_guichet =
'456';
388 $this->number =
'CUST12345';
391 $this->iban =
'FR999999999';
392 $this->domiciliation =
'Bank address of customer corp';
393 $this->proprio =
'Owner';
394 $this->owner_address =
'Owner address';
395 $this->country_id = 1;
397 $this->rum =
'UMR-CU1212-0007-5-1475405262';
398 $this->date_rum =
dol_now() - 10000;
399 $this->frstrecur =
'FRST';
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.
$conf db
API class for accounts.
Class to manage bank accounts.
update(User $user=null, $notrigger=0)
Update bank account.
setAsDefault($rib=0)
Set a BAN as Default.
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.
getRibLabel($displayriblabel=true)
Return RIB.
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
solde($option=0)
Return current sold.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $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_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