35require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
46 public $element =
'bank_account';
51 public $table_element =
'bank_account';
56 public $picto =
'account';
98 public $clos = self::STATUS_OPEN;
122 public $code_guichet;
160 public $pti_in_ctti = 0;
180 public $owner_address;
193 public $owner_country_id;
194 public $owner_country_code;
202 public $domiciliation;
219 public $type_lib = array();
225 public $account_number;
230 public $fk_accountancy_journal;
235 public $accountancy_journal;
241 public $currency_code;
249 public $account_currency_code;
299 public $ics_transfer;
335 public $fields = array(
336 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
337 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 25),
338 'label' => array(
'type' =>
'varchar(30)',
'label' =>
'Label',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 30),
339 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 35,
'index' => 1),
340 'bank' => array(
'type' =>
'varchar(60)',
'label' =>
'Bank',
'enabled' => 1,
'visible' => -1,
'position' => 40),
341 'code_banque' => array(
'type' =>
'varchar(128)',
'label' =>
'Code banque',
'enabled' => 1,
'visible' => -1,
'position' => 45),
342 'code_guichet' => array(
'type' =>
'varchar(6)',
'label' =>
'Code guichet',
'enabled' => 1,
'visible' => -1,
'position' => 50),
343 'number' => array(
'type' =>
'varchar(255)',
'label' =>
'Number',
'enabled' => 1,
'visible' => -1,
'position' => 55),
344 'cle_rib' => array(
'type' =>
'varchar(5)',
'label' =>
'Cle rib',
'enabled' => 1,
'visible' => -1,
'position' => 60),
345 'bic' => array(
'type' =>
'varchar(11)',
'label' =>
'Bic',
'enabled' => 1,
'visible' => -1,
'position' => 65),
346 'iban_prefix' => array(
'type' =>
'varchar(34)',
'label' =>
'Iban prefix',
'enabled' => 1,
'visible' => -1,
'position' => 70),
347 'country_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Country iban',
'enabled' => 1,
'visible' => -1,
'position' => 75),
348 'cle_iban' => array(
'type' =>
'varchar(2)',
'label' =>
'Cle iban',
'enabled' => 1,
'visible' => -1,
'position' => 80),
349 'domiciliation' => array(
'type' =>
'varchar(255)',
'label' =>
'Domiciliation',
'enabled' => 1,
'visible' => -1,
'position' => 85),
350 'state_id' => array(
'type' =>
'integer',
'label' =>
'StateId',
'enabled' => 1,
'visible' => -1,
'position' => 90),
351 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 95),
352 'proprio' => array(
'type' =>
'varchar(60)',
'label' =>
'Proprio',
'enabled' => 1,
'visible' => -1,
'position' => 100),
353 'owner_address' => array(
'type' =>
'varchar(255)',
'label' =>
'Owner address',
'enabled' => 1,
'visible' => -1,
'position' => 105),
354 'owner_zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Owner zip',
'enabled' => 1,
'visible' => -1,
'position' => 106),
355 'owner_town' => array(
'type' =>
'varchar(50)',
'label' =>
'Owner town',
'enabled' => 1,
'visible' => -1,
'position' => 107),
356 'owner_country_id' => array(
'type' =>
'integer',
'label' =>
'Owner country',
'enabled' => 1,
'visible' => -1,
'position' => 108),
357 'courant' => array(
'type' =>
'smallint(6)',
'label' =>
'Courant',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 110),
358 'clos' => array(
'type' =>
'smallint(6)',
'label' =>
'Clos',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 115),
359 'rappro' => array(
'type' =>
'smallint(6)',
'label' =>
'Rappro',
'enabled' => 1,
'visible' => -1,
'position' => 120),
360 'url' => array(
'type' =>
'varchar(128)',
'label' =>
'Url',
'enabled' => 1,
'visible' => -1,
'position' => 125),
361 'account_number' => array(
'type' =>
'varchar(32)',
'label' =>
'Account number',
'enabled' => 1,
'visible' => -1,
'position' => 130),
362 'fk_accountancy_journal' => array(
'type' =>
'integer',
'label' =>
'Accountancy journal ID',
'enabled' => 1,
'visible' => -1,
'position' => 132),
363 'accountancy_journal' => array(
'type' =>
'varchar(20)',
'label' =>
'Accountancy journal',
'enabled' => 1,
'visible' => -1,
'position' => 135),
364 'currency_code' => array(
'type' =>
'varchar(3)',
'label' =>
'Currency code',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 140),
365 'min_allowed' => array(
'type' =>
'integer',
'label' =>
'Min allowed',
'enabled' => 1,
'visible' => -1,
'position' => 145),
366 'min_desired' => array(
'type' =>
'integer',
'label' =>
'Min desired',
'enabled' => 1,
'visible' => -1,
'position' => 150),
367 'comment' => array(
'type' =>
'text',
'label' =>
'Comment',
'enabled' => 1,
'visible' => -1,
'position' => 155),
368 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 156),
369 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 157),
370 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 160),
371 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 165),
372 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 170),
373 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 175),
374 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 180),
375 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 185),
393 const STATUS_OPEN = 0;
394 const STATUS_CLOSED = 1;
408 $this->ismultientitymanaged = 1;
412 $this->type_lib = array(
413 self::TYPE_SAVINGS => $langs->transnoentitiesnoconv(
"BankType0"),
414 self::TYPE_CURRENT => $langs->transnoentitiesnoconv(
"BankType1"),
415 self::TYPE_CASH => $langs->transnoentitiesnoconv(
"BankType2"),
418 $this->labelStatus = array(
419 self::STATUS_OPEN => $langs->transnoentitiesnoconv(
"StatusAccountOpened"),
420 self::STATUS_CLOSED => $langs->transnoentitiesnoconv(
"StatusAccountClosed")
433 if ($val ==
'BankCode') {
434 $string .= $this->code_banque.
' ';
435 } elseif ($val ==
'BankAccountNumber') {
436 $string .= $this->number.
' ';
437 } elseif ($val ==
'DeskCode') {
438 $string .= $this->code_guichet.
' ';
439 } elseif ($val ==
'BankAccountNumberKey') {
440 $string .= $this->cle_rib.
' ';
441 } elseif ($val ==
'BIC') {
442 $string .= $this->bic.
' ';
443 } elseif ($val ==
'IBAN') {
444 $string .= $this->iban.
' ';
448 return trim($string);
461 if (empty($this->rappro)) {
490 $sqlcheck =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"bank_url";
491 $sqlcheck .=
" WHERE fk_bank = ".((int) $line_id);
492 $sqlcheck .=
" AND url_id = ".((int) $url_id);
493 $sqlcheck .=
" AND type = '".$this->db->escape($type).
"'";
494 $resqlcheck = $this->db->query($sqlcheck);
496 $obj = $this->db->fetch_object($resqlcheck);
498 $this->db->free($resqlcheck);
499 return (
int) $obj->rowid;
501 $this->db->free($resqlcheck);
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;
603 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
608 if (is_numeric($oper)) {
609 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
612 if (empty($this->
id) && !empty($this->
rowid)) {
613 $this->
id = $this->rowid;
617 $emetteur = trim($emetteur);
618 $banque = trim($banque);
619 $label = trim($label);
623 if (is_numeric($oper)) {
624 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
625 $sql .=
" WHERE id = ".((int) $oper);
626 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
627 $resql = $this->db->query($sql);
629 $obj = $this->db->fetch_object($resql);
639 $this->
error = $langs->trans(
"OperNotDefined");
643 $this->
error = $langs->trans(
"ThisIdNotDefined");
647 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
653 if (is_null($datev) || empty($datev)) {
658 $accline->datec = $now;
659 $accline->dateo = $date;
660 $accline->datev = $datev;
661 $accline->label = $label;
662 $accline->amount = $amount;
663 $accline->amount_main_currency = $amount_main_currency;
664 $accline->fk_user_author = $user->id;
665 $accline->fk_account = $this->id;
666 $accline->fk_type = $oper;
667 $accline->numero_compte = $accountancycode;
668 $accline->num_releve = $num_releve;
671 $accline->num_chq = $num_chq;
675 $accline->emetteur = $emetteur;
679 $accline->bank_chq = $banque;
682 if ($accline->insert() > 0) {
683 if ($categorie > 0) {
684 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
685 $sql .=
"lineid, fk_categ";
686 $sql .=
") VALUES (";
687 $sql .= ((int) $accline->id).
", '".$this->db->escape($categorie).
"'";
690 $result = $this->db->query($sql);
692 $this->
error = $this->db->lasterror();
693 $this->db->rollback();
704 $this->db->rollback();
719 global $langs, $conf;
724 if (!$this->min_allowed) {
725 $this->min_allowed = 0;
727 if (!$this->min_desired) {
728 $this->min_desired = 0;
732 if (empty($this->country_id)) {
733 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
737 if (empty($this->
ref)) {
738 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
742 if (empty($this->date_solde)) {
743 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
749 $balance = $this->balance;
750 if (empty($balance) && !empty($this->
solde)) {
751 $balance = $this->solde;
753 if (empty($balance)) {
756 if (empty($this->address && !empty($this->domiciliation))) {
757 dol_syslog(get_class($this).
"::create domiciliation is deprecated use address", LOG_NOTICE);
758 $this->address = $this->domiciliation;
760 if (empty($this->
status && !empty($this->clos))) {
761 dol_syslog(get_class($this).
"::create clos is deprecated use status", LOG_NOTICE);
762 $this->
status = $this->clos;
765 if (empty($this->address && !empty($this->domiciliation))) {
766 dol_syslog(get_class($this).
"::create domiciliation is deprecated use address", LOG_NOTICE);
767 $this->address = $this->domiciliation;
771 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
777 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
782 $sql .=
", account_number";
783 $sql .=
", fk_accountancy_journal";
785 $sql .=
", code_banque";
786 $sql .=
", code_guichet";
790 $sql .=
", iban_prefix";
791 $sql .=
", domiciliation";
792 $sql .=
", pti_in_ctti";
794 $sql .=
", owner_address";
795 $sql .=
", owner_zip";
796 $sql .=
", owner_town";
797 $sql .=
", owner_country_id";
798 $sql .=
", currency_code";
800 $sql .=
", min_allowed";
801 $sql .=
", min_desired";
803 $sql .=
", state_id";
806 $sql .=
", ics_transfer";
807 $sql .=
") VALUES (";
808 $sql .=
"'".$this->db->idate($now).
"'";
809 $sql .=
", '".$this->db->escape($this->
ref).
"'";
810 $sql .=
", '".$this->db->escape($this->label).
"'";
811 $sql .=
", ".((int) $conf->entity);
812 $sql .=
", '".$this->db->escape($this->account_number).
"'";
813 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
814 $sql .=
", '".$this->db->escape($this->bank).
"'";
815 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
816 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
817 $sql .=
", '".$this->db->escape($this->number).
"'";
818 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
819 $sql .=
", '".$this->db->escape($this->bic).
"'";
820 $sql .=
", '".$this->db->escape($this->iban).
"'";
821 $sql .=
", '".$this->db->escape($this->address).
"'";
822 $sql .=
", ".((int) $this->pti_in_ctti);
823 $sql .=
", '".$this->db->escape($this->owner_name ? $this->owner_name : $this->proprio).
"'";
824 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
825 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
826 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
827 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
828 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
829 $sql .=
", ".((int) $this->rappro);
830 $sql .=
", ".price2num($this->min_allowed,
'MT');
831 $sql .=
", ".price2num($this->min_desired,
'MT');
832 $sql .=
", '".$this->db->escape($this->comment).
"'";
833 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
834 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
835 $sql .=
", '".$this->db->escape($this->ics).
"'";
836 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
839 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
840 $resql = $this->db->query($sql);
842 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
844 $result = $this->
update($user, 1);
847 $accline->datec = $now;
848 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
849 $accline->amount = (float)
price2num($balance);
850 $accline->fk_user_author = $user->id;
851 $accline->fk_account = $this->id;
852 $accline->datev = $this->date_solde;
853 $accline->dateo = $this->date_solde;
854 $accline->fk_type =
'SOLD';
856 if ($accline->insert() < 0) {
858 $this->
error = $accline->error;
859 $this->errors = $accline->errors;
869 if (!$error && !$notrigger) {
871 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
881 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
882 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
885 $this->
error = $this->db->error().
" sql=".$sql;
894 $this->db->rollback();
908 global $langs, $conf;
915 if (empty($this->country_id)) {
916 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
920 if (empty($this->
ref)) {
921 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
926 $this->label =
"???";
929 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
930 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
931 $sql .=
",label = '".$this->db->escape($this->label).
"'";
932 $sql .=
",courant = ".((int) $this->
type);
933 $sql .=
",clos = ".((int) $this->
status);
934 $sql .=
",rappro = ".((int) $this->rappro);
935 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
936 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
937 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
938 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
939 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
940 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
941 $sql .=
",number='".$this->db->escape($this->number).
"'";
942 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
943 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
944 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
945 $sql .=
",domiciliation='".$this->db->escape($this->address).
"'";
946 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
947 $sql .=
",proprio = '".$this->db->escape($this->owner_name ? $this->owner_name : $this->proprio).
"'";
948 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
949 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
950 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
951 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
953 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
955 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
956 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
957 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
959 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
960 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
961 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
962 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
964 $sql .=
" WHERE rowid = ".((int) $this->
id);
966 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
967 $result = $this->db->query($sql);
977 if (!$error && !empty($this->oldref) && $this->oldref !== $this->
ref) {
978 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'bank/".$this->db->escape($this->
ref).
"'";
979 $sql .=
" WHERE filepath = 'bank/".$this->db->escape($this->oldref).
"' and src_object_type='bank_account' and entity = ".((int) $conf->entity);
980 $resql = $this->db->query($sql);
983 $this->
error = $this->db->lasterror();
989 $dirsource = $conf->bank->dir_output.
'/'.$oldref;
990 $dirdest = $conf->bank->dir_output.
'/'.$newref;
991 if (file_exists($dirsource)) {
992 dol_syslog(get_class($this).
"::update rename dir ".$dirsource.
" into ".$dirdest, LOG_DEBUG);
993 if (@rename($dirsource, $dirdest)) {
999 if (!$error && !$notrigger) {
1001 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
1009 $this->
error = $this->db->lasterror();
1014 $this->db->commit();
1017 $this->db->rollback();
1033 global $conf, $langs;
1036 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1038 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1042 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
1046 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET";
1047 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
1048 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
1049 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
1050 $sql .=
",number='".$this->db->escape($this->number).
"'";
1051 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
1052 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
1053 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
1054 $sql .=
",domiciliation='".$this->db->escape($this->address ? $this->address : $this->domiciliation).
"'";
1055 $sql .=
",proprio = '".$this->db->escape($this->owner_name ? $this->owner_name : $this->proprio).
"'";
1056 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
1057 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
1058 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
1059 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
1060 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
1061 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
1062 $sql .=
" WHERE rowid = ".((int) $this->
id);
1063 $sql .=
" AND entity = ".((int) $conf->entity);
1065 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
1067 $result = $this->db->query($sql);
1071 $this->
error = $this->db->lasterror();
1087 if (empty($id) && empty($ref)) {
1088 $this->
error =
"ErrorBadParameters";
1092 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url,";
1093 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1094 $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,";
1095 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1096 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1097 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1098 $sql .=
' c.code as country_code, c.label as country,';
1099 $sql .=
' d.code_departement as state_code, d.nom as state,';
1100 $sql .=
' aj.code as accountancy_journal';
1101 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1102 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1103 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1104 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1105 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1107 $sql .=
" AND ba.rowid = ".((int) $id);
1110 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1113 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1114 $result = $this->db->query($sql);
1116 if ($this->db->num_rows($result)) {
1117 $obj = $this->db->fetch_object($result);
1119 $this->
id = $obj->rowid;
1120 $this->
rowid = $obj->rowid;
1121 $this->
ref = $obj->ref;
1122 $this->label = $obj->label;
1123 $this->
type = $obj->type;
1124 $this->courant = $obj->type;
1125 $this->bank = $obj->bank;
1126 $this->clos = $obj->status;
1127 $this->
status = $obj->status;
1128 $this->rappro = $obj->rappro;
1129 $this->url = $obj->url;
1131 $this->code_banque = $obj->code_banque;
1132 $this->code_guichet = $obj->code_guichet;
1133 $this->number = $obj->number;
1134 $this->cle_rib = $obj->cle_rib;
1135 $this->bic = $obj->bic;
1136 $this->iban = $obj->iban;
1137 $this->domiciliation = $obj->address;
1138 $this->address = $obj->address;
1139 $this->pti_in_ctti = $obj->pti_in_ctti;
1140 $this->proprio = $obj->owner_name;
1141 $this->owner_name = $obj->owner_name;
1142 $this->owner_address = $obj->owner_address;
1143 $this->owner_zip = $obj->owner_zip;
1144 $this->owner_town = $obj->owner_town;
1145 $this->owner_country_id = $obj->owner_country_id;
1147 $this->state_id = $obj->state_id;
1148 $this->state_code = $obj->state_code;
1149 $this->state = $obj->state;
1151 $this->country_id = $obj->country_id;
1152 $this->country_code = $obj->country_code;
1153 $this->country = $obj->country;
1155 $this->account_number = $obj->account_number;
1156 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1157 $this->accountancy_journal = $obj->accountancy_journal;
1159 $this->currency_code = $obj->currency_code;
1160 $this->account_currency_code = $obj->currency_code;
1161 $this->min_allowed = $obj->min_allowed;
1162 $this->min_desired = $obj->min_desired;
1163 $this->comment = $obj->comment;
1165 $this->date_creation = $this->db->jdate($obj->date_creation);
1166 $this->date_modification = $this->db->jdate($obj->date_modification);
1168 $this->ics = $obj->ics;
1169 $this->ics_transfer = $obj->ics_transfer;
1180 $this->
error = $this->db->lasterror();
1181 $this->errors[] = $this->error;
1198 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1199 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1209 public function delete(
User $user =
null, $notrigger = 0)
1219 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1220 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1222 $resql = $this->db->query($sql);
1225 $this->
error =
"Error ".$this->db->lasterror();
1230 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1231 $sql .=
" WHERE rowid = ".((int) $this->
id);
1233 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1234 $result = $this->db->query($sql);
1241 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1246 $this->
error =
"Error ".$this->db->lasterror();
1251 $this->db->commit();
1254 $this->db->rollback();
1283 $langs->load(
'banks');
1285 if ($status == self::STATUS_OPEN) {
1286 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1287 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1288 $statusType =
'status4';
1290 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1291 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1292 $statusType =
'status5';
1295 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1308 $can_be_deleted =
false;
1310 $sql =
"SELECT COUNT(rowid) as nb";
1311 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1312 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1314 $resql = $this->db->query($sql);
1316 $obj = $this->db->fetch_object($resql);
1317 if ($obj->nb <= 1) {
1318 $can_be_deleted =
true;
1323 return $can_be_deleted;
1334 return $this->error;
1345 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1349 $sql =
"SELECT sum(amount) as amount";
1350 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1351 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1353 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1356 $resql = $this->db->query($sql);
1358 if ($this->db->num_rows($resql)) {
1359 $obj = $this->db->fetch_object($resql);
1360 $solde = $obj->amount;
1362 $this->db->free($resql);
1364 $this->errors[] = $this->db->lasterror;
1382 global $conf, $langs;
1388 $sql =
"SELECT b.rowid, b.datev as datefin";
1389 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1390 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1391 $sql .=
" WHERE b.rappro=0";
1392 $sql .=
" AND b.fk_account = ba.rowid";
1393 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1395 $sql .=
" AND clos = 0";
1396 if ($filteraccountid) {
1397 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1400 $resql = $this->db->query($sql);
1402 $langs->load(
"banks");
1405 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1408 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1409 $response->label = $langs->trans(
"TransactionsToConciliate");
1410 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1411 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1414 while ($obj = $this->db->fetch_object($resql)) {
1415 $response->nbtodo++;
1416 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1417 $response->nbtodolate++;
1424 $this->
error = $this->db->error();
1443 $sql =
"SELECT count(b.rowid) as nb";
1444 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1445 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1446 $sql .=
" WHERE b.fk_account = ba.rowid";
1447 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1448 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1449 $sql .=
" AND clos = 0";
1450 if ($filteraccountid) {
1451 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1454 $resql = $this->db->query($sql);
1456 while ($obj = $this->db->fetch_object($resql)) {
1457 $this->nb[
"banklines"] = $obj->nb;
1459 $this->db->free($resql);
1463 $this->
error = $this->db->error();
1485 $sql =
"SELECT COUNT(ba.rowid) as nb";
1486 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1487 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1488 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1493 $resql = $this->db->query($sql);
1495 $obj = $this->db->fetch_object($resql);
1514 $langs->loadLangs([
'banks',
'compta']);
1515 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1519 $nofetch = !empty($params[
'nofetch']);
1520 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1521 if (isset($this->
status)) {
1522 $pictos .=
' '.$this->getLibStatut(5);
1524 $datas[
'picto'] = $pictos;
1525 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1526 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1528 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1529 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1531 if (isModEnabled(
'accounting')) {
1532 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1533 $langs->load(
"accountancy");
1534 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1535 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1538 if (isModEnabled(
'category') && !$nofetch) {
1539 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1540 $form =
new Form($this->db);
1541 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1558 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1560 global $conf, $langs;
1562 if (!empty($conf->dol_no_mouse_hover)) {
1566 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1569 $classfortooltip =
'classfortooltip';
1573 'objecttype' => $this->element,
1574 'option' => $option,
1578 $classfortooltip =
'classforajaxtooltip';
1579 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1585 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1586 if ($mode ==
'transactions') {
1587 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1588 } elseif ($mode ==
'receipts') {
1589 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1592 if ($option !=
'nolink') {
1594 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1595 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1596 $add_save_lastsearch_values = 1;
1598 if ($add_save_lastsearch_values) {
1599 $url .=
'&save_lastsearch_values=1';
1604 if (empty($notooltip)) {
1606 $label = $langs->trans(
"BankAccount");
1607 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1609 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1610 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1612 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1615 if ($option ==
'nolink' || empty($url)) {
1616 $linkstart =
'<span';
1618 $linkstart =
'<a href="'.$url.
'"';
1620 $linkstart .= $linkclose.
'>';
1621 if ($option ==
'nolink' || empty($url)) {
1622 $linkend =
'</span>';
1627 $result .= $linkstart;
1630 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1632 if ($withpicto != 2) {
1633 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1635 $result .= $linkend;
1651 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1658 $this->
error =
'IBANNotValid';
1662 $this->
error =
'SwiftNotValid';
1682 if (!empty($this->country_code)) {
1683 return $this->country_code;
1687 if (!empty($this->iban)) {
1690 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1696 if (!empty($this->socid)) {
1697 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1698 $company =
new Societe($this->db);
1699 $result = $company->fetch($this->socid);
1700 if (!empty($company->country_code)) {
1701 return $company->country_code;
1706 if (!empty($mysoc->country_code)) {
1707 return $mysoc->country_code;
1722 global $conf, $langs;
1729 if (!empty($conf->use_javascript_ajax)) {
1731 $out .=
'<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).
'\',\
''.dol_escape_js($langs->trans(
"HelpCopyToClipboard")).
'\');
">';
1732 $out .= img_picto($langs->trans("Address
"), 'map-marker-alt');
1735 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1755 public function useDetailedBBAN()
1757 $country_code = $this->getCountryCode();
1759 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) {
1760 return 1; // France, Spain, Gabon, ... - Not valid for CH
1762 if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1763 return 2; // Australia, England...
1773 public function needIBAN()
1777 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1781 $country_code = $this->getCountryCode();
1783 $country_code_in_EEC = array(
1788 'CZ', // Czech republic
1795 'GB', // United Kingdom
1801 'IM', // Isle of Man - Included in UK
1806 'MC', // Monaco - Included in France
1815 'UK', // United Kingdom
1816 //'CH', // Switzerland - No. Swizerland in not in EEC
1819 if (in_array($country_code, $country_code_in_EEC)) {
1820 return 1; // France, Spain, ...
1831 public function info($id)
1849 public function getFieldsToShow($includeibanbic = 0)
1851 //Get the required properties depending on the country
1852 $detailedBBAN = $this->useDetailedBBAN();
1854 if ($detailedBBAN == 0) {
1855 $fieldarray = array(
1858 } elseif ($detailedBBAN == 2) {
1859 $fieldarray = array(
1864 $fieldarray = self::getAccountNumberOrder();
1867 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1868 if ($includeibanbic) {
1869 $fieldarray[] = 'IBAN';
1870 $fieldarray[] = 'BIC';
1874 //Get the order the properties are shown
1888 public static function getAccountNumberOrder()
1892 $fieldlists = array(
1895 'BankAccountNumber',
1896 'BankAccountNumberKey'
1899 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
1900 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
1901 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
1902 $fieldlists = array(
1905 'BankAccountNumberKey',
1910 //Replace the old AccountNumber key with the new BankAccountNumber key
1911 $fieldlists = explode(
1913 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1929 public function initAsSpecimen()
1931 // Example of IBAN FR7630001007941234567890185
1932 $this->specimen = 1;
1934 $this->label = 'My Big Company Bank account';
1935 $this->courant = Account::TYPE_CURRENT;
1936 $this->clos = Account::STATUS_OPEN;
1937 $this->type = Account::TYPE_CURRENT;
1938 $this->status = Account::STATUS_OPEN;
1939 $this->code_banque = '30001';
1940 $this->code_guichet = '00794';
1941 $this->number = '12345678901';
1942 $this->cle_rib = '85';
1943 $this->bic = 'AA12';
1944 $this->iban = 'FR7630001007941234567890185';
1946 $this->bank = 'MyBank';
1947 $this->address = 'Rue de Paris';
1948 $this->proprio = 'Owner';
1949 $this->owner_name = 'Owner';
1950 $this->owner_address = 'Owner address';
1951 $this->owner_zip = 'Owner zip';
1952 $this->owner_town = 'Owner town';
1953 $this->owner_country_id = 'Owner country_id';
1954 $this->country_id = 1;
1967 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
1969 $sql = "UPDATE
".MAIN_DB_PREFIX."bank_url SET url_id =
".((int) $dest_id)." WHERE url_id =
".((int) $origin_id)." AND
type=
'company'";
1971 if ($dbs->query($sql)) {
1974 //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.
1975 //$this->errors = $dbs->lasterror();
1987 public function getKanbanView($option = '', $arraydata = null)
1991 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1993 $return = '<div class="box-flex-item box-flex-grow-zero
">';
1994 $return .= '<div class="info-box
info-box-sm
">';
1995 $return .= '<span class="info-box-
icon bg-infobox-action
">';
1996 $return .= img_picto('', $this->picto);
1997 $return .= '</span>';
1998 $return .= '<div class="info-box-content
">';
1999 $return .= '<span class="info-box-
ref inline-block tdoverflowmax150 valignmiddle
">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2000 if ($selected >= 0) {
2001 $return .= '<input id="cb
'.$this->id.'" class="flat checkforselect fright
" type="checkbox
" name="toselect[]
" value="'.$this->id.'"'.($selected ? ' checked="checked
"' : '').'>';
2003 if (property_exists($this, 'type_lib')) {
2004 $return .= '<br><span class="info-box-label opacitymedium
" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2006 if (method_exists($this, 'solde')) {
2007 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?
id=
'.$this->id.'">';
2008 $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>';
2010 if (method_exists($this, 'getLibStatut')) {
2011 $return .= '<br><div class="info-box-
status">'.$this->getLibStatut(3).'</div>';
2013 $return .= '</div>';
2014 $return .= '</div>';
2015 $return .= '</div>';
2021require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2026class AccountLine extends CommonObjectLine
2036 public $element = 'bank';
2041 public $table_element = 'bank';
2046 public $picto = 'accountline';
2087 public $amount_main_currency;
2092 public $fk_user_author;
2097 public $fk_user_rappro;
2107 public $fk_bordereau;
2117 public $bank_account_ref;
2122 public $bank_account_label;
2127 public $numero_compte;
2168 public $user_rappro;
2176 public function __construct(DoliDB $db)
2189 public function fetch($rowid, $ref = '', $num = '')
2192 if (empty($rowid) && empty($ref) && empty($num)) {
2196 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,
";
2197 $sql .= " b.fk_user_author, b.fk_user_rappro,
";
2198 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,
";
2199 $sql .= " b.fk_bordereau, b.banque, b.emetteur,
";
2200 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label
";
2201 $sql .= " FROM
".MAIN_DB_PREFIX."bank as b,
";
2202 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba
";
2203 $sql .= " WHERE b.fk_account = ba.rowid
";
2204 $sql .= " AND ba.entity IN (
".getEntity('bank_account').")
";
2206 $sql .= " AND b.num_chq =
'".$this->db->escape($num)."'";
2208 $sql .= " AND b.rowid =
'".$this->db->escape($ref)."'";
2210 $sql .= " AND b.rowid =
".((int) $rowid);
2213 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2214 $result = $this->db->query($sql);
2218 $obj = $this->db->fetch_object($result);
2220 $this->id = $obj->rowid;
2221 $this->rowid = $obj->rowid;
2222 $this->ref = $obj->rowid;
2224 $this->datec = $this->db->jdate($obj->datec);
2225 $this->datev = $this->db->jdate($obj->datev);
2226 $this->dateo = $this->db->jdate($obj->dateo);
2227 $this->amount = $obj->amount;
2228 $this->label = $obj->label;
2229 $this->note = $obj->note;
2231 $this->fk_user_author = $obj->fk_user_author;
2232 $this->fk_user_rappro = $obj->fk_user_rappro;
2234 $this->fk_type = $obj->fk_type; // Type of transaction
2235 $this->rappro = (int) $obj->rappro;
2236 $this->num_releve = $obj->num_releve;
2238 $this->num_chq = $obj->num_chq;
2239 $this->bank_chq = $obj->banque;
2240 $this->fk_bordereau = $obj->fk_bordereau;
2242 $this->fk_account = $obj->fk_account;
2243 $this->bank_account_ref = $obj->bank_account_ref;
2244 $this->bank_account_label = $obj->bank_account_label;
2246 // Retrieve all extrafield
2247 // fetch optionals attributes and labels
2248 $this->fetch_optionals();
2252 $this->db->free($result);
2264 public function insert()
2270 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank (
";
2276 $sql .= ", amount_main_currency
";
2277 $sql .= ", fk_user_author
";
2278 $sql .= ", num_chq
";
2279 $sql .= ", fk_account
";
2280 $sql .= ", fk_type
";
2281 $sql .= ", emetteur,banque
";
2283 $sql .= ", numero_compte
";
2284 $sql .= ", num_releve
";
2285 $sql .= ") VALUES (
";
2286 $sql .= "'".$this->db->idate($this->datec)."'";
2287 $sql .= ",
'".$this->db->idate($this->dateo)."'";
2288 $sql .= ",
'".$this->db->idate($this->datev)."'";
2289 $sql .= ",
'".$this->db->escape($this->label)."'";
2290 $sql .= ",
".price2num($this->amount);
2291 $sql .= ",
".(empty($this->amount_main_currency) ? "NULL
" : price2num($this->amount_main_currency));
2292 $sql .= ",
".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2293 $sql .= ",
".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2294 $sql .= ",
'".$this->db->escape($this->fk_account)."'";
2295 $sql .= ",
'".$this->db->escape($this->fk_type)."'";
2296 $sql .= ",
".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2297 $sql .= ",
".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2298 $sql .= ",
".(int) $this->rappro;
2299 $sql .= ",
".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2300 $sql .= ",
".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2304 dol_syslog(get_class($this)."::insert
", LOG_DEBUG);
2305 $resql = $this->db->query($sql);
2307 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2308 // Actions on extra fields (by external module or standard code)
2309 $result = $this->insertExtraFields();
2315 $this->error = $this->db->lasterror();
2316 dol_print_error($this->db);
2320 $this->db->commit();
2323 $this->db->rollback();
2335 public function delete(User $user = null, $notrigger = 0)
2339 if ($this->rappro) {
2340 // Protection to avoid any delete of consolidated lines
2341 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2349 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2351 $this->db->rollback();
2354 // End call triggers
2357 // Protection to avoid any delete of accounted lines. Protection on by default
2358 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2359 $sql = "SELECT COUNT(
rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2360 $resql = $this->db->query($sql);
2362 $obj = $this->db->fetch_object($resql);
2363 if ($obj && $obj->nb) {
2364 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2365 $this->db->rollback();
2369 $this->error = $this->db->lasterror();
2370 $this->db->rollback();
2376 $result = $this->delete_urls($user);
2381 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_class WHERE lineid=
".(int) $this->rowid;
2382 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2383 $result = $this->db->query($sql);
2388 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=
".(int) $this->rowid;
2389 $result = $this->db->query($sql);
2394 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank WHERE
rowid=
".(int) $this->rowid;
2395 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2396 $result = $this->db->query($sql);
2402 $this->db->commit();
2405 $this->db->rollback();
2411 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2418 public function delete_urls(User $user = null)
2423 if ($this->rappro) {
2424 // Protection to avoid any delete of consolidated lines
2425 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated
";
2431 $sql = "DELETE FROM
".MAIN_DB_PREFIX."bank_url WHERE fk_bank=
".(int) $this->rowid;
2432 dol_syslog(get_class($this)."::delete_urls
", LOG_DEBUG);
2433 $result = $this->db->query($sql);
2439 $this->db->commit();
2442 $this->db->rollback();
2455 public function update(User $user, $notrigger = 0)
2459 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2460 $sql .= " amount =
".price2num($this->amount).",
";
2461 $sql .= " datev=
'".$this->db->idate($this->datev)."',
";
2462 $sql .= " dateo=
'".$this->db->idate($this->dateo)."'";
2463 $sql .= " WHERE
rowid =
".((int) $this->rowid);
2465 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2466 $resql = $this->db->query($sql);
2468 $this->db->commit();
2471 $this->db->rollback();
2472 $this->error = $this->db->error();
2483 public function updateLabel()
2487 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2488 $sql .= " label =
'".$this->db->escape($this->label)."'";
2489 $sql .= " WHERE
rowid =
".((int) $this->rowid);
2491 dol_syslog(get_class($this)."::update_label
", LOG_DEBUG);
2492 $resql = $this->db->query($sql);
2494 $this->db->commit();
2497 $this->db->rollback();
2498 $this->error = $this->db->error();
2504 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2513 public function update_conciliation(User $user, $cat, $conciliated = 1)
2516 global $conf, $langs;
2520 // Check statement field
2521 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2522 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2523 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex
", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2528 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2529 $sql .= " rappro =
".((int) $conciliated);
2530 $sql .= ", num_releve =
'".$this->db->escape($this->num_releve)."'";
2532 $sql .= ", fk_user_rappro =
".$user->id;
2534 $sql .= " WHERE
rowid =
".((int) $this->id);
2536 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2537 $resql = $this->db->query($sql);
2539 if (!empty($cat) && $cat > 0) {
2540 $sql = "INSERT INTO
".MAIN_DB_PREFIX."bank_class (
";
2542 $sql .= ", fk_categ
";
2543 $sql .= ") VALUES (
";
2545 $sql .= ",
".((int) $cat);
2548 dol_syslog(get_class($this)."::update_conciliation
", LOG_DEBUG);
2549 $this->db->query($sql);
2551 // No error check. Can fail if category already affected
2552 // TODO Do no try the insert if link already exists
2555 $this->rappro = (int) $conciliated;
2557 $this->db->commit();
2560 $this->db->rollback();
2566 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2574 public function datev_change($rowid, $sign = 1)
2577 $sql = "SELECT datev FROM
".MAIN_DB_PREFIX."bank WHERE
rowid =
".((int) $rowid);
2578 $resql = $this->db->query($sql);
2580 $obj = $this->db->fetch_object($resql);
2581 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2583 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2584 $sql .= " datev =
'".$this->db->idate($newdate)."'";
2585 $sql .= " WHERE
rowid =
".((int) $rowid);
2587 $result = $this->db->query($sql);
2589 if ($this->db->affected_rows($result)) {
2593 dol_print_error($this->db);
2597 dol_print_error($this->db);
2602 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2609 public function datev_next($id)
2612 return $this->datev_change($id, 1);
2615 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2622 public function datev_previous($id)
2625 return $this->datev_change($id, -1);
2629 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2637 public function dateo_change($rowid, $sign = 1)
2640 $sql = "SELECT dateo FROM
".MAIN_DB_PREFIX."bank WHERE
rowid =
".((int) $rowid);
2641 $resql = $this->db->query($sql);
2643 $obj = $this->db->fetch_object($resql);
2644 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2646 $sql = "UPDATE
".MAIN_DB_PREFIX."bank SET
";
2647 $sql .= " dateo =
'".$this->db->idate($newdate)."'";
2648 $sql .= " WHERE
rowid =
".((int) $rowid);
2650 $result = $this->db->query($sql);
2652 if ($this->db->affected_rows($result)) {
2656 dol_print_error($this->db);
2660 dol_print_error($this->db);
2665 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2672 public function dateo_next($id)
2675 return $this->dateo_change($id, 1);
2678 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2685 public function dateo_previous($id)
2688 return $this->dateo_change($id, -1);
2698 public function info($id)
2700 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2701 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2702 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2703 $sql .= ' WHERE b.rowid = '.((int) $id);
2705 $result = $this->db->query($sql);
2707 if ($this->db->num_rows($result)) {
2708 $obj = $this->db->fetch_object($result);
2710 $this->id = $obj->rowid;
2712 $this->user_creation_id = $obj->fk_user_author;
2713 $this->user_rappro = $obj->fk_user_rappro;
2714 $this->date_creation = $this->db->jdate($obj->datec);
2715 $this->date_modification = $this->db->jdate($obj->datem);
2716 //$this->date_rappro = $obj->daterappro; // Not yet managed
2718 $this->db->free($result);
2720 dol_print_error($this->db);
2734 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2736 global $conf, $langs;
2740 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine
").'</u>:<br>';
2741 $label .= '<b>'.$langs->trans("Ref
").':</b> '.$this->ref;
2742 if ($this->amount) {
2743 $label .= '<br><strong>'.$langs->trans("Amount
").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2746 $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
">';
2749 $result .= $linkstart;
2751 $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);
2753 if ($withpicto != 2) {
2754 $result .= ($this->ref ? $this->ref : $this->id);
2757 $result .= $linkend;
2759 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2760 $result .= ' <span class="opacitymedium
">(';
2762 if ($option == 'showall') {
2763 $result .= $langs->trans("BankAccount
").': ';
2764 $accountstatic = new Account($this->db);
2765 $accountstatic->id = $this->fk_account;
2766 $accountstatic->ref = $this->bank_account_ref;
2767 $accountstatic->label = $this->bank_account_label;
2768 $result .= $accountstatic->getNomUrl(0).', ';
2770 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2771 $result .= $langs->trans("BankLineConciliated
").': ';
2772 $result .= yn($this->rappro);
2774 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2775 $sql = "SELECT COUNT(
rowid) as nb FROM
".MAIN_DB_PREFIX."accounting_bookkeeping
";
2776 $sql .= " WHERE doc_type =
'bank' AND fk_doc =
".((int) $this->id);
2777 $resql = $this->db->query($sql);
2779 $obj = $this->db->fetch_object($resql);
2780 if ($obj && $obj->nb) {
2781 $result .= ' - '.$langs->trans("Accounted
").': '.yn(1);
2783 $result .= ' - '.$langs->trans("Accounted
").': '.yn(0);
2787 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2788 $result .= ')</span>';
2801 public function getLibStatut($mode = 0)
2803 return $this->LibStatut($this->status, $mode);
2806 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2814 public function LibStatut($status, $mode = 0)
2825 public function getVentilExportCompta()
2827 $alreadydispatched = 0;
2831 $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);
2832 $resql = $this->db->query($sql);
2834 $obj = $this->db->fetch_object($resql);
2836 $alreadydispatched = $obj->nb;
2839 $this->
error = $this->db->lasterror();
2843 if ($alreadydispatched) {
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
checkSwiftForAccount(Account $account=null, $swift=null)
Check SWIFT information for a bank account.
checkIbanForAccount(Account $account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
getIbanHumanReadable(Account $account)
Returns the iban human readable.
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current balance.
fetch($id, $ref='')
Load a bank account into memory from database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $mode='', $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clicable name (with picto eventually)
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
loadStateBoard($filteraccountid=0)
Load the indicators this->nb for the state board.
update(User $user, $notrigger=0)
Update bank account card.
getCountryCode()
Return account country code.
getLibStatut($mode=0)
Return label of object status.
delete(User $user=null, $notrigger=0)
Delete bank account from database.
getBannerAddress($htmlkey, $object)
Return full address for banner.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
__toString()
Shows the account number in the appropriate format.
const TYPE_SAVINGS
Savings account.
getTooltipContentArray($params)
getTooltipContentArray
canBeConciliated()
Return if a bank account need to be conciliated.
create(User $user, $notrigger=0)
Create bank account into database.
can_be_deleted()
Indicates if an account can be deleted or not (without movements)
update_bban(User $user=null)
Update BBAN (RIB) account fields.
const TYPE_CURRENT
Current account.
setCategories($categories)
Sets object to supplied categories.
countAccountToReconcile()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
verif()
Return if an account has valid information for Direct debit payment.
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
get_url($fk_bank=0, $url_id=0, $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null)
Add an entry into table ".MAIN_DB_PREFIX."bank.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
setErrorsFromObject($object)
setErrorsFromObject
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
table table fiche title col title div col center btnTitle icon
Automatically calls the icon named with the corresponding "object_" prefix.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid