dolibarr 25.0.0-alpha
companybankaccount.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2010-2023 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
6 * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2026 Nick Fragoulis
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32
33
38{
43 public $TRIGGER_PREFIX = 'COMPANY_RIB';
44
48 public $element = 'societe_rib';
49
53 public $table_element = 'societe_rib';
54
94 // BEGIN MODULEBUILDER PROPERTIES
98 public $fields = array(
99 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => -1,),
100 'type' => array('type' => 'varchar(32)', 'label' => 'Type', 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'visible' => -1,),
101 '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',),
102 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 25, 'notnull' => 0, 'visible' => -1,),
103 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => -1,),
104 'label' => array('type' => 'varchar(200)', 'label' => 'Label', 'enabled' => 1, 'position' => 35, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'csslist' => 'tdoverflowmax150',),
105 'bank' => array('type' => 'varchar(255)', 'label' => 'Bank', 'enabled' => 1, 'position' => 40, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
106 'code_banque' => array('type' => 'varchar(128)', 'label' => 'Codebanque', 'enabled' => 1, 'position' => 45, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
107 'code_guichet' => array('type' => 'varchar(6)', 'label' => 'Codeguichet', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
108 'number' => array('type' => 'varchar(255)', 'label' => 'Number', 'enabled' => 1, 'position' => 55, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
109 'cle_rib' => array('type' => 'varchar(5)', 'label' => 'Clerib', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
110 'bic' => array('type' => 'varchar(20)', 'label' => 'Bic', 'enabled' => 1, 'position' => 65, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
111 'iban_prefix' => array('type' => 'varchar(34)', 'label' => 'Ibanprefix', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
112 'domiciliation' => array('type' => 'varchar(255)', 'label' => 'Domiciliation', 'enabled' => 1, 'position' => 75, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
113 'proprio' => array('type' => 'varchar(60)', 'label' => 'Proprio', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
114 'owner_address' => array('type' => 'varchar(255)', 'label' => 'Owneraddress', 'enabled' => 1, 'position' => 85, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
115 'default_rib' => array('type' => 'smallint(6)', 'label' => 'Defaultrib', 'enabled' => 1, 'position' => 90, 'notnull' => 1, 'visible' => -1, 'alwayseditable' => 1,),
116 'state_id' => array('type' => 'integer', 'label' => 'Stateid', 'enabled' => 1, 'position' => 95, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
117 'fk_country' => array('type' => 'integer', 'label' => 'Country', 'enabled' => 1, 'position' => 100, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1, 'css' => 'maxwidth500 widthcentpercentminusxx',),
118 'currency_code' => array('type' => 'varchar(3)', 'label' => 'Currencycode', 'enabled' => 1, 'position' => 105, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
119 'rum' => array('type' => 'varchar(32)', 'label' => 'Rum', 'enabled' => 1, 'position' => 110, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
120 'date_rum' => array('type' => 'date', 'label' => 'Daterum', 'enabled' => 1, 'position' => 115, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
121 'payment_reference' => array('type' => 'varchar(35)', 'label' => 'PaymentReferenceOfAccount', 'enabled' => 1, 'position' => 117, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
122 'frstrecur' => array('type' => 'varchar(16)', 'label' => 'Frstrecur', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
123 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 900, 'notnull' => 0, 'visible' => -2, 'alwayseditable' => 1,),
124 'last_four' => array('type' => 'varchar(4)', 'label' => 'Lastfour', 'enabled' => 1, 'position' => 130, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
125 'card_type' => array('type' => 'varchar(255)', 'label' => 'Cardtype', 'enabled' => 1, 'position' => 135, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
126 'cvn' => array('type' => 'varchar(255)', 'label' => 'Cvn', 'enabled' => 1, 'position' => 140, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
127 'exp_date_month' => array('type' => 'integer', 'label' => 'Expdatemonth', 'enabled' => 1, 'position' => 145, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
128 'exp_date_year' => array('type' => 'integer', 'label' => 'Expdateyear', 'enabled' => 1, 'position' => 150, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
129 'country_code' => array('type' => 'varchar(10)', 'label' => 'Countrycode', 'enabled' => 1, 'position' => 155, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
130 'approved' => array('type' => 'integer', 'label' => 'Approved', 'enabled' => 1, 'position' => 160, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
131 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'position' => 165, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
132 'ending_date' => array('type' => 'date', 'label' => 'Endingdate', 'enabled' => 1, 'position' => 170, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
133 'max_total_amount_of_all_payments' => array('type' => 'double(24,8)', 'label' => 'Maxtotalamountofallpayments', 'enabled' => 1, 'position' => 175, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
134 'preapproval_key' => array('type' => 'varchar(255)', 'label' => 'Preapprovalkey', 'enabled' => 1, 'position' => 180, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
135 'starting_date' => array('type' => 'date', 'label' => 'Startingdate', 'enabled' => 1, 'position' => 185, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
136 'total_amount_of_all_payments' => array('type' => 'double(24,8)', 'label' => 'Totalamountofallpayments', 'enabled' => 1, 'position' => 190, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
137 'stripe_card_ref' => array('type' => 'varchar(128)', 'label' => 'Stripecardref', 'enabled' => 1, 'position' => 195, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
138 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -1, 'alwayseditable' => 1,),
139 'comment' => array('type' => 'varchar(255)', 'label' => 'Comment', 'enabled' => 1, 'position' => 205, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
140 'ipaddress' => array('type' => 'varchar(68)', 'label' => 'Ipaddress', 'enabled' => 1, 'position' => 210, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
141 'stripe_account' => array('type' => 'varchar(128)', 'label' => 'Stripeaccount', 'enabled' => 1, 'position' => 215, 'notnull' => 0, 'visible' => -1, 'alwayseditable' => 1,),
142 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => 0, 'position' => 230),
143 );
144
148 public $id;
149
153 public $type;
154
159 public $fk_soc;
160
164 public $socid;
165
171 public $datec;
172
176 public $label;
180 public $code_banque;
184 public $code_guichet;
188 public $number;
192 public $cle_rib;
196 public $bic;
200 public $iban_prefix;
201
205 public $bank;
206
210 public $state_id;
211
215 public $fk_country;
216
220 public $country_code;
221
225 public $default_rib;
226
230 public $currency_code;
231
235 public $rum;
236
240 public $date_rum;
241
246 public $payment_reference;
247
253 public $frstrecur;
257 public $import_key;
261 public $last_four;
265 public $card_type;
269 public $cvn;
273 public $exp_date_month;
277 public $exp_date_year;
281 public $approved;
282
286 public $email;
290 public $ending_date;
294 public $max_total_amount_of_all_payments;
298 public $preapproval_key;
302 public $starting_date;
306 public $total_amount_of_all_payments;
307
308
312 public $ext_payment_site; // Name of the external payment system ('StripeLive', 'StripeTest', 'StancerLive', 'StancerTest', ...)
313
317 public $comment;
318
322 public $ipaddress;
323
324
330 public $stripe_account;
331
337 public $stripe_card_ref;
338
344 public $datem;
345
346 const STATUS_OPEN = 0;
347 const STATUS_CLOSED = 1;
348
354 public function __construct(DoliDB $db)
355 {
356 global $langs;
357
358 $this->db = $db;
359
360 $this->socid = 0;
361 $this->solde = 0;
362 $this->balance = 0;
363 $this->default_rib = 0;
364 $this->type = "ban";
365
366 $this->labelStatus = array(
367 self::STATUS_OPEN => $langs->transnoentitiesnoconv("StatusAccountOpened"),
368 self::STATUS_CLOSED => $langs->transnoentitiesnoconv("StatusAccountClosed")
369 );
370 }
371
372
380 public function create($user, $notrigger = 0)
381 {
382 $now = dol_now();
383
384 $error = 0;
385
386 // Check parameters
387 if (empty($this->socid)) {
388 $this->error = 'BadValueForParameter';
389 $this->errors[] = $this->error;
390 return -1;
391 }
392
393 if (empty($this->datec)) {
394 $this->datec = $now;
395 }
396
397 // Correct ->default_rib to not set the new account as default, if there is already 1. We want to be sure to have always 1 default for type = 'ban'.
398 // If we really want the new bank account to be the default, we must set it by calling setDefault() after creation.
399 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib";
400 $sql .= " WHERE fk_soc = ".((int) $this->socid)." AND default_rib = 1 AND type = 'ban'";
401 $result = $this->db->query($sql);
402 if ($result) {
403 $numrows = $this->db->num_rows($result);
404 if ($this->default_rib && $numrows > 0) {
405 $this->default_rib = 0;
406 }
407 if (empty($this->default_rib) && $numrows == 0) {
408 $this->default_rib = 1;
409 }
410 }
411
412
413 $this->db->begin();
414
415 $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec, model_pdf)";
416 $sql .= " VALUES (".((int) $this->socid).", '".$this->db->escape($this->type)."', '".$this->db->idate($this->datec)."',";
417 $sql .= " '".$this->db->escape(getDolGlobalString("BANKADDON_PDF"))."'";
418 $sql .= ")";
419 $resql = $this->db->query($sql);
420 if ($resql) {
421 if ($this->db->affected_rows($resql)) {
422 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib");
423
424 if (!$notrigger) {
425 // Call trigger
426 $result = $this->call_trigger('COMPANY_RIB_CREATE', $user);
427 if ($result < 0) {
428 $error++;
429 }
430 // End call triggers
431 }
432 }
433 } else {
434 $error++;
435 $this->error = $this->db->lasterror();
436 $this->errors[] = $this->error;
437 }
438
439 if (!$error) {
440 $this->db->commit();
441 return $this->id;
442 } else {
443 $this->db->rollback();
444 return -1;
445 }
446 }
447
455 public function update($user, $notrigger = 0)
456 {
457 global $langs;
458
459 $error = 0;
460
461 if (!$this->id) {
462 return -1;
463 }
464
465 // Stored clean (an RF without spaces), the object keeps what is stored. A reference with
466 // check digits (RF) is checked, a typing error is found at once.
467 $this->payment_reference = self::cleanPaymentReference((string) $this->payment_reference);
468 $errorkey = self::checkPaymentReference($this->payment_reference);
469 if ($errorkey !== '') {
470 $langs->load('banks');
471 $this->error = $langs->trans($errorkey);
472 $this->errors[] = $this->error;
473 return -1;
474 }
475
476 if (!empty($this->address) && dol_strlen($this->address) > 255) {
477 $this->address = dol_trunc($this->address, 254, 'right', 'UTF-8', 1);
478 }
479 if (dol_strlen($this->owner_address) > 255) {
480 $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1);
481 }
482
483 if (isset($this->model_pdf)) {
484 $this->model_pdf = trim($this->model_pdf);
485 }
486
487 $this->db->begin();
488
489 $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET";
490 $sql .= " bank = '".$this->db->escape($this->bank)."'";
491 $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
492 $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
493 $sql .= ",number='".$this->db->escape($this->number)."'";
494 $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
495 $sql .= ",bic='".$this->db->escape($this->bic)."'";
496 $sql .= ",iban_prefix = '".$this->db->escape(dolEncrypt($this->iban))."'";
497 $sql .= ",currency_code = '".$this->db->escape($this->currency_code)."'";
498 $sql .= ",fk_country = ".((int) $this->fk_country);
499 $sql .= ",state_id = ".((int) $this->state_id);
500 $sql .= ",status = ".((int) $this->status);
501 $sql .= ",domiciliation = '".$this->db->escape($this->address)."'";
502 $sql .= ",proprio = '".$this->db->escape($this->owner_name)."'";
503 $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
504 $sql .= ",default_rib = ".((int) $this->default_rib);
505 $sql .= ",payment_reference = ".($this->payment_reference !== '' ? "'".$this->db->escape($this->payment_reference)."'" : "NULL");
506 if (isModEnabled('prelevement')) {
507 $sql .= ",frstrecur = '".$this->db->escape($this->frstrecur)."'";
508 $sql .= ",rum = '".$this->db->escape($this->rum)."'";
509 $sql .= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null");
510 }
511 if (trim($this->label) != '') {
512 $sql .= ",label = '".$this->db->escape($this->label)."'";
513 } else {
514 $sql .= ",label = NULL";
515 }
516 $sql .= ",stripe_card_ref = '".$this->db->escape($this->stripe_card_ref)."'";
517 $sql .= ",stripe_account = '".$this->db->escape($this->stripe_account)."'";
518 $sql .= ",model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
519 $sql .= " WHERE rowid = ".((int) $this->id);
520
521 $result = $this->db->query($sql);
522 if ($result) {
523 if (!$notrigger) {
524 // Call trigger
525 $result = $this->call_trigger('COMPANY_RIB_MODIFY', $user);
526 if ($result < 0) {
527 $error++;
528 }
529 // End call triggers
530 }
531 } else {
532 $error++;
533 if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
534 $this->error = $langs->trans('ErrorDuplicateField');
535 } else {
536 $this->error = $this->db->lasterror();
537 }
538 $this->errors[] = $this->error;
539 }
540
541 if (!$error) {
542 $this->db->commit();
543 return 1;
544 } else {
545 $this->db->rollback();
546 return -1;
547 }
548 }
549
560 public function fetch($id, $ref = '', $socid = 0, $default = 1, $type = 'ban')
561 {
562 if (empty($id) && empty($ref) && empty($socid)) {
563 return -1;
564 }
565
566 $sql = "SELECT sr.rowid, sr.label, sr.type, sr.fk_soc as socid, sr.bank, sr.number, sr.code_banque, sr.code_guichet, sr.cle_rib, sr.bic, sr.iban_prefix as iban,";
567 $sql .= " sr.currency_code, sr.fk_country, sr.state_id, sr.status, sr.domiciliation as address,";
568 $sql .= " sr.proprio as owner_name, sr.owner_address, sr.default_rib, sr.datec, sr.tms as datem, sr.rum, sr.frstrecur, sr.date_rum, sr.payment_reference,";
569 $sql .= " sr.stripe_card_ref, sr.stripe_account, sr.ext_payment_site,";
570 $sql .= " sr.last_main_doc, model_pdf,";
571 $sql .= " cc.code as country_code";
572 $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as sr";
573 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = sr.fk_country";
574
575 if ($id) {
576 $sql .= " WHERE sr.rowid = ".((int) $id);
577 } elseif ($ref) {
578 $sql .= " WHERE sr.rowid = ".((int) $ref);
579 } elseif ($socid > 0) {
580 $sql .= " WHERE sr.fk_soc = ".((int) $socid);
581 if ($default > -1) {
582 $sql .= " AND sr.default_rib = ".((int) $default);
583 }
584 if ($type) {
585 $sql .= " AND sr.type = '".$this->db->escape($type)."'";
586 }
587 }
588
589 $resql = $this->db->query($sql);
590 if ($resql) {
591 if ($this->db->num_rows($resql)) {
592 $obj = $this->db->fetch_object($resql);
593
594 $this->ref = $obj->socid.'-'.$obj->label; // Generate an artificial ref
595
596 $this->id = $obj->rowid;
597 $this->type = $obj->type;
598 $this->socid = $obj->socid;
599 $this->bank = $obj->bank;
600 $this->code_banque = $obj->code_banque;
601 $this->code_guichet = $obj->code_guichet;
602 $this->number = $obj->number;
603 $this->cle_rib = $obj->cle_rib;
604 $this->bic = $obj->bic;
605 $this->iban = dolDecrypt($obj->iban);
606
607 $this->currency_code = $obj->currency_code;
608
609 $this->fk_country = $obj->fk_country; // deprecated
610 $this->country_id = $obj->fk_country;
611 $this->country_code = $obj->country_code;
612 $this->state_id = $obj->state_id;
613 $this->address = $obj->address;
614
615 $this->status = $obj->status;
616
617 $this->owner_name = $obj->owner_name;
618 $this->proprio = $obj->owner_name;
619 $this->owner_address = $obj->owner_address;
620 $this->label = $obj->label;
621 $this->default_rib = $obj->default_rib;
622 $this->datec = $this->db->jdate($obj->datec);
623 $this->datem = $this->db->jdate($obj->datem);
624 $this->rum = $obj->rum;
625 $this->frstrecur = $obj->frstrecur;
626 $this->date_rum = $this->db->jdate($obj->date_rum);
627 $this->payment_reference = (string) $obj->payment_reference;
628 $this->stripe_card_ref = $obj->stripe_card_ref; // External system payment mode ID
629 $this->stripe_account = $obj->stripe_account; // External system customer ID
630 $this->ext_payment_site = $obj->ext_payment_site; // External system name ('StripeLive', 'StripeTest', 'StancerLive', 'StancerTest', ...)
631 $this->last_main_doc = $obj->last_main_doc;
632 $this->model_pdf = $obj->model_pdf;
633 }
634 $this->db->free($resql);
635
636 return 1;
637 } else {
638 dol_print_error($this->db);
639 return -1;
640 }
641 }
642
650 public function delete($user, $notrigger = 0)
651 {
652 $error = 0;
653
654 dol_syslog(get_class($this)."::delete ".$this->id, LOG_DEBUG);
655
656 $this->db->begin();
657
658 if (!$error && !$notrigger) {
659 // Call trigger
660 $result = $this->call_trigger('COMPANY_RIB_DELETE', $user);
661 if ($result < 0) {
662 $error++;
663 }
664 // End call triggers
665 }
666
667 if (!$error) {
668 $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_rib";
669 $sql .= " WHERE rowid = ".((int) $this->id);
670
671 if (!$this->db->query($sql)) {
672 $error++;
673 $this->errors[] = $this->db->lasterror();
674 }
675 }
676
677 if (!$error) {
678 $this->db->commit();
679 return 1;
680 } else {
681 $this->db->rollback();
682 return -1 * $error;
683 }
684 }
685
694 public static function cleanPaymentReference($ref)
695 {
696 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_creditorref.lib.php';
697
698 $ref = trim($ref);
699 if (strtoupper(substr(dolPayRefStrip($ref), 0, 2)) === 'RF') {
700 $ref = strtoupper(dolPayRefStrip($ref));
701 }
702
703 return $ref;
704 }
705
712 public static function checkPaymentReference($ref)
713 {
714 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions_creditorref.lib.php';
715
716 $ref = self::cleanPaymentReference($ref);
717 if ($ref === '') {
718 return '';
719 }
720 if (dol_strlen($ref) > 35) {
721 return 'ErrorPaymentReferenceOfAccountTooLong';
722 }
723 if (dolPayRefDetectScheme($ref) == 'SCOR' && !dolCreditorRefIsValid($ref)) {
724 return 'ErrorPaymentReferenceOfAccountNotValid';
725 }
726
727 return '';
728 }
729
736 public function getRibLabel($displayriblabel = true)
737 {
738 $rib = '';
739
740 if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic) {
741 if ($this->label && $displayriblabel) {
742 $rib = $this->label." : ";
743 }
744
745 $rib .= $this->iban;
746 }
747
748 return $rib;
749 }
750
758 public function setAsDefault($rib = 0, $resetolddefaultfor = 'ban')
759 {
760 $sql1 = "SELECT rowid as id, fk_soc as socid FROM ".MAIN_DB_PREFIX."societe_rib";
761 $sql1 .= " WHERE rowid = ".((int) ($rib ? $rib : ((int) $this->id)));
762
763 dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
764 $result1 = $this->db->query($sql1);
765 if ($result1) {
766 if ($this->db->num_rows($result1) == 0) {
767 return 0;
768 } else {
769 $obj = $this->db->fetch_object($result1);
770
771 $this->db->begin();
772
773 $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
774 $sql2 .= " WHERE fk_soc = ".((int) $obj->socid);
775 if ($resetolddefaultfor) {
776 $sql2 .= " AND type = '".$this->db->escape($resetolddefaultfor)."'";
777 }
778 $result2 = $this->db->query($sql2);
779
780 $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
781 $sql3 .= " WHERE rowid = ".((int) $obj->id);
782 $result3 = $this->db->query($sql3);
783
784 if (!$result2 || !$result3) {
785 $this->errors[] = $this->db->lasterror();
786 $this->db->rollback();
787 return -1;
788 } else {
789 $this->db->commit();
790 return 1;
791 }
792 }
793 } else {
794 $this->errors[] = $this->db->lasterror();
795 return -1;
796 }
797 }
798
806 public function initAsSpecimen()
807 {
808 $this->id = 0;
809 $this->specimen = 1;
810 $this->ref = 'CBA';
811 $this->label = 'CustomerCorp Bank account';
812 $this->bank = 'CustomerCorp Bank';
813 $this->type = 'ban';
814 $this->status = Account::STATUS_OPEN;
815 $this->code_banque = '123';
816 $this->code_guichet = '456';
817 $this->number = 'CUST12345';
818 $this->cle_rib = '50';
819 $this->bic = 'CC12';
820 $this->iban = 'FR999999999';
821
822 $this->address = 'Rue de Paris';
823 $this->country_id = 1;
824
825 $this->owner_name = 'Owner';
826 $this->owner_address = 'Owner address';
827 $this->owner_country_id = 1;
828
829 $this->rum = 'UMR-CU1212-0007-5-1475405262';
830 $this->date_rum = dol_now() - 10000;
831 $this->frstrecur = 'FRST';
832
833 $this->socid = 1;
834
835 return 1;
836 }
837}
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
$object ref
Definition info.php:90
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current balance.
error()
Return error.
Class to manage bank accounts description of third parties.
static checkPaymentReference($ref)
Check a payment reference before it is stored.
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.
static cleanPaymentReference($ref)
Payment reference in the form it is stored: an ISO 11649 (RF) reference without spaces and in upper c...
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...
Definition index.php:169
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
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.
dolCreditorRefIsValid($ref)
Check that a string is a valid ISO 11649 Structured Creditor Reference.
dolPayRefStrip($ref)
Remove formatting spaces from a payment reference (machine form).
dolPayRefDetectScheme($ref)
Detect which structured payment reference scheme a stored value belongs to.
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.
div refaddress div address