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);
235 } elseif ($socid > 0) {
236 $sql .=
" WHERE fk_soc = ".((int) $socid);
238 $sql .=
" AND default_rib = ".((int) $default);
241 $sql .=
" AND type = '".$this->db->escape($type).
"'";
248 $obj = $this->
db->fetch_object(
$resql);
250 $this->
ref = $obj->fk_soc.
'-'.$obj->label;
252 $this->
id = $obj->rowid;
253 $this->
type = $obj->type;
254 $this->socid = $obj->fk_soc;
255 $this->bank = $obj->bank;
256 $this->code_banque = $obj->code_banque;
257 $this->code_guichet = $obj->code_guichet;
258 $this->number = $obj->number;
259 $this->cle_rib = $obj->cle_rib;
260 $this->bic = $obj->bic;
261 $this->iban = $obj->iban;
262 $this->domiciliation = $obj->domiciliation;
263 $this->proprio = $obj->proprio;
264 $this->owner_address = $obj->owner_address;
265 $this->label = $obj->label;
266 $this->default_rib = $obj->default_rib;
267 $this->datec = $this->
db->jdate($obj->datec);
268 $this->datem = $this->
db->jdate($obj->datem);
269 $this->rum = $obj->rum;
270 $this->frstrecur = $obj->frstrecur;
271 $this->date_rum = $this->
db->jdate($obj->date_rum);
289 public function delete(
User $user =
null, $notrigger = 0)
293 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
297 if (!$error && !$notrigger) {
299 $result = $this->
call_trigger(
'COMPANY_RIB_DELETE', $user);
307 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib";
308 $sql .=
" WHERE rowid = ".((int) $this->
id);
310 if (!$this->
db->query($sql)) {
312 $this->errors[] = $this->
db->lasterror();
320 $this->
db->rollback();
335 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
336 if ($this->label && $displayriblabel) {
337 $rib = $this->label.
" : ";
340 $rib .= (string) $this;
355 $sql1 =
"SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX.
"societe_rib";
356 $sql1 .=
" WHERE rowid = ".($rib ? $rib : $this->id);
358 dol_syslog(get_class($this).
'::setAsDefault', LOG_DEBUG);
359 $result1 = $this->
db->query($sql1);
361 if ($this->
db->num_rows($result1) == 0) {
364 $obj = $this->
db->fetch_object($result1);
368 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 0";
369 $sql2 .=
" WHERE fk_soc = ".((int) $obj->fk_soc);
370 if ($resetolddefaultfor) {
371 $sql2 .=
" AND type = '".$this->db->escape($resetolddefaultfor).
"'";
373 $result2 = $this->
db->query($sql2);
375 $sql3 =
"UPDATE ".MAIN_DB_PREFIX.
"societe_rib SET default_rib = 1";
376 $sql3 .=
" WHERE rowid = ".((int) $obj->id);
377 $result3 = $this->
db->query($sql3);
379 if (!$result2 || !$result3) {
381 $this->
db->rollback();
405 $this->label =
'CustomerCorp Bank account';
406 $this->bank =
'CustomerCorp Bank';
408 $this->clos = Account::STATUS_OPEN;
409 $this->code_banque =
'123';
410 $this->code_guichet =
'456';
411 $this->number =
'CUST12345';
414 $this->iban =
'FR999999999';
415 $this->domiciliation =
'Bank address of customer corp';
416 $this->proprio =
'Owner';
417 $this->owner_address =
'Owner address';
418 $this->country_id = 1;
420 $this->rum =
'UMR-CU1212-0007-5-1475405262';
421 $this->date_rum =
dol_now() - 10000;
422 $this->frstrecur =
'FRST';