35require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
46 public $element =
'bank_account';
51 public $table_element =
'bank_account';
56 public $picto =
'account';
98 public $clos = self::STATUS_OPEN;
122 public $code_guichet;
160 public $pti_in_ctti = 0;
180 public $owner_address;
196 public $owner_country_id;
200 public $owner_country_code;
208 public $domiciliation;
237 public $type_lib = array();
243 public $account_number;
248 public $fk_accountancy_journal;
253 public $accountancy_journal;
259 public $currency_code;
267 public $account_currency_code;
317 public $ics_transfer;
353 public $fields = array(
354 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
355 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 25),
356 'label' => array(
'type' =>
'varchar(30)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
357 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 35,
'index' => 1),
358 'bank' => array(
'type' =>
'varchar(60)',
'label' =>
'Bank',
'enabled' => 1,
'visible' => -1,
'position' => 40),
359 'code_banque' => array(
'type' =>
'varchar(128)',
'label' =>
'Code banque',
'enabled' => 1,
'visible' => -1,
'position' => 45),
360 'code_guichet' => array(
'type' =>
'varchar(6)',
'label' =>
'Code guichet',
'enabled' => 1,
'visible' => -1,
'position' => 50),
361 'number' => array(
'type' =>
'varchar(255)',
'label' =>
'Number',
'enabled' => 1,
'visible' => -1,
'position' => 55),
362 'cle_rib' => array(
'type' =>
'varchar(5)',
'label' =>
'Cle rib',
'enabled' => 1,
'visible' => -1,
'position' => 60),
363 'bic' => array(
'type' =>
'varchar(11)',
'label' =>
'Bic',
'enabled' => 1,
'visible' => -1,
'position' => 65),
364 'iban_prefix' => array(
'type' =>
'varchar(34)',
'label' =>
'Iban prefix',
'enabled' => 1,
'visible' => -1,
'position' => 70),
365 'country_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Country iban',
'enabled' => 1,
'visible' => -1,
'position' => 75),
366 'cle_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Cle iban',
'enabled' => 1,
'visible' => -1,
'position' => 80),
367 'domiciliation' => array(
'type' =>
'varchar(255)',
'label' =>
'Domiciliation',
'enabled' => 1,
'visible' => -1,
'position' => 85),
368 'state_id' => array(
'type' =>
'integer',
'label' =>
'StateId',
'enabled' => 1,
'visible' => -1,
'position' => 90),
369 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 95),
370 'proprio' => array(
'type' =>
'varchar(60)',
'label' =>
'Proprio',
'enabled' => 1,
'visible' => -1,
'position' => 100),
371 'owner_address' => array(
'type' =>
'varchar(255)',
'label' =>
'Owner address',
'enabled' => 1,
'visible' => -1,
'position' => 105),
372 'owner_zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Owner zip',
'enabled' => 1,
'visible' => -1,
'position' => 106),
373 'owner_town' => array(
'type' =>
'varchar(50)',
'label' =>
'Owner town',
'enabled' => 1,
'visible' => -1,
'position' => 107),
374 'owner_country_id' => array(
'type' =>
'integer',
'label' =>
'Owner country',
'enabled' => 1,
'visible' => -1,
'position' => 108),
375 'courant' => array(
'type' =>
'smallint(6)',
'label' =>
'Courant',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 110),
376 'clos' => array(
'type' =>
'smallint(6)',
'label' =>
'Clos',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 115),
377 'rappro' => array(
'type' =>
'smallint(6)',
'label' =>
'Rappro',
'enabled' => 1,
'visible' => -1,
'position' => 120),
378 'url' => array(
'type' =>
'varchar(128)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 125),
379 'account_number' => array(
'type' =>
'varchar(32)',
'label' =>
'Account number',
'enabled' => 1,
'visible' => -1,
'position' => 130),
380 'fk_accountancy_journal' => array(
'type' =>
'integer',
'label' =>
'Accountancy journal ID',
'enabled' => 1,
'visible' => -1,
'position' => 132),
381 'accountancy_journal' => array(
'type' =>
'varchar(20)',
'label' =>
'Accountancy journal',
'enabled' => 1,
'visible' => -1,
'position' => 135),
382 'currency_code' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency code',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 140),
383 'min_allowed' => array(
'type' =>
'integer',
'label' =>
'Min allowed',
'enabled' => 1,
'visible' => -1,
'position' => 145),
384 'min_desired' => array(
'type' =>
'integer',
'label' =>
'Min desired',
'enabled' => 1,
'visible' => -1,
'position' => 150),
385 'comment' => array(
'type' =>
'text',
'label' =>
'Comment',
'enabled' => 1,
'visible' => -1,
'position' => 155),
386 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 156),
387 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 157),
388 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 160),
389 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 165),
390 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 170),
391 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 175),
392 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 180),
393 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 185),
411 const STATUS_OPEN = 0;
412 const STATUS_CLOSED = 1;
426 $this->ismultientitymanaged = 1;
430 $this->type_lib = array(
431 self::TYPE_SAVINGS => $langs->transnoentitiesnoconv(
"BankType0"),
432 self::TYPE_CURRENT => $langs->transnoentitiesnoconv(
"BankType1"),
433 self::TYPE_CASH => $langs->transnoentitiesnoconv(
"BankType2"),
436 $this->labelStatus = array(
437 self::STATUS_OPEN => $langs->transnoentitiesnoconv(
"StatusAccountOpened"),
438 self::STATUS_CLOSED => $langs->transnoentitiesnoconv(
"StatusAccountClosed")
451 if ($val ==
'BankCode') {
452 $string .= $this->code_banque.
' ';
453 } elseif ($val ==
'BankAccountNumber') {
454 $string .= $this->number.
' ';
455 } elseif ($val ==
'DeskCode') {
456 $string .= $this->code_guichet.
' ';
457 } elseif ($val ==
'BankAccountNumberKey') {
458 $string .= $this->cle_rib.
' ';
459 } elseif ($val ==
'BIC') {
460 $string .= $this->bic.
' ';
461 } elseif ($val ==
'IBAN') {
462 $string .= $this->iban.
' ';
466 return trim($string);
479 if (empty($this->rappro)) {
508 $sqlcheck =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"bank_url";
509 $sqlcheck .=
" WHERE fk_bank = ".((int) $line_id);
510 $sqlcheck .=
" AND url_id = ".((int) $url_id);
511 $sqlcheck .=
" AND type = '".$this->db->escape($type).
"'";
512 $resqlcheck = $this->db->query($sqlcheck);
514 $obj = $this->db->fetch_object($resqlcheck);
516 $this->db->free($resqlcheck);
517 return (
int) $obj->rowid;
519 $this->db->free($resqlcheck);
522 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
528 $sql .=
") VALUES (";
529 $sql .= ((int) $line_id);
530 $sql .=
", ".((int) $url_id);
531 $sql .=
", '".$this->db->escape($url).
"'";
532 $sql .=
", '".$this->db->escape($label).
"'";
533 $sql .=
", '".$this->db->escape($type).
"'";
536 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
537 if ($this->db->query($sql)) {
538 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
541 $this->
error = $this->db->lasterror();
556 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
562 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
563 $this->
error =
"ErrorBadParameter";
567 $sql =
"SELECT fk_bank, url_id, url, label, type";
568 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
570 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
572 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
574 $sql .=
" ORDER BY type, label";
576 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
577 $result = $this->db->query($sql);
580 $num = $this->db->num_rows($result);
582 $obj = $this->db->fetch_object($result);
584 $lines[$i][0] = $obj->url;
585 $lines[$i][1] = $obj->url_id;
586 $lines[$i][2] = $obj->label;
587 $lines[$i][3] = $obj->type;
589 $lines[$i][
'url'] = $obj->url;
590 $lines[$i][
'url_id'] = $obj->url_id;
591 $lines[$i][
'label'] = $obj->label;
592 $lines[$i][
'type'] = $obj->type;
593 $lines[$i][
'fk_bank'] = $obj->fk_bank;
622 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null, $note_private =
'')
627 if (is_numeric($oper)) {
628 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
631 if (empty($this->
id) && !empty($this->rowid)) {
632 $this->
id = $this->rowid;
636 $emetteur = trim($emetteur);
637 $banque = trim($banque);
638 $label = trim($label);
642 if (is_numeric($oper)) {
643 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
644 $sql .=
" WHERE id = ".((int) $oper);
645 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
646 $resql = $this->db->query($sql);
648 $obj = $this->db->fetch_object($resql);
658 $this->
error = $langs->trans(
"OperNotDefined");
662 $this->
error = $langs->trans(
"ThisIdNotDefined");
666 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
672 if (is_null($datev) || empty($datev)) {
677 $accline->datec = $now;
678 $accline->dateo = $date;
679 $accline->datev = $datev;
680 $accline->label = $label;
681 $accline->amount = $amount;
682 $accline->amount_main_currency = $amount_main_currency;
683 $accline->fk_user_author = $user->id;
684 $accline->fk_account = $this->id;
685 $accline->fk_type = $oper;
686 $accline->numero_compte = $accountancycode;
687 $accline->num_releve = $num_releve;
688 $accline->note_private = $note_private;
691 $accline->num_chq = $num_chq;
695 $accline->emetteur = $emetteur;
699 $accline->bank_chq = $banque;
702 if ($accline->insert() > 0) {
703 if ($categorie > 0) {
704 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bankline(";
705 $sql .=
"lineid, fk_categ";
706 $sql .=
") VALUES (";
707 $sql .= ((int) $accline->id).
", ".((int) $categorie);
710 $result = $this->db->query($sql);
712 $this->
error = $this->db->lasterror();
713 $this->db->rollback();
724 $this->db->rollback();
737 public function create($user, $notrigger = 0)
739 global $langs,
$conf;
744 if (!$this->min_allowed) {
745 $this->min_allowed = 0;
747 if (!$this->min_desired) {
748 $this->min_desired = 0;
752 if (empty($this->country_id)) {
753 $langs->load(
'errors');
754 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
758 if (empty($this->
ref)) {
759 $langs->load(
'errors');
760 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
764 if (empty($this->date_solde)) {
765 $langs->load(
'errors');
766 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
772 $balance = $this->balance;
773 if (empty($balance) && !empty($this->
solde)) {
774 dol_syslog(get_class($this).
"::create solde is deprecated use balance", LOG_NOTICE);
775 $balance = $this->solde;
777 if (empty($balance)) {
780 if (empty($this->
status && !empty($this->clos))) {
781 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
782 $this->
status = $this->clos;
785 if (empty($this->country_id) && !empty($this->country_code)) {
786 $country_id =
getCountry($this->country_code,
'3');
787 $this->country_id = is_int($country_id) ? $country_id : 0;
791 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
797 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
802 $sql .=
", account_number";
803 $sql .=
", fk_accountancy_journal";
805 $sql .=
", code_banque";
806 $sql .=
", code_guichet";
810 $sql .=
", iban_prefix";
811 $sql .=
", domiciliation";
812 $sql .=
", pti_in_ctti";
814 $sql .=
", owner_address";
815 $sql .=
", owner_zip";
816 $sql .=
", owner_town";
817 $sql .=
", owner_country_id";
818 $sql .=
", currency_code";
820 $sql .=
", min_allowed";
821 $sql .=
", min_desired";
823 $sql .=
", state_id";
826 $sql .=
", ics_transfer";
827 $sql .=
") VALUES (";
828 $sql .=
"'".$this->db->idate($now).
"'";
829 $sql .=
", '".$this->db->escape($this->
ref).
"'";
830 $sql .=
", '".$this->db->escape($this->label).
"'";
831 $sql .=
", ".((int)
$conf->entity);
832 $sql .=
", '".$this->db->escape($this->account_number).
"'";
833 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
834 $sql .=
", '".$this->db->escape($this->bank).
"'";
835 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
836 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
837 $sql .=
", '".$this->db->escape($this->number).
"'";
838 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
839 $sql .=
", '".$this->db->escape($this->bic).
"'";
840 $sql .=
", '".$this->db->escape($this->iban).
"'";
841 $sql .=
", '".$this->db->escape($this->
address).
"'";
842 $sql .=
", ".((int) $this->pti_in_ctti);
843 $sql .=
", '".$this->db->escape($this->owner_name).
"'";
844 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
845 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
846 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
847 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
848 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
849 $sql .=
", ".((int) $this->rappro);
850 $sql .=
", ".price2num($this->min_allowed,
'MT');
851 $sql .=
", ".price2num($this->min_desired,
'MT');
852 $sql .=
", '".$this->db->escape($this->comment).
"'";
853 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
854 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
855 $sql .=
", '".$this->db->escape($this->ics).
"'";
856 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
859 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
860 $resql = $this->db->query($sql);
862 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
864 $result = $this->
update($user, 1);
867 $accline->datec = $now;
868 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
869 $accline->amount = (float)
price2num($balance);
870 $accline->fk_user_author = $user->id;
871 $accline->fk_account = $this->id;
872 $accline->datev = $this->date_solde;
873 $accline->dateo = $this->date_solde;
874 $accline->fk_type =
'SOLD';
876 if ($accline->insert() < 0) {
888 if (!$error && !$notrigger) {
890 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
900 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
901 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
904 $this->
error = $this->db->error().
" sql=".$sql;
913 $this->db->rollback();
925 public function update($user, $notrigger = 0)
927 global $langs,
$conf;
929 if (empty($this->country_id) && !empty($this->country_code)) {
930 $country_id =
getCountry($this->country_code,
'3');
931 $this->country_id = is_int($country_id) ? $country_id : 0;
939 if (empty($this->country_id)) {
940 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
944 if (empty($this->
ref)) {
945 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
950 $this->label =
"???";
953 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
954 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
955 $sql .=
",label = '".$this->db->escape($this->label).
"'";
956 $sql .=
",courant = ".((int) $this->
type);
957 $sql .=
",clos = ".((int) $this->
status);
958 $sql .=
",rappro = ".((int) $this->rappro);
959 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
960 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
961 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
962 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
963 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
964 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
965 $sql .=
",number='".$this->db->escape($this->number).
"'";
966 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
967 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
968 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
969 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
970 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
971 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
972 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
973 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
974 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
975 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
977 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
979 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
980 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
981 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
983 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
984 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
985 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
986 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
988 $sql .=
" WHERE rowid = ".((int) $this->
id);
990 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
991 $result = $this->db->query($sql);
1001 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
1002 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
1003 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type='bank_account' and entity = ".((int)
$conf->entity);
1004 $resql = $this->db->query($sql);
1007 $this->
error = $this->db->lasterror();
1013 $dirsource =
$conf->bank->dir_output.
'/'.$oldref;
1014 $dirdest =
$conf->bank->dir_output.
'/'.$newref;
1015 if (file_exists($dirsource)) {
1016 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
1017 if (@rename($dirsource, $dirdest)) {
1023 if (!$error && !$notrigger) {
1025 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
1033 $this->
error = $this->db->lasterror();
1038 $this->db->commit();
1041 $this->db->rollback();
1057 global
$conf, $langs;
1060 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1062 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1066 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1070 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1071 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1072 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1073 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1074 $sql .=
",number='".$this->db->escape($this->number).
"'";
1075 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1076 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1077 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1078 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
1079 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
1080 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1081 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1082 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1083 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1084 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1085 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1086 $sql .=
" WHERE rowid = ".((int) $this->
id);
1087 $sql .=
" AND entity = ".((int)
$conf->entity);
1089 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1091 $result = $this->db->query($sql);
1095 $this->
error = $this->db->lasterror();
1111 if (empty($id) && empty($ref)) {
1112 $this->
error =
"ErrorBadParameters";
1116 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url, ba.entity,";
1117 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1118 $sql .=
" ba.domiciliation as address, ba.pti_in_ctti, ba.proprio as owner_name, ba.owner_address, ba.owner_zip, ba.owner_town, ba.owner_country_id, ba.state_id, ba.fk_pays as country_id,";
1119 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1120 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1121 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1122 $sql .=
' c.code as country_code, c.label as country,';
1123 $sql .=
' d.code_departement as state_code, d.nom as state,';
1124 $sql .=
' aj.code as accountancy_journal';
1125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1126 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1127 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1128 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid = ba.fk_accountancy_journal';
1129 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1131 $sql .=
" AND ba.rowid = ".((int) $id);
1134 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1137 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1138 $result = $this->db->query($sql);
1140 if ($this->db->num_rows($result)) {
1141 $obj = $this->db->fetch_object($result);
1143 $this->
id = $obj->rowid;
1144 $this->rowid = $obj->rowid;
1145 $this->entity = $obj->entity;
1146 $this->
ref = $obj->ref;
1147 $this->label = $obj->label;
1148 $this->
type = $obj->type;
1149 $this->courant = $obj->type;
1150 $this->bank = $obj->bank;
1151 $this->clos = $obj->status;
1152 $this->
status = $obj->status;
1153 $this->rappro = $obj->rappro;
1154 $this->url = $obj->url;
1156 $this->code_banque = $obj->code_banque;
1157 $this->code_guichet = $obj->code_guichet;
1158 $this->number = $obj->number;
1159 $this->cle_rib = $obj->cle_rib;
1160 $this->bic = $obj->bic;
1161 $this->iban = $obj->iban;
1162 $this->
address = $obj->address;
1164 $this->owner_name = $obj->owner_name;
1165 $this->proprio = $this->owner_name;
1166 $this->owner_address = $obj->owner_address;
1167 $this->owner_zip = $obj->owner_zip;
1168 $this->owner_town = $obj->owner_town;
1169 $this->owner_country_id = $obj->owner_country_id;
1171 $this->pti_in_ctti = $obj->pti_in_ctti;
1173 $this->state_id = $obj->state_id;
1174 $this->state_code = $obj->state_code;
1175 $this->state = $obj->state;
1177 $this->country_id = $obj->country_id;
1178 $this->country_code = $obj->country_code;
1179 $this->country = $obj->country;
1181 $this->account_number = $obj->account_number;
1182 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1183 $this->accountancy_journal = $obj->accountancy_journal;
1185 $this->currency_code = $obj->currency_code;
1186 $this->account_currency_code = $obj->currency_code;
1187 $this->min_allowed = $obj->min_allowed;
1188 $this->min_desired = $obj->min_desired;
1189 $this->comment = $obj->comment;
1191 $this->date_creation = $this->db->jdate($obj->date_creation);
1192 $this->date_modification = $this->db->jdate($obj->date_modification);
1194 $this->ics = $obj->ics;
1195 $this->ics_transfer = $obj->ics_transfer;
1206 $this->
error = $this->db->lasterror();
1207 $this->errors[] = $this->error;
1224 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1225 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1235 public function delete($user, $notrigger = 0)
1245 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1246 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1248 $resql = $this->db->query($sql);
1251 $this->
error =
"Error ".$this->db->lasterror();
1256 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1257 $sql .=
" WHERE rowid = ".((int) $this->
id);
1259 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1260 $result = $this->db->query($sql);
1267 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1272 $this->
error =
"Error ".$this->db->lasterror();
1277 $this->db->commit();
1280 $this->db->rollback();
1309 $langs->load(
'banks');
1311 if ($status == self::STATUS_OPEN) {
1312 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1313 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1314 $statusType =
'status4';
1316 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1317 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1318 $statusType =
'status5';
1321 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1334 $can_be_deleted =
false;
1336 $sql =
"SELECT COUNT(rowid) as nb";
1337 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1338 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1340 $resql = $this->db->query($sql);
1342 $obj = $this->db->fetch_object($resql);
1343 if ($obj->nb <= 1) {
1344 $can_be_deleted =
true;
1349 return $can_be_deleted;
1360 return $this->error;
1371 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1375 $sql =
"SELECT sum(amount) as amount";
1376 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1377 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1379 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1382 $resql = $this->db->query($sql);
1384 if ($this->db->num_rows($resql)) {
1385 $obj = $this->db->fetch_object($resql);
1386 $solde = $obj->amount;
1388 $this->db->free($resql);
1390 $this->errors[] = $this->db->lasterror;
1408 global
$conf, $langs;
1414 $sql =
"SELECT b.rowid, b.datev as datefin";
1415 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1416 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1417 $sql .=
" WHERE b.rappro=0";
1418 $sql .=
" AND b.fk_account = ba.rowid";
1419 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1421 $sql .=
" AND clos = 0";
1422 if ($filteraccountid) {
1423 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1426 $resql = $this->db->query($sql);
1428 $langs->load(
"banks");
1431 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1434 $response->warning_delay =
$conf->bank->rappro->warning_delay / 60 / 60 / 24;
1435 $response->label = $langs->trans(
"TransactionsToConciliate");
1436 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1437 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1440 while ($obj = $this->db->fetch_object($resql)) {
1441 $response->nbtodo++;
1442 if ($this->db->jdate($obj->datefin) < ($now -
$conf->bank->rappro->warning_delay)) {
1443 $response->nbtodolate++;
1450 $this->
error = $this->db->error();
1469 $sql =
"SELECT count(b.rowid) as nb";
1470 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1471 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1472 $sql .=
" WHERE b.fk_account = ba.rowid";
1473 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1474 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1475 $sql .=
" AND clos = 0";
1476 if ($filteraccountid) {
1477 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1480 $resql = $this->db->query($sql);
1482 while ($obj = $this->db->fetch_object($resql)) {
1483 $this->nb[
"banklines"] = $obj->nb;
1485 $this->db->free($resql);
1489 $this->
error = $this->db->error();
1511 $sql =
"SELECT COUNT(ba.rowid) as nb";
1512 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1513 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1514 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1519 $resql = $this->db->query($sql);
1521 $obj = $this->db->fetch_object($resql);
1541 $langs->loadLangs([
'banks',
'compta']);
1542 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1546 $nofetch = !empty($params[
'nofetch']);
1547 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1548 if (isset($this->
status)) {
1549 $pictos .=
' '.$this->getLibStatut(5);
1551 $datas[
'picto'] = $pictos;
1552 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1553 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1554 $datas[
'accountnumber'] =
'<br><br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1556 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1557 $datas[
'accountcurrency'] =
'<br><br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1559 if (isModEnabled(
'accounting')) {
1560 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1561 $langs->load(
"accountancy");
1562 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1563 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1566 if (isModEnabled(
'category') && !$nofetch) {
1567 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1568 $form =
new Form($this->db);
1569 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1586 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1588 global
$conf, $langs;
1590 if (!empty(
$conf->dol_no_mouse_hover)) {
1594 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1597 $classfortooltip =
'classfortooltip';
1601 'objecttype' => $this->element,
1602 'option' => $option,
1606 $classfortooltip =
'classforajaxtooltip';
1607 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1613 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1614 if ($mode ==
'transactions') {
1615 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1616 } elseif ($mode ==
'receipts') {
1617 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1620 if ($option !=
'nolink') {
1622 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1623 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1624 $add_save_lastsearch_values = 1;
1626 if ($add_save_lastsearch_values) {
1627 $url .=
'&save_lastsearch_values=1';
1632 if (empty($notooltip)) {
1634 $label = $langs->trans(
"BankAccount");
1635 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1637 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1638 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1640 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1643 if ($option ==
'nolink' || empty($url)) {
1644 $linkstart =
'<span';
1646 $linkstart =
'<a href="'.$url.
'"';
1648 $linkstart .= $linkclose.
'>';
1649 if ($option ==
'nolink' || empty($url)) {
1650 $linkend =
'</span>';
1655 $result .= $linkstart;
1658 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1660 if ($withpicto != 2) {
1661 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1663 $result .= $linkend;
1679 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1686 $this->
error =
'IBANNotValid';
1692 $this->
error =
'SwiftNotValid';
1712 if (!empty($this->country_code)) {
1713 return $this->country_code;
1717 if (!empty($this->iban)) {
1720 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1726 if (!empty($this->socid)) {
1727 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1728 $company =
new Societe($this->db);
1729 $result = $company->fetch($this->socid);
1730 if (!empty($company->country_code)) {
1731 return $company->country_code;
1736 if (!empty($mysoc->country_code)) {
1737 return $mysoc->country_code;
1752 global
$conf, $langs;
1759 if (!empty(
$conf->use_javascript_ajax)) {
1761 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1762 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1765 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1785 public function useDetailedBBAN()
1787 $country_code = $this->getCountryCode();
1789 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1790 return 1; // France, Spain, Gabon, ... - Not valid for CH
1792 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1793 return 2; // Australia, England...
1803 public function needIBAN()
1807 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1811 $country_code = $this->getCountryCode();
1813 $country_code_in_EEC = array(
1818 'CZ', // Czech republic
1825 'GB', // United Kingdom
1831 'IM', // Isle of Man - Included in UK
1836 'MC', // Monaco - Included in France
1845 'UK', // United Kingdom
1846 //'CH', // Switzerland - No. Swizerland in not in EEC
1849 if (in_array($country_code, $country_code_in_EEC)) {
1850 return 1; // France, Spain, ...
1860 public function needBIC()
1862 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1866 $country_code = $this->getCountryCode();
1868 $country_code_in_EEC = array(
1880 if (in_array($country_code, $country_code_in_EEC)) {
1881 return 1; // Andorra, Bahrein, ...
1892 public function info($id)
1910 public function getFieldsToShow($includeibanbic = 0)
1912 //Get the required properties depending on the country
1913 $detailedBBAN = $this->useDetailedBBAN();
1915 if ($detailedBBAN == 0) {
1916 $fieldarray = array(
1919 } elseif ($detailedBBAN == 2) {
1920 $fieldarray = array(
1925 $fieldarray = self::getAccountNumberOrder();
1928 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1929 if ($includeibanbic) {
1930 $fieldarray[] = 'IBAN';
1931 $fieldarray[] = 'BIC';
1935 //Get the order the properties are shown
1949 public static function getAccountNumberOrder()
1953 $fieldlists = array(
1956 'BankAccountNumber',
1957 'BankAccountNumberKey'
1960 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1961 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1962 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1963 $fieldlists = array(
1966 'BankAccountNumberKey',
1971 //Replace the old AccountNumber key with the new BankAccountNumber key
1972 $fieldlists = explode(
1974 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1990 public function initAsSpecimen()
1992 // Example of IBAN FR7630001007941234567890185
1993 $this->specimen = 1;
1995 $this->label = 'My Big Company Bank account';
1996 $this->courant = Account::TYPE_CURRENT;
1997 $this->clos = Account::STATUS_OPEN;
1998 $this->type = Account::TYPE_CURRENT;
1999 $this->status = Account::STATUS_OPEN;
2000 $this->code_banque = '30001';
2001 $this->code_guichet = '00794';
2002 $this->number = '12345678901';
2003 $this->cle_rib = '85';
2004 $this->bic = 'AA12';
2005 $this->iban = 'FR7630001007941234567890185';
2007 $this->bank = 'MyBank';
2008 $this->address = 'Rue de Paris';
2009 $this->owner_name = 'Owner';
2010 $this->owner_address = 'Owner address';
2011 $this->owner_zip = 'Owner zip';
2012 $this->owner_town = 'Owner town';
2013 $this->owner_country_id = 1;
2014 $this->country_id = 1;
2027 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2029 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type=
'company'";
2031 if ($dbs->query($sql)) {
2034 //if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdparty and B-C on old one, we must get A-B-C after merge. Not A-B.
2035 //$this->errors = $dbs->lasterror();
2047 public function getKanbanView($option = '', $arraydata = null)
2051 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2053 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2054 $return .= '<div class="info-box
info-box-sm
">';
2055 $return .= '<span class="info-box-icon bg-infobox-action
">';
2056 $return .= img_picto('', $this->picto);
2057 $return .= '</span>';
2058 $return .= '<div class="info-box-content
">';
2059 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2060 if ($selected >= 0) {
2061 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2063 if (property_exists($this, 'type_lib')) {
2064 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2066 if (method_exists($this, 'solde')) {
2067 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2068 $return .= '<span class="opacitymedium
">'.$langs->trans("Balance
").'</span> : <span class="amount
">'.price(price2num($this->solde(1), 'MT'), 0, $langs, 1, -1, -1, $this->currency_code).'</span>';
2070 if (method_exists($this, 'getLibStatut')) {
2071 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2073 $return .= '</div>';
2074 $return .= '</div>';
2075 $return .= '</div>';
2081require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2086class AccountLine extends CommonObjectLine
2096 public $element = 'bank';
2101 public $table_element = 'bank';
2106 public $picto = 'accountline';
2147 public $amount_main_currency;
2152 public $fk_user_author;
2157 public $fk_user_rappro;
2167 public $fk_bordereau;
2177 public $bank_account_ref;
2182 public $bank_account_label;
2187 public $numero_compte;
2229 public $user_rappro;
2237 public function __construct(DoliDB $db)
2250 public function fetch($rowid, $ref = '', $num = '')
2253 if (empty($rowid) && empty($ref) && empty($num)) {
2257 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2258 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2259 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2260 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2261 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2262 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2263 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2264 $sql .= " WHERE b.fk_account = ba.rowid
";
2265 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2267 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2269 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2271 $sql .= " AND b.rowid =
".((int) $rowid);
2274 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2275 $result = $this->db->query($sql);
2279 $obj = $this->db->fetch_object($result);
2281 $this->id = $obj->rowid;
2282 $this->rowid = $obj->rowid;
2283 $this->ref = $obj->rowid;
2285 $this->datec = $this->db->jdate($obj->datec);
2286 $this->datev = $this->db->jdate($obj->datev);
2287 $this->dateo = $this->db->jdate($obj->dateo);
2288 $this->amount = $obj->amount;
2289 $this->label = $obj->label;
2290 $this->note = $obj->note;
2292 $this->fk_user_author = $obj->fk_user_author;
2293 $this->fk_user_rappro = $obj->fk_user_rappro;
2295 $this->fk_type = $obj->fk_type; // Type of transaction
2296 $this->rappro = (int) $obj->rappro;
2297 $this->num_releve = $obj->num_releve;
2299 $this->num_chq = $obj->num_chq;
2300 $this->bank_chq = $obj->banque;
2301 $this->fk_bordereau = $obj->fk_bordereau;
2303 $this->fk_account = $obj->fk_account;
2304 $this->bank_account_ref = $obj->bank_account_ref;
2305 $this->bank_account_label = $obj->bank_account_label;
2307 // Retrieve all extrafield
2308 // fetch optionals attributes and labels
2309 $this->fetch_optionals();
2313 $this->db->free($result);
2325 public function insert()
2331 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2337 $sql .= ", amount_main_currency
";
2338 $sql .= ", fk_user_author
";
2339 $sql .= ", num_chq
";
2340 $sql .= ", fk_account
";
2341 $sql .= ", fk_type
";
2342 $sql .= ", emetteur,banque
";
2344 $sql .= ", numero_compte
";
2345 $sql .= ", num_releve
";
2347 $sql .= ") VALUES (
";
2348 $sql .= "'".$this->db->idate($this->datec)."'";
2349 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2350 $sql .= ",
'".$this->db->idate($this->datev)."'";
2351 $sql .= ",
'".$this->db->escape($this->label)."'";
2352 $sql .= ",
".price2num($this->amount);
2353 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2354 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2355 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2356 $sql .= ",
'".$this->db->escape((string) $this->fk_account)."'";
2357 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2358 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2359 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2360 $sql .= ",
".(int) $this->rappro;
2361 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2362 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2363 $sql .= ",
".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2367 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2368 $resql = $this->db->query($sql);
2370 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2371 // Actions on extra fields (by external module or standard code)
2372 $result = $this->insertExtraFields();
2378 $this->error = $this->db->lasterror();
2379 dol_print_error($this->db);
2383 $this->db->commit();
2386 $this->db->rollback();
2398 public function delete($user, $notrigger = 0)
2402 if ($this->rappro) {
2403 // Protection to avoid any delete of consolidated lines
2404 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2412 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2414 $this->db->rollback();
2417 // End call triggers
2420 // Protection to avoid any delete of accounted lines. Protection on by default
2421 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2422 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2423 $resql = $this->db->query($sql);
2425 $obj = $this->db->fetch_object($resql);
2426 if ($obj && $obj->nb) {
2427 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2428 $this->db->rollback();
2432 $this->error = $this->db->lasterror();
2433 $this->db->rollback();
2439 $result = $this->delete_urls($user);
2444 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2445 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2446 $result = $this->db->query($sql);
2451 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2452 $result = $this->db->query($sql);
2457 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2458 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2459 $result = $this->db->query($sql);
2465 $this->db->commit();
2468 $this->db->rollback();
2474 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2481 public function delete_urls($user = null)
2486 if ($this->rappro) {
2487 // Protection to avoid any delete of consolidated lines
2488 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2494 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2495 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2496 $result = $this->db->query($sql);
2502 $this->db->commit();
2505 $this->db->rollback();
2518 public function update(User $user, $notrigger = 0)
2522 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2523 $sql .= " amount =
".price2num($this->amount).",
";
2524 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2525 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2526 $sql .= " WHERE rowid =
".((int) $this->rowid);
2528 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2529 $resql = $this->db->query($sql);
2531 $this->db->commit();
2534 $this->db->rollback();
2535 $this->error = $this->db->error();
2546 public function updateLabel()
2550 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2551 $sql .= " label =
'".$this->db->escape($this->label)."'";
2552 $sql .= " WHERE rowid =
".((int) $this->rowid);
2554 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2555 $resql = $this->db->query($sql);
2557 $this->db->commit();
2560 $this->db->rollback();
2561 $this->error = $this->db->error();
2567 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2576 public function update_conciliation(User $user, $cat, $conciliated = 1)
2579 global $conf, $langs;
2583 // Check statement field
2584 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2585 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2586 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2591 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2592 $sql .= " rappro =
".((int) $conciliated);
2593 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2595 $sql .= ", fk_user_rappro =
".((int) $user->id);
2597 $sql .= " WHERE rowid =
".((int) $this->id);
2599 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2600 $resql = $this->db->query($sql);
2602 if (!empty($cat) && $cat > 0) {
2603 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2605 $sql .= ", fk_categ
";
2606 $sql .= ") VALUES (
";
2608 $sql .= ",
".((int) $cat);
2611 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2612 $this->db->query($sql);
2614 // No error check. Can fail if category already affected
2615 // TODO Do no try the insert if link already exists
2618 $this->rappro = (int) $conciliated;
2620 $this->db->commit();
2623 $this->db->rollback();
2629 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2637 public function datev_change($rowid, $sign = 1)
2640 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2641 $resql = $this->db->query($sql);
2643 $obj = $this->db->fetch_object($resql);
2644 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2646 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2647 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2648 $sql .= " WHERE rowid =
".((int) $rowid);
2650 $result = $this->db->query($sql);
2652 if ($this->db->affected_rows($result)) {
2656 dol_print_error($this->db);
2660 dol_print_error($this->db);
2665 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2672 public function datev_next($id)
2675 return $this->datev_change($id, 1);
2678 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2685 public function datev_previous($id)
2688 return $this->datev_change($id, -1);
2692 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2700 public function dateo_change($rowid, $sign = 1)
2703 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2704 $resql = $this->db->query($sql);
2706 $obj = $this->db->fetch_object($resql);
2707 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2709 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2710 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2711 $sql .= " WHERE rowid =
".((int) $rowid);
2713 $result = $this->db->query($sql);
2715 if ($this->db->affected_rows($result)) {
2719 dol_print_error($this->db);
2723 dol_print_error($this->db);
2728 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2735 public function dateo_next($id)
2738 return $this->dateo_change($id, 1);
2741 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2748 public function dateo_previous($id)
2751 return $this->dateo_change($id, -1);
2761 public function info($id)
2763 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2764 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2765 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2766 $sql .= ' WHERE b.rowid = '.((int) $id);
2768 $result = $this->db->query($sql);
2770 if ($this->db->num_rows($result)) {
2771 $obj = $this->db->fetch_object($result);
2773 $this->id = $obj->rowid;
2775 $this->user_creation_id = $obj->fk_user_author;
2776 $this->user_rappro = $obj->fk_user_rappro;
2777 $this->date_creation = $this->db->jdate($obj->datec);
2778 $this->date_modification = $this->db->jdate($obj->datem);
2779 //$this->date_rappro = $obj->daterappro; // Not yet managed
2781 $this->db->free($result);
2783 dol_print_error($this->db);
2797 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2799 global $conf, $langs;
2803 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2804 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2805 if ($this->amount) {
2806 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2809 $linkstart = '<a href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid=
'.((int) $this->id).'&save_lastsearch_values=1
" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip
">';
2812 $result .= $linkstart;
2814 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'account'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright
"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright
' : '').'classfortooltip
"'), 0, 0, $notooltip ? 0 : 1);
2816 if ($withpicto != 2) {
2817 $result .= ($this->ref ? $this->ref : $this->id);
2820 $result .= $linkend;
2822 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2823 $result .= ' <span class="opacitymedium
">(';
2825 if ($option == 'showall') {
2826 $result .= $langs->trans("BankAccount
").': ';
2827 $accountstatic = new Account($this->db);
2828 $accountstatic->id = $this->fk_account;
2829 $accountstatic->ref = $this->bank_account_ref;
2830 $accountstatic->label = $this->bank_account_label;
2831 $result .= $accountstatic->getNomUrl(0).', ';
2833 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2834 $result .= $langs->trans("BankLineConciliated
").': ';
2835 $result .= yn($this->rappro);
2837 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2838 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2839 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2840 $resql = $this->db->query($sql);
2842 $obj = $this->db->fetch_object($resql);
2843 if ($obj && $obj->nb) {
2844 $result .= ' - '.$langs->trans("Accounted
").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2846 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2850 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2851 $result .= ')</span>';
2864 public function getLibStatut($mode = 0)
2866 return $this->LibStatut($this->status, $mode);
2869 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2877 public function LibStatut($status, $mode = 0)
2889 public function getVentilExportCompta($mode = 0)
2891 $alreadydispatched = 0;
2895 $sql = " SELECT
".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb
";
2896 $sql .= " FROM
".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type =
'".$this->db->escape($type)."' AND ab.fk_doc =
".((int) $this->id);
2897 $resql = $this->db->query($sql);
2899 $obj = $this->db->fetch_object($resql);
2901 $alreadydispatched = $obj->nb;
2904 $this->error = $this->db->lasterror();
2908 if ($alreadydispatched) {
2909 return $alreadydispatched;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
checkIbanForAccount($account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current balance.
fetch($id, $ref='')
Load a bank account into memory from database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $mode='', $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
loadStateBoard($filteraccountid=0)
Load the indicators this->nb for the state board.
getCountryCode()
Return account country code.
getLibStatut($mode=0)
Return label of object status.
update_bban($user=null)
Update BBAN (RIB) account fields.
create($user, $notrigger=0)
Create bank account into database.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null, $note_private='')
Add an entry into table llx_bank.
getBannerAddress($htmlkey, $object)
Return full address for banner.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
update($user, $notrigger=0)
Update bank account card.
__toString()
Shows the account number in the appropriate format.
delete($user, $notrigger=0)
Delete bank account from database.
const TYPE_SAVINGS
Savings account.
getTooltipContentArray($params)
getTooltipContentArray
canBeConciliated()
Return if a bank account need to be conciliated.
can_be_deleted()
Indicates if an account can be deleted or not (without movements)
const TYPE_CURRENT
Current account.
setCategories($categories)
Sets object to supplied categories.
countAccountToReconcile()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
verif()
Return if an account has valid information for Direct debit payment.
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
get_url($fk_bank=0, $url_id=0, $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
setErrorsFromObject($object)
setErrorsFromObject
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type