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';
105 public $clos = self::STATUS_OPEN;
129 public $code_guichet;
167 public $pti_in_ctti = 0;
187 public $owner_address;
203 public $owner_country_id;
207 public $owner_country_code;
215 public $domiciliation;
244 public $type_lib = array();
250 public $account_number;
255 public $fk_accountancy_journal;
260 public $accountancy_journal;
266 public $currency_code;
274 public $account_currency_code;
324 public $ics_transfer;
360 public $fields = array(
361 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
362 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 25),
363 'label' => array(
'type' =>
'varchar(30)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
364 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 35,
'index' => 1),
365 'bank' => array(
'type' =>
'varchar(60)',
'label' =>
'Bank',
'enabled' => 1,
'visible' => -1,
'position' => 40),
366 'code_banque' => array(
'type' =>
'varchar(128)',
'label' =>
'Code banque',
'enabled' => 1,
'visible' => -1,
'position' => 45),
367 'code_guichet' => array(
'type' =>
'varchar(6)',
'label' =>
'Code guichet',
'enabled' => 1,
'visible' => -1,
'position' => 50),
368 'number' => array(
'type' =>
'varchar(255)',
'label' =>
'Number',
'enabled' => 1,
'visible' => -1,
'position' => 55),
369 'cle_rib' => array(
'type' =>
'varchar(5)',
'label' =>
'Cle rib',
'enabled' => 1,
'visible' => -1,
'position' => 60),
370 'bic' => array(
'type' =>
'varchar(11)',
'label' =>
'Bic',
'enabled' => 1,
'visible' => -1,
'position' => 65),
371 'iban_prefix' => array(
'type' =>
'varchar(34)',
'label' =>
'Iban prefix',
'enabled' => 1,
'visible' => -1,
'position' => 70),
372 'country_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Country iban',
'enabled' => 1,
'visible' => -1,
'position' => 75),
373 'cle_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Cle iban',
'enabled' => 1,
'visible' => -1,
'position' => 80),
374 'domiciliation' => array(
'type' =>
'varchar(255)',
'label' =>
'Domiciliation',
'enabled' => 1,
'visible' => -1,
'position' => 85),
375 'state_id' => array(
'type' =>
'integer',
'label' =>
'StateId',
'enabled' => 1,
'visible' => -1,
'position' => 90),
376 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 95),
377 'proprio' => array(
'type' =>
'varchar(60)',
'label' =>
'Proprio',
'enabled' => 1,
'visible' => -1,
'position' => 100),
378 'owner_address' => array(
'type' =>
'varchar(255)',
'label' =>
'Owner address',
'enabled' => 1,
'visible' => -1,
'position' => 105),
379 'owner_zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Owner zip',
'enabled' => 1,
'visible' => -1,
'position' => 106),
380 'owner_town' => array(
'type' =>
'varchar(50)',
'label' =>
'Owner town',
'enabled' => 1,
'visible' => -1,
'position' => 107),
381 'owner_country_id' => array(
'type' =>
'integer',
'label' =>
'Owner country',
'enabled' => 1,
'visible' => -1,
'position' => 108),
382 'courant' => array(
'type' =>
'smallint(6)',
'label' =>
'Courant',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 110),
383 'clos' => array(
'type' =>
'smallint(6)',
'label' =>
'Clos',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 115),
384 'rappro' => array(
'type' =>
'smallint(6)',
'label' =>
'Rappro',
'enabled' => 1,
'visible' => -1,
'position' => 120),
385 'url' => array(
'type' =>
'varchar(128)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 125),
386 'account_number' => array(
'type' =>
'varchar(32)',
'label' =>
'Account number',
'enabled' => 1,
'visible' => -1,
'position' => 130),
387 'fk_accountancy_journal' => array(
'type' =>
'integer',
'label' =>
'Accountancy journal ID',
'enabled' => 1,
'visible' => -1,
'position' => 132),
388 'accountancy_journal' => array(
'type' =>
'varchar(20)',
'label' =>
'Accountancy journal',
'enabled' => 1,
'visible' => -1,
'position' => 135),
389 'currency_code' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency code',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 140),
390 'min_allowed' => array(
'type' =>
'integer',
'label' =>
'Min allowed',
'enabled' => 1,
'visible' => -1,
'position' => 145),
391 'min_desired' => array(
'type' =>
'integer',
'label' =>
'Min desired',
'enabled' => 1,
'visible' => -1,
'position' => 150),
392 'comment' => array(
'type' =>
'text',
'label' =>
'Comment',
'enabled' => 1,
'visible' => -1,
'position' => 155),
393 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 156),
394 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 157),
395 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 160),
396 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 165),
397 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 170),
398 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 175),
399 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 180),
400 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 185),
418 const STATUS_OPEN = 0;
419 const STATUS_CLOSED = 1;
433 $this->ismultientitymanaged = 1;
437 $this->type_lib = array(
438 self::TYPE_SAVINGS => $langs->transnoentitiesnoconv(
"BankType0"),
439 self::TYPE_CURRENT => $langs->transnoentitiesnoconv(
"BankType1"),
440 self::TYPE_CASH => $langs->transnoentitiesnoconv(
"BankType2"),
443 $this->labelStatus = array(
444 self::STATUS_OPEN => $langs->transnoentitiesnoconv(
"StatusAccountOpened"),
445 self::STATUS_CLOSED => $langs->transnoentitiesnoconv(
"StatusAccountClosed")
458 if ($val ==
'BankCode') {
459 $string .= $this->code_banque.
' ';
460 } elseif ($val ==
'BankAccountNumber') {
461 $string .= $this->number.
' ';
462 } elseif ($val ==
'DeskCode') {
463 $string .= $this->code_guichet.
' ';
464 } elseif ($val ==
'BankAccountNumberKey') {
465 $string .= $this->cle_rib.
' ';
466 } elseif ($val ==
'BIC') {
467 $string .= $this->bic.
' ';
468 } elseif ($val ==
'IBAN') {
469 $string .= $this->iban.
' ';
473 return trim($string);
484 if (empty($this->rappro)) {
513 $sqlcheck =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"bank_url";
514 $sqlcheck .=
" WHERE fk_bank = ".((int) $line_id);
515 $sqlcheck .=
" AND url_id = ".((int) $url_id);
516 $sqlcheck .=
" AND type = '".$this->db->escape($type).
"'";
517 $resqlcheck = $this->db->query($sqlcheck);
519 $obj = $this->db->fetch_object($resqlcheck);
521 $this->db->free($resqlcheck);
522 return (
int) $obj->rowid;
524 $this->db->free($resqlcheck);
527 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
533 $sql .=
") VALUES (";
534 $sql .= ((int) $line_id);
535 $sql .=
", ".((int) $url_id);
536 $sql .=
", '".$this->db->escape($url).
"'";
537 $sql .=
", '".$this->db->escape($label).
"'";
538 $sql .=
", '".$this->db->escape($type).
"'";
541 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
542 if ($this->db->query($sql)) {
543 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
546 $this->
error = $this->db->lasterror();
561 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
567 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
568 $this->
error =
"ErrorBadParameter";
572 $sql =
"SELECT fk_bank, url_id, url, label, type";
573 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
575 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
577 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
579 $sql .=
" ORDER BY type, label";
581 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
582 $result = $this->db->query($sql);
585 $num = $this->db->num_rows($result);
587 $obj = $this->db->fetch_object($result);
589 $lines[$i][0] = $obj->url;
590 $lines[$i][1] = $obj->url_id;
591 $lines[$i][2] = $obj->label;
592 $lines[$i][3] = $obj->type;
594 $lines[$i][
'url'] = $obj->url;
595 $lines[$i][
'url_id'] = $obj->url_id;
596 $lines[$i][
'label'] = $obj->label;
597 $lines[$i][
'type'] = $obj->type;
598 $lines[$i][
'fk_bank'] = $obj->fk_bank;
627 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 =
'')
632 if (is_numeric($oper)) {
633 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
636 if (empty($this->
id) && !empty($this->rowid)) {
637 $this->
id = $this->rowid;
641 $emetteur = trim($emetteur);
642 $banque = trim($banque);
643 $label = trim($label);
647 if (is_numeric($oper)) {
648 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
649 $sql .=
" WHERE id = ".((int) $oper);
650 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
651 $resql = $this->db->query($sql);
653 $obj = $this->db->fetch_object($resql);
663 $this->
error = $langs->trans(
"OperNotDefined");
667 $this->
error = $langs->trans(
"ThisIdNotDefined");
671 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
677 if (is_null($datev) || empty($datev)) {
682 $accline->datec = $now;
683 $accline->dateo = $date;
684 $accline->datev = $datev;
685 $accline->label = $label;
686 $accline->amount = $amount;
687 $accline->amount_main_currency = $amount_main_currency;
688 $accline->fk_user_author = $user->id;
689 $accline->fk_account = $this->id;
690 $accline->fk_type = $oper;
691 $accline->numero_compte = $accountancycode;
692 $accline->num_releve = $num_releve;
693 $accline->note_private = $note_private;
696 $accline->num_chq = $num_chq;
700 $accline->emetteur = $emetteur;
704 $accline->bank_chq = $banque;
707 if ($accline->insert() > 0) {
708 if ($categorie > 0) {
709 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bankline(";
710 $sql .=
"lineid, fk_categ";
711 $sql .=
") VALUES (";
712 $sql .= ((int) $accline->id).
", ".((int) $categorie);
715 $result = $this->db->query($sql);
717 $this->
error = $this->db->lasterror();
718 $this->db->rollback();
729 $this->db->rollback();
742 public function create($user, $notrigger = 0)
744 global $langs,
$conf;
749 if (!$this->min_allowed) {
750 $this->min_allowed = 0;
752 if (!$this->min_desired) {
753 $this->min_desired = 0;
757 if (empty($this->country_id)) {
758 $langs->load(
'errors');
759 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
763 if (empty($this->
ref)) {
764 $langs->load(
'errors');
765 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
769 if (empty($this->date_solde)) {
770 $langs->load(
'errors');
771 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
777 $balance = $this->balance;
778 if (empty($balance) && !empty($this->
solde)) {
779 dol_syslog(get_class($this).
"::create solde is deprecated use balance", LOG_NOTICE);
780 $balance = $this->solde;
782 if (empty($balance)) {
785 if (empty($this->
status && !empty($this->clos))) {
786 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
787 $this->
status = $this->clos;
790 if (empty($this->country_id) && !empty($this->country_code)) {
791 $country_id =
getCountry($this->country_code,
'3');
792 $this->country_id = is_int($country_id) ? $country_id : 0;
796 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
802 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
807 $sql .=
", account_number";
808 $sql .=
", fk_accountancy_journal";
810 $sql .=
", code_banque";
811 $sql .=
", code_guichet";
815 $sql .=
", iban_prefix";
816 $sql .=
", domiciliation";
817 $sql .=
", pti_in_ctti";
819 $sql .=
", owner_address";
820 $sql .=
", owner_zip";
821 $sql .=
", owner_town";
822 $sql .=
", owner_country_id";
823 $sql .=
", currency_code";
825 $sql .=
", min_allowed";
826 $sql .=
", min_desired";
828 $sql .=
", state_id";
831 $sql .=
", ics_transfer";
832 $sql .=
") VALUES (";
833 $sql .=
"'".$this->db->idate($now).
"'";
834 $sql .=
", '".$this->db->escape($this->
ref).
"'";
835 $sql .=
", '".$this->db->escape($this->label).
"'";
836 $sql .=
", ".((int)
$conf->entity);
837 $sql .=
", '".$this->db->escape($this->account_number).
"'";
838 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
839 $sql .=
", '".$this->db->escape($this->bank).
"'";
840 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
841 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
842 $sql .=
", '".$this->db->escape($this->number).
"'";
843 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
844 $sql .=
", '".$this->db->escape($this->bic).
"'";
845 $sql .=
", '".$this->db->escape($this->iban).
"'";
846 $sql .=
", '".$this->db->escape($this->
address).
"'";
847 $sql .=
", ".((int) $this->pti_in_ctti);
848 $sql .=
", '".$this->db->escape($this->owner_name).
"'";
849 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
850 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
851 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
852 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
853 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
854 $sql .=
", ".((int) $this->rappro);
855 $sql .=
", ".price2num($this->min_allowed,
'MT');
856 $sql .=
", ".price2num($this->min_desired,
'MT');
857 $sql .=
", '".$this->db->escape($this->comment).
"'";
858 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
859 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
860 $sql .=
", '".$this->db->escape($this->ics).
"'";
861 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
864 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
865 $resql = $this->db->query($sql);
867 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
869 $result = $this->
update($user, 1);
872 $accline->datec = $now;
873 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
874 $accline->amount = (float)
price2num($balance);
875 $accline->fk_user_author = $user->id;
876 $accline->fk_account = $this->id;
877 $accline->datev = $this->date_solde;
878 $accline->dateo = $this->date_solde;
879 $accline->fk_type =
'SOLD';
881 if ($accline->insert() < 0) {
893 if (!$error && !$notrigger) {
895 $result = $this->call_trigger(
'BANKACCOUNT_CREATE', $user);
905 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
906 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
909 $this->
error = $this->db->error().
" sql=".$sql;
918 $this->db->rollback();
930 public function update($user, $notrigger = 0)
932 global $langs,
$conf;
934 if (empty($this->country_id) && !empty($this->country_code)) {
935 $country_id =
getCountry($this->country_code,
'3');
936 $this->country_id = is_int($country_id) ? $country_id : 0;
944 if (empty($this->country_id)) {
945 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
949 if (empty($this->
ref)) {
950 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
955 $this->label =
"???";
958 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
959 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
960 $sql .=
",label = '".$this->db->escape($this->label).
"'";
961 $sql .=
",courant = ".((int) $this->
type);
962 $sql .=
",clos = ".((int) $this->
status);
963 $sql .=
",rappro = ".((int) $this->rappro);
964 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
965 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
966 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
967 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
968 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
969 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
970 $sql .=
",number='".$this->db->escape($this->number).
"'";
971 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
972 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
973 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
974 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
975 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
976 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
977 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
978 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
979 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
980 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
982 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
984 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
985 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
986 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
988 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
989 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
990 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
991 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
993 $sql .=
" WHERE rowid = ".((int) $this->
id);
995 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
996 $result = $this->db->query($sql);
1006 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
1007 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
1008 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type = 'bank_account' and entity = ".((int)
$conf->entity);
1009 $resql = $this->db->query($sql);
1012 $this->
error = $this->db->lasterror();
1018 $dirsource =
$conf->bank->dir_output.
'/'.$oldref;
1019 $dirdest =
$conf->bank->dir_output.
'/'.$newref;
1020 if (file_exists($dirsource)) {
1021 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
1022 if (@rename($dirsource, $dirdest)) {
1028 if (!$error && !$notrigger) {
1030 $result = $this->call_trigger(
'BANKACCOUNT_MODIFY', $user);
1038 $this->
error = $this->db->lasterror();
1043 $this->db->commit();
1046 $this->db->rollback();
1062 global
$conf, $langs;
1065 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1067 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1071 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1075 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1076 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1077 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1078 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1079 $sql .=
",number='".$this->db->escape($this->number).
"'";
1080 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1081 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1082 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1083 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
1084 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
1085 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1086 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1087 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1088 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1089 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
1090 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
1091 $sql .=
" WHERE rowid = ".((int) $this->
id);
1092 $sql .=
" AND entity = ".((int)
$conf->entity);
1094 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1096 $result = $this->db->query($sql);
1100 $this->
error = $this->db->lasterror();
1116 if (empty($id) && empty($ref)) {
1117 $this->
error =
"ErrorBadParameters";
1121 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1122 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1123 $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,";
1124 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1125 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1126 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1127 $sql .=
' c.code as country_code, c.label as country,';
1128 $sql .=
' d.code_departement as state_code, d.nom as state,';
1129 $sql .=
' aj.code as accountancy_journal';
1130 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1131 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1132 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1133 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1134 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1136 $sql .=
" AND ba.rowid = ".((int) $id);
1139 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1142 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1143 $result = $this->db->query($sql);
1145 if ($this->db->num_rows($result)) {
1146 $obj = $this->db->fetch_object($result);
1148 $this->
id = $obj->rowid;
1149 $this->rowid = $obj->rowid;
1150 $this->
ref = $obj->ref;
1151 $this->label = $obj->label;
1152 $this->
type = $obj->type;
1153 $this->courant = $obj->type;
1154 $this->bank = $obj->bank;
1155 $this->clos = $obj->status;
1156 $this->
status = $obj->status;
1157 $this->rappro = $obj->rappro;
1158 $this->url = $obj->url;
1160 $this->code_banque = $obj->code_banque;
1161 $this->code_guichet = $obj->code_guichet;
1162 $this->number = $obj->number;
1163 $this->cle_rib = $obj->cle_rib;
1164 $this->bic = $obj->bic;
1165 $this->iban = $obj->iban;
1166 $this->
address = $obj->address;
1168 $this->owner_name = $obj->owner_name;
1169 $this->proprio = $this->owner_name;
1170 $this->owner_address = $obj->owner_address;
1171 $this->owner_zip = $obj->owner_zip;
1172 $this->owner_town = $obj->owner_town;
1173 $this->owner_country_id = $obj->owner_country_id;
1175 $this->pti_in_ctti = $obj->pti_in_ctti;
1177 $this->state_id = $obj->state_id;
1178 $this->state_code = $obj->state_code;
1179 $this->state = $obj->state;
1181 $this->country_id = $obj->country_id;
1182 $this->country_code = $obj->country_code;
1183 $this->country = $obj->country;
1185 $this->account_number = $obj->account_number;
1186 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1187 $this->accountancy_journal = $obj->accountancy_journal;
1189 $this->currency_code = $obj->currency_code;
1190 $this->account_currency_code = $obj->currency_code;
1191 $this->min_allowed = $obj->min_allowed;
1192 $this->min_desired = $obj->min_desired;
1193 $this->comment = $obj->comment;
1195 $this->date_creation = $this->db->jdate($obj->date_creation);
1196 $this->date_modification = $this->db->jdate($obj->date_modification);
1198 $this->ics = $obj->ics;
1199 $this->ics_transfer = $obj->ics_transfer;
1210 $this->
error = $this->db->lasterror();
1211 $this->errors[] = $this->error;
1228 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1229 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1239 public function delete($user, $notrigger = 0)
1249 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1250 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1252 $resql = $this->db->query($sql);
1255 $this->
error =
"Error ".$this->db->lasterror();
1260 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1261 $sql .=
" WHERE rowid = ".((int) $this->
id);
1263 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1264 $result = $this->db->query($sql);
1271 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1276 $this->
error =
"Error ".$this->db->lasterror();
1281 $this->db->commit();
1284 $this->db->rollback();
1313 $langs->load(
'banks');
1315 if ($status == self::STATUS_OPEN) {
1316 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1317 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1318 $statusType =
'status4';
1320 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1321 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1322 $statusType =
'status5';
1325 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1338 $can_be_deleted =
false;
1340 $sql =
"SELECT COUNT(rowid) as nb";
1341 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1342 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1344 $resql = $this->db->query($sql);
1346 $obj = $this->db->fetch_object($resql);
1347 if ($obj->nb <= 1) {
1348 $can_be_deleted =
true;
1353 return $can_be_deleted;
1364 return $this->error;
1375 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1379 $sql =
"SELECT sum(amount) as amount";
1380 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1381 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1383 $sql .=
" AND ".$this->db->sanitize($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1386 $resql = $this->db->query($sql);
1388 if ($this->db->num_rows($resql)) {
1389 $obj = $this->db->fetch_object($resql);
1390 $solde = $obj->amount;
1392 $this->db->free($resql);
1394 $this->errors[] = $this->db->lasterror;
1412 global
$conf, $langs;
1418 $sql =
"SELECT b.rowid, b.datev as datefin";
1419 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1420 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1421 $sql .=
" WHERE b.rappro=0";
1422 $sql .=
" AND b.fk_account = ba.rowid";
1423 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1425 $sql .=
" AND clos = 0";
1426 if ($filteraccountid) {
1427 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1429 $resql = $this->db->query($sql);
1431 $langs->load(
"banks");
1434 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1437 $response->warning_delay =
$conf->bank->rappro->warning_delay / 60 / 60 / 24;
1438 $response->label = $langs->trans(
"TransactionsToConciliate");
1439 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1440 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1443 while ($obj = $this->db->fetch_object($resql)) {
1444 $response->nbtodo++;
1445 if ((
int) $this->db->jdate($obj->datefin) < ($now -
$conf->bank->rappro->warning_delay)) {
1446 $response->nbtodolate++;
1452 $this->
error = $this->db->error();
1471 $sql =
"SELECT count(b.rowid) as nb";
1472 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1473 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1474 $sql .=
" WHERE b.fk_account = ba.rowid";
1475 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1476 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1477 $sql .=
" AND clos = 0";
1478 if ($filteraccountid) {
1479 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1482 $resql = $this->db->query($sql);
1484 while ($obj = $this->db->fetch_object($resql)) {
1485 $this->nb[
"banklines"] = $obj->nb;
1487 $this->db->free($resql);
1491 $this->
error = $this->db->error();
1513 $sql =
"SELECT COUNT(ba.rowid) as nb";
1514 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1515 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1516 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1521 $resql = $this->db->query($sql);
1523 $obj = $this->db->fetch_object($resql);
1524 $nb = (int) $obj->nb;
1543 $langs->loadLangs([
'banks',
'compta']);
1544 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1548 $nofetch = !empty($params[
'nofetch']);
1549 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1550 if (isset($this->
status)) {
1551 $pictos .=
' '.$this->getLibStatut(5);
1553 $datas[
'picto'] = $pictos;
1554 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1555 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1556 $datas[
'accountnumber'] =
'<br><br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1558 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1559 $datas[
'accountcurrency'] =
'<br><br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1562 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1563 $langs->load(
"accountancy");
1564 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1565 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1569 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1570 $form =
new Form($this->db);
1571 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1588 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1590 global
$conf, $langs;
1592 if (!empty(
$conf->dol_no_mouse_hover)) {
1596 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1599 $classfortooltip =
'classfortooltip';
1603 'objecttype' => $this->element,
1604 'option' => $option,
1608 $classfortooltip =
'classforajaxtooltip';
1609 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1615 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1616 if ($mode ==
'transactions') {
1617 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1618 } elseif ($mode ==
'receipts') {
1619 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1622 if ($option !=
'nolink') {
1624 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1625 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1626 $add_save_lastsearch_values = 1;
1628 if ($add_save_lastsearch_values) {
1629 $url .=
'&save_lastsearch_values=1';
1634 if (empty($notooltip)) {
1636 $label = $langs->trans(
"BankAccount");
1637 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1639 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1640 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1642 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1645 if ($option ==
'nolink' || empty($url)) {
1646 $linkstart =
'<span';
1648 $linkstart =
'<a href="'.$url.
'"';
1650 $linkstart .= $linkclose.
'>';
1651 if ($option ==
'nolink' || empty($url)) {
1652 $linkend =
'</span>';
1657 $result .= $linkstart;
1660 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1662 if ($withpicto != 2) {
1663 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1665 $result .= $linkend;
1681 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1688 $this->
error =
'IBANNotValid';
1694 $this->
error =
'SwiftNotValid';
1714 if (!empty($this->country_code)) {
1715 return $this->country_code;
1719 if (!empty($this->iban)) {
1722 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1728 if (!empty($this->socid)) {
1729 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1730 $company =
new Societe($this->db);
1731 $result = $company->fetch($this->socid);
1732 if (!empty($company->country_code)) {
1733 return $company->country_code;
1738 if (!empty(
$mysoc->country_code)) {
1739 return $mysoc->country_code;
1754 global
$conf, $langs;
1761 if (!empty(
$conf->use_javascript_ajax)) {
1763 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1764 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1767 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1787 public function useDetailedBBAN()
1789 $country_code = $this->getCountryCode();
1791 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1792 return 1; // France, Spain, Gabon, ... - Not valid for CH
1794 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1795 return 2; // Australia, England...
1805 public function needIBAN()
1809 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1813 $country_code = $this->getCountryCode();
1815 $country_code_in_EEC = array(
1820 'CZ', // Czech republic
1827 'GB', // United Kingdom
1833 'IM', // Isle of Man - Included in UK
1838 'MC', // Monaco - Included in France
1847 'UK', // United Kingdom
1848 //'CH', // Switzerland - No. Swizerland in not in EEC
1851 if (in_array($country_code, $country_code_in_EEC)) {
1852 return 1; // France, Spain, ...
1862 public function needBIC()
1864 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1868 $country_code = $this->getCountryCode();
1870 $country_code_in_EEC = array(
1882 if (in_array($country_code, $country_code_in_EEC)) {
1883 return 1; // Andorra, Bahrein, ...
1894 public function info($id)
1912 public function getFieldsToShow($includeibanbic = 0)
1914 //Get the required properties depending on the country
1915 $detailedBBAN = $this->useDetailedBBAN();
1917 if ($detailedBBAN == 0) {
1918 $fieldarray = array(
1921 } elseif ($detailedBBAN == 2) {
1922 $fieldarray = array(
1927 $fieldarray = self::getAccountNumberOrder();
1930 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1931 if ($includeibanbic) {
1932 $fieldarray[] = 'IBAN';
1933 $fieldarray[] = 'BIC';
1937 //Get the order the properties are shown
1951 public static function getAccountNumberOrder()
1955 $fieldlists = array(
1958 'BankAccountNumber',
1959 'BankAccountNumberKey'
1962 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1963 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1964 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1965 $fieldlists = array(
1968 'BankAccountNumberKey',
1973 //Replace the old AccountNumber key with the new BankAccountNumber key
1974 $fieldlists = explode(
1976 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1992 public function initAsSpecimen()
1994 // Example of IBAN FR7630001007941234567890185
1995 $this->specimen = 1;
1997 $this->label = 'My Big Company Bank account';
1998 $this->clos = Account::STATUS_OPEN;
1999 $this->type = Account::TYPE_CURRENT;
2000 $this->status = Account::STATUS_OPEN;
2001 $this->code_banque = '30001';
2002 $this->code_guichet = '00794';
2003 $this->number = '12345678901';
2004 $this->cle_rib = '85';
2005 $this->bic = 'AA12';
2006 $this->iban = 'FR7630001007941234567890185';
2008 $this->bank = 'MyBank';
2009 $this->address = 'Rue de Paris';
2010 $this->owner_name = 'Owner';
2011 $this->owner_address = 'Owner address';
2012 $this->owner_zip = 'Owner zip';
2013 $this->owner_town = 'Owner town';
2014 $this->owner_country_id = 1;
2015 $this->country_id = 1;
2028 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2030 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type =
'company'";
2032 if ($dbs->query($sql)) {
2035 //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.
2036 //$this->errors = $dbs->lasterror();
2048 public function getKanbanView($option = '', $arraydata = null)
2052 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2054 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2055 $return .= '<div class="info-box
info-box-sm
">';
2056 $return .= '<span class="info-box-icon bg-infobox-action
">';
2057 $return .= img_picto('', $this->picto);
2058 $return .= '</span>';
2059 $return .= '<div class="info-box-content
">';
2060 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2061 if ($selected >= 0) {
2062 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2064 if (property_exists($this, 'type_lib')) {
2065 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2067 if (method_exists($this, 'solde')) {
2068 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2069 $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>';
2071 if (method_exists($this, 'getLibStatut')) {
2072 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2074 $return .= '</div>';
2075 $return .= '</div>';
2076 $return .= '</div>';
2082require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2087class AccountLine extends CommonObjectLine
2097 public $element = 'bank';
2102 public $table_element = 'bank';
2107 public $picto = 'accountline';
2148 public $amount_main_currency;
2153 public $fk_user_author;
2158 public $fk_user_rappro;
2168 public $fk_bordereau;
2178 public $bank_account_ref;
2183 public $bank_account_label;
2188 public $numero_compte;
2230 public $user_rappro;
2238 public function __construct(DoliDB $db)
2251 public function fetch($rowid, $ref = '', $num = '')
2254 if (empty($rowid) && empty($ref) && empty($num)) {
2258 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2259 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2260 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2261 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2262 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2263 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2264 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2265 $sql .= " WHERE b.fk_account = ba.rowid
";
2266 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2268 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2270 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2272 $sql .= " AND b.rowid =
".((int) $rowid);
2275 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2276 $result = $this->db->query($sql);
2280 $obj = $this->db->fetch_object($result);
2282 $this->id = $obj->rowid;
2283 $this->rowid = $obj->rowid;
2284 $this->ref = $obj->rowid;
2286 $this->datec = $this->db->jdate($obj->datec);
2287 $this->datev = $this->db->jdate($obj->datev);
2288 $this->dateo = $this->db->jdate($obj->dateo);
2289 $this->amount = $obj->amount;
2290 $this->label = $obj->label;
2291 $this->note = $obj->note;
2293 $this->fk_user_author = $obj->fk_user_author;
2294 $this->fk_user_rappro = $obj->fk_user_rappro;
2296 $this->fk_type = $obj->fk_type; // Type of transaction
2297 $this->rappro = (int) $obj->rappro;
2298 $this->num_releve = $obj->num_releve;
2300 $this->num_chq = $obj->num_chq;
2301 $this->bank_chq = $obj->banque;
2302 $this->fk_bordereau = $obj->fk_bordereau;
2304 $this->fk_account = $obj->fk_account;
2305 $this->bank_account_ref = $obj->bank_account_ref;
2306 $this->bank_account_label = $obj->bank_account_label;
2308 // Retrieve all extrafield
2309 // fetch optionals attributes and labels
2310 $this->fetch_optionals();
2314 $this->db->free($result);
2326 public function insert()
2332 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2338 $sql .= ", amount_main_currency
";
2339 $sql .= ", fk_user_author
";
2340 $sql .= ", num_chq
";
2341 $sql .= ", fk_account
";
2342 $sql .= ", fk_type
";
2343 $sql .= ", emetteur,banque
";
2345 $sql .= ", numero_compte
";
2346 $sql .= ", num_releve
";
2348 $sql .= ") VALUES (
";
2349 $sql .= "'".$this->db->idate($this->datec)."'";
2350 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2351 $sql .= ",
'".$this->db->idate($this->datev)."'";
2352 $sql .= ",
'".$this->db->escape($this->label)."'";
2353 $sql .= ",
".price2num($this->amount);
2354 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2355 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2356 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2357 $sql .= ",
'".$this->db->escape((string) $this->fk_account)."'";
2358 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2359 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2360 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2361 $sql .= ",
".(int) $this->rappro;
2362 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2363 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2364 $sql .= ",
".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2368 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2369 $resql = $this->db->query($sql);
2371 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2372 // Actions on extra fields (by external module or standard code)
2373 $result = $this->insertExtraFields();
2379 $this->error = $this->db->lasterror();
2380 dol_print_error($this->db);
2384 $this->db->commit();
2387 $this->db->rollback();
2399 public function delete($user, $notrigger = 0)
2403 if ($this->rappro) {
2404 // Protection to avoid any delete of consolidated lines
2405 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2413 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2415 $this->db->rollback();
2418 // End call triggers
2421 // Protection to avoid any delete of accounted lines. Protection on by default
2422 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2423 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2424 $resql = $this->db->query($sql);
2426 $obj = $this->db->fetch_object($resql);
2427 if ($obj && $obj->nb) {
2428 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2429 $this->db->rollback();
2433 $this->error = $this->db->lasterror();
2434 $this->db->rollback();
2440 $result = $this->delete_urls($user);
2445 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2446 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2447 $result = $this->db->query($sql);
2452 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2453 $result = $this->db->query($sql);
2458 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2459 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2460 $result = $this->db->query($sql);
2466 $this->db->commit();
2469 $this->db->rollback();
2475 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2482 public function delete_urls($user = null)
2487 if ($this->rappro) {
2488 // Protection to avoid any delete of consolidated lines
2489 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2495 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2496 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2497 $result = $this->db->query($sql);
2503 $this->db->commit();
2506 $this->db->rollback();
2519 public function update(User $user, $notrigger = 0)
2523 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2524 $sql .= " amount =
".price2num($this->amount).",
";
2525 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2526 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2527 $sql .= " WHERE rowid =
".((int) $this->rowid);
2529 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2530 $resql = $this->db->query($sql);
2532 $this->db->commit();
2535 $this->db->rollback();
2536 $this->error = $this->db->error();
2547 public function updateLabel()
2551 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2552 $sql .= " label =
'".$this->db->escape($this->label)."'";
2553 $sql .= " WHERE rowid =
".((int) $this->rowid);
2555 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2556 $resql = $this->db->query($sql);
2558 $this->db->commit();
2561 $this->db->rollback();
2562 $this->error = $this->db->error();
2568 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2577 public function update_conciliation(User $user, $cat, $conciliated = 1)
2580 global $conf, $langs;
2584 // Check statement field
2585 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2586 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2587 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2592 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2593 $sql .= " rappro =
".((int) $conciliated);
2594 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2596 $sql .= ", fk_user_rappro =
".((int) $user->id);
2598 $sql .= " WHERE rowid =
".((int) $this->id);
2600 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2601 $resql = $this->db->query($sql);
2603 if (!empty($cat) && $cat > 0) {
2604 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2606 $sql .= ", fk_categ
";
2607 $sql .= ") VALUES (
";
2608 $sql .= ((int) $this->id);
2609 $sql .= ",
".((int) $cat);
2612 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2613 $this->db->query($sql);
2615 // No error check. Can fail if category already affected
2616 // TODO Do no try the insert if link already exists
2619 $this->rappro = (int) $conciliated;
2621 $this->db->commit();
2624 $this->db->rollback();
2630 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2638 public function datev_change($rowid, $sign = 1)
2641 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2642 $resql = $this->db->query($sql);
2644 $obj = $this->db->fetch_object($resql);
2645 $newdate = (int) $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2647 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2648 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2649 $sql .= " WHERE rowid =
".((int) $rowid);
2651 $result = $this->db->query($sql);
2653 if ($this->db->affected_rows($result)) {
2657 dol_print_error($this->db);
2661 dol_print_error($this->db);
2666 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2673 public function datev_next($id)
2676 return $this->datev_change($id, 1);
2679 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2686 public function datev_previous($id)
2689 return $this->datev_change($id, -1);
2693 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2701 public function dateo_change($rowid, $sign = 1)
2704 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2705 $resql = $this->db->query($sql);
2707 $obj = $this->db->fetch_object($resql);
2708 $newdate = (int) $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2710 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2711 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2712 $sql .= " WHERE rowid =
".((int) $rowid);
2714 $result = $this->db->query($sql);
2716 if ($this->db->affected_rows($result)) {
2720 dol_print_error($this->db);
2724 dol_print_error($this->db);
2729 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2736 public function dateo_next($id)
2739 return $this->dateo_change($id, 1);
2742 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2749 public function dateo_previous($id)
2752 return $this->dateo_change($id, -1);
2762 public function info($id)
2764 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2765 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2766 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2767 $sql .= ' WHERE b.rowid = '.((int) $id);
2769 $result = $this->db->query($sql);
2771 if ($this->db->num_rows($result)) {
2772 $obj = $this->db->fetch_object($result);
2774 $this->id = $obj->rowid;
2776 $this->user_creation_id = $obj->fk_user_author;
2777 $this->user_rappro = $obj->fk_user_rappro;
2778 $this->date_creation = $this->db->jdate($obj->datec);
2779 $this->date_modification = $this->db->jdate($obj->datem);
2780 //$this->date_rappro = $obj->daterappro; // Not yet managed
2782 $this->db->free($result);
2784 dol_print_error($this->db);
2798 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2800 global $conf, $langs;
2804 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2805 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2806 if ($this->amount) {
2807 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2810 $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
">';
2813 $result .= $linkstart;
2815 $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);
2817 if ($withpicto != 2) {
2818 $result .= ($this->ref ? $this->ref : $this->id);
2821 $result .= $linkend;
2823 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2824 $result .= ' <span class="opacitymedium
">(';
2826 if ($option == 'showall') {
2827 $result .= $langs->trans("BankAccount
").': ';
2828 $accountstatic = new Account($this->db);
2829 $accountstatic->id = $this->fk_account;
2830 $accountstatic->ref = $this->bank_account_ref;
2831 $accountstatic->label = $this->bank_account_label;
2832 $result .= $accountstatic->getNomUrl(0).', ';
2834 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2835 $result .= $langs->trans("BankLineConciliated
").': ';
2836 $result .= yn($this->rappro);
2838 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2839 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2840 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2841 $resql = $this->db->query($sql);
2843 $obj = $this->db->fetch_object($resql);
2844 if ($obj && $obj->nb) {
2845 $result .= ' - '.$langs->trans("Accounted
").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2847 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2851 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2852 $result .= ')</span>';
2865 public function getLibStatut($mode = 0)
2867 return $this->LibStatut($this->status, $mode);
2870 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2878 public function LibStatut($status, $mode = 0)
2890 public function getVentilExportCompta($mode = 0)
2892 $alreadydispatched = 0;
2896 $sql = " SELECT
".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb
";
2897 $sql .= " FROM
".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type =
'".$this->db->escape($type)."' AND ab.fk_doc =
".((int) $this->id);
2898 $resql = $this->db->query($sql);
2900 $obj = $this->db->fetch_object($resql);
2902 $alreadydispatched = $obj->nb;
2905 $this->error = $this->db->lasterror();
2909 if ($alreadydispatched) {
2910 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
print $langs trans('Date')." left Ref 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 Paid 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]]]',...