32 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'bank_account';
48 public $table_element =
'bank_account';
53 public $picto =
'account';
90 public $clos = self::STATUS_OPEN;
114 public $code_guichet;
152 public $domiciliation;
158 public $pti_in_ctti = 0;
170 public $owner_address;
181 public $type_lib = array();
188 public $status = array();
194 public $account_number;
199 public $fk_accountancy_journal;
203 public $accountancy_journal;
209 public $currency_code;
216 public $account_currency_code;
252 public $ics_transfer;
284 public $fields = array(
285 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
286 'ref' =>array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>25),
287 'label' =>array(
'type'=>
'varchar(30)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
288 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>35,
'index'=>1),
289 'bank' =>array(
'type'=>
'varchar(60)',
'label'=>
'Bank',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
290 'code_banque' =>array(
'type'=>
'varchar(128)',
'label'=>
'Code banque',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
291 'code_guichet' =>array(
'type'=>
'varchar(6)',
'label'=>
'Code guichet',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
292 'number' =>array(
'type'=>
'varchar(255)',
'label'=>
'Number',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
293 'cle_rib' =>array(
'type'=>
'varchar(5)',
'label'=>
'Cle rib',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
294 'bic' =>array(
'type'=>
'varchar(11)',
'label'=>
'Bic',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
295 'iban_prefix' =>array(
'type'=>
'varchar(34)',
'label'=>
'Iban prefix',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
296 'country_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Country iban',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
297 'cle_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Cle iban',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
298 'domiciliation' =>array(
'type'=>
'varchar(255)',
'label'=>
'Domiciliation',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
299 'state_id' =>array(
'type'=>
'integer',
'label'=>
'State id',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
300 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Fk pays',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>95),
301 'proprio' =>array(
'type'=>
'varchar(60)',
'label'=>
'Proprio',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
302 'owner_address' =>array(
'type'=>
'text',
'label'=>
'Owner address',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
303 'courant' =>array(
'type'=>
'smallint(6)',
'label'=>
'Courant',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>110),
304 'clos' =>array(
'type'=>
'smallint(6)',
'label'=>
'Clos',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>115),
305 'rappro' =>array(
'type'=>
'smallint(6)',
'label'=>
'Rappro',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
306 'url' =>array(
'type'=>
'varchar(128)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
307 'account_number' =>array(
'type'=>
'varchar(32)',
'label'=>
'Account number',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
308 'fk_accountancy_journal' =>array(
'type'=>
'integer',
'label'=>
'Accountancy journal ID',
'enabled'=>1,
'visible'=>-1,
'position'=>132),
309 'accountancy_journal' =>array(
'type'=>
'varchar(20)',
'label'=>
'Accountancy journal',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
310 'currency_code' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>140),
311 'min_allowed' =>array(
'type'=>
'integer',
'label'=>
'Min allowed',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
312 'min_desired' =>array(
'type'=>
'integer',
'label'=>
'Min desired',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
313 'comment' =>array(
'type'=>
'text',
'label'=>
'Comment',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
314 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>156),
315 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>157),
316 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
317 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>165),
318 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>170),
319 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>175),
320 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>180),
321 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
339 const STATUS_OPEN = 0;
340 const STATUS_CLOSED = 1;
356 $this->type_lib = array(
357 self::TYPE_SAVINGS => $langs->trans(
"BankType0"),
358 self::TYPE_CURRENT => $langs->trans(
"BankType1"),
359 self::TYPE_CASH => $langs->trans(
"BankType2"),
362 $this->status = array(
363 self::STATUS_OPEN => $langs->trans(
"StatusAccountOpened"),
364 self::STATUS_CLOSED => $langs->trans(
"StatusAccountClosed")
377 if ($val ==
'BankCode') {
378 $string .= $this->code_banque.
' ';
379 } elseif ($val ==
'BankAccountNumber') {
380 $string .= $this->number.
' ';
381 } elseif ($val ==
'DeskCode') {
382 $string .= $this->code_guichet.
' ';
383 } elseif ($val ==
'BankAccountNumberKey') {
384 $string .= $this->cle_rib.
' ';
385 } elseif ($val ==
'BIC') {
386 $string .= $this->bic.
' ';
387 } elseif ($val ==
'IBAN') {
388 $string .= $this->iban.
' ';
392 return trim($string);
405 if (empty($this->rappro)) {
408 if ($this->courant ==
Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
432 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
438 $sql .=
") VALUES (";
439 $sql .=
" ".((int) $line_id);
440 $sql .=
", ".((int) $url_id);
441 $sql .=
", '".$this->db->escape($url).
"'";
442 $sql .=
", '".$this->db->escape($label).
"'";
443 $sql .=
", '".$this->db->escape($type).
"'";
446 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
447 if ($this->
db->query($sql)) {
448 $rowid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
451 $this->
error = $this->
db->lasterror();
466 public function get_url($fk_bank =
'', $url_id =
'', $type =
'')
472 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
473 $this->
error =
"ErrorBadParameter";
477 $sql =
"SELECT fk_bank, url_id, url, label, type";
478 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
480 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
482 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->
db->escape($type).
"'";
484 $sql .=
" ORDER BY type, label";
486 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
487 $result = $this->
db->query($sql);
490 $num = $this->
db->num_rows($result);
492 $obj = $this->
db->fetch_object($result);
494 $lines[$i][0] = $obj->url;
495 $lines[$i][1] = $obj->url_id;
496 $lines[$i][2] = $obj->label;
497 $lines[$i][3] = $obj->type;
499 $lines[$i][
'url'] = $obj->url;
500 $lines[$i][
'url_id'] = $obj->url_id;
501 $lines[$i][
'label'] = $obj->label;
502 $lines[$i][
'type'] = $obj->type;
503 $lines[$i][
'fk_bank'] = $obj->fk_bank;
531 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
534 if (is_numeric($oper)) {
535 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
538 if (empty($this->
id) && !empty($this->
rowid)) {
539 $this->
id = $this->rowid;
543 $emetteur = trim($emetteur);
544 $banque = trim($banque);
545 $label = trim($label);
549 if (is_numeric($oper)) {
550 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
551 $sql .=
" WHERE id = ".((int) $oper);
552 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
555 $obj = $this->
db->fetch_object(
$resql);
565 $this->
error =
"oper not defined";
569 $this->
error =
"this->id not defined";
573 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
579 if (is_null($datev) || empty($datev)) {
584 $accline->datec = $now;
585 $accline->dateo = $date;
586 $accline->datev = $datev;
587 $accline->label = $label;
588 $accline->amount = $amount;
589 $accline->amount_main_currency = $amount_main_currency;
590 $accline->fk_user_author = $user->id;
591 $accline->fk_account = $this->id;
592 $accline->fk_type = $oper;
593 $accline->numero_compte = $accountancycode;
594 $accline->num_releve = $num_releve;
597 $accline->num_chq = $num_chq;
601 $accline->emetteur = $emetteur;
605 $accline->bank_chq = $banque;
608 if ($accline->insert() > 0) {
609 if ($categorie > 0) {
610 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
611 $sql .=
"lineid, fk_categ";
612 $sql .=
") VALUES (";
613 $sql .= ((int) $accline->id).
", '".$this->
db->escape($categorie).
"'";
616 $result = $this->
db->query($sql);
618 $this->
error = $this->
db->lasterror();
619 $this->
db->rollback();
629 $this->
error = $accline->error;
630 $this->errors = $accline->errors;
631 $this->
db->rollback();
646 global $langs, $conf;
651 if (!$this->min_allowed) {
652 $this->min_allowed = 0;
654 if (!$this->min_desired) {
655 $this->min_desired = 0;
659 if (empty($this->country_id)) {
660 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
664 if (empty($this->
ref)) {
665 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
669 if (empty($this->date_solde)) {
670 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
676 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
682 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
687 $sql .=
", account_number";
688 $sql .=
", fk_accountancy_journal";
690 $sql .=
", code_banque";
691 $sql .=
", code_guichet";
695 $sql .=
", iban_prefix";
696 $sql .=
", domiciliation";
697 $sql .=
", pti_in_ctti";
699 $sql .=
", owner_address";
700 $sql .=
", currency_code";
702 $sql .=
", min_allowed";
703 $sql .=
", min_desired";
705 $sql .=
", state_id";
708 $sql .=
", ics_transfer";
709 $sql .=
") VALUES (";
710 $sql .=
"'".$this->db->idate($now).
"'";
711 $sql .=
", '".$this->db->escape($this->
ref).
"'";
712 $sql .=
", '".$this->db->escape($this->label).
"'";
713 $sql .=
", ".((int) $conf->entity);
714 $sql .=
", '".$this->db->escape($this->account_number).
"'";
715 $sql .=
", ".($this->fk_accountancy_journal > 0 ? $this->
db->escape($this->fk_accountancy_journal) :
"null");
716 $sql .=
", '".$this->db->escape($this->bank).
"'";
717 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
718 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
719 $sql .=
", '".$this->db->escape($this->number).
"'";
720 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
721 $sql .=
", '".$this->db->escape($this->bic).
"'";
722 $sql .=
", '".$this->db->escape($this->iban).
"'";
723 $sql .=
", '".$this->db->escape($this->domiciliation).
"'";
724 $sql .=
", ".((int) $this->pti_in_ctti);
725 $sql .=
", '".$this->db->escape($this->proprio).
"'";
726 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
727 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
728 $sql .=
", ".((int) $this->rappro);
729 $sql .=
", ".price2num($this->min_allowed,
'MT');
730 $sql .=
", ".price2num($this->min_desired,
'MT');
731 $sql .=
", '".$this->db->escape($this->comment).
"'";
732 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
733 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
734 $sql .=
", '".$this->db->escape($this->ics).
"'";
735 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
738 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
741 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
743 $result = $this->
update($user, 1);
746 $accline->datec = $this->
db->idate($now);
747 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
749 $accline->fk_user_author = $user->id;
750 $accline->fk_account = $this->id;
751 $accline->datev = $this->
db->idate($this->date_solde);
752 $accline->dateo = $this->
db->idate($this->date_solde);
753 $accline->fk_type =
'SOLD';
755 if ($accline->insert() < 0) {
757 $this->
error = $accline->error;
758 $this->errors = $accline->errors;
768 if (!$error && !$notrigger) {
770 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
780 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
781 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
784 $this->
error = $this->
db->error().
" sql=".$sql;
793 $this->
db->rollback();
807 global $langs, $conf;
814 if (empty($this->country_id)) {
815 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
819 if (empty($this->
ref)) {
820 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
825 $this->label =
"???";
828 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
830 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
831 $sql .=
",label = '".$this->db->escape($this->label).
"'";
833 $sql .=
",courant = ".((int) $this->courant);
834 $sql .=
",clos = ".((int) $this->clos);
835 $sql .=
",rappro = ".((int) $this->rappro);
836 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
837 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
838 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? $this->
db->escape($this->fk_accountancy_journal) :
"null");
839 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
840 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
841 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
842 $sql .=
",number='".$this->db->escape($this->number).
"'";
843 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
844 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
845 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
846 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
847 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
848 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
849 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
851 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
853 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
854 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
855 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
857 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
858 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
859 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
860 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
862 $sql .=
" WHERE rowid = ".((int) $this->
id);
864 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
865 $result = $this->
db->query($sql);
875 if (!$error && !$notrigger) {
877 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
885 $this->
error = $this->
db->lasterror();
893 $this->
db->rollback();
909 global $conf, $langs;
912 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
914 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
918 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
922 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
923 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
924 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
925 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
926 $sql .=
",number='".$this->db->escape($this->number).
"'";
927 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
928 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
929 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
930 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
931 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
932 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
933 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
934 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
935 $sql .=
" WHERE rowid = ".((int) $this->
id);
936 $sql .=
" AND entity = ".((int) $conf->entity);
938 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
940 $result = $this->
db->query($sql);
944 $this->
error = $this->
db->lasterror();
958 public function fetch($id, $ref =
'')
962 if (empty($id) && empty($ref)) {
963 $this->
error =
"ErrorBadParameters";
967 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
968 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
969 $sql .=
" ba.domiciliation, ba.pti_in_ctti, ba.proprio, ba.owner_address, ba.state_id, ba.fk_pays as country_id,";
970 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
971 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
972 $sql .=
" ba.datec as date_creation, ba.tms as date_update, ba.ics, ba.ics_transfer,";
973 $sql .=
' c.code as country_code, c.label as country,';
974 $sql .=
' d.code_departement as state_code, d.nom as state';
975 $sql .=
' , aj.code as accountancy_journal';
976 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
977 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
978 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
979 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
980 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
982 $sql .=
" AND ba.rowid = ".((int) $id);
985 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
988 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
989 $result = $this->
db->query($sql);
991 if ($this->
db->num_rows($result)) {
992 $obj = $this->
db->fetch_object($result);
994 $this->
id = $obj->rowid;
995 $this->
rowid = $obj->rowid;
996 $this->
ref = $obj->ref;
997 $this->label = $obj->label;
998 $this->
type = $obj->courant;
999 $this->courant = $obj->courant;
1000 $this->bank = $obj->bank;
1001 $this->clos = $obj->clos;
1002 $this->rappro = $obj->rappro;
1003 $this->url = $obj->url;
1005 $this->code_banque = $obj->code_banque;
1006 $this->code_guichet = $obj->code_guichet;
1007 $this->number = $obj->number;
1008 $this->cle_rib = $obj->cle_rib;
1009 $this->bic = $obj->bic;
1010 $this->iban = $obj->iban;
1011 $this->domiciliation = $obj->domiciliation;
1012 $this->pti_in_ctti = $obj->pti_in_ctti;
1013 $this->proprio = $obj->proprio;
1014 $this->owner_address = $obj->owner_address;
1016 $this->state_id = $obj->state_id;
1017 $this->state_code = $obj->state_code;
1018 $this->state = $obj->state;
1020 $this->country_id = $obj->country_id;
1021 $this->country_code = $obj->country_code;
1022 $this->country = $obj->country;
1024 $this->account_number = $obj->account_number;
1025 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1026 $this->accountancy_journal = $obj->accountancy_journal;
1028 $this->currency_code = $obj->currency_code;
1029 $this->account_currency_code = $obj->currency_code;
1030 $this->min_allowed = $obj->min_allowed;
1031 $this->min_desired = $obj->min_desired;
1032 $this->comment = $obj->comment;
1034 $this->date_creation = $this->
db->jdate($obj->date_creation);
1035 $this->date_update = $this->
db->jdate($obj->date_update);
1037 $this->ics = $obj->ics;
1038 $this->ics_transfer = $obj->ics_transfer;
1049 $this->
error = $this->
db->lasterror;
1050 $this->errors[] = $this->error;
1067 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1068 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1077 public function delete(
User $user =
null)
1089 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1090 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1095 $this->
error =
"Error ".$this->db->lasterror();
1100 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_account";
1101 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
1103 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1104 $result = $this->
db->query($sql);
1111 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1116 $this->
error =
"Error ".$this->db->lasterror();
1121 $this->
db->commit();
1124 $this->
db->rollback();
1138 return $this->
LibStatut($this->clos, $mode);
1153 $langs->load(
'banks');
1155 if ($status == self::STATUS_OPEN) {
1156 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1157 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1158 $statusType =
'status4';
1160 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1161 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1162 $statusType =
'status5';
1165 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1178 $can_be_deleted =
false;
1180 $sql =
"SELECT COUNT(rowid) as nb";
1181 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1182 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1186 $obj = $this->
db->fetch_object(
$resql);
1187 if ($obj->nb <= 1) {
1188 $can_be_deleted =
true;
1193 return $can_be_deleted;
1204 return $this->error;
1215 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1219 $sql =
"SELECT sum(amount) as amount";
1220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1221 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1223 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->
db->idate($date_end) : $this->
db->idate(
dol_now())).
"'";
1229 $obj = $this->
db->fetch_object(
$resql);
1230 $solde = $obj->amount;
1234 $this->errors[] = $this->
db->lasterror;
1252 global $conf, $langs;
1258 $sql =
"SELECT b.rowid, b.datev as datefin";
1259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1260 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1261 $sql .=
" WHERE b.rappro=0";
1262 $sql .=
" AND b.fk_account = ba.rowid";
1263 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1264 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1265 $sql .=
" AND clos = 0";
1266 if ($filteraccountid) {
1267 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1272 $langs->load(
"banks");
1275 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1278 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1279 $response->label = $langs->trans(
"TransactionsToConciliate");
1280 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1281 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1284 while ($obj = $this->
db->fetch_object(
$resql)) {
1285 $response->nbtodo++;
1286 if ($this->
db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1287 $response->nbtodolate++;
1294 $this->
error = $this->
db->error();
1314 $sql =
"SELECT count(b.rowid) as nb";
1315 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1316 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1317 $sql .=
" WHERE b.fk_account = ba.rowid";
1318 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1319 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1320 $sql .=
" AND clos = 0";
1321 if ($filteraccountid) {
1322 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1327 while ($obj = $this->
db->fetch_object(
$resql)) {
1328 $this->nb[
"banklines"] = $obj->nb;
1333 $this->
error = $this->
db->error();
1346 global $db, $conf, $user;
1355 $sql =
"SELECT COUNT(ba.rowid) as nb";
1356 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1357 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1358 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1359 if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
1360 $sql .=
" AND ba.courant != 2";
1364 $obj = $this->
db->fetch_object(
$resql);
1383 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0)
1385 global $conf, $langs, $user;
1388 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1389 if (isset($this->status)) {
1390 $label .=
' '.$this->getLibStatut(5);
1392 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1393 $label .=
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1394 $label .=
'<br><b>'.$langs->trans(
'IBAN').
':</b> '.$this->iban;
1395 $label .=
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1396 $label .=
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1398 if (empty($user->rights->banque->lire) || !empty($user->socid)) {
1403 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1404 $langs->load(
"accountancy");
1405 $label .=
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1406 $label .=
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1409 $linkclose =
'" title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1411 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1412 if ($mode ==
'transactions') {
1413 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1414 } elseif ($mode ==
'receipts') {
1415 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1418 if ($option !=
'nolink') {
1420 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1421 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1422 $add_save_lastsearch_values = 1;
1424 if ($add_save_lastsearch_values) {
1425 $url .=
'&save_lastsearch_values=1';
1429 $linkstart =
'<a href="'.$url.$linkclose;
1432 if ($option ==
'nolink') {
1437 $result .= $linkstart;
1439 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1441 if ($withpicto != 2) {
1442 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1444 $result .= $linkend;
1460 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1462 $this->error_number = 0;
1467 $this->error_number = 12;
1468 $this->error_message =
'IBANNotValid';
1471 $this->error_number = 12;
1472 $this->error_message =
'SwiftNotValid';
1480 if ($this->error_number == 0) {
1497 if (!empty($this->country_code)) {
1498 return $this->country_code;
1502 if (!empty($this->iban)) {
1505 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1511 if (!empty($this->socid)) {
1512 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1514 $result = $company->fetch($this->socid);
1515 if (!empty($company->country_code)) {
1516 return $company->country_code;
1521 if (!empty($mysoc->country_code)) {
1522 return $mysoc->country_code;
1540 if (in_array($country_code, array(
'FR',
'ES',
'GA',
'IT',
'NC'))) {
1543 if (in_array($country_code, array(
'AD',
'AU',
'BE',
'CA',
'DE',
'DK',
'GR',
'GB',
'ID',
'IE',
'IR',
'KR',
'NL',
'NZ',
'UK',
'US'))) {
1558 if (!empty($conf->global->MAIN_IBAN_IS_NEVER_MANDATORY)) {
1564 $country_code_in_EEC = array(
1600 if (in_array($country_code, $country_code_in_EEC)) {
1635 if ($detailedBBAN == 0) {
1636 $fieldarray = array(
1639 } elseif ($detailedBBAN == 2) {
1640 $fieldarray = array(
1649 if ($includeibanbic) {
1650 $fieldarray[] =
'IBAN';
1651 $fieldarray[] =
'BIC';
1673 $fieldlists = array(
1676 'BankAccountNumber',
1677 'BankAccountNumberKey'
1680 if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {
1681 if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1682 if ($conf->global->BANK_SHOW_ORDER_OPTION ==
'1') {
1683 $fieldlists = array(
1686 'BankAccountNumberKey',
1692 $fieldlists = explode(
1694 preg_replace(
'/ ?[^Bank]AccountNumber ?/',
'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1713 $this->specimen = 1;
1715 $this->label =
'My Big Company Bank account';
1716 $this->bank =
'MyBank';
1718 $this->clos = Account::STATUS_OPEN;
1719 $this->code_banque =
'30001';
1720 $this->code_guichet =
'00794';
1721 $this->number =
'12345678901';
1722 $this->cle_rib =
'85';
1723 $this->bic =
'AA12';
1724 $this->iban =
'FR7630001007941234567890185';
1725 $this->domiciliation =
'Banque de France';
1726 $this->proprio =
'Owner';
1727 $this->owner_address =
'Owner address';
1728 $this->country_id = 1;
1741 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_url SET url_id = ".((int) $dest_id).
" WHERE url_id = ".((int) $origin_id).
" AND type='company'";
1743 if ($dbs->query($sql)) {
1772 public $element =
'bank';
1777 public $table_element =
'bank';
1782 public $picto =
'accountline';
1816 public $amount_main_currency;
1821 public $fk_user_author;
1826 public $fk_user_rappro;
1836 public $fk_bordereau;
1846 public $bank_account_ref;
1851 public $bank_account_label;
1856 public $numero_compte;
1895 public function fetch($rowid, $ref =
'', $num =
'')
1900 if (empty($rowid) && empty($ref) && empty($num)) {
1904 $sql =
"SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
1905 $sql .=
" b.fk_user_author, b.fk_user_rappro,";
1906 $sql .=
" b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
1907 $sql .=
" b.fk_bordereau, b.banque, b.emetteur,";
1908 $sql .=
" ba.ref as bank_account_ref, ba.label as bank_account_label";
1909 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1910 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1911 $sql .=
" WHERE b.fk_account = ba.rowid";
1912 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1914 $sql .=
" AND b.num_chq='".$this->db->escape($num).
"'";
1916 $sql .=
" AND b.rowid='".$this->db->escape($ref).
"'";
1918 $sql .=
" AND b.rowid = ".((int) $rowid);
1921 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1922 $result = $this->
db->query($sql);
1926 $obj = $this->
db->fetch_object($result);
1928 $this->
id = $obj->rowid;
1929 $this->
rowid = $obj->rowid;
1930 $this->
ref = $obj->rowid;
1932 $this->datec = $obj->datec;
1933 $this->datev = $obj->datev;
1934 $this->dateo = $obj->dateo;
1935 $this->amount = $obj->amount;
1936 $this->label = $obj->label;
1937 $this->note = $obj->note;
1939 $this->fk_user_author = $obj->fk_user_author;
1940 $this->fk_user_rappro = $obj->fk_user_rappro;
1942 $this->fk_type = $obj->fk_type;
1943 $this->rappro = $obj->rappro;
1944 $this->num_releve = $obj->num_releve;
1946 $this->num_chq = $obj->num_chq;
1947 $this->bank_chq = $obj->banque;
1948 $this->fk_bordereau = $obj->fk_bordereau;
1950 $this->fk_account = $obj->fk_account;
1951 $this->bank_account_ref = $obj->bank_account_ref;
1952 $this->bank_account_label = $obj->bank_account_label;
1956 $this->
db->free($result);
1970 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank (";
1976 $sql .=
", amount_main_currency";
1977 $sql .=
", fk_user_author";
1978 $sql .=
", num_chq";
1979 $sql .=
", fk_account";
1980 $sql .=
", fk_type";
1981 $sql .=
", emetteur,banque";
1983 $sql .=
", numero_compte";
1984 $sql .=
", num_releve";
1985 $sql .=
") VALUES (";
1986 $sql .=
"'".$this->db->idate($this->datec).
"'";
1987 $sql .=
", '".$this->db->idate($this->dateo).
"'";
1988 $sql .=
", '".$this->db->idate($this->datev).
"'";
1989 $sql .=
", '".$this->db->escape($this->label).
"'";
1990 $sql .=
", ".price2num($this->amount);
1991 $sql .=
", ".(empty($this->amount_main_currency) ?
"NULL" :
price2num($this->amount_main_currency));
1992 $sql .=
", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) :
"null");
1993 $sql .=
", ".($this->num_chq ?
"'".$this->db->escape($this->num_chq).
"'" :
"null");
1994 $sql .=
", '".$this->db->escape($this->fk_account).
"'";
1995 $sql .=
", '".$this->db->escape($this->fk_type).
"'";
1996 $sql .=
", ".($this->emetteur ?
"'".$this->db->escape($this->emetteur).
"'" :
"null");
1997 $sql .=
", ".($this->bank_chq ?
"'".$this->db->escape($this->bank_chq).
"'" :
"null");
1998 $sql .=
", ".(int) $this->rappro;
1999 $sql .=
", ".($this->numero_compte ?
"'".$this->db->escape($this->numero_compte).
"'" :
"''");
2000 $sql .=
", ".($this->num_releve ?
"'".$this->db->escape($this->num_releve).
"'" :
"null");
2003 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2007 $this->error = $this->
db->lasterror();
2011 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'bank');
2022 public function delete(
User $user =
null)
2028 if ($this->rappro) {
2030 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2037 if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING)) {
2038 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2041 $obj = $this->
db->fetch_object(
$resql);
2042 if ($obj && $obj->nb) {
2043 $this->error =
'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2044 $this->
db->rollback();
2048 $this->error = $this->
db->lasterror();
2049 $this->
db->rollback();
2060 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class WHERE lineid=".(int) $this->
rowid;
2061 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2062 $result = $this->
db->query($sql);
2067 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid=".(int) $this->
rowid;
2068 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2069 $result = $this->
db->query($sql);
2075 $this->
db->commit();
2078 $this->
db->rollback();
2096 if ($this->rappro) {
2098 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2104 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url WHERE fk_bank=".(int) $this->
rowid;
2105 dol_syslog(get_class($this).
"::delete_urls", LOG_DEBUG);
2106 $result = $this->
db->query($sql);
2112 $this->
db->commit();
2115 $this->
db->rollback();
2132 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2133 $sql .=
" amount = ".price2num($this->amount).
",";
2134 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
2135 $sql .=
" dateo='".$this->db->idate($this->dateo).
"'";
2136 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
2138 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2141 $this->
db->commit();
2144 $this->
db->rollback();
2145 $this->error = $this->
db->error();
2163 global $conf, $langs;
2168 if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE)) {
2169 if (!preg_match(
'/'.$conf->global->BANK_STATEMENT_REGEX_RULE.
'/', $this->num_releve)) {
2170 $this->errors[] = $langs->trans(
"ErrorBankStatementNameMustFollowRegex", $conf->global->BANK_STATEMENT_REGEX_RULE);
2175 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2176 $sql .=
" rappro = ".((int) $conciliated);
2177 $sql .=
", num_releve = '".$this->db->escape($this->num_releve).
"'";
2179 $sql .=
", fk_user_rappro = ".$user->id;
2181 $sql .=
" WHERE rowid = ".((int) $this->
id);
2183 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2187 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class (";
2189 $sql .=
", fk_categ";
2190 $sql .=
") VALUES (";
2192 $sql .=
", ".((int) $cat);
2195 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2196 $this->
db->query($sql);
2203 $this->
db->commit();
2206 $this->
db->rollback();
2223 $sql =
"SELECT datev FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2226 $obj = $this->
db->fetch_object(
$resql);
2227 $newdate = $this->
db->jdate($obj->datev) + (3600 * 24 * $sign);
2229 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2230 $sql .=
" datev = '".$this->db->idate($newdate).
"'";
2231 $sql .=
" WHERE rowid = ".((int) $rowid);
2233 $result = $this->
db->query($sql);
2235 if ($this->
db->affected_rows($result)) {
2286 $sql =
"SELECT dateo FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2289 $obj = $this->
db->fetch_object(
$resql);
2290 $newdate = $this->
db->jdate($obj->dateo) + (3600 * 24 * $sign);
2292 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2293 $sql .=
" dateo = '".$this->db->idate($newdate).
"'";
2294 $sql .=
" WHERE rowid = ".((int) $rowid);
2296 $result = $this->
db->query($sql);
2298 if ($this->
db->affected_rows($result)) {
2346 $sql =
'SELECT b.rowid, b.datec, b.tms as datem,';
2347 $sql .=
' b.fk_user_author, b.fk_user_rappro';
2348 $sql .=
' FROM '.MAIN_DB_PREFIX.
'bank as b';
2349 $sql .=
' WHERE b.rowid = '.((int) $id);
2351 $result = $this->
db->query($sql);
2353 if ($this->
db->num_rows($result)) {
2354 $obj = $this->
db->fetch_object($result);
2355 $this->
id = $obj->rowid;
2357 if ($obj->fk_user_author) {
2358 $cuser =
new User($this->
db);
2359 $cuser->fetch($obj->fk_user_author);
2360 $this->user_creation = $cuser;
2362 if ($obj->fk_user_rappro) {
2363 $ruser =
new User($this->
db);
2364 $ruser->fetch($obj->fk_user_rappro);
2365 $this->user_rappro = $ruser;
2368 $this->date_creation = $this->
db->jdate($obj->datec);
2369 $this->date_modification = $this->
db->jdate($obj->datem);
2372 $this->
db->free($result);
2388 public function getNomUrl($withpicto = 0, $maxlen = 0, $option =
'', $notooltip = 0)
2394 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"BankTransactionLine").
'</u>:<br>';
2395 $label .=
'<b>'.$langs->trans(
"Ref").
':</b> '.$this->ref;
2397 $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">';
2400 $result .= $linkstart;
2402 $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);
2404 if ($withpicto != 2) {
2405 $result .= ($this->
ref ? $this->
ref : $this->id);
2407 $result .= $linkend;
2409 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2410 $result .=
' <span class="opacitymedium">(';
2412 if ($option ==
'showall') {
2413 $result .= $langs->trans(
"BankAccount").
': ';
2414 $accountstatic =
new Account($this->
db);
2415 $accountstatic->id = $this->fk_account;
2416 $accountstatic->ref = $this->bank_account_ref;
2417 $accountstatic->label = $this->bank_account_label;
2418 $result .= $accountstatic->getNomUrl(0).
', ';
2420 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2421 $result .= $langs->trans(
"BankLineConciliated").
': ';
2422 $result .=
yn($this->rappro);
2424 if ($option ==
'showall' || $option ==
'showconciliatedandaccounted') {
2425 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2428 $obj = $this->
db->fetch_object(
$resql);
2429 if ($obj && $obj->nb) {
2430 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(1);
2432 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(0);
2436 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2437 $result .=
')</span>';
2452 return $this->
LibStatut($this->status, $mode);
2509 $alreadydispatched = 0;
2513 $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);
2516 $obj = $this->
db->fetch_object(
$resql);
2518 $alreadydispatched = $obj->nb;
2521 $this->error = $this->
db->lasterror();
2525 if ($alreadydispatched) {