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' =>
'UserAuthor',
'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);
477 if (empty($this->rappro)) {
506 $sqlcheck =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"bank_url";
507 $sqlcheck .=
" WHERE fk_bank = ".((int) $line_id);
508 $sqlcheck .=
" AND url_id = ".((int) $url_id);
509 $sqlcheck .=
" AND type = '".$this->db->escape($type).
"'";
510 $resqlcheck = $this->db->query($sqlcheck);
512 $obj = $this->db->fetch_object($resqlcheck);
514 $this->db->free($resqlcheck);
515 return (
int) $obj->rowid;
517 $this->db->free($resqlcheck);
520 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
526 $sql .=
") VALUES (";
527 $sql .= ((int) $line_id);
528 $sql .=
", ".((int) $url_id);
529 $sql .=
", '".$this->db->escape($url).
"'";
530 $sql .=
", '".$this->db->escape($label).
"'";
531 $sql .=
", '".$this->db->escape($type).
"'";
534 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
535 if ($this->db->query($sql)) {
536 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
539 $this->
error = $this->db->lasterror();
554 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
560 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
561 $this->
error =
"ErrorBadParameter";
565 $sql =
"SELECT fk_bank, url_id, url, label, type";
566 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
568 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
570 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
572 $sql .=
" ORDER BY type, label";
574 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
575 $result = $this->db->query($sql);
578 $num = $this->db->num_rows($result);
580 $obj = $this->db->fetch_object($result);
582 $lines[$i][0] = $obj->url;
583 $lines[$i][1] = $obj->url_id;
584 $lines[$i][2] = $obj->label;
585 $lines[$i][3] = $obj->type;
587 $lines[$i][
'url'] = $obj->url;
588 $lines[$i][
'url_id'] = $obj->url_id;
589 $lines[$i][
'label'] = $obj->label;
590 $lines[$i][
'type'] = $obj->type;
591 $lines[$i][
'fk_bank'] = $obj->fk_bank;
620 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 =
'')
625 if (is_numeric($oper)) {
626 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
629 if (empty($this->
id) && !empty($this->rowid)) {
630 $this->
id = $this->rowid;
634 $emetteur = trim($emetteur);
635 $banque = trim($banque);
636 $label = trim($label);
640 if (is_numeric($oper)) {
641 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
642 $sql .=
" WHERE id = ".((int) $oper);
643 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
644 $resql = $this->db->query($sql);
646 $obj = $this->db->fetch_object($resql);
656 $this->
error = $langs->trans(
"OperNotDefined");
660 $this->
error = $langs->trans(
"ThisIdNotDefined");
664 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
670 if (is_null($datev) || empty($datev)) {
675 $accline->datec = $now;
676 $accline->dateo = $date;
677 $accline->datev = $datev;
678 $accline->label = $label;
679 $accline->amount = $amount;
680 $accline->amount_main_currency = $amount_main_currency;
681 $accline->fk_user_author = $user->id;
682 $accline->fk_account = $this->id;
683 $accline->fk_type = $oper;
684 $accline->numero_compte = $accountancycode;
685 $accline->num_releve = $num_releve;
686 $accline->note_private = $note_private;
689 $accline->num_chq = $num_chq;
693 $accline->emetteur = $emetteur;
697 $accline->bank_chq = $banque;
700 if ($accline->insert() > 0) {
701 if ($categorie > 0) {
702 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bankline(";
703 $sql .=
"lineid, fk_categ";
704 $sql .=
") VALUES (";
705 $sql .= ((int) $accline->id).
", ".((int) $categorie);
708 $result = $this->db->query($sql);
710 $this->
error = $this->db->lasterror();
711 $this->db->rollback();
722 $this->db->rollback();
735 public function create($user, $notrigger = 0)
737 global $langs, $conf;
742 if (!$this->min_allowed) {
743 $this->min_allowed = 0;
745 if (!$this->min_desired) {
746 $this->min_desired = 0;
750 if (empty($this->country_id)) {
751 $langs->load(
'errors');
752 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
756 if (empty($this->
ref)) {
757 $langs->load(
'errors');
758 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
762 if (empty($this->date_solde)) {
763 $langs->load(
'errors');
764 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
770 $balance = $this->balance;
771 if (empty($balance) && !empty($this->
solde)) {
772 dol_syslog(get_class($this).
"::create solde is deprecated use balance", LOG_NOTICE);
773 $balance = $this->solde;
775 if (empty($balance)) {
778 if (empty($this->
status && !empty($this->clos))) {
779 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
780 $this->
status = $this->clos;
783 if (empty($this->country_id) && !empty($this->country_code)) {
784 $country_id =
getCountry($this->country_code,
'3');
785 $this->country_id = is_int($country_id) ? $country_id : 0;
789 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
795 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
800 $sql .=
", account_number";
801 $sql .=
", fk_accountancy_journal";
803 $sql .=
", code_banque";
804 $sql .=
", code_guichet";
808 $sql .=
", iban_prefix";
809 $sql .=
", domiciliation";
810 $sql .=
", pti_in_ctti";
812 $sql .=
", owner_address";
813 $sql .=
", owner_zip";
814 $sql .=
", owner_town";
815 $sql .=
", owner_country_id";
816 $sql .=
", currency_code";
818 $sql .=
", min_allowed";
819 $sql .=
", min_desired";
821 $sql .=
", state_id";
824 $sql .=
", ics_transfer";
825 $sql .=
") VALUES (";
826 $sql .=
"'".$this->db->idate($now).
"'";
827 $sql .=
", '".$this->db->escape($this->
ref).
"'";
828 $sql .=
", '".$this->db->escape($this->label).
"'";
829 $sql .=
", ".((int) $conf->entity);
830 $sql .=
", '".$this->db->escape($this->account_number).
"'";
831 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
832 $sql .=
", '".$this->db->escape($this->bank).
"'";
833 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
834 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
835 $sql .=
", '".$this->db->escape($this->number).
"'";
836 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
837 $sql .=
", '".$this->db->escape($this->bic).
"'";
838 $sql .=
", '".$this->db->escape($this->iban).
"'";
839 $sql .=
", '".$this->db->escape($this->
address).
"'";
840 $sql .=
", ".((int) $this->pti_in_ctti);
841 $sql .=
", '".$this->db->escape($this->owner_name).
"'";
842 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
843 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
844 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
845 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
846 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
847 $sql .=
", ".((int) $this->rappro);
848 $sql .=
", ".price2num($this->min_allowed,
'MT');
849 $sql .=
", ".price2num($this->min_desired,
'MT');
850 $sql .=
", '".$this->db->escape($this->comment).
"'";
851 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
852 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
853 $sql .=
", '".$this->db->escape($this->ics).
"'";
854 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
857 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
858 $resql = $this->db->query($sql);
860 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
862 $result = $this->
update($user, 1);
865 $accline->datec = $now;
866 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
867 $accline->amount = (float)
price2num($balance);
868 $accline->fk_user_author = $user->id;
869 $accline->fk_account = $this->id;
870 $accline->datev = $this->date_solde;
871 $accline->dateo = $this->date_solde;
872 $accline->fk_type =
'SOLD';
874 if ($accline->insert() < 0) {
886 if (!$error && !$notrigger) {
888 $result = $this->call_trigger(
'BANKACCOUNT_CREATE', $user);
898 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
899 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
902 $this->
error = $this->db->error().
" sql=".$sql;
911 $this->db->rollback();
923 public function update($user, $notrigger = 0)
925 global $langs, $conf;
927 if (empty($this->country_id) && !empty($this->country_code)) {
928 $country_id =
getCountry($this->country_code,
'3');
929 $this->country_id = is_int($country_id) ? $country_id : 0;
937 if (empty($this->country_id)) {
938 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
942 if (empty($this->
ref)) {
943 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
948 $this->label =
"???";
951 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
952 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
953 $sql .=
",label = '".$this->db->escape($this->label).
"'";
954 $sql .=
",courant = ".((int) $this->
type);
955 $sql .=
",clos = ".((int) $this->
status);
956 $sql .=
",rappro = ".((int) $this->rappro);
957 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
958 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
959 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
960 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
961 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
962 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
963 $sql .=
",number='".$this->db->escape($this->number).
"'";
964 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
965 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
966 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
967 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
968 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
969 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
970 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
971 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
972 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
973 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
975 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
977 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
978 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
979 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
981 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
982 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
983 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
984 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
986 $sql .=
" WHERE rowid = ".((int) $this->
id);
988 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
989 $result = $this->db->query($sql);
999 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
1000 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
1001 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type = 'bank_account' and entity = ".((int) $conf->entity);
1002 $resql = $this->db->query($sql);
1005 $this->
error = $this->db->lasterror();
1011 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
1012 $dirdest = $conf->bank->dir_output.
'/'.$newref;
1013 if (file_exists($dirsource)) {
1014 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
1015 if (@rename($dirsource, $dirdest)) {
1021 if (!$error && !$notrigger) {
1023 $result = $this->call_trigger(
'BANKACCOUNT_MODIFY', $user);
1031 $this->
error = $this->db->lasterror();
1036 $this->db->commit();
1039 $this->db->rollback();
1055 global $conf, $langs;
1058 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1060 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1064 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1068 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1069 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1070 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1071 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1072 $sql .=
",number='".$this->db->escape($this->number).
"'";
1073 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1074 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1075 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1076 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
1077 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
1078 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1079 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1080 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1081 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1082 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1083 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1084 $sql .=
" WHERE rowid = ".((int) $this->
id);
1085 $sql .=
" AND entity = ".((int) $conf->entity);
1087 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1089 $result = $this->db->query($sql);
1093 $this->
error = $this->db->lasterror();
1109 if (empty($id) && empty($ref)) {
1110 $this->
error =
"ErrorBadParameters";
1114 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1115 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1116 $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,";
1117 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1118 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1119 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1120 $sql .=
' c.code as country_code, c.label as country,';
1121 $sql .=
' d.code_departement as state_code, d.nom as state,';
1122 $sql .=
' aj.code as accountancy_journal';
1123 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1124 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1125 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1126 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1127 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1129 $sql .=
" AND ba.rowid = ".((int) $id);
1132 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1135 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1136 $result = $this->db->query($sql);
1138 if ($this->db->num_rows($result)) {
1139 $obj = $this->db->fetch_object($result);
1141 $this->
id = $obj->rowid;
1142 $this->rowid = $obj->rowid;
1143 $this->
ref = $obj->ref;
1144 $this->label = $obj->label;
1145 $this->
type = $obj->type;
1146 $this->courant = $obj->type;
1147 $this->bank = $obj->bank;
1148 $this->clos = $obj->status;
1149 $this->
status = $obj->status;
1150 $this->rappro = $obj->rappro;
1151 $this->url = $obj->url;
1153 $this->code_banque = $obj->code_banque;
1154 $this->code_guichet = $obj->code_guichet;
1155 $this->number = $obj->number;
1156 $this->cle_rib = $obj->cle_rib;
1157 $this->bic = $obj->bic;
1158 $this->iban = $obj->iban;
1159 $this->
address = $obj->address;
1161 $this->owner_name = $obj->owner_name;
1162 $this->proprio = $this->owner_name;
1163 $this->owner_address = $obj->owner_address;
1164 $this->owner_zip = $obj->owner_zip;
1165 $this->owner_town = $obj->owner_town;
1166 $this->owner_country_id = $obj->owner_country_id;
1168 $this->pti_in_ctti = $obj->pti_in_ctti;
1170 $this->state_id = $obj->state_id;
1171 $this->state_code = $obj->state_code;
1172 $this->state = $obj->state;
1174 $this->country_id = $obj->country_id;
1175 $this->country_code = $obj->country_code;
1176 $this->country = $obj->country;
1178 $this->account_number = $obj->account_number;
1179 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1180 $this->accountancy_journal = $obj->accountancy_journal;
1182 $this->currency_code = $obj->currency_code;
1183 $this->account_currency_code = $obj->currency_code;
1184 $this->min_allowed = $obj->min_allowed;
1185 $this->min_desired = $obj->min_desired;
1186 $this->comment = $obj->comment;
1188 $this->date_creation = $this->db->jdate($obj->date_creation);
1189 $this->date_modification = $this->db->jdate($obj->date_modification);
1191 $this->ics = $obj->ics;
1192 $this->ics_transfer = $obj->ics_transfer;
1203 $this->
error = $this->db->lasterror();
1204 $this->errors[] = $this->error;
1221 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1222 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1232 public function delete($user, $notrigger = 0)
1242 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1243 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1245 $resql = $this->db->query($sql);
1248 $this->
error =
"Error ".$this->db->lasterror();
1253 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1254 $sql .=
" WHERE rowid = ".((int) $this->
id);
1256 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1257 $result = $this->db->query($sql);
1264 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1269 $this->
error =
"Error ".$this->db->lasterror();
1274 $this->db->commit();
1277 $this->db->rollback();
1306 $langs->load(
'banks');
1308 if ($status == self::STATUS_OPEN) {
1309 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1310 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1311 $statusType =
'status4';
1313 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1314 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1315 $statusType =
'status5';
1318 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1331 $can_be_deleted =
false;
1333 $sql =
"SELECT COUNT(rowid) as nb";
1334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1335 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1337 $resql = $this->db->query($sql);
1339 $obj = $this->db->fetch_object($resql);
1340 if ($obj->nb <= 1) {
1341 $can_be_deleted =
true;
1346 return $can_be_deleted;
1357 return $this->error;
1368 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1372 $sql =
"SELECT sum(amount) as amount";
1373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1374 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1376 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1379 $resql = $this->db->query($sql);
1381 if ($this->db->num_rows($resql)) {
1382 $obj = $this->db->fetch_object($resql);
1383 $solde = $obj->amount;
1385 $this->db->free($resql);
1387 $this->errors[] = $this->db->lasterror;
1405 global $conf, $langs;
1411 $sql =
"SELECT b.rowid, b.datev as datefin";
1412 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1413 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1414 $sql .=
" WHERE b.rappro=0";
1415 $sql .=
" AND b.fk_account = ba.rowid";
1416 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1418 $sql .=
" AND clos = 0";
1419 if ($filteraccountid) {
1420 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1423 $resql = $this->db->query($sql);
1425 $langs->load(
"banks");
1428 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1431 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1432 $response->label = $langs->trans(
"TransactionsToConciliate");
1433 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1434 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1437 while ($obj = $this->db->fetch_object($resql)) {
1438 $response->nbtodo++;
1439 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1440 $response->nbtodolate++;
1447 $this->
error = $this->db->error();
1466 $sql =
"SELECT count(b.rowid) as nb";
1467 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1468 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1469 $sql .=
" WHERE b.fk_account = ba.rowid";
1470 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1471 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1472 $sql .=
" AND clos = 0";
1473 if ($filteraccountid) {
1474 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1477 $resql = $this->db->query($sql);
1479 while ($obj = $this->db->fetch_object($resql)) {
1480 $this->nb[
"banklines"] = $obj->nb;
1482 $this->db->free($resql);
1486 $this->
error = $this->db->error();
1508 $sql =
"SELECT COUNT(ba.rowid) as nb";
1509 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1510 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1511 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1516 $resql = $this->db->query($sql);
1518 $obj = $this->db->fetch_object($resql);
1519 $nb = (int) $obj->nb;
1538 $langs->loadLangs([
'banks',
'compta']);
1539 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1543 $nofetch = !empty($params[
'nofetch']);
1544 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1545 if (isset($this->
status)) {
1546 $pictos .=
' '.$this->getLibStatut(5);
1548 $datas[
'picto'] = $pictos;
1549 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1550 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1551 $datas[
'accountnumber'] =
'<br><br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1553 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1554 $datas[
'accountcurrency'] =
'<br><br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1557 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1558 $langs->load(
"accountancy");
1559 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1560 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1564 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1565 $form =
new Form($this->db);
1566 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1583 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1585 global $conf, $langs;
1587 if (!empty($conf->dol_no_mouse_hover)) {
1591 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1594 $classfortooltip =
'classfortooltip';
1598 'objecttype' => $this->element,
1599 'option' => $option,
1603 $classfortooltip =
'classforajaxtooltip';
1604 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1610 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1611 if ($mode ==
'transactions') {
1612 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1613 } elseif ($mode ==
'receipts') {
1614 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1617 if ($option !=
'nolink') {
1619 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1620 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1621 $add_save_lastsearch_values = 1;
1623 if ($add_save_lastsearch_values) {
1624 $url .=
'&save_lastsearch_values=1';
1629 if (empty($notooltip)) {
1631 $label = $langs->trans(
"BankAccount");
1632 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1634 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1635 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1637 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1640 if ($option ==
'nolink' || empty($url)) {
1641 $linkstart =
'<span';
1643 $linkstart =
'<a href="'.$url.
'"';
1645 $linkstart .= $linkclose.
'>';
1646 if ($option ==
'nolink' || empty($url)) {
1647 $linkend =
'</span>';
1652 $result .= $linkstart;
1655 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1657 if ($withpicto != 2) {
1658 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1660 $result .= $linkend;
1676 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1683 $this->
error =
'IBANNotValid';
1689 $this->
error =
'SwiftNotValid';
1709 if (!empty($this->country_code)) {
1710 return $this->country_code;
1714 if (!empty($this->iban)) {
1717 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1723 if (!empty($this->socid)) {
1724 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1725 $company =
new Societe($this->db);
1726 $result = $company->fetch($this->socid);
1727 if (!empty($company->country_code)) {
1728 return $company->country_code;
1733 if (!empty(
$mysoc->country_code)) {
1734 return $mysoc->country_code;
1749 global $conf, $langs;
1756 if (!empty($conf->use_javascript_ajax)) {
1758 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1759 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1762 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1782 public function useDetailedBBAN()
1784 $country_code = $this->getCountryCode();
1786 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1787 return 1; // France, Spain, Gabon, ... - Not valid for CH
1789 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1790 return 2; // Australia, England...
1800 public function needIBAN()
1804 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1808 $country_code = $this->getCountryCode();
1810 $country_code_in_EEC = array(
1815 'CZ', // Czech republic
1822 'GB', // United Kingdom
1828 'IM', // Isle of Man - Included in UK
1833 'MC', // Monaco - Included in France
1842 'UK', // United Kingdom
1843 //'CH', // Switzerland - No. Swizerland in not in EEC
1846 if (in_array($country_code, $country_code_in_EEC)) {
1847 return 1; // France, Spain, ...
1857 public function needBIC()
1859 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1863 $country_code = $this->getCountryCode();
1865 $country_code_in_EEC = array(
1877 if (in_array($country_code, $country_code_in_EEC)) {
1878 return 1; // Andorra, Bahrein, ...
1889 public function info($id)
1907 public function getFieldsToShow($includeibanbic = 0)
1909 //Get the required properties depending on the country
1910 $detailedBBAN = $this->useDetailedBBAN();
1912 if ($detailedBBAN == 0) {
1913 $fieldarray = array(
1916 } elseif ($detailedBBAN == 2) {
1917 $fieldarray = array(
1922 $fieldarray = self::getAccountNumberOrder();
1925 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1926 if ($includeibanbic) {
1927 $fieldarray[] = 'IBAN';
1928 $fieldarray[] = 'BIC';
1932 //Get the order the properties are shown
1946 public static function getAccountNumberOrder()
1950 $fieldlists = array(
1953 'BankAccountNumber',
1954 'BankAccountNumberKey'
1957 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1958 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1959 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1960 $fieldlists = array(
1963 'BankAccountNumberKey',
1968 //Replace the old AccountNumber key with the new BankAccountNumber key
1969 $fieldlists = explode(
1971 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1987 public function initAsSpecimen()
1989 // Example of IBAN FR7630001007941234567890185
1990 $this->specimen = 1;
1992 $this->label = 'My Big Company Bank account';
1993 $this->clos = Account::STATUS_OPEN;
1994 $this->type = Account::TYPE_CURRENT;
1995 $this->status = Account::STATUS_OPEN;
1996 $this->code_banque = '30001';
1997 $this->code_guichet = '00794';
1998 $this->number = '12345678901';
1999 $this->cle_rib = '85';
2000 $this->bic = 'AA12';
2001 $this->iban = 'FR7630001007941234567890185';
2003 $this->bank = 'MyBank';
2004 $this->address = 'Rue de Paris';
2005 $this->owner_name = 'Owner';
2006 $this->owner_address = 'Owner address';
2007 $this->owner_zip = 'Owner zip';
2008 $this->owner_town = 'Owner town';
2009 $this->owner_country_id = 1;
2010 $this->country_id = 1;
2023 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2025 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type =
'company'";
2027 if ($dbs->query($sql)) {
2030 //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.
2031 //$this->errors = $dbs->lasterror();
2043 public function getKanbanView($option = '', $arraydata = null)
2047 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2049 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2050 $return .= '<div class="info-box
info-box-sm
">';
2051 $return .= '<span class="info-box-icon bg-infobox-action
">';
2052 $return .= img_picto('', $this->picto);
2053 $return .= '</span>';
2054 $return .= '<div class="info-box-content
">';
2055 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2056 if ($selected >= 0) {
2057 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2059 if (property_exists($this, 'type_lib')) {
2060 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2062 if (method_exists($this, 'solde')) {
2063 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2064 $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>';
2066 if (method_exists($this, 'getLibStatut')) {
2067 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2069 $return .= '</div>';
2070 $return .= '</div>';
2071 $return .= '</div>';
2077require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2082class AccountLine extends CommonObjectLine
2092 public $element = 'bank';
2097 public $table_element = 'bank';
2102 public $picto = 'accountline';
2143 public $amount_main_currency;
2148 public $fk_user_author;
2153 public $fk_user_rappro;
2163 public $fk_bordereau;
2173 public $bank_account_ref;
2178 public $bank_account_label;
2183 public $numero_compte;
2225 public $user_rappro;
2233 public function __construct(DoliDB $db)
2246 public function fetch($rowid, $ref = '', $num = '')
2249 if (empty($rowid) && empty($ref) && empty($num)) {
2253 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2254 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2255 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2256 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2257 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2258 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2259 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2260 $sql .= " WHERE b.fk_account = ba.rowid
";
2261 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2263 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2265 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2267 $sql .= " AND b.rowid =
".((int) $rowid);
2270 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2271 $result = $this->db->query($sql);
2275 $obj = $this->db->fetch_object($result);
2277 $this->id = $obj->rowid;
2278 $this->rowid = $obj->rowid;
2279 $this->ref = $obj->rowid;
2281 $this->datec = $this->db->jdate($obj->datec);
2282 $this->datev = $this->db->jdate($obj->datev);
2283 $this->dateo = $this->db->jdate($obj->dateo);
2284 $this->amount = $obj->amount;
2285 $this->label = $obj->label;
2286 $this->note = $obj->note;
2288 $this->fk_user_author = $obj->fk_user_author;
2289 $this->fk_user_rappro = $obj->fk_user_rappro;
2291 $this->fk_type = $obj->fk_type; // Type of transaction
2292 $this->rappro = (int) $obj->rappro;
2293 $this->num_releve = $obj->num_releve;
2295 $this->num_chq = $obj->num_chq;
2296 $this->bank_chq = $obj->banque;
2297 $this->fk_bordereau = $obj->fk_bordereau;
2299 $this->fk_account = $obj->fk_account;
2300 $this->bank_account_ref = $obj->bank_account_ref;
2301 $this->bank_account_label = $obj->bank_account_label;
2303 // Retrieve all extrafield
2304 // fetch optionals attributes and labels
2305 $this->fetch_optionals();
2309 $this->db->free($result);
2321 public function insert()
2327 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2333 $sql .= ", amount_main_currency
";
2334 $sql .= ", fk_user_author
";
2335 $sql .= ", num_chq
";
2336 $sql .= ", fk_account
";
2337 $sql .= ", fk_type
";
2338 $sql .= ", emetteur,banque
";
2340 $sql .= ", numero_compte
";
2341 $sql .= ", num_releve
";
2343 $sql .= ") VALUES (
";
2344 $sql .= "'".$this->db->idate($this->datec)."'";
2345 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2346 $sql .= ",
'".$this->db->idate($this->datev)."'";
2347 $sql .= ",
'".$this->db->escape($this->label)."'";
2348 $sql .= ",
".price2num($this->amount);
2349 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2350 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2351 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2352 $sql .= ",
'".$this->db->escape((string) $this->fk_account)."'";
2353 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2354 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2355 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2356 $sql .= ",
".(int) $this->rappro;
2357 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2358 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2359 $sql .= ",
".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2363 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2364 $resql = $this->db->query($sql);
2366 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2367 // Actions on extra fields (by external module or standard code)
2368 $result = $this->insertExtraFields();
2374 $this->error = $this->db->lasterror();
2375 dol_print_error($this->db);
2379 $this->db->commit();
2382 $this->db->rollback();
2394 public function delete($user, $notrigger = 0)
2398 if ($this->rappro) {
2399 // Protection to avoid any delete of consolidated lines
2400 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2408 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2410 $this->db->rollback();
2413 // End call triggers
2416 // Protection to avoid any delete of accounted lines. Protection on by default
2417 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2418 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2419 $resql = $this->db->query($sql);
2421 $obj = $this->db->fetch_object($resql);
2422 if ($obj && $obj->nb) {
2423 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2424 $this->db->rollback();
2428 $this->error = $this->db->lasterror();
2429 $this->db->rollback();
2435 $result = $this->delete_urls($user);
2440 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2441 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2442 $result = $this->db->query($sql);
2447 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2448 $result = $this->db->query($sql);
2453 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2454 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2455 $result = $this->db->query($sql);
2461 $this->db->commit();
2464 $this->db->rollback();
2470 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2477 public function delete_urls($user = null)
2482 if ($this->rappro) {
2483 // Protection to avoid any delete of consolidated lines
2484 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2490 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2491 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2492 $result = $this->db->query($sql);
2498 $this->db->commit();
2501 $this->db->rollback();
2514 public function update(User $user, $notrigger = 0)
2518 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2519 $sql .= " amount =
".price2num($this->amount).",
";
2520 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2521 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2522 $sql .= " WHERE rowid =
".((int) $this->rowid);
2524 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2525 $resql = $this->db->query($sql);
2527 $this->db->commit();
2530 $this->db->rollback();
2531 $this->error = $this->db->error();
2542 public function updateLabel()
2546 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2547 $sql .= " label =
'".$this->db->escape($this->label)."'";
2548 $sql .= " WHERE rowid =
".((int) $this->rowid);
2550 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2551 $resql = $this->db->query($sql);
2553 $this->db->commit();
2556 $this->db->rollback();
2557 $this->error = $this->db->error();
2563 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2572 public function update_conciliation(User $user, $cat, $conciliated = 1)
2575 global $conf, $langs;
2579 // Check statement field
2580 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2581 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2582 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2587 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2588 $sql .= " rappro =
".((int) $conciliated);
2589 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2591 $sql .= ", fk_user_rappro =
".((int) $user->id);
2593 $sql .= " WHERE rowid =
".((int) $this->id);
2595 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2596 $resql = $this->db->query($sql);
2598 if (!empty($cat) && $cat > 0) {
2599 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2601 $sql .= ", fk_categ
";
2602 $sql .= ") VALUES (
";
2604 $sql .= ",
".((int) $cat);
2607 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2608 $this->db->query($sql);
2610 // No error check. Can fail if category already affected
2611 // TODO Do no try the insert if link already exists
2614 $this->rappro = (int) $conciliated;
2616 $this->db->commit();
2619 $this->db->rollback();
2625 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2633 public function datev_change($rowid, $sign = 1)
2636 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2637 $resql = $this->db->query($sql);
2639 $obj = $this->db->fetch_object($resql);
2640 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2642 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2643 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2644 $sql .= " WHERE rowid =
".((int) $rowid);
2646 $result = $this->db->query($sql);
2648 if ($this->db->affected_rows($result)) {
2652 dol_print_error($this->db);
2656 dol_print_error($this->db);
2661 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2668 public function datev_next($id)
2671 return $this->datev_change($id, 1);
2674 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2681 public function datev_previous($id)
2684 return $this->datev_change($id, -1);
2688 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2696 public function dateo_change($rowid, $sign = 1)
2699 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2700 $resql = $this->db->query($sql);
2702 $obj = $this->db->fetch_object($resql);
2703 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2705 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2706 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2707 $sql .= " WHERE rowid =
".((int) $rowid);
2709 $result = $this->db->query($sql);
2711 if ($this->db->affected_rows($result)) {
2715 dol_print_error($this->db);
2719 dol_print_error($this->db);
2724 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2731 public function dateo_next($id)
2734 return $this->dateo_change($id, 1);
2737 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2744 public function dateo_previous($id)
2747 return $this->dateo_change($id, -1);
2757 public function info($id)
2759 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2760 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2761 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2762 $sql .= ' WHERE b.rowid = '.((int) $id);
2764 $result = $this->db->query($sql);
2766 if ($this->db->num_rows($result)) {
2767 $obj = $this->db->fetch_object($result);
2769 $this->id = $obj->rowid;
2771 $this->user_creation_id = $obj->fk_user_author;
2772 $this->user_rappro = $obj->fk_user_rappro;
2773 $this->date_creation = $this->db->jdate($obj->datec);
2774 $this->date_modification = $this->db->jdate($obj->datem);
2775 //$this->date_rappro = $obj->daterappro; // Not yet managed
2777 $this->db->free($result);
2779 dol_print_error($this->db);
2793 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2795 global $conf, $langs;
2799 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2800 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2801 if ($this->amount) {
2802 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2805 $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
">';
2808 $result .= $linkstart;
2810 $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);
2812 if ($withpicto != 2) {
2813 $result .= ($this->ref ? $this->ref : $this->id);
2816 $result .= $linkend;
2818 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2819 $result .= ' <span class="opacitymedium
">(';
2821 if ($option == 'showall') {
2822 $result .= $langs->trans("BankAccount
").': ';
2823 $accountstatic = new Account($this->db);
2824 $accountstatic->id = $this->fk_account;
2825 $accountstatic->ref = $this->bank_account_ref;
2826 $accountstatic->label = $this->bank_account_label;
2827 $result .= $accountstatic->getNomUrl(0).', ';
2829 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2830 $result .= $langs->trans("BankLineConciliated
").': ';
2831 $result .= yn($this->rappro);
2833 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2834 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2835 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2836 $resql = $this->db->query($sql);
2838 $obj = $this->db->fetch_object($resql);
2839 if ($obj && $obj->nb) {
2840 $result .= ' - '.$langs->trans("Accounted
").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2842 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2846 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2847 $result .= ')</span>';
2860 public function getLibStatut($mode = 0)
2862 return $this->LibStatut($this->status, $mode);
2865 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2873 public function LibStatut($status, $mode = 0)
2885 public function getVentilExportCompta($mode = 0)
2887 $alreadydispatched = 0;
2891 $sql = " SELECT
".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb
";
2892 $sql .= " FROM
".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type =
'".$this->db->escape($type)."' AND ab.fk_doc =
".((int) $this->id);
2893 $resql = $this->db->query($sql);
2895 $obj = $this->db->fetch_object($resql);
2897 $alreadydispatched = $obj->nb;
2900 $this->error = $this->db->lasterror();
2904 if ($alreadydispatched) {
2905 return $alreadydispatched;
if(! $sortfield) if(! $sortorder) $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.
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.
dol_now($mode='gmt')
Return date for now.
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...