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;
196 public $owner_country_id;
200 public $owner_country_code;
208 public $domiciliation;
237 public $type_lib = array();
243 public $account_number;
248 public $fk_accountancy_journal;
253 public $accountancy_journal;
259 public $currency_code;
267 public $account_currency_code;
317 public $ics_transfer;
353 public $fields = array(
354 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
355 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 25),
356 'label' => array(
'type' =>
'varchar(30)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
357 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 35,
'index' => 1),
358 'bank' => array(
'type' =>
'varchar(60)',
'label' =>
'Bank',
'enabled' => 1,
'visible' => -1,
'position' => 40),
359 'code_banque' => array(
'type' =>
'varchar(128)',
'label' =>
'Code banque',
'enabled' => 1,
'visible' => -1,
'position' => 45),
360 'code_guichet' => array(
'type' =>
'varchar(6)',
'label' =>
'Code guichet',
'enabled' => 1,
'visible' => -1,
'position' => 50),
361 'number' => array(
'type' =>
'varchar(255)',
'label' =>
'Number',
'enabled' => 1,
'visible' => -1,
'position' => 55),
362 'cle_rib' => array(
'type' =>
'varchar(5)',
'label' =>
'Cle rib',
'enabled' => 1,
'visible' => -1,
'position' => 60),
363 'bic' => array(
'type' =>
'varchar(11)',
'label' =>
'Bic',
'enabled' => 1,
'visible' => -1,
'position' => 65),
364 'iban_prefix' => array(
'type' =>
'varchar(34)',
'label' =>
'Iban prefix',
'enabled' => 1,
'visible' => -1,
'position' => 70),
365 'country_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Country iban',
'enabled' => 1,
'visible' => -1,
'position' => 75),
366 'cle_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Cle iban',
'enabled' => 1,
'visible' => -1,
'position' => 80),
367 'domiciliation' => array(
'type' =>
'varchar(255)',
'label' =>
'Domiciliation',
'enabled' => 1,
'visible' => -1,
'position' => 85),
368 'state_id' => array(
'type' =>
'integer',
'label' =>
'StateId',
'enabled' => 1,
'visible' => -1,
'position' => 90),
369 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 95),
370 'proprio' => array(
'type' =>
'varchar(60)',
'label' =>
'Proprio',
'enabled' => 1,
'visible' => -1,
'position' => 100),
371 'owner_address' => array(
'type' =>
'varchar(255)',
'label' =>
'Owner address',
'enabled' => 1,
'visible' => -1,
'position' => 105),
372 'owner_zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Owner zip',
'enabled' => 1,
'visible' => -1,
'position' => 106),
373 'owner_town' => array(
'type' =>
'varchar(50)',
'label' =>
'Owner town',
'enabled' => 1,
'visible' => -1,
'position' => 107),
374 'owner_country_id' => array(
'type' =>
'integer',
'label' =>
'Owner country',
'enabled' => 1,
'visible' => -1,
'position' => 108),
375 'courant' => array(
'type' =>
'smallint(6)',
'label' =>
'Courant',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 110),
376 'clos' => array(
'type' =>
'smallint(6)',
'label' =>
'Clos',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 115),
377 'rappro' => array(
'type' =>
'smallint(6)',
'label' =>
'Rappro',
'enabled' => 1,
'visible' => -1,
'position' => 120),
378 'url' => array(
'type' =>
'varchar(128)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 125),
379 'account_number' => array(
'type' =>
'varchar(32)',
'label' =>
'Account number',
'enabled' => 1,
'visible' => -1,
'position' => 130),
380 'fk_accountancy_journal' => array(
'type' =>
'integer',
'label' =>
'Accountancy journal ID',
'enabled' => 1,
'visible' => -1,
'position' => 132),
381 'accountancy_journal' => array(
'type' =>
'varchar(20)',
'label' =>
'Accountancy journal',
'enabled' => 1,
'visible' => -1,
'position' => 135),
382 'currency_code' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency code',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 140),
383 'min_allowed' => array(
'type' =>
'integer',
'label' =>
'Min allowed',
'enabled' => 1,
'visible' => -1,
'position' => 145),
384 'min_desired' => array(
'type' =>
'integer',
'label' =>
'Min desired',
'enabled' => 1,
'visible' => -1,
'position' => 150),
385 'comment' => array(
'type' =>
'text',
'label' =>
'Comment',
'enabled' => 1,
'visible' => -1,
'position' => 155),
386 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 156),
387 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 157),
388 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 160),
389 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 165),
390 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 170),
391 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 175),
392 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 180),
393 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 185),
411 const STATUS_OPEN = 0;
412 const STATUS_CLOSED = 1;
426 $this->ismultientitymanaged = 1;
430 $this->type_lib = array(
431 self::TYPE_SAVINGS => $langs->transnoentitiesnoconv(
"BankType0"),
432 self::TYPE_CURRENT => $langs->transnoentitiesnoconv(
"BankType1"),
433 self::TYPE_CASH => $langs->transnoentitiesnoconv(
"BankType2"),
436 $this->labelStatus = array(
437 self::STATUS_OPEN => $langs->transnoentitiesnoconv(
"StatusAccountOpened"),
438 self::STATUS_CLOSED => $langs->transnoentitiesnoconv(
"StatusAccountClosed")
451 if ($val ==
'BankCode') {
452 $string .= $this->code_banque.
' ';
453 } elseif ($val ==
'BankAccountNumber') {
454 $string .= $this->number.
' ';
455 } elseif ($val ==
'DeskCode') {
456 $string .= $this->code_guichet.
' ';
457 } elseif ($val ==
'BankAccountNumberKey') {
458 $string .= $this->cle_rib.
' ';
459 } elseif ($val ==
'BIC') {
460 $string .= $this->bic.
' ';
461 } elseif ($val ==
'IBAN') {
462 $string .= $this->iban.
' ';
466 return trim($string);
477 if (empty($this->rappro)) {
504 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
510 $sql .=
") VALUES (";
511 $sql .= ((int) $line_id);
512 $sql .=
", ".((int) $url_id);
513 $sql .=
", '".$this->db->escape($url).
"'";
514 $sql .=
", '".$this->db->escape($label).
"'";
515 $sql .=
", '".$this->db->escape($type).
"'";
518 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
519 if ($this->db->query($sql)) {
520 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
523 $this->
error = $this->db->lasterror();
538 public function get_url($fk_bank = 0, $url_id = 0, $type =
'')
544 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
545 $this->
error =
"ErrorBadParameter";
549 $sql =
"SELECT fk_bank, url_id, url, label, type";
550 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
552 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
554 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
556 $sql .=
" ORDER BY type, label";
558 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
559 $result = $this->db->query($sql);
562 $num = $this->db->num_rows($result);
564 $obj = $this->db->fetch_object($result);
566 $lines[$i][0] = $obj->url;
567 $lines[$i][1] = $obj->url_id;
568 $lines[$i][2] = $obj->label;
569 $lines[$i][3] = $obj->type;
571 $lines[$i][
'url'] = $obj->url;
572 $lines[$i][
'url_id'] = $obj->url_id;
573 $lines[$i][
'label'] = $obj->label;
574 $lines[$i][
'type'] = $obj->type;
575 $lines[$i][
'fk_bank'] = $obj->fk_bank;
604 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null, $note_private =
'')
609 if (is_numeric($oper)) {
610 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
613 if (empty($this->
id) && !empty($this->rowid)) {
614 $this->
id = $this->rowid;
618 $emetteur = trim($emetteur);
619 $banque = trim($banque);
620 $label = trim($label);
624 if (is_numeric($oper)) {
625 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
626 $sql .=
" WHERE id = ".((int) $oper);
627 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
628 $resql = $this->db->query($sql);
630 $obj = $this->db->fetch_object($resql);
640 $this->
error = $langs->trans(
"OperNotDefined");
644 $this->
error = $langs->trans(
"ThisIdNotDefined");
648 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
654 if (is_null($datev) || empty($datev)) {
659 $accline->datec = $now;
660 $accline->dateo = $date;
661 $accline->datev = $datev;
662 $accline->label = $label;
663 $accline->amount = $amount;
664 $accline->amount_main_currency = $amount_main_currency;
665 $accline->fk_user_author = $user->id;
666 $accline->fk_account = $this->id;
667 $accline->fk_type = $oper;
668 $accline->numero_compte = $accountancycode;
669 $accline->num_releve = $num_releve;
670 $accline->note_private = $note_private;
673 $accline->num_chq = $num_chq;
677 $accline->emetteur = $emetteur;
681 $accline->bank_chq = $banque;
684 if ($accline->insert() > 0) {
685 if ($categorie > 0) {
686 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bankline(";
687 $sql .=
"lineid, fk_categ";
688 $sql .=
") VALUES (";
689 $sql .= ((int) $accline->id).
", ".((int) $categorie);
692 $result = $this->db->query($sql);
694 $this->
error = $this->db->lasterror();
695 $this->db->rollback();
706 $this->db->rollback();
719 public function create($user, $notrigger = 0)
721 global $langs, $conf;
726 if (!$this->min_allowed) {
727 $this->min_allowed = 0;
729 if (!$this->min_desired) {
730 $this->min_desired = 0;
734 if (empty($this->country_id)) {
735 $langs->load(
'errors');
736 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
740 if (empty($this->
ref)) {
741 $langs->load(
'errors');
742 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
746 if (empty($this->date_solde)) {
747 $langs->load(
'errors');
748 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
754 $balance = $this->balance;
755 if (empty($balance) && !empty($this->
solde)) {
756 dol_syslog(get_class($this).
"::create solde is deprecated use balance", LOG_NOTICE);
757 $balance = $this->solde;
759 if (empty($balance)) {
762 if (empty($this->
status && !empty($this->clos))) {
763 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
764 $this->
status = $this->clos;
767 if (empty($this->country_id) && !empty($this->country_code)) {
768 $country_id =
getCountry($this->country_code,
'3');
769 $this->country_id = is_int($country_id) ? $country_id : 0;
773 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
779 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
784 $sql .=
", account_number";
785 $sql .=
", fk_accountancy_journal";
787 $sql .=
", code_banque";
788 $sql .=
", code_guichet";
792 $sql .=
", iban_prefix";
793 $sql .=
", domiciliation";
794 $sql .=
", pti_in_ctti";
796 $sql .=
", owner_address";
797 $sql .=
", owner_zip";
798 $sql .=
", owner_town";
799 $sql .=
", owner_country_id";
800 $sql .=
", currency_code";
802 $sql .=
", min_allowed";
803 $sql .=
", min_desired";
805 $sql .=
", state_id";
808 $sql .=
", ics_transfer";
809 $sql .=
") VALUES (";
810 $sql .=
"'".$this->db->idate($now).
"'";
811 $sql .=
", '".$this->db->escape($this->
ref).
"'";
812 $sql .=
", '".$this->db->escape($this->label).
"'";
813 $sql .=
", ".((int) $conf->entity);
814 $sql .=
", '".$this->db->escape($this->account_number).
"'";
815 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
816 $sql .=
", '".$this->db->escape($this->bank).
"'";
817 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
818 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
819 $sql .=
", '".$this->db->escape($this->number).
"'";
820 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
821 $sql .=
", '".$this->db->escape($this->bic).
"'";
822 $sql .=
", '".$this->db->escape($this->iban).
"'";
823 $sql .=
", '".$this->db->escape($this->
address).
"'";
824 $sql .=
", ".((int) $this->pti_in_ctti);
825 $sql .=
", '".$this->db->escape($this->owner_name).
"'";
826 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
827 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
828 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
829 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
830 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
831 $sql .=
", ".((int) $this->rappro);
832 $sql .=
", ".price2num($this->min_allowed,
'MT');
833 $sql .=
", ".price2num($this->min_desired,
'MT');
834 $sql .=
", '".$this->db->escape($this->comment).
"'";
835 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
836 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
837 $sql .=
", '".$this->db->escape($this->ics).
"'";
838 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
841 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
842 $resql = $this->db->query($sql);
844 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
846 $result = $this->
update($user, 1);
849 $accline->datec = $now;
850 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
851 $accline->amount = (float)
price2num($balance);
852 $accline->fk_user_author = $user->id;
853 $accline->fk_account = $this->id;
854 $accline->datev = $this->date_solde;
855 $accline->dateo = $this->date_solde;
856 $accline->fk_type =
'SOLD';
858 if ($accline->insert() < 0) {
870 if (!$error && !$notrigger) {
872 $result = $this->call_trigger(
'BANKACCOUNT_CREATE', $user);
882 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
883 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
886 $this->
error = $this->db->error().
" sql=".$sql;
895 $this->db->rollback();
907 public function update($user, $notrigger = 0)
909 global $langs, $conf;
911 if (empty($this->country_id) && !empty($this->country_code)) {
912 $country_id =
getCountry($this->country_code,
'3');
913 $this->country_id = is_int($country_id) ? $country_id : 0;
921 if (empty($this->country_id)) {
922 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
926 if (empty($this->
ref)) {
927 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
932 $this->label =
"???";
935 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
936 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
937 $sql .=
",label = '".$this->db->escape($this->label).
"'";
938 $sql .=
",courant = ".((int) $this->
type);
939 $sql .=
",clos = ".((int) $this->
status);
940 $sql .=
",rappro = ".((int) $this->rappro);
941 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
942 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
943 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
944 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
945 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
946 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
947 $sql .=
",number='".$this->db->escape($this->number).
"'";
948 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
949 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
950 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
951 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
952 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
953 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
954 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
955 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
956 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
957 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
959 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
961 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
962 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
963 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
965 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
966 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
967 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
968 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
970 $sql .=
" WHERE rowid = ".((int) $this->
id);
972 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
973 $result = $this->db->query($sql);
983 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
984 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
985 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type = 'bank_account' and entity = ".((int) $conf->entity);
986 $resql = $this->db->query($sql);
989 $this->
error = $this->db->lasterror();
995 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
996 $dirdest = $conf->bank->dir_output.
'/'.$newref;
997 if (file_exists($dirsource)) {
998 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
999 if (@rename($dirsource, $dirdest)) {
1005 if (!$error && !$notrigger) {
1007 $result = $this->call_trigger(
'BANKACCOUNT_MODIFY', $user);
1015 $this->
error = $this->db->lasterror();
1020 $this->db->commit();
1023 $this->db->rollback();
1039 global $conf, $langs;
1042 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1044 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1048 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1052 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1053 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1054 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1055 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1056 $sql .=
",number='".$this->db->escape($this->number).
"'";
1057 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1058 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1059 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1060 $sql .=
",domiciliation='".$this->db->escape($this->
address).
"'";
1061 $sql .=
",proprio = '".$this->db->escape($this->owner_name).
"'";
1062 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1063 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1064 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1065 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1066 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1067 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1068 $sql .=
" WHERE rowid = ".((int) $this->
id);
1069 $sql .=
" AND entity = ".((int) $conf->entity);
1071 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1073 $result = $this->db->query($sql);
1077 $this->
error = $this->db->lasterror();
1093 if (empty($id) && empty($ref)) {
1094 $this->
error =
"ErrorBadParameters";
1098 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1099 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1100 $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,";
1101 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1102 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1103 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1104 $sql .=
' c.code as country_code, c.label as country,';
1105 $sql .=
' d.code_departement as state_code, d.nom as state,';
1106 $sql .=
' aj.code as accountancy_journal';
1107 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1108 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1109 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1110 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1111 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1113 $sql .=
" AND ba.rowid = ".((int) $id);
1116 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1119 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1120 $result = $this->db->query($sql);
1122 if ($this->db->num_rows($result)) {
1123 $obj = $this->db->fetch_object($result);
1125 $this->
id = $obj->rowid;
1126 $this->rowid = $obj->rowid;
1127 $this->
ref = $obj->ref;
1128 $this->label = $obj->label;
1129 $this->
type = $obj->type;
1130 $this->courant = $obj->type;
1131 $this->bank = $obj->bank;
1132 $this->clos = $obj->status;
1133 $this->
status = $obj->status;
1134 $this->rappro = $obj->rappro;
1135 $this->url = $obj->url;
1137 $this->code_banque = $obj->code_banque;
1138 $this->code_guichet = $obj->code_guichet;
1139 $this->number = $obj->number;
1140 $this->cle_rib = $obj->cle_rib;
1141 $this->bic = $obj->bic;
1142 $this->iban = $obj->iban;
1143 $this->
address = $obj->address;
1145 $this->owner_name = $obj->owner_name;
1146 $this->proprio = $this->owner_name;
1147 $this->owner_address = $obj->owner_address;
1148 $this->owner_zip = $obj->owner_zip;
1149 $this->owner_town = $obj->owner_town;
1150 $this->owner_country_id = $obj->owner_country_id;
1152 $this->pti_in_ctti = $obj->pti_in_ctti;
1154 $this->state_id = $obj->state_id;
1155 $this->state_code = $obj->state_code;
1156 $this->state = $obj->state;
1158 $this->country_id = $obj->country_id;
1159 $this->country_code = $obj->country_code;
1160 $this->country = $obj->country;
1162 $this->account_number = $obj->account_number;
1163 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1164 $this->accountancy_journal = $obj->accountancy_journal;
1166 $this->currency_code = $obj->currency_code;
1167 $this->account_currency_code = $obj->currency_code;
1168 $this->min_allowed = $obj->min_allowed;
1169 $this->min_desired = $obj->min_desired;
1170 $this->comment = $obj->comment;
1172 $this->date_creation = $this->db->jdate($obj->date_creation);
1173 $this->date_modification = $this->db->jdate($obj->date_modification);
1175 $this->ics = $obj->ics;
1176 $this->ics_transfer = $obj->ics_transfer;
1187 $this->
error = $this->db->lasterror();
1188 $this->errors[] = $this->error;
1205 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1206 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1216 public function delete($user, $notrigger = 0)
1226 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1227 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1229 $resql = $this->db->query($sql);
1232 $this->
error =
"Error ".$this->db->lasterror();
1237 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1238 $sql .=
" WHERE rowid = ".((int) $this->
id);
1240 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1241 $result = $this->db->query($sql);
1248 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1253 $this->
error =
"Error ".$this->db->lasterror();
1258 $this->db->commit();
1261 $this->db->rollback();
1290 $langs->load(
'banks');
1292 if ($status == self::STATUS_OPEN) {
1293 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1294 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1295 $statusType =
'status4';
1297 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1298 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1299 $statusType =
'status5';
1302 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1315 $can_be_deleted =
false;
1317 $sql =
"SELECT COUNT(rowid) as nb";
1318 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1319 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1321 $resql = $this->db->query($sql);
1323 $obj = $this->db->fetch_object($resql);
1324 if ($obj->nb <= 1) {
1325 $can_be_deleted =
true;
1330 return $can_be_deleted;
1341 return $this->error;
1352 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1356 $sql =
"SELECT sum(amount) as amount";
1357 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1358 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1360 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1363 $resql = $this->db->query($sql);
1365 if ($this->db->num_rows($resql)) {
1366 $obj = $this->db->fetch_object($resql);
1367 $solde = $obj->amount;
1369 $this->db->free($resql);
1371 $this->errors[] = $this->db->lasterror;
1389 global $conf, $langs;
1395 $sql =
"SELECT b.rowid, b.datev as datefin";
1396 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1397 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1398 $sql .=
" WHERE b.rappro=0";
1399 $sql .=
" AND b.fk_account = ba.rowid";
1400 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1402 $sql .=
" AND clos = 0";
1403 if ($filteraccountid) {
1404 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1407 $resql = $this->db->query($sql);
1409 $langs->load(
"banks");
1412 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1415 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1416 $response->label = $langs->trans(
"TransactionsToConciliate");
1417 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1418 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1421 while ($obj = $this->db->fetch_object($resql)) {
1422 $response->nbtodo++;
1423 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1424 $response->nbtodolate++;
1431 $this->
error = $this->db->error();
1450 $sql =
"SELECT count(b.rowid) as nb";
1451 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1452 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1453 $sql .=
" WHERE b.fk_account = ba.rowid";
1454 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1455 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1456 $sql .=
" AND clos = 0";
1457 if ($filteraccountid) {
1458 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1461 $resql = $this->db->query($sql);
1463 while ($obj = $this->db->fetch_object($resql)) {
1464 $this->nb[
"banklines"] = $obj->nb;
1466 $this->db->free($resql);
1470 $this->
error = $this->db->error();
1492 $sql =
"SELECT COUNT(ba.rowid) as nb";
1493 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1494 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1495 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1500 $resql = $this->db->query($sql);
1502 $obj = $this->db->fetch_object($resql);
1503 $nb = (int) $obj->nb;
1522 $langs->loadLangs([
'banks',
'compta']);
1523 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1527 $nofetch = !empty($params[
'nofetch']);
1528 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1529 if (isset($this->
status)) {
1530 $pictos .=
' '.$this->getLibStatut(5);
1532 $datas[
'picto'] = $pictos;
1533 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1534 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1535 $datas[
'accountnumber'] =
'<br><br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1537 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1538 $datas[
'accountcurrency'] =
'<br><br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1541 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1542 $langs->load(
"accountancy");
1543 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1544 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1548 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1549 $form =
new Form($this->db);
1550 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1567 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1569 global $conf, $langs;
1571 if (!empty($conf->dol_no_mouse_hover)) {
1575 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1578 $classfortooltip =
'classfortooltip';
1582 'objecttype' => $this->element,
1583 'option' => $option,
1587 $classfortooltip =
'classforajaxtooltip';
1588 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1594 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1595 if ($mode ==
'transactions') {
1596 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1597 } elseif ($mode ==
'receipts') {
1598 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1601 if ($option !=
'nolink') {
1603 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1604 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1605 $add_save_lastsearch_values = 1;
1607 if ($add_save_lastsearch_values) {
1608 $url .=
'&save_lastsearch_values=1';
1613 if (empty($notooltip)) {
1615 $label = $langs->trans(
"BankAccount");
1616 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1618 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1619 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1621 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1624 if ($option ==
'nolink' || empty($url)) {
1625 $linkstart =
'<span';
1627 $linkstart =
'<a href="'.$url.
'"';
1629 $linkstart .= $linkclose.
'>';
1630 if ($option ==
'nolink' || empty($url)) {
1631 $linkend =
'</span>';
1636 $result .= $linkstart;
1639 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1641 if ($withpicto != 2) {
1642 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1644 $result .= $linkend;
1660 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1667 $this->
error =
'IBANNotValid';
1673 $this->
error =
'SwiftNotValid';
1693 if (!empty($this->country_code)) {
1694 return $this->country_code;
1698 if (!empty($this->iban)) {
1701 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1707 if (!empty($this->socid)) {
1708 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1709 $company =
new Societe($this->db);
1710 $result = $company->fetch($this->socid);
1711 if (!empty($company->country_code)) {
1712 return $company->country_code;
1717 if (!empty(
$mysoc->country_code)) {
1718 return $mysoc->country_code;
1733 global $conf, $langs;
1740 if (!empty($conf->use_javascript_ajax)) {
1742 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1743 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1746 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1766 public function useDetailedBBAN()
1768 $country_code = $this->getCountryCode();
1770 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1771 return 1; // France, Spain, Gabon, ... - Not valid for CH
1773 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1774 return 2; // Australia, England...
1784 public function needIBAN()
1788 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1792 $country_code = $this->getCountryCode();
1794 $country_code_in_EEC = array(
1799 'CZ', // Czech republic
1806 'GB', // United Kingdom
1812 'IM', // Isle of Man - Included in UK
1817 'MC', // Monaco - Included in France
1826 'UK', // United Kingdom
1827 //'CH', // Switzerland - No. Swizerland in not in EEC
1830 if (in_array($country_code, $country_code_in_EEC)) {
1831 return 1; // France, Spain, ...
1841 public function needBIC()
1843 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1847 $country_code = $this->getCountryCode();
1849 $country_code_in_EEC = array(
1861 if (in_array($country_code, $country_code_in_EEC)) {
1862 return 1; // Andorra, Bahrein, ...
1873 public function info($id)
1891 public function getFieldsToShow($includeibanbic = 0)
1893 //Get the required properties depending on the country
1894 $detailedBBAN = $this->useDetailedBBAN();
1896 if ($detailedBBAN == 0) {
1897 $fieldarray = array(
1900 } elseif ($detailedBBAN == 2) {
1901 $fieldarray = array(
1906 $fieldarray = self::getAccountNumberOrder();
1909 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1910 if ($includeibanbic) {
1911 $fieldarray[] = 'IBAN';
1912 $fieldarray[] = 'BIC';
1916 //Get the order the properties are shown
1930 public static function getAccountNumberOrder()
1934 $fieldlists = array(
1937 'BankAccountNumber',
1938 'BankAccountNumberKey'
1941 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1942 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1943 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1944 $fieldlists = array(
1947 'BankAccountNumberKey',
1952 //Replace the old AccountNumber key with the new BankAccountNumber key
1953 $fieldlists = explode(
1955 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1971 public function initAsSpecimen()
1973 // Example of IBAN FR7630001007941234567890185
1974 $this->specimen = 1;
1976 $this->label = 'My Big Company Bank account';
1977 $this->clos = Account::STATUS_OPEN;
1978 $this->type = Account::TYPE_CURRENT;
1979 $this->status = Account::STATUS_OPEN;
1980 $this->code_banque = '30001';
1981 $this->code_guichet = '00794';
1982 $this->number = '12345678901';
1983 $this->cle_rib = '85';
1984 $this->bic = 'AA12';
1985 $this->iban = 'FR7630001007941234567890185';
1987 $this->bank = 'MyBank';
1988 $this->address = 'Rue de Paris';
1989 $this->owner_name = 'Owner';
1990 $this->owner_address = 'Owner address';
1991 $this->owner_zip = 'Owner zip';
1992 $this->owner_town = 'Owner town';
1993 $this->owner_country_id = 1;
1994 $this->country_id = 1;
2007 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2009 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type =
'company'";
2011 if ($dbs->query($sql)) {
2014 //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.
2015 //$this->errors = $dbs->lasterror();
2027 public function getKanbanView($option = '', $arraydata = null)
2031 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2033 $return = '<div class="box-flex-item box-flex-grow-zero
">';
2034 $return .= '<div class="info-box
info-box-sm
">';
2035 $return .= '<span class="info-box-icon bg-infobox-action
">';
2036 $return .= img_picto('', $this->picto);
2037 $return .= '</span>';
2038 $return .= '<div class="info-box-content
">';
2039 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2040 if ($selected >= 0) {
2041 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2043 if (property_exists($this, 'type_lib')) {
2044 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2046 if (method_exists($this, 'solde')) {
2047 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2048 $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>';
2050 if (method_exists($this, 'getLibStatut')) {
2051 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2053 $return .= '</div>';
2054 $return .= '</div>';
2055 $return .= '</div>';
2061require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2066class AccountLine extends CommonObjectLine
2076 public $element = 'bank';
2081 public $table_element = 'bank';
2086 public $picto = 'accountline';
2127 public $amount_main_currency;
2132 public $fk_user_author;
2137 public $fk_user_rappro;
2147 public $fk_bordereau;
2157 public $bank_account_ref;
2162 public $bank_account_label;
2167 public $numero_compte;
2209 public $user_rappro;
2217 public function __construct(DoliDB $db)
2230 public function fetch($rowid, $ref = '', $num = '')
2233 if (empty($rowid) && empty($ref) && empty($num)) {
2237 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2238 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2239 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2240 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2241 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2242 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2243 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2244 $sql .= " WHERE b.fk_account = ba.rowid
";
2245 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2247 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2249 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2251 $sql .= " AND b.rowid =
".((int) $rowid);
2254 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2255 $result = $this->db->query($sql);
2259 $obj = $this->db->fetch_object($result);
2261 $this->id = $obj->rowid;
2262 $this->rowid = $obj->rowid;
2263 $this->ref = $obj->rowid;
2265 $this->datec = $this->db->jdate($obj->datec);
2266 $this->datev = $this->db->jdate($obj->datev);
2267 $this->dateo = $this->db->jdate($obj->dateo);
2268 $this->amount = $obj->amount;
2269 $this->label = $obj->label;
2270 $this->note = $obj->note;
2272 $this->fk_user_author = $obj->fk_user_author;
2273 $this->fk_user_rappro = $obj->fk_user_rappro;
2275 $this->fk_type = $obj->fk_type; // Type of transaction
2276 $this->rappro = (int) $obj->rappro;
2277 $this->num_releve = $obj->num_releve;
2279 $this->num_chq = $obj->num_chq;
2280 $this->bank_chq = $obj->banque;
2281 $this->fk_bordereau = $obj->fk_bordereau;
2283 $this->fk_account = $obj->fk_account;
2284 $this->bank_account_ref = $obj->bank_account_ref;
2285 $this->bank_account_label = $obj->bank_account_label;
2287 // Retrieve all extrafield
2288 // fetch optionals attributes and labels
2289 $this->fetch_optionals();
2293 $this->db->free($result);
2305 public function insert()
2311 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2317 $sql .= ", amount_main_currency
";
2318 $sql .= ", fk_user_author
";
2319 $sql .= ", num_chq
";
2320 $sql .= ", fk_account
";
2321 $sql .= ", fk_type
";
2322 $sql .= ", emetteur,banque
";
2324 $sql .= ", numero_compte
";
2325 $sql .= ", num_releve
";
2327 $sql .= ") VALUES (
";
2328 $sql .= "'".$this->db->idate($this->datec)."'";
2329 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2330 $sql .= ",
'".$this->db->idate($this->datev)."'";
2331 $sql .= ",
'".$this->db->escape($this->label)."'";
2332 $sql .= ",
".price2num($this->amount);
2333 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2334 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2335 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2336 $sql .= ",
'".$this->db->escape((string) $this->fk_account)."'";
2337 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2338 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2339 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2340 $sql .= ",
".(int) $this->rappro;
2341 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2342 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2343 $sql .= ",
".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2347 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2348 $resql = $this->db->query($sql);
2350 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2351 // Actions on extra fields (by external module or standard code)
2352 $result = $this->insertExtraFields();
2358 $this->error = $this->db->lasterror();
2359 dol_print_error($this->db);
2363 $this->db->commit();
2366 $this->db->rollback();
2378 public function delete($user, $notrigger = 0)
2382 if ($this->rappro) {
2383 // Protection to avoid any delete of consolidated lines
2384 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2392 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2394 $this->db->rollback();
2397 // End call triggers
2400 // Protection to avoid any delete of accounted lines. Protection on by default
2401 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2402 $sql = "SELECT COUNT(rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2403 $resql = $this->db->query($sql);
2405 $obj = $this->db->fetch_object($resql);
2406 if ($obj && $obj->nb) {
2407 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2408 $this->db->rollback();
2412 $this->error = $this->db->lasterror();
2413 $this->db->rollback();
2419 $result = $this->delete_urls($user);
2424 $sql = "DELETE FROM
".MAIN_DB_PREFIX."category_bankline WHERE lineid=
".(int) $this->rowid;
2425 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2426 $result = $this->db->query($sql);
2431 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2432 $result = $this->db->query($sql);
2437 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE rowid=
".(int) $this->rowid;
2438 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2439 $result = $this->db->query($sql);
2445 $this->db->commit();
2448 $this->db->rollback();
2454 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2461 public function delete_urls($user = null)
2466 if ($this->rappro) {
2467 // Protection to avoid any delete of consolidated lines
2468 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2474 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2475 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2476 $result = $this->db->query($sql);
2482 $this->db->commit();
2485 $this->db->rollback();
2498 public function update(User $user, $notrigger = 0)
2502 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2503 $sql .= " amount =
".price2num($this->amount).",
";
2504 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2505 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2506 $sql .= " WHERE rowid =
".((int) $this->rowid);
2508 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2509 $resql = $this->db->query($sql);
2511 $this->db->commit();
2514 $this->db->rollback();
2515 $this->error = $this->db->error();
2526 public function updateLabel()
2530 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2531 $sql .= " label =
'".$this->db->escape($this->label)."'";
2532 $sql .= " WHERE rowid =
".((int) $this->rowid);
2534 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2535 $resql = $this->db->query($sql);
2537 $this->db->commit();
2540 $this->db->rollback();
2541 $this->error = $this->db->error();
2547 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2556 public function update_conciliation(User $user, $cat, $conciliated = 1)
2559 global $conf, $langs;
2563 // Check statement field
2564 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2565 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2566 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2571 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2572 $sql .= " rappro =
".((int) $conciliated);
2573 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2575 $sql .= ", fk_user_rappro =
".((int) $user->id);
2577 $sql .= " WHERE rowid =
".((int) $this->id);
2579 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2580 $resql = $this->db->query($sql);
2582 if (!empty($cat) && $cat > 0) {
2583 $sql = "INSERT INTO
".MAIN_DB_PREFIX."category_bankline (
";
2585 $sql .= ", fk_categ
";
2586 $sql .= ") VALUES (
";
2588 $sql .= ",
".((int) $cat);
2591 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2592 $this->db->query($sql);
2594 // No error check. Can fail if category already affected
2595 // TODO Do no try the insert if link already exists
2598 $this->rappro = (int) $conciliated;
2600 $this->db->commit();
2603 $this->db->rollback();
2609 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2617 public function datev_change($rowid, $sign = 1)
2620 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2621 $resql = $this->db->query($sql);
2623 $obj = $this->db->fetch_object($resql);
2624 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2626 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2627 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2628 $sql .= " WHERE rowid =
".((int) $rowid);
2630 $result = $this->db->query($sql);
2632 if ($this->db->affected_rows($result)) {
2636 dol_print_error($this->db);
2640 dol_print_error($this->db);
2645 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2652 public function datev_next($id)
2655 return $this->datev_change($id, 1);
2658 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2665 public function datev_previous($id)
2668 return $this->datev_change($id, -1);
2672 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2680 public function dateo_change($rowid, $sign = 1)
2683 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE rowid =
".((int) $rowid);
2684 $resql = $this->db->query($sql);
2686 $obj = $this->db->fetch_object($resql);
2687 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2689 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2690 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2691 $sql .= " WHERE rowid =
".((int) $rowid);
2693 $result = $this->db->query($sql);
2695 if ($this->db->affected_rows($result)) {
2699 dol_print_error($this->db);
2703 dol_print_error($this->db);
2708 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2715 public function dateo_next($id)
2718 return $this->dateo_change($id, 1);
2721 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2728 public function dateo_previous($id)
2731 return $this->dateo_change($id, -1);
2741 public function info($id)
2743 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2744 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2745 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2746 $sql .= ' WHERE b.rowid = '.((int) $id);
2748 $result = $this->db->query($sql);
2750 if ($this->db->num_rows($result)) {
2751 $obj = $this->db->fetch_object($result);
2753 $this->id = $obj->rowid;
2755 $this->user_creation_id = $obj->fk_user_author;
2756 $this->user_rappro = $obj->fk_user_rappro;
2757 $this->date_creation = $this->db->jdate($obj->datec);
2758 $this->date_modification = $this->db->jdate($obj->datem);
2759 //$this->date_rappro = $obj->daterappro; // Not yet managed
2761 $this->db->free($result);
2763 dol_print_error($this->db);
2777 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2779 global $conf, $langs;
2783 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2784 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2785 if ($this->amount) {
2786 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2789 $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
">';
2792 $result .= $linkstart;
2794 $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);
2796 if ($withpicto != 2) {
2797 $result .= ($this->ref ? $this->ref : $this->id);
2800 $result .= $linkend;
2802 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2803 $result .= ' <span class="opacitymedium
">(';
2805 if ($option == 'showall') {
2806 $result .= $langs->trans("BankAccount
").': ';
2807 $accountstatic = new Account($this->db);
2808 $accountstatic->id = $this->fk_account;
2809 $accountstatic->ref = $this->bank_account_ref;
2810 $accountstatic->label = $this->bank_account_label;
2811 $result .= $accountstatic->getNomUrl(0).', ';
2813 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2814 $result .= $langs->trans("BankLineConciliated
").': ';
2815 $result .= yn($this->rappro);
2817 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2818 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2819 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2820 $resql = $this->db->query($sql);
2822 $obj = $this->db->fetch_object($resql);
2823 if ($obj && $obj->nb) {
2824 $result .= ' - '.$langs->trans("Accounted
").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2826 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2830 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2831 $result .= ')</span>';
2844 public function getLibStatut($mode = 0)
2846 return $this->LibStatut($this->status, $mode);
2849 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2857 public function LibStatut($status, $mode = 0)
2869 public function getVentilExportCompta($mode = 0)
2871 $alreadydispatched = 0;
2875 $sql = " SELECT
".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb
";
2876 $sql .= " FROM
".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type =
'".$this->db->escape($type)."' AND ab.fk_doc =
".((int) $this->id);
2877 $resql = $this->db->query($sql);
2879 $obj = $this->db->fetch_object($resql);
2881 $alreadydispatched = $obj->nb;
2884 $this->error = $this->db->lasterror();
2888 if ($alreadydispatched) {
2889 return $alreadydispatched;
if(! $sortfield) if(! $sortorder) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
checkIbanForAccount($account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current balance.
fetch($id, $ref='')
Load a bank account into memory from database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $mode='', $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
loadStateBoard($filteraccountid=0)
Load the indicators this->nb for the state board.
getCountryCode()
Return account country code.
getLibStatut($mode=0)
Return label of object status.
update_bban($user=null)
Update BBAN (RIB) account fields.
create($user, $notrigger=0)
Create bank account into database.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null, $note_private='')
Add an entry into table llx_bank.
getBannerAddress($htmlkey, $object)
Return full address for banner.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
update($user, $notrigger=0)
Update bank account card.
__toString()
Shows the account number in the appropriate format.
delete($user, $notrigger=0)
Delete bank account from database.
const TYPE_SAVINGS
Savings account.
getTooltipContentArray($params)
getTooltipContentArray
canBeConciliated()
Return if a bank account need to be conciliated.
can_be_deleted()
Indicates if an account can be deleted or not (without movements)
const TYPE_CURRENT
Current account.
setCategories($categories)
Sets object to supplied categories.
countAccountToReconcile()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
verif()
Return if an account has valid information for Direct debit payment.
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
get_url($fk_bank=0, $url_id=0, $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
setErrorsFromObject($object)
setErrorsFromObject
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...