35require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
46 public $element =
'bank_account';
51 public $table_element =
'bank_account';
56 public $picto =
'account';
98 public $clos = self::STATUS_OPEN;
122 public $code_guichet;
160 public $pti_in_ctti = 0;
180 public $owner_address;
193 public $owner_country_id;
194 public $owner_country_code;
202 public $domiciliation;
219 public $type_lib = array();
225 public $account_number;
230 public $fk_accountancy_journal;
235 public $accountancy_journal;
241 public $currency_code;
249 public $account_currency_code;
299 public $ics_transfer;
335 public $fields = array(
336 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
337 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 25),
338 'label' => array(
'type' =>
'varchar(30)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
339 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 35,
'index' => 1),
340 'bank' => array(
'type' =>
'varchar(60)',
'label' =>
'Bank',
'enabled' => 1,
'visible' => -1,
'position' => 40),
341 'code_banque' => array(
'type' =>
'varchar(128)',
'label' =>
'Code banque',
'enabled' => 1,
'visible' => -1,
'position' => 45),
342 'code_guichet' => array(
'type' =>
'varchar(6)',
'label' =>
'Code guichet',
'enabled' => 1,
'visible' => -1,
'position' => 50),
343 'number' => array(
'type' =>
'varchar(255)',
'label' =>
'Number',
'enabled' => 1,
'visible' => -1,
'position' => 55),
344 'cle_rib' => array(
'type' =>
'varchar(5)',
'label' =>
'Cle rib',
'enabled' => 1,
'visible' => -1,
'position' => 60),
345 'bic' => array(
'type' =>
'varchar(11)',
'label' =>
'Bic',
'enabled' => 1,
'visible' => -1,
'position' => 65),
346 'iban_prefix' => array(
'type' =>
'varchar(34)',
'label' =>
'Iban prefix',
'enabled' => 1,
'visible' => -1,
'position' => 70),
347 'country_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Country iban',
'enabled' => 1,
'visible' => -1,
'position' => 75),
348 'cle_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Cle iban',
'enabled' => 1,
'visible' => -1,
'position' => 80),
349 'domiciliation' => array(
'type' =>
'varchar(255)',
'label' =>
'Domiciliation',
'enabled' => 1,
'visible' => -1,
'position' => 85),
350 'state_id' => array(
'type' =>
'integer',
'label' =>
'StateId',
'enabled' => 1,
'visible' => -1,
'position' => 90),
351 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 95),
352 'proprio' => array(
'type' =>
'varchar(60)',
'label' =>
'Proprio',
'enabled' => 1,
'visible' => -1,
'position' => 100),
353 'owner_address' => array(
'type' =>
'varchar(255)',
'label' =>
'Owner address',
'enabled' => 1,
'visible' => -1,
'position' => 105),
354 'owner_zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Owner zip',
'enabled' => 1,
'visible' => -1,
'position' => 106),
355 'owner_town' => array(
'type' =>
'varchar(50)',
'label' =>
'Owner town',
'enabled' => 1,
'visible' => -1,
'position' => 107),
356 'owner_country_id' => array(
'type' =>
'integer',
'label' =>
'Owner country',
'enabled' => 1,
'visible' => -1,
'position' => 108),
357 'courant' => array(
'type' =>
'smallint(6)',
'label' =>
'Courant',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 110),
358 'clos' => array(
'type' =>
'smallint(6)',
'label' =>
'Clos',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 115),
359 'rappro' => array(
'type' =>
'smallint(6)',
'label' =>
'Rappro',
'enabled' => 1,
'visible' => -1,
'position' => 120),
360 'url' => array(
'type' =>
'varchar(128)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 125),
361 'account_number' => array(
'type' =>
'varchar(32)',
'label' =>
'Account number',
'enabled' => 1,
'visible' => -1,
'position' => 130),
362 'fk_accountancy_journal' => array(
'type' =>
'integer',
'label' =>
'Accountancy journal ID',
'enabled' => 1,
'visible' => -1,
'position' => 132),
363 'accountancy_journal' => array(
'type' =>
'varchar(20)',
'label' =>
'Accountancy journal',
'enabled' => 1,
'visible' => -1,
'position' => 135),
364 'currency_code' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency code',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 140),
365 'min_allowed' => array(
'type' =>
'integer',
'label' =>
'Min allowed',
'enabled' => 1,
'visible' => -1,
'position' => 145),
366 'min_desired' => array(
'type' =>
'integer',
'label' =>
'Min desired',
'enabled' => 1,
'visible' => -1,
'position' => 150),
367 'comment' => array(
'type' =>
'text',
'label' =>
'Comment',
'enabled' => 1,
'visible' => -1,
'position' => 155),
368 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 156),
369 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 157),
370 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 160),
371 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 165),
372 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 170),
373 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 175),
374 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 180),
375 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 185),
393 const STATUS_OPEN = 0;
394 const STATUS_CLOSED = 1;
408 $this->ismultientitymanaged = 1;
412 $this->type_lib = array(
413 self::TYPE_SAVINGS => $langs->transnoentitiesnoconv(
"BankType0"),
414 self::TYPE_CURRENT => $langs->transnoentitiesnoconv(
"BankType1"),
415 self::TYPE_CASH => $langs->transnoentitiesnoconv(
"BankType2"),
418 $this->labelStatus = array(
419 self::STATUS_OPEN => $langs->transnoentitiesnoconv(
"StatusAccountOpened"),
420 self::STATUS_CLOSED => $langs->transnoentitiesnoconv(
"StatusAccountClosed")
433 if ($val ==
'BankCode') {
434 $string .= $this->code_banque.
' ';
435 } elseif ($val ==
'BankAccountNumber') {
436 $string .= $this->number.
' ';
437 } elseif ($val ==
'DeskCode') {
438 $string .= $this->code_guichet.
' ';
439 } elseif ($val ==
'BankAccountNumberKey') {
440 $string .= $this->cle_rib.
' ';
441 } elseif ($val ==
'BIC') {
442 $string .= $this->bic.
' ';
443 } elseif ($val ==
'IBAN') {
444 $string .= $this->iban.
' ';
448 return trim($string);
461 if (empty($this->rappro)) {
488 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
494 $sql .=
") VALUES (";
495 $sql .= ((int) $line_id);
496 $sql .=
", ".((int) $url_id);
497 $sql .=
", '".$this->db->escape($url).
"'";
498 $sql .=
", '".$this->db->escape($label).
"'";
499 $sql .=
", '".$this->db->escape($type).
"'";
502 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
503 if ($this->db->query($sql)) {
504 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
507 $this->
error = $this->db->lasterror();
522 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
528 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
529 $this->
error =
"ErrorBadParameter";
533 $sql =
"SELECT fk_bank, url_id, url, label, type";
534 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
536 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
538 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
540 $sql .=
" ORDER BY type, label";
542 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
543 $result = $this->db->query($sql);
546 $num = $this->db->num_rows($result);
548 $obj = $this->db->fetch_object($result);
550 $lines[$i][0] = $obj->url;
551 $lines[$i][1] = $obj->url_id;
552 $lines[$i][2] = $obj->label;
553 $lines[$i][3] = $obj->type;
555 $lines[$i][
'url'] = $obj->url;
556 $lines[$i][
'url_id'] = $obj->url_id;
557 $lines[$i][
'label'] = $obj->label;
558 $lines[$i][
'type'] = $obj->type;
559 $lines[$i][
'fk_bank'] = $obj->fk_bank;
587 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
592 if (is_numeric($oper)) {
593 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
596 if (empty($this->
id) && !empty($this->
rowid)) {
597 $this->
id = $this->rowid;
601 $emetteur = trim($emetteur);
602 $banque = trim($banque);
603 $label = trim($label);
607 if (is_numeric($oper)) {
608 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
609 $sql .=
" WHERE id = ".((int) $oper);
610 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
611 $resql = $this->db->query($sql);
613 $obj = $this->db->fetch_object($resql);
623 $this->
error = $langs->trans(
"OperNotDefined");
627 $this->
error = $langs->trans(
"ThisIdNotDefined");
631 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
637 if (is_null($datev) || empty($datev)) {
642 $accline->datec = $now;
643 $accline->dateo = $date;
644 $accline->datev = $datev;
645 $accline->label = $label;
646 $accline->amount = $amount;
647 $accline->amount_main_currency = $amount_main_currency;
648 $accline->fk_user_author = $user->id;
649 $accline->fk_account = $this->id;
650 $accline->fk_type = $oper;
651 $accline->numero_compte = $accountancycode;
652 $accline->num_releve = $num_releve;
655 $accline->num_chq = $num_chq;
659 $accline->emetteur = $emetteur;
663 $accline->bank_chq = $banque;
666 if ($accline->insert() > 0) {
667 if ($categorie > 0) {
668 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
669 $sql .=
"lineid, fk_categ";
670 $sql .=
") VALUES (";
671 $sql .= ((int) $accline->id).
", '".$this->db->escape($categorie).
"'";
674 $result = $this->db->query($sql);
676 $this->
error = $this->db->lasterror();
677 $this->db->rollback();
688 $this->db->rollback();
703 global $langs, $conf;
708 if (!$this->min_allowed) {
709 $this->min_allowed = 0;
711 if (!$this->min_desired) {
712 $this->min_desired = 0;
716 if (empty($this->country_id)) {
717 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
721 if (empty($this->
ref)) {
722 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
726 if (empty($this->date_solde)) {
727 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
733 $balance = $this->balance;
734 if (empty($balance) && !empty($this->
solde)) {
735 $balance = $this->solde;
737 if (empty($balance)) {
740 if (empty($this->address && !empty($this->domiciliation))) {
741 dol_syslog(get_class($this).
"::create domiciliation is deprecated use address", LOG_NOTICE);
742 $this->address = $this->domiciliation;
744 if (empty($this->
status && !empty($this->clos))) {
745 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
746 $this->
status = $this->clos;
749 if (empty($this->address && !empty($this->domiciliation))) {
750 dol_syslog(get_class($this).
"::create domiciliation is deprecated use address", LOG_NOTICE);
751 $this->address = $this->domiciliation;
755 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
761 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
766 $sql .=
", account_number";
767 $sql .=
", fk_accountancy_journal";
769 $sql .=
", code_banque";
770 $sql .=
", code_guichet";
774 $sql .=
", iban_prefix";
775 $sql .=
", domiciliation";
776 $sql .=
", pti_in_ctti";
778 $sql .=
", owner_address";
779 $sql .=
", owner_zip";
780 $sql .=
", owner_town";
781 $sql .=
", owner_country_id";
782 $sql .=
", currency_code";
784 $sql .=
", min_allowed";
785 $sql .=
", min_desired";
787 $sql .=
", state_id";
790 $sql .=
", ics_transfer";
791 $sql .=
") VALUES (";
792 $sql .=
"'".$this->db->idate($now).
"'";
793 $sql .=
", '".$this->db->escape($this->
ref).
"'";
794 $sql .=
", '".$this->db->escape($this->label).
"'";
795 $sql .=
", ".((int) $conf->entity);
796 $sql .=
", '".$this->db->escape($this->account_number).
"'";
797 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
798 $sql .=
", '".$this->db->escape($this->bank).
"'";
799 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
800 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
801 $sql .=
", '".$this->db->escape($this->number).
"'";
802 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
803 $sql .=
", '".$this->db->escape($this->bic).
"'";
804 $sql .=
", '".$this->db->escape($this->iban).
"'";
805 $sql .=
", '".$this->db->escape($this->address).
"'";
806 $sql .=
", ".((int) $this->pti_in_ctti);
807 $sql .=
", '".$this->db->escape($this->owner_name ? $this->owner_name : $this->proprio).
"'";
808 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
809 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
810 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
811 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
812 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
813 $sql .=
", ".((int) $this->rappro);
814 $sql .=
", ".price2num($this->min_allowed,
'MT');
815 $sql .=
", ".price2num($this->min_desired,
'MT');
816 $sql .=
", '".$this->db->escape($this->comment).
"'";
817 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
818 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
819 $sql .=
", '".$this->db->escape($this->ics).
"'";
820 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
823 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
824 $resql = $this->db->query($sql);
826 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
828 $result = $this->
update($user, 1);
831 $accline->datec = $now;
832 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
833 $accline->amount = (float)
price2num($balance);
834 $accline->fk_user_author = $user->id;
835 $accline->fk_account = $this->id;
836 $accline->datev = $this->date_solde;
837 $accline->dateo = $this->date_solde;
838 $accline->fk_type =
'SOLD';
840 if ($accline->insert() < 0) {
842 $this->
error = $accline->error;
843 $this->errors = $accline->errors;
853 if (!$error && !$notrigger) {
855 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
865 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
866 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
869 $this->
error = $this->db->error().
" sql=".$sql;
878 $this->db->rollback();
892 global $langs, $conf;
899 if (empty($this->country_id)) {
900 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
904 if (empty($this->
ref)) {
905 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
910 $this->label =
"???";
913 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
914 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
915 $sql .=
",label = '".$this->db->escape($this->label).
"'";
916 $sql .=
",courant = ".((int) $this->
type);
917 $sql .=
",clos = ".((int) $this->
status);
918 $sql .=
",rappro = ".((int) $this->rappro);
919 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
920 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
921 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
922 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
923 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
924 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
925 $sql .=
",number='".$this->db->escape($this->number).
"'";
926 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
927 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
928 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
929 $sql .=
",domiciliation='".$this->db->escape($this->address).
"'";
930 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
931 $sql .=
",proprio = '".$this->db->escape($this->owner_name ? $this->owner_name : $this->proprio).
"'";
932 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
933 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
934 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
935 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
937 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
939 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
940 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
941 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
943 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
944 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
945 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
946 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
948 $sql .=
" WHERE rowid = ".((int) $this->
id);
950 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
951 $result = $this->db->query($sql);
961 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
962 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
963 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type='bank_account' and entity = ".((int) $conf->entity);
964 $resql = $this->db->query($sql);
967 $this->
error = $this->db->lasterror();
973 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
974 $dirdest = $conf->bank->dir_output.
'/'.$newref;
975 if (file_exists($dirsource)) {
976 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
977 if (@rename($dirsource, $dirdest)) {
983 if (!$error && !$notrigger) {
985 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
993 $this->
error = $this->db->lasterror();
1001 $this->db->rollback();
1017 global $conf, $langs;
1020 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1022 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1026 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1030 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1031 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1032 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1033 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1034 $sql .=
",number='".$this->db->escape($this->number).
"'";
1035 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1036 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1037 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1038 $sql .=
",domiciliation='".$this->db->escape($this->address ? $this->address : $this->domiciliation).
"'";
1039 $sql .=
",proprio = '".$this->db->escape($this->owner_name ? $this->owner_name : $this->proprio).
"'";
1040 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1041 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1042 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1043 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1044 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1045 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1046 $sql .=
" WHERE rowid = ".((int) $this->
id);
1047 $sql .=
" AND entity = ".((int) $conf->entity);
1049 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1051 $result = $this->db->query($sql);
1055 $this->
error = $this->db->lasterror();
1071 if (empty($id) && empty($ref)) {
1072 $this->
error =
"ErrorBadParameters";
1076 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1077 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1078 $sql .=
" ba.domiciliation as address, ba.pti_in_ctti, ba.proprio as owner_name, ba.owner_address, ba.owner_zip, ba.owner_town, ba.owner_country_id, ba.state_id, ba.fk_pays as country_id,";
1079 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1080 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1081 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1082 $sql .=
' c.code as country_code, c.label as country,';
1083 $sql .=
' d.code_departement as state_code, d.nom as state,';
1084 $sql .=
' aj.code as accountancy_journal';
1085 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1086 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1087 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1088 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1089 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1091 $sql .=
" AND ba.rowid = ".((int) $id);
1094 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1097 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1098 $result = $this->db->query($sql);
1100 if ($this->db->num_rows($result)) {
1101 $obj = $this->db->fetch_object($result);
1103 $this->
id = $obj->rowid;
1104 $this->
rowid = $obj->rowid;
1105 $this->
ref = $obj->ref;
1106 $this->label = $obj->label;
1107 $this->
type = $obj->type;
1108 $this->courant = $obj->type;
1109 $this->bank = $obj->bank;
1110 $this->clos = $obj->status;
1111 $this->
status = $obj->status;
1112 $this->rappro = $obj->rappro;
1113 $this->url = $obj->url;
1115 $this->code_banque = $obj->code_banque;
1116 $this->code_guichet = $obj->code_guichet;
1117 $this->number = $obj->number;
1118 $this->cle_rib = $obj->cle_rib;
1119 $this->bic = $obj->bic;
1120 $this->iban = $obj->iban;
1121 $this->domiciliation = $obj->address;
1122 $this->address = $obj->address;
1123 $this->pti_in_ctti = $obj->pti_in_ctti;
1124 $this->proprio = $obj->owner_name;
1125 $this->owner_name = $obj->owner_name;
1126 $this->owner_address = $obj->owner_address;
1127 $this->owner_zip = $obj->owner_zip;
1128 $this->owner_town = $obj->owner_town;
1129 $this->owner_country_id = $obj->owner_country_id;
1131 $this->state_id = $obj->state_id;
1132 $this->state_code = $obj->state_code;
1133 $this->state = $obj->state;
1135 $this->country_id = $obj->country_id;
1136 $this->country_code = $obj->country_code;
1137 $this->country = $obj->country;
1139 $this->account_number = $obj->account_number;
1140 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1141 $this->accountancy_journal = $obj->accountancy_journal;
1143 $this->currency_code = $obj->currency_code;
1144 $this->account_currency_code = $obj->currency_code;
1145 $this->min_allowed = $obj->min_allowed;
1146 $this->min_desired = $obj->min_desired;
1147 $this->comment = $obj->comment;
1149 $this->date_creation = $this->db->jdate($obj->date_creation);
1150 $this->date_modification = $this->db->jdate($obj->date_modification);
1152 $this->ics = $obj->ics;
1153 $this->ics_transfer = $obj->ics_transfer;
1164 $this->
error = $this->db->lasterror();
1165 $this->errors[] = $this->error;
1182 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1183 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1193 public function delete(
User $user =
null, $notrigger = 0)
1203 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1204 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1206 $resql = $this->db->query($sql);
1209 $this->
error =
"Error ".$this->db->lasterror();
1214 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1215 $sql .=
" WHERE rowid = ".((int) $this->
id);
1217 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1218 $result = $this->db->query($sql);
1225 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1230 $this->
error =
"Error ".$this->db->lasterror();
1235 $this->db->commit();
1238 $this->db->rollback();
1267 $langs->load(
'banks');
1269 if ($status == self::STATUS_OPEN) {
1270 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1271 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1272 $statusType =
'status4';
1274 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1275 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1276 $statusType =
'status5';
1279 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1292 $can_be_deleted =
false;
1294 $sql =
"SELECT COUNT(rowid) as nb";
1295 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1296 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1298 $resql = $this->db->query($sql);
1300 $obj = $this->db->fetch_object($resql);
1301 if ($obj->nb <= 1) {
1302 $can_be_deleted =
true;
1307 return $can_be_deleted;
1318 return $this->error;
1329 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1333 $sql =
"SELECT sum(amount) as amount";
1334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1335 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1337 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1340 $resql = $this->db->query($sql);
1342 if ($this->db->num_rows($resql)) {
1343 $obj = $this->db->fetch_object($resql);
1344 $solde = $obj->amount;
1346 $this->db->free($resql);
1348 $this->errors[] = $this->db->lasterror;
1366 global $conf, $langs;
1372 $sql =
"SELECT b.rowid, b.datev as datefin";
1373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1374 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1375 $sql .=
" WHERE b.rappro=0";
1376 $sql .=
" AND b.fk_account = ba.rowid";
1377 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1379 $sql .=
" AND clos = 0";
1380 if ($filteraccountid) {
1381 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1384 $resql = $this->db->query($sql);
1386 $langs->load(
"banks");
1389 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1392 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1393 $response->label = $langs->trans(
"TransactionsToConciliate");
1394 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1395 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1398 while ($obj = $this->db->fetch_object($resql)) {
1399 $response->nbtodo++;
1400 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1401 $response->nbtodolate++;
1408 $this->
error = $this->db->error();
1427 $sql =
"SELECT count(b.rowid) as nb";
1428 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1429 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1430 $sql .=
" WHERE b.fk_account = ba.rowid";
1431 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1432 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1433 $sql .=
" AND clos = 0";
1434 if ($filteraccountid) {
1435 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1438 $resql = $this->db->query($sql);
1440 while ($obj = $this->db->fetch_object($resql)) {
1441 $this->nb[
"banklines"] = $obj->nb;
1443 $this->db->free($resql);
1447 $this->
error = $this->db->error();
1469 $sql =
"SELECT COUNT(ba.rowid) as nb";
1470 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1471 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1472 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1477 $resql = $this->db->query($sql);
1479 $obj = $this->db->fetch_object($resql);
1498 $langs->loadLangs([
'banks',
'compta']);
1499 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1503 $nofetch = !empty($params[
'nofetch']);
1504 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1505 if (isset($this->
status)) {
1506 $pictos .=
' '.$this->getLibStatut(5);
1508 $datas[
'picto'] = $pictos;
1509 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1510 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1512 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1513 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1515 if (isModEnabled(
'accounting')) {
1516 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1517 $langs->load(
"accountancy");
1518 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1519 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1522 if (isModEnabled(
'category') && !$nofetch) {
1523 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1524 $form =
new Form($this->db);
1525 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1542 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1544 global $conf, $langs;
1546 if (!empty($conf->dol_no_mouse_hover)) {
1550 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1553 $classfortooltip =
'classfortooltip';
1557 'objecttype' => $this->element,
1558 'option' => $option,
1562 $classfortooltip =
'classforajaxtooltip';
1563 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1569 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1570 if ($mode ==
'transactions') {
1571 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1572 } elseif ($mode ==
'receipts') {
1573 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1576 if ($option !=
'nolink') {
1578 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1579 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1580 $add_save_lastsearch_values = 1;
1582 if ($add_save_lastsearch_values) {
1583 $url .=
'&save_lastsearch_values=1';
1588 if (empty($notooltip)) {
1590 $label = $langs->trans(
"BankAccount");
1591 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1593 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1594 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1596 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1599 if ($option ==
'nolink' || empty($url)) {
1600 $linkstart =
'<span';
1602 $linkstart =
'<a href="'.$url.
'"';
1604 $linkstart .= $linkclose.
'>';
1605 if ($option ==
'nolink' || empty($url)) {
1606 $linkend =
'</span>';
1611 $result .= $linkstart;
1614 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1616 if ($withpicto != 2) {
1617 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1619 $result .= $linkend;
1635 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1642 $this->
error =
'IBANNotValid';
1646 $this->
error =
'SwiftNotValid';
1666 if (!empty($this->country_code)) {
1667 return $this->country_code;
1671 if (!empty($this->iban)) {
1674 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1680 if (!empty($this->socid)) {
1681 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1682 $company =
new Societe($this->db);
1683 $result = $company->fetch($this->socid);
1684 if (!empty($company->country_code)) {
1685 return $company->country_code;
1690 if (!empty($mysoc->country_code)) {
1691 return $mysoc->country_code;
1706 global $conf, $langs;
1713 if (!empty($conf->use_javascript_ajax)) {
1715 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1716 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1719 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1739 public function useDetailedBBAN()
1741 $country_code = $this->getCountryCode();
1743 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1744 return 1; // France, Spain, Gabon, ... - Not valid for CH
1746 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1747 return 2; // Australia, England...
1757 public function needIBAN()
1761 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1765 $country_code = $this->getCountryCode();
1767 $country_code_in_EEC = array(
1772 'CZ', // Czech republic
1779 'GB', // United Kingdom
1785 'IM', // Isle of Man - Included in UK
1790 'MC', // Monaco - Included in France
1799 'UK', // United Kingdom
1800 //'CH', // Switzerland - No. Swizerland in not in EEC
1803 if (in_array($country_code, $country_code_in_EEC)) {
1804 return 1; // France, Spain, ...
1815 public function info($id)
1833 public function getFieldsToShow($includeibanbic = 0)
1835 //Get the required properties depending on the country
1836 $detailedBBAN = $this->useDetailedBBAN();
1838 if ($detailedBBAN == 0) {
1839 $fieldarray = array(
1842 } elseif ($detailedBBAN == 2) {
1843 $fieldarray = array(
1848 $fieldarray = self::getAccountNumberOrder();
1851 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1852 if ($includeibanbic) {
1853 $fieldarray[] = 'IBAN';
1854 $fieldarray[] = 'BIC';
1858 //Get the order the properties are shown
1872 public static function getAccountNumberOrder()
1876 $fieldlists = array(
1879 'BankAccountNumber',
1880 'BankAccountNumberKey'
1883 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1884 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1885 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1886 $fieldlists = array(
1889 'BankAccountNumberKey',
1894 //Replace the old AccountNumber key with the new BankAccountNumber key
1895 $fieldlists = explode(
1897 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1913 public function initAsSpecimen()
1915 // Example of IBAN FR7630001007941234567890185
1916 $this->specimen = 1;
1918 $this->label = 'My Big Company Bank account';
1919 $this->courant = Account::TYPE_CURRENT;
1920 $this->clos = Account::STATUS_OPEN;
1921 $this->type = Account::TYPE_CURRENT;
1922 $this->status = Account::STATUS_OPEN;
1923 $this->code_banque = '30001';
1924 $this->code_guichet = '00794';
1925 $this->number = '12345678901';
1926 $this->cle_rib = '85';
1927 $this->bic = 'AA12';
1928 $this->iban = 'FR7630001007941234567890185';
1930 $this->bank = 'MyBank';
1931 $this->address = 'Rue de Paris';
1932 $this->proprio = 'Owner';
1933 $this->owner_name = 'Owner';
1934 $this->owner_address = 'Owner address';
1935 $this->owner_zip = 'Owner zip';
1936 $this->owner_town = 'Owner town';
1937 $this->owner_country_id = 'Owner country_id';
1938 $this->country_id = 1;
1951 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
1953 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type=
'company'";
1955 if ($dbs->query($sql)) {
1958 //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.
1959 //$this->errors = $dbs->lasterror();
1971 public function getKanbanView($option = '', $arraydata = null)
1975 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1977 $return = '<div class="box-flex-item box-flex-grow-zero
">';
1978 $return .= '<div class="info-box
info-box-sm
">';
1979 $return .= '<span class="info-box-
icon bg-infobox-action
">';
1980 $return .= img_picto('', $this->picto);
1981 $return .= '</span>';
1982 $return .= '<div class="info-box-content
">';
1983 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1984 if ($selected >= 0) {
1985 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
1987 if (property_exists($this, 'type_lib')) {
1988 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
1990 if (method_exists($this, 'solde')) {
1991 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
1992 $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>';
1994 if (method_exists($this, 'getLibStatut')) {
1995 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
1997 $return .= '</div>';
1998 $return .= '</div>';
1999 $return .= '</div>';
2005require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2010class AccountLine extends CommonObjectLine
2020 public $element = 'bank';
2025 public $table_element = 'bank';
2030 public $picto = 'accountline';
2071 public $amount_main_currency;
2076 public $fk_user_author;
2081 public $fk_user_rappro;
2091 public $fk_bordereau;
2101 public $bank_account_ref;
2106 public $bank_account_label;
2111 public $numero_compte;
2152 public $user_rappro;
2160 public function __construct(DoliDB $db)
2173 public function fetch($rowid, $ref = '', $num = '')
2176 if (empty($rowid) && empty($ref) && empty($num)) {
2180 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2181 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2182 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2183 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2184 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2185 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2186 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2187 $sql .= " WHERE b.fk_account = ba.rowid
";
2188 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2190 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2192 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2194 $sql .= " AND b.rowid =
".((int) $rowid);
2197 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2198 $result = $this->db->query($sql);
2202 $obj = $this->db->fetch_object($result);
2204 $this->id = $obj->rowid;
2205 $this->rowid = $obj->rowid;
2206 $this->ref = $obj->rowid;
2208 $this->datec = $this->db->jdate($obj->datec);
2209 $this->datev = $this->db->jdate($obj->datev);
2210 $this->dateo = $this->db->jdate($obj->dateo);
2211 $this->amount = $obj->amount;
2212 $this->label = $obj->label;
2213 $this->note = $obj->note;
2215 $this->fk_user_author = $obj->fk_user_author;
2216 $this->fk_user_rappro = $obj->fk_user_rappro;
2218 $this->fk_type = $obj->fk_type; // Type of transaction
2219 $this->rappro = (int) $obj->rappro;
2220 $this->num_releve = $obj->num_releve;
2222 $this->num_chq = $obj->num_chq;
2223 $this->bank_chq = $obj->banque;
2224 $this->fk_bordereau = $obj->fk_bordereau;
2226 $this->fk_account = $obj->fk_account;
2227 $this->bank_account_ref = $obj->bank_account_ref;
2228 $this->bank_account_label = $obj->bank_account_label;
2230 // Retrieve all extrafield
2231 // fetch optionals attributes and labels
2232 $this->fetch_optionals();
2236 $this->db->free($result);
2248 public function insert()
2254 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2260 $sql .= ", amount_main_currency
";
2261 $sql .= ", fk_user_author
";
2262 $sql .= ", num_chq
";
2263 $sql .= ", fk_account
";
2264 $sql .= ", fk_type
";
2265 $sql .= ", emetteur,banque
";
2267 $sql .= ", numero_compte
";
2268 $sql .= ", num_releve
";
2269 $sql .= ") VALUES (
";
2270 $sql .= "'".$this->db->idate($this->datec)."'";
2271 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2272 $sql .= ",
'".$this->db->idate($this->datev)."'";
2273 $sql .= ",
'".$this->db->escape($this->label)."'";
2274 $sql .= ",
".price2num($this->amount);
2275 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2276 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2277 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2278 $sql .= ",
'".$this->db->escape($this->fk_account)."'";
2279 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2280 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2281 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2282 $sql .= ",
".(int) $this->rappro;
2283 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2284 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2288 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2289 $resql = $this->db->query($sql);
2291 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2292 // Actions on extra fields (by external module or standard code)
2293 $result = $this->insertExtraFields();
2299 $this->error = $this->db->lasterror();
2300 dol_print_error($this->db);
2304 $this->db->commit();
2307 $this->db->rollback();
2319 public function delete(User $user = null, $notrigger = 0)
2323 if ($this->rappro) {
2324 // Protection to avoid any delete of consolidated lines
2325 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2333 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2335 $this->db->rollback();
2338 // End call triggers
2341 // Protection to avoid any delete of accounted lines. Protection on by default
2342 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2343 $sql = "SELECT COUNT(
rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2344 $resql = $this->db->query($sql);
2346 $obj = $this->db->fetch_object($resql);
2347 if ($obj && $obj->nb) {
2348 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2349 $this->db->rollback();
2353 $this->error = $this->db->lasterror();
2354 $this->db->rollback();
2360 $result = $this->delete_urls($user);
2365 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_class WHERE lineid=
".(int) $this->rowid;
2366 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2367 $result = $this->db->query($sql);
2372 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2373 $result = $this->db->query($sql);
2378 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE
rowid=
".(int) $this->rowid;
2379 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2380 $result = $this->db->query($sql);
2386 $this->db->commit();
2389 $this->db->rollback();
2395 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2402 public function delete_urls(User $user = null)
2407 if ($this->rappro) {
2408 // Protection to avoid any delete of consolidated lines
2409 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2415 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2416 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2417 $result = $this->db->query($sql);
2423 $this->db->commit();
2426 $this->db->rollback();
2439 public function update(User $user, $notrigger = 0)
2443 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2444 $sql .= " amount =
".price2num($this->amount).",
";
2445 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2446 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2447 $sql .= " WHERE
rowid =
".((int) $this->rowid);
2449 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2450 $resql = $this->db->query($sql);
2452 $this->db->commit();
2455 $this->db->rollback();
2456 $this->error = $this->db->error();
2467 public function updateLabel()
2471 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2472 $sql .= " label =
'".$this->db->escape($this->label)."'";
2473 $sql .= " WHERE
rowid =
".((int) $this->rowid);
2475 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2476 $resql = $this->db->query($sql);
2478 $this->db->commit();
2481 $this->db->rollback();
2482 $this->error = $this->db->error();
2488 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2497 public function update_conciliation(User $user, $cat, $conciliated = 1)
2500 global $conf, $langs;
2504 // Check statement field
2505 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2506 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2507 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2512 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2513 $sql .= " rappro =
".((int) $conciliated);
2514 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2516 $sql .= ", fk_user_rappro =
".$user->id;
2518 $sql .= " WHERE
rowid =
".((int) $this->id);
2520 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2521 $resql = $this->db->query($sql);
2523 if (!empty($cat) && $cat > 0) {
2524 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank_class (
";
2526 $sql .= ", fk_categ
";
2527 $sql .= ") VALUES (
";
2529 $sql .= ",
".((int) $cat);
2532 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2533 $this->db->query($sql);
2535 // No error check. Can fail if category already affected
2536 // TODO Do no try the insert if link already exists
2539 $this->rappro = (int) $conciliated;
2541 $this->db->commit();
2544 $this->db->rollback();
2550 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2558 public function datev_change($rowid, $sign = 1)
2561 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE
rowid =
".((int) $rowid);
2562 $resql = $this->db->query($sql);
2564 $obj = $this->db->fetch_object($resql);
2565 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2567 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2568 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2569 $sql .= " WHERE
rowid =
".((int) $rowid);
2571 $result = $this->db->query($sql);
2573 if ($this->db->affected_rows($result)) {
2577 dol_print_error($this->db);
2581 dol_print_error($this->db);
2586 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2593 public function datev_next($id)
2596 return $this->datev_change($id, 1);
2599 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2606 public function datev_previous($id)
2609 return $this->datev_change($id, -1);
2613 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2621 public function dateo_change($rowid, $sign = 1)
2624 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE
rowid =
".((int) $rowid);
2625 $resql = $this->db->query($sql);
2627 $obj = $this->db->fetch_object($resql);
2628 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2630 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2631 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2632 $sql .= " WHERE
rowid =
".((int) $rowid);
2634 $result = $this->db->query($sql);
2636 if ($this->db->affected_rows($result)) {
2640 dol_print_error($this->db);
2644 dol_print_error($this->db);
2649 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2656 public function dateo_next($id)
2659 return $this->dateo_change($id, 1);
2662 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2669 public function dateo_previous($id)
2672 return $this->dateo_change($id, -1);
2682 public function info($id)
2684 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2685 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2686 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2687 $sql .= ' WHERE b.rowid = '.((int) $id);
2689 $result = $this->db->query($sql);
2691 if ($this->db->num_rows($result)) {
2692 $obj = $this->db->fetch_object($result);
2694 $this->id = $obj->rowid;
2696 $this->user_creation_id = $obj->fk_user_author;
2697 $this->user_rappro = $obj->fk_user_rappro;
2698 $this->date_creation = $this->db->jdate($obj->datec);
2699 $this->date_modification = $this->db->jdate($obj->datem);
2700 //$this->date_rappro = $obj->daterappro; // Not yet managed
2702 $this->db->free($result);
2704 dol_print_error($this->db);
2718 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2720 global $conf, $langs;
2724 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2725 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2726 if ($this->amount) {
2727 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2730 $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
">';
2733 $result .= $linkstart;
2735 $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);
2737 if ($withpicto != 2) {
2738 $result .= ($this->ref ? $this->ref : $this->id);
2741 $result .= $linkend;
2743 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2744 $result .= ' <span class="opacitymedium
">(';
2746 if ($option == 'showall') {
2747 $result .= $langs->trans("BankAccount
").': ';
2748 $accountstatic = new Account($this->db);
2749 $accountstatic->id = $this->fk_account;
2750 $accountstatic->ref = $this->bank_account_ref;
2751 $accountstatic->label = $this->bank_account_label;
2752 $result .= $accountstatic->getNomUrl(0).', ';
2754 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2755 $result .= $langs->trans("BankLineConciliated
").': ';
2756 $result .= yn($this->rappro);
2758 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2759 $sql = "SELECT COUNT(
rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2760 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2761 $resql = $this->db->query($sql);
2763 $obj = $this->db->fetch_object($resql);
2764 if ($obj && $obj->nb) {
2765 $result .= ' - '.$langs->trans("Accounted
").': '.yn(1);
2767 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2771 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2772 $result .= ')</span>';
2785 public function getLibStatut($mode = 0)
2787 return $this->LibStatut($this->status, $mode);
2790 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2798 public function LibStatut($status, $mode = 0)
2809 public function getVentilExportCompta()
2811 $alreadydispatched = 0;
2815 $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);
2816 $resql = $this->db->query($sql);
2818 $obj = $this->db->fetch_object($resql);
2820 $alreadydispatched = $obj->nb;
2823 $this->
error = $this->db->lasterror();
2827 if ($alreadydispatched) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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
Or an array listing all the potential status of the object: array: int of the status => translated la...
checkSwiftForAccount(Account $account=null, $swift=null)
Check SWIFT information for a bank account.
checkIbanForAccount(Account $account=null, $ibantocheck=null)
Check IBAN number information 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 balance.
fetch($id, $ref='')
Load a bank account into memory from database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $mode='', $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return 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.
loadStateBoard($filteraccountid=0)
Load the indicators this->nb for the state board.
update(User $user, $notrigger=0)
Update bank account card.
getCountryCode()
Return account country code.
getLibStatut($mode=0)
Return label of object status.
delete(User $user=null, $notrigger=0)
Delete bank account from database.
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.
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()
Indicates if an account can be deleted or not (without movements)
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 ...
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...
setErrorsFromObject($object)
setErrorsFromObject
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
table table fiche title col title div col center btnTitle icon
Automatically calls the icon named with the corresponding "object_" prefix.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid