34 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45 public $element =
'bank_account';
50 public $table_element =
'bank_account';
56 public $ismultientitymanaged = 1;
61 public $picto =
'account';
98 public $clos = self::STATUS_OPEN;
122 public $code_guichet;
160 public $pti_in_ctti = 0;
172 public $owner_address;
175 public $owner_country_id;
176 public $owner_country_code;
182 public $domiciliation;
193 public $type_lib = array();
200 public $status = array();
206 public $account_number;
211 public $fk_accountancy_journal;
215 public $accountancy_journal;
221 public $currency_code;
228 public $account_currency_code;
278 public $ics_transfer;
310 public $fields = array(
311 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
312 'ref' =>array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>25),
313 'label' =>array(
'type'=>
'varchar(30)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
314 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>35,
'index'=>1),
315 'bank' =>array(
'type'=>
'varchar(60)',
'label'=>
'Bank',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
316 'code_banque' =>array(
'type'=>
'varchar(128)',
'label'=>
'Code banque',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
317 'code_guichet' =>array(
'type'=>
'varchar(6)',
'label'=>
'Code guichet',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
318 'number' =>array(
'type'=>
'varchar(255)',
'label'=>
'Number',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
319 'cle_rib' =>array(
'type'=>
'varchar(5)',
'label'=>
'Cle rib',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
320 'bic' =>array(
'type'=>
'varchar(11)',
'label'=>
'Bic',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
321 'iban_prefix' =>array(
'type'=>
'varchar(34)',
'label'=>
'Iban prefix',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
322 'country_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Country iban',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
323 'cle_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Cle iban',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
324 'domiciliation' =>array(
'type'=>
'varchar(255)',
'label'=>
'Domiciliation',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
325 'state_id' =>array(
'type'=>
'integer',
'label'=>
'StateId',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
326 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>95),
327 'proprio' =>array(
'type'=>
'varchar(60)',
'label'=>
'Proprio',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
328 'owner_address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Owner address',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
329 'owner_zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Owner zip',
'enabled'=>1,
'visible'=>-1,
'position'=>106),
330 'owner_town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Owner town',
'enabled'=>1,
'visible'=>-1,
'position'=>107),
331 'owner_country_id' =>array(
'type'=>
'integer',
'label'=>
'Owner country',
'enabled'=>1,
'visible'=>-1,
'position'=>108),
332 'courant' =>array(
'type'=>
'smallint(6)',
'label'=>
'Courant',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>110),
333 'clos' =>array(
'type'=>
'smallint(6)',
'label'=>
'Clos',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>115),
334 'rappro' =>array(
'type'=>
'smallint(6)',
'label'=>
'Rappro',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
335 'url' =>array(
'type'=>
'varchar(128)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
336 'account_number' =>array(
'type'=>
'varchar(32)',
'label'=>
'Account number',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
337 'fk_accountancy_journal' =>array(
'type'=>
'integer',
'label'=>
'Accountancy journal ID',
'enabled'=>1,
'visible'=>-1,
'position'=>132),
338 'accountancy_journal' =>array(
'type'=>
'varchar(20)',
'label'=>
'Accountancy journal',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
339 'currency_code' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>140),
340 'min_allowed' =>array(
'type'=>
'integer',
'label'=>
'Min allowed',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
341 'min_desired' =>array(
'type'=>
'integer',
'label'=>
'Min desired',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
342 'comment' =>array(
'type'=>
'text',
'label'=>
'Comment',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
343 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>156),
344 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>157),
345 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
346 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>165),
347 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>170),
348 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>175),
349 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>180),
350 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
368 const STATUS_OPEN = 0;
369 const STATUS_CLOSED = 1;
385 $this->type_lib = array(
386 self::TYPE_SAVINGS => $langs->trans(
"BankType0"),
387 self::TYPE_CURRENT => $langs->trans(
"BankType1"),
388 self::TYPE_CASH => $langs->trans(
"BankType2"),
391 $this->status = array(
392 self::STATUS_OPEN => $langs->trans(
"StatusAccountOpened"),
393 self::STATUS_CLOSED => $langs->trans(
"StatusAccountClosed")
406 if ($val ==
'BankCode') {
407 $string .= $this->code_banque.
' ';
408 } elseif ($val ==
'BankAccountNumber') {
409 $string .= $this->number.
' ';
410 } elseif ($val ==
'DeskCode') {
411 $string .= $this->code_guichet.
' ';
412 } elseif ($val ==
'BankAccountNumberKey') {
413 $string .= $this->cle_rib.
' ';
414 } elseif ($val ==
'BIC') {
415 $string .= $this->bic.
' ';
416 } elseif ($val ==
'IBAN') {
417 $string .= $this->iban.
' ';
421 return trim($string);
434 if (empty($this->rappro)) {
437 if ($this->courant ==
Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
461 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
467 $sql .=
") VALUES (";
468 $sql .=
" ".((int) $line_id);
469 $sql .=
", ".((int) $url_id);
470 $sql .=
", '".$this->db->escape($url).
"'";
471 $sql .=
", '".$this->db->escape($label).
"'";
472 $sql .=
", '".$this->db->escape($type).
"'";
475 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
476 if ($this->db->query(
$sql)) {
477 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
480 $this->
error = $this->db->lasterror();
495 public function get_url($fk_bank =
'', $url_id =
'', $type =
'')
501 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
502 $this->
error =
"ErrorBadParameter";
506 $sql =
"SELECT fk_bank, url_id, url, label, type";
507 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
509 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
511 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
513 $sql .=
" ORDER BY type, label";
515 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
516 $result = $this->db->query(
$sql);
519 $num = $this->db->num_rows($result);
521 $obj = $this->db->fetch_object($result);
523 $lines[$i][0] = $obj->url;
524 $lines[$i][1] = $obj->url_id;
525 $lines[$i][2] = $obj->label;
526 $lines[$i][3] = $obj->type;
528 $lines[$i][
'url'] = $obj->url;
529 $lines[$i][
'url_id'] = $obj->url_id;
530 $lines[$i][
'label'] = $obj->label;
531 $lines[$i][
'type'] = $obj->type;
532 $lines[$i][
'fk_bank'] = $obj->fk_bank;
560 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
565 if (is_numeric($oper)) {
566 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
569 if (empty($this->
id) && !empty($this->
rowid)) {
570 $this->
id = $this->rowid;
574 $emetteur = trim($emetteur);
575 $banque = trim($banque);
576 $label = trim($label);
580 if (is_numeric($oper)) {
581 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
582 $sql .=
" WHERE id = ".((int) $oper);
583 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
584 $resql = $this->db->query(
$sql);
586 $obj = $this->db->fetch_object($resql);
596 $this->
error = $langs->trans(
"OperNotDefined");
600 $this->
error = $langs->trans(
"ThisIdNotDefined");
604 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
610 if (is_null($datev) || empty($datev)) {
615 $accline->datec = $now;
616 $accline->dateo = $date;
617 $accline->datev = $datev;
618 $accline->label = $label;
619 $accline->amount = $amount;
620 $accline->amount_main_currency = $amount_main_currency;
621 $accline->fk_user_author = $user->id;
622 $accline->fk_account = $this->id;
623 $accline->fk_type = $oper;
624 $accline->numero_compte = $accountancycode;
625 $accline->num_releve = $num_releve;
628 $accline->num_chq = $num_chq;
632 $accline->emetteur = $emetteur;
636 $accline->bank_chq = $banque;
639 if ($accline->insert() > 0) {
640 if ($categorie > 0) {
641 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
642 $sql .=
"lineid, fk_categ";
643 $sql .=
") VALUES (";
644 $sql .= ((int) $accline->id).
", '".$this->db->escape($categorie).
"'";
647 $result = $this->db->query(
$sql);
649 $this->
error = $this->db->lasterror();
650 $this->db->rollback();
660 $this->
error = $accline->error;
661 $this->errors = $accline->errors;
662 $this->db->rollback();
677 global $langs, $conf;
682 if (!$this->min_allowed) {
683 $this->min_allowed = 0;
685 if (!$this->min_desired) {
686 $this->min_desired = 0;
690 if (empty($this->country_id)) {
691 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
695 if (empty($this->
ref)) {
696 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
700 if (empty($this->date_solde)) {
701 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
706 $balance = $this->balance;
707 if (empty($balance) && !empty($this->
solde)) {
708 $balance = $this->solde;
710 if (empty($balance)) {
715 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
721 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
726 $sql .=
", account_number";
727 $sql .=
", fk_accountancy_journal";
729 $sql .=
", code_banque";
730 $sql .=
", code_guichet";
734 $sql .=
", iban_prefix";
735 $sql .=
", domiciliation";
736 $sql .=
", pti_in_ctti";
738 $sql .=
", owner_address";
739 $sql .=
", owner_zip";
740 $sql .=
", owner_town";
741 $sql .=
", owner_country_id";
742 $sql .=
", currency_code";
744 $sql .=
", min_allowed";
745 $sql .=
", min_desired";
747 $sql .=
", state_id";
750 $sql .=
", ics_transfer";
751 $sql .=
") VALUES (";
752 $sql .=
"'".$this->db->idate($now).
"'";
753 $sql .=
", '".$this->db->escape($this->
ref).
"'";
754 $sql .=
", '".$this->db->escape($this->label).
"'";
755 $sql .=
", ".((int) $conf->entity);
756 $sql .=
", '".$this->db->escape($this->account_number).
"'";
757 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
758 $sql .=
", '".$this->db->escape($this->bank).
"'";
759 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
760 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
761 $sql .=
", '".$this->db->escape($this->number).
"'";
762 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
763 $sql .=
", '".$this->db->escape($this->bic).
"'";
764 $sql .=
", '".$this->db->escape($this->iban).
"'";
765 $sql .=
", '".$this->db->escape($this->domiciliation).
"'";
766 $sql .=
", ".((int) $this->pti_in_ctti);
767 $sql .=
", '".$this->db->escape($this->proprio).
"'";
768 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
769 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
770 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
771 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
772 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
773 $sql .=
", ".((int) $this->rappro);
774 $sql .=
", ".price2num($this->min_allowed,
'MT');
775 $sql .=
", ".price2num($this->min_desired,
'MT');
776 $sql .=
", '".$this->db->escape($this->comment).
"'";
777 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
778 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
779 $sql .=
", '".$this->db->escape($this->ics).
"'";
780 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
783 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
784 $resql = $this->db->query(
$sql);
786 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
788 $result = $this->
update($user, 1);
791 $accline->datec = $this->db->idate($now);
792 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
794 $accline->fk_user_author = $user->id;
795 $accline->fk_account = $this->id;
796 $accline->datev = $this->db->idate($this->date_solde);
797 $accline->dateo = $this->db->idate($this->date_solde);
798 $accline->fk_type =
'SOLD';
800 if ($accline->insert() < 0) {
802 $this->
error = $accline->error;
803 $this->errors = $accline->errors;
813 if (!$error && !$notrigger) {
815 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
825 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
826 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
829 $this->
error = $this->db->error().
" sql=".
$sql;
838 $this->db->rollback();
852 global $langs, $conf;
859 if (empty($this->country_id)) {
860 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
864 if (empty($this->
ref)) {
865 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
870 $this->label =
"???";
873 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
875 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
876 $sql .=
",label = '".$this->db->escape($this->label).
"'";
878 $sql .=
",courant = ".((int) $this->courant);
879 $sql .=
",clos = ".((int) $this->clos);
880 $sql .=
",rappro = ".((int) $this->rappro);
881 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
882 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
883 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
884 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
885 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
886 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
887 $sql .=
",number='".$this->db->escape($this->number).
"'";
888 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
889 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
890 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
891 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
892 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
893 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
894 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
895 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
896 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
897 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
899 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
901 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
902 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
903 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
905 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
906 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
907 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
908 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
910 $sql .=
" WHERE rowid = ".((int) $this->
id);
912 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
913 $result = $this->db->query(
$sql);
923 if (!$error && !$notrigger) {
925 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
933 $this->
error = $this->db->lasterror();
941 $this->db->rollback();
957 global $conf, $langs;
960 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
962 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
966 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
970 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
971 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
972 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
973 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
974 $sql .=
",number='".$this->db->escape($this->number).
"'";
975 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
976 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
977 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
978 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
979 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
980 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
981 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
982 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
983 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
984 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
985 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
986 $sql .=
" WHERE rowid = ".((int) $this->
id);
987 $sql .=
" AND entity = ".((int) $conf->entity);
989 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
991 $result = $this->db->query(
$sql);
995 $this->
error = $this->db->lasterror();
1011 if (empty($id) && empty($ref)) {
1012 $this->
error =
"ErrorBadParameters";
1016 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
1017 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1018 $sql .=
" ba.domiciliation as address, ba.pti_in_ctti, ba.proprio, ba.owner_address, ba.owner_zip, ba.owner_town, ba.owner_country_id, ba.state_id, ba.fk_pays as country_id,";
1019 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1020 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1021 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1022 $sql .=
' c.code as country_code, c.label as country,';
1023 $sql .=
' d.code_departement as state_code, d.nom as state,';
1024 $sql .=
' aj.code as accountancy_journal';
1025 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1026 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1027 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1028 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1029 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1031 $sql .=
" AND ba.rowid = ".((int) $id);
1034 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1037 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1038 $result = $this->db->query(
$sql);
1040 if ($this->db->num_rows($result)) {
1041 $obj = $this->db->fetch_object($result);
1043 $this->
id = $obj->rowid;
1044 $this->
rowid = $obj->rowid;
1045 $this->
ref = $obj->ref;
1046 $this->label = $obj->label;
1047 $this->
type = $obj->courant;
1048 $this->courant = $obj->courant;
1049 $this->bank = $obj->bank;
1050 $this->clos = $obj->clos;
1051 $this->rappro = $obj->rappro;
1052 $this->url = $obj->url;
1054 $this->code_banque = $obj->code_banque;
1055 $this->code_guichet = $obj->code_guichet;
1056 $this->number = $obj->number;
1057 $this->cle_rib = $obj->cle_rib;
1058 $this->bic = $obj->bic;
1059 $this->iban = $obj->iban;
1060 $this->domiciliation = $obj->address;
1061 $this->address = $obj->address;
1062 $this->pti_in_ctti = $obj->pti_in_ctti;
1063 $this->proprio = $obj->proprio;
1064 $this->owner_address = $obj->owner_address;
1065 $this->owner_zip = $obj->owner_zip;
1066 $this->owner_town = $obj->owner_town;
1067 $this->owner_country_id = $obj->owner_country_id;
1069 $this->state_id = $obj->state_id;
1070 $this->state_code = $obj->state_code;
1071 $this->state = $obj->state;
1073 $this->country_id = $obj->country_id;
1074 $this->country_code = $obj->country_code;
1075 $this->country = $obj->country;
1077 $this->account_number = $obj->account_number;
1078 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1079 $this->accountancy_journal = $obj->accountancy_journal;
1081 $this->currency_code = $obj->currency_code;
1082 $this->account_currency_code = $obj->currency_code;
1083 $this->min_allowed = $obj->min_allowed;
1084 $this->min_desired = $obj->min_desired;
1085 $this->comment = $obj->comment;
1087 $this->date_creation = $this->db->jdate($obj->date_creation);
1088 $this->date_modification = $this->db->jdate($obj->date_modification);
1091 $this->ics = $obj->ics;
1092 $this->ics_transfer = $obj->ics_transfer;
1103 $this->
error = $this->db->lasterror();
1104 $this->errors[] = $this->error;
1121 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1122 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1131 public function delete(
User $user =
null)
1141 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1142 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1144 $resql = $this->db->query(
$sql);
1147 $this->
error =
"Error ".$this->db->lasterror();
1152 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1153 $sql .=
" WHERE rowid = ".((int) $this->
id);
1155 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1156 $result = $this->db->query(
$sql);
1163 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1168 $this->
error =
"Error ".$this->db->lasterror();
1173 $this->db->commit();
1176 $this->db->rollback();
1190 return $this->
LibStatut($this->clos, $mode);
1205 $langs->load(
'banks');
1207 if ($status == self::STATUS_OPEN) {
1208 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1209 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1210 $statusType =
'status4';
1212 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1213 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1214 $statusType =
'status5';
1217 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1230 $can_be_deleted =
false;
1232 $sql =
"SELECT COUNT(rowid) as nb";
1233 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1234 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1236 $resql = $this->db->query(
$sql);
1238 $obj = $this->db->fetch_object($resql);
1239 if ($obj->nb <= 1) {
1240 $can_be_deleted =
true;
1245 return $can_be_deleted;
1256 return $this->error;
1267 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1271 $sql =
"SELECT sum(amount) as amount";
1272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1273 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1275 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1278 $resql = $this->db->query(
$sql);
1280 if ($this->db->num_rows($resql)) {
1281 $obj = $this->db->fetch_object($resql);
1282 $solde = $obj->amount;
1284 $this->db->free($resql);
1286 $this->errors[] = $this->db->lasterror;
1304 global $conf, $langs;
1310 $sql =
"SELECT b.rowid, b.datev as datefin";
1311 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1312 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1313 $sql .=
" WHERE b.rappro=0";
1314 $sql .=
" AND b.fk_account = ba.rowid";
1315 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1316 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1317 $sql .=
" AND clos = 0";
1318 if ($filteraccountid) {
1319 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1322 $resql = $this->db->query(
$sql);
1324 $langs->load(
"banks");
1327 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1330 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1331 $response->label = $langs->trans(
"TransactionsToConciliate");
1332 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1333 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1336 while ($obj = $this->db->fetch_object($resql)) {
1337 $response->nbtodo++;
1338 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1339 $response->nbtodolate++;
1346 $this->
error = $this->db->error();
1367 $sql =
"SELECT count(b.rowid) as nb";
1368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1369 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1370 $sql .=
" WHERE b.fk_account = ba.rowid";
1371 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1372 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1373 $sql .=
" AND clos = 0";
1374 if ($filteraccountid) {
1375 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1378 $resql = $this->db->query(
$sql);
1380 while ($obj = $this->db->fetch_object($resql)) {
1381 $this->nb[
"banklines"] = $obj->nb;
1383 $this->db->free($resql);
1387 $this->
error = $this->db->error();
1400 global $db, $conf, $user;
1409 $sql =
"SELECT COUNT(ba.rowid) as nb";
1410 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1411 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1412 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1413 if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
1414 $sql .=
" AND ba.courant != 2";
1416 $resql = $this->db->query(
$sql);
1418 $obj = $this->db->fetch_object($resql);
1437 $langs->loadLangs([
'banks',
'compta']);
1438 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1442 $nofetch = !empty($params[
'nofetch']);
1443 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1444 if (isset($this->status)) {
1445 $pictos .=
' '.$this->getLibStatut(5);
1447 $datas[
'picto'] = $pictos;
1448 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1449 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1451 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1452 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1455 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1456 $langs->load(
"accountancy");
1457 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1458 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1462 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1464 $datas[
'categories'] =
'<br>' .
$form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1481 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1483 global $conf, $langs;
1485 if (!empty($conf->dol_no_mouse_hover)) {
1489 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1492 $classfortooltip =
'classfortooltip';
1496 'objecttype' => $this->element,
1497 'option' => $option,
1501 $classfortooltip =
'classforajaxtooltip';
1502 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1508 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1509 if ($mode ==
'transactions') {
1510 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1511 } elseif ($mode ==
'receipts') {
1512 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1515 if ($option !=
'nolink') {
1517 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1518 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1519 $add_save_lastsearch_values = 1;
1521 if ($add_save_lastsearch_values) {
1522 $url .=
'&save_lastsearch_values=1';
1527 if (empty($notooltip)) {
1529 $label = $langs->trans(
"BankAccount");
1530 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1532 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1533 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1535 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1538 if ($option ==
'nolink' || empty($url)) {
1539 $linkstart =
'<span';
1541 $linkstart =
'<a href="'.$url.
'"';
1543 $linkstart .= $linkclose.
'>';
1544 if ($option ==
'nolink' || empty($url)) {
1545 $linkend =
'</span>';
1550 $result .= $linkstart;
1553 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1555 if ($withpicto != 2) {
1556 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1558 $result .= $linkend;
1574 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1576 $this->error_number = 0;
1581 $this->error_number = 12;
1582 $this->error_message =
'IBANNotValid';
1585 $this->error_number = 12;
1586 $this->error_message =
'SwiftNotValid';
1594 if ($this->error_number == 0) {
1611 if (!empty($this->country_code)) {
1612 return $this->country_code;
1616 if (!empty($this->iban)) {
1619 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1625 if (!empty($this->socid)) {
1626 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1627 $company =
new Societe($this->db);
1628 $result = $company->fetch($this->socid);
1629 if (!empty($company->country_code)) {
1630 return $company->country_code;
1635 if (!empty($mysoc->country_code)) {
1636 return $mysoc->country_code;
1654 if (in_array($country_code, array(
'FR',
'ES',
'GA',
'IT',
'NC'))) {
1657 if (in_array($country_code, array(
'AD',
'AU',
'BE',
'CA',
'DE',
'DK',
'GR',
'GB',
'ID',
'IE',
'IR',
'KR',
'NL',
'NZ',
'UK',
'US'))) {
1672 if (!empty($conf->global->MAIN_IBAN_IS_NEVER_MANDATORY)) {
1678 $country_code_in_EEC = array(
1714 if (in_array($country_code, $country_code_in_EEC)) {
1749 if ($detailedBBAN == 0) {
1750 $fieldarray = array(
1753 } elseif ($detailedBBAN == 2) {
1754 $fieldarray = array(
1763 if ($includeibanbic) {
1764 $fieldarray[] =
'IBAN';
1765 $fieldarray[] =
'BIC';
1787 $fieldlists = array(
1790 'BankAccountNumber',
1791 'BankAccountNumberKey'
1794 if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {
1795 if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1796 if ($conf->global->BANK_SHOW_ORDER_OPTION ==
'1') {
1797 $fieldlists = array(
1800 'BankAccountNumberKey',
1806 $fieldlists = explode(
1808 preg_replace(
'/ ?[^Bank]AccountNumber ?/',
'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1827 $this->specimen = 1;
1829 $this->label =
'My Big Company Bank account';
1830 $this->bank =
'MyBank';
1832 $this->clos = Account::STATUS_OPEN;
1833 $this->code_banque =
'30001';
1834 $this->code_guichet =
'00794';
1835 $this->number =
'12345678901';
1836 $this->cle_rib =
'85';
1837 $this->bic =
'AA12';
1838 $this->iban =
'FR7630001007941234567890185';
1839 $this->domiciliation =
'Banque de France';
1840 $this->proprio =
'Owner';
1841 $this->owner_address =
'Owner address';
1842 $this->owner_zip =
'Owner zip';
1843 $this->owner_town =
'Owner town';
1844 $this->owner_country_id =
'Owner country_id';
1845 $this->country_id = 1;
1858 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_url SET url_id = ".((int) $dest_id).
" WHERE url_id = ".((int) $origin_id).
" AND type='company'";
1860 if ($dbs->query(
$sql)) {
1880 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1882 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1883 $return .=
'<div class="info-box info-box-sm">';
1884 $return .=
'<span class="info-box-icon bg-infobox-action">';
1886 $return .=
'</span>';
1887 $return .=
'<div class="info-box-content">';
1888 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1889 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1891 if (property_exists($this,
'type_lib')) {
1892 $return .=
'<br><span class="info-box-label opacitymedium" title="'.$this->type_lib[$this->type].
'">'.substr($this->type_lib[$this->
type], 0, 24).
'...</span>';
1894 if (method_exists($this,
'solde')) {
1895 $return .=
'<br><a href="'.DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->
id.
'">';
1896 $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>';
1898 if (method_exists($this,
'getLibStatut')) {
1899 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1901 $return .=
'</div>';
1902 $return .=
'</div>';
1903 $return .=
'</div>';
1909 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1929 public $element =
'bank';
1934 public $table_element =
'bank';
1939 public $picto =
'accountline';
1973 public $amount_main_currency;
1978 public $fk_user_author;
1983 public $fk_user_rappro;
1993 public $fk_bordereau;
2003 public $bank_account_ref;
2008 public $bank_account_label;
2013 public $numero_compte;
2052 public function fetch($rowid, $ref =
'', $num =
'')
2057 if (empty($rowid) && empty($ref) && empty($num)) {
2061 $sql =
"SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
2062 $sql .=
" b.fk_user_author, b.fk_user_rappro,";
2063 $sql .=
" b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
2064 $sql .=
" b.fk_bordereau, b.banque, b.emetteur,";
2065 $sql .=
" ba.ref as bank_account_ref, ba.label as bank_account_label";
2066 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
2067 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
2068 $sql .=
" WHERE b.fk_account = ba.rowid";
2069 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
2071 $sql .=
" AND b.num_chq='".$this->db->escape($num).
"'";
2073 $sql .=
" AND b.rowid='".$this->db->escape($ref).
"'";
2075 $sql .=
" AND b.rowid = ".((int) $rowid);
2078 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
2079 $result = $this->db->query(
$sql);
2083 $obj = $this->db->fetch_object($result);
2085 $this->
id = $obj->rowid;
2086 $this->
rowid = $obj->rowid;
2087 $this->
ref = $obj->rowid;
2089 $this->datec = $obj->datec;
2090 $this->datev = $obj->datev;
2091 $this->dateo = $obj->dateo;
2092 $this->amount = $obj->amount;
2093 $this->label = $obj->label;
2094 $this->note = $obj->note;
2096 $this->fk_user_author = $obj->fk_user_author;
2097 $this->fk_user_rappro = $obj->fk_user_rappro;
2099 $this->fk_type = $obj->fk_type;
2100 $this->rappro = $obj->rappro;
2101 $this->num_releve = $obj->num_releve;
2103 $this->num_chq = $obj->num_chq;
2104 $this->bank_chq = $obj->banque;
2105 $this->fk_bordereau = $obj->fk_bordereau;
2107 $this->fk_account = $obj->fk_account;
2108 $this->bank_account_ref = $obj->bank_account_ref;
2109 $this->bank_account_label = $obj->bank_account_label;
2117 $this->db->free($result);
2135 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank (";
2141 $sql .=
", amount_main_currency";
2142 $sql .=
", fk_user_author";
2143 $sql .=
", num_chq";
2144 $sql .=
", fk_account";
2145 $sql .=
", fk_type";
2146 $sql .=
", emetteur,banque";
2148 $sql .=
", numero_compte";
2149 $sql .=
", num_releve";
2150 $sql .=
") VALUES (";
2151 $sql .=
"'".$this->db->idate($this->datec).
"'";
2152 $sql .=
", '".$this->db->idate($this->dateo).
"'";
2153 $sql .=
", '".$this->db->idate($this->datev).
"'";
2154 $sql .=
", '".$this->db->escape($this->label).
"'";
2155 $sql .=
", ".price2num($this->amount);
2156 $sql .=
", ".(empty($this->amount_main_currency) ?
"NULL" :
price2num($this->amount_main_currency));
2157 $sql .=
", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) :
"null");
2158 $sql .=
", ".($this->num_chq ?
"'".$this->db->escape($this->num_chq).
"'" :
"null");
2159 $sql .=
", '".$this->db->escape($this->fk_account).
"'";
2160 $sql .=
", '".$this->db->escape($this->fk_type).
"'";
2161 $sql .=
", ".($this->emetteur ?
"'".$this->db->escape($this->emetteur).
"'" :
"null");
2162 $sql .=
", ".($this->bank_chq ?
"'".$this->db->escape($this->bank_chq).
"'" :
"null");
2163 $sql .=
", ".(int) $this->rappro;
2164 $sql .=
", ".($this->numero_compte ?
"'".$this->db->escape($this->numero_compte).
"'" :
"''");
2165 $sql .=
", ".($this->num_releve ?
"'".$this->db->escape($this->num_releve).
"'" :
"null");
2168 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2169 $resql = $this->db->query(
$sql);
2171 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'bank');
2179 $this->error = $this->db->lasterror();
2184 $this->db->commit();
2187 $this->db->rollback();
2198 public function delete(
User $user =
null)
2204 if ($this->rappro) {
2206 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2213 if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING)) {
2214 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2215 $resql = $this->db->query(
$sql);
2217 $obj = $this->db->fetch_object($resql);
2218 if ($obj && $obj->nb) {
2219 $this->error =
'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2220 $this->db->rollback();
2224 $this->error = $this->db->lasterror();
2225 $this->db->rollback();
2236 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class WHERE lineid=".(int) $this->
rowid;
2237 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2238 $result = $this->db->query(
$sql);
2243 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_extrafields WHERE fk_object=".(int) $this->
rowid;
2244 $result = $this->db->query(
$sql);
2249 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid=".(int) $this->
rowid;
2250 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2251 $result = $this->db->query(
$sql);
2257 $this->db->commit();
2260 $this->db->rollback();
2278 if ($this->rappro) {
2280 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2286 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url WHERE fk_bank=".(int) $this->
rowid;
2287 dol_syslog(get_class($this).
"::delete_urls", LOG_DEBUG);
2288 $result = $this->db->query(
$sql);
2294 $this->db->commit();
2297 $this->db->rollback();
2314 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2315 $sql .=
" amount = ".price2num($this->amount).
",";
2316 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
2317 $sql .=
" dateo='".$this->db->idate($this->dateo).
"'";
2318 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
2320 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2321 $resql = $this->db->query(
$sql);
2323 $this->db->commit();
2326 $this->db->rollback();
2327 $this->error = $this->db->error();
2345 global $conf, $langs;
2350 if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE)) {
2351 if (!preg_match(
'/'.$conf->global->BANK_STATEMENT_REGEX_RULE.
'/', $this->num_releve)) {
2352 $this->errors[] = $langs->trans(
"ErrorBankStatementNameMustFollowRegex", $conf->global->BANK_STATEMENT_REGEX_RULE);
2357 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2358 $sql .=
" rappro = ".((int) $conciliated);
2359 $sql .=
", num_releve = '".$this->db->escape($this->num_releve).
"'";
2361 $sql .=
", fk_user_rappro = ".$user->id;
2363 $sql .=
" WHERE rowid = ".((int) $this->
id);
2365 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2366 $resql = $this->db->query(
$sql);
2368 if (!empty($cat) && $cat > 0) {
2369 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class (";
2371 $sql .=
", fk_categ";
2372 $sql .=
") VALUES (";
2374 $sql .=
", ".((int) $cat);
2377 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2378 $this->db->query(
$sql);
2386 $this->db->commit();
2389 $this->db->rollback();
2406 $sql =
"SELECT datev FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2407 $resql = $this->db->query(
$sql);
2409 $obj = $this->db->fetch_object($resql);
2410 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2412 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2413 $sql .=
" datev = '".$this->db->idate($newdate).
"'";
2414 $sql .=
" WHERE rowid = ".((int) $rowid);
2416 $result = $this->db->query(
$sql);
2418 if ($this->db->affected_rows($result)) {
2469 $sql =
"SELECT dateo FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2470 $resql = $this->db->query(
$sql);
2472 $obj = $this->db->fetch_object($resql);
2473 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2475 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2476 $sql .=
" dateo = '".$this->db->idate($newdate).
"'";
2477 $sql .=
" WHERE rowid = ".((int) $rowid);
2479 $result = $this->db->query(
$sql);
2481 if ($this->db->affected_rows($result)) {
2529 $sql =
'SELECT b.rowid, b.datec, b.tms as datem,';
2530 $sql .=
' b.fk_user_author, b.fk_user_rappro';
2531 $sql .=
' FROM '.MAIN_DB_PREFIX.
'bank as b';
2532 $sql .=
' WHERE b.rowid = '.((int) $id);
2534 $result = $this->db->query(
$sql);
2536 if ($this->db->num_rows($result)) {
2537 $obj = $this->db->fetch_object($result);
2538 $this->
id = $obj->rowid;
2540 if ($obj->fk_user_author) {
2541 $cuser =
new User($this->db);
2542 $cuser->fetch($obj->fk_user_author);
2543 $this->user_creation = $cuser;
2545 if ($obj->fk_user_rappro) {
2546 $ruser =
new User($this->db);
2547 $ruser->fetch($obj->fk_user_rappro);
2548 $this->user_rappro = $ruser;
2551 $this->date_creation = $this->db->jdate($obj->datec);
2552 $this->date_modification = $this->db->jdate($obj->datem);
2555 $this->db->free($result);
2571 public function getNomUrl($withpicto = 0, $maxlen = 0, $option =
'', $notooltip = 0)
2573 global $conf, $langs;
2577 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"BankTransactionLine").
'</u>:<br>';
2578 $label .=
'<b>'.$langs->trans(
"Ref").
':</b> '.$this->ref;
2579 if ($this->amount) {
2580 $label .=
'<br><strong>'.$langs->trans(
"Amount").
':</strong> '.
price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2583 $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">';
2586 $result .= $linkstart;
2588 $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);
2590 if ($withpicto != 2) {
2591 $result .= ($this->
ref ? $this->
ref : $this->id);
2594 $result .= $linkend;
2596 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2597 $result .=
' <span class="opacitymedium">(';
2599 if ($option ==
'showall') {
2600 $result .= $langs->trans(
"BankAccount").
': ';
2601 $accountstatic =
new Account($this->db);
2602 $accountstatic->id = $this->fk_account;
2603 $accountstatic->ref = $this->bank_account_ref;
2604 $accountstatic->label = $this->bank_account_label;
2605 $result .= $accountstatic->getNomUrl(0).
', ';
2607 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2608 $result .= $langs->trans(
"BankLineConciliated").
': ';
2609 $result .=
yn($this->rappro);
2611 if (
isModEnabled(
'accounting') && ($option ==
'showall' || $option ==
'showconciliatedandaccounted')) {
2612 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
2613 $sql .=
" WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2614 $resql = $this->db->query(
$sql);
2616 $obj = $this->db->fetch_object($resql);
2617 if ($obj && $obj->nb) {
2618 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(1);
2620 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(0);
2624 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2625 $result .=
')</span>';
2640 return $this->
LibStatut($this->status, $mode);
2700 $alreadydispatched = 0;
2704 $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);
2705 $resql = $this->db->query(
$sql);
2707 $obj = $this->db->fetch_object($resql);
2709 $alreadydispatched = $obj->nb;
2712 $this->error = $this->db->lasterror();
2716 if ($alreadydispatched) {
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
checkIbanForAccount(Account $account)
Check IBAN number informations for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current sold.
fetch($id, $ref='')
Load a bank account into memory from database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $mode='', $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clicable name (with picto eventually)
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
static replaceThirdparty($dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
update(User $user, $notrigger=0)
Update bank account card.
getCountryCode()
Return account country code.
needIBAN()
Return 1 if IBAN / BIC is mandatory (otherwise option)
getLibStatut($mode=0)
Return label of object status.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
__toString()
Shows the account number in the appropriate format.
const TYPE_SAVINGS
Savings account.
useDetailedBBAN()
Return if a bank account is defined with detailed information (bank code, desk code,...
static getAccountNumberOrder()
Returns the components of the bank account in order.
load_state_board($filteraccountid=0)
Charge indicateurs this->nb de tableau de bord.
getTooltipContentArray($params)
getTooltipContentArray
canBeConciliated()
Return if a bank account need to be conciliated.
create(User $user, $notrigger=0)
Create bank account into database.
can_be_deleted()
Renvoi si un compte peut etre supprimer ou non (sans mouvements)
update_bban(User $user=null)
Update BBAN (RIB) account fields.
const TYPE_CURRENT
Current account.
setCategories($categories)
Sets object to supplied categories.
countAccountToReconcile()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
verif()
Return if an account has valid information for Direct debit payment.
initAsSpecimen()
Initialise an instance with random values.
get_url($fk_bank='', $url_id='', $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null)
Add an entry into table ".MAIN_DB_PREFIX."bank.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
info($id)
Load miscellaneous information for tab "Info".
__construct(DoliDB $db)
Constructor.
update_conciliation(User $user, $cat, $conciliated=1)
Update conciliation field.
getLibStatut($mode=0)
Return the label of the status.
fetch($rowid, $ref='', $num='')
Load into memory content of a bank transaction line.
dateo_change($rowid, $sign=1)
Increase/decrease operation date of a rowid.
datev_next($id)
Increase value date of a rowid.
LibStatut($status, $mode=0)
Return the label of a given status.
update(User $user, $notrigger=0)
Update bank account record in database.
insert()
Inserts a transaction to a bank account.
getNomUrl($withpicto=0, $maxlen=0, $option='', $notooltip=0)
Return clickable name (with picto eventually)
delete_urls(User $user=null)
Delete bank line records.
getVentilExportCompta()
Return if a bank line was dispatched into bookkeeping.
datev_change($rowid, $sign=1)
Increase/decrease value date of a rowid.
dateo_previous($id)
Decrease operation date of a rowid.
dateo_next($id)
Increase operation date of a rowid.
datev_previous($id)
Decrease value date of a rowid.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type