34 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
45 public $element =
'bank_account';
50 public $table_element =
'bank_account';
55 public $picto =
'account';
92 public $clos = self::STATUS_OPEN;
116 public $code_guichet;
154 public $pti_in_ctti = 0;
166 public $owner_address;
169 public $owner_country_id;
170 public $owner_country_code;
176 public $domiciliation;
187 public $type_lib = array();
194 public $status = array();
200 public $account_number;
205 public $fk_accountancy_journal;
209 public $accountancy_journal;
215 public $currency_code;
222 public $account_currency_code;
272 public $ics_transfer;
304 public $fields = array(
305 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
306 'ref' =>array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>25),
307 'label' =>array(
'type'=>
'varchar(30)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
308 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>35,
'index'=>1),
309 'bank' =>array(
'type'=>
'varchar(60)',
'label'=>
'Bank',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
310 'code_banque' =>array(
'type'=>
'varchar(128)',
'label'=>
'Code banque',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
311 'code_guichet' =>array(
'type'=>
'varchar(6)',
'label'=>
'Code guichet',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
312 'number' =>array(
'type'=>
'varchar(255)',
'label'=>
'Number',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
313 'cle_rib' =>array(
'type'=>
'varchar(5)',
'label'=>
'Cle rib',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
314 'bic' =>array(
'type'=>
'varchar(11)',
'label'=>
'Bic',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
315 'iban_prefix' =>array(
'type'=>
'varchar(34)',
'label'=>
'Iban prefix',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
316 'country_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Country iban',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
317 'cle_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Cle iban',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
318 'domiciliation' =>array(
'type'=>
'varchar(255)',
'label'=>
'Domiciliation',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
319 'state_id' =>array(
'type'=>
'integer',
'label'=>
'StateId',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
320 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>95),
321 'proprio' =>array(
'type'=>
'varchar(60)',
'label'=>
'Proprio',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
322 'owner_address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Owner address',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
323 'owner_zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Owner zip',
'enabled'=>1,
'visible'=>-1,
'position'=>106),
324 'owner_town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Owner town',
'enabled'=>1,
'visible'=>-1,
'position'=>107),
325 'owner_country_id' =>array(
'type'=>
'integer',
'label'=>
'Owner country',
'enabled'=>1,
'visible'=>-1,
'position'=>108),
326 'courant' =>array(
'type'=>
'smallint(6)',
'label'=>
'Courant',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>110),
327 'clos' =>array(
'type'=>
'smallint(6)',
'label'=>
'Clos',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>115),
328 'rappro' =>array(
'type'=>
'smallint(6)',
'label'=>
'Rappro',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
329 'url' =>array(
'type'=>
'varchar(128)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
330 'account_number' =>array(
'type'=>
'varchar(32)',
'label'=>
'Account number',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
331 'fk_accountancy_journal' =>array(
'type'=>
'integer',
'label'=>
'Accountancy journal ID',
'enabled'=>1,
'visible'=>-1,
'position'=>132),
332 'accountancy_journal' =>array(
'type'=>
'varchar(20)',
'label'=>
'Accountancy journal',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
333 'currency_code' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>140),
334 'min_allowed' =>array(
'type'=>
'integer',
'label'=>
'Min allowed',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
335 'min_desired' =>array(
'type'=>
'integer',
'label'=>
'Min desired',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
336 'comment' =>array(
'type'=>
'text',
'label'=>
'Comment',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
337 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>156),
338 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>157),
339 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
340 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>165),
341 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>170),
342 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>175),
343 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>180),
344 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
362 const STATUS_OPEN = 0;
363 const STATUS_CLOSED = 1;
379 $this->type_lib = array(
380 self::TYPE_SAVINGS => $langs->trans(
"BankType0"),
381 self::TYPE_CURRENT => $langs->trans(
"BankType1"),
382 self::TYPE_CASH => $langs->trans(
"BankType2"),
385 $this->status = array(
386 self::STATUS_OPEN => $langs->trans(
"StatusAccountOpened"),
387 self::STATUS_CLOSED => $langs->trans(
"StatusAccountClosed")
400 if ($val ==
'BankCode') {
401 $string .= $this->code_banque.
' ';
402 } elseif ($val ==
'BankAccountNumber') {
403 $string .= $this->number.
' ';
404 } elseif ($val ==
'DeskCode') {
405 $string .= $this->code_guichet.
' ';
406 } elseif ($val ==
'BankAccountNumberKey') {
407 $string .= $this->cle_rib.
' ';
408 } elseif ($val ==
'BIC') {
409 $string .= $this->bic.
' ';
410 } elseif ($val ==
'IBAN') {
411 $string .= $this->iban.
' ';
415 return trim($string);
428 if (empty($this->rappro)) {
431 if ($this->courant ==
Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
455 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
461 $sql .=
") VALUES (";
462 $sql .=
" ".((int) $line_id);
463 $sql .=
", ".((int) $url_id);
464 $sql .=
", '".$this->db->escape($url).
"'";
465 $sql .=
", '".$this->db->escape($label).
"'";
466 $sql .=
", '".$this->db->escape($type).
"'";
469 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
470 if ($this->db->query(
$sql)) {
471 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
474 $this->
error = $this->db->lasterror();
489 public function get_url($fk_bank =
'', $url_id =
'', $type =
'')
495 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
496 $this->
error =
"ErrorBadParameter";
500 $sql =
"SELECT fk_bank, url_id, url, label, type";
501 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
503 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
505 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->db->escape($type).
"'";
507 $sql .=
" ORDER BY type, label";
509 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
510 $result = $this->db->query(
$sql);
513 $num = $this->db->num_rows($result);
515 $obj = $this->db->fetch_object($result);
517 $lines[$i][0] = $obj->url;
518 $lines[$i][1] = $obj->url_id;
519 $lines[$i][2] = $obj->label;
520 $lines[$i][3] = $obj->type;
522 $lines[$i][
'url'] = $obj->url;
523 $lines[$i][
'url_id'] = $obj->url_id;
524 $lines[$i][
'label'] = $obj->label;
525 $lines[$i][
'type'] = $obj->type;
526 $lines[$i][
'fk_bank'] = $obj->fk_bank;
554 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
557 if (is_numeric($oper)) {
558 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
561 if (empty($this->
id) && !empty($this->
rowid)) {
562 $this->
id = $this->rowid;
566 $emetteur = trim($emetteur);
567 $banque = trim($banque);
568 $label = trim($label);
572 if (is_numeric($oper)) {
573 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
574 $sql .=
" WHERE id = ".((int) $oper);
575 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
576 $resql = $this->db->query(
$sql);
578 $obj = $this->db->fetch_object($resql);
588 $this->
error =
"oper not defined";
592 $this->
error =
"this->id not defined";
596 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
602 if (is_null($datev) || empty($datev)) {
607 $accline->datec = $now;
608 $accline->dateo = $date;
609 $accline->datev = $datev;
610 $accline->label = $label;
611 $accline->amount = $amount;
612 $accline->amount_main_currency = $amount_main_currency;
613 $accline->fk_user_author = $user->id;
614 $accline->fk_account = $this->id;
615 $accline->fk_type = $oper;
616 $accline->numero_compte = $accountancycode;
617 $accline->num_releve = $num_releve;
620 $accline->num_chq = $num_chq;
624 $accline->emetteur = $emetteur;
628 $accline->bank_chq = $banque;
631 if ($accline->insert() > 0) {
632 if ($categorie > 0) {
633 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
634 $sql .=
"lineid, fk_categ";
635 $sql .=
") VALUES (";
636 $sql .= ((int) $accline->id).
", '".$this->db->escape($categorie).
"'";
639 $result = $this->db->query(
$sql);
641 $this->
error = $this->db->lasterror();
642 $this->db->rollback();
652 $this->
error = $accline->error;
653 $this->errors = $accline->errors;
654 $this->db->rollback();
669 global $langs, $conf;
674 if (!$this->min_allowed) {
675 $this->min_allowed = 0;
677 if (!$this->min_desired) {
678 $this->min_desired = 0;
682 if (empty($this->country_id)) {
683 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
687 if (empty($this->
ref)) {
688 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
692 if (empty($this->date_solde)) {
693 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
699 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
705 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
710 $sql .=
", account_number";
711 $sql .=
", fk_accountancy_journal";
713 $sql .=
", code_banque";
714 $sql .=
", code_guichet";
718 $sql .=
", iban_prefix";
719 $sql .=
", domiciliation";
720 $sql .=
", pti_in_ctti";
722 $sql .=
", owner_address";
723 $sql .=
", owner_zip";
724 $sql .=
", owner_town";
725 $sql .=
", owner_country_id";
726 $sql .=
", currency_code";
728 $sql .=
", min_allowed";
729 $sql .=
", min_desired";
731 $sql .=
", state_id";
734 $sql .=
", ics_transfer";
735 $sql .=
") VALUES (";
736 $sql .=
"'".$this->db->idate($now).
"'";
737 $sql .=
", '".$this->db->escape($this->
ref).
"'";
738 $sql .=
", '".$this->db->escape($this->label).
"'";
739 $sql .=
", ".((int) $conf->entity);
740 $sql .=
", '".$this->db->escape($this->account_number).
"'";
741 $sql .=
", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
742 $sql .=
", '".$this->db->escape($this->bank).
"'";
743 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
744 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
745 $sql .=
", '".$this->db->escape($this->number).
"'";
746 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
747 $sql .=
", '".$this->db->escape($this->bic).
"'";
748 $sql .=
", '".$this->db->escape($this->iban).
"'";
749 $sql .=
", '".$this->db->escape($this->domiciliation).
"'";
750 $sql .=
", ".((int) $this->pti_in_ctti);
751 $sql .=
", '".$this->db->escape($this->proprio).
"'";
752 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
753 $sql .=
", '".$this->db->escape($this->owner_zip).
"'";
754 $sql .=
", '".$this->db->escape($this->owner_town).
"'";
755 $sql .=
", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
756 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
757 $sql .=
", ".((int) $this->rappro);
758 $sql .=
", ".price2num($this->min_allowed,
'MT');
759 $sql .=
", ".price2num($this->min_desired,
'MT');
760 $sql .=
", '".$this->db->escape($this->comment).
"'";
761 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
762 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
763 $sql .=
", '".$this->db->escape($this->ics).
"'";
764 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
767 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
768 $resql = $this->db->query(
$sql);
770 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
772 $result = $this->
update($user, 1);
775 $accline->datec = $this->db->idate($now);
776 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
778 $accline->fk_user_author = $user->id;
779 $accline->fk_account = $this->id;
780 $accline->datev = $this->db->idate($this->date_solde);
781 $accline->dateo = $this->db->idate($this->date_solde);
782 $accline->fk_type =
'SOLD';
784 if ($accline->insert() < 0) {
786 $this->
error = $accline->error;
787 $this->errors = $accline->errors;
797 if (!$error && !$notrigger) {
799 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
809 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
810 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
813 $this->
error = $this->db->error().
" sql=".
$sql;
822 $this->db->rollback();
836 global $langs, $conf;
843 if (empty($this->country_id)) {
844 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
848 if (empty($this->
ref)) {
849 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
854 $this->label =
"???";
857 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
859 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
860 $sql .=
",label = '".$this->db->escape($this->label).
"'";
862 $sql .=
",courant = ".((int) $this->courant);
863 $sql .=
",clos = ".((int) $this->clos);
864 $sql .=
",rappro = ".((int) $this->rappro);
865 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
866 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
867 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) :
"null");
868 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
869 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
870 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
871 $sql .=
",number='".$this->db->escape($this->number).
"'";
872 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
873 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
874 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
875 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
876 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
877 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
878 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
879 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
880 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
881 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
883 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
885 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
886 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
887 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
889 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
890 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
891 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
892 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
894 $sql .=
" WHERE rowid = ".((int) $this->
id);
896 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
897 $result = $this->db->query(
$sql);
907 if (!$error && !$notrigger) {
909 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
917 $this->
error = $this->db->lasterror();
925 $this->db->rollback();
941 global $conf, $langs;
944 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
946 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
950 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
954 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
955 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
956 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
957 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
958 $sql .=
",number='".$this->db->escape($this->number).
"'";
959 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
960 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
961 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
962 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
963 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
964 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
965 $sql .=
",owner_zip = '".$this->db->escape($this->owner_zip).
"'";
966 $sql .=
",owner_town = '".$this->db->escape($this->owner_town).
"'";
967 $sql .=
",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) :
"null");
968 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
969 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
970 $sql .=
" WHERE rowid = ".((int) $this->
id);
971 $sql .=
" AND entity = ".((int) $conf->entity);
973 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
975 $result = $this->db->query(
$sql);
979 $this->
error = $this->db->lasterror();
993 public function fetch($id, $ref =
'')
995 if (empty($id) && empty($ref)) {
996 $this->
error =
"ErrorBadParameters";
1000 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
1001 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1002 $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,";
1003 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1004 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
1005 $sql .=
" ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1006 $sql .=
' c.code as country_code, c.label as country,';
1007 $sql .=
' d.code_departement as state_code, d.nom as state,';
1008 $sql .=
' aj.code as accountancy_journal';
1009 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1010 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
1011 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
1012 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
1013 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
1015 $sql .=
" AND ba.rowid = ".((int) $id);
1018 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
1021 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1022 $result = $this->db->query(
$sql);
1024 if ($this->db->num_rows($result)) {
1025 $obj = $this->db->fetch_object($result);
1027 $this->
id = $obj->rowid;
1028 $this->
rowid = $obj->rowid;
1029 $this->
ref = $obj->ref;
1030 $this->label = $obj->label;
1031 $this->
type = $obj->courant;
1032 $this->courant = $obj->courant;
1033 $this->bank = $obj->bank;
1034 $this->clos = $obj->clos;
1035 $this->rappro = $obj->rappro;
1036 $this->url = $obj->url;
1038 $this->code_banque = $obj->code_banque;
1039 $this->code_guichet = $obj->code_guichet;
1040 $this->number = $obj->number;
1041 $this->cle_rib = $obj->cle_rib;
1042 $this->bic = $obj->bic;
1043 $this->iban = $obj->iban;
1044 $this->domiciliation = $obj->address;
1045 $this->address = $obj->address;
1046 $this->pti_in_ctti = $obj->pti_in_ctti;
1047 $this->proprio = $obj->proprio;
1048 $this->owner_address = $obj->owner_address;
1049 $this->owner_zip = $obj->owner_zip;
1050 $this->owner_town = $obj->owner_town;
1051 $this->owner_country_id = $obj->owner_country_id;
1053 $this->state_id = $obj->state_id;
1054 $this->state_code = $obj->state_code;
1055 $this->state = $obj->state;
1057 $this->country_id = $obj->country_id;
1058 $this->country_code = $obj->country_code;
1059 $this->country = $obj->country;
1061 $this->account_number = $obj->account_number;
1062 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1063 $this->accountancy_journal = $obj->accountancy_journal;
1065 $this->currency_code = $obj->currency_code;
1066 $this->account_currency_code = $obj->currency_code;
1067 $this->min_allowed = $obj->min_allowed;
1068 $this->min_desired = $obj->min_desired;
1069 $this->comment = $obj->comment;
1071 $this->date_creation = $this->db->jdate($obj->date_creation);
1072 $this->date_modification = $this->db->jdate($obj->date_modification);
1075 $this->ics = $obj->ics;
1076 $this->ics_transfer = $obj->ics_transfer;
1087 $this->
error = $this->db->lasterror();
1088 $this->errors[] = $this->error;
1105 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1106 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1115 public function delete(
User $user =
null)
1125 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1126 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1128 $resql = $this->db->query(
$sql);
1131 $this->
error =
"Error ".$this->db->lasterror();
1136 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1137 $sql .=
" WHERE rowid = ".((int) $this->
id);
1139 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1140 $result = $this->db->query(
$sql);
1147 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1152 $this->
error =
"Error ".$this->db->lasterror();
1157 $this->db->commit();
1160 $this->db->rollback();
1174 return $this->
LibStatut($this->clos, $mode);
1189 $langs->load(
'banks');
1191 if ($status == self::STATUS_OPEN) {
1192 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1193 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1194 $statusType =
'status4';
1196 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1197 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1198 $statusType =
'status5';
1201 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1214 $can_be_deleted =
false;
1216 $sql =
"SELECT COUNT(rowid) as nb";
1217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1218 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1220 $resql = $this->db->query(
$sql);
1222 $obj = $this->db->fetch_object($resql);
1223 if ($obj->nb <= 1) {
1224 $can_be_deleted =
true;
1229 return $can_be_deleted;
1240 return $this->error;
1251 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1255 $sql =
"SELECT sum(amount) as amount";
1256 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1257 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1259 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(
dol_now())).
"'";
1262 $resql = $this->db->query(
$sql);
1264 if ($this->db->num_rows($resql)) {
1265 $obj = $this->db->fetch_object($resql);
1266 $solde = $obj->amount;
1268 $this->db->free($resql);
1270 $this->errors[] = $this->db->lasterror;
1288 global $conf, $langs;
1294 $sql =
"SELECT b.rowid, b.datev as datefin";
1295 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1296 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1297 $sql .=
" WHERE b.rappro=0";
1298 $sql .=
" AND b.fk_account = ba.rowid";
1299 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1300 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1301 $sql .=
" AND clos = 0";
1302 if ($filteraccountid) {
1303 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1306 $resql = $this->db->query(
$sql);
1308 $langs->load(
"banks");
1311 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1314 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1315 $response->label = $langs->trans(
"TransactionsToConciliate");
1316 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1317 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1320 while ($obj = $this->db->fetch_object($resql)) {
1321 $response->nbtodo++;
1322 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1323 $response->nbtodolate++;
1330 $this->
error = $this->db->error();
1351 $sql =
"SELECT count(b.rowid) as nb";
1352 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1353 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1354 $sql .=
" WHERE b.fk_account = ba.rowid";
1355 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1356 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1357 $sql .=
" AND clos = 0";
1358 if ($filteraccountid) {
1359 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1362 $resql = $this->db->query(
$sql);
1364 while ($obj = $this->db->fetch_object($resql)) {
1365 $this->nb[
"banklines"] = $obj->nb;
1367 $this->db->free($resql);
1371 $this->
error = $this->db->error();
1384 global $db, $conf, $user;
1393 $sql =
"SELECT COUNT(ba.rowid) as nb";
1394 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1395 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1396 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1397 if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
1398 $sql .=
" AND ba.courant != 2";
1400 $resql = $this->db->query(
$sql);
1402 $obj = $this->db->fetch_object($resql);
1421 $langs->loadLangs([
'banks',
'compta']);
1422 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1426 $nofetch = !empty($params[
'nofetch']);
1427 $pictos =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1428 if (isset($this->status)) {
1429 $pictos .=
' '.$this->getLibStatut(5);
1431 $datas[
'picto'] = $pictos;
1432 $datas[
'label'] =
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1433 $datas[
'accountnumber'] =
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1435 $datas[
'bic'] =
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1436 $datas[
'accountcurrency'] =
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1439 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1440 $langs->load(
"accountancy");
1441 $datas[
'accountaccounting'] =
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1442 $datas[
'accountancyjournal'] =
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1446 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1448 $datas[
'categories'] =
'<br>' .
$form->showCategories($this->
id, Categorie::TYPE_ACCOUNT, 1);
1464 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0)
1466 global $conf, $langs, $user;
1468 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1471 $classfortooltip =
'classfortooltip';
1475 'objecttype' => $this->element,
1476 'option' => $option,
1480 $classfortooltip =
'classforajaxtooltip';
1481 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1488 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1489 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'">';
1491 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1492 if ($mode ==
'transactions') {
1493 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1494 } elseif ($mode ==
'receipts') {
1495 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1498 if ($option !=
'nolink') {
1500 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1501 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1502 $add_save_lastsearch_values = 1;
1504 if ($add_save_lastsearch_values) {
1505 $url .=
'&save_lastsearch_values=1';
1509 $linkstart =
'<a href="'.$url.
'"'.$linkclose;
1512 if ($option ==
'nolink') {
1517 $result .= $linkstart;
1519 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
1521 if ($withpicto != 2) {
1522 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1524 $result .= $linkend;
1540 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1547 $this->error_message =
'IBANNotValid';
1551 $this->error_message =
'SwiftNotValid';
1571 if (!empty($this->country_code)) {
1572 return $this->country_code;
1576 if (!empty($this->iban)) {
1579 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1585 if (!empty($this->socid)) {
1586 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1587 $company =
new Societe($this->db);
1588 $result = $company->fetch($this->socid);
1589 if (!empty($company->country_code)) {
1590 return $company->country_code;
1595 if (!empty($mysoc->country_code)) {
1596 return $mysoc->country_code;
1614 if (in_array($country_code, array(
'FR',
'ES',
'GA',
'IT',
'NC'))) {
1617 if (in_array($country_code, array(
'AD',
'AU',
'BE',
'CA',
'DE',
'DK',
'GR',
'GB',
'ID',
'IE',
'IR',
'KR',
'NL',
'NZ',
'UK',
'US'))) {
1632 if (!empty($conf->global->MAIN_IBAN_IS_NEVER_MANDATORY)) {
1638 $country_code_in_EEC = array(
1674 if (in_array($country_code, $country_code_in_EEC)) {
1709 if ($detailedBBAN == 0) {
1710 $fieldarray = array(
1713 } elseif ($detailedBBAN == 2) {
1714 $fieldarray = array(
1723 if ($includeibanbic) {
1724 $fieldarray[] =
'IBAN';
1725 $fieldarray[] =
'BIC';
1747 $fieldlists = array(
1750 'BankAccountNumber',
1751 'BankAccountNumberKey'
1754 if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {
1755 if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1756 if ($conf->global->BANK_SHOW_ORDER_OPTION ==
'1') {
1757 $fieldlists = array(
1760 'BankAccountNumberKey',
1766 $fieldlists = explode(
1768 preg_replace(
'/ ?[^Bank]AccountNumber ?/',
'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1787 $this->specimen = 1;
1789 $this->label =
'My Big Company Bank account';
1790 $this->bank =
'MyBank';
1792 $this->clos = Account::STATUS_OPEN;
1793 $this->code_banque =
'30001';
1794 $this->code_guichet =
'00794';
1795 $this->number =
'12345678901';
1796 $this->cle_rib =
'85';
1797 $this->bic =
'AA12';
1798 $this->iban =
'FR7630001007941234567890185';
1799 $this->domiciliation =
'Banque de France';
1800 $this->proprio =
'Owner';
1801 $this->owner_address =
'Owner address';
1802 $this->owner_zip =
'Owner zip';
1803 $this->owner_town =
'Owner town';
1804 $this->owner_country_id =
'Owner country_id';
1805 $this->country_id = 1;
1818 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_url SET url_id = ".((int) $dest_id).
" WHERE url_id = ".((int) $origin_id).
" AND type='company'";
1820 if ($dbs->query(
$sql)) {
1840 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1842 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1843 $return .=
'<div class="info-box info-box-sm">';
1844 $return .=
'<span class="info-box-icon bg-infobox-action">';
1846 $return .=
'</span>';
1847 $return .=
'<div class="info-box-content">';
1848 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1849 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1851 if (property_exists($this,
'type_lib')) {
1852 $return .=
'<br><span class="info-box-label opacitymedium" title="'.$this->type_lib[$this->type].
'">'.substr($this->type_lib[$this->
type], 0, 24).
'...</span>';
1854 if (method_exists($this,
'solde')) {
1855 $return .=
'<br><a href="'.DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->
id.
'">';
1856 $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>';
1858 if (method_exists($this,
'getLibStatut')) {
1859 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1861 $return .=
'</div>';
1862 $return .=
'</div>';
1863 $return .=
'</div>';
1869 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
1889 public $element =
'bank';
1894 public $table_element =
'bank';
1899 public $picto =
'accountline';
1933 public $amount_main_currency;
1938 public $fk_user_author;
1943 public $fk_user_rappro;
1953 public $fk_bordereau;
1963 public $bank_account_ref;
1968 public $bank_account_label;
1973 public $numero_compte;
2012 public function fetch($rowid, $ref =
'', $num =
'')
2017 if (empty($rowid) && empty($ref) && empty($num)) {
2021 $sql =
"SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
2022 $sql .=
" b.fk_user_author, b.fk_user_rappro,";
2023 $sql .=
" b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
2024 $sql .=
" b.fk_bordereau, b.banque, b.emetteur,";
2025 $sql .=
" ba.ref as bank_account_ref, ba.label as bank_account_label";
2026 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
2027 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
2028 $sql .=
" WHERE b.fk_account = ba.rowid";
2029 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
2031 $sql .=
" AND b.num_chq='".$this->db->escape($num).
"'";
2033 $sql .=
" AND b.rowid='".$this->db->escape($ref).
"'";
2035 $sql .=
" AND b.rowid = ".((int) $rowid);
2038 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
2039 $result = $this->db->query(
$sql);
2043 $obj = $this->db->fetch_object($result);
2045 $this->
id = $obj->rowid;
2046 $this->
rowid = $obj->rowid;
2047 $this->
ref = $obj->rowid;
2049 $this->datec = $obj->datec;
2050 $this->datev = $obj->datev;
2051 $this->dateo = $obj->dateo;
2052 $this->amount = $obj->amount;
2053 $this->label = $obj->label;
2054 $this->note = $obj->note;
2056 $this->fk_user_author = $obj->fk_user_author;
2057 $this->fk_user_rappro = $obj->fk_user_rappro;
2059 $this->fk_type = $obj->fk_type;
2060 $this->rappro = $obj->rappro;
2061 $this->num_releve = $obj->num_releve;
2063 $this->num_chq = $obj->num_chq;
2064 $this->bank_chq = $obj->banque;
2065 $this->fk_bordereau = $obj->fk_bordereau;
2067 $this->fk_account = $obj->fk_account;
2068 $this->bank_account_ref = $obj->bank_account_ref;
2069 $this->bank_account_label = $obj->bank_account_label;
2077 $this->db->free($result);
2095 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank (";
2101 $sql .=
", amount_main_currency";
2102 $sql .=
", fk_user_author";
2103 $sql .=
", num_chq";
2104 $sql .=
", fk_account";
2105 $sql .=
", fk_type";
2106 $sql .=
", emetteur,banque";
2108 $sql .=
", numero_compte";
2109 $sql .=
", num_releve";
2110 $sql .=
") VALUES (";
2111 $sql .=
"'".$this->db->idate($this->datec).
"'";
2112 $sql .=
", '".$this->db->idate($this->dateo).
"'";
2113 $sql .=
", '".$this->db->idate($this->datev).
"'";
2114 $sql .=
", '".$this->db->escape($this->label).
"'";
2115 $sql .=
", ".price2num($this->amount);
2116 $sql .=
", ".(empty($this->amount_main_currency) ?
"NULL" :
price2num($this->amount_main_currency));
2117 $sql .=
", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) :
"null");
2118 $sql .=
", ".($this->num_chq ?
"'".$this->db->escape($this->num_chq).
"'" :
"null");
2119 $sql .=
", '".$this->db->escape($this->fk_account).
"'";
2120 $sql .=
", '".$this->db->escape($this->fk_type).
"'";
2121 $sql .=
", ".($this->emetteur ?
"'".$this->db->escape($this->emetteur).
"'" :
"null");
2122 $sql .=
", ".($this->bank_chq ?
"'".$this->db->escape($this->bank_chq).
"'" :
"null");
2123 $sql .=
", ".(int) $this->rappro;
2124 $sql .=
", ".($this->numero_compte ?
"'".$this->db->escape($this->numero_compte).
"'" :
"''");
2125 $sql .=
", ".($this->num_releve ?
"'".$this->db->escape($this->num_releve).
"'" :
"null");
2128 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2129 $resql = $this->db->query(
$sql);
2131 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'bank');
2139 $this->error = $this->db->lasterror();
2144 $this->db->commit();
2147 $this->db->rollback();
2158 public function delete(
User $user =
null)
2164 if ($this->rappro) {
2166 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2173 if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING)) {
2174 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2175 $resql = $this->db->query(
$sql);
2177 $obj = $this->db->fetch_object($resql);
2178 if ($obj && $obj->nb) {
2179 $this->error =
'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2180 $this->db->rollback();
2184 $this->error = $this->db->lasterror();
2185 $this->db->rollback();
2196 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class WHERE lineid=".(int) $this->
rowid;
2197 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2198 $result = $this->db->query(
$sql);
2203 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_extrafields WHERE fk_object=".(int) $this->
rowid;
2204 $result = $this->db->query(
$sql);
2209 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid=".(int) $this->
rowid;
2210 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2211 $result = $this->db->query(
$sql);
2217 $this->db->commit();
2220 $this->db->rollback();
2238 if ($this->rappro) {
2240 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2246 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url WHERE fk_bank=".(int) $this->
rowid;
2247 dol_syslog(get_class($this).
"::delete_urls", LOG_DEBUG);
2248 $result = $this->db->query(
$sql);
2254 $this->db->commit();
2257 $this->db->rollback();
2274 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2275 $sql .=
" amount = ".price2num($this->amount).
",";
2276 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
2277 $sql .=
" dateo='".$this->db->idate($this->dateo).
"'";
2278 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
2280 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2281 $resql = $this->db->query(
$sql);
2283 $this->db->commit();
2286 $this->db->rollback();
2287 $this->error = $this->db->error();
2305 global $conf, $langs;
2310 if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE)) {
2311 if (!preg_match(
'/'.$conf->global->BANK_STATEMENT_REGEX_RULE.
'/', $this->num_releve)) {
2312 $this->errors[] = $langs->trans(
"ErrorBankStatementNameMustFollowRegex", $conf->global->BANK_STATEMENT_REGEX_RULE);
2317 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2318 $sql .=
" rappro = ".((int) $conciliated);
2319 $sql .=
", num_releve = '".$this->db->escape($this->num_releve).
"'";
2321 $sql .=
", fk_user_rappro = ".$user->id;
2323 $sql .=
" WHERE rowid = ".((int) $this->
id);
2325 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2326 $resql = $this->db->query(
$sql);
2329 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class (";
2331 $sql .=
", fk_categ";
2332 $sql .=
") VALUES (";
2334 $sql .=
", ".((int) $cat);
2337 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2338 $this->db->query(
$sql);
2345 $this->db->commit();
2348 $this->db->rollback();
2365 $sql =
"SELECT datev FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2366 $resql = $this->db->query(
$sql);
2368 $obj = $this->db->fetch_object($resql);
2369 $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2371 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2372 $sql .=
" datev = '".$this->db->idate($newdate).
"'";
2373 $sql .=
" WHERE rowid = ".((int) $rowid);
2375 $result = $this->db->query(
$sql);
2377 if ($this->db->affected_rows($result)) {
2428 $sql =
"SELECT dateo FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2429 $resql = $this->db->query(
$sql);
2431 $obj = $this->db->fetch_object($resql);
2432 $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2434 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2435 $sql .=
" dateo = '".$this->db->idate($newdate).
"'";
2436 $sql .=
" WHERE rowid = ".((int) $rowid);
2438 $result = $this->db->query(
$sql);
2440 if ($this->db->affected_rows($result)) {
2488 $sql =
'SELECT b.rowid, b.datec, b.tms as datem,';
2489 $sql .=
' b.fk_user_author, b.fk_user_rappro';
2490 $sql .=
' FROM '.MAIN_DB_PREFIX.
'bank as b';
2491 $sql .=
' WHERE b.rowid = '.((int) $id);
2493 $result = $this->db->query(
$sql);
2495 if ($this->db->num_rows($result)) {
2496 $obj = $this->db->fetch_object($result);
2497 $this->
id = $obj->rowid;
2499 if ($obj->fk_user_author) {
2500 $cuser =
new User($this->db);
2501 $cuser->fetch($obj->fk_user_author);
2502 $this->user_creation = $cuser;
2504 if ($obj->fk_user_rappro) {
2505 $ruser =
new User($this->db);
2506 $ruser->fetch($obj->fk_user_rappro);
2507 $this->user_rappro = $ruser;
2510 $this->date_creation = $this->db->jdate($obj->datec);
2511 $this->date_modification = $this->db->jdate($obj->datem);
2514 $this->db->free($result);
2530 public function getNomUrl($withpicto = 0, $maxlen = 0, $option =
'', $notooltip = 0)
2536 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"BankTransactionLine").
'</u>:<br>';
2537 $label .=
'<b>'.$langs->trans(
"Ref").
':</b> '.$this->ref;
2539 $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">';
2542 $result .= $linkstart;
2544 $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);
2546 if ($withpicto != 2) {
2547 $result .= ($this->
ref ? $this->
ref : $this->id);
2549 $result .= $linkend;
2551 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2552 $result .=
' <span class="opacitymedium">(';
2554 if ($option ==
'showall') {
2555 $result .= $langs->trans(
"BankAccount").
': ';
2556 $accountstatic =
new Account($this->db);
2557 $accountstatic->id = $this->fk_account;
2558 $accountstatic->ref = $this->bank_account_ref;
2559 $accountstatic->label = $this->bank_account_label;
2560 $result .= $accountstatic->getNomUrl(0).
', ';
2562 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2563 $result .= $langs->trans(
"BankLineConciliated").
': ';
2564 $result .=
yn($this->rappro);
2566 if (
isModEnabled(
'accounting') && ($option ==
'showall' || $option ==
'showconciliatedandaccounted')) {
2567 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping";
2568 $sql .=
" WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2569 $resql = $this->db->query(
$sql);
2571 $obj = $this->db->fetch_object($resql);
2572 if ($obj && $obj->nb) {
2573 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(1);
2575 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(0);
2579 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2580 $result .=
')</span>';
2595 return $this->
LibStatut($this->status, $mode);
2655 $alreadydispatched = 0;
2659 $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);
2660 $resql = $this->db->query(
$sql);
2662 $obj = $this->db->fetch_object($resql);
2664 $alreadydispatched = $obj->nb;
2667 $this->error = $this->db->lasterror();
2671 if ($alreadydispatched) {