34require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45 public $element =
'bank_account';
50 public $table_element =
'bank_account';
56 public $ismultientitymanaged = 1;
61 public $picto =
'account';
98 public $clos = self::STATUS_OPEN;
122 public $code_guichet;
160 public $pti_in_ctti = 0;
172 public $owner_address;
175 public $owner_country_id;
176 public $owner_country_code;
182 public $domiciliation;
193 public $type_lib = array();
200 public $status = array();
206 public $account_number;
211 public $fk_accountancy_journal;
215 public $accountancy_journal;
221 public $currency_code;
228 public $account_currency_code;
278 public $ics_transfer;
315 public $fields = array(
316 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
317 'ref' =>array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>25),
318 'label' =>array(
'type'=>
'varchar(30)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
319 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>35,
'index'=>1),
320 'bank' =>array(
'type'=>
'varchar(60)',
'label'=>
'Bank',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
321 'code_banque' =>array(
'type'=>
'varchar(128)',
'label'=>
'Code banque',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
322 'code_guichet' =>array(
'type'=>
'varchar(6)',
'label'=>
'Code guichet',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
323 'number' =>array(
'type'=>
'varchar(255)',
'label'=>
'Number',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
324 'cle_rib' =>array(
'type'=>
'varchar(5)',
'label'=>
'Cle rib',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
325 'bic' =>array(
'type'=>
'varchar(11)',
'label'=>
'Bic',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
326 'iban_prefix' =>array(
'type'=>
'varchar(34)',
'label'=>
'Iban prefix',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
327 'country_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Country iban',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
328 'cle_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Cle iban',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
329 'domiciliation' =>array(
'type'=>
'varchar(255)',
'label'=>
'Domiciliation',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
330 'state_id' =>array(
'type'=>
'integer',
'label'=>
'StateId',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
331 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>95),
332 'proprio' =>array(
'type'=>
'varchar(60)',
'label'=>
'Proprio',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
333 'owner_address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Owner address',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
334 'owner_zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Owner zip',
'enabled'=>1,
'visible'=>-1,
'position'=>106),
335 'owner_town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Owner town',
'enabled'=>1,
'visible'=>-1,
'position'=>107),
336 'owner_country_id' =>array(
'type'=>
'integer',
'label'=>
'Owner country',
'enabled'=>1,
'visible'=>-1,
'position'=>108),
337 'courant' =>array(
'type'=>
'smallint(6)',
'label'=>
'Courant',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>110),
338 'clos' =>array(
'type'=>
'smallint(6)',
'label'=>
'Clos',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>115),
339 'rappro' =>array(
'type'=>
'smallint(6)',
'label'=>
'Rappro',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
340 'url' =>array(
'type'=>
'varchar(128)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
341 'account_number' =>array(
'type'=>
'varchar(32)',
'label'=>
'Account number',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
342 'fk_accountancy_journal' =>array(
'type'=>
'integer',
'label'=>
'Accountancy journal ID',
'enabled'=>1,
'visible'=>-1,
'position'=>132),
343 'accountancy_journal' =>array(
'type'=>
'varchar(20)',
'label'=>
'Accountancy journal',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
344 'currency_code' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>140),
345 'min_allowed' =>array(
'type'=>
'integer',
'label'=>
'Min allowed',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
346 'min_desired' =>array(
'type'=>
'integer',
'label'=>
'Min desired',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
347 'comment' =>array(
'type'=>
'text',
'label'=>
'Comment',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
348 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>156),
349 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>157),
350 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
351 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>165),
352 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>170),
353 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>175),
354 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>180),
355 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
373 const STATUS_OPEN = 0;
374 const STATUS_CLOSED = 1;
390 $this->type_lib = array(
391 self::TYPE_SAVINGS => $langs->trans(
"BankType0"),
392 self::TYPE_CURRENT => $langs->trans(
"BankType1"),
393 self::TYPE_CASH => $langs->trans(
"BankType2"),
396 $this->status = array(
397 self::STATUS_OPEN => $langs->trans(
"StatusAccountOpened"),
398 self::STATUS_CLOSED => $langs->trans(
"StatusAccountClosed")
411 if ($val ==
'BankCode') {
412 $string .= $this->code_banque.
' ';
413 } elseif ($val ==
'BankAccountNumber') {
414 $string .= $this->number.
' ';
415 } elseif ($val ==
'DeskCode') {
416 $string .= $this->code_guichet.
' ';
417 } elseif ($val ==
'BankAccountNumberKey') {
418 $string .= $this->cle_rib.
' ';
419 } elseif ($val ==
'BIC') {
420 $string .= $this->bic.
' ';
421 } elseif ($val ==
'IBAN') {
422 $string .= $this->iban.
' ';
426 return trim($string);
439 if (empty($this->rappro)) {
442 if ($this->courant ==
Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
466 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
472 $sql .=
") VALUES (";
473 $sql .=
" ".((int) $line_id);
474 $sql .=
", ".((int) $url_id);
475 $sql .=
", '".$this->db->escape($url).
"'";
476 $sql .=
", '".$this->db->escape($label).
"'";
477 $sql .=
", '".$this->db->escape($type).
"'";
480 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
481 if ($this->db->query($sql)) {
482 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
485 $this->
error = $this->db->lasterror();
500 public function get_url($fk_bank =
'', $url_id =
'', $type =
'')
506 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
507 $this->
error =
"ErrorBadParameter";
511 $sql =
"SELECT fk_bank, url_id, url, label, type";
512 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
514 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
516 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
518 $sql .=
" ORDER BY type, label";
520 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
521 $result = $this->db->query($sql);
524 $num = $this->db->num_rows($result);
526 $obj = $this->db->fetch_object($result);
528 $lines[$i][0] = $obj->url;
529 $lines[$i][1] = $obj->url_id;
530 $lines[$i][2] = $obj->label;
531 $lines[$i][3] = $obj->type;
533 $lines[$i][
'url'] = $obj->url;
534 $lines[$i][
'url_id'] = $obj->url_id;
535 $lines[$i][
'label'] = $obj->label;
536 $lines[$i][
'type'] = $obj->type;
537 $lines[$i][
'fk_bank'] = $obj->fk_bank;
565 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
570 if (is_numeric($oper)) {
571 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
574 if (empty($this->
id) && !empty($this->
rowid)) {
575 $this->
id = $this->rowid;
579 $emetteur = trim($emetteur);
580 $banque = trim($banque);
581 $label = trim($label);
585 if (is_numeric($oper)) {
586 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
587 $sql .=
" WHERE id = ".((int) $oper);
588 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
589 $resql = $this->db->query($sql);
591 $obj = $this->db->fetch_object($resql);
601 $this->
error = $langs->trans(
"OperNotDefined");
605 $this->
error = $langs->trans(
"ThisIdNotDefined");
609 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
615 if (is_null($datev) || empty($datev)) {
620 $accline->datec = $now;
621 $accline->dateo = $date;
622 $accline->datev = $datev;
623 $accline->label = $label;
624 $accline->amount = $amount;
625 $accline->amount_main_currency = $amount_main_currency;
626 $accline->fk_user_author = $user->id;
627 $accline->fk_account = $this->id;
628 $accline->fk_type = $oper;
629 $accline->numero_compte = $accountancycode;
630 $accline->num_releve = $num_releve;
633 $accline->num_chq = $num_chq;
637 $accline->emetteur = $emetteur;
641 $accline->bank_chq = $banque;
644 if ($accline->insert() > 0) {
645 if ($categorie > 0) {
646 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
647 $sql .=
"lineid, fk_categ";
648 $sql .=
") VALUES (";
649 $sql .= ((int) $accline->id).
", '".$this->db->escape($categorie).
"'";
652 $result = $this->db->query($sql);
654 $this->
error = $this->db->lasterror();
655 $this->db->rollback();
665 $this->
error = $accline->error;
666 $this->errors = $accline->errors;
667 $this->db->rollback();
682 global $langs, $conf;
687 if (!$this->min_allowed) {
688 $this->min_allowed = 0;
690 if (!$this->min_desired) {
691 $this->min_desired = 0;
695 if (empty($this->country_id)) {
696 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
700 if (empty($this->
ref)) {
701 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
705 if (empty($this->date_solde)) {
706 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
711 $balance = $this->balance;
712 if (empty($balance) && !empty($this->
solde)) {
713 $balance = $this->solde;
715 if (empty($balance)) {
720 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
726 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
731 $sql .=
", account_number";
732 $sql .=
", fk_accountancy_journal";
734 $sql .=
", code_banque";
735 $sql .=
", code_guichet";
739 $sql .=
", iban_prefix";
740 $sql .=
", domiciliation";
741 $sql .=
", pti_in_ctti";
743 $sql .=
", owner_address";
744 $sql .=
", owner_zip";
745 $sql .=
", owner_town";
746 $sql .=
", owner_country_id";
747 $sql .=
", currency_code";
749 $sql .=
", min_allowed";
750 $sql .=
", min_desired";
752 $sql .=
", state_id";
755 $sql .=
", ics_transfer";
756 $sql .=
") VALUES (";
757 $sql .=
"'".$this->db->idate($now).
"'";
758 $sql .=
", '".$this->db->escape($this->
ref).
"'";
759 $sql .=
", '".$this->db->escape($this->label).
"'";
760 $sql .=
", ".((int) $conf->entity);
761 $sql .=
", '".$this->db->escape($this->account_number).
"'";
762 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
763 $sql .=
", '".$this->db->escape($this->bank).
"'";
764 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
765 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
766 $sql .=
", '".$this->db->escape($this->number).
"'";
767 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
768 $sql .=
", '".$this->db->escape($this->bic).
"'";
769 $sql .=
", '".$this->db->escape($this->iban).
"'";
770 $sql .=
", '".$this->db->escape($this->domiciliation).
"'";
771 $sql .=
", ".((int) $this->pti_in_ctti);
772 $sql .=
", '".$this->db->escape($this->proprio).
"'";
773 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
774 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
775 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
776 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
777 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
778 $sql .=
", ".((int) $this->rappro);
779 $sql .=
", ".price2num($this->min_allowed,
'MT');
780 $sql .=
", ".price2num($this->min_desired,
'MT');
781 $sql .=
", '".$this->db->escape($this->comment).
"'";
782 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
783 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
784 $sql .=
", '".$this->db->escape($this->ics).
"'";
785 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
788 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
789 $resql = $this->db->query($sql);
791 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
793 $result = $this->
update($user, 1);
796 $accline->datec = $this->db->idate($now);
797 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
799 $accline->fk_user_author = $user->id;
800 $accline->fk_account = $this->id;
801 $accline->datev = $this->db->idate($this->date_solde);
802 $accline->dateo = $this->db->idate($this->date_solde);
803 $accline->fk_type =
'SOLD';
805 if ($accline->insert() < 0) {
807 $this->
error = $accline->error;
808 $this->errors = $accline->errors;
818 if (!$error && !$notrigger) {
820 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
830 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
831 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
834 $this->
error = $this->db->error().
" sql=".$sql;
843 $this->db->rollback();
857 global $langs, $conf;
864 if (empty($this->country_id)) {
865 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
869 if (empty($this->
ref)) {
870 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
875 $this->label =
"???";
878 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
880 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
881 $sql .=
",label = '".$this->db->escape($this->label).
"'";
883 $sql .=
",courant = ".((int) $this->courant);
884 $sql .=
",clos = ".((int) $this->clos);
885 $sql .=
",rappro = ".((int) $this->rappro);
886 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
887 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
888 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
889 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
890 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
891 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
892 $sql .=
",number='".$this->db->escape($this->number).
"'";
893 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
894 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
895 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
896 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
897 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
898 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
899 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
900 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
901 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
902 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
904 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
906 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
907 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
908 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
910 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
911 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
912 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
913 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
915 $sql .=
" WHERE rowid = ".((int) $this->
id);
917 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
918 $result = $this->db->query($sql);
928 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
929 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
930 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type='bank_account' and entity = ".((int) $conf->entity);
931 $resql = $this->db->query($sql);
934 $this->
error = $this->db->lasterror();
940 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
941 $dirdest = $conf->bank->dir_output.
'/'.$newref;
942 if (file_exists($dirsource)) {
943 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
944 if (@rename($dirsource, $dirdest)) {
950 if (!$error && !$notrigger) {
952 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
960 $this->
error = $this->db->lasterror();
968 $this->db->rollback();
984 global $conf, $langs;
987 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
989 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
993 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
997 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
998 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
999 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1000 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1001 $sql .=
",number='".$this->db->escape($this->number).
"'";
1002 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1003 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1004 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1005 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
1006 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
1007 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1008 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1009 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1010 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1011 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1012 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1013 $sql .=
" WHERE rowid = ".((int) $this->
id);
1014 $sql .=
" AND entity = ".((int) $conf->entity);
1016 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1018 $result = $this->db->query($sql);
1022 $this->
error = $this->db->lasterror();
1038 if (empty($id) && empty($ref)) {
1039 $this->
error =
"ErrorBadParameters";
1043 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
1044 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1045 $sql .=
" ba.domiciliation as address, ba.pti_in_ctti, ba.proprio, ba.owner_address, ba.owner_zip, ba.owner_town, ba.owner_country_id, ba.state_id, ba.fk_pays as country_id,";
1046 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1047 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1048 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1049 $sql .=
' c.code as country_code, c.label as country,';
1050 $sql .=
' d.code_departement as state_code, d.nom as state,';
1051 $sql .=
' aj.code as accountancy_journal';
1052 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1053 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1054 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1055 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1056 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1058 $sql .=
" AND ba.rowid = ".((int) $id);
1061 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1064 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1065 $result = $this->db->query($sql);
1067 if ($this->db->num_rows($result)) {
1068 $obj = $this->db->fetch_object($result);
1070 $this->
id = $obj->rowid;
1071 $this->
rowid = $obj->rowid;
1072 $this->
ref = $obj->ref;
1073 $this->label = $obj->label;
1074 $this->
type = $obj->courant;
1075 $this->courant = $obj->courant;
1076 $this->bank = $obj->bank;
1077 $this->clos = $obj->clos;
1078 $this->rappro = $obj->rappro;
1079 $this->url = $obj->url;
1081 $this->code_banque = $obj->code_banque;
1082 $this->code_guichet = $obj->code_guichet;
1083 $this->number = $obj->number;
1084 $this->cle_rib = $obj->cle_rib;
1085 $this->bic = $obj->bic;
1086 $this->iban = $obj->iban;
1087 $this->domiciliation = $obj->address;
1088 $this->address = $obj->address;
1089 $this->pti_in_ctti = $obj->pti_in_ctti;
1090 $this->proprio = $obj->proprio;
1091 $this->owner_address = $obj->owner_address;
1092 $this->owner_zip = $obj->owner_zip;
1093 $this->owner_town = $obj->owner_town;
1094 $this->owner_country_id = $obj->owner_country_id;
1096 $this->state_id = $obj->state_id;
1097 $this->state_code = $obj->state_code;
1098 $this->state = $obj->state;
1100 $this->country_id = $obj->country_id;
1101 $this->country_code = $obj->country_code;
1102 $this->country = $obj->country;
1104 $this->account_number = $obj->account_number;
1105 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1106 $this->accountancy_journal = $obj->accountancy_journal;
1108 $this->currency_code = $obj->currency_code;
1109 $this->account_currency_code = $obj->currency_code;
1110 $this->min_allowed = $obj->min_allowed;
1111 $this->min_desired = $obj->min_desired;
1112 $this->comment = $obj->comment;
1114 $this->date_creation = $this->db->jdate($obj->date_creation);
1115 $this->date_modification = $this->db->jdate($obj->date_modification);
1118 $this->ics = $obj->ics;
1119 $this->ics_transfer = $obj->ics_transfer;
1130 $this->
error = $this->db->lasterror();
1131 $this->errors[] = $this->error;
1148 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1149 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1158 public function delete(
User $user =
null)
1168 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1169 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1171 $resql = $this->db->query($sql);
1174 $this->
error =
"Error ".$this->db->lasterror();
1179 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1180 $sql .=
" WHERE rowid = ".((int) $this->
id);
1182 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1183 $result = $this->db->query($sql);
1190 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1195 $this->
error =
"Error ".$this->db->lasterror();
1200 $this->db->commit();
1203 $this->db->rollback();
1217 return $this->
LibStatut($this->clos, $mode);
1232 $langs->load(
'banks');
1234 if ($status == self::STATUS_OPEN) {
1235 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1236 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1237 $statusType =
'status4';
1239 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1240 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1241 $statusType =
'status5';
1244 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1257 $can_be_deleted =
false;
1259 $sql =
"SELECT COUNT(rowid) as nb";
1260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1261 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1263 $resql = $this->db->query($sql);
1265 $obj = $this->db->fetch_object($resql);
1266 if ($obj->nb <= 1) {
1267 $can_be_deleted =
true;
1272 return $can_be_deleted;
1283 return $this->error;
1294 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1298 $sql =
"SELECT sum(amount) as amount";
1299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1300 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1302 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1305 $resql = $this->db->query($sql);
1307 if ($this->db->num_rows($resql)) {
1308 $obj = $this->db->fetch_object($resql);
1309 $solde = $obj->amount;
1311 $this->db->free($resql);
1313 $this->errors[] = $this->db->lasterror;
1331 global $conf, $langs;
1337 $sql =
"SELECT b.rowid, b.datev as datefin";
1338 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1339 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1340 $sql .=
" WHERE b.rappro=0";
1341 $sql .=
" AND b.fk_account = ba.rowid";
1342 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1343 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1344 $sql .=
" AND clos = 0";
1345 if ($filteraccountid) {
1346 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1349 $resql = $this->db->query($sql);
1351 $langs->load(
"banks");
1354 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1357 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1358 $response->label = $langs->trans(
"TransactionsToConciliate");
1359 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1360 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1363 while ($obj = $this->db->fetch_object($resql)) {
1364 $response->nbtodo++;
1365 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1366 $response->nbtodolate++;
1373 $this->
error = $this->db->error();
1394 $sql =
"SELECT count(b.rowid) as nb";
1395 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1396 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1397 $sql .=
" WHERE b.fk_account = ba.rowid";
1398 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1399 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1400 $sql .=
" AND clos = 0";
1401 if ($filteraccountid) {
1402 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1405 $resql = $this->db->query($sql);
1407 while ($obj = $this->db->fetch_object($resql)) {
1408 $this->nb[
"banklines"] = $obj->nb;
1410 $this->db->free($resql);
1414 $this->
error = $this->db->error();
1427 global $db, $conf, $user;
1436 $sql =
"SELECT COUNT(ba.rowid) as nb";
1437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1438 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1439 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1440 if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
1441 $sql .=
" AND ba.courant != 2";
1443 $resql = $this->db->query($sql);
1445 $obj = $this->db->fetch_object($resql);
1464 $langs->loadLangs([
'banks',
'compta']);
1465 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1469 $nofetch = !empty($params[
'nofetch']);
1470 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1471 if (isset($this->status)) {
1472 $pictos .=
' '.$this->getLibStatut(5);
1474 $datas[
'picto'] = $pictos;
1475 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1476 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1478 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1479 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1481 if (isModEnabled(
'accounting')) {
1482 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1483 $langs->load(
"accountancy");
1484 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1485 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1488 if (isModEnabled(
'categorie') && !$nofetch) {
1489 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1490 $form =
new Form($this->db);
1491 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1508 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1510 global $conf, $langs;
1512 if (!empty($conf->dol_no_mouse_hover)) {
1516 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1519 $classfortooltip =
'classfortooltip';
1523 'objecttype' => $this->element,
1524 'option' => $option,
1528 $classfortooltip =
'classforajaxtooltip';
1529 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1535 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1536 if ($mode ==
'transactions') {
1537 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1538 } elseif ($mode ==
'receipts') {
1539 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1542 if ($option !=
'nolink') {
1544 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1545 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1546 $add_save_lastsearch_values = 1;
1548 if ($add_save_lastsearch_values) {
1549 $url .=
'&save_lastsearch_values=1';
1554 if (empty($notooltip)) {
1556 $label = $langs->trans(
"BankAccount");
1557 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1559 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1560 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1562 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1565 if ($option ==
'nolink' || empty($url)) {
1566 $linkstart =
'<span';
1568 $linkstart =
'<a href="'.$url.
'"';
1570 $linkstart .= $linkclose.
'>';
1571 if ($option ==
'nolink' || empty($url)) {
1572 $linkend =
'</span>';
1577 $result .= $linkstart;
1580 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1582 if ($withpicto != 2) {
1583 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1585 $result .= $linkend;
1601 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1603 $this->error_number = 0;
1608 $this->error_number = 12;
1609 $this->error_message =
'IBANNotValid';
1612 $this->error_number = 12;
1613 $this->error_message =
'SwiftNotValid';
1621 if ($this->error_number == 0) {
1638 if (!empty($this->country_code)) {
1639 return $this->country_code;
1643 if (!empty($this->iban)) {
1646 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1652 if (!empty($this->socid)) {
1653 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1654 $company =
new Societe($this->db);
1655 $result = $company->fetch($this->socid);
1656 if (!empty($company->country_code)) {
1657 return $company->country_code;
1662 if (!empty($mysoc->country_code)) {
1663 return $mysoc->country_code;
1681 if (in_array($country_code, array(
'FR',
'ES',
'GA',
'IT',
'NC'))) {
1684 if (in_array($country_code, array(
'AD',
'AU',
'BE',
'CA',
'DE',
'DK',
'GR',
'GB',
'ID',
'IE',
'IR',
'KR',
'NL',
'NZ',
'UK',
'US'))) {
1699 if (!empty($conf->global->MAIN_IBAN_IS_NEVER_MANDATORY)) {
1705 $country_code_in_EEC = array(
1741 if (in_array($country_code, $country_code_in_EEC)) {
1776 if ($detailedBBAN == 0) {
1777 $fieldarray = array(
1780 } elseif ($detailedBBAN == 2) {
1781 $fieldarray = array(
1790 if ($includeibanbic) {
1791 $fieldarray[] =
'IBAN';
1792 $fieldarray[] =
'BIC';
1814 $fieldlists = array(
1817 'BankAccountNumber',
1818 'BankAccountNumberKey'
1821 if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {
1822 if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1823 if ($conf->global->BANK_SHOW_ORDER_OPTION ==
'1') {
1824 $fieldlists = array(
1827 'BankAccountNumberKey',
1833 $fieldlists = explode(
1835 preg_replace(
'/ ?[^Bank]AccountNumber ?/',
'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1854 $this->specimen = 1;
1856 $this->label =
'My Big Company Bank account';
1857 $this->bank =
'MyBank';
1859 $this->clos = Account::STATUS_OPEN;
1860 $this->code_banque =
'30001';
1861 $this->code_guichet =
'00794';
1862 $this->number =
'12345678901';
1863 $this->cle_rib =
'85';
1864 $this->bic =
'AA12';
1865 $this->iban =
'FR7630001007941234567890185';
1866 $this->domiciliation =
'Banque de France';
1867 $this->proprio =
'Owner';
1868 $this->owner_address =
'Owner address';
1869 $this->owner_zip =
'Owner zip';
1870 $this->owner_town =
'Owner town';
1871 $this->owner_country_id =
'Owner country_id';
1872 $this->country_id = 1;
1885 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_url SET url_id = ".((int) $dest_id).
" WHERE url_id = ".((int) $origin_id).
" AND type='company'";
1887 if ($dbs->query($sql)) {
1907 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1909 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1910 $return .=
'<div class="info-box info-box-sm">';
1911 $return .=
'<span class="info-box-icon bg-infobox-action">';
1913 $return .=
'</span>';
1914 $return .=
'<div class="info-box-content">';
1915 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1916 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1918 if (property_exists($this,
'type_lib')) {
1919 $return .=
'<br><span class="info-box-label opacitymedium" title="'.$this->type_lib[$this->type].
'">'.substr($this->type_lib[$this->
type], 0, 24).
'...</span>';
1921 if (method_exists($this,
'solde')) {
1922 $return .=
'<br><a href="'.DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->
id.
'">';
1923 $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>';
1925 if (method_exists($this,
'getLibStatut')) {
1926 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1928 $return .=
'</div>';
1929 $return .=
'</div>';
1930 $return .=
'</div>';
1936require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1956 public $element =
'bank';
1961 public $table_element =
'bank';
1966 public $picto =
'accountline';
2000 public $amount_main_currency;
2005 public $fk_user_author;
2010 public $fk_user_rappro;
2020 public $fk_bordereau;
2030 public $bank_account_ref;
2035 public $bank_account_label;
2040 public $numero_compte;
2079 public function fetch($rowid, $ref =
'', $num =
'')
2084 if (empty($rowid) && empty($ref) && empty($num)) {
2088 $sql =
"SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
2089 $sql .=
" b.fk_user_author, b.fk_user_rappro,";
2090 $sql .=
" b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
2091 $sql .=
" b.fk_bordereau, b.banque, b.emetteur,";
2092 $sql .=
" ba.ref as bank_account_ref, ba.label as bank_account_label";
2093 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
2094 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
2095 $sql .=
" WHERE b.fk_account = ba.rowid";
2096 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
2098 $sql .=
" AND b.num_chq='".$this->db->escape($num).
"'";
2100 $sql .=
" AND b.rowid='".$this->db->escape($ref).
"'";
2102 $sql .=
" AND b.rowid = ".((int) $rowid);
2105 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
2106 $result = $this->db->query($sql);
2110 $obj = $this->db->fetch_object($result);
2112 $this->
id = $obj->rowid;
2113 $this->
rowid = $obj->rowid;
2114 $this->
ref = $obj->rowid;
2116 $this->datec = $obj->datec;
2117 $this->datev = $obj->datev;
2118 $this->dateo = $obj->dateo;
2119 $this->amount = $obj->amount;
2120 $this->label = $obj->label;
2121 $this->note = $obj->note;
2123 $this->fk_user_author = $obj->fk_user_author;
2124 $this->fk_user_rappro = $obj->fk_user_rappro;
2126 $this->fk_type = $obj->fk_type;
2127 $this->rappro = $obj->rappro;
2128 $this->num_releve = $obj->num_releve;
2130 $this->num_chq = $obj->num_chq;
2131 $this->bank_chq = $obj->banque;
2132 $this->fk_bordereau = $obj->fk_bordereau;
2134 $this->fk_account = $obj->fk_account;
2135 $this->bank_account_ref = $obj->bank_account_ref;
2136 $this->bank_account_label = $obj->bank_account_label;
2144 $this->db->free($result);
2162 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank (";
2168 $sql .=
", amount_main_currency";
2169 $sql .=
", fk_user_author";
2170 $sql .=
", num_chq";
2171 $sql .=
", fk_account";
2172 $sql .=
", fk_type";
2173 $sql .=
", emetteur,banque";
2175 $sql .=
", numero_compte";
2176 $sql .=
", num_releve";
2177 $sql .=
") VALUES (";
2178 $sql .=
"'".$this->db->idate($this->datec).
"'";
2179 $sql .=
", '".$this->db->idate($this->dateo).
"'";
2180 $sql .=
", '".$this->db->idate($this->datev).
"'";
2181 $sql .=
", '".$this->db->escape($this->label).
"'";
2182 $sql .=
", ".price2num($this->amount);
2183 $sql .=
", ".(empty($this->amount_main_currency) ?
"NULL" :
price2num($this->amount_main_currency));
2184 $sql .=
", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) :
"null");
2185 $sql .=
", ".($this->num_chq ?
"'".$this->db->escape($this->num_chq).
"'" :
"null");
2186 $sql .=
", '".$this->db->escape($this->fk_account).
"'";
2187 $sql .=
", '".$this->db->escape($this->fk_type).
"'";
2188 $sql .=
", ".($this->emetteur ?
"'".$this->db->escape($this->emetteur).
"'" :
"null");
2189 $sql .=
", ".($this->bank_chq ?
"'".$this->db->escape($this->bank_chq).
"'" :
"null");
2190 $sql .=
", ".(int) $this->rappro;
2191 $sql .=
", ".($this->numero_compte ?
"'".$this->db->escape($this->numero_compte).
"'" :
"''");
2192 $sql .=
", ".($this->num_releve ?
"'".$this->db->escape($this->num_releve).
"'" :
"null");
2195 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2196 $resql = $this->db->query($sql);
2198 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'bank');
2206 $this->error = $this->db->lasterror();
2211 $this->db->commit();
2214 $this->db->rollback();
2225 public function delete(
User $user =
null)
2231 if ($this->rappro) {
2233 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2240 if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING)) {
2241 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2242 $resql = $this->db->query($sql);
2244 $obj = $this->db->fetch_object($resql);
2245 if ($obj && $obj->nb) {
2246 $this->error =
'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2247 $this->db->rollback();
2251 $this->error = $this->db->lasterror();
2252 $this->db->rollback();
2263 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class WHERE lineid=".(int) $this->
rowid;
2264 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2265 $result = $this->db->query($sql);
2270 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_extrafields WHERE fk_object=".(int) $this->
rowid;
2271 $result = $this->db->query($sql);
2276 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid=".(int) $this->
rowid;
2277 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2278 $result = $this->db->query($sql);
2284 $this->db->commit();
2287 $this->db->rollback();
2305 if ($this->rappro) {
2307 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2313 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url WHERE fk_bank=".(int) $this->
rowid;
2314 dol_syslog(get_class($this).
"::delete_urls", LOG_DEBUG);
2315 $result = $this->db->query($sql);
2321 $this->db->commit();
2324 $this->db->rollback();
2341 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2342 $sql .=
" amount = ".price2num($this->amount).
",";
2343 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
2344 $sql .=
" dateo='".$this->db->idate($this->dateo).
"'";
2345 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
2347 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2348 $resql = $this->db->query($sql);
2350 $this->db->commit();
2353 $this->db->rollback();
2354 $this->error = $this->db->error();
2372 global $conf, $langs;
2377 if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE)) {
2378 if (!preg_match(
'/'.$conf->global->BANK_STATEMENT_REGEX_RULE.
'/', $this->num_releve)) {
2379 $this->errors[] = $langs->trans(
"ErrorBankStatementNameMustFollowRegex", $conf->global->BANK_STATEMENT_REGEX_RULE);
2384 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2385 $sql .=
" rappro = ".((int) $conciliated);
2386 $sql .=
", num_releve = '".$this->db->escape($this->num_releve).
"'";
2388 $sql .=
", fk_user_rappro = ".$user->id;
2390 $sql .=
" WHERE rowid = ".((int) $this->
id);
2392 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2393 $resql = $this->db->query($sql);
2395 if (!empty($cat) && $cat > 0) {
2396 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class (";
2398 $sql .=
", fk_categ";
2399 $sql .=
") VALUES (";
2401 $sql .=
", ".((int) $cat);
2404 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2405 $this->db->query($sql);
2413 $this->db->commit();
2416 $this->db->rollback();
2433 $sql =
"SELECT datev FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2434 $resql = $this->db->query($sql);
2436 $obj = $this->db->fetch_object($resql);
2437 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2439 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2440 $sql .=
" datev = '".$this->db->idate($newdate).
"'";
2441 $sql .=
" WHERE rowid = ".((int) $rowid);
2443 $result = $this->db->query($sql);
2445 if ($this->db->affected_rows($result)) {
2496 $sql =
"SELECT dateo FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2497 $resql = $this->db->query($sql);
2499 $obj = $this->db->fetch_object($resql);
2500 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2502 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2503 $sql .=
" dateo = '".$this->db->idate($newdate).
"'";
2504 $sql .=
" WHERE rowid = ".((int) $rowid);
2506 $result = $this->db->query($sql);
2508 if ($this->db->affected_rows($result)) {
2556 $sql =
'SELECT b.rowid, b.datec, b.tms as datem,';
2557 $sql .=
' b.fk_user_author, b.fk_user_rappro';
2558 $sql .=
' FROM '.MAIN_DB_PREFIX.
'bank as b';
2559 $sql .=
' WHERE b.rowid = '.((int) $id);
2561 $result = $this->db->query($sql);
2563 if ($this->db->num_rows($result)) {
2564 $obj = $this->db->fetch_object($result);
2565 $this->
id = $obj->rowid;
2567 if ($obj->fk_user_author) {
2568 $cuser =
new User($this->db);
2569 $cuser->fetch($obj->fk_user_author);
2570 $this->user_creation = $cuser;
2572 if ($obj->fk_user_rappro) {
2573 $ruser =
new User($this->db);
2574 $ruser->fetch($obj->fk_user_rappro);
2575 $this->user_rappro = $ruser;
2578 $this->date_creation = $this->db->jdate($obj->datec);
2579 $this->date_modification = $this->db->jdate($obj->datem);
2582 $this->db->free($result);
2598 public function getNomUrl($withpicto = 0, $maxlen = 0, $option =
'', $notooltip = 0)
2600 global $conf, $langs;
2604 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"BankTransactionLine").
'</u>:<br>';
2605 $label .=
'<b>'.$langs->trans(
"Ref").
':</b> '.$this->ref;
2606 if ($this->amount) {
2607 $label .=
'<br><strong>'.$langs->trans(
"Amount").
':</strong> '.
price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2610 $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">';
2613 $result .= $linkstart;
2615 $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);
2617 if ($withpicto != 2) {
2618 $result .= ($this->
ref ? $this->
ref : $this->id);
2621 $result .= $linkend;
2623 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2624 $result .=
' <span class="opacitymedium">(';
2626 if ($option ==
'showall') {
2627 $result .= $langs->trans(
"BankAccount").
': ';
2628 $accountstatic =
new Account($this->db);
2629 $accountstatic->id = $this->fk_account;
2630 $accountstatic->ref = $this->bank_account_ref;
2631 $accountstatic->label = $this->bank_account_label;
2632 $result .= $accountstatic->getNomUrl(0).
', ';
2634 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2635 $result .= $langs->trans(
"BankLineConciliated").
': ';
2636 $result .=
yn($this->rappro);
2638 if (isModEnabled(
'accounting') && ($option ==
'showall' || $option ==
'showconciliatedandaccounted')) {
2639 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
2640 $sql .=
" WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2641 $resql = $this->db->query($sql);
2643 $obj = $this->db->fetch_object($resql);
2644 if ($obj && $obj->nb) {
2645 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(1);
2647 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(0);
2651 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2652 $result .=
')</span>';
2667 return $this->
LibStatut($this->status, $mode);
2727 $alreadydispatched = 0;
2731 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->
id);
2732 $resql = $this->db->query($sql);
2734 $obj = $this->db->fetch_object($resql);
2736 $alreadydispatched = $obj->nb;
2739 $this->error = $this->db->lasterror();
2743 if ($alreadydispatched) {
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
checkIbanForAccount(Account $account)
Check IBAN number informations for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current sold.
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 clicable name (with picto eventually)
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
static replaceThirdparty($dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
update(User $user, $notrigger=0)
Update bank account card.
getCountryCode()
Return account country code.
needIBAN()
Return 1 if IBAN / BIC is mandatory (otherwise option)
getLibStatut($mode=0)
Return label of object status.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
__toString()
Shows the account number in the appropriate format.
const TYPE_SAVINGS
Savings account.
useDetailedBBAN()
Return if a bank account is defined with detailed information (bank code, desk code,...
static getAccountNumberOrder()
Returns the components of the bank account in order.
load_state_board($filteraccountid=0)
Charge indicateurs this->nb de tableau de bord.
getTooltipContentArray($params)
getTooltipContentArray
canBeConciliated()
Return if a bank account need to be conciliated.
create(User $user, $notrigger=0)
Create bank account into database.
can_be_deleted()
Renvoi si un compte peut etre supprimer ou non (sans mouvements)
update_bban(User $user=null)
Update BBAN (RIB) account fields.
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.
initAsSpecimen()
Initialise an instance with random values.
get_url($fk_bank='', $url_id='', $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
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)
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null)
Add an entry into table ".MAIN_DB_PREFIX."bank.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
info($id)
Load miscellaneous information for tab "Info".
__construct(DoliDB $db)
Constructor.
update_conciliation(User $user, $cat, $conciliated=1)
Update conciliation field.
getLibStatut($mode=0)
Return the label of the status.
fetch($rowid, $ref='', $num='')
Load into memory content of a bank transaction line.
dateo_change($rowid, $sign=1)
Increase/decrease operation date of a rowid.
datev_next($id)
Increase value date of a rowid.
LibStatut($status, $mode=0)
Return the label of a given status.
update(User $user, $notrigger=0)
Update bank account record in database.
insert()
Inserts a transaction to a bank account.
getNomUrl($withpicto=0, $maxlen=0, $option='', $notooltip=0)
Return clickable name (with picto eventually)
delete_urls(User $user=null)
Delete bank line records.
getVentilExportCompta()
Return if a bank line was dispatched into bookkeeping.
datev_change($rowid, $sign=1)
Increase/decrease value date of a rowid.
dateo_previous($id)
Decrease operation date of a rowid.
dateo_next($id)
Increase operation date of a rowid.
datev_previous($id)
Decrease value date of a rowid.
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...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type