33 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
44 public $element =
'bank_account';
49 public $table_element =
'bank_account';
54 public $picto =
'account';
91 public $clos = self::STATUS_OPEN;
115 public $code_guichet;
153 public $domiciliation;
159 public $pti_in_ctti = 0;
171 public $owner_address;
182 public $type_lib = array();
189 public $status = array();
195 public $account_number;
200 public $fk_accountancy_journal;
204 public $accountancy_journal;
210 public $currency_code;
217 public $account_currency_code;
253 public $ics_transfer;
285 public $fields = array(
286 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
287 'ref' =>array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>25),
288 'label' =>array(
'type'=>
'varchar(30)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
289 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>35,
'index'=>1),
290 'bank' =>array(
'type'=>
'varchar(60)',
'label'=>
'Bank',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
291 'code_banque' =>array(
'type'=>
'varchar(128)',
'label'=>
'Code banque',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
292 'code_guichet' =>array(
'type'=>
'varchar(6)',
'label'=>
'Code guichet',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
293 'number' =>array(
'type'=>
'varchar(255)',
'label'=>
'Number',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
294 'cle_rib' =>array(
'type'=>
'varchar(5)',
'label'=>
'Cle rib',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
295 'bic' =>array(
'type'=>
'varchar(11)',
'label'=>
'Bic',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
296 'iban_prefix' =>array(
'type'=>
'varchar(34)',
'label'=>
'Iban prefix',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
297 'country_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Country iban',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
298 'cle_iban' =>array(
'type'=>
'varchar(2)',
'label'=>
'Cle iban',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
299 'domiciliation' =>array(
'type'=>
'varchar(255)',
'label'=>
'Domiciliation',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
300 'state_id' =>array(
'type'=>
'integer',
'label'=>
'State id',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
301 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Fk pays',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>95),
302 'proprio' =>array(
'type'=>
'varchar(60)',
'label'=>
'Proprio',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
303 'owner_address' =>array(
'type'=>
'text',
'label'=>
'Owner address',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
304 'courant' =>array(
'type'=>
'smallint(6)',
'label'=>
'Courant',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>110),
305 'clos' =>array(
'type'=>
'smallint(6)',
'label'=>
'Clos',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>115),
306 'rappro' =>array(
'type'=>
'smallint(6)',
'label'=>
'Rappro',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
307 'url' =>array(
'type'=>
'varchar(128)',
'label'=>
'Url',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
308 'account_number' =>array(
'type'=>
'varchar(32)',
'label'=>
'Account number',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
309 'fk_accountancy_journal' =>array(
'type'=>
'integer',
'label'=>
'Accountancy journal ID',
'enabled'=>1,
'visible'=>-1,
'position'=>132),
310 'accountancy_journal' =>array(
'type'=>
'varchar(20)',
'label'=>
'Accountancy journal',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
311 'currency_code' =>array(
'type'=>
'varchar(3)',
'label'=>
'Currency code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>140),
312 'min_allowed' =>array(
'type'=>
'integer',
'label'=>
'Min allowed',
'enabled'=>1,
'visible'=>-1,
'position'=>145),
313 'min_desired' =>array(
'type'=>
'integer',
'label'=>
'Min desired',
'enabled'=>1,
'visible'=>-1,
'position'=>150),
314 'comment' =>array(
'type'=>
'text',
'label'=>
'Comment',
'enabled'=>1,
'visible'=>-1,
'position'=>155),
315 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>156),
316 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>157),
317 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
318 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>165),
319 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>170),
320 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>175),
321 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>180),
322 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
340 const STATUS_OPEN = 0;
341 const STATUS_CLOSED = 1;
357 $this->type_lib = array(
358 self::TYPE_SAVINGS => $langs->trans(
"BankType0"),
359 self::TYPE_CURRENT => $langs->trans(
"BankType1"),
360 self::TYPE_CASH => $langs->trans(
"BankType2"),
363 $this->status = array(
364 self::STATUS_OPEN => $langs->trans(
"StatusAccountOpened"),
365 self::STATUS_CLOSED => $langs->trans(
"StatusAccountClosed")
378 if ($val ==
'BankCode') {
379 $string .= $this->code_banque.
' ';
380 } elseif ($val ==
'BankAccountNumber') {
381 $string .= $this->number.
' ';
382 } elseif ($val ==
'DeskCode') {
383 $string .= $this->code_guichet.
' ';
384 } elseif ($val ==
'BankAccountNumberKey') {
385 $string .= $this->cle_rib.
' ';
386 } elseif ($val ==
'BIC') {
387 $string .= $this->bic.
' ';
388 } elseif ($val ==
'IBAN') {
389 $string .= $this->iban.
' ';
393 return trim($string);
406 if (empty($this->rappro)) {
409 if ($this->courant ==
Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
433 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
439 $sql .=
") VALUES (";
440 $sql .=
" ".((int) $line_id);
441 $sql .=
", ".((int) $url_id);
442 $sql .=
", '".$this->db->escape($url).
"'";
443 $sql .=
", '".$this->db->escape($label).
"'";
444 $sql .=
", '".$this->db->escape($type).
"'";
447 dol_syslog(get_class($this).
"::add_url_line", LOG_DEBUG);
448 if ($this->
db->query($sql)) {
449 $rowid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"bank_url");
452 $this->
error = $this->
db->lasterror();
467 public function get_url($fk_bank =
'', $url_id =
'', $type =
'')
473 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
474 $this->
error =
"ErrorBadParameter";
478 $sql =
"SELECT fk_bank, url_id, url, label, type";
479 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_url";
481 $sql .=
" WHERE fk_bank = ".((int) $fk_bank);
483 $sql .=
" WHERE url_id = ".((int) $url_id).
" AND type = '".$this->
db->escape($type).
"'";
485 $sql .=
" ORDER BY type, label";
487 dol_syslog(get_class($this).
"::get_url", LOG_DEBUG);
488 $result = $this->
db->query($sql);
491 $num = $this->
db->num_rows($result);
493 $obj = $this->
db->fetch_object($result);
495 $lines[$i][0] = $obj->url;
496 $lines[$i][1] = $obj->url_id;
497 $lines[$i][2] = $obj->label;
498 $lines[$i][3] = $obj->type;
500 $lines[$i][
'url'] = $obj->url;
501 $lines[$i][
'url_id'] = $obj->url_id;
502 $lines[$i][
'label'] = $obj->label;
503 $lines[$i][
'type'] = $obj->type;
504 $lines[$i][
'fk_bank'] = $obj->fk_bank;
532 public function addline($date, $oper, $label, $amount, $num_chq, $categorie,
User $user, $emetteur =
'', $banque =
'', $accountancycode =
'', $datev =
null, $num_releve =
'', $amount_main_currency =
null)
535 if (is_numeric($oper)) {
536 dol_syslog(__METHOD__.
": using numeric operations is deprecated", LOG_WARNING);
539 if (empty($this->
id) && !empty($this->
rowid)) {
540 $this->
id = $this->rowid;
544 $emetteur = trim($emetteur);
545 $banque = trim($banque);
546 $label = trim($label);
550 if (is_numeric($oper)) {
551 $sql =
"SELECT code FROM ".MAIN_DB_PREFIX.
"c_paiement";
552 $sql .=
" WHERE id = ".((int) $oper);
553 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
556 $obj = $this->
db->fetch_object(
$resql);
566 $this->
error =
"oper not defined";
570 $this->
error =
"this->id not defined";
574 $this->
error =
"ErrorCashAccountAcceptsOnlyCashMoney";
580 if (is_null($datev) || empty($datev)) {
585 $accline->datec = $now;
586 $accline->dateo = $date;
587 $accline->datev = $datev;
588 $accline->label = $label;
589 $accline->amount = $amount;
590 $accline->amount_main_currency = $amount_main_currency;
591 $accline->fk_user_author = $user->id;
592 $accline->fk_account = $this->id;
593 $accline->fk_type = $oper;
594 $accline->numero_compte = $accountancycode;
595 $accline->num_releve = $num_releve;
598 $accline->num_chq = $num_chq;
602 $accline->emetteur = $emetteur;
606 $accline->bank_chq = $banque;
609 if ($accline->insert() > 0) {
610 if ($categorie > 0) {
611 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class(";
612 $sql .=
"lineid, fk_categ";
613 $sql .=
") VALUES (";
614 $sql .= ((int) $accline->id).
", '".$this->
db->escape($categorie).
"'";
617 $result = $this->
db->query($sql);
619 $this->
error = $this->
db->lasterror();
620 $this->
db->rollback();
630 $this->
error = $accline->error;
631 $this->errors = $accline->errors;
632 $this->
db->rollback();
647 global $langs, $conf;
652 if (!$this->min_allowed) {
653 $this->min_allowed = 0;
655 if (!$this->min_desired) {
656 $this->min_desired = 0;
660 if (empty($this->country_id)) {
661 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
665 if (empty($this->
ref)) {
666 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
670 if (empty($this->date_solde)) {
671 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateInitialBalance"));
677 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
683 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_account (";
688 $sql .=
", account_number";
689 $sql .=
", fk_accountancy_journal";
691 $sql .=
", code_banque";
692 $sql .=
", code_guichet";
696 $sql .=
", iban_prefix";
697 $sql .=
", domiciliation";
698 $sql .=
", pti_in_ctti";
700 $sql .=
", owner_address";
701 $sql .=
", currency_code";
703 $sql .=
", min_allowed";
704 $sql .=
", min_desired";
706 $sql .=
", state_id";
709 $sql .=
", ics_transfer";
710 $sql .=
") VALUES (";
711 $sql .=
"'".$this->db->idate($now).
"'";
712 $sql .=
", '".$this->db->escape($this->
ref).
"'";
713 $sql .=
", '".$this->db->escape($this->label).
"'";
714 $sql .=
", ".((int) $conf->entity);
715 $sql .=
", '".$this->db->escape($this->account_number).
"'";
716 $sql .=
", ".($this->fk_accountancy_journal > 0 ? $this->
db->escape($this->fk_accountancy_journal) :
"null");
717 $sql .=
", '".$this->db->escape($this->bank).
"'";
718 $sql .=
", '".$this->db->escape($this->code_banque).
"'";
719 $sql .=
", '".$this->db->escape($this->code_guichet).
"'";
720 $sql .=
", '".$this->db->escape($this->number).
"'";
721 $sql .=
", '".$this->db->escape($this->cle_rib).
"'";
722 $sql .=
", '".$this->db->escape($this->bic).
"'";
723 $sql .=
", '".$this->db->escape($this->iban).
"'";
724 $sql .=
", '".$this->db->escape($this->domiciliation).
"'";
725 $sql .=
", ".((int) $this->pti_in_ctti);
726 $sql .=
", '".$this->db->escape($this->proprio).
"'";
727 $sql .=
", '".$this->db->escape($this->owner_address).
"'";
728 $sql .=
", '".$this->db->escape($this->currency_code).
"'";
729 $sql .=
", ".((int) $this->rappro);
730 $sql .=
", ".price2num($this->min_allowed,
'MT');
731 $sql .=
", ".price2num($this->min_desired,
'MT');
732 $sql .=
", '".$this->db->escape($this->comment).
"'";
733 $sql .=
", ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
734 $sql .=
", ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
735 $sql .=
", '".$this->db->escape($this->ics).
"'";
736 $sql .=
", '".$this->db->escape($this->ics_transfer).
"'";
739 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
742 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"bank_account");
744 $result = $this->
update($user, 1);
747 $accline->datec = $this->
db->idate($now);
748 $accline->label =
'('.$langs->trans(
"InitialBankBalance").
')';
750 $accline->fk_user_author = $user->id;
751 $accline->fk_account = $this->id;
752 $accline->datev = $this->
db->idate($this->date_solde);
753 $accline->dateo = $this->
db->idate($this->date_solde);
754 $accline->fk_type =
'SOLD';
756 if ($accline->insert() < 0) {
758 $this->
error = $accline->error;
759 $this->errors = $accline->errors;
769 if (!$error && !$notrigger) {
771 $result = $this->
call_trigger(
'BANKACCOUNT_CREATE', $user);
781 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
782 $this->
error = $langs->trans(
"ErrorBankLabelAlreadyExists");
785 $this->
error = $this->
db->error().
" sql=".$sql;
794 $this->
db->rollback();
808 global $langs, $conf;
815 if (empty($this->country_id)) {
816 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Country"));
820 if (empty($this->
ref)) {
821 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Ref"));
826 $this->label =
"???";
829 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
831 $sql .=
" ref = '".$this->db->escape($this->
ref).
"'";
832 $sql .=
",label = '".$this->db->escape($this->label).
"'";
834 $sql .=
",courant = ".((int) $this->courant);
835 $sql .=
",clos = ".((int) $this->clos);
836 $sql .=
",rappro = ".((int) $this->rappro);
837 $sql .=
",url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
"null");
838 $sql .=
",account_number = '".$this->db->escape($this->account_number).
"'";
839 $sql .=
",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? $this->
db->escape($this->fk_accountancy_journal) :
"null");
840 $sql .=
",bank = '".$this->db->escape($this->bank).
"'";
841 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
842 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
843 $sql .=
",number='".$this->db->escape($this->number).
"'";
844 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
845 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
846 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
847 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
848 $sql .=
",pti_in_ctti=".((int) $this->pti_in_ctti);
849 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
850 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
852 $sql .=
",currency_code = '".$this->db->escape($this->currency_code).
"'";
854 $sql .=
",min_allowed = ".($this->min_allowed !=
'' ?
price2num($this->min_allowed) :
"null");
855 $sql .=
",min_desired = ".($this->min_desired !=
'' ?
price2num($this->min_desired) :
"null");
856 $sql .=
",comment = '".$this->db->escape($this->comment).
"'";
858 $sql .=
",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) :
"null");
859 $sql .=
",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) :
"null");
860 $sql .=
",ics = '".$this->db->escape($this->ics).
"'";
861 $sql .=
",ics_transfer = '".$this->db->escape($this->ics_transfer).
"'";
863 $sql .=
" WHERE rowid = ".((int) $this->
id);
865 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
866 $result = $this->
db->query($sql);
876 if (!$error && !$notrigger) {
878 $result = $this->
call_trigger(
'BANKACCOUNT_MODIFY', $user);
886 $this->
error = $this->
db->lasterror();
894 $this->
db->rollback();
910 global $conf, $langs;
913 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
915 dol_syslog(get_class($this).
"::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
919 $this->
error = $langs->transnoentitiesnoconv(
"ErrorFieldRequired", $langs->trans(
"Ref"));
923 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_account SET ";
924 $sql .=
" bank = '".$this->db->escape($this->bank).
"'";
925 $sql .=
",code_banque='".$this->db->escape($this->code_banque).
"'";
926 $sql .=
",code_guichet='".$this->db->escape($this->code_guichet).
"'";
927 $sql .=
",number='".$this->db->escape($this->number).
"'";
928 $sql .=
",cle_rib='".$this->db->escape($this->cle_rib).
"'";
929 $sql .=
",bic='".$this->db->escape($this->bic).
"'";
930 $sql .=
",iban_prefix = '".$this->db->escape($this->iban).
"'";
931 $sql .=
",domiciliation='".$this->db->escape($this->domiciliation).
"'";
932 $sql .=
",proprio = '".$this->db->escape($this->proprio).
"'";
933 $sql .=
",owner_address = '".$this->db->escape($this->owner_address).
"'";
934 $sql .=
",state_id = ".($this->state_id > 0 ? $this->state_id :
"null");
935 $sql .=
",fk_pays = ".($this->country_id > 0 ? $this->country_id :
"null");
936 $sql .=
" WHERE rowid = ".((int) $this->
id);
937 $sql .=
" AND entity = ".((int) $conf->entity);
939 dol_syslog(get_class($this).
"::update_bban", LOG_DEBUG);
941 $result = $this->
db->query($sql);
945 $this->
error = $this->
db->lasterror();
959 public function fetch($id, $ref =
'')
963 if (empty($id) && empty($ref)) {
964 $this->
error =
"ErrorBadParameters";
968 $sql =
"SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
969 $sql .=
" ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
970 $sql .=
" ba.domiciliation, ba.pti_in_ctti, ba.proprio, ba.owner_address, ba.state_id, ba.fk_pays as country_id,";
971 $sql .=
" ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
972 $sql .=
" ba.min_allowed, ba.min_desired, ba.comment,";
973 $sql .=
" ba.datec as date_creation, ba.tms as date_update, ba.ics, ba.ics_transfer,";
974 $sql .=
' c.code as country_code, c.label as country,';
975 $sql .=
' d.code_departement as state_code, d.nom as state';
976 $sql .=
' , aj.code as accountancy_journal';
977 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
978 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON ba.fk_pays = c.rowid';
979 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON ba.state_id = d.rowid';
980 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
981 $sql .=
" WHERE ba.entity IN (".getEntity($this->element).
")";
983 $sql .=
" AND ba.rowid = ".((int) $id);
986 $sql .=
" AND ba.ref = '".$this->db->escape($ref).
"'";
989 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
990 $result = $this->
db->query($sql);
992 if ($this->
db->num_rows($result)) {
993 $obj = $this->
db->fetch_object($result);
995 $this->
id = $obj->rowid;
996 $this->
rowid = $obj->rowid;
997 $this->
ref = $obj->ref;
998 $this->label = $obj->label;
999 $this->
type = $obj->courant;
1000 $this->courant = $obj->courant;
1001 $this->bank = $obj->bank;
1002 $this->clos = $obj->clos;
1003 $this->rappro = $obj->rappro;
1004 $this->url = $obj->url;
1006 $this->code_banque = $obj->code_banque;
1007 $this->code_guichet = $obj->code_guichet;
1008 $this->number = $obj->number;
1009 $this->cle_rib = $obj->cle_rib;
1010 $this->bic = $obj->bic;
1011 $this->iban = $obj->iban;
1012 $this->domiciliation = $obj->domiciliation;
1013 $this->pti_in_ctti = $obj->pti_in_ctti;
1014 $this->proprio = $obj->proprio;
1015 $this->owner_address = $obj->owner_address;
1017 $this->state_id = $obj->state_id;
1018 $this->state_code = $obj->state_code;
1019 $this->state = $obj->state;
1021 $this->country_id = $obj->country_id;
1022 $this->country_code = $obj->country_code;
1023 $this->country = $obj->country;
1025 $this->account_number = $obj->account_number;
1026 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1027 $this->accountancy_journal = $obj->accountancy_journal;
1029 $this->currency_code = $obj->currency_code;
1030 $this->account_currency_code = $obj->currency_code;
1031 $this->min_allowed = $obj->min_allowed;
1032 $this->min_desired = $obj->min_desired;
1033 $this->comment = $obj->comment;
1035 $this->date_creation = $this->
db->jdate($obj->date_creation);
1036 $this->date_update = $this->
db->jdate($obj->date_update);
1038 $this->ics = $obj->ics;
1039 $this->ics_transfer = $obj->ics_transfer;
1050 $this->
error = $this->
db->lasterror;
1051 $this->errors[] = $this->error;
1068 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1069 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1078 public function delete(
User $user =
null)
1086 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
1087 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1092 $this->
error =
"Error ".$this->db->lasterror();
1097 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1098 $sql .=
" WHERE rowid = ".((int) $this->
id);
1100 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1101 $result = $this->
db->query($sql);
1108 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1113 $this->
error =
"Error ".$this->db->lasterror();
1118 $this->
db->commit();
1121 $this->
db->rollback();
1135 return $this->
LibStatut($this->clos, $mode);
1150 $langs->load(
'banks');
1152 if ($status == self::STATUS_OPEN) {
1153 $label = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1154 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountOpened");
1155 $statusType =
'status4';
1157 $label = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1158 $labelshort = $langs->transnoentitiesnoconv(
"StatusAccountClosed");
1159 $statusType =
'status5';
1162 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1175 $can_be_deleted =
false;
1177 $sql =
"SELECT COUNT(rowid) as nb";
1178 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1179 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1183 $obj = $this->
db->fetch_object(
$resql);
1184 if ($obj->nb <= 1) {
1185 $can_be_deleted =
true;
1190 return $can_be_deleted;
1201 return $this->error;
1212 public function solde($option = 0, $date_end =
'', $field =
'dateo')
1216 $sql =
"SELECT sum(amount) as amount";
1217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank";
1218 $sql .=
" WHERE fk_account = ".((int) $this->
id);
1220 $sql .=
" AND ".$this->db->escape($field).
" <= '".(!empty($date_end) ? $this->
db->idate($date_end) : $this->
db->idate(
dol_now())).
"'";
1226 $obj = $this->
db->fetch_object(
$resql);
1227 $solde = $obj->amount;
1231 $this->errors[] = $this->
db->lasterror;
1249 global $conf, $langs;
1255 $sql =
"SELECT b.rowid, b.datev as datefin";
1256 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1257 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1258 $sql .=
" WHERE b.rappro=0";
1259 $sql .=
" AND b.fk_account = ba.rowid";
1260 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1261 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1262 $sql .=
" AND clos = 0";
1263 if ($filteraccountid) {
1264 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1269 $langs->load(
"banks");
1272 require_once DOL_DOCUMENT_ROOT.
'/core/class/workboardresponse.class.php';
1275 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1276 $response->label = $langs->trans(
"TransactionsToConciliate");
1277 $response->labelShort = $langs->trans(
"TransactionsToConciliateShort");
1278 $response->url = DOL_URL_ROOT.
'/compta/bank/list.php?leftmenu=bank&mainmenu=bank';
1281 while ($obj = $this->
db->fetch_object(
$resql)) {
1282 $response->nbtodo++;
1283 if ($this->
db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1284 $response->nbtodolate++;
1291 $this->
error = $this->
db->error();
1311 $sql =
"SELECT count(b.rowid) as nb";
1312 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1313 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1314 $sql .=
" WHERE b.fk_account = ba.rowid";
1315 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1316 $sql .=
" AND (ba.rappro = 1 AND ba.courant != 2)";
1317 $sql .=
" AND clos = 0";
1318 if ($filteraccountid) {
1319 $sql .=
" AND ba.rowid = ".((int) $filteraccountid);
1324 while ($obj = $this->
db->fetch_object(
$resql)) {
1325 $this->nb[
"banklines"] = $obj->nb;
1330 $this->
error = $this->
db->error();
1343 global $db, $conf, $user;
1352 $sql =
"SELECT COUNT(ba.rowid) as nb";
1353 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_account as ba";
1354 $sql .=
" WHERE ba.rappro > 0 and ba.clos = 0";
1355 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1356 if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) {
1357 $sql .=
" AND ba.courant != 2";
1361 $obj = $this->
db->fetch_object(
$resql);
1380 public function getNomUrl($withpicto = 0, $mode =
'', $option =
'', $save_lastsearch_value = -1, $notooltip = 0)
1382 global $conf, $langs, $user;
1383 include_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1386 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightnow">'.$langs->trans(
"BankAccount").
'</u>';
1387 if (isset($this->status)) {
1388 $label .=
' '.$this->getLibStatut(5);
1390 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
1391 $label .=
'<br><b>'.$langs->trans(
'AccountNumber').
':</b> '.$this->number;
1393 $label .=
'<br><b>'.$langs->trans(
'BIC').
':</b> '.$this->bic;
1394 $label .=
'<br><b>'.$langs->trans(
"AccountCurrency").
':</b> '.$this->currency_code;
1396 if (empty($user->rights->banque->lire) || !empty($user->socid)) {
1401 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1402 $langs->load(
"accountancy");
1403 $label .=
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
1404 $label .=
'<br><b>'.$langs->trans(
'AccountancyJournal').
':</b> '.$this->accountancy_journal;
1407 $linkclose =
'" title="'.dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
1409 $url = DOL_URL_ROOT.
'/compta/bank/card.php?id='.$this->id;
1410 if ($mode ==
'transactions') {
1411 $url = DOL_URL_ROOT.
'/compta/bank/bankentries_list.php?id='.$this->id;
1412 } elseif ($mode ==
'receipts') {
1413 $url = DOL_URL_ROOT.
'/compta/bank/releve.php?account='.$this->id;
1416 if ($option !=
'nolink') {
1418 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1419 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1420 $add_save_lastsearch_values = 1;
1422 if ($add_save_lastsearch_values) {
1423 $url .=
'&save_lastsearch_values=1';
1427 $linkstart =
'<a href="'.$url.$linkclose;
1430 if ($option ==
'nolink') {
1435 $result .= $linkstart;
1437 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1439 if ($withpicto != 2) {
1440 $result .= $this->
ref.($option ==
'reflabel' && $this->label ?
' - '.$this->label :
'');
1442 $result .= $linkend;
1458 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1460 $this->error_number = 0;
1465 $this->error_number = 12;
1466 $this->error_message =
'IBANNotValid';
1469 $this->error_number = 12;
1470 $this->error_message =
'SwiftNotValid';
1478 if ($this->error_number == 0) {
1495 if (!empty($this->country_code)) {
1496 return $this->country_code;
1500 if (!empty($this->iban)) {
1503 if (preg_match(
"/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1509 if (!empty($this->socid)) {
1510 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1512 $result = $company->fetch($this->socid);
1513 if (!empty($company->country_code)) {
1514 return $company->country_code;
1519 if (!empty($mysoc->country_code)) {
1520 return $mysoc->country_code;
1538 if (in_array($country_code, array(
'FR',
'ES',
'GA',
'IT',
'NC'))) {
1541 if (in_array($country_code, array(
'AD',
'AU',
'BE',
'CA',
'DE',
'DK',
'GR',
'GB',
'ID',
'IE',
'IR',
'KR',
'NL',
'NZ',
'UK',
'US'))) {
1556 if (!empty($conf->global->MAIN_IBAN_IS_NEVER_MANDATORY)) {
1562 $country_code_in_EEC = array(
1598 if (in_array($country_code, $country_code_in_EEC)) {
1633 if ($detailedBBAN == 0) {
1634 $fieldarray = array(
1637 } elseif ($detailedBBAN == 2) {
1638 $fieldarray = array(
1647 if ($includeibanbic) {
1648 $fieldarray[] =
'IBAN';
1649 $fieldarray[] =
'BIC';
1671 $fieldlists = array(
1674 'BankAccountNumber',
1675 'BankAccountNumberKey'
1678 if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {
1679 if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1680 if ($conf->global->BANK_SHOW_ORDER_OPTION ==
'1') {
1681 $fieldlists = array(
1684 'BankAccountNumberKey',
1690 $fieldlists = explode(
1692 preg_replace(
'/ ?[^Bank]AccountNumber ?/',
'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1711 $this->specimen = 1;
1713 $this->label =
'My Big Company Bank account';
1714 $this->bank =
'MyBank';
1716 $this->clos = Account::STATUS_OPEN;
1717 $this->code_banque =
'30001';
1718 $this->code_guichet =
'00794';
1719 $this->number =
'12345678901';
1720 $this->cle_rib =
'85';
1721 $this->bic =
'AA12';
1722 $this->iban =
'FR7630001007941234567890185';
1723 $this->domiciliation =
'Banque de France';
1724 $this->proprio =
'Owner';
1725 $this->owner_address =
'Owner address';
1726 $this->country_id = 1;
1739 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_url SET url_id = ".((int) $dest_id).
" WHERE url_id = ".((int) $origin_id).
" AND type='company'";
1741 if ($dbs->query($sql)) {
1770 public $element =
'bank';
1775 public $table_element =
'bank';
1780 public $picto =
'accountline';
1814 public $amount_main_currency;
1819 public $fk_user_author;
1824 public $fk_user_rappro;
1834 public $fk_bordereau;
1844 public $bank_account_ref;
1849 public $bank_account_label;
1854 public $numero_compte;
1893 public function fetch($rowid, $ref =
'', $num =
'')
1898 if (empty($rowid) && empty($ref) && empty($num)) {
1902 $sql =
"SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
1903 $sql .=
" b.fk_user_author, b.fk_user_rappro,";
1904 $sql .=
" b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
1905 $sql .=
" b.fk_bordereau, b.banque, b.emetteur,";
1907 $sql .=
" ba.ref as bank_account_ref, ba.label as bank_account_label";
1908 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b,";
1909 $sql .=
" ".MAIN_DB_PREFIX.
"bank_account as ba";
1910 $sql .=
" WHERE b.fk_account = ba.rowid";
1911 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
1913 $sql .=
" AND b.num_chq='".$this->db->escape($num).
"'";
1915 $sql .=
" AND b.rowid='".$this->db->escape($ref).
"'";
1917 $sql .=
" AND b.rowid = ".((int) $rowid);
1920 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1921 $result = $this->
db->query($sql);
1925 $obj = $this->
db->fetch_object($result);
1927 $this->
id = $obj->rowid;
1928 $this->
rowid = $obj->rowid;
1929 $this->
ref = $obj->rowid;
1931 $this->datec = $obj->datec;
1932 $this->datev = $obj->datev;
1933 $this->dateo = $obj->dateo;
1934 $this->amount = $obj->amount;
1935 $this->label = $obj->label;
1936 $this->note = $obj->note;
1938 $this->fk_user_author = $obj->fk_user_author;
1939 $this->fk_user_rappro = $obj->fk_user_rappro;
1941 $this->fk_type = $obj->fk_type;
1942 $this->rappro = $obj->rappro;
1943 $this->num_releve = $obj->num_releve;
1945 $this->num_chq = $obj->num_chq;
1946 $this->bank_chq = $obj->banque;
1947 $this->fk_bordereau = $obj->fk_bordereau;
1949 $this->fk_account = $obj->fk_account;
1950 $this->bank_account_ref = $obj->bank_account_ref;
1951 $this->bank_account_label = $obj->bank_account_label;
1959 $this->
db->free($result);
1977 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank (";
1983 $sql .=
", amount_main_currency";
1984 $sql .=
", fk_user_author";
1985 $sql .=
", num_chq";
1986 $sql .=
", fk_account";
1987 $sql .=
", fk_type";
1988 $sql .=
", emetteur,banque";
1990 $sql .=
", numero_compte";
1991 $sql .=
", num_releve";
1992 $sql .=
") VALUES (";
1993 $sql .=
"'".$this->db->idate($this->datec).
"'";
1994 $sql .=
", '".$this->db->idate($this->dateo).
"'";
1995 $sql .=
", '".$this->db->idate($this->datev).
"'";
1996 $sql .=
", '".$this->db->escape($this->label).
"'";
1997 $sql .=
", ".price2num($this->amount);
1998 $sql .=
", ".(empty($this->amount_main_currency) ?
"NULL" :
price2num($this->amount_main_currency));
1999 $sql .=
", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) :
"null");
2000 $sql .=
", ".($this->num_chq ?
"'".$this->db->escape($this->num_chq).
"'" :
"null");
2001 $sql .=
", '".$this->db->escape($this->fk_account).
"'";
2002 $sql .=
", '".$this->db->escape($this->fk_type).
"'";
2003 $sql .=
", ".($this->emetteur ?
"'".$this->db->escape($this->emetteur).
"'" :
"null");
2004 $sql .=
", ".($this->bank_chq ?
"'".$this->db->escape($this->bank_chq).
"'" :
"null");
2005 $sql .=
", ".(int) $this->rappro;
2006 $sql .=
", ".($this->numero_compte ?
"'".$this->db->escape($this->numero_compte).
"'" :
"''");
2007 $sql .=
", ".($this->num_releve ?
"'".$this->db->escape($this->num_releve).
"'" :
"null");
2010 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
2013 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'bank');
2021 $this->error = $this->
db->lasterror();
2026 $this->
db->commit();
2029 $this->
db->rollback();
2040 public function delete(
User $user =
null)
2046 if ($this->rappro) {
2048 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2055 if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING)) {
2056 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2059 $obj = $this->
db->fetch_object(
$resql);
2060 if ($obj && $obj->nb) {
2061 $this->error =
'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2062 $this->
db->rollback();
2066 $this->error = $this->
db->lasterror();
2067 $this->
db->rollback();
2078 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class WHERE lineid=".(int) $this->
rowid;
2079 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2080 $result = $this->
db->query($sql);
2085 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_extrafields WHERE fk_object=".(int) $this->
rowid;
2086 $result = $this->
db->query($sql);
2091 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid=".(int) $this->
rowid;
2092 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2093 $result = $this->
db->query($sql);
2099 $this->
db->commit();
2102 $this->
db->rollback();
2120 if ($this->rappro) {
2122 $this->error =
"ErrorDeleteNotPossibleLineIsConsolidated";
2128 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url WHERE fk_bank=".(int) $this->
rowid;
2129 dol_syslog(get_class($this).
"::delete_urls", LOG_DEBUG);
2130 $result = $this->
db->query($sql);
2136 $this->
db->commit();
2139 $this->
db->rollback();
2156 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2157 $sql .=
" amount = ".price2num($this->amount).
",";
2158 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
2159 $sql .=
" dateo='".$this->db->idate($this->dateo).
"'";
2160 $sql .=
" WHERE rowid = ".((int) $this->
rowid);
2162 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2165 $this->
db->commit();
2168 $this->
db->rollback();
2169 $this->error = $this->
db->error();
2187 global $conf, $langs;
2192 if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE)) {
2193 if (!preg_match(
'/'.$conf->global->BANK_STATEMENT_REGEX_RULE.
'/', $this->num_releve)) {
2194 $this->errors[] = $langs->trans(
"ErrorBankStatementNameMustFollowRegex", $conf->global->BANK_STATEMENT_REGEX_RULE);
2199 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2200 $sql .=
" rappro = ".((int) $conciliated);
2201 $sql .=
", num_releve = '".$this->db->escape($this->num_releve).
"'";
2203 $sql .=
", fk_user_rappro = ".$user->id;
2205 $sql .=
" WHERE rowid = ".((int) $this->
id);
2207 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2211 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_class (";
2213 $sql .=
", fk_categ";
2214 $sql .=
") VALUES (";
2216 $sql .=
", ".((int) $cat);
2219 dol_syslog(get_class($this).
"::update_conciliation", LOG_DEBUG);
2220 $this->
db->query($sql);
2227 $this->
db->commit();
2230 $this->
db->rollback();
2247 $sql =
"SELECT datev FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2250 $obj = $this->
db->fetch_object(
$resql);
2251 $newdate = $this->
db->jdate($obj->datev) + (3600 * 24 * $sign);
2253 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2254 $sql .=
" datev = '".$this->db->idate($newdate).
"'";
2255 $sql .=
" WHERE rowid = ".((int) $rowid);
2257 $result = $this->
db->query($sql);
2259 if ($this->
db->affected_rows($result)) {
2310 $sql =
"SELECT dateo FROM ".MAIN_DB_PREFIX.
"bank WHERE rowid = ".((int) $rowid);
2313 $obj = $this->
db->fetch_object(
$resql);
2314 $newdate = $this->
db->jdate($obj->dateo) + (3600 * 24 * $sign);
2316 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank SET";
2317 $sql .=
" dateo = '".$this->db->idate($newdate).
"'";
2318 $sql .=
" WHERE rowid = ".((int) $rowid);
2320 $result = $this->
db->query($sql);
2322 if ($this->
db->affected_rows($result)) {
2370 $sql =
'SELECT b.rowid, b.datec, b.tms as datem,';
2371 $sql .=
' b.fk_user_author, b.fk_user_rappro';
2372 $sql .=
' FROM '.MAIN_DB_PREFIX.
'bank as b';
2373 $sql .=
' WHERE b.rowid = '.((int) $id);
2375 $result = $this->
db->query($sql);
2377 if ($this->
db->num_rows($result)) {
2378 $obj = $this->
db->fetch_object($result);
2379 $this->
id = $obj->rowid;
2381 if ($obj->fk_user_author) {
2382 $cuser =
new User($this->
db);
2383 $cuser->fetch($obj->fk_user_author);
2384 $this->user_creation = $cuser;
2386 if ($obj->fk_user_rappro) {
2387 $ruser =
new User($this->
db);
2388 $ruser->fetch($obj->fk_user_rappro);
2389 $this->user_rappro = $ruser;
2392 $this->date_creation = $this->
db->jdate($obj->datec);
2393 $this->date_modification = $this->
db->jdate($obj->datem);
2396 $this->
db->free($result);
2412 public function getNomUrl($withpicto = 0, $maxlen = 0, $option =
'', $notooltip = 0)
2418 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"BankTransactionLine").
'</u>:<br>';
2419 $label .=
'<b>'.$langs->trans(
"Ref").
':</b> '.$this->ref;
2421 $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">';
2424 $result .= $linkstart;
2426 $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);
2428 if ($withpicto != 2) {
2429 $result .= ($this->
ref ? $this->
ref : $this->id);
2431 $result .= $linkend;
2433 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2434 $result .=
' <span class="opacitymedium">(';
2436 if ($option ==
'showall') {
2437 $result .= $langs->trans(
"BankAccount").
': ';
2438 $accountstatic =
new Account($this->
db);
2439 $accountstatic->id = $this->fk_account;
2440 $accountstatic->ref = $this->bank_account_ref;
2441 $accountstatic->label = $this->bank_account_label;
2442 $result .= $accountstatic->getNomUrl(0).
', ';
2444 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2445 $result .= $langs->trans(
"BankLineConciliated").
': ';
2446 $result .=
yn($this->rappro);
2448 if ($option ==
'showall' || $option ==
'showconciliatedandaccounted') {
2449 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->
id);
2452 $obj = $this->
db->fetch_object(
$resql);
2453 if ($obj && $obj->nb) {
2454 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(1);
2456 $result .=
' - '.$langs->trans(
"Accounted").
': '.
yn(0);
2460 if ($option ==
'showall' || $option ==
'showconciliated' || $option ==
'showconciliatedandaccounted') {
2461 $result .=
')</span>';
2476 return $this->
LibStatut($this->status, $mode);
2533 $alreadydispatched = 0;
2537 $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);
2540 $obj = $this->
db->fetch_object(
$resql);
2542 $alreadydispatched = $obj->nb;
2545 $this->error = $this->
db->lasterror();
2549 if ($alreadydispatched) {