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,";
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->
ref = $obj->ref;
1146 $this->label = $obj->label;
1147 $this->
type = $obj->type;
1148 $this->courant = $obj->type;
1149 $this->bank = $obj->bank;
1150 $this->clos = $obj->status;
1151 $this->
status = $obj->status;
1152 $this->rappro = $obj->rappro;
1153 $this->url = $obj->url;
1155 $this->code_banque = $obj->code_banque;
1156 $this->code_guichet = $obj->code_guichet;
1157 $this->number = $obj->number;
1158 $this->cle_rib = $obj->cle_rib;
1159 $this->bic = $obj->bic;
1160 $this->iban = $obj->iban;
1161 $this->
address = $obj->address;
1163 $this->owner_name = $obj->owner_name;
1164 $this->proprio = $this->owner_name;
1165 $this->owner_address = $obj->owner_address;
1166 $this->owner_zip = $obj->owner_zip;
1167 $this->owner_town = $obj->owner_town;
1168 $this->owner_country_id = $obj->owner_country_id;
1170 $this->pti_in_ctti = $obj->pti_in_ctti;
1172 $this->state_id = $obj->state_id;
1173 $this->state_code = $obj->state_code;
1174 $this->state = $obj->state;
1176 $this->country_id = $obj->country_id;
1177 $this->country_code = $obj->country_code;
1178 $this->country = $obj->country;
1180 $this->account_number = $obj->account_number;
1181 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1182 $this->accountancy_journal = $obj->accountancy_journal;
1184 $this->currency_code = $obj->currency_code;
1185 $this->account_currency_code = $obj->currency_code;
1186 $this->min_allowed = $obj->min_allowed;
1187 $this->min_desired = $obj->min_desired;
1188 $this->comment = $obj->comment;
1190 $this->date_creation = $this->db->jdate($obj->date_creation);
1191 $this->date_modification = $this->db->jdate($obj->date_modification);
1193 $this->ics = $obj->ics;
1194 $this->ics_transfer = $obj->ics_transfer;
1205 $this->
error = $this->db->lasterror();
1206 $this->errors[] = $this->error;
1223 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1224 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1234 public function delete($user, $notrigger = 0)
1244 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1245 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1247 $resql = $this->db->query($sql);
1250 $this->
error =
"Error ".$this->db->lasterror();
1255 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1256 $sql .=
" WHERE rowid = ".((int) $this->
id);
1258 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1259 $result = $this->db->query($sql);
1266 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1271 $this->
error =
"Error ".$this->db->lasterror();
1276 $this->db->commit();
1279 $this->db->rollback();
1308 $langs->load(
'banks');
1310 if ($status == self::STATUS_OPEN) {
1311 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1312 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1313 $statusType =
'status4';
1315 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1316 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1317 $statusType =
'status5';
1320 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1333 $can_be_deleted =
false;
1335 $sql =
"SELECT COUNT(rowid) as nb";
1336 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1337 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1339 $resql = $this->db->query($sql);
1341 $obj = $this->db->fetch_object($resql);
1342 if ($obj->nb <= 1) {
1343 $can_be_deleted =
true;
1348 return $can_be_deleted;
1359 return $this->error;
1370 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1374 $sql =
"SELECT sum(amount) as amount";
1375 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1376 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1378 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1381 $resql = $this->db->query($sql);
1383 if ($this->db->num_rows($resql)) {
1384 $obj = $this->db->fetch_object($resql);
1385 $solde = $obj->amount;
1387 $this->db->free($resql);
1389 $this->errors[] = $this->db->lasterror;
1407 global
$conf, $langs;
1413 $sql =
"SELECT b.rowid, b.datev as datefin";
1414 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1415 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1416 $sql .=
" WHERE b.rappro=0";
1417 $sql .=
" AND b.fk_account = ba.rowid";
1418 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1420 $sql .=
" AND clos = 0";
1421 if ($filteraccountid) {
1422 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1425 $resql = $this->db->query($sql);
1427 $langs->load(
"banks");
1430 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1433 $response->warning_delay =
$conf->bank->rappro->warning_delay / 60 / 60 / 24;
1434 $response->label = $langs->trans(
"TransactionsToConciliate");
1435 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1436 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1439 while ($obj = $this->db->fetch_object($resql)) {
1440 $response->nbtodo++;
1441 if ($this->db->jdate($obj->datefin) < ($now -
$conf->bank->rappro->warning_delay)) {
1442 $response->nbtodolate++;
1449 $this->
error = $this->db->error();
1468 $sql =
"SELECT count(b.rowid) as nb";
1469 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1470 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1471 $sql .=
" WHERE b.fk_account = ba.rowid";
1472 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1473 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1474 $sql .=
" AND clos = 0";
1475 if ($filteraccountid) {
1476 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1479 $resql = $this->db->query($sql);
1481 while ($obj = $this->db->fetch_object($resql)) {
1482 $this->nb[
"banklines"] = $obj->nb;
1484 $this->db->free($resql);
1488 $this->
error = $this->db->error();
1510 $sql =
"SELECT COUNT(ba.rowid) as nb";
1511 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1512 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1513 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1518 $resql = $this->db->query($sql);
1520 $obj = $this->db->fetch_object($resql);
1540 $langs->loadLangs([
'banks',
'compta']);
1541 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1545 $nofetch = !empty($params[
'nofetch']);
1546 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1547 if (isset($this->
status)) {
1548 $pictos .=
' '.$this->getLibStatut(5);
1550 $datas[
'picto'] = $pictos;
1551 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1552 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1553 $datas[
'accountnumber'] =
'<br><br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1555 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1556 $datas[
'accountcurrency'] =
'<br><br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1558 if (isModEnabled(
'accounting')) {
1559 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1560 $langs->load(
"accountancy");
1561 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1562 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1565 if (isModEnabled(
'category') && !$nofetch) {
1566 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1567 $form =
new Form($this->db);
1568 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1585 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1587 global
$conf, $langs;
1589 if (!empty(
$conf->dol_no_mouse_hover)) {
1593 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1596 $classfortooltip =
'classfortooltip';
1600 'objecttype' => $this->element,
1601 'option' => $option,
1605 $classfortooltip =
'classforajaxtooltip';
1606 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1612 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1613 if ($mode ==
'transactions') {
1614 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1615 } elseif ($mode ==
'receipts') {
1616 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1619 if ($option !=
'nolink') {
1621 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1622 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1623 $add_save_lastsearch_values = 1;
1625 if ($add_save_lastsearch_values) {
1626 $url .=
'&save_lastsearch_values=1';
1631 if (empty($notooltip)) {
1633 $label = $langs->trans(
"BankAccount");
1634 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1636 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1637 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1639 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1642 if ($option ==
'nolink' || empty($url)) {
1643 $linkstart =
'<span';
1645 $linkstart =
'<a href="'.$url.
'"';
1647 $linkstart .= $linkclose.
'>';
1648 if ($option ==
'nolink' || empty($url)) {
1649 $linkend =
'</span>';
1654 $result .= $linkstart;
1657 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1659 if ($withpicto != 2) {
1660 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1662 $result .= $linkend;
1678 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1685 $this->
error =
'IBANNotValid';
1691 $this->
error =
'SwiftNotValid';
1711 if (!empty($this->country_code)) {
1712 return $this->country_code;
1716 if (!empty($this->iban)) {
1719 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1725 if (!empty($this->socid)) {
1726 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1727 $company =
new Societe($this->db);
1728 $result = $company->fetch($this->socid);
1729 if (!empty($company->country_code)) {
1730 return $company->country_code;
1735 if (!empty($mysoc->country_code)) {
1736 return $mysoc->country_code;
1751 global
$conf, $langs;
1758 if (!empty(
$conf->use_javascript_ajax)) {
1760 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1761 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1764 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1784 public function useDetailedBBAN()
1786 $country_code = $this->getCountryCode();
1788 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1789 return 1; // France, Spain, Gabon, ... - Not valid for CH
1791 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1792 return 2; // Australia, England...
1802 public function needIBAN()
1806 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1810 $country_code = $this->getCountryCode();
1812 $country_code_in_EEC = array(
1817 'CZ', // Czech republic
1824 'GB', // United Kingdom
1830 'IM', // Isle of Man - Included in UK
1835 'MC', // Monaco - Included in France
1844 'UK', // United Kingdom
1845 //'CH', // Switzerland - No. Swizerland in not in EEC
1848 if (in_array($country_code, $country_code_in_EEC)) {
1849 return 1; // France, Spain, ...
1859 public function needBIC()
1861 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1865 $country_code = $this->getCountryCode();
1867 $country_code_in_EEC = array(
1879 if (in_array($country_code, $country_code_in_EEC)) {
1880 return 1; // Andorra, Bahrein, ...
1891 public function info($id)
1909 public function getFieldsToShow($includeibanbic = 0)
1911 //Get the required properties depending on the country
1912 $detailedBBAN = $this->useDetailedBBAN();
1914 if ($detailedBBAN == 0) {
1915 $fieldarray = array(
1918 } elseif ($detailedBBAN == 2) {
1919 $fieldarray = array(
1924 $fieldarray = self::getAccountNumberOrder();
1927 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1928 if ($includeibanbic) {
1929 $fieldarray[] = 'IBAN';
1930 $fieldarray[] = 'BIC';
1934 //Get the order the properties are shown
1948 public static function getAccountNumberOrder()
1952 $fieldlists = array(
1955 'BankAccountNumber',
1956 'BankAccountNumberKey'
1959 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1960 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1961 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1962 $fieldlists = array(
1965 'BankAccountNumberKey',
1970 //Replace the old AccountNumber key with the new BankAccountNumber key
1971 $fieldlists = explode(
1973 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1989 public function initAsSpecimen()
1991 // Example of IBAN FR7630001007941234567890185
1992 $this->specimen = 1;
1994 $this->label = 'My Big Company Bank account';
1995 $this->courant = Account::TYPE_CURRENT;
1996 $this->clos = Account::STATUS_OPEN;
1997 $this->type = Account::TYPE_CURRENT;
1998 $this->status = Account::STATUS_OPEN;
1999 $this->code_banque = '30001';
2000 $this->code_guichet = '00794';
2001 $this->number = '12345678901';
2002 $this->cle_rib = '85';
2003 $this->bic = 'AA12';
2004 $this->iban = 'FR7630001007941234567890185';
2006 $this->bank = 'MyBank';
2007 $this->address = 'Rue de Paris';
2008 $this->owner_name = 'Owner';
2009 $this->owner_address = 'Owner address';
2010 $this->owner_zip = 'Owner zip';
2011 $this->owner_town = 'Owner town';
2012 $this->owner_country_id = 1;
2013 $this->country_id = 1;
2026 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2028 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type=
'company'";
2030 if ($dbs->query($sql)) {
2033 //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.
2034 //$this->errors = $dbs->lasterror();
2046 public function getKanbanView($option = '', $arraydata = null)
2050 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2052 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2053 $return .= '<div class="info-box
info-box-sm
">';
2054 $return .= '<span class="info-box-icon bg-infobox-action
">';
2055 $return .= img_picto('', $this->picto);
2056 $return .= '</span>';
2057 $return .= '<div class="info-box-content
">';
2058 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2059 if ($selected >= 0) {
2060 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2062 if (property_exists($this, 'type_lib')) {
2063 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2065 if (method_exists($this, 'solde')) {
2066 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2067 $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>';
2069 if (method_exists($this, 'getLibStatut')) {
2070 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2072 $return .= '</div>';
2073 $return .= '</div>';
2074 $return .= '</div>';
2080require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2085class AccountLine extends CommonObjectLine
2095 public $element = 'bank';
2100 public $table_element = 'bank';
2105 public $picto = 'accountline';
2146 public $amount_main_currency;
2151 public $fk_user_author;
2156 public $fk_user_rappro;
2166 public $fk_bordereau;
2176 public $bank_account_ref;
2181 public $bank_account_label;
2186 public $numero_compte;
2228 public $user_rappro;
2236 public function __construct(DoliDB $db)
2249 public function fetch($rowid, $ref = '', $num = '')
2252 if (empty($rowid) && empty($ref) && empty($num)) {
2256 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2257 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2258 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2259 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2260 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2261 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2262 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2263 $sql .= " WHERE b.fk_account = ba.rowid
";
2264 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2266 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2268 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2270 $sql .= " AND b.rowid =
".((int) $rowid);
2273 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2274 $result = $this->db->query($sql);
2278 $obj = $this->db->fetch_object($result);
2280 $this->id = $obj->rowid;
2281 $this->rowid = $obj->rowid;
2282 $this->ref = $obj->rowid;
2284 $this->datec = $this->db->jdate($obj->datec);
2285 $this->datev = $this->db->jdate($obj->datev);
2286 $this->dateo = $this->db->jdate($obj->dateo);
2287 $this->amount = $obj->amount;
2288 $this->label = $obj->label;
2289 $this->note = $obj->note;
2291 $this->fk_user_author = $obj->fk_user_author;
2292 $this->fk_user_rappro = $obj->fk_user_rappro;
2294 $this->fk_type = $obj->fk_type; // Type of transaction
2295 $this->rappro = (int) $obj->rappro;
2296 $this->num_releve = $obj->num_releve;
2298 $this->num_chq = $obj->num_chq;
2299 $this->bank_chq = $obj->banque;
2300 $this->fk_bordereau = $obj->fk_bordereau;
2302 $this->fk_account = $obj->fk_account;
2303 $this->bank_account_ref = $obj->bank_account_ref;
2304 $this->bank_account_label = $obj->bank_account_label;
2306 // Retrieve all extrafield
2307 // fetch optionals attributes and labels
2308 $this->fetch_optionals();
2312 $this->db->free($result);
2324 public function insert()
2330 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2336 $sql .= ", amount_main_currency
";
2337 $sql .= ", fk_user_author
";
2338 $sql .= ", num_chq
";
2339 $sql .= ", fk_account
";
2340 $sql .= ", fk_type
";
2341 $sql .= ", emetteur,banque
";
2343 $sql .= ", numero_compte
";
2344 $sql .= ", num_releve
";
2346 $sql .= ") VALUES (
";
2347 $sql .= "'".$this->db->idate($this->datec)."'";
2348 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2349 $sql .= ",
'".$this->db->idate($this->datev)."'";
2350 $sql .= ",
'".$this->db->escape($this->label)."'";
2351 $sql .= ",
".price2num($this->amount);
2352 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2353 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2354 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2355 $sql .= ",
'".$this->db->escape((string) $this->fk_account)."'";
2356 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2357 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2358 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2359 $sql .= ",
".(int) $this->rappro;
2360 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2361 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2362 $sql .= ",
".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2366 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2367 $resql = $this->db->query($sql);
2369 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2370 // Actions on extra fields (by external module or standard code)
2371 $result = $this->insertExtraFields();
2377 $this->error = $this->db->lasterror();
2378 dol_print_error($this->db);
2382 $this->db->commit();
2385 $this->db->rollback();
2397 public function delete($user, $notrigger = 0)
2401 if ($this->rappro) {
2402 // Protection to avoid any delete of consolidated lines
2403 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2411 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2413 $this->db->rollback();
2416 // End call triggers
2419 // Protection to avoid any delete of accounted lines. Protection on by default
2420 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2421 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2422 $resql = $this->db->query($sql);
2424 $obj = $this->db->fetch_object($resql);
2425 if ($obj && $obj->nb) {
2426 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2427 $this->db->rollback();
2431 $this->error = $this->db->lasterror();
2432 $this->db->rollback();
2438 $result = $this->delete_urls($user);
2443 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2444 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2445 $result = $this->db->query($sql);
2450 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2451 $result = $this->db->query($sql);
2456 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2457 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2458 $result = $this->db->query($sql);
2464 $this->db->commit();
2467 $this->db->rollback();
2473 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2480 public function delete_urls($user = null)
2485 if ($this->rappro) {
2486 // Protection to avoid any delete of consolidated lines
2487 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2493 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2494 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2495 $result = $this->db->query($sql);
2501 $this->db->commit();
2504 $this->db->rollback();
2517 public function update(User $user, $notrigger = 0)
2521 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2522 $sql .= " amount =
".price2num($this->amount).",
";
2523 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2524 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2525 $sql .= " WHERE rowid =
".((int) $this->rowid);
2527 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2528 $resql = $this->db->query($sql);
2530 $this->db->commit();
2533 $this->db->rollback();
2534 $this->error = $this->db->error();
2545 public function updateLabel()
2549 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2550 $sql .= " label =
'".$this->db->escape($this->label)."'";
2551 $sql .= " WHERE rowid =
".((int) $this->rowid);
2553 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2554 $resql = $this->db->query($sql);
2556 $this->db->commit();
2559 $this->db->rollback();
2560 $this->error = $this->db->error();
2566 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2575 public function update_conciliation(User $user, $cat, $conciliated = 1)
2578 global $conf, $langs;
2582 // Check statement field
2583 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2584 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2585 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2590 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2591 $sql .= " rappro =
".((int) $conciliated);
2592 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2594 $sql .= ", fk_user_rappro =
".((int) $user->id);
2596 $sql .= " WHERE rowid =
".((int) $this->id);
2598 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2599 $resql = $this->db->query($sql);
2601 if (!empty($cat) && $cat > 0) {
2602 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2604 $sql .= ", fk_categ
";
2605 $sql .= ") VALUES (
";
2607 $sql .= ",
".((int) $cat);
2610 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2611 $this->db->query($sql);
2613 // No error check. Can fail if category already affected
2614 // TODO Do no try the insert if link already exists
2617 $this->rappro = (int) $conciliated;
2619 $this->db->commit();
2622 $this->db->rollback();
2628 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2636 public function datev_change($rowid, $sign = 1)
2639 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2640 $resql = $this->db->query($sql);
2642 $obj = $this->db->fetch_object($resql);
2643 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2645 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2646 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2647 $sql .= " WHERE rowid =
".((int) $rowid);
2649 $result = $this->db->query($sql);
2651 if ($this->db->affected_rows($result)) {
2655 dol_print_error($this->db);
2659 dol_print_error($this->db);
2664 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2671 public function datev_next($id)
2674 return $this->datev_change($id, 1);
2677 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2684 public function datev_previous($id)
2687 return $this->datev_change($id, -1);
2691 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2699 public function dateo_change($rowid, $sign = 1)
2702 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2703 $resql = $this->db->query($sql);
2705 $obj = $this->db->fetch_object($resql);
2706 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2708 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2709 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2710 $sql .= " WHERE rowid =
".((int) $rowid);
2712 $result = $this->db->query($sql);
2714 if ($this->db->affected_rows($result)) {
2718 dol_print_error($this->db);
2722 dol_print_error($this->db);
2727 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2734 public function dateo_next($id)
2737 return $this->dateo_change($id, 1);
2740 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2747 public function dateo_previous($id)
2750 return $this->dateo_change($id, -1);
2760 public function info($id)
2762 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2763 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2764 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2765 $sql .= ' WHERE b.rowid = '.((int) $id);
2767 $result = $this->db->query($sql);
2769 if ($this->db->num_rows($result)) {
2770 $obj = $this->db->fetch_object($result);
2772 $this->id = $obj->rowid;
2774 $this->user_creation_id = $obj->fk_user_author;
2775 $this->user_rappro = $obj->fk_user_rappro;
2776 $this->date_creation = $this->db->jdate($obj->datec);
2777 $this->date_modification = $this->db->jdate($obj->datem);
2778 //$this->date_rappro = $obj->daterappro; // Not yet managed
2780 $this->db->free($result);
2782 dol_print_error($this->db);
2796 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2798 global $conf, $langs;
2802 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2803 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2804 if ($this->amount) {
2805 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2808 $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
">';
2811 $result .= $linkstart;
2813 $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);
2815 if ($withpicto != 2) {
2816 $result .= ($this->ref ? $this->ref : $this->id);
2819 $result .= $linkend;
2821 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2822 $result .= ' <span class="opacitymedium
">(';
2824 if ($option == 'showall') {
2825 $result .= $langs->trans("BankAccount
").': ';
2826 $accountstatic = new Account($this->db);
2827 $accountstatic->id = $this->fk_account;
2828 $accountstatic->ref = $this->bank_account_ref;
2829 $accountstatic->label = $this->bank_account_label;
2830 $result .= $accountstatic->getNomUrl(0).', ';
2832 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2833 $result .= $langs->trans("BankLineConciliated
").': ';
2834 $result .= yn($this->rappro);
2836 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2837 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2838 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2839 $resql = $this->db->query($sql);
2841 $obj = $this->db->fetch_object($resql);
2842 if ($obj && $obj->nb) {
2843 $result .= ' - '.$langs->trans("Accounted
").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2845 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2849 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2850 $result .= ')</span>';
2863 public function getLibStatut($mode = 0)
2865 return $this->LibStatut($this->status, $mode);
2868 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2876 public function LibStatut($status, $mode = 0)
2888 public function getVentilExportCompta($mode = 0)
2890 $alreadydispatched = 0;
2894 $sql = " SELECT
".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb
";
2895 $sql .= " FROM
".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type =
'".$this->db->escape($type)."' AND ab.fk_doc =
".((int) $this->id);
2896 $resql = $this->db->query($sql);
2898 $obj = $this->db->fetch_object($resql);
2900 $alreadydispatched = $obj->nb;
2903 $this->error = $this->db->lasterror();
2907 if ($alreadydispatched) {
2908 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