dolibarr 25.0.0-alpha
account.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
6 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2015-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
10 * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
11 * Copyright (C) 2019 JC Prieto <jcprieto@virtual20.com><prietojc@gmail.com>
12 * Copyright (C) 2022-2026 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
14 * Copyright (C) 2026 Sylvain Legrand <contact@infras.fr>
15 * Copyright (C) 2026 Lucky Ranasolonirina <technique@infras.fr>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 */
30
37require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
38
39
43class Account extends CommonObject
44{
48 public $element = 'bank_account';
49
53 public $table_element = 'bank_account';
54
58 public $picto = 'account';
59
65 public $ref;
66
72 public $rowid;
73
78 public $label;
79
86 public $courant;
87
92 public $type;
93
98 public $bank;
99
107 public $clos = self::STATUS_OPEN;
108
113 public $rappro = 1;
114
119 public $url;
120
125 public $socid;
126
131 public $code_banque;
132
137 public $code_guichet;
138
143 public $number;
144
149 public $cle_rib;
150
155 public $bic;
156
161 public $iban;
162
169 public $iban_prefix;
170
175 public $pti_in_ctti = 0;
176
182 public $sepa_category_purpose = 'CORE';
183
189 public $sepa_local_instrument = 'CORE';
190
197 public $proprio;
198
203 public $owner_name;
204
209 public $owner_address;
210
215 public $owner_zip;
216
221 public $owner_town;
225 public $owner_country_id;
229 public $owner_country_code;
230
237 public $domiciliation;
238
243 public $address;
247 public $state_id;
251 public $state_code;
255 public $state;
259 public $country_id;
260
266 public $type_lib = array();
267
272 public $account_number;
273
277 public $fk_accountancy_journal;
278
282 public $accountancy_journal;
283
288 public $currency_code;
289
296 public $account_currency_code;
297
302 public $min_allowed;
303
308 public $min_desired;
309
314 public $comment;
315
320 public $date_solde;
321
328 public $solde;
329
334 public $balance;
335
340 public $ics;
341
346 public $ics_transfer;
347
351 public $oldref;
352
353
378 // BEGIN MODULEBUILDER PROPERTIES
382 public $fields = array(
383 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
384 'ref' => array('type' => 'varchar(12)', 'label' => 'Ref', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'showoncombobox' => 1, 'position' => 25),
385 'label' => array('type' => 'varchar(30)', 'label' => 'Label', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 30),
386 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 35, 'index' => 1),
387 'bank' => array('type' => 'varchar(60)', 'label' => 'Bank', 'enabled' => 1, 'visible' => -1, 'position' => 40),
388 'code_banque' => array('type' => 'varchar(128)', 'label' => 'Code banque', 'enabled' => 1, 'visible' => -1, 'position' => 45),
389 'code_guichet' => array('type' => 'varchar(6)', 'label' => 'Code guichet', 'enabled' => 1, 'visible' => -1, 'position' => 50),
390 'number' => array('type' => 'varchar(255)', 'label' => 'Number', 'enabled' => 1, 'visible' => -1, 'position' => 55),
391 'cle_rib' => array('type' => 'varchar(5)', 'label' => 'Cle rib', 'enabled' => 1, 'visible' => -1, 'position' => 60),
392 'bic' => array('type' => 'varchar(11)', 'label' => 'Bic', 'enabled' => 1, 'visible' => -1, 'position' => 65),
393 'iban_prefix' => array('type' => 'varchar(34)', 'label' => 'Iban prefix', 'enabled' => 1, 'visible' => -1, 'position' => 70),
394 'country_iban' => array('type' => 'varchar(2)', 'label' => 'Country iban', 'enabled' => 1, 'visible' => -1, 'position' => 75),
395 'cle_iban' => array('type' => 'varchar(2)', 'label' => 'Cle iban', 'enabled' => 1, 'visible' => -1, 'position' => 80),
396 'domiciliation' => array('type' => 'varchar(255)', 'label' => 'Domiciliation', 'enabled' => 1, 'visible' => -1, 'position' => 85),
397 'state_id' => array('type' => 'integer', 'label' => 'StateId', 'enabled' => 1, 'visible' => -1, 'position' => 90),
398 'fk_pays' => array('type' => 'integer', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 95),
399 'proprio' => array('type' => 'varchar(60)', 'label' => 'Proprio', 'enabled' => 1, 'visible' => -1, 'position' => 100),
400 'owner_address' => array('type' => 'varchar(255)', 'label' => 'Owner address', 'enabled' => 1, 'visible' => -1, 'position' => 105),
401 'owner_zip' => array('type' => 'varchar(25)', 'label' => 'Owner zip', 'enabled' => 1, 'visible' => -1, 'position' => 106),
402 'owner_town' => array('type' => 'varchar(50)', 'label' => 'Owner town', 'enabled' => 1, 'visible' => -1, 'position' => 107),
403 'owner_country_id' => array('type' => 'integer', 'label' => 'Owner country', 'enabled' => 1, 'visible' => -1, 'position' => 108),
404 'courant' => array('type' => 'smallint(6)', 'label' => 'Courant', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 110),
405 'clos' => array('type' => 'smallint(6)', 'label' => 'Clos', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 115),
406 'rappro' => array('type' => 'smallint(6)', 'label' => 'Rappro', 'enabled' => 1, 'visible' => -1, 'position' => 120),
407 'url' => array('type' => 'varchar(128)', 'label' => 'Url', 'enabled' => 1, 'visible' => -1, 'position' => 125),
408 'account_number' => array('type' => 'varchar(32)', 'label' => 'Account number', 'enabled' => 1, 'visible' => -1, 'position' => 130),
409 'fk_accountancy_journal' => array('type' => 'integer', 'label' => 'Accountancy journal ID', 'enabled' => 1, 'visible' => -1, 'position' => 132),
410 'accountancy_journal' => array('type' => 'varchar(20)', 'label' => 'Accountancy journal', 'enabled' => 1, 'visible' => -1, 'position' => 135),
411 'currency_code' => array('type' => 'varchar(3)', 'label' => 'Currency code', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 140),
412 'min_allowed' => array('type' => 'integer', 'label' => 'Min allowed', 'enabled' => 1, 'visible' => -1, 'position' => 145),
413 'min_desired' => array('type' => 'integer', 'label' => 'Min desired', 'enabled' => 1, 'visible' => -1, 'position' => 150),
414 'comment' => array('type' => 'text', 'label' => 'Comment', 'enabled' => 1, 'visible' => -1, 'position' => 155),
415 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 156),
416 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 157),
417 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -1, 'position' => 160),
418 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 165),
419 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 170),
420 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 175),
421 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 180),
422 'extraparams' => array('type' => 'varchar(255)', 'label' => 'Extraparams', 'enabled' => 1, 'visible' => -1, 'position' => 185),
423 );
424 // END MODULEBUILDER PROPERTIES
425
429 const TYPE_CURRENT = 1;
433 const TYPE_CASH = 2;
437 const TYPE_SAVINGS = 0;
438
439
440 const STATUS_OPEN = 0;
441 const STATUS_CLOSED = 1;
442
447 const SEPA_CATEGORY_PURPOSES = array('CORE', 'CORT', 'CASH', 'INST', 'SUPP', 'TREA');
448
453 const SEPA_LOCAL_INSTRUMENTS = array('CORE', 'INST');
454
455
461 public function __construct(DoliDB $db)
462 {
463 global $langs;
464
465 $this->db = $db;
466
467 $this->ismultientitymanaged = 1;
468
469 $this->balance = 0;
470
471 // $langs may be null when called from a page with NOREQUIRETRAN (like viewimage.php)
472 if (is_object($langs)) {
473 $this->type_lib = array(
474 self::TYPE_SAVINGS => $langs->transnoentitiesnoconv("BankType0"),
475 self::TYPE_CURRENT => $langs->transnoentitiesnoconv("BankType1"),
476 self::TYPE_CASH => $langs->transnoentitiesnoconv("BankType2"),
477 );
478
479 $this->labelStatus = array(
480 self::STATUS_OPEN => $langs->transnoentitiesnoconv("StatusAccountOpened"),
481 self::STATUS_CLOSED => $langs->transnoentitiesnoconv("StatusAccountClosed")
482 );
483 }
484 }
485
492 public function getSepaCategoryPurpose()
493 {
494 $code = strtoupper(trim((string) $this->sepa_category_purpose));
495 return (in_array($code, self::SEPA_CATEGORY_PURPOSES) ? $code : 'CORE');
496 }
497
504 public function getSepaLocalInstrument()
505 {
506 $code = strtoupper(trim((string) $this->sepa_local_instrument));
507 return (in_array($code, self::SEPA_LOCAL_INSTRUMENTS) ? $code : 'CORE');
508 }
509
515 public function __toString()
516 {
517 $string = '';
518 foreach ($this->getFieldsToShow() as $val) {
519 if ($val == 'BankCode') {
520 $string .= $this->code_banque.' ';
521 } elseif ($val == 'BankAccountNumber') {
522 $string .= $this->number.' ';
523 } elseif ($val == 'DeskCode') {
524 $string .= $this->code_guichet.' ';
525 } elseif ($val == 'BankAccountNumberKey') {
526 $string .= $this->cle_rib.' ';
527 } elseif ($val == 'BIC') {
528 $string .= $this->bic.' ';
529 } elseif ($val == 'IBAN') {
530 $string .= $this->iban.' ';
531 }
532 }
533
534 return trim($string);
535 }
536
537
543 public function canBeConciliated()
544 {
545 if (empty($this->rappro)) {
546 return -1;
547 }
548 if ($this->type == Account::TYPE_CASH && !getDolGlobalString('BANK_CAN_RECONCILIATE_CASHACCOUNT')) {
549 return -2;
550 }
551 if ($this->status) {
552 return -3;
553 }
554 return 1;
555 }
556
557
558 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
569 public function add_url_line($line_id, $url_id, $url, $label, $type)
570 {
571 // phpcs:enable
572 // Avoid uk_bank_url collision when the same target (line_id, url_id, type) is linked twice
573 // e.g. two distinct credit transfers for the same employee dispatched on the same bank line.
574 $sqlcheck = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank_url";
575 $sqlcheck .= " WHERE fk_bank = ".((int) $line_id);
576 $sqlcheck .= " AND url_id = ".((int) $url_id);
577 $sqlcheck .= " AND type = '".$this->db->escape($type)."'";
578 $resqlcheck = $this->db->query($sqlcheck);
579 if ($resqlcheck) {
580 $obj = $this->db->fetch_object($resqlcheck);
581 if ($obj) {
582 $this->db->free($resqlcheck);
583 return (int) $obj->rowid;
584 }
585 $this->db->free($resqlcheck);
586 }
587
588 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
589 $sql .= "fk_bank";
590 $sql .= ", url_id";
591 $sql .= ", url"; // deprecated
592 $sql .= ", label";
593 $sql .= ", type";
594 $sql .= ") VALUES (";
595 $sql .= ((int) $line_id);
596 $sql .= ", ".((int) $url_id);
597 $sql .= ", '".$this->db->escape($url)."'"; // deprecated
598 $sql .= ", '".$this->db->escape($label)."'";
599 $sql .= ", '".$this->db->escape($type)."'";
600 $sql .= ")";
601
602 dol_syslog(get_class($this)."::add_url_line", LOG_DEBUG);
603 if ($this->db->query($sql)) {
604 $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
605 return $rowid;
606 } else {
607 $this->error = $this->db->lasterror();
608 return -1;
609 }
610 }
611
612 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
622 public function get_url($fk_bank = 0, $url_id = 0, $type = '')
623 {
624 // phpcs:enable
625 $lines = array();
626
627 // Check parameters
628 if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) {
629 $this->error = "ErrorBadParameter";
630 return -1;
631 }
632
633 $sql = "SELECT fk_bank, url_id, url, label, type";
634 $sql .= " FROM ".MAIN_DB_PREFIX."bank_url";
635 if ($fk_bank > 0) {
636 $sql .= " WHERE fk_bank = ".((int) $fk_bank);
637 } else {
638 $sql .= " WHERE url_id = ".((int) $url_id)." AND type = '".$this->db->escape($type)."'";
639 }
640 $sql .= " ORDER BY type, label";
641
642 dol_syslog(get_class($this)."::get_url", LOG_DEBUG);
643 $result = $this->db->query($sql);
644 if ($result) {
645 $i = 0;
646 $num = $this->db->num_rows($result);
647 while ($i < $num) {
648 $obj = $this->db->fetch_object($result);
649 // Old links (for compatibility)
650 $lines[$i][0] = $obj->url;
651 $lines[$i][1] = $obj->url_id;
652 $lines[$i][2] = $obj->label;
653 $lines[$i][3] = $obj->type;
654 // New links
655 $lines[$i]['url'] = $obj->url;
656 $lines[$i]['url_id'] = $obj->url_id;
657 $lines[$i]['label'] = $obj->label;
658 $lines[$i]['type'] = $obj->type;
659 $lines[$i]['fk_bank'] = $obj->fk_bank;
660 $i++;
661 }
662 } else {
663 dol_print_error($this->db);
664 }
665
666 return $lines;
667 }
668
688 public function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur = '', $banque = '', $accountancycode = '', $datev = null, $num_releve = '', $amount_main_currency = null, $note_private = '')
689 {
690 global $langs;
691
692 // Deprecation warning
693 if (is_numeric($oper)) {
694 dol_syslog(__METHOD__.": using numeric operations is deprecated", LOG_WARNING);
695 }
696
697 if (empty($this->id) && !empty($this->rowid)) { // For backward compatibility
698 $this->id = $this->rowid;
699 }
700
701 // Clean parameters
702 $emetteur = trim($emetteur);
703 $banque = trim($banque);
704 $label = trim($label);
705
706 $now = dol_now();
707
708 if (is_numeric($oper)) { // Clean operation to have a code instead of a rowid
709 $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement";
710 $sql .= " WHERE id = ".((int) $oper);
711 $sql .= " AND entity IN (".getEntity('c_paiement').")";
712 $resql = $this->db->query($sql);
713 if ($resql) {
714 $obj = $this->db->fetch_object($resql);
715 $oper = $obj->code;
716 } else {
717 dol_print_error($this->db, 'Failed to get payment type code');
718 return -1;
719 }
720 }
721
722 // Check parameters
723 if (!$oper) {
724 $this->error = $langs->trans("OperNotDefined");
725 return -1;
726 }
727 if (!$this->id) {
728 $this->error = $langs->trans("ThisIdNotDefined");
729 return -2;
730 }
731 if ($this->type == Account::TYPE_CASH && $oper != 'LIQ') {
732 $this->error = "ErrorCashAccountAcceptsOnlyCashMoney";
733 return -3;
734 }
735
736 $this->db->begin();
737
738 if (is_null($datev) || empty($datev)) {
739 $datev = $date;
740 }
741
742 $accline = new AccountLine($this->db);
743 $accline->datec = $now;
744 $accline->dateo = $date;
745 $accline->datev = $datev;
746 $accline->label = $label;
747 $accline->amount = $amount;
748 $accline->amount_main_currency = $amount_main_currency;
749 $accline->fk_user_author = $user->id;
750 $accline->fk_account = $this->id;
751 $accline->fk_type = $oper;
752 $accline->numero_compte = $accountancycode;
753 $accline->num_releve = $num_releve;
754 $accline->note_private = $note_private;
755
756 if ($num_chq) {
757 $accline->num_chq = $num_chq;
758 }
759
760 if ($emetteur) {
761 $accline->emetteur = $emetteur;
762 }
763
764 if ($banque) {
765 $accline->bank_chq = $banque;
766 }
767
768 if ($accline->insert() > 0) {
769 if ($categorie > 0) {
770 $sql = "INSERT INTO ".MAIN_DB_PREFIX."category_bankline(";
771 $sql .= "lineid, fk_categ";
772 $sql .= ") VALUES (";
773 $sql .= ((int) $accline->id).", ".((int) $categorie);
774 $sql .= ")";
775
776 $result = $this->db->query($sql);
777 if (!$result) {
778 $this->error = $this->db->lasterror();
779 $this->db->rollback();
780
781 return -4;
782 }
783 }
784
785 $this->db->commit();
786
787 return $accline->id;
788 } else {
789 $this->setErrorsFromObject($accline);
790 $this->db->rollback();
791
792 return -5;
793 }
794 }
795
803 public function create($user, $notrigger = 0)
804 {
805 global $langs, $conf;
806
807 $error = 0;
808
809 // Clean parameters
810 if (!$this->min_allowed) {
811 $this->min_allowed = 0;
812 }
813 if (!$this->min_desired) {
814 $this->min_desired = 0;
815 }
816
817 // Check parameters
818 if (empty($this->country_id)) {
819 $langs->load('errors');
820 $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Country"));
821 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
822 return -1;
823 }
824 if (empty($this->ref)) {
825 $langs->load('errors');
826 $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref"));
827 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
828 return -1;
829 }
830 if (empty($this->date_solde)) {
831 $langs->load('errors');
832 $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateInitialBalance"));
833 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
834 return -1;
835 }
836
837 // Load libraries to check BAN
838 $balance = $this->balance;
839 if (empty($balance) && !empty($this->solde)) {
840 dol_syslog(get_class($this)."::create solde is deprecated use balance", LOG_NOTICE);
841 $balance = $this->solde;
842 }
843 if (empty($balance)) {
844 $balance = 0;
845 }
846 if (empty($this->status && !empty($this->clos))) {
847 dol_syslog(get_class($this)."::create clos is deprecated use status", LOG_NOTICE);
848 $this->status = $this->clos;
849 }
850
851 if (empty($this->country_id) && !empty($this->country_code)) {
852 $country_id = getCountry($this->country_code, '3');
853 $this->country_id = is_int($country_id) ? $country_id : 0;
854 }
855
856 // Load the library to validate/check a BAN account
857 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
858
859 $now = dol_now();
860
861 $this->db->begin();
862
863 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (";
864 $sql .= "datec";
865 $sql .= ", ref";
866 $sql .= ", label";
867 $sql .= ", entity";
868 $sql .= ", account_number";
869 $sql .= ", fk_accountancy_journal";
870 $sql .= ", bank";
871 $sql .= ", code_banque";
872 $sql .= ", code_guichet";
873 $sql .= ", number";
874 $sql .= ", cle_rib";
875 $sql .= ", bic";
876 $sql .= ", iban_prefix";
877 $sql .= ", domiciliation";
878 $sql .= ", pti_in_ctti";
879 $sql .= ", sepa_category_purpose";
880 $sql .= ", sepa_local_instrument";
881 $sql .= ", proprio";
882 $sql .= ", owner_address";
883 $sql .= ", owner_zip";
884 $sql .= ", owner_town";
885 $sql .= ", owner_country_id";
886 $sql .= ", currency_code";
887 $sql .= ", rappro";
888 $sql .= ", min_allowed";
889 $sql .= ", min_desired";
890 $sql .= ", comment";
891 $sql .= ", state_id";
892 $sql .= ", fk_pays";
893 $sql .= ", ics";
894 $sql .= ", ics_transfer";
895 $sql .= ") VALUES (";
896 $sql .= "'".$this->db->idate($now)."'";
897 $sql .= ", '".$this->db->escape($this->ref)."'";
898 $sql .= ", '".$this->db->escape($this->label)."'";
899 $sql .= ", ".((int) $conf->entity);
900 $sql .= ", '".$this->db->escape($this->account_number)."'";
901 $sql .= ", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) : "null");
902 $sql .= ", '".$this->db->escape($this->bank)."'";
903 $sql .= ", '".$this->db->escape($this->code_banque)."'";
904 $sql .= ", '".$this->db->escape($this->code_guichet)."'";
905 $sql .= ", '".$this->db->escape($this->number)."'";
906 $sql .= ", '".$this->db->escape($this->cle_rib)."'";
907 $sql .= ", '".$this->db->escape($this->bic)."'";
908 $sql .= ", '".$this->db->escape($this->iban)."'";
909 $sql .= ", '".$this->db->escape($this->address)."'";
910 $sql .= ", ".((int) $this->pti_in_ctti);
911 $sql .= ", '".$this->db->escape($this->getSepaCategoryPurpose())."'";
912 $sql .= ", '".$this->db->escape($this->getSepaLocalInstrument())."'";
913 $sql .= ", '".$this->db->escape($this->owner_name)."'";
914 $sql .= ", '".$this->db->escape($this->owner_address)."'";
915 $sql .= ", '".$this->db->escape($this->owner_zip)."'";
916 $sql .= ", '".$this->db->escape($this->owner_town)."'";
917 $sql .= ", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) : "null");
918 $sql .= ", '".$this->db->escape($this->currency_code)."'";
919 $sql .= ", ".((int) $this->rappro);
920 $sql .= ", ".price2num($this->min_allowed, 'MT');
921 $sql .= ", ".price2num($this->min_desired, 'MT');
922 $sql .= ", '".$this->db->escape($this->comment)."'";
923 $sql .= ", ".($this->state_id > 0 ? ((int) $this->state_id) : "null");
924 $sql .= ", ".($this->country_id > 0 ? ((int) $this->country_id) : "null");
925 $sql .= ", '".$this->db->escape($this->ics)."'";
926 $sql .= ", '".$this->db->escape($this->ics_transfer)."'";
927 $sql .= ")";
928
929 dol_syslog(get_class($this)."::create", LOG_DEBUG);
930 $resql = $this->db->query($sql);
931 if ($resql) {
932 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
933
934 $result = $this->update($user, 1);
935 if ($result > 0) {
936 $accline = new AccountLine($this->db);
937 $accline->datec = $now;
938 $accline->label = '('.$langs->trans("InitialBankBalance").')';
939 $accline->amount = (float) price2num($balance);
940 $accline->fk_user_author = $user->id;
941 $accline->fk_account = $this->id;
942 $accline->datev = $this->date_solde;
943 $accline->dateo = $this->date_solde;
944 $accline->fk_type = 'SOLD';
945
946 if ($accline->insert() < 0) {
947 $error++;
948 $this->setErrorsFromObject($accline);
949 }
950
951 if (!$error) {
952 $result = $this->insertExtraFields();
953 if ($result < 0) {
954 $error++;
955 }
956 }
957
958 if (!$error && !$notrigger) {
959 // Call trigger
960 $result = $this->call_trigger('BANKACCOUNT_CREATE', $user);
961 if ($result < 0) {
962 $error++;
963 }
964 // End call triggers
965 }
966 } else {
967 $error++;
968 }
969 } else {
970 if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
971 $this->error = $langs->trans("ErrorBankLabelAlreadyExists");
972 $error++;
973 } else {
974 $this->error = $this->db->error()." sql=".$sql;
975 $error++;
976 }
977 }
978
979 if (!$error) {
980 $this->db->commit();
981 return $this->id;
982 } else {
983 $this->db->rollback();
984 return -1 * $error;
985 }
986 }
987
995 public function update($user, $notrigger = 0)
996 {
997 global $langs, $conf;
998
999 if (empty($this->country_id) && !empty($this->country_code)) {
1000 $country_id = getCountry($this->country_code, '3');
1001 $this->country_id = is_int($country_id) ? $country_id : 0;
1002 }
1003
1004 $error = 0;
1005
1006 $this->db->begin();
1007
1008 // Check parameters
1009 if (empty($this->country_id)) {
1010 $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Country"));
1011 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1012 return -1;
1013 }
1014 if (empty($this->ref)) {
1015 $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref"));
1016 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1017 return -1;
1018 }
1019 if (!$this->label) {
1020 $this->label = "???";
1021 }
1022
1023 $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET";
1024 $sql .= " ref = '".$this->db->escape($this->ref)."'";
1025 $sql .= ",label = '".$this->db->escape($this->label)."'";
1026 $sql .= ",courant = ".((int) $this->type);
1027 $sql .= ",clos = ".((int) $this->status);
1028 $sql .= ",rappro = ".((int) $this->rappro);
1029 $sql .= ",url = ".($this->url ? "'".$this->db->escape($this->url)."'" : "null");
1030 $sql .= ",account_number = '".$this->db->escape($this->account_number)."'";
1031 $sql .= ",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) : "null");
1032 $sql .= ",bank = '".$this->db->escape($this->bank)."'";
1033 $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
1034 $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
1035 $sql .= ",number='".$this->db->escape($this->number)."'";
1036 $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
1037 $sql .= ",bic='".$this->db->escape($this->bic)."'";
1038 $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
1039 $sql .= ",domiciliation='".$this->db->escape($this->address)."'";
1040 $sql .= ",pti_in_ctti=".((int) $this->pti_in_ctti);
1041 $sql .= ",sepa_category_purpose = '".$this->db->escape($this->getSepaCategoryPurpose())."'";
1042 $sql .= ",sepa_local_instrument = '".$this->db->escape($this->getSepaLocalInstrument())."'";
1043 $sql .= ",proprio = '".$this->db->escape($this->owner_name)."'";
1044 $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
1045 $sql .= ",owner_zip = '".$this->db->escape($this->owner_zip)."'";
1046 $sql .= ",owner_town = '".$this->db->escape($this->owner_town)."'";
1047 $sql .= ",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) : "null");
1048
1049 $sql .= ",currency_code = '".$this->db->escape($this->currency_code)."'";
1050
1051 $sql .= ",min_allowed = ".($this->min_allowed != '' ? price2num($this->min_allowed) : "null");
1052 $sql .= ",min_desired = ".($this->min_desired != '' ? price2num($this->min_desired) : "null");
1053 $sql .= ",comment = '".$this->db->escape($this->comment)."'";
1054
1055 $sql .= ",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) : "null");
1056 $sql .= ",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) : "null");
1057 $sql .= ",ics = '".$this->db->escape($this->ics)."'";
1058 $sql .= ",ics_transfer = '".$this->db->escape($this->ics_transfer)."'";
1059
1060 $sql .= " WHERE rowid = ".((int) $this->id);
1061
1062 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1063 $result = $this->db->query($sql);
1064 if ($result) {
1065 // Actions on extra fields (by external module or standard code)
1066 if (!$error) {
1067 $result = $this->insertExtraFields();
1068 if ($result < 0) {
1069 $error++;
1070 }
1071 }
1072
1073 if (!$error && !empty($this->oldref) && $this->oldref !== $this->ref) {
1074 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'bank/".$this->db->escape($this->ref)."'";
1075 $sql .= " WHERE filepath = 'bank/".$this->db->escape($this->oldref)."' and src_object_type = 'bank_account' and entity = ".((int) $conf->entity);
1076 $resql = $this->db->query($sql);
1077 if (!$resql) {
1078 $error++;
1079 $this->error = $this->db->lasterror();
1080 }
1081
1082 // We rename directory in order not to lose the attachments
1083 $oldref = dol_sanitizeFileName($this->oldref);
1084 $newref = dol_sanitizeFileName($this->ref);
1085 $dirsource = $conf->bank->dir_output.'/'.$oldref;
1086 $dirdest = $conf->bank->dir_output.'/'.$newref;
1087 if (file_exists($dirsource)) {
1088 dol_syslog(get_class($this)."::update rename dir ".$dirsource." into ".$dirdest, LOG_DEBUG);
1089 if (@rename($dirsource, $dirdest)) {
1090 dol_syslog("Rename ok", LOG_DEBUG);
1091 }
1092 }
1093 }
1094
1095 if (!$error && !$notrigger) {
1096 // Call trigger
1097 $result = $this->call_trigger('BANKACCOUNT_MODIFY', $user);
1098 if ($result < 0) {
1099 $error++;
1100 }
1101 // End call triggers
1102 }
1103 } else {
1104 $error++;
1105 $this->error = $this->db->lasterror();
1106 dol_print_error($this->db);
1107 }
1108
1109 if (!$error) {
1110 $this->db->commit();
1111 return $this->id;
1112 } else {
1113 $this->db->rollback();
1114 return -1 * $error;
1115 }
1116 }
1117
1118
1119 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1126 public function update_bban($user = null)
1127 {
1128 // phpcs:enable
1129 global $conf, $langs;
1130
1131 // Load library to get BAN control function
1132 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
1133
1134 dol_syslog(get_class($this)."::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
1135
1136 // Check parameters
1137 if (!$this->ref) {
1138 $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->trans("Ref"));
1139 return -2;
1140 }
1141
1142 $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET";
1143 $sql .= " bank = '".$this->db->escape($this->bank)."'";
1144 $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
1145 $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
1146 $sql .= ",number='".$this->db->escape($this->number)."'";
1147 $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
1148 $sql .= ",bic='".$this->db->escape($this->bic)."'";
1149 $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
1150 $sql .= ",domiciliation='".$this->db->escape($this->address)."'";
1151 $sql .= ",proprio = '".$this->db->escape($this->owner_name)."'";
1152 $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
1153 $sql .= ",owner_zip = '".$this->db->escape($this->owner_zip)."'";
1154 $sql .= ",owner_town = '".$this->db->escape($this->owner_town)."'";
1155 $sql .= ",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) : "null");
1156 $sql .= ",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) : "null");
1157 $sql .= ",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) : "null");
1158 $sql .= " WHERE rowid = ".((int) $this->id);
1159 $sql .= " AND entity = ".((int) $conf->entity);
1160
1161 dol_syslog(get_class($this)."::update_bban", LOG_DEBUG);
1162
1163 $result = $this->db->query($sql);
1164 if ($result) {
1165 return 1;
1166 } else {
1167 $this->error = $this->db->lasterror();
1168 dol_print_error($this->db);
1169 return -1;
1170 }
1171 }
1172
1173
1181 public function fetch($id, $ref = '')
1182 {
1183 if (empty($id) && empty($ref)) {
1184 $this->error = "ErrorBadParameters";
1185 return -1;
1186 }
1187
1188 $sql = "SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant as type, ba.clos as status, ba.rappro, ba.url, ba.entity,";
1189 $sql .= " ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
1190 $sql .= " ba.domiciliation as address, ba.pti_in_ctti, ba.sepa_category_purpose, ba.sepa_local_instrument, ba.proprio as owner_name, ba.owner_address, ba.owner_zip, ba.owner_town, ba.owner_country_id, ba.state_id, ba.fk_pays as country_id,";
1191 $sql .= " ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
1192 $sql .= " ba.min_allowed, ba.min_desired, ba.comment,";
1193 $sql .= " ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,";
1194 $sql .= ' c.code as country_code, c.label as country,';
1195 $sql .= ' d.code_departement as state_code, d.nom as state,';
1196 $sql .= ' aj.code as accountancy_journal';
1197 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
1198 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON ba.fk_pays = c.rowid';
1199 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON ba.state_id = d.rowid';
1200 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid = ba.fk_accountancy_journal';
1201 $sql .= " WHERE ba.entity IN (".getEntity($this->element).")";
1202 if ($id) {
1203 $sql .= " AND ba.rowid = ".((int) $id);
1204 }
1205 if ($ref) {
1206 $sql .= " AND ba.ref = '".$this->db->escape($ref)."'";
1207 }
1208
1209 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1210 $result = $this->db->query($sql);
1211 if ($result) {
1212 if ($this->db->num_rows($result)) {
1213 $obj = $this->db->fetch_object($result);
1214
1215 $this->id = $obj->rowid;
1216 $this->rowid = $obj->rowid;
1217 $this->entity = $obj->entity;
1218 $this->ref = $obj->ref;
1219 $this->label = $obj->label;
1220 $this->type = $obj->type;
1221 $this->courant = $obj->type;
1222 $this->bank = $obj->bank;
1223 $this->clos = $obj->status;
1224 $this->status = $obj->status;
1225 $this->rappro = $obj->rappro;
1226 $this->url = $obj->url;
1227
1228 $this->code_banque = $obj->code_banque;
1229 $this->code_guichet = $obj->code_guichet;
1230 $this->number = $obj->number;
1231 $this->cle_rib = $obj->cle_rib;
1232 $this->bic = $obj->bic;
1233 $this->iban = $obj->iban;
1234 $this->address = $obj->address;
1235
1236 $this->owner_name = $obj->owner_name;
1237 $this->proprio = $this->owner_name;
1238 $this->owner_address = $obj->owner_address;
1239 $this->owner_zip = $obj->owner_zip;
1240 $this->owner_town = $obj->owner_town;
1241 $this->owner_country_id = $obj->owner_country_id;
1242
1243 $this->pti_in_ctti = $obj->pti_in_ctti;
1244 $this->sepa_category_purpose = (in_array($obj->sepa_category_purpose, self::SEPA_CATEGORY_PURPOSES) ? $obj->sepa_category_purpose : 'CORE');
1245 $this->sepa_local_instrument = (in_array($obj->sepa_local_instrument, self::SEPA_LOCAL_INSTRUMENTS) ? $obj->sepa_local_instrument : 'CORE');
1246
1247 $this->state_id = $obj->state_id;
1248 $this->state_code = $obj->state_code;
1249 $this->state = $obj->state;
1250
1251 $this->country_id = $obj->country_id;
1252 $this->country_code = $obj->country_code;
1253 $this->country = $obj->country;
1254
1255 $this->account_number = $obj->account_number;
1256 $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
1257 $this->accountancy_journal = $obj->accountancy_journal;
1258
1259 $this->currency_code = $obj->currency_code;
1260 $this->account_currency_code = $obj->currency_code;
1261 $this->min_allowed = $obj->min_allowed;
1262 $this->min_desired = $obj->min_desired;
1263 $this->comment = $obj->comment;
1264
1265 $this->date_creation = $this->db->jdate($obj->date_creation);
1266 $this->date_modification = $this->db->jdate($obj->date_modification);
1267
1268 $this->ics = $obj->ics;
1269 $this->ics_transfer = $obj->ics_transfer;
1270
1271 // Retrieve all extrafield
1272 // fetch optionals attributes and labels
1273 $this->fetch_optionals();
1274
1275 return 1;
1276 } else {
1277 return 0;
1278 }
1279 } else {
1280 $this->error = $this->db->lasterror();
1281 $this->errors[] = $this->error;
1282 return -1;
1283 }
1284 }
1285
1296 public function setCategories($categories)
1297 {
1298 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1299 return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT);
1300 }
1301
1309 public function delete($user, $notrigger = 0)
1310 {
1311 $error = 0;
1312
1313 $this->db->begin();
1314
1315 // @TODO Check there is no child into llx_payment_various, ... to allow deletion ?
1316
1317 // Delete link between tag and bank account
1318 if (!$error) {
1319 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
1320 $sql .= " WHERE fk_account = ".((int) $this->id);
1321
1322 $resql = $this->db->query($sql);
1323 if (!$resql) {
1324 $error++;
1325 $this->error = "Error ".$this->db->lasterror();
1326 }
1327 }
1328
1329 if (!$error) {
1330 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
1331 $sql .= " WHERE rowid = ".((int) $this->id);
1332
1333 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1334 $result = $this->db->query($sql);
1335 if ($result) {
1336 // Remove extrafields
1337 if (!$error) {
1338 $result = $this->deleteExtraFields();
1339 if ($result < 0) {
1340 $error++;
1341 dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
1342 }
1343 }
1344 } else {
1345 $error++;
1346 $this->error = "Error ".$this->db->lasterror();
1347 }
1348 }
1349
1350 if (!$error && !$notrigger) {
1351 // Call trigger
1352 $result = $this->call_trigger('BANKACCOUNT_DELETE', $user);
1353 if ($result < 0) {
1354 $error++;
1355 }
1356 // End call triggers
1357 }
1358
1359 if (!$error) {
1360 $this->db->commit();
1361 return 1;
1362 } else {
1363 $this->db->rollback();
1364 return -1;
1365 }
1366 }
1367
1368
1375 public function getLibStatut($mode = 0)
1376 {
1377 return $this->LibStatut($this->status, $mode);
1378 }
1379
1380 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1388 public function LibStatut($status, $mode = 0)
1389 {
1390 // phpcs:enable
1391 global $langs;
1392 $langs->load('banks');
1393
1394 if ($status == self::STATUS_OPEN) {
1395 $label = $langs->transnoentitiesnoconv("StatusAccountOpened");
1396 $labelshort = $langs->transnoentitiesnoconv("StatusAccountOpened");
1397 $statusType = 'status4';
1398 } else {
1399 $label = $langs->transnoentitiesnoconv("StatusAccountClosed");
1400 $labelshort = $langs->transnoentitiesnoconv("StatusAccountClosed");
1401 $statusType = 'status5';
1402 }
1403
1404 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
1405 }
1406
1407
1408 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1414 public function can_be_deleted()
1415 {
1416 // phpcs:enable
1417 $can_be_deleted = false;
1418
1419 $sql = "SELECT COUNT(rowid) as nb";
1420 $sql .= " FROM ".MAIN_DB_PREFIX."bank";
1421 $sql .= " WHERE fk_account = ".((int) $this->id);
1422
1423 $resql = $this->db->query($sql);
1424 if ($resql) {
1425 $obj = $this->db->fetch_object($resql);
1426 if ($obj->nb <= 1) {
1427 $can_be_deleted = true; // Juste le solde
1428 }
1429 } else {
1430 dol_print_error($this->db);
1431 }
1432 return $can_be_deleted;
1433 }
1434
1435
1441 public function error()
1442 {
1443 return $this->error;
1444 }
1445
1454 public function solde($option = 0, $date_end = '', $field = 'dateo')
1455 {
1456 $solde = 0;
1457
1458 $sql = "SELECT sum(amount) as amount";
1459 $sql .= " FROM ".MAIN_DB_PREFIX."bank";
1460 $sql .= " WHERE fk_account = ".((int) $this->id);
1461 if ($option == 1) {
1462 $sql .= " AND ".$this->db->sanitize($field)." <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(dol_now()))."'";
1463 }
1464
1465 $resql = $this->db->query($sql);
1466 if ($resql) {
1467 if ($this->db->num_rows($resql)) {
1468 $obj = $this->db->fetch_object($resql);
1469 $solde = $obj->amount;
1470 }
1471 $this->db->free($resql);
1472 } else {
1473 $this->errors[] = $this->db->lasterror;
1474 return -1;
1475 }
1476
1477 return (float) price2num($solde, 'MU');
1478 }
1479
1480 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1488 public function load_board(User $user, $filteraccountid = 0)
1489 {
1490 // phpcs:enable
1491 global $conf, $langs;
1492
1493 if ($user->socid) {
1494 return -1; // Protection to prevent calls by external users
1495 }
1496
1497 $now = dol_now();
1498
1499 // The count and the number of late transactions are computed by the database instead of reading every transaction to
1500 // conciliate (there can be a lot of them). A transaction is late when its value date is before now minus the warning
1501 // delay (a transaction without value date was counted as late, this is kept).
1502 $sql = "SELECT COUNT(b.rowid) as nb,";
1503 $sql .= " SUM(CASE WHEN b.datev IS NULL OR b.datev < '".$this->db->idate($now - $conf->bank->rappro->warning_delay)."' THEN 1 ELSE 0 END) as nblate";
1504 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b,";
1505 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
1506 $sql .= " WHERE b.rappro=0";
1507 $sql .= " AND b.fk_account = ba.rowid";
1508 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1509 $sql .= " AND (ba.rappro = 1 AND ba.courant != " . Account::TYPE_CASH . ")"; // Compte rapprochable
1510 $sql .= " AND clos = 0";
1511 if ($filteraccountid) {
1512 $sql .= " AND ba.rowid = ".((int) $filteraccountid);
1513 }
1514 $resql = $this->db->query($sql);
1515 if ($resql) {
1516 $langs->load("banks");
1517
1518 require_once DOL_DOCUMENT_ROOT.'/core/class/workboardresponse.class.php';
1519
1520 $response = new WorkboardResponse();
1521 $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1522 $response->label = $langs->trans("TransactionsToConciliate");
1523 $response->labelShort = $langs->trans("TransactionsToConciliateShort");
1524 $response->url = DOL_URL_ROOT.'/compta/bank/list.php?leftmenu=bank&amp;mainmenu=bank';
1525 $response->img = img_object('', "payment");
1526
1527 $obj = $this->db->fetch_object($resql);
1528 if ($obj) {
1529 $response->nbtodo = (int) $obj->nb;
1530 $response->nbtodolate = (int) $obj->nblate;
1531 }
1532 return $response;
1533 } else {
1534 dol_print_error($this->db);
1535 $this->error = $this->db->error();
1536 return -1;
1537 }
1538 }
1539
1546 public function loadStateBoard($filteraccountid = 0)
1547 {
1548 global $user;
1549
1550 if ($user->socid) {
1551 return -1; // Protection to prevent calls by external users
1552 }
1553
1554 $sql = "SELECT count(b.rowid) as nb";
1555 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b,";
1556 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
1557 $sql .= " WHERE b.fk_account = ba.rowid";
1558 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1559 $sql .= " AND (ba.rappro = 1 AND ba.courant != 2)"; // Compte rapprochable
1560 $sql .= " AND clos = 0";
1561 if ($filteraccountid) {
1562 $sql .= " AND ba.rowid = ".((int) $filteraccountid);
1563 }
1564
1565 $resql = $this->db->query($sql);
1566 if ($resql) {
1567 while ($obj = $this->db->fetch_object($resql)) {
1568 $this->nb["banklines"] = $obj->nb;
1569 }
1570 $this->db->free($resql);
1571 return 1;
1572 } else {
1573 dol_print_error($this->db);
1574 $this->error = $this->db->error();
1575 return -1;
1576 }
1577 }
1578
1579
1585 public function countAccountToReconcile()
1586 {
1587 global $user;
1588
1589 //Protection against external users
1590 if ($user->socid) {
1591 return 0;
1592 }
1593
1594 $nb = 0;
1595
1596 $sql = "SELECT COUNT(ba.rowid) as nb";
1597 $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
1598 $sql .= " WHERE ba.rappro > 0 and ba.clos = 0";
1599 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1600 if (!getDolGlobalString('BANK_CAN_RECONCILIATE_CASHACCOUNT')) {
1601 $sql .= " AND ba.courant != " . Account::TYPE_CASH;
1602 }
1603
1604 $resql = $this->db->query($sql);
1605 if ($resql) {
1606 $obj = $this->db->fetch_object($resql);
1607 $nb = (int) $obj->nb;
1608 } else {
1609 dol_print_error($this->db);
1610 }
1611
1612 return $nb;
1613 }
1614
1623 public function getTooltipContentArray($params)
1624 {
1625 global $langs;
1626 $langs->loadLangs(['banks', 'compta']);
1627 include_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
1628
1629 $datas = array();
1630
1631 $nofetch = !empty($params['nofetch']);
1632 $pictos = img_picto('', $this->picto).' <u class="paddingrightnow">'.$langs->trans("BankAccount").'</u>';
1633 if (isset($this->status)) {
1634 $pictos .= ' '.$this->getLibStatut(5);
1635 }
1636 $datas['picto'] = $pictos;
1637 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1638 $datas['label'] = '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1639 $datas['accountnumber'] = '<br><br><b>'.$langs->trans('AccountNumber').':</b> '.$this->number;
1640 $datas['iban'] = '<br><b>'.$langs->trans('IBAN').':</b> '.getIbanHumanReadable($this);
1641 $datas['bic'] = '<br><b>'.$langs->trans('BIC').':</b> '.$this->bic;
1642 $datas['accountcurrency'] = '<br><br><b>'.$langs->trans("AccountCurrency").':</b> '.$this->currency_code;
1643
1644 if (isModEnabled('accounting')) {
1645 include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
1646 $langs->load("accountancy");
1647 $datas['accountaccounting'] = '<br><b>'.$langs->trans('AccountAccounting').':</b> '.length_accountg($this->account_number);
1648 $datas['accountancyjournal'] = '<br><b>'.$langs->trans('AccountancyJournal').':</b> '.$this->accountancy_journal;
1649 }
1650 // show categories for this record only in ajax to not overload lists
1651 if (isModEnabled('category') && !$nofetch) {
1652 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1653 $form = new Form($this->db);
1654 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_ACCOUNT, 1);
1655 }
1656
1657 return $datas;
1658 }
1659
1671 public function getNomUrl($withpicto = 0, $mode = '', $option = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1672 {
1673 global $conf, $langs;
1674
1675 if (!empty($conf->dol_no_mouse_hover)) {
1676 $notooltip = 1; // Force disable tooltips
1677 }
1678
1679 include_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
1680
1681 $result = '';
1682 $classfortooltip = 'classfortooltip';
1683 $dataparams = '';
1684 $params = [
1685 'id' => $this->id,
1686 'objecttype' => $this->element,
1687 'option' => $option,
1688 'nofetch' => 1,
1689 ];
1690 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1691 $classfortooltip = 'classforajaxtooltip';
1692 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1693 $label = '';
1694 } else {
1695 $label = implode($this->getTooltipContentArray($params));
1696 }
1697
1698 $baseurl = DOL_URL_ROOT.'/compta/bank/card.php';
1699 $query = ['id' => $this->id];
1700 if ($mode == 'transactions') {
1701 $baseurl = DOL_URL_ROOT.'/compta/bank/bankentries_list.php';
1702 } elseif ($mode == 'receipts') {
1703 $baseurl = DOL_URL_ROOT.'/compta/bank/releve.php';
1704 $query = ['account' => $this->id];
1705 }
1706
1707 if ($option != 'nolink') {
1708 // Add param to save lastsearch_values or not
1709 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1710 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1711 $add_save_lastsearch_values = 1;
1712 }
1713 if ($add_save_lastsearch_values) {
1714 $query = array_merge($query, ['save_lastsearch_values' => 1]);
1715 }
1716 }
1717 $url = dolBuildUrl($baseurl, $query);
1718
1719 $linkclose = '';
1720 if (empty($notooltip)) {
1721 if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1722 $label = $langs->trans("BankAccount");
1723 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1724 }
1725 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1726 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1727 } else {
1728 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1729 }
1730
1731 if ($option == 'nolink' || empty($url)) {
1732 $linkstart = '<span';
1733 } else {
1734 $linkstart = '<a href="'.$url.'"';
1735 }
1736 $linkstart .= $linkclose.'>';
1737 if ($option == 'nolink' || empty($url)) {
1738 $linkend = '</span>';
1739 } else {
1740 $linkend = '</a>';
1741 }
1742
1743 $result .= $linkstart;
1744
1745 if ($withpicto) {
1746 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1747 }
1748 if ($withpicto != 2) {
1749 $result .= $this->ref.($option == 'reflabel' && $this->label ? ' - '.$this->label : '');
1750 }
1751 $result .= $linkend;
1752
1753 global $action, $hookmanager;
1754 $hookmanager->initHooks(array($this->element . 'dao'));
1755 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1756 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1757 if ($reshook > 0) {
1758 $result = $hookmanager->resPrint;
1759 } else {
1760 $result .= $hookmanager->resPrint;
1761 }
1762
1763 return $result;
1764 }
1765
1766
1767 // Method after here are common to Account and CompanyBankAccount
1768
1769
1775 public function verif()
1776 {
1777 require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
1778
1779 $error = 0;
1780
1781 // Call functions to check BAN
1782 if (!checkIbanForAccount($this)) {
1783 $error++;
1784 $this->error = 'IBANNotValid';
1785 }
1786 // Call function to check Swift/BIC.
1787 // A non valid BIC/Swift is a problem if: it is not empty or always a problem if WITHDRAWAL_WITHOUT_BIC is not set).
1788 if (!checkSwiftForAccount($this) && (!empty($this->bic) || !getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC'))) {
1789 $error++;
1790 $this->error = 'SwiftNotValid';
1791 }
1792
1793 if (! $error) {
1794 return 1;
1795 } else {
1796 return 0;
1797 }
1798 }
1799
1805 public function getCountryCode()
1806 {
1807 global $mysoc;
1808
1809 // We return country code of bank account
1810 if (!empty($this->country_code)) {
1811 return $this->country_code;
1812 }
1813
1814 // For backward compatibility, we try to guess country from other information
1815 if (!empty($this->iban)) {
1816 // If IBAN defined, we can know country of account from it
1817 $reg = array();
1818 if (preg_match("/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) {
1819 return $reg[1];
1820 }
1821 }
1822
1823 // If this class is linked to a third party
1824 if (!empty($this->socid)) {
1825 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1826 $company = new Societe($this->db);
1827 $result = $company->fetch($this->socid);
1828 if (!empty($company->country_code)) {
1829 return $company->country_code;
1830 }
1831 }
1832
1833 // We return country code of managed company
1834 if (!empty($mysoc->country_code)) {
1835 return $mysoc->country_code;
1836 }
1837
1838 return '';
1839 }
1840
1848 public function getBannerAddress($htmlkey, $object)
1849 {
1850 global $conf, $langs;
1851
1852 $out = '';
1853
1854 $outdone = 0;
1855 $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT'));
1856 if ($coords) {
1857 if (!empty($conf->use_javascript_ajax)) {
1858 // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile
1859 $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($coords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
1860 $out .= img_picto($langs->trans("Address"), 'map-marker-alt');
1861 $out .= '</a> ';
1862 }
1863 $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', ');
1864 if ($address) {
1865 $out .= $address;
1866 $outdone++;
1867 }
1868 $outdone++;
1869 }
1870
1871 return $out;
1872 }
1873
1880 public function getBankFieldLabel($field)
1881 {
1882 $country_code = $this->getCountryCode();
1883
1884 if ($country_code == 'CA' && $field == 'BankCode') {
1885 return 'InstitutionNumber';
1886 }
1887 if ($country_code == 'CA' && $field == 'DeskCode') {
1888 return 'TransitNumber';
1889 }
1890 if ($country_code == 'US' && $field == 'BankCode') {
1891 return 'ABARoutingNumber';
1892 }
1893
1894 return $field;
1895 }
1896
1906 public function useDetailedBBAN()
1907 {
1908 $country_code = $this->getCountryCode();
1909
1910 if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC', 'DZ'))) {
1911 return 1; // France, Spain, Gabon, ... - Not valid for CH
1912 }
1913 if ($country_code == 'CA') {
1914 return 3;
1915 }
1916 if (in_array($country_code, array('AD', 'AU', 'BE', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) {
1917 return 2; // Australia, England...
1918 }
1919 return 0;
1920 }
1921
1927 public function needIBAN()
1928 {
1929 global $conf;
1930
1931 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1932 return 0;
1933 }
1934
1935 $country_code = $this->getCountryCode();
1936
1937 $country_code_in_EEC = array(
1938 'AT', // Austria
1939 'BE', // Belgium
1940 'BG', // Bulgaria
1941 'CY', // Cyprus
1942 'CZ', // Czech republic
1943 'DE', // Germany
1944 'DK', // Danemark
1945 'EE', // Estonia
1946 'ES', // Spain
1947 'FI', // Finland
1948 'FR', // France
1949 'GB', // United Kingdom
1950 'GR', // Greece
1951 'HR', // Croatia
1952 'NL', // Holland
1953 'HU', // Hungary
1954 'IE', // Ireland
1955 'IM', // Isle of Man - Included in UK
1956 'IT', // Italy
1957 'LT', // Lithuania
1958 'LU', // Luxembourg
1959 'LV', // Latvia
1960 'MC', // Monaco - Included in France
1961 'MT', // Malta
1962 //'NO', // Norway
1963 'PL', // Poland
1964 'PT', // Portugal
1965 'RO', // Romania
1966 'SE', // Sweden
1967 'SK', // Slovakia
1968 'SI', // Slovenia
1969 'UK', // United Kingdom
1970 //'CH', // Switzerland - No. Swizerland in not in EEC
1971 );
1972
1973 if (in_array($country_code, $country_code_in_EEC)) {
1974 return 1; // France, Spain, ...
1975 }
1976 return 0;
1977 }
1978
1984 public function needBIC()
1985 {
1986 if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) {
1987 return 0;
1988 }
1989
1990 $country_code = $this->getCountryCode();
1991
1992 $country_code_in_EEC = array(
1993 'AD', // Andorra
1994 'BH', // Bahrein
1995 'DK', // Denmark
1996 'FR', // France
1997 'GH', // Ghana
1998 'HU', // Hungary
1999 'JP', // Japan
2000 'LV', // Latvia
2001 'SE', // Sweden
2002 );
2003
2004 if (in_array($country_code, $country_code_in_EEC)) {
2005 return 1; // Andorra, Bahrein, ...
2006 }
2007 return 0;
2008 }
2009
2016 public function info($id)
2017 {
2018 }
2019
2034 public function getFieldsToShow($includeibanbic = 0)
2035 {
2036 //Get the required properties depending on the country
2037 $detailedBBAN = $this->useDetailedBBAN();
2038
2039 if ($detailedBBAN == 0) {
2040 $fieldarray = array(
2041 'BankAccountNumber'
2042 );
2043 } elseif ($detailedBBAN == 2) {
2044 $fieldarray = array(
2045 'BankCode',
2046 'BankAccountNumber'
2047 );
2048 } elseif ($detailedBBAN == 3) {
2049 $fieldarray = array(
2050 'BankCode',
2051 'DeskCode',
2052 'BankAccountNumber'
2053 );
2054 } else {
2055 $fieldarray = self::getAccountNumberOrder();
2056 }
2057
2058 //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
2059 if ($includeibanbic) {
2060 $fieldarray[] = 'IBAN';
2061 $fieldarray[] = 'BIC';
2062 }
2063 //}
2064
2065 //Get the order the properties are shown
2066 return $fieldarray;
2067 }
2068
2079 public static function getAccountNumberOrder()
2080 {
2081 global $conf;
2082
2083 $fieldlists = array(
2084 'BankCode',
2085 'DeskCode',
2086 'BankAccountNumber',
2087 'BankAccountNumberKey'
2088 );
2089
2090 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) {
2091 if (is_numeric(getDolGlobalString('BANK_SHOW_ORDER_OPTION'))) {
2092 if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') {
2093 $fieldlists = array(
2094 'BankCode',
2095 'DeskCode',
2096 'BankAccountNumberKey',
2097 'BankAccountNumber'
2098 );
2099 }
2100 } else {
2101 //Replace the old AccountNumber key with the new BankAccountNumber key
2102 $fieldlists = explode(
2103 ' ',
2104 preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
2105 );
2106 }
2107 }
2108
2109 return $fieldlists;
2110 }
2111
2112
2120 public function initAsSpecimen()
2121 {
2122 // Example of IBAN FR7630001007941234567890185
2123 $this->specimen = 1;
2124 $this->ref = 'MBA';
2125 $this->label = 'My Big Company Bank account';
2126 $this->clos = Account::STATUS_OPEN;
2127 $this->type = Account::TYPE_CURRENT;
2128 $this->status = Account::STATUS_OPEN;
2129 $this->code_banque = '30001';
2130 $this->code_guichet = '00794';
2131 $this->number = '12345678901';
2132 $this->cle_rib = '85';
2133 $this->bic = 'AA12';
2134 $this->iban = 'FR7630001007941234567890185';
2135
2136 $this->bank = 'MyBank';
2137 $this->address = 'Rue de Paris';
2138 $this->owner_name = 'Owner';
2139 $this->owner_address = 'Owner address';
2140 $this->owner_zip = 'Owner zip';
2141 $this->owner_town = 'Owner town';
2142 $this->owner_country_id = 1;
2143 $this->country_id = 1;
2144
2145 return 1;
2146 }
2147
2156 public static function replaceThirdparty($dbs, $origin_id, $dest_id)
2157 {
2158 $sql = "UPDATE ".MAIN_DB_PREFIX."bank_url SET url_id = ".((int) $dest_id)." WHERE url_id = ".((int) $origin_id)." AND type = 'company'";
2159
2160 if ($dbs->query($sql)) {
2161 return true;
2162 } else {
2163 //if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdparty and B-C on old one, we must get A-B-C after merge. Not A-B.
2164 //$this->errors = $dbs->lasterror();
2165 return false;
2166 }
2167 }
2168
2176 public function getKanbanView($option = '', $arraydata = null)
2177 {
2178 global $langs;
2179
2180 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2181
2182 $return = '<div class="box-flex-item box-flex-grow-zero">';
2183 $return .= '<div class="info-box info-box-sm">';
2184 $return .= '<span class="info-box-icon bg-infobox-action">';
2185 $return .= img_picto('', $this->picto);
2186 $return .= '</span>';
2187 $return .= '<div class="info-box-content">';
2188 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
2189 if ($selected >= 0) {
2190 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2191 }
2192 if (property_exists($this, 'type_lib')) {
2193 $return .= '<br><span class="info-box-label opacitymedium" title="'.$this->type_lib[$this->type].'">'.substr($this->type_lib[$this->type], 0, 24).'...</span>';
2194 }
2195 if (method_exists($this, 'solde')) {
2196 $return .= '<br><a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$this->id.'">';
2197 $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>';
2198 }
2199 if (method_exists($this, 'getLibStatut')) {
2200 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2201 }
2202 $return .= '</div>';
2203 $return .= '</div>';
2204 $return .= '</div>';
2205 return $return;
2206 }
2207}
2208
2209
2210require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
2211
2215class AccountLine extends CommonObjectLine
2216{
2220 public $db;
2221
2225 public $element = 'bank';
2226
2230 public $table_element = 'bank';
2231
2235 public $picto = 'accountline';
2236
2240 public $id;
2241
2245 public $ref;
2246
2252 public $datec;
2253
2259 public $dateo;
2260
2266 public $datev;
2267
2271 public $amount;
2272
2276 public $amount_main_currency;
2277
2281 public $fk_user_author;
2282
2286 public $fk_user_rappro;
2287
2291 public $fk_type;
2292
2296 public $fk_bordereau;
2297
2301 public $fk_account;
2302
2306 public $bank_account_ref;
2307
2311 public $bank_account_label;
2312
2316 public $numero_compte;
2317
2321 public $emetteur;
2322
2326 public $rappro;
2327
2331 public $num_releve;
2332
2336 public $num_chq;
2337
2341 public $bank_chq;
2342
2346 public $label;
2347
2351 public $note;
2352
2358 public $user_rappro;
2359
2360
2366 public function __construct(DoliDB $db)
2367 {
2368 $this->db = $db;
2369 }
2370
2379 public function fetch($rowid, $ref = '', $num = '')
2380 {
2381 // Check parameters
2382 if (empty($rowid) && empty($ref) && empty($num)) {
2383 return -1;
2384 }
2385
2386 $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
2387 $sql .= " b.fk_user_author, b.fk_user_rappro,";
2388 $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
2389 $sql .= " b.fk_bordereau, b.banque, b.emetteur,";
2390 $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label";
2391 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b,";
2392 $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
2393 $sql .= " WHERE b.fk_account = ba.rowid";
2394 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
2395 if ($num) {
2396 $sql .= " AND b.num_chq = '".$this->db->escape($num)."'";
2397 } elseif ($ref) {
2398 $sql .= " AND b.rowid = '".$this->db->escape($ref)."'";
2399 } else {
2400 $sql .= " AND b.rowid = ".((int) $rowid);
2401 }
2402
2403 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
2404 $result = $this->db->query($sql);
2405 if ($result) {
2406 $ret = 0;
2407
2408 $obj = $this->db->fetch_object($result);
2409 if ($obj) {
2410 $this->id = $obj->rowid;
2411 $this->rowid = $obj->rowid;
2412 $this->ref = $obj->rowid;
2413
2414 $this->datec = $this->db->jdate($obj->datec);
2415 $this->datev = $this->db->jdate($obj->datev);
2416 $this->dateo = $this->db->jdate($obj->dateo);
2417 $this->amount = $obj->amount;
2418 $this->label = $obj->label;
2419 $this->note = $obj->note;
2420
2421 $this->fk_user_author = $obj->fk_user_author;
2422 $this->fk_user_rappro = $obj->fk_user_rappro;
2423
2424 $this->fk_type = $obj->fk_type; // Type of transaction
2425 $this->rappro = (int) $obj->rappro;
2426 $this->num_releve = $obj->num_releve;
2427
2428 $this->num_chq = $obj->num_chq;
2429 $this->bank_chq = $obj->banque;
2430 $this->fk_bordereau = $obj->fk_bordereau;
2431
2432 $this->fk_account = $obj->fk_account;
2433 $this->bank_account_ref = $obj->bank_account_ref;
2434 $this->bank_account_label = $obj->bank_account_label;
2435
2436 // Retrieve all extrafield
2437 // fetch optionals attributes and labels
2438 $this->fetch_optionals();
2439
2440 $ret = 1;
2441 }
2442 $this->db->free($result);
2443 return $ret;
2444 } else {
2445 return -1;
2446 }
2447 }
2448
2454 public function insert()
2455 {
2456 $error = 0;
2457
2458 $this->db->begin();
2459
2460 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (";
2461 $sql .= "datec";
2462 $sql .= ", dateo";
2463 $sql .= ", datev";
2464 $sql .= ", label";
2465 $sql .= ", amount";
2466 $sql .= ", amount_main_currency";
2467 $sql .= ", fk_user_author";
2468 $sql .= ", num_chq";
2469 $sql .= ", fk_account";
2470 $sql .= ", fk_type";
2471 $sql .= ", emetteur,banque";
2472 $sql .= ", rappro";
2473 $sql .= ", numero_compte";
2474 $sql .= ", num_releve";
2475 $sql .= ", note";
2476 $sql .= ") VALUES (";
2477 $sql .= "'".$this->db->idate($this->datec)."'";
2478 $sql .= ", '".$this->db->idate($this->dateo)."'";
2479 $sql .= ", '".$this->db->idate($this->datev)."'";
2480 $sql .= ", '".$this->db->escape($this->label)."'";
2481 $sql .= ", ".price2num($this->amount);
2482 $sql .= ", ".(empty($this->amount_main_currency) ? "NULL" : price2num($this->amount_main_currency));
2483 $sql .= ", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null");
2484 $sql .= ", ".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
2485 $sql .= ", '".$this->db->escape((string) $this->fk_account)."'";
2486 $sql .= ", '".$this->db->escape($this->fk_type)."'";
2487 $sql .= ", ".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
2488 $sql .= ", ".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
2489 $sql .= ", ".(int) $this->rappro;
2490 $sql .= ", ".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
2491 $sql .= ", ".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null");
2492 $sql .= ", ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
2493 $sql .= ")";
2494
2495
2496 dol_syslog(get_class($this)."::insert", LOG_DEBUG);
2497 $resql = $this->db->query($sql);
2498 if ($resql) {
2499 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
2500 // Actions on extra fields (by external module or standard code)
2501 $result = $this->insertExtraFields();
2502 if ($result < 0) {
2503 $error++;
2504 }
2505 } else {
2506 $error++;
2507 $this->error = $this->db->lasterror();
2508 dol_print_error($this->db);
2509 }
2510
2511 if (!$error) {
2512 $this->db->commit();
2513 return $this->id;
2514 } else {
2515 $this->db->rollback();
2516 return -1 * $error;
2517 }
2518 }
2519
2527 public function delete($user, $notrigger = 0)
2528 {
2529 $nbko = 0;
2530
2531 if ($this->rappro) {
2532 // Protection to avoid any delete of consolidated lines
2533 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated";
2534 return -1;
2535 }
2536
2537 $this->db->begin();
2538
2539 if (!$notrigger) {
2540 // Call trigger
2541 $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user);
2542 if ($result < 0) {
2543 $this->db->rollback();
2544 return -1;
2545 }
2546 // End call triggers
2547 }
2548
2549 // Protection to avoid any delete of accounted lines. Protection on by default
2550 if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) {
2551 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->id);
2552 $resql = $this->db->query($sql);
2553 if ($resql) {
2554 $obj = $this->db->fetch_object($resql);
2555 if ($obj && $obj->nb) {
2556 $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
2557 $this->db->rollback();
2558 return -1;
2559 }
2560 } else {
2561 $this->error = $this->db->lasterror();
2562 $this->db->rollback();
2563 return -1;
2564 }
2565 }
2566
2567 // Delete urls
2568 $result = $this->delete_urls($user);
2569 if ($result < 0) {
2570 $nbko++;
2571 }
2572
2573 $sql = "DELETE FROM ".MAIN_DB_PREFIX."category_bankline WHERE lineid=".(int) $this->rowid;
2574 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2575 $result = $this->db->query($sql);
2576 if (!$result) {
2577 $nbko++;
2578 }
2579
2580 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=".(int) $this->rowid;
2581 $result = $this->db->query($sql);
2582 if (!$result) {
2583 $nbko++;
2584 }
2585
2586 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".(int) $this->rowid;
2587 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
2588 $result = $this->db->query($sql);
2589 if (!$result) {
2590 $nbko++;
2591 }
2592
2593 if (!$nbko) {
2594 $this->db->commit();
2595 return 1;
2596 } else {
2597 $this->db->rollback();
2598 return -$nbko;
2599 }
2600 }
2601
2602
2603 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2610 public function delete_urls($user = null)
2611 {
2612 // phpcs:enable
2613 $nbko = 0;
2614
2615 if ($this->rappro) {
2616 // Protection to avoid any delete of consolidated lines
2617 $this->error = "ErrorDeleteNotPossibleLineIsConsolidated";
2618 return -1;
2619 }
2620
2621 $this->db->begin();
2622
2623 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".(int) $this->rowid;
2624 dol_syslog(get_class($this)."::delete_urls", LOG_DEBUG);
2625 $result = $this->db->query($sql);
2626 if (!$result) {
2627 $nbko++;
2628 }
2629
2630 if (!$nbko) {
2631 $this->db->commit();
2632 return 1;
2633 } else {
2634 $this->db->rollback();
2635 return -$nbko;
2636 }
2637 }
2638
2639
2647 public function update(User $user, $notrigger = 0)
2648 {
2649 $this->db->begin();
2650
2651 $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2652 $sql .= " amount = ".price2num($this->amount).",";
2653 $sql .= " datev='".$this->db->idate($this->datev)."',";
2654 $sql .= " dateo='".$this->db->idate($this->dateo)."'";
2655 $sql .= " WHERE rowid = ".((int) $this->rowid);
2656
2657 dol_syslog(get_class($this)."::update", LOG_DEBUG);
2658 $resql = $this->db->query($sql);
2659 if (!$resql) {
2660 $this->db->rollback();
2661 $this->error = $this->db->error();
2662 return -1;
2663 }
2664
2665 if (!$notrigger) {
2666 // Call trigger
2667 $result = $this->call_trigger('BANKACCOUNTLINE_MODIFY', $user);
2668 if ($result < 0) {
2669 $this->db->rollback();
2670 return -1;
2671 }
2672 // End call triggers
2673 }
2674
2675 $this->db->commit();
2676 return 1;
2677 }
2678
2679
2685 public function updateLabel()
2686 {
2687 $this->db->begin();
2688
2689 $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2690 $sql .= " label = '".$this->db->escape($this->label)."'";
2691 $sql .= " WHERE rowid = ".((int) $this->rowid);
2692
2693 dol_syslog(get_class($this)."::update_label", LOG_DEBUG);
2694 $resql = $this->db->query($sql);
2695 if ($resql) {
2696 $this->db->commit();
2697 return 1;
2698 } else {
2699 $this->db->rollback();
2700 $this->error = $this->db->error();
2701 return -1;
2702 }
2703 }
2704
2705
2706 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2716 public function update_conciliation(User $user, $cat, $conciliated = 1, $notrigger = 0)
2717 {
2718 // phpcs:enable
2719 global $conf, $langs;
2720
2721 $this->db->begin();
2722
2723 // Check statement field
2724 if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) {
2725 if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) {
2726 $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex", getDolGlobalString('BANK_STATEMENT_REGEX_RULE'));
2727 $this->db->rollback();
2728 return -1;
2729 }
2730 }
2731
2732 $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2733 $sql .= " rappro = ".((int) $conciliated);
2734 $sql .= ", num_releve = '".$this->db->escape($this->num_releve)."'";
2735 if ($conciliated) {
2736 $sql .= ", fk_user_rappro = ".((int) $user->id);
2737 }
2738 $sql .= " WHERE rowid = ".((int) $this->id);
2739
2740 dol_syslog(get_class($this)."::update_conciliation", LOG_DEBUG);
2741 $resql = $this->db->query($sql);
2742 if ($resql) {
2743 if (!empty($cat) && $cat > 0) {
2744 $sql = "INSERT INTO ".MAIN_DB_PREFIX."category_bankline (";
2745 $sql .= "lineid";
2746 $sql .= ", fk_categ";
2747 $sql .= ") VALUES (";
2748 $sql .= ((int) $this->id);
2749 $sql .= ", ".((int) $cat);
2750 $sql .= ")";
2751
2752 dol_syslog(get_class($this)."::update_conciliation", LOG_DEBUG);
2753 $this->db->query($sql);
2754
2755 // No error check. Can fail if category already affected
2756 // TODO Do no try the insert if link already exists
2757 }
2758
2759 $this->rappro = (int) $conciliated;
2760
2761 if (!$notrigger) {
2762 // Call trigger
2763 $result = $this->call_trigger('BANKACCOUNTLINE_MODIFY', $user);
2764 if ($result < 0) {
2765 $this->db->rollback();
2766 return -1;
2767 }
2768 // End call triggers
2769 }
2770
2771 $this->db->commit();
2772 return 1;
2773 } else {
2774 $this->db->rollback();
2775 return -1;
2776 }
2777 }
2778
2779
2780 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2788 public function datev_change($rowid, $sign = 1)
2789 {
2790 // phpcs:enable
2791 $sql = "SELECT datev FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".((int) $rowid);
2792 $resql = $this->db->query($sql);
2793 if ($resql) {
2794 $obj = $this->db->fetch_object($resql);
2795 $newdate = (int) $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2796
2797 $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2798 $sql .= " datev = '".$this->db->idate($newdate)."'";
2799 $sql .= " WHERE rowid = ".((int) $rowid);
2800
2801 $result = $this->db->query($sql);
2802 if ($result) {
2803 if ($this->db->affected_rows($result)) {
2804 return 1;
2805 }
2806 } else {
2807 dol_print_error($this->db);
2808 return 0;
2809 }
2810 } else {
2811 dol_print_error($this->db);
2812 }
2813 return 0;
2814 }
2815
2816 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2823 public function datev_next($id)
2824 {
2825 // phpcs:enable
2826 return $this->datev_change($id, 1);
2827 }
2828
2829 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2836 public function datev_previous($id)
2837 {
2838 // phpcs:enable
2839 return $this->datev_change($id, -1);
2840 }
2841
2842
2843 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2851 public function dateo_change($rowid, $sign = 1)
2852 {
2853 // phpcs:enable
2854 $sql = "SELECT dateo FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".((int) $rowid);
2855 $resql = $this->db->query($sql);
2856 if ($resql) {
2857 $obj = $this->db->fetch_object($resql);
2858 $newdate = (int) $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2859
2860 $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2861 $sql .= " dateo = '".$this->db->idate($newdate)."'";
2862 $sql .= " WHERE rowid = ".((int) $rowid);
2863
2864 $result = $this->db->query($sql);
2865 if ($result) {
2866 if ($this->db->affected_rows($result)) {
2867 return 1;
2868 }
2869 } else {
2870 dol_print_error($this->db);
2871 return 0;
2872 }
2873 } else {
2874 dol_print_error($this->db);
2875 }
2876 return 0;
2877 }
2878
2879 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2886 public function dateo_next($id)
2887 {
2888 // phpcs:enable
2889 return $this->dateo_change($id, 1);
2890 }
2891
2892 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2899 public function dateo_previous($id)
2900 {
2901 // phpcs:enable
2902 return $this->dateo_change($id, -1);
2903 }
2904
2905
2912 public function info($id)
2913 {
2914 $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2915 $sql .= ' b.fk_user_author, b.fk_user_rappro';
2916 $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2917 $sql .= ' WHERE b.rowid = '.((int) $id);
2918
2919 $result = $this->db->query($sql);
2920 if ($result) {
2921 if ($this->db->num_rows($result)) {
2922 $obj = $this->db->fetch_object($result);
2923
2924 $this->id = $obj->rowid;
2925
2926 $this->user_creation_id = $obj->fk_user_author;
2927 $this->fk_user_rappro = $obj->fk_user_rappro;
2928 $this->user_rappro = $obj->fk_user_rappro;
2929 $this->date_creation = $this->db->jdate($obj->datec);
2930 $this->date_modification = $this->db->jdate($obj->datem);
2931 //$this->date_rappro = $obj->daterappro; // Not yet managed
2932 }
2933 $this->db->free($result);
2934 } else {
2935 dol_print_error($this->db);
2936 }
2937 }
2938
2939
2949 public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2950 {
2951 global $conf, $langs;
2952
2953 $result = '';
2954
2955 $label = img_picto('', $this->picto).' <u>'.$langs->trans("BankTransactionLine").'</u>:<br>';
2956 $label .= '<b>'.$langs->trans("Ref").':</b> '.$this->ref;
2957 if ($this->amount) {
2958 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
2959 }
2960
2961 $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">';
2962 $linkend = '</a>';
2963
2964 $result .= $linkstart;
2965 if ($withpicto) {
2966 $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);
2967 }
2968 if ($withpicto != 2) {
2969 $result .= ($this->ref ? $this->ref : $this->id);
2970 }
2971
2972 $result .= $linkend;
2973
2974 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2975 $result .= ' <span class="opacitymedium">(';
2976 }
2977 if ($option == 'showall') {
2978 $result .= $langs->trans("BankAccount").': ';
2979 $accountstatic = new Account($this->db);
2980 $accountstatic->id = $this->fk_account;
2981 $accountstatic->ref = $this->bank_account_ref;
2982 $accountstatic->label = $this->bank_account_label;
2983 $result .= $accountstatic->getNomUrl(0).', ';
2984 }
2985 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
2986 $result .= $langs->trans("BankLineConciliated").': ';
2987 $result .= yn($this->rappro);
2988 }
2989 if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) {
2990 $sql = "SELECT COUNT(rowid) as nb, MAX(piece_num) as banktransactionid FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
2991 $sql .= " WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->id);
2992 $resql = $this->db->query($sql);
2993 if ($resql) {
2994 $obj = $this->db->fetch_object($resql);
2995 if ($obj && $obj->nb) {
2996 $result .= ' - '.$langs->trans("Accounted").': <span title="'.$langs->trans("TransactionNumShort").' '.$obj->banktransactionid.'">'.yn(1).'</span>';
2997 } else {
2998 $result .= ' - '.$langs->trans("Accounted").': '.yn(0);
2999 }
3000 }
3001 }
3002 if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') {
3003 $result .= ')</span>';
3004 }
3005
3006 global $action, $hookmanager;
3007 $hookmanager->initHooks(array($this->element . 'dao'));
3008 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
3009 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
3010 if ($reshook > 0) {
3011 $result = $hookmanager->resPrint;
3012 } else {
3013 $result .= $hookmanager->resPrint;
3014 }
3015
3016 return $result;
3017 }
3018
3019
3026 public function getLibStatut($mode = 0)
3027 {
3028 return $this->LibStatut($this->status, $mode);
3029 }
3030
3031 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3039 public function LibStatut($status, $mode = 0)
3040 {
3041 // phpcs:enable
3042 return '';
3043 }
3044
3051 public function getVentilExportCompta($mode = 0)
3052 {
3053 $alreadydispatched = 0;
3054
3055 $type = 'bank';
3056
3057 $sql = " SELECT ".($mode ? 'DISTINCT piece_num' : 'COUNT(ab.rowid)')." as nb";
3058 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type = '".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id);
3059 $resql = $this->db->query($sql);
3060 if ($resql) {
3061 $obj = $this->db->fetch_object($resql);
3062 if ($obj) {
3063 $alreadydispatched = $obj->nb;
3064 }
3065 } else {
3066 $this->error = $this->db->lasterror();
3067 return -1;
3068 }
3069
3070 if ($alreadydispatched) {
3071 return $alreadydispatched;
3072 }
3073 return 0;
3074 }
3075}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
checkIbanForAccount($account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
Definition bank.lib.php:394
getIbanHumanReadable(Account $account)
Returns the iban human readable.
Definition bank.lib.php:419
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
Definition bank.lib.php:373
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
solde($option=0, $date_end='', $field='dateo')
Return current balance.
fetch($id, $ref='')
Load a bank account into memory from database.
__construct(DoliDB $db)
Constructor.
getNomUrl($withpicto=0, $mode='', $option='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return clickable name (with picto eventually)
getSepaCategoryPurpose()
Return the category purpose code to write into a SEPA file for this account (PmtTpInf/CtgyPurp/Cd).
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
const SEPA_CATEGORY_PURPOSES
Allowed codes for the category purpose of a SEPA payment (ISO 20022, ExternalCategoryPurpose1Code sub...
loadStateBoard($filteraccountid=0)
Load the indicators this->nb for the state board.
getCountryCode()
Return account country code.
getLibStatut($mode=0)
Return label of object status.
update_bban($user=null)
Update BBAN (RIB) account fields.
create($user, $notrigger=0)
Create bank account into database.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='', $banque='', $accountancycode='', $datev=null, $num_releve='', $amount_main_currency=null, $note_private='')
Add an entry into table llx_bank.
getBannerAddress($htmlkey, $object)
Return full address for banner.
error()
Return error.
info($id)
Load miscellaneous information for tab "Info".
const TYPE_CASH
Cash account.
update($user, $notrigger=0)
Update bank account card.
__toString()
Shows the account number in the appropriate format.
delete($user, $notrigger=0)
Delete bank account from database.
const TYPE_SAVINGS
Savings account.
getTooltipContentArray($params)
getTooltipContentArray
canBeConciliated()
Return if a bank account need to be conciliated.
can_be_deleted()
Indicates if an account can be deleted or not (without movements)
const TYPE_CURRENT
Current account.
setCategories($categories)
Sets object to supplied categories.
countAccountToReconcile()
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
verif()
Return if an account has valid information for Direct debit payment.
getSepaLocalInstrument()
Return the local instrument code to write into a SEPA file for this account (PmtTpInf/LclInstrm/Cd).
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
const SEPA_LOCAL_INSTRUMENTS
Allowed codes for the local instrument of a SEPA payment (ISO 20022, ExternalLocalInstrument1Code sub...
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
get_url($fk_bank=0, $url_id=0, $type='')
TODO Move this into AccountLine Return array with links from llx_bank_url.
LibStatut($status, $mode=0)
Return label of given object status.
Class to manage bank transaction lines.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
setErrorsFromObject($object)
setErrorsFromObject
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:494
div refaddress div address