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;
194 public $type_lib = array();
201 public $status = array();
207 public $account_number;
212 public $fk_accountancy_journal;
216 public $accountancy_journal;
222 public $currency_code;
229 public $account_currency_code;
279 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"),
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)) {
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 = 0, $url_id = 0, $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"));
712 $balance = $this->balance;
713 if (empty($balance) && !empty($this->
solde)) {
714 $balance = $this->solde;
716 if (empty($balance)) {
720 if (empty($this->address && !empty($this->domiciliation))) {
721 dol_syslog(get_class($this).
"::create domiciliation is deprecated use address", LOG_NOTICE);
722 $this->address = $this->domiciliation;
726 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
732 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
737 $sql .=
", account_number";
738 $sql .=
", fk_accountancy_journal";
740 $sql .=
", code_banque";
741 $sql .=
", code_guichet";
745 $sql .=
", iban_prefix";
746 $sql .=
", domiciliation";
747 $sql .=
", pti_in_ctti";
749 $sql .=
", owner_address";
750 $sql .=
", owner_zip";
751 $sql .=
", owner_town";
752 $sql .=
", owner_country_id";
753 $sql .=
", currency_code";
755 $sql .=
", min_allowed";
756 $sql .=
", min_desired";
758 $sql .=
", state_id";
761 $sql .=
", ics_transfer";
762 $sql .=
") VALUES (";
763 $sql .=
"'".$this->db->idate($now).
"'";
764 $sql .=
", '".$this->db->escape($this->
ref).
"'";
765 $sql .=
", '".$this->db->escape($this->label).
"'";
766 $sql .=
", ".((int) $conf->entity);
767 $sql .=
", '".$this->db->escape($this->account_number).
"'";
768 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
769 $sql .=
", '".$this->db->escape($this->bank).
"'";
770 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
771 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
772 $sql .=
", '".$this->db->escape($this->number).
"'";
773 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
774 $sql .=
", '".$this->db->escape($this->bic).
"'";
775 $sql .=
", '".$this->db->escape($this->iban).
"'";
776 $sql .=
", '".$this->db->escape($this->address).
"'";
777 $sql .=
", ".((int) $this->pti_in_ctti);
778 $sql .=
", '".$this->db->escape($this->proprio).
"'";
779 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
780 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
781 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
782 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
783 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
784 $sql .=
", ".((int) $this->rappro);
785 $sql .=
", ".price2num($this->min_allowed,
'MT');
786 $sql .=
", ".price2num($this->min_desired,
'MT');
787 $sql .=
", '".$this->db->escape($this->comment).
"'";
788 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
789 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
790 $sql .=
", '".$this->db->escape($this->ics).
"'";
791 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
794 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
795 $resql = $this->db->query($sql);
797 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
799 $result = $this->
update($user, 1);
802 $accline->datec = $now;
803 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
805 $accline->fk_user_author = $user->id;
806 $accline->fk_account = $this->id;
807 $accline->datev = $this->date_solde;
808 $accline->dateo = $this->date_solde;
809 $accline->fk_type =
'SOLD';
811 if ($accline->insert() < 0) {
813 $this->
error = $accline->error;
814 $this->errors = $accline->errors;
824 if (!$error && !$notrigger) {
826 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
836 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
837 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
840 $this->
error = $this->db->error().
" sql=".$sql;
849 $this->db->rollback();
863 global $langs, $conf;
870 if (empty($this->country_id)) {
871 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
875 if (empty($this->
ref)) {
876 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
881 $this->label =
"???";
884 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
886 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
887 $sql .=
",label = '".$this->db->escape($this->label).
"'";
889 $sql .=
",courant = ".((int) $this->courant);
890 $sql .=
",clos = ".((int) $this->clos);
891 $sql .=
",rappro = ".((int) $this->rappro);
892 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
893 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
894 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
895 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
896 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
897 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
898 $sql .=
",number='".$this->db->escape($this->number).
"'";
899 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
900 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
901 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
902 $sql .=
",domiciliation='".$this->db->escape($this->address).
"'";
903 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
904 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
905 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
906 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
907 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
908 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
910 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
912 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
913 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
914 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
916 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
917 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
918 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
919 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
921 $sql .=
" WHERE rowid = ".((int) $this->
id);
923 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
924 $result = $this->db->query($sql);
934 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
935 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
936 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type='bank_account' and entity = ".((int) $conf->entity);
937 $resql = $this->db->query($sql);
940 $this->
error = $this->db->lasterror();
946 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
947 $dirdest = $conf->bank->dir_output.
'/'.$newref;
948 if (file_exists($dirsource)) {
949 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
950 if (@rename($dirsource, $dirdest)) {
956 if (!$error && !$notrigger) {
958 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
966 $this->
error = $this->db->lasterror();
974 $this->db->rollback();
990 global $conf, $langs;
993 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
995 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
999 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1003 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
1004 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1005 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1006 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1007 $sql .=
",number='".$this->db->escape($this->number).
"'";
1008 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1009 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1010 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1011 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
1012 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
1013 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1014 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1015 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1016 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1017 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1018 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1019 $sql .=
" WHERE rowid = ".((int) $this->
id);
1020 $sql .=
" AND entity = ".((int) $conf->entity);
1022 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1024 $result = $this->db->query($sql);
1028 $this->
error = $this->db->lasterror();
1044 if (empty($id) && empty($ref)) {
1045 $this->
error =
"ErrorBadParameters";
1049 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
1050 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1051 $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,";
1052 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1053 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1054 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1055 $sql .=
' c.code as country_code, c.label as country,';
1056 $sql .=
' d.code_departement as state_code, d.nom as state,';
1057 $sql .=
' aj.code as accountancy_journal';
1058 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1059 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1060 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1061 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1062 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1064 $sql .=
" AND ba.rowid = ".((int) $id);
1067 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1070 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1071 $result = $this->db->query($sql);
1073 if ($this->db->num_rows($result)) {
1074 $obj = $this->db->fetch_object($result);
1076 $this->
id = $obj->rowid;
1077 $this->
rowid = $obj->rowid;
1078 $this->
ref = $obj->ref;
1079 $this->label = $obj->label;
1080 $this->
type = $obj->courant;
1081 $this->courant = $obj->courant;
1082 $this->bank = $obj->bank;
1083 $this->clos = $obj->clos;
1084 $this->rappro = $obj->rappro;
1085 $this->url = $obj->url;
1087 $this->code_banque = $obj->code_banque;
1088 $this->code_guichet = $obj->code_guichet;
1089 $this->number = $obj->number;
1090 $this->cle_rib = $obj->cle_rib;
1091 $this->bic = $obj->bic;
1092 $this->iban = $obj->iban;
1093 $this->domiciliation = $obj->address;
1094 $this->address = $obj->address;
1095 $this->pti_in_ctti = $obj->pti_in_ctti;
1096 $this->proprio = $obj->proprio;
1097 $this->owner_address = $obj->owner_address;
1098 $this->owner_zip = $obj->owner_zip;
1099 $this->owner_town = $obj->owner_town;
1100 $this->owner_country_id = $obj->owner_country_id;
1102 $this->state_id = $obj->state_id;
1103 $this->state_code = $obj->state_code;
1104 $this->state = $obj->state;
1106 $this->country_id = $obj->country_id;
1107 $this->country_code = $obj->country_code;
1108 $this->country = $obj->country;
1110 $this->account_number = $obj->account_number;
1111 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1112 $this->accountancy_journal = $obj->accountancy_journal;
1114 $this->currency_code = $obj->currency_code;
1115 $this->account_currency_code = $obj->currency_code;
1116 $this->min_allowed = $obj->min_allowed;
1117 $this->min_desired = $obj->min_desired;
1118 $this->comment = $obj->comment;
1120 $this->date_creation = $this->db->jdate($obj->date_creation);
1121 $this->date_modification = $this->db->jdate($obj->date_modification);
1124 $this->ics = $obj->ics;
1125 $this->ics_transfer = $obj->ics_transfer;
1136 $this->
error = $this->db->lasterror();
1137 $this->errors[] = $this->error;
1154 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1155 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1164 public function delete(
User $user =
null)
1174 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1175 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1177 $resql = $this->db->query($sql);
1180 $this->
error =
"Error ".$this->db->lasterror();
1185 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1186 $sql .=
" WHERE rowid = ".((int) $this->
id);
1188 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1189 $result = $this->db->query($sql);
1196 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1201 $this->
error =
"Error ".$this->db->lasterror();
1206 $this->db->commit();
1209 $this->db->rollback();
1223 return $this->
LibStatut($this->clos, $mode);
1238 $langs->load(
'banks');
1240 if ($status == self::STATUS_OPEN) {
1241 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1242 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1243 $statusType =
'status4';
1245 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1246 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1247 $statusType =
'status5';
1250 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1263 $can_be_deleted =
false;
1265 $sql =
"SELECT COUNT(rowid) as nb";
1266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1267 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1269 $resql = $this->db->query($sql);
1271 $obj = $this->db->fetch_object($resql);
1272 if ($obj->nb <= 1) {
1273 $can_be_deleted =
true;
1278 return $can_be_deleted;
1289 return $this->error;
1300 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1304 $sql =
"SELECT sum(amount) as amount";
1305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1306 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1308 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1311 $resql = $this->db->query($sql);
1313 if ($this->db->num_rows($resql)) {
1314 $obj = $this->db->fetch_object($resql);
1315 $solde = $obj->amount;
1317 $this->db->free($resql);
1319 $this->errors[] = $this->db->lasterror;
1337 global $conf, $langs;
1343 $sql =
"SELECT b.rowid, b.datev as datefin";
1344 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1345 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1346 $sql .=
" WHERE b.rappro=0";
1347 $sql .=
" AND b.fk_account = ba.rowid";
1348 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1349 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1350 $sql .=
" AND clos = 0";
1351 if ($filteraccountid) {
1352 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1355 $resql = $this->db->query($sql);
1357 $langs->load(
"banks");
1360 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1363 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1364 $response->label = $langs->trans(
"TransactionsToConciliate");
1365 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1366 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1369 while ($obj = $this->db->fetch_object($resql)) {
1370 $response->nbtodo++;
1371 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1372 $response->nbtodolate++;
1379 $this->
error = $this->db->error();
1400 $sql =
"SELECT count(b.rowid) as nb";
1401 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1402 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1403 $sql .=
" WHERE b.fk_account = ba.rowid";
1404 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1405 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1406 $sql .=
" AND clos = 0";
1407 if ($filteraccountid) {
1408 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1411 $resql = $this->db->query($sql);
1413 while ($obj = $this->db->fetch_object($resql)) {
1414 $this->nb[
"banklines"] = $obj->nb;
1416 $this->db->free($resql);
1420 $this->
error = $this->db->error();
1433 global $db, $conf, $user;
1442 $sql =
"SELECT COUNT(ba.rowid) as nb";
1443 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1444 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1445 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1447 $sql .=
" AND ba.courant != 2";
1449 $resql = $this->db->query($sql);
1451 $obj = $this->db->fetch_object($resql);
1470 $langs->loadLangs([
'banks',
'compta']);
1471 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1475 $nofetch = !empty($params[
'nofetch']);
1476 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1477 if (isset($this->
status)) {
1478 $pictos .=
' '.$this->getLibStatut(5);
1480 $datas[
'picto'] = $pictos;
1481 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1482 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1484 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1485 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1487 if (isModEnabled(
'accounting')) {
1488 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1489 $langs->load(
"accountancy");
1490 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1491 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1494 if (isModEnabled(
'categorie') && !$nofetch) {
1495 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1496 $form =
new Form($this->db);
1497 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1514 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1516 global $conf, $langs;
1518 if (!empty($conf->dol_no_mouse_hover)) {
1522 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1525 $classfortooltip =
'classfortooltip';
1529 'objecttype' => $this->element,
1530 'option' => $option,
1534 $classfortooltip =
'classforajaxtooltip';
1535 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1541 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1542 if ($mode ==
'transactions') {
1543 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1544 } elseif ($mode ==
'receipts') {
1545 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1548 if ($option !=
'nolink') {
1550 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1551 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1552 $add_save_lastsearch_values = 1;
1554 if ($add_save_lastsearch_values) {
1555 $url .=
'&save_lastsearch_values=1';
1560 if (empty($notooltip)) {
1562 $label = $langs->trans(
"BankAccount");
1563 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1565 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1566 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1568 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1571 if ($option ==
'nolink' || empty($url)) {
1572 $linkstart =
'<span';
1574 $linkstart =
'<a href="'.$url.
'"';
1576 $linkstart .= $linkclose.
'>';
1577 if ($option ==
'nolink' || empty($url)) {
1578 $linkend =
'</span>';
1583 $result .= $linkstart;
1586 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1588 if ($withpicto != 2) {
1589 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1591 $result .= $linkend;
1607 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1614 $this->
error =
'IBANNotValid';
1618 $this->
error =
'SwiftNotValid';
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;
1678 global $conf, $langs;
1685 if (!empty($conf->use_javascript_ajax)) {
1687 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1688 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1691 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1711 public function useDetailedBBAN()
1713 $country_code = $this->getCountryCode();
1715 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1716 return 1; // France, Spain, Gabon, ... - Not valid for CH
1718 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1719 return 2; // Australia, England...
1729 public function needIBAN()
1733 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1737 $country_code = $this->getCountryCode();
1739 $country_code_in_EEC = array(
1744 'CZ', // Czech republic
1751 'GB', // United Kingdom
1757 'IM', // Isle of Man - Included in UK
1762 'MC', // Monaco - Included in France
1771 'UK', // United Kingdom
1772 //'CH', // Switzerland - No. Swizerland in not in EEC
1775 if (in_array($country_code, $country_code_in_EEC)) {
1776 return 1; // France, Spain, ...
1787 public function info($id)
1805 public function getFieldsToShow($includeibanbic = 0)
1807 //Get the required properties depending on the country
1808 $detailedBBAN = $this->useDetailedBBAN();
1810 if ($detailedBBAN == 0) {
1811 $fieldarray = array(
1814 } elseif ($detailedBBAN == 2) {
1815 $fieldarray = array(
1820 $fieldarray = self::getAccountNumberOrder();
1823 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1824 if ($includeibanbic) {
1825 $fieldarray[] = 'IBAN';
1826 $fieldarray[] = 'BIC';
1830 //Get the order the properties are shown
1844 public static function getAccountNumberOrder()
1848 $fieldlists = array(
1851 'BankAccountNumber',
1852 'BankAccountNumberKey'
1855 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1856 if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1857 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1858 $fieldlists = array(
1861 'BankAccountNumberKey',
1866 //Replace the old AccountNumber key with the new BankAccountNumber key
1867 $fieldlists = explode(
1869 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1885 public function initAsSpecimen()
1887 // Example of IBAN FR7630001007941234567890185
1888 $this->specimen = 1;
1890 $this->label = 'My Big Company Bank account';
1891 $this->bank = 'MyBank';
1892 $this->courant = Account::TYPE_CURRENT;
1893 $this->clos = Account::STATUS_OPEN;
1894 $this->code_banque = '30001';
1895 $this->code_guichet = '00794';
1896 $this->number = '12345678901';
1897 $this->cle_rib = '85';
1898 $this->bic = 'AA12';
1899 $this->iban = 'FR7630001007941234567890185';
1900 $this->domiciliation = 'Banque de France';
1901 $this->proprio = 'Owner';
1902 $this->owner_address = 'Owner address';
1903 $this->owner_zip = 'Owner zip';
1904 $this->owner_town = 'Owner town';
1905 $this->owner_country_id = 'Owner country_id';
1906 $this->country_id = 1;
1917 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
1919 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type=
'company'";
1921 if ($dbs->query($sql)) {
1924 //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.
1925 //$this->errors = $dbs->lasterror();
1937 public function getKanbanView($option = '', $arraydata = null)
1941 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1943 $return = '<div class="box-flex-item box-flex-grow-zero
">';
1944 $return .= '<div class="info-box
info-box-sm
">';
1945 $return .= '<span class="info-box-icon bg-infobox-action
">';
1946 $return .= img_picto('', $this->picto);
1947 $return .= '</span>';
1948 $return .= '<div class="info-box-content
">';
1949 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1950 if ($selected >= 0) {
1951 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
1953 if (property_exists($this, 'type_lib')) {
1954 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
1956 if (method_exists($this, 'solde')) {
1957 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
1958 $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>';
1960 if (method_exists($this, 'getLibStatut')) {
1961 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
1963 $return .= '</div>';
1964 $return .= '</div>';
1965 $return .= '</div>';
1971require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
1976class AccountLine extends CommonObjectLine
1991 public $element = 'bank';
1996 public $table_element = 'bank';
2001 public $picto = 'accountline';
2034 public $amount; /* Amount of payment in the bank account currency */
2035 public $amount_main_currency; /* Amount in the currency of company if bank account use another currency */
2040 public $fk_user_author;
2045 public $fk_user_rappro;
2055 public $fk_bordereau;
2065 public $bank_account_ref;
2070 public $bank_account_label;
2075 public $numero_compte;
2082 public $rappro; // Is it conciliated
2083 public $num_releve; // If conciliated, what is bank statement
2084 public $num_chq; // Num of cheque
2085 public $bank_chq; // Bank of cheque
2097 public $user_rappro;
2105 public function __construct(DoliDB $db)
2118 public function fetch($rowid, $ref = '', $num = '')
2121 if (empty($rowid) && empty($ref) && empty($num)) {
2125 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2126 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2127 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2128 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2129 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2130 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2131 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2132 $sql .= " WHERE b.fk_account = ba.rowid
";
2133 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2135 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2137 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2139 $sql .= " AND b.rowid =
".((int) $rowid);
2142 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2143 $result = $this->db->query($sql);
2147 $obj = $this->db->fetch_object($result);
2149 $this->id = $obj->rowid;
2150 $this->rowid = $obj->rowid;
2151 $this->ref = $obj->rowid;
2153 $this->datec = $this->db->jdate($obj->datec);
2154 $this->datev = $this->db->jdate($obj->datev);
2155 $this->dateo = $this->db->jdate($obj->dateo);
2156 $this->amount = $obj->amount;
2157 $this->label = $obj->label;
2158 $this->note = $obj->note;
2160 $this->fk_user_author = $obj->fk_user_author;
2161 $this->fk_user_rappro = $obj->fk_user_rappro;
2163 $this->fk_type = $obj->fk_type; // Type of transaction
2164 $this->rappro = (int) $obj->rappro;
2165 $this->num_releve = $obj->num_releve;
2167 $this->num_chq = $obj->num_chq;
2168 $this->bank_chq = $obj->banque;
2169 $this->fk_bordereau = $obj->fk_bordereau;
2171 $this->fk_account = $obj->fk_account;
2172 $this->bank_account_ref = $obj->bank_account_ref;
2173 $this->bank_account_label = $obj->bank_account_label;
2175 // Retrieve all extrafield
2176 // fetch optionals attributes and labels
2177 $this->fetch_optionals();
2181 $this->db->free($result);
2193 public function insert()
2199 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2205 $sql .= ", amount_main_currency
";
2206 $sql .= ", fk_user_author
";
2207 $sql .= ", num_chq
";
2208 $sql .= ", fk_account
";
2209 $sql .= ", fk_type
";
2210 $sql .= ", emetteur,banque
";
2212 $sql .= ", numero_compte
";
2213 $sql .= ", num_releve
";
2214 $sql .= ") VALUES (
";
2215 $sql .= "'".$this->db->idate($this->datec)."'";
2216 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2217 $sql .= ",
'".$this->db->idate($this->datev)."'";
2218 $sql .= ",
'".$this->db->escape($this->label)."'";
2219 $sql .= ",
".price2num($this->amount);
2220 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2221 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2222 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2223 $sql .= ",
'".$this->db->escape($this->fk_account)."'";
2224 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2225 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2226 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2227 $sql .= ",
".(int) $this->rappro;
2228 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2229 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2233 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2234 $resql = $this->db->query($sql);
2236 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2237 // Actions on extra fields (by external module or standard code)
2238 $result = $this->insertExtraFields();
2244 $this->error = $this->db->lasterror();
2245 dol_print_error($this->db);
2249 $this->db->commit();
2252 $this->db->rollback();
2264 public function delete(User $user = null, $notrigger = 0)
2268 if ($this->rappro) {
2269 // Protection to avoid any delete of consolidated lines
2270 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2278 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2280 $this->db->rollback();
2283 // End call triggers
2286 // Protection to avoid any delete of accounted lines. Protection on by default
2287 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2288 $sql = "SELECT COUNT(
rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2289 $resql = $this->db->query($sql);
2291 $obj = $this->db->fetch_object($resql);
2292 if ($obj && $obj->nb) {
2293 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2294 $this->db->rollback();
2298 $this->error = $this->db->lasterror();
2299 $this->db->rollback();
2305 $result = $this->delete_urls($user);
2310 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_class WHERE lineid=
".(int) $this->rowid;
2311 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2312 $result = $this->db->query($sql);
2317 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2318 $result = $this->db->query($sql);
2323 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE
rowid=
".(int) $this->rowid;
2324 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2325 $result = $this->db->query($sql);
2331 $this->db->commit();
2334 $this->db->rollback();
2340 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2347 public function delete_urls(User $user = null)
2352 if ($this->rappro) {
2353 // Protection to avoid any delete of consolidated lines
2354 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2360 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2361 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2362 $result = $this->db->query($sql);
2368 $this->db->commit();
2371 $this->db->rollback();
2384 public function update(User $user, $notrigger = 0)
2388 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2389 $sql .= " amount =
".price2num($this->amount).",
";
2390 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2391 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2392 $sql .= " WHERE
rowid =
".((int) $this->rowid);
2394 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2395 $resql = $this->db->query($sql);
2397 $this->db->commit();
2400 $this->db->rollback();
2401 $this->error = $this->db->error();
2407 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2416 public function update_conciliation(User $user, $cat, $conciliated = 1)
2419 global $conf, $langs;
2423 // Check statement field
2424 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2425 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2426 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", $conf->global->BANK_STATEMENT_REGEX_RULE);
2431 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2432 $sql .= " rappro =
".((int) $conciliated);
2433 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2435 $sql .= ", fk_user_rappro =
".$user->id;
2437 $sql .= " WHERE
rowid =
".((int) $this->id);
2439 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2440 $resql = $this->db->query($sql);
2442 if (!empty($cat) && $cat > 0) {
2443 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank_class (
";
2445 $sql .= ", fk_categ
";
2446 $sql .= ") VALUES (
";
2448 $sql .= ",
".((int) $cat);
2451 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2452 $this->db->query($sql);
2454 // No error check. Can fail if category already affected
2455 // TODO Do no try the insert if link already exists
2460 $this->db->commit();
2463 $this->db->rollback();
2469 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2477 public function datev_change($rowid, $sign = 1)
2480 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE
rowid =
".((int) $rowid);
2481 $resql = $this->db->query($sql);
2483 $obj = $this->db->fetch_object($resql);
2484 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2486 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2487 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2488 $sql .= " WHERE
rowid =
".((int) $rowid);
2490 $result = $this->db->query($sql);
2492 if ($this->db->affected_rows($result)) {
2496 dol_print_error($this->db);
2500 dol_print_error($this->db);
2505 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2512 public function datev_next($id)
2515 return $this->datev_change($id, 1);
2518 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2525 public function datev_previous($id)
2528 return $this->datev_change($id, -1);
2532 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2540 public function dateo_change($rowid, $sign = 1)
2543 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE
rowid =
".((int) $rowid);
2544 $resql = $this->db->query($sql);
2546 $obj = $this->db->fetch_object($resql);
2547 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2549 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2550 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2551 $sql .= " WHERE
rowid =
".((int) $rowid);
2553 $result = $this->db->query($sql);
2555 if ($this->db->affected_rows($result)) {
2559 dol_print_error($this->db);
2563 dol_print_error($this->db);
2568 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2575 public function dateo_next($id)
2578 return $this->dateo_change($id, 1);
2581 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2588 public function dateo_previous($id)
2591 return $this->dateo_change($id, -1);
2601 public function info($id)
2603 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2604 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2605 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2606 $sql .= ' WHERE b.rowid = '.((int) $id);
2608 $result = $this->db->query($sql);
2610 if ($this->db->num_rows($result)) {
2611 $obj = $this->db->fetch_object($result);
2613 $this->id = $obj->rowid;
2615 $this->user_creation_id = $obj->fk_user_author;
2616 $this->user_rappro = $obj->fk_user_rappro;
2617 $this->date_creation = $this->db->jdate($obj->datec);
2618 $this->date_modification = $this->db->jdate($obj->datem);
2619 //$this->date_rappro = $obj->daterappro; // Not yet managed
2621 $this->db->free($result);
2623 dol_print_error($this->db);
2637 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2639 global $conf, $langs;
2643 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2644 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2645 if ($this->amount) {
2646 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2649 $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
">';
2652 $result .= $linkstart;
2654 $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);
2656 if ($withpicto != 2) {
2657 $result .= ($this->ref ? $this->ref : $this->id);
2660 $result .= $linkend;
2662 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2663 $result .= ' <span class="opacitymedium
">(';
2665 if ($option == 'showall') {
2666 $result .= $langs->trans("BankAccount
").': ';
2667 $accountstatic = new Account($this->db);
2668 $accountstatic->id = $this->fk_account;
2669 $accountstatic->ref = $this->bank_account_ref;
2670 $accountstatic->label = $this->bank_account_label;
2671 $result .= $accountstatic->getNomUrl(0).', ';
2673 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2674 $result .= $langs->trans("BankLineConciliated
").': ';
2675 $result .= yn($this->rappro);
2677 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2678 $sql = "SELECT COUNT(
rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2679 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2680 $resql = $this->db->query($sql);
2682 $obj = $this->db->fetch_object($resql);
2683 if ($obj && $obj->nb) {
2684 $result .= ' - '.$langs->trans("Accounted
").': '.yn(1);
2686 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2690 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2691 $result .= ')</span>';
2704 public function getLibStatut($mode = 0)
2706 return $this->LibStatut($this->status, $mode);
2709 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2717 public function LibStatut($status, $mode = 0)
2722 //$langs->load('companies');
2726 if ($status==0) return $langs->trans("ActivityCeased
");
2727 if ($status==1) return $langs->trans("InActivity
");
2731 if ($status==0) return $langs->trans("ActivityCeased
");
2732 if ($status==1) return $langs->trans("InActivity
");
2736 if ($status==0) return img_picto($langs->trans("ActivityCeased
"),'statut5', 'class="pictostatus
"').' '.$langs->trans("ActivityCeased
");
2737 if ($status==1) return img_picto($langs->trans("InActivity
"),'statut4', 'class="pictostatus
"').' '.$langs->trans("InActivity
");
2741 if ($status==0) return img_picto($langs->trans("ActivityCeased
"),'statut5', 'class="pictostatus
"');
2742 if ($status==1) return img_picto($langs->trans("InActivity
"),'statut4', 'class="pictostatus
"');
2746 if ($status==0) return img_picto($langs->trans("ActivityCeased
"),'statut5', 'class="pictostatus
"').' '.$langs->trans("ActivityCeased
");
2747 if ($status==1) return img_picto($langs->trans("InActivity
"),'statut4', 'class="pictostatus
"').' '.$langs->trans("InActivity
");
2751 if ($status==0) return $langs->trans("ActivityCeased
").' '.img_picto($langs->trans("ActivityCeased
"),'statut5', 'class="pictostatus
"');
2752 if ($status==1) return $langs->trans("InActivity
").' '.img_picto($langs->trans("InActivity
"),'statut4', 'class="pictostatus
"');
2763 public function getVentilExportCompta()
2765 $alreadydispatched = 0;
2769 $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);
2770 $resql = $this->db->query($sql);
2772 $obj = $this->db->fetch_object($resql);
2774 $alreadydispatched = $obj->nb;
2777 $this->
error = $this->db->lasterror();
2781 if ($alreadydispatched) {
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
checkSwiftForAccount(Account $account=null, $swift=null)
Check SWIFT informations for a bank account.
checkIbanForAccount(Account $account=null, $ibantocheck=null)
Check IBAN number informations for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
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.
update(User $user, $notrigger=0)
Update bank account card.
getCountryCode()
Return account country code.
getLibStatut($mode=0)
Return label of object status.
getBannerAddress($htmlkey, $object)
Return full address for banner.
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.
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.
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
delete(User $user=null)
Delete bank account from database.
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
get_url($fk_bank=0, $url_id=0, $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null)
Add an entry into table ".MAIN_DB_PREFIX."bank.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a 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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type