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)) {
506 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
512 $sql .=
") VALUES (";
513 $sql .= ((int) $line_id);
514 $sql .=
", ".((int) $url_id);
515 $sql .=
", '".$this->db->escape($url).
"'";
516 $sql .=
", '".$this->db->escape($label).
"'";
517 $sql .=
", '".$this->db->escape($type).
"'";
520 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
521 if ($this->db->query($sql)) {
522 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
525 $this->
error = $this->db->lasterror();
540 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
546 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
547 $this->
error =
"ErrorBadParameter";
551 $sql =
"SELECT fk_bank, url_id, url, label, type";
552 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
554 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
556 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
558 $sql .=
" ORDER BY type, label";
560 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
561 $result = $this->db->query($sql);
564 $num = $this->db->num_rows($result);
566 $obj = $this->db->fetch_object($result);
568 $lines[$i][0] = $obj->url;
569 $lines[$i][1] = $obj->url_id;
570 $lines[$i][2] = $obj->label;
571 $lines[$i][3] = $obj->type;
573 $lines[$i][
'url'] = $obj->url;
574 $lines[$i][
'url_id'] = $obj->url_id;
575 $lines[$i][
'label'] = $obj->label;
576 $lines[$i][
'type'] = $obj->type;
577 $lines[$i][
'fk_bank'] = $obj->fk_bank;
605 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
610 if (is_numeric($oper)) {
611 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
614 if (empty($this->
id) && !empty($this->rowid)) {
615 $this->
id = $this->rowid;
619 $emetteur = trim($emetteur);
620 $banque = trim($banque);
621 $label = trim($label);
625 if (is_numeric($oper)) {
626 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
627 $sql .=
" WHERE id = ".((int) $oper);
628 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
629 $resql = $this->db->query($sql);
631 $obj = $this->db->fetch_object($resql);
641 $this->
error = $langs->trans(
"OperNotDefined");
645 $this->
error = $langs->trans(
"ThisIdNotDefined");
649 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
655 if (is_null($datev) || empty($datev)) {
660 $accline->datec = $now;
661 $accline->dateo = $date;
662 $accline->datev = $datev;
663 $accline->label = $label;
664 $accline->amount = $amount;
665 $accline->amount_main_currency = $amount_main_currency;
666 $accline->fk_user_author = $user->id;
667 $accline->fk_account = $this->id;
668 $accline->fk_type = $oper;
669 $accline->numero_compte = $accountancycode;
670 $accline->num_releve = $num_releve;
673 $accline->num_chq = $num_chq;
677 $accline->emetteur = $emetteur;
681 $accline->bank_chq = $banque;
684 if ($accline->insert() > 0) {
685 if ($categorie > 0) {
686 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bankline(";
687 $sql .=
"lineid, fk_categ";
688 $sql .=
") VALUES (";
689 $sql .= ((int) $accline->id).
", '".$this->db->escape($categorie).
"'";
692 $result = $this->db->query($sql);
694 $this->
error = $this->db->lasterror();
695 $this->db->rollback();
706 $this->db->rollback();
719 public function create($user, $notrigger = 0)
721 global $langs, $conf;
726 if (!$this->min_allowed) {
727 $this->min_allowed = 0;
729 if (!$this->min_desired) {
730 $this->min_desired = 0;
734 if (empty($this->country_id)) {
735 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
739 if (empty($this->
ref)) {
740 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
744 if (empty($this->date_solde)) {
745 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
751 $balance = $this->balance;
752 if (empty($balance) && !empty($this->
solde)) {
753 $balance = $this->solde;
755 if (empty($balance)) {
758 if (empty($this->
status && !empty($this->clos))) {
759 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
760 $this->
status = $this->clos;
764 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
770 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
775 $sql .=
", account_number";
776 $sql .=
", fk_accountancy_journal";
778 $sql .=
", code_banque";
779 $sql .=
", code_guichet";
783 $sql .=
", iban_prefix";
784 $sql .=
", domiciliation";
785 $sql .=
", pti_in_ctti";
787 $sql .=
", owner_address";
788 $sql .=
", owner_zip";
789 $sql .=
", owner_town";
790 $sql .=
", owner_country_id";
791 $sql .=
", currency_code";
793 $sql .=
", min_allowed";
794 $sql .=
", min_desired";
796 $sql .=
", state_id";
799 $sql .=
", ics_transfer";
800 $sql .=
") VALUES (";
801 $sql .=
"'".$this->db->idate($now).
"'";
802 $sql .=
", '".$this->db->escape($this->
ref).
"'";
803 $sql .=
", '".$this->db->escape($this->label).
"'";
804 $sql .=
", ".((int) $conf->entity);
805 $sql .=
", '".$this->db->escape($this->account_number).
"'";
806 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
807 $sql .=
", '".$this->db->escape($this->bank).
"'";
808 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
809 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
810 $sql .=
", '".$this->db->escape($this->number).
"'";
811 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
812 $sql .=
", '".$this->db->escape($this->bic).
"'";
813 $sql .=
", '".$this->db->escape($this->iban).
"'";
814 $sql .=
", '".$this->db->escape($this->
address).
"'";
815 $sql .=
", ".((int) $this->pti_in_ctti);
816 $sql .=
", '".$this->db->escape($this->owner_name).
"'";
817 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
818 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
819 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
820 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
821 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
822 $sql .=
", ".((int) $this->rappro);
823 $sql .=
", ".price2num($this->min_allowed,
'MT');
824 $sql .=
", ".price2num($this->min_desired,
'MT');
825 $sql .=
", '".$this->db->escape($this->comment).
"'";
826 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
827 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
828 $sql .=
", '".$this->db->escape($this->ics).
"'";
829 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
832 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
833 $resql = $this->db->query($sql);
835 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
837 $result = $this->
update($user, 1);
840 $accline->datec = $now;
841 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
842 $accline->amount = (float)
price2num($balance);
843 $accline->fk_user_author = $user->id;
844 $accline->fk_account = $this->id;
845 $accline->datev = $this->date_solde;
846 $accline->dateo = $this->date_solde;
847 $accline->fk_type =
'SOLD';
849 if ($accline->insert() < 0) {
851 $this->
error = $accline->error;
852 $this->errors = $accline->errors;
862 if (!$error && !$notrigger) {
864 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
874 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
875 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
878 $this->
error = $this->db->error().
" sql=".$sql;
887 $this->db->rollback();
899 public function update($user, $notrigger = 0)
901 global $langs, $conf;
908 if (empty($this->country_id)) {
909 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
913 if (empty($this->
ref)) {
914 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
919 $this->label =
"???";
922 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
923 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
924 $sql .=
",label = '".$this->db->escape($this->label).
"'";
925 $sql .=
",courant = ".((int) $this->
type);
926 $sql .=
",clos = ".((int) $this->
status);
927 $sql .=
",rappro = ".((int) $this->rappro);
928 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
929 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
930 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
931 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
932 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
933 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
934 $sql .=
",number='".$this->db->escape($this->number).
"'";
935 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
936 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
937 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
938 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
939 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
940 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
941 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
942 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
943 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
944 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
946 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
948 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
949 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
950 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
952 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
953 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
954 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
955 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
957 $sql .=
" WHERE rowid = ".((int) $this->
id);
959 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
960 $result = $this->db->query($sql);
970 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
971 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
972 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type='bank_account' and entity = ".((int) $conf->entity);
973 $resql = $this->db->query($sql);
976 $this->
error = $this->db->lasterror();
982 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
983 $dirdest = $conf->bank->dir_output.
'/'.$newref;
984 if (file_exists($dirsource)) {
985 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
986 if (@rename($dirsource, $dirdest)) {
992 if (!$error && !$notrigger) {
994 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
1002 $this->
error = $this->db->lasterror();
1007 $this->db->commit();
1010 $this->db->rollback();
1026 global $conf, $langs;
1029 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1031 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1035 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1039 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1040 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1041 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1042 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1043 $sql .=
",number='".$this->db->escape($this->number).
"'";
1044 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1045 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1046 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1047 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
1048 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
1049 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1050 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1051 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1052 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1053 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1054 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1055 $sql .=
" WHERE rowid = ".((int) $this->
id);
1056 $sql .=
" AND entity = ".((int) $conf->entity);
1058 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1060 $result = $this->db->query($sql);
1064 $this->
error = $this->db->lasterror();
1080 if (empty($id) && empty($ref)) {
1081 $this->
error =
"ErrorBadParameters";
1085 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1086 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1087 $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,";
1088 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1089 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1090 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1091 $sql .=
' c.code as country_code, c.label as country,';
1092 $sql .=
' d.code_departement as state_code, d.nom as state,';
1093 $sql .=
' aj.code as accountancy_journal';
1094 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1095 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1096 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1097 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1098 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1100 $sql .=
" AND ba.rowid = ".((int) $id);
1103 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1106 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1107 $result = $this->db->query($sql);
1109 if ($this->db->num_rows($result)) {
1110 $obj = $this->db->fetch_object($result);
1112 $this->
id = $obj->rowid;
1113 $this->rowid = $obj->rowid;
1114 $this->
ref = $obj->ref;
1115 $this->label = $obj->label;
1116 $this->
type = $obj->type;
1117 $this->courant = $obj->type;
1118 $this->bank = $obj->bank;
1119 $this->clos = $obj->status;
1120 $this->
status = $obj->status;
1121 $this->rappro = $obj->rappro;
1122 $this->url = $obj->url;
1124 $this->code_banque = $obj->code_banque;
1125 $this->code_guichet = $obj->code_guichet;
1126 $this->number = $obj->number;
1127 $this->cle_rib = $obj->cle_rib;
1128 $this->bic = $obj->bic;
1129 $this->iban = $obj->iban;
1130 $this->
address = $obj->address;
1132 $this->owner_name = $obj->owner_name;
1133 $this->proprio = $this->owner_name;
1134 $this->owner_address = $obj->owner_address;
1135 $this->owner_zip = $obj->owner_zip;
1136 $this->owner_town = $obj->owner_town;
1137 $this->owner_country_id = $obj->owner_country_id;
1139 $this->pti_in_ctti = $obj->pti_in_ctti;
1141 $this->state_id = $obj->state_id;
1142 $this->state_code = $obj->state_code;
1143 $this->state = $obj->state;
1145 $this->country_id = $obj->country_id;
1146 $this->country_code = $obj->country_code;
1147 $this->country = $obj->country;
1149 $this->account_number = $obj->account_number;
1150 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1151 $this->accountancy_journal = $obj->accountancy_journal;
1153 $this->currency_code = $obj->currency_code;
1154 $this->account_currency_code = $obj->currency_code;
1155 $this->min_allowed = $obj->min_allowed;
1156 $this->min_desired = $obj->min_desired;
1157 $this->comment = $obj->comment;
1159 $this->date_creation = $this->db->jdate($obj->date_creation);
1160 $this->date_modification = $this->db->jdate($obj->date_modification);
1162 $this->ics = $obj->ics;
1163 $this->ics_transfer = $obj->ics_transfer;
1174 $this->
error = $this->db->lasterror();
1175 $this->errors[] = $this->error;
1192 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1193 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1203 public function delete($user =
null, $notrigger = 0)
1213 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1214 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1216 $resql = $this->db->query($sql);
1219 $this->
error =
"Error ".$this->db->lasterror();
1224 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1225 $sql .=
" WHERE rowid = ".((int) $this->
id);
1227 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1228 $result = $this->db->query($sql);
1235 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1240 $this->
error =
"Error ".$this->db->lasterror();
1245 $this->db->commit();
1248 $this->db->rollback();
1277 $langs->load(
'banks');
1279 if ($status == self::STATUS_OPEN) {
1280 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1281 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1282 $statusType =
'status4';
1284 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1285 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1286 $statusType =
'status5';
1289 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1302 $can_be_deleted =
false;
1304 $sql =
"SELECT COUNT(rowid) as nb";
1305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1306 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1308 $resql = $this->db->query($sql);
1310 $obj = $this->db->fetch_object($resql);
1311 if ($obj->nb <= 1) {
1312 $can_be_deleted =
true;
1317 return $can_be_deleted;
1328 return $this->error;
1339 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1343 $sql =
"SELECT sum(amount) as amount";
1344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1345 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1347 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1350 $resql = $this->db->query($sql);
1352 if ($this->db->num_rows($resql)) {
1353 $obj = $this->db->fetch_object($resql);
1354 $solde = $obj->amount;
1356 $this->db->free($resql);
1358 $this->errors[] = $this->db->lasterror;
1376 global $conf, $langs;
1382 $sql =
"SELECT b.rowid, b.datev as datefin";
1383 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1384 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1385 $sql .=
" WHERE b.rappro=0";
1386 $sql .=
" AND b.fk_account = ba.rowid";
1387 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1389 $sql .=
" AND clos = 0";
1390 if ($filteraccountid) {
1391 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1394 $resql = $this->db->query($sql);
1396 $langs->load(
"banks");
1399 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1402 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1403 $response->label = $langs->trans(
"TransactionsToConciliate");
1404 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1405 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1408 while ($obj = $this->db->fetch_object($resql)) {
1409 $response->nbtodo++;
1410 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1411 $response->nbtodolate++;
1418 $this->
error = $this->db->error();
1437 $sql =
"SELECT count(b.rowid) as nb";
1438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1439 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1440 $sql .=
" WHERE b.fk_account = ba.rowid";
1441 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1442 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1443 $sql .=
" AND clos = 0";
1444 if ($filteraccountid) {
1445 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1448 $resql = $this->db->query($sql);
1450 while ($obj = $this->db->fetch_object($resql)) {
1451 $this->nb[
"banklines"] = $obj->nb;
1453 $this->db->free($resql);
1457 $this->
error = $this->db->error();
1479 $sql =
"SELECT COUNT(ba.rowid) as nb";
1480 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1481 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1482 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1487 $resql = $this->db->query($sql);
1489 $obj = $this->db->fetch_object($resql);
1507 $langs->loadLangs([
'banks',
'compta']);
1508 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1512 $nofetch = !empty($params[
'nofetch']);
1513 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1514 if (isset($this->
status)) {
1515 $pictos .=
' '.$this->getLibStatut(5);
1517 $datas[
'picto'] = $pictos;
1518 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1519 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1521 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1522 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1524 if (isModEnabled(
'accounting')) {
1525 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1526 $langs->load(
"accountancy");
1527 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1528 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1531 if (isModEnabled(
'category') && !$nofetch) {
1532 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1533 $form =
new Form($this->db);
1534 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1551 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1553 global $conf, $langs;
1555 if (!empty($conf->dol_no_mouse_hover)) {
1559 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1562 $classfortooltip =
'classfortooltip';
1566 'objecttype' => $this->element,
1567 'option' => $option,
1571 $classfortooltip =
'classforajaxtooltip';
1572 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1578 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1579 if ($mode ==
'transactions') {
1580 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1581 } elseif ($mode ==
'receipts') {
1582 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1585 if ($option !=
'nolink') {
1587 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1588 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1589 $add_save_lastsearch_values = 1;
1591 if ($add_save_lastsearch_values) {
1592 $url .=
'&save_lastsearch_values=1';
1597 if (empty($notooltip)) {
1599 $label = $langs->trans(
"BankAccount");
1600 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1602 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1603 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1605 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1608 if ($option ==
'nolink' || empty($url)) {
1609 $linkstart =
'<span';
1611 $linkstart =
'<a href="'.$url.
'"';
1613 $linkstart .= $linkclose.
'>';
1614 if ($option ==
'nolink' || empty($url)) {
1615 $linkend =
'</span>';
1620 $result .= $linkstart;
1623 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1625 if ($withpicto != 2) {
1626 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1628 $result .= $linkend;
1644 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1651 $this->
error =
'IBANNotValid';
1657 $this->
error =
'SwiftNotValid';
1677 if (!empty($this->country_code)) {
1678 return $this->country_code;
1682 if (!empty($this->iban)) {
1685 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1691 if (!empty($this->socid)) {
1692 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1693 $company =
new Societe($this->db);
1694 $result = $company->fetch($this->socid);
1695 if (!empty($company->country_code)) {
1696 return $company->country_code;
1701 if (!empty($mysoc->country_code)) {
1702 return $mysoc->country_code;
1717 global $conf, $langs;
1724 if (!empty($conf->use_javascript_ajax)) {
1726 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1727 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1730 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1750 public function useDetailedBBAN()
1752 $country_code = $this->getCountryCode();
1754 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1755 return 1; // France, Spain, Gabon, ... - Not valid for CH
1757 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1758 return 2; // Australia, England...
1768 public function needIBAN()
1772 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1776 $country_code = $this->getCountryCode();
1778 $country_code_in_EEC = array(
1783 'CZ', // Czech republic
1790 'GB', // United Kingdom
1796 'IM', // Isle of Man - Included in UK
1801 'MC', // Monaco - Included in France
1810 'UK', // United Kingdom
1811 //'CH', // Switzerland - No. Swizerland in not in EEC
1814 if (in_array($country_code, $country_code_in_EEC)) {
1815 return 1; // France, Spain, ...
1825 public function needBIC()
1827 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1831 $country_code = $this->getCountryCode();
1833 $country_code_in_EEC = array(
1845 if (in_array($country_code, $country_code_in_EEC)) {
1846 return 1; // Andorra, Bahrein, ...
1857 public function info($id)
1875 public function getFieldsToShow($includeibanbic = 0)
1877 //Get the required properties depending on the country
1878 $detailedBBAN = $this->useDetailedBBAN();
1880 if ($detailedBBAN == 0) {
1881 $fieldarray = array(
1884 } elseif ($detailedBBAN == 2) {
1885 $fieldarray = array(
1890 $fieldarray = self::getAccountNumberOrder();
1893 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1894 if ($includeibanbic) {
1895 $fieldarray[] = 'IBAN';
1896 $fieldarray[] = 'BIC';
1900 //Get the order the properties are shown
1914 public static function getAccountNumberOrder()
1918 $fieldlists = array(
1921 'BankAccountNumber',
1922 'BankAccountNumberKey'
1925 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1926 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1927 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1928 $fieldlists = array(
1931 'BankAccountNumberKey',
1936 //Replace the old AccountNumber key with the new BankAccountNumber key
1937 $fieldlists = explode(
1939 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1955 public function initAsSpecimen()
1957 // Example of IBAN FR7630001007941234567890185
1958 $this->specimen = 1;
1960 $this->label = 'My Big Company Bank account';
1961 $this->courant = Account::TYPE_CURRENT;
1962 $this->clos = Account::STATUS_OPEN;
1963 $this->type = Account::TYPE_CURRENT;
1964 $this->status = Account::STATUS_OPEN;
1965 $this->code_banque = '30001';
1966 $this->code_guichet = '00794';
1967 $this->number = '12345678901';
1968 $this->cle_rib = '85';
1969 $this->bic = 'AA12';
1970 $this->iban = 'FR7630001007941234567890185';
1972 $this->bank = 'MyBank';
1973 $this->address = 'Rue de Paris';
1974 $this->owner_name = 'Owner';
1975 $this->owner_address = 'Owner address';
1976 $this->owner_zip = 'Owner zip';
1977 $this->owner_town = 'Owner town';
1978 $this->owner_country_id = 1;
1979 $this->country_id = 1;
1992 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
1994 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type=
'company'";
1996 if ($dbs->query($sql)) {
1999 //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.
2000 //$this->errors = $dbs->lasterror();
2012 public function getKanbanView($option = '', $arraydata = null)
2016 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2018 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2019 $return .= '<div class="info-box
info-box-sm
">';
2020 $return .= '<span class="info-box-icon bg-infobox-action
">';
2021 $return .= img_picto('', $this->picto);
2022 $return .= '</span>';
2023 $return .= '<div class="info-box-content
">';
2024 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2025 if ($selected >= 0) {
2026 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2028 if (property_exists($this, 'type_lib')) {
2029 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2031 if (method_exists($this, 'solde')) {
2032 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2033 $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>';
2035 if (method_exists($this, 'getLibStatut')) {
2036 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2038 $return .= '</div>';
2039 $return .= '</div>';
2040 $return .= '</div>';
2046require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2051class AccountLine extends CommonObjectLine
2061 public $element = 'bank';
2066 public $table_element = 'bank';
2071 public $picto = 'accountline';
2112 public $amount_main_currency;
2117 public $fk_user_author;
2122 public $fk_user_rappro;
2132 public $fk_bordereau;
2142 public $bank_account_ref;
2147 public $bank_account_label;
2152 public $numero_compte;
2194 public $user_rappro;
2202 public function __construct(DoliDB $db)
2215 public function fetch($rowid, $ref = '', $num = '')
2218 if (empty($rowid) && empty($ref) && empty($num)) {
2222 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2223 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2224 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2225 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2226 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2227 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2228 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2229 $sql .= " WHERE b.fk_account = ba.rowid
";
2230 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2232 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2234 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2236 $sql .= " AND b.rowid =
".((int) $rowid);
2239 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2240 $result = $this->db->query($sql);
2244 $obj = $this->db->fetch_object($result);
2246 $this->id = $obj->rowid;
2247 $this->rowid = $obj->rowid;
2248 $this->ref = $obj->rowid;
2250 $this->datec = $this->db->jdate($obj->datec);
2251 $this->datev = $this->db->jdate($obj->datev);
2252 $this->dateo = $this->db->jdate($obj->dateo);
2253 $this->amount = $obj->amount;
2254 $this->label = $obj->label;
2255 $this->note = $obj->note;
2257 $this->fk_user_author = $obj->fk_user_author;
2258 $this->fk_user_rappro = $obj->fk_user_rappro;
2260 $this->fk_type = $obj->fk_type; // Type of transaction
2261 $this->rappro = (int) $obj->rappro;
2262 $this->num_releve = $obj->num_releve;
2264 $this->num_chq = $obj->num_chq;
2265 $this->bank_chq = $obj->banque;
2266 $this->fk_bordereau = $obj->fk_bordereau;
2268 $this->fk_account = $obj->fk_account;
2269 $this->bank_account_ref = $obj->bank_account_ref;
2270 $this->bank_account_label = $obj->bank_account_label;
2272 // Retrieve all extrafield
2273 // fetch optionals attributes and labels
2274 $this->fetch_optionals();
2278 $this->db->free($result);
2290 public function insert()
2296 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2302 $sql .= ", amount_main_currency
";
2303 $sql .= ", fk_user_author
";
2304 $sql .= ", num_chq
";
2305 $sql .= ", fk_account
";
2306 $sql .= ", fk_type
";
2307 $sql .= ", emetteur,banque
";
2309 $sql .= ", numero_compte
";
2310 $sql .= ", num_releve
";
2311 $sql .= ") VALUES (
";
2312 $sql .= "'".$this->db->idate($this->datec)."'";
2313 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2314 $sql .= ",
'".$this->db->idate($this->datev)."'";
2315 $sql .= ",
'".$this->db->escape($this->label)."'";
2316 $sql .= ",
".price2num($this->amount);
2317 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2318 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2319 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2320 $sql .= ",
'".$this->db->escape($this->fk_account)."'";
2321 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2322 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2323 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2324 $sql .= ",
".(int) $this->rappro;
2325 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2326 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2330 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2331 $resql = $this->db->query($sql);
2333 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2334 // Actions on extra fields (by external module or standard code)
2335 $result = $this->insertExtraFields();
2341 $this->error = $this->db->lasterror();
2342 dol_print_error($this->db);
2346 $this->db->commit();
2349 $this->db->rollback();
2361 public function delete($user = null, $notrigger = 0)
2365 if ($this->rappro) {
2366 // Protection to avoid any delete of consolidated lines
2367 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2375 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2377 $this->db->rollback();
2380 // End call triggers
2383 // Protection to avoid any delete of accounted lines. Protection on by default
2384 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2385 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2386 $resql = $this->db->query($sql);
2388 $obj = $this->db->fetch_object($resql);
2389 if ($obj && $obj->nb) {
2390 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2391 $this->db->rollback();
2395 $this->error = $this->db->lasterror();
2396 $this->db->rollback();
2402 $result = $this->delete_urls($user);
2407 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2408 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2409 $result = $this->db->query($sql);
2414 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2415 $result = $this->db->query($sql);
2420 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2421 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2422 $result = $this->db->query($sql);
2428 $this->db->commit();
2431 $this->db->rollback();
2437 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2444 public function delete_urls($user = null)
2449 if ($this->rappro) {
2450 // Protection to avoid any delete of consolidated lines
2451 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2457 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2458 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2459 $result = $this->db->query($sql);
2465 $this->db->commit();
2468 $this->db->rollback();
2481 public function update(User $user, $notrigger = 0)
2485 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2486 $sql .= " amount =
".price2num($this->amount).",
";
2487 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2488 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2489 $sql .= " WHERE rowid =
".((int) $this->rowid);
2491 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2492 $resql = $this->db->query($sql);
2494 $this->db->commit();
2497 $this->db->rollback();
2498 $this->error = $this->db->error();
2509 public function updateLabel()
2513 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2514 $sql .= " label =
'".$this->db->escape($this->label)."'";
2515 $sql .= " WHERE rowid =
".((int) $this->rowid);
2517 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2518 $resql = $this->db->query($sql);
2520 $this->db->commit();
2523 $this->db->rollback();
2524 $this->error = $this->db->error();
2530 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2539 public function update_conciliation(User $user, $cat, $conciliated = 1)
2542 global $conf, $langs;
2546 // Check statement field
2547 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2548 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2549 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2554 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2555 $sql .= " rappro =
".((int) $conciliated);
2556 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2558 $sql .= ", fk_user_rappro =
".$user->id;
2560 $sql .= " WHERE rowid =
".((int) $this->id);
2562 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2563 $resql = $this->db->query($sql);
2565 if (!empty($cat) && $cat > 0) {
2566 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2568 $sql .= ", fk_categ
";
2569 $sql .= ") VALUES (
";
2571 $sql .= ",
".((int) $cat);
2574 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2575 $this->db->query($sql);
2577 // No error check. Can fail if category already affected
2578 // TODO Do no try the insert if link already exists
2581 $this->rappro = (int) $conciliated;
2583 $this->db->commit();
2586 $this->db->rollback();
2592 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2600 public function datev_change($rowid, $sign = 1)
2603 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2604 $resql = $this->db->query($sql);
2606 $obj = $this->db->fetch_object($resql);
2607 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2609 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2610 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2611 $sql .= " WHERE rowid =
".((int) $rowid);
2613 $result = $this->db->query($sql);
2615 if ($this->db->affected_rows($result)) {
2619 dol_print_error($this->db);
2623 dol_print_error($this->db);
2628 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2635 public function datev_next($id)
2638 return $this->datev_change($id, 1);
2641 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2648 public function datev_previous($id)
2651 return $this->datev_change($id, -1);
2655 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2663 public function dateo_change($rowid, $sign = 1)
2666 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2667 $resql = $this->db->query($sql);
2669 $obj = $this->db->fetch_object($resql);
2670 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2672 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2673 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2674 $sql .= " WHERE rowid =
".((int) $rowid);
2676 $result = $this->db->query($sql);
2678 if ($this->db->affected_rows($result)) {
2682 dol_print_error($this->db);
2686 dol_print_error($this->db);
2691 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2698 public function dateo_next($id)
2701 return $this->dateo_change($id, 1);
2704 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2711 public function dateo_previous($id)
2714 return $this->dateo_change($id, -1);
2724 public function info($id)
2726 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2727 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2728 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2729 $sql .= ' WHERE b.rowid = '.((int) $id);
2731 $result = $this->db->query($sql);
2733 if ($this->db->num_rows($result)) {
2734 $obj = $this->db->fetch_object($result);
2736 $this->id = $obj->rowid;
2738 $this->user_creation_id = $obj->fk_user_author;
2739 $this->user_rappro = $obj->fk_user_rappro;
2740 $this->date_creation = $this->db->jdate($obj->datec);
2741 $this->date_modification = $this->db->jdate($obj->datem);
2742 //$this->date_rappro = $obj->daterappro; // Not yet managed
2744 $this->db->free($result);
2746 dol_print_error($this->db);
2760 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2762 global $conf, $langs;
2766 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2767 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2768 if ($this->amount) {
2769 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2772 $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
">';
2775 $result .= $linkstart;
2777 $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);
2779 if ($withpicto != 2) {
2780 $result .= ($this->ref ? $this->ref : $this->id);
2783 $result .= $linkend;
2785 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2786 $result .= ' <span class="opacitymedium
">(';
2788 if ($option == 'showall') {
2789 $result .= $langs->trans("BankAccount
").': ';
2790 $accountstatic = new Account($this->db);
2791 $accountstatic->id = $this->fk_account;
2792 $accountstatic->ref = $this->bank_account_ref;
2793 $accountstatic->label = $this->bank_account_label;
2794 $result .= $accountstatic->getNomUrl(0).', ';
2796 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2797 $result .= $langs->trans("BankLineConciliated
").': ';
2798 $result .= yn($this->rappro);
2800 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2801 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2802 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2803 $resql = $this->db->query($sql);
2805 $obj = $this->db->fetch_object($resql);
2806 if ($obj && $obj->nb) {
2807 $result .= ' - '.$langs->trans("Accounted
").': '.yn(1);
2809 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2813 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2814 $result .= ')</span>';
2827 public function getLibStatut($mode = 0)
2829 return $this->LibStatut($this->status, $mode);
2832 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2840 public function LibStatut($status, $mode = 0)
2851 public function getVentilExportCompta()
2853 $alreadydispatched = 0;
2857 $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((
int) $this->
id);
2858 $resql = $this->db->query($sql);
2860 $obj = $this->db->fetch_object($resql);
2862 $alreadydispatched = $obj->nb;
2865 $this->
error = $this->db->lasterror();
2869 if ($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.
getBannerAddress($htmlkey, $object)
Return full address for banner.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
delete($user=null, $notrigger=0)
Delete bank account from database.
update($user, $notrigger=0)
Update bank account card.
__toString()
Shows the account number in the appropriate format.
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.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null)
Add an entry into table ".MAIN_DB_PREFIX."bank.
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type