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)) {
511 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
517 $sql .=
") VALUES (";
518 $sql .= ((int) $line_id);
519 $sql .=
", ".((int) $url_id);
520 $sql .=
", '".$this->db->escape($url).
"'";
521 $sql .=
", '".$this->db->escape($label).
"'";
522 $sql .=
", '".$this->db->escape($type).
"'";
525 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
526 if ($this->db->query($sql)) {
527 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
530 $this->
error = $this->db->lasterror();
545 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
551 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
552 $this->
error =
"ErrorBadParameter";
556 $sql =
"SELECT fk_bank, url_id, url, label, type";
557 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
559 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
561 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
563 $sql .=
" ORDER BY type, label";
565 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
566 $result = $this->db->query($sql);
569 $num = $this->db->num_rows($result);
571 $obj = $this->db->fetch_object($result);
573 $lines[$i][0] = $obj->url;
574 $lines[$i][1] = $obj->url_id;
575 $lines[$i][2] = $obj->label;
576 $lines[$i][3] = $obj->type;
578 $lines[$i][
'url'] = $obj->url;
579 $lines[$i][
'url_id'] = $obj->url_id;
580 $lines[$i][
'label'] = $obj->label;
581 $lines[$i][
'type'] = $obj->type;
582 $lines[$i][
'fk_bank'] = $obj->fk_bank;
611 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 =
'')
616 if (is_numeric($oper)) {
617 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
620 if (empty($this->
id) && !empty($this->rowid)) {
621 $this->
id = $this->rowid;
625 $emetteur = trim($emetteur);
626 $banque = trim($banque);
627 $label = trim($label);
631 if (is_numeric($oper)) {
632 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
633 $sql .=
" WHERE id = ".((int) $oper);
634 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
635 $resql = $this->db->query($sql);
637 $obj = $this->db->fetch_object($resql);
647 $this->
error = $langs->trans(
"OperNotDefined");
651 $this->
error = $langs->trans(
"ThisIdNotDefined");
655 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
661 if (is_null($datev) || empty($datev)) {
666 $accline->datec = $now;
667 $accline->dateo = $date;
668 $accline->datev = $datev;
669 $accline->label = $label;
670 $accline->amount = $amount;
671 $accline->amount_main_currency = $amount_main_currency;
672 $accline->fk_user_author = $user->id;
673 $accline->fk_account = $this->id;
674 $accline->fk_type = $oper;
675 $accline->numero_compte = $accountancycode;
676 $accline->num_releve = $num_releve;
677 $accline->note_private = $note_private;
680 $accline->num_chq = $num_chq;
684 $accline->emetteur = $emetteur;
688 $accline->bank_chq = $banque;
691 if ($accline->insert() > 0) {
692 if ($categorie > 0) {
693 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bankline(";
694 $sql .=
"lineid, fk_categ";
695 $sql .=
") VALUES (";
696 $sql .= ((int) $accline->id).
", ".((int) $categorie);
699 $result = $this->db->query($sql);
701 $this->
error = $this->db->lasterror();
702 $this->db->rollback();
713 $this->db->rollback();
726 public function create($user, $notrigger = 0)
728 global $langs,
$conf;
733 if (!$this->min_allowed) {
734 $this->min_allowed = 0;
736 if (!$this->min_desired) {
737 $this->min_desired = 0;
741 if (empty($this->country_id)) {
742 $langs->load(
'errors');
743 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
747 if (empty($this->
ref)) {
748 $langs->load(
'errors');
749 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
753 if (empty($this->date_solde)) {
754 $langs->load(
'errors');
755 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
761 $balance = $this->balance;
762 if (empty($balance) && !empty($this->
solde)) {
763 dol_syslog(get_class($this).
"::create solde is deprecated use balance", LOG_NOTICE);
764 $balance = $this->solde;
766 if (empty($balance)) {
769 if (empty($this->
status && !empty($this->clos))) {
770 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
771 $this->
status = $this->clos;
774 if (empty($this->country_id) && !empty($this->country_code)) {
775 $country_id =
getCountry($this->country_code,
'3');
776 $this->country_id = is_int($country_id) ? $country_id : 0;
780 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
786 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
791 $sql .=
", account_number";
792 $sql .=
", fk_accountancy_journal";
794 $sql .=
", code_banque";
795 $sql .=
", code_guichet";
799 $sql .=
", iban_prefix";
800 $sql .=
", domiciliation";
801 $sql .=
", pti_in_ctti";
803 $sql .=
", owner_address";
804 $sql .=
", owner_zip";
805 $sql .=
", owner_town";
806 $sql .=
", owner_country_id";
807 $sql .=
", currency_code";
809 $sql .=
", min_allowed";
810 $sql .=
", min_desired";
812 $sql .=
", state_id";
815 $sql .=
", ics_transfer";
816 $sql .=
") VALUES (";
817 $sql .=
"'".$this->db->idate($now).
"'";
818 $sql .=
", '".$this->db->escape($this->
ref).
"'";
819 $sql .=
", '".$this->db->escape($this->label).
"'";
820 $sql .=
", ".((int)
$conf->entity);
821 $sql .=
", '".$this->db->escape($this->account_number).
"'";
822 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
823 $sql .=
", '".$this->db->escape($this->bank).
"'";
824 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
825 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
826 $sql .=
", '".$this->db->escape($this->number).
"'";
827 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
828 $sql .=
", '".$this->db->escape($this->bic).
"'";
829 $sql .=
", '".$this->db->escape($this->iban).
"'";
830 $sql .=
", '".$this->db->escape($this->
address).
"'";
831 $sql .=
", ".((int) $this->pti_in_ctti);
832 $sql .=
", '".$this->db->escape($this->owner_name).
"'";
833 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
834 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
835 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
836 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
837 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
838 $sql .=
", ".((int) $this->rappro);
839 $sql .=
", ".price2num($this->min_allowed,
'MT');
840 $sql .=
", ".price2num($this->min_desired,
'MT');
841 $sql .=
", '".$this->db->escape($this->comment).
"'";
842 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
843 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
844 $sql .=
", '".$this->db->escape($this->ics).
"'";
845 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
848 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
849 $resql = $this->db->query($sql);
851 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
853 $result = $this->
update($user, 1);
856 $accline->datec = $now;
857 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
858 $accline->amount = (float)
price2num($balance);
859 $accline->fk_user_author = $user->id;
860 $accline->fk_account = $this->id;
861 $accline->datev = $this->date_solde;
862 $accline->dateo = $this->date_solde;
863 $accline->fk_type =
'SOLD';
865 if ($accline->insert() < 0) {
877 if (!$error && !$notrigger) {
879 $result = $this->call_trigger(
'BANKACCOUNT_CREATE', $user);
889 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
890 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
893 $this->
error = $this->db->error().
" sql=".$sql;
902 $this->db->rollback();
914 public function update($user, $notrigger = 0)
916 global $langs,
$conf;
918 if (empty($this->country_id) && !empty($this->country_code)) {
919 $country_id =
getCountry($this->country_code,
'3');
920 $this->country_id = is_int($country_id) ? $country_id : 0;
928 if (empty($this->country_id)) {
929 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
933 if (empty($this->
ref)) {
934 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
939 $this->label =
"???";
942 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
943 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
944 $sql .=
",label = '".$this->db->escape($this->label).
"'";
945 $sql .=
",courant = ".((int) $this->
type);
946 $sql .=
",clos = ".((int) $this->
status);
947 $sql .=
",rappro = ".((int) $this->rappro);
948 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
949 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
950 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
951 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
952 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
953 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
954 $sql .=
",number='".$this->db->escape($this->number).
"'";
955 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
956 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
957 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
958 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
959 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
960 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
961 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
962 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
963 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
964 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
966 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
968 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
969 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
970 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
972 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
973 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
974 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
975 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
977 $sql .=
" WHERE rowid = ".((int) $this->
id);
979 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
980 $result = $this->db->query($sql);
990 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
991 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
992 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type = 'bank_account' and entity = ".((int)
$conf->entity);
993 $resql = $this->db->query($sql);
996 $this->
error = $this->db->lasterror();
1002 $dirsource =
$conf->bank->dir_output.
'/'.$oldref;
1003 $dirdest =
$conf->bank->dir_output.
'/'.$newref;
1004 if (file_exists($dirsource)) {
1005 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
1006 if (@rename($dirsource, $dirdest)) {
1012 if (!$error && !$notrigger) {
1014 $result = $this->call_trigger(
'BANKACCOUNT_MODIFY', $user);
1022 $this->
error = $this->db->lasterror();
1027 $this->db->commit();
1030 $this->db->rollback();
1046 global
$conf, $langs;
1049 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1051 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1055 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1059 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1060 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1061 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1062 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1063 $sql .=
",number='".$this->db->escape($this->number).
"'";
1064 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1065 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1066 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1067 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
1068 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
1069 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1070 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1071 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1072 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1073 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1074 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1075 $sql .=
" WHERE rowid = ".((int) $this->
id);
1076 $sql .=
" AND entity = ".((int)
$conf->entity);
1078 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1080 $result = $this->db->query($sql);
1084 $this->
error = $this->db->lasterror();
1100 if (empty($id) && empty($ref)) {
1101 $this->
error =
"ErrorBadParameters";
1105 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1106 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1107 $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,";
1108 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1109 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1110 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1111 $sql .=
' c.code as country_code, c.label as country,';
1112 $sql .=
' d.code_departement as state_code, d.nom as state,';
1113 $sql .=
' aj.code as accountancy_journal';
1114 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1115 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1116 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1117 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1118 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1120 $sql .=
" AND ba.rowid = ".((int) $id);
1123 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1126 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1127 $result = $this->db->query($sql);
1129 if ($this->db->num_rows($result)) {
1130 $obj = $this->db->fetch_object($result);
1132 $this->
id = $obj->rowid;
1133 $this->rowid = $obj->rowid;
1134 $this->
ref = $obj->ref;
1135 $this->label = $obj->label;
1136 $this->
type = $obj->type;
1137 $this->courant = $obj->type;
1138 $this->bank = $obj->bank;
1139 $this->clos = $obj->status;
1140 $this->
status = $obj->status;
1141 $this->rappro = $obj->rappro;
1142 $this->url = $obj->url;
1144 $this->code_banque = $obj->code_banque;
1145 $this->code_guichet = $obj->code_guichet;
1146 $this->number = $obj->number;
1147 $this->cle_rib = $obj->cle_rib;
1148 $this->bic = $obj->bic;
1149 $this->iban = $obj->iban;
1150 $this->
address = $obj->address;
1152 $this->owner_name = $obj->owner_name;
1153 $this->proprio = $this->owner_name;
1154 $this->owner_address = $obj->owner_address;
1155 $this->owner_zip = $obj->owner_zip;
1156 $this->owner_town = $obj->owner_town;
1157 $this->owner_country_id = $obj->owner_country_id;
1159 $this->pti_in_ctti = $obj->pti_in_ctti;
1161 $this->state_id = $obj->state_id;
1162 $this->state_code = $obj->state_code;
1163 $this->state = $obj->state;
1165 $this->country_id = $obj->country_id;
1166 $this->country_code = $obj->country_code;
1167 $this->country = $obj->country;
1169 $this->account_number = $obj->account_number;
1170 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1171 $this->accountancy_journal = $obj->accountancy_journal;
1173 $this->currency_code = $obj->currency_code;
1174 $this->account_currency_code = $obj->currency_code;
1175 $this->min_allowed = $obj->min_allowed;
1176 $this->min_desired = $obj->min_desired;
1177 $this->comment = $obj->comment;
1179 $this->date_creation = $this->db->jdate($obj->date_creation);
1180 $this->date_modification = $this->db->jdate($obj->date_modification);
1182 $this->ics = $obj->ics;
1183 $this->ics_transfer = $obj->ics_transfer;
1194 $this->
error = $this->db->lasterror();
1195 $this->errors[] = $this->error;
1212 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1213 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1223 public function delete($user, $notrigger = 0)
1233 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1234 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1236 $resql = $this->db->query($sql);
1239 $this->
error =
"Error ".$this->db->lasterror();
1244 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1245 $sql .=
" WHERE rowid = ".((int) $this->
id);
1247 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1248 $result = $this->db->query($sql);
1255 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1260 $this->
error =
"Error ".$this->db->lasterror();
1265 $this->db->commit();
1268 $this->db->rollback();
1297 $langs->load(
'banks');
1299 if ($status == self::STATUS_OPEN) {
1300 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1301 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1302 $statusType =
'status4';
1304 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1305 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1306 $statusType =
'status5';
1309 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1322 $can_be_deleted =
false;
1324 $sql =
"SELECT COUNT(rowid) as nb";
1325 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1326 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1328 $resql = $this->db->query($sql);
1330 $obj = $this->db->fetch_object($resql);
1331 if ($obj->nb <= 1) {
1332 $can_be_deleted =
true;
1337 return $can_be_deleted;
1348 return $this->error;
1359 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1363 $sql =
"SELECT sum(amount) as amount";
1364 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1365 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1367 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1370 $resql = $this->db->query($sql);
1372 if ($this->db->num_rows($resql)) {
1373 $obj = $this->db->fetch_object($resql);
1374 $solde = $obj->amount;
1376 $this->db->free($resql);
1378 $this->errors[] = $this->db->lasterror;
1396 global
$conf, $langs;
1402 $sql =
"SELECT b.rowid, b.datev as datefin";
1403 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1404 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1405 $sql .=
" WHERE b.rappro=0";
1406 $sql .=
" AND b.fk_account = ba.rowid";
1407 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1409 $sql .=
" AND clos = 0";
1410 if ($filteraccountid) {
1411 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1413 $resql = $this->db->query($sql);
1415 $langs->load(
"banks");
1418 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1421 $response->warning_delay =
$conf->bank->rappro->warning_delay / 60 / 60 / 24;
1422 $response->label = $langs->trans(
"TransactionsToConciliate");
1423 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1424 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1427 while ($obj = $this->db->fetch_object($resql)) {
1428 $response->nbtodo++;
1429 if ((
int) $this->db->jdate($obj->datefin) < ($now -
$conf->bank->rappro->warning_delay)) {
1430 $response->nbtodolate++;
1436 $this->
error = $this->db->error();
1455 $sql =
"SELECT count(b.rowid) as nb";
1456 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1457 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1458 $sql .=
" WHERE b.fk_account = ba.rowid";
1459 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1460 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1461 $sql .=
" AND clos = 0";
1462 if ($filteraccountid) {
1463 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1466 $resql = $this->db->query($sql);
1468 while ($obj = $this->db->fetch_object($resql)) {
1469 $this->nb[
"banklines"] = $obj->nb;
1471 $this->db->free($resql);
1475 $this->
error = $this->db->error();
1497 $sql =
"SELECT COUNT(ba.rowid) as nb";
1498 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1499 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1500 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1505 $resql = $this->db->query($sql);
1507 $obj = $this->db->fetch_object($resql);
1508 $nb = (int) $obj->nb;
1527 $langs->loadLangs([
'banks',
'compta']);
1528 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1532 $nofetch = !empty($params[
'nofetch']);
1533 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1534 if (isset($this->
status)) {
1535 $pictos .=
' '.$this->getLibStatut(5);
1537 $datas[
'picto'] = $pictos;
1538 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1539 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1540 $datas[
'accountnumber'] =
'<br><br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1542 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1543 $datas[
'accountcurrency'] =
'<br><br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1546 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1547 $langs->load(
"accountancy");
1548 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1549 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1553 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1554 $form =
new Form($this->db);
1555 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1572 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1574 global
$conf, $langs;
1576 if (!empty(
$conf->dol_no_mouse_hover)) {
1580 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1583 $classfortooltip =
'classfortooltip';
1587 'objecttype' => $this->element,
1588 'option' => $option,
1592 $classfortooltip =
'classforajaxtooltip';
1593 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1599 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1600 if ($mode ==
'transactions') {
1601 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1602 } elseif ($mode ==
'receipts') {
1603 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1606 if ($option !=
'nolink') {
1608 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1609 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1610 $add_save_lastsearch_values = 1;
1612 if ($add_save_lastsearch_values) {
1613 $url .=
'&save_lastsearch_values=1';
1618 if (empty($notooltip)) {
1620 $label = $langs->trans(
"BankAccount");
1621 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1623 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1624 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1626 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1629 if ($option ==
'nolink' || empty($url)) {
1630 $linkstart =
'<span';
1632 $linkstart =
'<a href="'.$url.
'"';
1634 $linkstart .= $linkclose.
'>';
1635 if ($option ==
'nolink' || empty($url)) {
1636 $linkend =
'</span>';
1641 $result .= $linkstart;
1644 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1646 if ($withpicto != 2) {
1647 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1649 $result .= $linkend;
1665 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1672 $this->
error =
'IBANNotValid';
1678 $this->
error =
'SwiftNotValid';
1698 if (!empty($this->country_code)) {
1699 return $this->country_code;
1703 if (!empty($this->iban)) {
1706 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1712 if (!empty($this->socid)) {
1713 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1714 $company =
new Societe($this->db);
1715 $result = $company->fetch($this->socid);
1716 if (!empty($company->country_code)) {
1717 return $company->country_code;
1722 if (!empty(
$mysoc->country_code)) {
1723 return $mysoc->country_code;
1738 global
$conf, $langs;
1745 if (!empty(
$conf->use_javascript_ajax)) {
1747 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1748 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1751 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1771 public function useDetailedBBAN()
1773 $country_code = $this->getCountryCode();
1775 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1776 return 1; // France, Spain, Gabon, ... - Not valid for CH
1778 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1779 return 2; // Australia, England...
1789 public function needIBAN()
1793 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1797 $country_code = $this->getCountryCode();
1799 $country_code_in_EEC = array(
1804 'CZ', // Czech republic
1811 'GB', // United Kingdom
1817 'IM', // Isle of Man - Included in UK
1822 'MC', // Monaco - Included in France
1831 'UK', // United Kingdom
1832 //'CH', // Switzerland - No. Swizerland in not in EEC
1835 if (in_array($country_code, $country_code_in_EEC)) {
1836 return 1; // France, Spain, ...
1846 public function needBIC()
1848 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1852 $country_code = $this->getCountryCode();
1854 $country_code_in_EEC = array(
1866 if (in_array($country_code, $country_code_in_EEC)) {
1867 return 1; // Andorra, Bahrein, ...
1878 public function info($id)
1896 public function getFieldsToShow($includeibanbic = 0)
1898 //Get the required properties depending on the country
1899 $detailedBBAN = $this->useDetailedBBAN();
1901 if ($detailedBBAN == 0) {
1902 $fieldarray = array(
1905 } elseif ($detailedBBAN == 2) {
1906 $fieldarray = array(
1911 $fieldarray = self::getAccountNumberOrder();
1914 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1915 if ($includeibanbic) {
1916 $fieldarray[] = 'IBAN';
1917 $fieldarray[] = 'BIC';
1921 //Get the order the properties are shown
1935 public static function getAccountNumberOrder()
1939 $fieldlists = array(
1942 'BankAccountNumber',
1943 'BankAccountNumberKey'
1946 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1947 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1948 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1949 $fieldlists = array(
1952 'BankAccountNumberKey',
1957 //Replace the old AccountNumber key with the new BankAccountNumber key
1958 $fieldlists = explode(
1960 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1976 public function initAsSpecimen()
1978 // Example of IBAN FR7630001007941234567890185
1979 $this->specimen = 1;
1981 $this->label = 'My Big Company Bank account';
1982 $this->clos = Account::STATUS_OPEN;
1983 $this->type = Account::TYPE_CURRENT;
1984 $this->status = Account::STATUS_OPEN;
1985 $this->code_banque = '30001';
1986 $this->code_guichet = '00794';
1987 $this->number = '12345678901';
1988 $this->cle_rib = '85';
1989 $this->bic = 'AA12';
1990 $this->iban = 'FR7630001007941234567890185';
1992 $this->bank = 'MyBank';
1993 $this->address = 'Rue de Paris';
1994 $this->owner_name = 'Owner';
1995 $this->owner_address = 'Owner address';
1996 $this->owner_zip = 'Owner zip';
1997 $this->owner_town = 'Owner town';
1998 $this->owner_country_id = 1;
1999 $this->country_id = 1;
2012 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2014 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type =
'company'";
2016 if ($dbs->query($sql)) {
2019 //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.
2020 //$this->errors = $dbs->lasterror();
2032 public function getKanbanView($option = '', $arraydata = null)
2036 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2038 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2039 $return .= '<div class="info-box
info-box-sm
">';
2040 $return .= '<span class="info-box-icon bg-infobox-action
">';
2041 $return .= img_picto('', $this->picto);
2042 $return .= '</span>';
2043 $return .= '<div class="info-box-content
">';
2044 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2045 if ($selected >= 0) {
2046 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2048 if (property_exists($this, 'type_lib')) {
2049 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2051 if (method_exists($this, 'solde')) {
2052 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2053 $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>';
2055 if (method_exists($this, 'getLibStatut')) {
2056 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2058 $return .= '</div>';
2059 $return .= '</div>';
2060 $return .= '</div>';
2066require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2071class AccountLine extends CommonObjectLine
2081 public $element = 'bank';
2086 public $table_element = 'bank';
2091 public $picto = 'accountline';
2132 public $amount_main_currency;
2137 public $fk_user_author;
2142 public $fk_user_rappro;
2152 public $fk_bordereau;
2162 public $bank_account_ref;
2167 public $bank_account_label;
2172 public $numero_compte;
2214 public $user_rappro;
2222 public function __construct(DoliDB $db)
2235 public function fetch($rowid, $ref = '', $num = '')
2238 if (empty($rowid) && empty($ref) && empty($num)) {
2242 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2243 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2244 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2245 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2246 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2247 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2248 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2249 $sql .= " WHERE b.fk_account = ba.rowid
";
2250 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2252 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2254 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2256 $sql .= " AND b.rowid =
".((int) $rowid);
2259 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2260 $result = $this->db->query($sql);
2264 $obj = $this->db->fetch_object($result);
2266 $this->id = $obj->rowid;
2267 $this->rowid = $obj->rowid;
2268 $this->ref = $obj->rowid;
2270 $this->datec = $this->db->jdate($obj->datec);
2271 $this->datev = $this->db->jdate($obj->datev);
2272 $this->dateo = $this->db->jdate($obj->dateo);
2273 $this->amount = $obj->amount;
2274 $this->label = $obj->label;
2275 $this->note = $obj->note;
2277 $this->fk_user_author = $obj->fk_user_author;
2278 $this->fk_user_rappro = $obj->fk_user_rappro;
2280 $this->fk_type = $obj->fk_type; // Type of transaction
2281 $this->rappro = (int) $obj->rappro;
2282 $this->num_releve = $obj->num_releve;
2284 $this->num_chq = $obj->num_chq;
2285 $this->bank_chq = $obj->banque;
2286 $this->fk_bordereau = $obj->fk_bordereau;
2288 $this->fk_account = $obj->fk_account;
2289 $this->bank_account_ref = $obj->bank_account_ref;
2290 $this->bank_account_label = $obj->bank_account_label;
2292 // Retrieve all extrafield
2293 // fetch optionals attributes and labels
2294 $this->fetch_optionals();
2298 $this->db->free($result);
2310 public function insert()
2316 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2322 $sql .= ", amount_main_currency
";
2323 $sql .= ", fk_user_author
";
2324 $sql .= ", num_chq
";
2325 $sql .= ", fk_account
";
2326 $sql .= ", fk_type
";
2327 $sql .= ", emetteur,banque
";
2329 $sql .= ", numero_compte
";
2330 $sql .= ", num_releve
";
2332 $sql .= ") VALUES (
";
2333 $sql .= "'".$this->db->idate($this->datec)."'";
2334 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2335 $sql .= ",
'".$this->db->idate($this->datev)."'";
2336 $sql .= ",
'".$this->db->escape($this->label)."'";
2337 $sql .= ",
".price2num($this->amount);
2338 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2339 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2340 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2341 $sql .= ",
'".$this->db->escape((string) $this->fk_account)."'";
2342 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2343 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2344 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2345 $sql .= ",
".(int) $this->rappro;
2346 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2347 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2348 $sql .= ",
".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2352 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2353 $resql = $this->db->query($sql);
2355 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2356 // Actions on extra fields (by external module or standard code)
2357 $result = $this->insertExtraFields();
2363 $this->error = $this->db->lasterror();
2364 dol_print_error($this->db);
2368 $this->db->commit();
2371 $this->db->rollback();
2383 public function delete($user, $notrigger = 0)
2387 if ($this->rappro) {
2388 // Protection to avoid any delete of consolidated lines
2389 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2397 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2399 $this->db->rollback();
2402 // End call triggers
2405 // Protection to avoid any delete of accounted lines. Protection on by default
2406 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2407 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2408 $resql = $this->db->query($sql);
2410 $obj = $this->db->fetch_object($resql);
2411 if ($obj && $obj->nb) {
2412 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2413 $this->db->rollback();
2417 $this->error = $this->db->lasterror();
2418 $this->db->rollback();
2424 $result = $this->delete_urls($user);
2429 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2430 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2431 $result = $this->db->query($sql);
2436 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2437 $result = $this->db->query($sql);
2442 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2443 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2444 $result = $this->db->query($sql);
2450 $this->db->commit();
2453 $this->db->rollback();
2459 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2466 public function delete_urls($user = null)
2471 if ($this->rappro) {
2472 // Protection to avoid any delete of consolidated lines
2473 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2479 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2480 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2481 $result = $this->db->query($sql);
2487 $this->db->commit();
2490 $this->db->rollback();
2503 public function update(User $user, $notrigger = 0)
2507 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2508 $sql .= " amount =
".price2num($this->amount).",
";
2509 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2510 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2511 $sql .= " WHERE rowid =
".((int) $this->rowid);
2513 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2514 $resql = $this->db->query($sql);
2516 $this->db->commit();
2519 $this->db->rollback();
2520 $this->error = $this->db->error();
2531 public function updateLabel()
2535 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2536 $sql .= " label =
'".$this->db->escape($this->label)."'";
2537 $sql .= " WHERE rowid =
".((int) $this->rowid);
2539 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2540 $resql = $this->db->query($sql);
2542 $this->db->commit();
2545 $this->db->rollback();
2546 $this->error = $this->db->error();
2552 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2561 public function update_conciliation(User $user, $cat, $conciliated = 1)
2564 global $conf, $langs;
2568 // Check statement field
2569 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2570 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2571 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2576 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2577 $sql .= " rappro =
".((int) $conciliated);
2578 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2580 $sql .= ", fk_user_rappro =
".((int) $user->id);
2582 $sql .= " WHERE rowid =
".((int) $this->id);
2584 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2585 $resql = $this->db->query($sql);
2587 if (!empty($cat) && $cat > 0) {
2588 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2590 $sql .= ", fk_categ
";
2591 $sql .= ") VALUES (
";
2593 $sql .= ",
".((int) $cat);
2596 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2597 $this->db->query($sql);
2599 // No error check. Can fail if category already affected
2600 // TODO Do no try the insert if link already exists
2603 $this->rappro = (int) $conciliated;
2605 $this->db->commit();
2608 $this->db->rollback();
2614 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2622 public function datev_change($rowid, $sign = 1)
2625 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2626 $resql = $this->db->query($sql);
2628 $obj = $this->db->fetch_object($resql);
2629 $newdate = (int) $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2631 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2632 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2633 $sql .= " WHERE rowid =
".((int) $rowid);
2635 $result = $this->db->query($sql);
2637 if ($this->db->affected_rows($result)) {
2641 dol_print_error($this->db);
2645 dol_print_error($this->db);
2650 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2657 public function datev_next($id)
2660 return $this->datev_change($id, 1);
2663 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2670 public function datev_previous($id)
2673 return $this->datev_change($id, -1);
2677 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2685 public function dateo_change($rowid, $sign = 1)
2688 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2689 $resql = $this->db->query($sql);
2691 $obj = $this->db->fetch_object($resql);
2692 $newdate = (int) $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2694 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2695 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2696 $sql .= " WHERE rowid =
".((int) $rowid);
2698 $result = $this->db->query($sql);
2700 if ($this->db->affected_rows($result)) {
2704 dol_print_error($this->db);
2708 dol_print_error($this->db);
2713 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2720 public function dateo_next($id)
2723 return $this->dateo_change($id, 1);
2726 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2733 public function dateo_previous($id)
2736 return $this->dateo_change($id, -1);
2746 public function info($id)
2748 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2749 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2750 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2751 $sql .= ' WHERE b.rowid = '.((int) $id);
2753 $result = $this->db->query($sql);
2755 if ($this->db->num_rows($result)) {
2756 $obj = $this->db->fetch_object($result);
2758 $this->id = $obj->rowid;
2760 $this->user_creation_id = $obj->fk_user_author;
2761 $this->user_rappro = $obj->fk_user_rappro;
2762 $this->date_creation = $this->db->jdate($obj->datec);
2763 $this->date_modification = $this->db->jdate($obj->datem);
2764 //$this->date_rappro = $obj->daterappro; // Not yet managed
2766 $this->db->free($result);
2768 dol_print_error($this->db);
2782 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2784 global $conf, $langs;
2788 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2789 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2790 if ($this->amount) {
2791 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2794 $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
">';
2797 $result .= $linkstart;
2799 $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);
2801 if ($withpicto != 2) {
2802 $result .= ($this->ref ? $this->ref : $this->id);
2805 $result .= $linkend;
2807 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2808 $result .= ' <span class="opacitymedium
">(';
2810 if ($option == 'showall') {
2811 $result .= $langs->trans("BankAccount
").': ';
2812 $accountstatic = new Account($this->db);
2813 $accountstatic->id = $this->fk_account;
2814 $accountstatic->ref = $this->bank_account_ref;
2815 $accountstatic->label = $this->bank_account_label;
2816 $result .= $accountstatic->getNomUrl(0).', ';
2818 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2819 $result .= $langs->trans("BankLineConciliated
").': ';
2820 $result .= yn($this->rappro);
2822 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2823 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2824 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2825 $resql = $this->db->query($sql);
2827 $obj = $this->db->fetch_object($resql);
2828 if ($obj && $obj->nb) {
2829 $result .= ' - '.$langs->trans("Accounted
").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2831 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2835 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2836 $result .= ')</span>';
2849 public function getLibStatut($mode = 0)
2851 return $this->LibStatut($this->status, $mode);
2854 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2862 public function LibStatut($status, $mode = 0)
2874 public function getVentilExportCompta($mode = 0)
2876 $alreadydispatched = 0;
2880 $sql = " SELECT
".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb
";
2881 $sql .= " FROM
".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type =
'".$this->db->escape($type)."' AND ab.fk_doc =
".((int) $this->id);
2882 $resql = $this->db->query($sql);
2884 $obj = $this->db->fetch_object($resql);
2886 $alreadydispatched = $obj->nb;
2889 $this->error = $this->db->lasterror();
2893 if ($alreadydispatched) {
2894 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.
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]]]',...