dolibarr  13.0.2
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-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
10  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
31 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32 
33 
37 class Account extends CommonObject
38 {
42  public $element = 'bank_account';
43 
47  public $table_element = 'bank_account';
48 
52  public $picto = 'account';
53 
59  public $rowid;
60 
65  public $label;
66 
71  public $courant;
72 
77  public $type;
78 
83  public $bank;
84 
89  public $clos = self::STATUS_OPEN;
90 
95  public $rappro = 1;
96 
101  public $url;
102 
107  public $code_banque;
108 
113  public $code_guichet;
114 
119  public $number;
120 
125  public $cle_rib;
126 
131  public $bic;
132 
137  public $iban;
138 
143  public $proprio;
144 
149  public $owner_address;
150 
151  public $state_id;
152  public $state_code;
153  public $state;
154 
160  public $type_lib = array();
161 
167  public $status = array();
168 
173  public $account_number;
174 
178  public $fk_accountancy_journal;
179 
184  public $currency_code;
185 
191  public $account_currency_code;
192 
197  public $min_allowed;
198 
203  public $min_desired;
204 
209  public $comment;
210 
215  public $date_solde;
216 
217 
242  // BEGIN MODULEBUILDER PROPERTIES
246  public $fields = array(
247  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
248  'ref' =>array('type'=>'varchar(12)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'showoncombobox'=>1, 'position'=>25),
249  'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30),
250  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>35, 'index'=>1),
251  'bank' =>array('type'=>'varchar(60)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-1, 'position'=>40),
252  'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-1, 'position'=>45),
253  'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-1, 'position'=>50),
254  'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-1, 'position'=>55),
255  'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-1, 'position'=>60),
256  'bic' =>array('type'=>'varchar(11)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-1, 'position'=>65),
257  'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-1, 'position'=>70),
258  'country_iban' =>array('type'=>'varchar(2)', 'label'=>'Country iban', 'enabled'=>1, 'visible'=>-1, 'position'=>75),
259  'cle_iban' =>array('type'=>'varchar(2)', 'label'=>'Cle iban', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
260  'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-1, 'position'=>85),
261  'state_id' =>array('type'=>'integer', 'label'=>'State id', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
262  'fk_pays' =>array('type'=>'integer', 'label'=>'Fk pays', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>95),
263  'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
264  'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-1, 'position'=>105),
265  'courant' =>array('type'=>'smallint(6)', 'label'=>'Courant', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>110),
266  'clos' =>array('type'=>'smallint(6)', 'label'=>'Clos', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>115),
267  'rappro' =>array('type'=>'smallint(6)', 'label'=>'Rappro', 'enabled'=>1, 'visible'=>-1, 'position'=>120),
268  'url' =>array('type'=>'varchar(128)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>125),
269  'account_number' =>array('type'=>'varchar(32)', 'label'=>'Account number', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
270  'accountancy_journal' =>array('type'=>'varchar(20)', 'label'=>'Accountancy journal', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
271  'currency_code' =>array('type'=>'varchar(3)', 'label'=>'Currency code', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>140),
272  'min_allowed' =>array('type'=>'integer', 'label'=>'Min allowed', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
273  'min_desired' =>array('type'=>'integer', 'label'=>'Min desired', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
274  'comment' =>array('type'=>'text', 'label'=>'Comment', 'enabled'=>1, 'visible'=>-1, 'position'=>155),
275  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>156),
276  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>157),
277  'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>160),
278  'fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>165),
279  'note_public' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>170),
280  'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>175),
281  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
282  'extraparams' =>array('type'=>'varchar(255)', 'label'=>'Extraparams', 'enabled'=>1, 'visible'=>-1, 'position'=>185),
283  'fk_accountancy_journal' =>array('type'=>'integer', 'label'=>'Fk accountancy journal', 'enabled'=>1, 'visible'=>-1, 'position'=>190),
284  );
285  // END MODULEBUILDER PROPERTIES
286 
290  const TYPE_CURRENT = 1;
294  const TYPE_CASH = 2;
298  const TYPE_SAVINGS = 0;
299 
300  const STATUS_OPEN = 0;
301  const STATUS_CLOSED = 1;
302 
308  public function __construct(DoliDB $db)
309  {
310  global $langs;
311 
312  $this->db = $db;
313 
314  $this->solde = 0;
315 
316  $this->type_lib = array(
317  self::TYPE_SAVINGS => $langs->trans("BankType0"),
318  self::TYPE_CURRENT => $langs->trans("BankType1"),
319  self::TYPE_CASH => $langs->trans("BankType2"),
320  );
321 
322  $this->status = array(
323  self::STATUS_OPEN => $langs->trans("StatusAccountOpened"),
324  self::STATUS_CLOSED => $langs->trans("StatusAccountClosed")
325  );
326  }
327 
333  public function __toString()
334  {
335  $string = '';
336  foreach ($this->getFieldsToShow() as $val) {
337  if ($val == 'BankCode') {
338  $string .= $this->code_banque.' ';
339  } elseif ($val == 'BankAccountNumber') {
340  $string .= $this->number.' ';
341  } elseif ($val == 'DeskCode') {
342  $string .= $this->code_guichet.' ';
343  } elseif ($val == 'BankAccountNumberKey') {
344  $string .= $this->cle_rib.' ';
345  } elseif ($val == 'BIC') {
346  $string .= $this->bic.' ';
347  } elseif ($val == 'IBAN') {
348  $string .= $this->iban.' ';
349  }
350  }
351 
352  return trim($string);
353  }
354 
355 
361  public function canBeConciliated()
362  {
363  global $conf;
364 
365  if (empty($this->rappro)) return -1;
366  if ($this->courant == Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) return -2;
367  if ($this->clos) return -3;
368  return 1;
369  }
370 
371 
372  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
383  public function add_url_line($line_id, $url_id, $url, $label, $type)
384  {
385  // phpcs:enable
386  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
387  $sql .= "fk_bank";
388  $sql .= ", url_id";
389  $sql .= ", url";
390  $sql .= ", label";
391  $sql .= ", type";
392  $sql .= ") VALUES (";
393  $sql .= " ".((int) $line_id);
394  $sql .= ", '".$this->db->escape($url_id)."'";
395  $sql .= ", '".$this->db->escape($url)."'";
396  $sql .= ", '".$this->db->escape($label)."'";
397  $sql .= ", '".$this->db->escape($type)."'";
398  $sql .= ")";
399 
400  dol_syslog(get_class($this)."::add_url_line", LOG_DEBUG);
401  if ($this->db->query($sql))
402  {
403  $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
404  return $rowid;
405  } else {
406  $this->error = $this->db->lasterror();
407  return -1;
408  }
409  }
410 
411  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
421  public function get_url($fk_bank = '', $url_id = '', $type = '')
422  {
423  // phpcs:enable
424  $lines = array();
425 
426  // Check parameters
427  if (!empty($fk_bank) && (!empty($url_id) || !empty($type)))
428  {
429  $this->error = "ErrorBadParameter";
430  return -1;
431  }
432 
433  $sql = "SELECT fk_bank, url_id, url, label, type";
434  $sql .= " FROM ".MAIN_DB_PREFIX."bank_url";
435  if ($fk_bank > 0) {
436  $sql .= " WHERE fk_bank = ".$fk_bank;
437  } else { $sql .= " WHERE url_id = ".$url_id." AND type = '".$this->db->escape($type)."'";
438  }
439  $sql .= " ORDER BY type, label";
440 
441  dol_syslog(get_class($this)."::get_url", LOG_DEBUG);
442  $result = $this->db->query($sql);
443  if ($result)
444  {
445  $i = 0;
446  $num = $this->db->num_rows($result);
447  while ($i < $num)
448  {
449  $obj = $this->db->fetch_object($result);
450  // Anciens liens (pour compatibilite)
451  $lines[$i][0] = $obj->url;
452  $lines[$i][1] = $obj->url_id;
453  $lines[$i][2] = $obj->label;
454  $lines[$i][3] = $obj->type;
455  // Nouveaux liens
456  $lines[$i]['url'] = $obj->url;
457  $lines[$i]['url_id'] = $obj->url_id;
458  $lines[$i]['label'] = $obj->label;
459  $lines[$i]['type'] = $obj->type;
460  $lines[$i]['fk_bank'] = $obj->fk_bank;
461  $i++;
462  }
463  } else dol_print_error($this->db);
464 
465  return $lines;
466  }
467 
484  public function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur = '', $banque = '', $accountancycode = '', $datev = null)
485  {
486  // Deprecation warning
487  if (is_numeric($oper)) {
488  dol_syslog(__METHOD__.": using numeric operations is deprecated", LOG_WARNING);
489  }
490 
491  // Clean parameters
492  $emetteur = trim($emetteur);
493  $banque = trim($banque);
494 
495  $now = dol_now();
496 
497  if (is_numeric($oper)) // Clean operation to have a code instead of a rowid
498  {
499  $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement";
500  $sql .= " WHERE id=".$oper;
501  $sql .= " AND entity IN (".getEntity('c_paiement').")";
502  $resql = $this->db->query($sql);
503  if ($resql)
504  {
505  $obj = $this->db->fetch_object($resql);
506  $oper = $obj->code;
507  } else {
508  dol_print_error($this->db, 'Failed to get payment type code');
509  return -1;
510  }
511  }
512 
513  // Check parameters
514  if (!$oper)
515  {
516  $this->error = "oper not defined";
517  return -1;
518  }
519  if (!$this->rowid)
520  {
521  $this->error = "this->rowid not defined";
522  return -2;
523  }
524  if ($this->courant == Account::TYPE_CASH && $oper != 'LIQ')
525  {
526  $this->error = "ErrorCashAccountAcceptsOnlyCashMoney";
527  return -3;
528  }
529 
530  $this->db->begin();
531 
532  if (is_null($datev) || empty($datev)) $datev = $date;
533 
534  $accline = new AccountLine($this->db);
535  $accline->datec = $now;
536  $accline->dateo = $date;
537  $accline->datev = $datev;
538  $accline->label = $label;
539  $accline->amount = $amount;
540  $accline->fk_user_author = $user->id;
541  $accline->fk_account = $this->rowid;
542  $accline->fk_type = $oper;
543  $accline->numero_compte = $accountancycode;
544 
545  if ($num_chq) {
546  $accline->num_chq = $num_chq;
547  }
548 
549  if ($emetteur) {
550  $accline->emetteur = $emetteur;
551  }
552 
553  if ($banque) {
554  $accline->bank_chq = $banque;
555  }
556 
557  if ($accline->insert() > 0) {
558  if ($categorie > 0) {
559  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (";
560  $sql .= "lineid, fk_categ";
561  $sql .= ") VALUES (";
562  $sql .= $accline->id.", ".$categorie;
563  $sql .= ")";
564 
565  $result = $this->db->query($sql);
566  if (!$result) {
567  $this->error = $this->db->lasterror();
568  $this->db->rollback();
569 
570  return -3;
571  }
572  }
573 
574  $this->db->commit();
575 
576  return $accline->id;
577  } else {
578  $this->error = $accline->error;
579  $this->errors = $accline->errors;
580  $this->db->rollback();
581 
582  return -2;
583  }
584  }
585 
593  public function create(User $user, $notrigger = 0)
594  {
595  global $langs, $conf, $hookmanager;
596 
597  $error = 0;
598 
599  // Clean parameters
600  if (!$this->min_allowed) $this->min_allowed = 0;
601  if (!$this->min_desired) $this->min_desired = 0;
602  $this->state_id = ($this->state_id ? $this->state_id : $this->state_id);
603  $this->country_id = ($this->country_id ? $this->country_id : $this->country_id);
604 
605  // Check parameters
606  if (empty($this->country_id))
607  {
608  $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Country"));
609  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
610  return -1;
611  }
612  if (empty($this->ref))
613  {
614  $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref"));
615  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
616  return -1;
617  }
618  if (empty($this->date_solde))
619  {
620  $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateInitialBalance"));
621  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
622  return -1;
623  }
624 
625  // Chargement librairie pour acces fonction controle RIB
626  require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
627 
628  $now = dol_now();
629 
630  $this->db->begin();
631 
632  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (";
633  $sql .= "datec";
634  $sql .= ", ref";
635  $sql .= ", label";
636  $sql .= ", entity";
637  $sql .= ", account_number";
638  $sql .= ", fk_accountancy_journal";
639  $sql .= ", bank";
640  $sql .= ", code_banque";
641  $sql .= ", code_guichet";
642  $sql .= ", number";
643  $sql .= ", cle_rib";
644  $sql .= ", bic";
645  $sql .= ", iban_prefix";
646  $sql .= ", domiciliation";
647  $sql .= ", proprio";
648  $sql .= ", owner_address";
649  $sql .= ", currency_code";
650  $sql .= ", rappro";
651  $sql .= ", min_allowed";
652  $sql .= ", min_desired";
653  $sql .= ", comment";
654  $sql .= ", state_id";
655  $sql .= ", fk_pays";
656  $sql .= ") VALUES (";
657  $sql .= "'".$this->db->idate($now)."'";
658  $sql .= ", '".$this->db->escape($this->ref)."'";
659  $sql .= ", '".$this->db->escape($this->label)."'";
660  $sql .= ", ".$conf->entity;
661  $sql .= ", '".$this->db->escape($this->account_number)."'";
662  $sql .= ", ".($this->fk_accountancy_journal > 0 ? $this->db->escape($this->fk_accountancy_journal) : "null");
663  $sql .= ", '".$this->db->escape($this->bank)."'";
664  $sql .= ", '".$this->db->escape($this->code_banque)."'";
665  $sql .= ", '".$this->db->escape($this->code_guichet)."'";
666  $sql .= ", '".$this->db->escape($this->number)."'";
667  $sql .= ", '".$this->db->escape($this->cle_rib)."'";
668  $sql .= ", '".$this->db->escape($this->bic)."'";
669  $sql .= ", '".$this->db->escape($this->iban)."'";
670  $sql .= ", '".$this->db->escape($this->domiciliation)."'";
671  $sql .= ", '".$this->db->escape($this->proprio)."'";
672  $sql .= ", '".$this->db->escape($this->owner_address)."'";
673  $sql .= ", '".$this->db->escape($this->currency_code)."'";
674  $sql .= ", ".$this->rappro;
675  $sql .= ", ".price2num($this->min_allowed);
676  $sql .= ", ".price2num($this->min_desired);
677  $sql .= ", '".$this->db->escape($this->comment)."'";
678  $sql .= ", ".($this->state_id > 0 ? $this->state_id : "null");
679  $sql .= ", ".$this->country_id;
680  $sql .= ")";
681 
682  dol_syslog(get_class($this)."::create", LOG_DEBUG);
683  $resql = $this->db->query($sql);
684  if ($resql)
685  {
686  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
687 
688  $result = $this->update($user, 1);
689  if ($result > 0)
690  {
691  $accline = new AccountLine($this->db);
692  $accline->datec = $this->db->idate($now);
693  $accline->label = '('.$langs->trans("InitialBankBalance").')';
694  $accline->amount = price2num($this->solde);
695  $accline->fk_user_author = $user->id;
696  $accline->fk_account = $this->id;
697  $accline->datev = $this->db->idate($this->date_solde);
698  $accline->dateo = $this->db->idate($this->date_solde);
699  $accline->fk_type = 'SOLD';
700 
701  if ($accline->insert() < 0) {
702  $error++;
703  $this->error = $accline->error;
704  $this->errors = $accline->errors;
705  }
706 
707  if (!$error)
708  {
709  $result = $this->insertExtraFields();
710  if ($result < 0) $error++;
711  }
712 
713  if (!$error && !$notrigger)
714  {
715  // Call trigger
716  $result = $this->call_trigger('BANKACCOUNT_CREATE', $user);
717  if ($result < 0) $error++;
718  // End call triggers
719  }
720  } else {
721  $error++;
722  }
723  } else {
724  if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
725  {
726  $this->error = $langs->trans("ErrorBankLabelAlreadyExists");
727  $error++;
728  } else {
729  $this->error = $this->db->error()." sql=".$sql;
730  $error++;
731  }
732  }
733 
734  if (!$error)
735  {
736  $this->db->commit();
737  return $this->id;
738  } else {
739  $this->db->rollback();
740  return -1 * $error;
741  }
742  }
743 
751  public function update(User $user, $notrigger = 0)
752  {
753  global $langs, $conf, $hookmanager;
754 
755  $error = 0;
756 
757  $this->db->begin();
758 
759  // Clean parameters
760  $this->state_id = ($this->state_id ? $this->state_id : $this->state_id);
761  $this->country_id = ($this->country_id ? $this->country_id : $this->country_id);
762 
763  // Check parameters
764  if (empty($this->country_id))
765  {
766  $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Country"));
767  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
768  return -1;
769  }
770  if (empty($this->ref))
771  {
772  $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref"));
773  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
774  return -1;
775  }
776  if (!$this->label) $this->label = "???";
777 
778  $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET ";
779 
780  $sql .= " ref = '".$this->db->escape($this->ref)."'";
781  $sql .= ",label = '".$this->db->escape($this->label)."'";
782 
783  $sql .= ",courant = ".$this->courant;
784  $sql .= ",clos = ".$this->clos;
785  $sql .= ",rappro = ".$this->rappro;
786  $sql .= ",url = ".($this->url ? "'".$this->db->escape($this->url)."'" : "null");
787  $sql .= ",account_number = '".$this->db->escape($this->account_number)."'";
788  $sql .= ",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? $this->db->escape($this->fk_accountancy_journal) : "null");
789  $sql .= ",bank = '".$this->db->escape($this->bank)."'";
790  $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
791  $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
792  $sql .= ",number='".$this->db->escape($this->number)."'";
793  $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
794  $sql .= ",bic='".$this->db->escape($this->bic)."'";
795  $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
796  $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
797  $sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
798  $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
799 
800  $sql .= ",currency_code = '".$this->db->escape($this->currency_code)."'";
801 
802  $sql .= ",min_allowed = ".($this->min_allowed != '' ? price2num($this->min_allowed) : "null");
803  $sql .= ",min_desired = ".($this->min_desired != '' ? price2num($this->min_desired) : "null");
804  $sql .= ",comment = '".$this->db->escape($this->comment)."'";
805 
806  $sql .= ",state_id = ".($this->state_id > 0 ? $this->state_id : "null");
807  $sql .= ",fk_pays = ".$this->country_id;
808 
809  $sql .= " WHERE rowid = ".$this->id;
810 
811  dol_syslog(get_class($this)."::update", LOG_DEBUG);
812  $result = $this->db->query($sql);
813  if ($result)
814  {
815  // Actions on extra fields (by external module or standard code)
816  if (!$error)
817  {
818  $result = $this->insertExtraFields();
819  if ($result < 0) $error++;
820  }
821 
822  if (!$error && !$notrigger)
823  {
824  // Call trigger
825  $result = $this->call_trigger('BANKACCOUNT_UPDATE', $user);
826  if ($result < 0) $error++;
827  // End call triggers
828  }
829  } else {
830  $error++;
831  $this->error = $this->db->lasterror();
832  dol_print_error($this->db);
833  }
834 
835  if (!$error)
836  {
837  $this->db->commit();
838  return $this->id;
839  } else {
840  $this->db->rollback();
841  return -1 * $error;
842  }
843  }
844 
845 
846  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
853  public function update_bban(User $user = null)
854  {
855  // phpcs:enable
856  global $conf, $langs;
857 
858  // Clean parameters
859  $this->state_id = ($this->state_id ? $this->state_id : $this->state_id);
860  $this->country_id = ($this->country_id ? $this->country_id : $this->country_id);
861 
862  // Chargement librairie pour acces fonction controle RIB
863  require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
864 
865  dol_syslog(get_class($this)."::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
866 
867  // Check parameters
868  if (!$this->ref)
869  {
870  $this->error = $langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->trans("Ref"));
871  return -2;
872  }
873 
874  $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET ";
875  $sql .= " bank = '".$this->db->escape($this->bank)."'";
876  $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'";
877  $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'";
878  $sql .= ",number='".$this->db->escape($this->number)."'";
879  $sql .= ",cle_rib='".$this->db->escape($this->cle_rib)."'";
880  $sql .= ",bic='".$this->db->escape($this->bic)."'";
881  $sql .= ",iban_prefix = '".$this->db->escape($this->iban)."'";
882  $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
883  $sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
884  $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
885  $sql .= ",state_id = ".($this->state_id > 0 ? $this->state_id : "null");
886  $sql .= ",fk_pays = ".$this->country_id;
887  $sql .= " WHERE rowid = ".$this->id;
888  $sql .= " AND entity = ".$conf->entity;
889 
890  dol_syslog(get_class($this)."::update_bban", LOG_DEBUG);
891 
892  $result = $this->db->query($sql);
893  if ($result)
894  {
895  return 1;
896  } else {
897  $this->error = $this->db->lasterror();
898  dol_print_error($this->db);
899  return -1;
900  }
901  }
902 
903 
911  public function fetch($id, $ref = '')
912  {
913  global $conf;
914 
915  if (empty($id) && empty($ref))
916  {
917  $this->error = "ErrorBadParameters";
918  return -1;
919  }
920 
921  $sql = "SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
922  $sql .= " ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
923  $sql .= " ba.domiciliation, ba.proprio, ba.owner_address, ba.state_id, ba.fk_pays as country_id,";
924  $sql .= " ba.account_number, ba.fk_accountancy_journal, ba.currency_code,";
925  $sql .= " ba.min_allowed, ba.min_desired, ba.comment,";
926  $sql .= " ba.datec as date_creation, ba.tms as date_update,";
927  $sql .= ' c.code as country_code, c.label as country,';
928  $sql .= ' d.code_departement as state_code, d.nom as state';
929  $sql .= ' , aj.code as accountancy_journal';
930  $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
931  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON ba.fk_pays = c.rowid';
932  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON ba.state_id = d.rowid';
933  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal';
934  $sql .= " WHERE ba.entity IN (".getEntity($this->element).")";
935  if ($id) $sql .= " AND ba.rowid = ".$id;
936  if ($ref) $sql .= " AND ba.ref = '".$this->db->escape($ref)."'";
937 
938  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
939  $result = $this->db->query($sql);
940  if ($result)
941  {
942  if ($this->db->num_rows($result))
943  {
944  $obj = $this->db->fetch_object($result);
945 
946  $this->id = $obj->rowid;
947  $this->rowid = $obj->rowid;
948  $this->ref = $obj->ref;
949  $this->label = $obj->label;
950  $this->type = $obj->courant;
951  $this->courant = $obj->courant;
952  $this->bank = $obj->bank;
953  $this->clos = $obj->clos;
954  $this->rappro = $obj->rappro;
955  $this->url = $obj->url;
956 
957  $this->code_banque = $obj->code_banque;
958  $this->code_guichet = $obj->code_guichet;
959  $this->number = $obj->number;
960  $this->cle_rib = $obj->cle_rib;
961  $this->bic = $obj->bic;
962  $this->iban = $obj->iban;
963  $this->domiciliation = $obj->domiciliation;
964  $this->proprio = $obj->proprio;
965  $this->owner_address = $obj->owner_address;
966 
967  $this->state_id = $obj->state_id;
968  $this->state_code = $obj->state_code;
969  $this->state = $obj->state;
970 
971  $this->country_id = $obj->country_id;
972  $this->country_code = $obj->country_code;
973  $this->country = $obj->country;
974 
975  $this->account_number = $obj->account_number;
976  $this->fk_accountancy_journal = $obj->fk_accountancy_journal;
977  $this->accountancy_journal = $obj->accountancy_journal;
978 
979  $this->currency_code = $obj->currency_code;
980  $this->account_currency_code = $obj->currency_code;
981  $this->min_allowed = $obj->min_allowed;
982  $this->min_desired = $obj->min_desired;
983  $this->comment = $obj->comment;
984 
985  $this->date_creation = $this->db->jdate($obj->date_creation);
986  $this->date_update = $this->db->jdate($obj->date_update);
987 
988  // Retrieve all extrafield
989  // fetch optionals attributes and labels
990  $this->fetch_optionals();
991 
992  return 1;
993  } else {
994  return 0;
995  }
996  } else {
997  $this->error = $this->db->lasterror;
998  $this->errors[] = $this->error;
999  return -1;
1000  }
1001  }
1002 
1013  public function setCategories($categories)
1014  {
1015  // Handle single category
1016  if (!is_array($categories)) {
1017  $categories = array($categories);
1018  }
1019 
1020  // Get current categories
1021  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1022  $c = new Categorie($this->db);
1023  $existing = $c->containing($this->id, Categorie::TYPE_ACCOUNT, 'id');
1024 
1025  // Diff
1026  if (is_array($existing)) {
1027  $to_del = array_diff($existing, $categories);
1028  $to_add = array_diff($categories, $existing);
1029  } else {
1030  $to_del = array(); // Nothing to delete
1031  $to_add = $categories;
1032  }
1033 
1034  // Process
1035  foreach ($to_del as $del) {
1036  if ($c->fetch($del) > 0) {
1037  $c->del_type($this, Categorie::TYPE_ACCOUNT);
1038  }
1039  }
1040  foreach ($to_add as $add) {
1041  if ($c->fetch($add) > 0) {
1042  $c->add_type($this, Categorie::TYPE_ACCOUNT);
1043  }
1044  }
1045 
1046  return;
1047  }
1048 
1055  public function delete(User $user = null)
1056  {
1057  global $conf;
1058 
1059  $error = 0;
1060 
1061  $this->db->begin();
1062 
1063  // Delete link between tag and bank account
1064  if (!$error)
1065  {
1066  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
1067  $sql .= " WHERE fk_account = ".$this->id;
1068 
1069  $resql = $this->db->query($sql);
1070  if (!$resql)
1071  {
1072  $error++;
1073  $this->error = "Error ".$this->db->lasterror();
1074  }
1075  }
1076 
1077  if (!$error)
1078  {
1079  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
1080  $sql .= " WHERE rowid = ".$this->rowid;
1081 
1082  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1083  $result = $this->db->query($sql);
1084  if ($result)
1085  {
1086  // Remove extrafields
1087  if (!$error)
1088  {
1089  $result = $this->deleteExtraFields();
1090  if ($result < 0)
1091  {
1092  $error++;
1093  dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
1094  }
1095  }
1096  } else {
1097  $error++;
1098  $this->error = "Error ".$this->db->lasterror();
1099  }
1100  }
1101 
1102  if (!$error)
1103  {
1104  $this->db->commit();
1105  return 1;
1106  } else {
1107  $this->db->rollback();
1108  return -1;
1109  }
1110  }
1111 
1112 
1119  public function getLibStatut($mode = 0)
1120  {
1121  return $this->LibStatut($this->clos, $mode);
1122  }
1123 
1124  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1132  public function LibStatut($status, $mode = 0)
1133  {
1134  // phpcs:enable
1135  global $langs;
1136  $langs->load('banks');
1137 
1138  if ($status == self::STATUS_OPEN) {
1139  $label = $langs->trans("StatusAccountOpened");
1140  $labelshort = $langs->trans("StatusAccountOpened");
1141  $statusType = 'status4';
1142  } else {
1143  $label = $langs->trans("StatusAccountClosed");
1144  $labelshort = $langs->trans("StatusAccountClosed");
1145  $statusType = 'status5';
1146  }
1147 
1148  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
1149  }
1150 
1151 
1152  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1158  public function can_be_deleted()
1159  {
1160  // phpcs:enable
1161  $can_be_deleted = false;
1162 
1163  $sql = "SELECT COUNT(rowid) as nb";
1164  $sql .= " FROM ".MAIN_DB_PREFIX."bank";
1165  $sql .= " WHERE fk_account=".$this->id;
1166 
1167  $resql = $this->db->query($sql);
1168  if ($resql) {
1169  $obj = $this->db->fetch_object($resql);
1170  if ($obj->nb <= 1) $can_be_deleted = true; // Juste le solde
1171  } else {
1172  dol_print_error($this->db);
1173  }
1174  return $can_be_deleted;
1175  }
1176 
1177 
1183  public function error()
1184  {
1185  return $this->error;
1186  }
1187 
1194  public function solde($option = 0)
1195  {
1196  $solde = 0;
1197 
1198  $sql = "SELECT sum(amount) as amount";
1199  $sql .= " FROM ".MAIN_DB_PREFIX."bank";
1200  $sql .= " WHERE fk_account = ".$this->id;
1201  if ($option == 1) $sql .= " AND dateo <= '".$this->db->idate(dol_now())."'";
1202 
1203  $resql = $this->db->query($sql);
1204  if ($resql)
1205  {
1206  if ($this->db->num_rows($resql))
1207  {
1208  $obj = $this->db->fetch_object($resql);
1209  $solde = $obj->amount;
1210  }
1211  $this->db->free($resql);
1212  } else {
1213  $this->errors[] = $this->db->lasterror;
1214  return -1;
1215  }
1216 
1217  return price2num($solde, 'MU');
1218  }
1219 
1220  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1228  public function load_board(User $user, $filteraccountid = 0)
1229  {
1230  // phpcs:enable
1231  global $conf, $langs;
1232 
1233  if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
1234 
1235  $sql = "SELECT b.rowid, b.datev as datefin";
1236  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b,";
1237  $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
1238  $sql .= " WHERE b.rappro=0";
1239  $sql .= " AND b.fk_account = ba.rowid";
1240  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1241  $sql .= " AND (ba.rappro = 1 AND ba.courant != 2)"; // Compte rapprochable
1242  $sql .= " AND clos = 0";
1243  if ($filteraccountid) $sql .= " AND ba.rowid = ".$filteraccountid;
1244 
1245  $resql = $this->db->query($sql);
1246  if ($resql)
1247  {
1248  $langs->load("banks");
1249  $now = dol_now();
1250 
1251  require_once DOL_DOCUMENT_ROOT.'/core/class/workboardresponse.class.php';
1252 
1253  $response = new WorkboardResponse();
1254  $response->warning_delay = $conf->bank->rappro->warning_delay / 60 / 60 / 24;
1255  $response->label = $langs->trans("TransactionsToConciliate");
1256  $response->labelShort = $langs->trans("TransactionsToConciliateShort");
1257  $response->url = DOL_URL_ROOT.'/compta/bank/list.php?leftmenu=bank&amp;mainmenu=bank';
1258  $response->img = img_object('', "payment");
1259 
1260  while ($obj = $this->db->fetch_object($resql))
1261  {
1262  $response->nbtodo++;
1263  if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) {
1264  $response->nbtodolate++;
1265  }
1266  }
1267 
1268  return $response;
1269  } else {
1270  dol_print_error($this->db);
1271  $this->error = $this->db->error();
1272  return -1;
1273  }
1274  }
1275 
1276  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1282  public function load_state_board($filteraccountid = 0)
1283  {
1284  // phpcs:enable
1285  global $user;
1286 
1287  if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
1288 
1289  $sql = "SELECT count(b.rowid) as nb";
1290  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b,";
1291  $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
1292  $sql .= " WHERE b.fk_account = ba.rowid";
1293  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1294  $sql .= " AND (ba.rappro = 1 AND ba.courant != 2)"; // Compte rapprochable
1295  $sql .= " AND clos = 0";
1296  if ($filteraccountid) $sql .= " AND ba.rowid = ".$filteraccountid;
1297 
1298  $resql = $this->db->query($sql);
1299  if ($resql)
1300  {
1301  while ($obj = $this->db->fetch_object($resql))
1302  {
1303  $this->nb["banklines"] = $obj->nb;
1304  }
1305  $this->db->free($resql);
1306  } else {
1307  dol_print_error($this->db);
1308  $this->error = $this->db->error();
1309  return -1;
1310  }
1311  }
1312 
1313 
1319  public function countAccountToReconcile()
1320  {
1321  global $db, $conf, $user;
1322 
1323  //Protection against external users
1324  if ($user->socid) {
1325  return 0;
1326  }
1327 
1328  $nb = 0;
1329 
1330  $sql = "SELECT COUNT(ba.rowid) as nb";
1331  $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
1332  $sql .= " WHERE ba.rappro > 0 and ba.clos = 0";
1333  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1334  if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) $sql .= " AND ba.courant != 2";
1335  $resql = $this->db->query($sql);
1336  if ($resql)
1337  {
1338  $obj = $this->db->fetch_object($resql);
1339  $nb = $obj->nb;
1340  } else dol_print_error($this->db);
1341 
1342  return $nb;
1343  }
1344 
1355  public function getNomUrl($withpicto = 0, $mode = '', $option = '', $save_lastsearch_value = -1, $notooltip = 0)
1356  {
1357  global $conf, $langs, $user;
1358 
1359  $result = '';
1360  $label = img_picto('', $this->picto).' <u class="paddingrightnow">'.$langs->trans("BankAccount").'</u>';
1361  if (isset($this->status)) {
1362  $label .= ' '.$this->getLibStatut(5);
1363  }
1364  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
1365  $label .= '<br><b>'.$langs->trans('AccountNumber').':</b> '.$this->number;
1366  $label .= '<br><b>'.$langs->trans('IBAN').':</b> '.$this->iban;
1367  $label .= '<br><b>'.$langs->trans('BIC').':</b> '.$this->bic;
1368  $label .= '<br><b>'.$langs->trans("AccountCurrency").':</b> '.$this->currency_code;
1369 
1370  if (empty($user->rights->banque->lire) || !empty($user->socid))
1371  {
1372  $option = 'nolink';
1373  }
1374 
1375  if (!empty($conf->accounting->enabled))
1376  {
1377  include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
1378  $langs->load("accountancy");
1379  $label .= '<br><b>'.$langs->trans('AccountAccounting').':</b> '.length_accountg($this->account_number);
1380  $label .= '<br><b>'.$langs->trans('AccountancyJournal').':</b> '.$this->accountancy_journal;
1381  }
1382 
1383  $linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1384 
1385  $url = DOL_URL_ROOT.'/compta/bank/card.php?id='.$this->id;
1386  if ($mode == 'transactions')
1387  {
1388  $url = DOL_URL_ROOT.'/compta/bank/bankentries_list.php?id='.$this->id;
1389  } elseif ($mode == 'receipts')
1390  {
1391  $url = DOL_URL_ROOT.'/compta/bank/releve.php?account='.$this->id;
1392  }
1393 
1394  if ($option != 'nolink')
1395  {
1396  // Add param to save lastsearch_values or not
1397  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1398  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
1399  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
1400  }
1401 
1402  $linkstart = '<a href="'.$url.$linkclose;
1403  $linkend = '</a>';
1404 
1405  if ($option == 'nolink') {
1406  $linkstart = '';
1407  $linkend = '';
1408  }
1409 
1410  $result .= $linkstart;
1411  if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1412  if ($withpicto != 2) $result .= $this->ref.($option == 'reflabel' && $this->label ? ' - '.$this->label : '');
1413  $result .= $linkend;
1414 
1415  return $result;
1416  }
1417 
1418 
1419  // Method after here are common to Account and CompanyBankAccount
1420 
1421 
1427  public function verif()
1428  {
1429  require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
1430 
1431  $this->error_number = 0;
1432 
1433  // Call function to check BAN
1434 
1435  if (!checkIbanForAccount($this) || !checkSwiftForAccount($this))
1436  {
1437  $this->error_number = 12;
1438  $this->error_message = 'IBANSWIFTControlError';
1439  }
1440  /*if (! checkBanForAccount($this))
1441  {
1442  $this->error_number = 12;
1443  $this->error_message = 'BANControlError';
1444  }*/
1445 
1446  if ($this->error_number == 0)
1447  {
1448  return 1;
1449  } else {
1450  return 0;
1451  }
1452  }
1453 
1459  public function getCountryCode()
1460  {
1461  global $mysoc;
1462 
1463  // We return country code of bank account
1464  if (!empty($this->country_code)) return $this->country_code;
1465 
1466  // For backward compatibility, we try to guess country from other information
1467  if (!empty($this->iban))
1468  {
1469  // If IBAN defined, we can know country of account from it
1470  $reg = array();
1471  if (preg_match("/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) return $reg[1];
1472  }
1473 
1474  // If this class is linked to a third party
1475  if (!empty($this->socid))
1476  {
1477  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1478  $company = new Societe($this->db);
1479  $result = $company->fetch($this->socid);
1480  if (!empty($company->country_code)) return $company->country_code;
1481  }
1482 
1483  // We return country code of managed company
1484  if (!empty($mysoc->country_code)) return $mysoc->country_code;
1485 
1486  return '';
1487  }
1488 
1497  public function useDetailedBBAN()
1498  {
1499  $country_code = $this->getCountryCode();
1500 
1501  if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) return 1; // France, Spain, Gabon, ... - Not valid for CH
1502  if (in_array($country_code, array('AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) return 2; // Australia, England...
1503  return 0;
1504  }
1505 
1511  public function needIBAN()
1512  {
1513  $country_code = $this->getCountryCode();
1514 
1515  $country_code_in_EEC = array(
1516  'AT', // Austria
1517  'BE', // Belgium
1518  'BG', // Bulgaria
1519  'CY', // Cyprus
1520  'CZ', // Czech republic
1521  'DE', // Germany
1522  'DK', // Danemark
1523  'EE', // Estonia
1524  'ES', // Spain
1525  'FI', // Finland
1526  'FR', // France
1527  'GB', // United Kingdom
1528  'GR', // Greece
1529  'HR', // Croatia
1530  'NL', // Holland
1531  'HU', // Hungary
1532  'IE', // Ireland
1533  'IM', // Isle of Man - Included in UK
1534  'IT', // Italy
1535  'LT', // Lithuania
1536  'LU', // Luxembourg
1537  'LV', // Latvia
1538  'MC', // Monaco - Included in France
1539  'MT', // Malta
1540  //'NO', // Norway
1541  'PL', // Poland
1542  'PT', // Portugal
1543  'RO', // Romania
1544  'SE', // Sweden
1545  'SK', // Slovakia
1546  'SI', // Slovenia
1547  'UK', // United Kingdom
1548  //'CH', // Switzerland - No. Swizerland in not in EEC
1549  );
1550 
1551  if (in_array($country_code, $country_code_in_EEC)) return 1; // France, Spain, ...
1552  return 0;
1553  }
1554 
1561  public function info($id)
1562  {
1563  }
1564 
1579  public function getFieldsToShow($includeibanbic = 0)
1580  {
1581  //Get the required properties depending on the country
1582  $detailedBBAN = $this->useDetailedBBAN();
1583 
1584  if ($detailedBBAN == 0) {
1585  $fieldarray = array(
1586  'BankAccountNumber'
1587  );
1588  } elseif ($detailedBBAN == 2) {
1589  $fieldarray = array(
1590  'BankCode',
1591  'BankAccountNumber'
1592  );
1593  } else {
1594  $fieldarray = self::getAccountNumberOrder();
1595  }
1596 
1597  //if ($this->needIBAN()) { // return always IBAN and BIC (this was old behaviour)
1598  if ($includeibanbic)
1599  {
1600  $fieldarray[] = 'IBAN';
1601  $fieldarray[] = 'BIC';
1602  }
1603  //}
1604 
1605  //Get the order the properties are shown
1606  return $fieldarray;
1607  }
1608 
1619  public static function getAccountNumberOrder()
1620  {
1621  global $conf;
1622 
1623  $fieldlists = array(
1624  'BankCode',
1625  'DeskCode',
1626  'BankAccountNumber',
1627  'BankAccountNumberKey'
1628  );
1629 
1630  if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {
1631  if (is_numeric($conf->global->BANK_SHOW_ORDER_OPTION)) {
1632  if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') {
1633  $fieldlists = array(
1634  'BankCode',
1635  'DeskCode',
1636  'BankAccountNumberKey',
1637  'BankAccountNumber'
1638  );
1639  }
1640  } else {
1641  //Replace the old AccountNumber key with the new BankAccountNumber key
1642  $fieldlists = explode(
1643  ' ',
1644  preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION)
1645  );
1646  }
1647  }
1648 
1649  return $fieldlists;
1650  }
1651 
1652 
1660  public function initAsSpecimen()
1661  {
1662  $this->specimen = 1;
1663  $this->ref = 'MBA';
1664  $this->label = 'My Big Company Bank account';
1665  $this->bank = 'MyBank';
1666  $this->courant = Account::TYPE_CURRENT;
1667  $this->clos = Account::STATUS_OPEN;
1668  $this->code_banque = '123';
1669  $this->code_guichet = '456';
1670  $this->number = 'ABC12345';
1671  $this->cle_rib = '50';
1672  $this->bic = 'AA12';
1673  $this->iban = 'FR999999999';
1674  $this->domiciliation = 'My bank address';
1675  $this->proprio = 'Owner';
1676  $this->owner_address = 'Owner address';
1677  $this->country_id = 1;
1678  }
1679 }
1680 
1681 
1686 {
1690  public $error = '';
1691 
1695  public $db;
1696 
1700  public $element = 'bank';
1701 
1705  public $table_element = 'bank';
1706 
1710  public $picto = 'accountline';
1711 
1715  public $id;
1716 
1720  public $ref;
1721 
1727  public $datec;
1728 
1734  public $dateo;
1735 
1741  public $datev;
1742 
1743  public $amount;
1744 
1748  public $fk_user_author;
1749 
1753  public $fk_user_rappro;
1754 
1758  public $fk_type;
1759 
1763  public $fk_bordereau;
1764 
1768  public $fk_account;
1769 
1773  public $bank_account_ref;
1774 
1778  public $bank_account_label;
1779 
1783  public $numero_compte;
1784 
1788  public $emetteur;
1789 
1790  public $rappro; // Is it conciliated
1791  public $num_releve; // If conciliated, what is bank statement
1792  public $num_chq; // Num of cheque
1793  public $bank_chq; // Bank of cheque
1794 
1798  public $label;
1799 
1800  public $note;
1801 
1802 
1803 
1809  public function __construct(DoliDB $db)
1810  {
1811  $this->db = $db;
1812  }
1813 
1822  public function fetch($rowid, $ref = '', $num = '')
1823  {
1824  global $conf;
1825 
1826  // Check parameters
1827  if (empty($rowid) && empty($ref) && empty($num)) return -1;
1828 
1829  $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
1830  $sql .= " b.fk_user_author, b.fk_user_rappro,";
1831  $sql .= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
1832  $sql .= " b.fk_bordereau, b.banque, b.emetteur,";
1833  //$sql.= " b.author"; // Is this used ?
1834  $sql .= " ba.ref as bank_account_ref, ba.label as bank_account_label";
1835  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b,";
1836  $sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
1837  $sql .= " WHERE b.fk_account = ba.rowid";
1838  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
1839  if ($num) $sql .= " AND b.num_chq='".$this->db->escape($num)."'";
1840  elseif ($ref) $sql .= " AND b.rowid='".$this->db->escape($ref)."'";
1841  else $sql .= " AND b.rowid = ".((int) $rowid);
1842 
1843  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1844  $result = $this->db->query($sql);
1845  if ($result)
1846  {
1847  $ret = 0;
1848 
1849  $obj = $this->db->fetch_object($result);
1850  if ($obj)
1851  {
1852  $this->id = $obj->rowid;
1853  $this->rowid = $obj->rowid;
1854  $this->ref = $obj->rowid;
1855 
1856  $this->datec = $obj->datec;
1857  $this->datev = $obj->datev;
1858  $this->dateo = $obj->dateo;
1859  $this->amount = $obj->amount;
1860  $this->label = $obj->label;
1861  $this->note = $obj->note;
1862 
1863  $this->fk_user_author = $obj->fk_user_author;
1864  $this->fk_user_rappro = $obj->fk_user_rappro;
1865 
1866  $this->fk_type = $obj->fk_type; // Type of transaction
1867  $this->rappro = $obj->rappro;
1868  $this->num_releve = $obj->num_releve;
1869 
1870  $this->num_chq = $obj->num_chq;
1871  $this->bank_chq = $obj->banque;
1872  $this->fk_bordereau = $obj->fk_bordereau;
1873 
1874  $this->fk_account = $obj->fk_account;
1875  $this->bank_account_ref = $obj->bank_account_ref;
1876  $this->bank_account_label = $obj->bank_account_label;
1877 
1878  $ret = 1;
1879  }
1880  $this->db->free($result);
1881  return $ret;
1882  } else {
1883  return -1;
1884  }
1885  }
1886 
1892  public function insert()
1893  {
1894  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (";
1895  $sql .= "datec";
1896  $sql .= ", dateo";
1897  $sql .= ", datev";
1898  $sql .= ", label";
1899  $sql .= ", amount";
1900  $sql .= ", fk_user_author";
1901  $sql .= ", num_chq";
1902  $sql .= ", fk_account";
1903  $sql .= ", fk_type";
1904  $sql .= ", emetteur,banque";
1905  $sql .= ", rappro";
1906  $sql .= ", numero_compte";
1907  $sql .= ") VALUES (";
1908  $sql .= "'".$this->db->idate($this->datec)."'";
1909  $sql .= ", '".$this->db->idate($this->dateo)."'";
1910  $sql .= ", '".$this->db->idate($this->datev)."'";
1911  $sql .= ", '".$this->db->escape($this->label)."'";
1912  $sql .= ", ".price2num($this->amount);
1913  $sql .= ", ".($this->fk_user_author > 0 ? $this->fk_user_author : "null");
1914  $sql .= ", ".($this->num_chq ? "'".$this->db->escape($this->num_chq)."'" : "null");
1915  $sql .= ", '".$this->db->escape($this->fk_account)."'";
1916  $sql .= ", '".$this->db->escape($this->fk_type)."'";
1917  $sql .= ", ".($this->emetteur ? "'".$this->db->escape($this->emetteur)."'" : "null");
1918  $sql .= ", ".($this->bank_chq ? "'".$this->db->escape($this->bank_chq)."'" : "null");
1919  $sql .= ", ".(int) $this->rappro;
1920  $sql .= ", ".($this->numero_compte ? "'".$this->db->escape($this->numero_compte)."'" : "''");
1921  $sql .= ")";
1922 
1923  dol_syslog(get_class($this)."::insert", LOG_DEBUG);
1924  $resql = $this->db->query($sql);
1925 
1926  if (!$resql) {
1927  $this->error = $this->db->lasterror();
1928  return -1;
1929  }
1930 
1931  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank');
1932 
1933  return $this->id;
1934  }
1935 
1942  public function delete(User $user = null)
1943  {
1944  global $conf;
1945 
1946  $nbko = 0;
1947 
1948  if ($this->rappro)
1949  {
1950  // Protection to avoid any delete of consolidated lines
1951  $this->error = "ErrorDeleteNotPossibleLineIsConsolidated";
1952  return -1;
1953  }
1954 
1955  $this->db->begin();
1956 
1957  // Protection to avoid any delete of accounted lines. Protection on by default
1958  if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING))
1959  {
1960  $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".$this->id;
1961  $resql = $this->db->query($sql);
1962  if ($resql) {
1963  $obj = $this->db->fetch_object($resql);
1964  if ($obj && $obj->nb) {
1965  $this->error = 'ErrorRecordAlreadyInAccountingDeletionNotPossible';
1966  $this->db->rollback();
1967  return -1;
1968  }
1969  } else {
1970  $this->error = $this->db->lasterror();
1971  $this->db->rollback();
1972  return -1;
1973  }
1974  }
1975 
1976  // Delete urls
1977  $result = $this->delete_urls($user);
1978  if ($result < 0)
1979  {
1980  $nbko++;
1981  }
1982 
1983  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".(int) $this->rowid;
1984  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1985  $result = $this->db->query($sql);
1986  if (!$result) $nbko++;
1987 
1988  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".(int) $this->rowid;
1989  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1990  $result = $this->db->query($sql);
1991  if (!$result) $nbko++;
1992 
1993  if (!$nbko)
1994  {
1995  $this->db->commit();
1996  return 1;
1997  } else {
1998  $this->db->rollback();
1999  return -$nbko;
2000  }
2001  }
2002 
2003 
2004  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011  public function delete_urls(User $user = null)
2012  {
2013  // phpcs:enable
2014  $nbko = 0;
2015 
2016  if ($this->rappro)
2017  {
2018  // Protection to avoid any delete of consolidated lines
2019  $this->error = "ErrorDeleteNotPossibleLineIsConsolidated";
2020  return -1;
2021  }
2022 
2023  $this->db->begin();
2024 
2025  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".(int) $this->rowid;
2026  dol_syslog(get_class($this)."::delete_urls", LOG_DEBUG);
2027  $result = $this->db->query($sql);
2028  if (!$result) $nbko++;
2029 
2030  if (!$nbko)
2031  {
2032  $this->db->commit();
2033  return 1;
2034  } else {
2035  $this->db->rollback();
2036  return -$nbko;
2037  }
2038  }
2039 
2040 
2048  public function update(User $user, $notrigger = 0)
2049  {
2050  $this->db->begin();
2051 
2052  $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2053  $sql .= " amount = ".price2num($this->amount).",";
2054  $sql .= " datev='".$this->db->idate($this->datev)."',";
2055  $sql .= " dateo='".$this->db->idate($this->dateo)."'";
2056  $sql .= " WHERE rowid = ".$this->rowid;
2057 
2058  dol_syslog(get_class($this)."::update", LOG_DEBUG);
2059  $resql = $this->db->query($sql);
2060  if ($resql)
2061  {
2062  $this->db->commit();
2063  return 1;
2064  } else {
2065  $this->db->rollback();
2066  $this->error = $this->db->error();
2067  return -1;
2068  }
2069  }
2070 
2071 
2072  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2081  public function update_conciliation(User $user, $cat, $conciliated = 1)
2082  {
2083  // phpcs:enable
2084  global $conf, $langs;
2085 
2086  $this->db->begin();
2087 
2088  // Check statement field
2089  if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE))
2090  {
2091  if (!preg_match('/'.$conf->global->BANK_STATEMENT_REGEX_RULE.'/', $this->num_releve))
2092  {
2093  $this->errors[] = $langs->trans("ErrorBankStatementNameMustFollowRegex", $conf->global->BANK_STATEMENT_REGEX_RULE);
2094  return -1;
2095  }
2096  }
2097 
2098  $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2099  $sql .= " rappro = ".$conciliated;
2100  $sql .= ", num_releve = '".$this->db->escape($this->num_releve)."'";
2101  if ($conciliated) $sql .= ", fk_user_rappro = ".$user->id;
2102  $sql .= " WHERE rowid = ".$this->id;
2103 
2104  dol_syslog(get_class($this)."::update_conciliation", LOG_DEBUG);
2105  $resql = $this->db->query($sql);
2106  if ($resql)
2107  {
2108  if (!empty($cat))
2109  {
2110  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (";
2111  $sql .= "lineid";
2112  $sql .= ", fk_categ";
2113  $sql .= ") VALUES (";
2114  $sql .= $this->id;
2115  $sql .= ", ".$cat;
2116  $sql .= ")";
2117 
2118  dol_syslog(get_class($this)."::update_conciliation", LOG_DEBUG);
2119  $this->db->query($sql);
2120 
2121  // No error check. Can fail if category already affected
2122  }
2123 
2124  $this->rappro = 1;
2125 
2126  $this->db->commit();
2127  return 1;
2128  } else {
2129  $this->db->rollback();
2130  return -1;
2131  }
2132  }
2133 
2134 
2135  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2143  public function datev_change($rowid, $sign = 1)
2144  {
2145  // phpcs:enable
2146  $sql = "SELECT datev FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid;
2147  $resql = $this->db->query($sql);
2148  if ($resql)
2149  {
2150  $obj = $this->db->fetch_object($resql);
2151  $newdate = $this->db->jdate($obj->datev) + (3600 * 24 * $sign);
2152 
2153  $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2154  $sql .= " datev = '".$this->db->idate($newdate)."'";
2155  $sql .= " WHERE rowid = ".$rowid;
2156 
2157  $result = $this->db->query($sql);
2158  if ($result)
2159  {
2160  if ($this->db->affected_rows($result))
2161  {
2162  return 1;
2163  }
2164  } else {
2165  dol_print_error($this->db);
2166  return 0;
2167  }
2168  } else dol_print_error($this->db);
2169  return 0;
2170  }
2171 
2172  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2179  public function datev_next($id)
2180  {
2181  // phpcs:enable
2182  return $this->datev_change($id, 1);
2183  }
2184 
2185  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2192  public function datev_previous($id)
2193  {
2194  // phpcs:enable
2195  return $this->datev_change($id, -1);
2196  }
2197 
2198 
2199  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2207  public function dateo_change($rowid, $sign = 1)
2208  {
2209  // phpcs:enable
2210  $sql = "SELECT dateo FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid;
2211  $resql = $this->db->query($sql);
2212  if ($resql)
2213  {
2214  $obj = $this->db->fetch_object($resql);
2215  $newdate = $this->db->jdate($obj->dateo) + (3600 * 24 * $sign);
2216 
2217  $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
2218  $sql .= " dateo = '".$this->db->idate($newdate)."'";
2219  $sql .= " WHERE rowid = ".$rowid;
2220 
2221  $result = $this->db->query($sql);
2222  if ($result)
2223  {
2224  if ($this->db->affected_rows($result))
2225  {
2226  return 1;
2227  }
2228  } else {
2229  dol_print_error($this->db);
2230  return 0;
2231  }
2232  } else dol_print_error($this->db);
2233  return 0;
2234  }
2235 
2236  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2243  public function dateo_next($id)
2244  {
2245  // phpcs:enable
2246  return $this->dateo_change($id, 1);
2247  }
2248 
2249  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2256  public function dateo_previous($id)
2257  {
2258  // phpcs:enable
2259  return $this->dateo_change($id, -1);
2260  }
2261 
2262 
2269  public function info($id)
2270  {
2271  $sql = 'SELECT b.rowid, b.datec, b.tms as datem,';
2272  $sql .= ' b.fk_user_author, b.fk_user_rappro';
2273  $sql .= ' FROM '.MAIN_DB_PREFIX.'bank as b';
2274  $sql .= ' WHERE b.rowid = '.$id;
2275 
2276  $result = $this->db->query($sql);
2277  if ($result)
2278  {
2279  if ($this->db->num_rows($result))
2280  {
2281  $obj = $this->db->fetch_object($result);
2282  $this->id = $obj->rowid;
2283 
2284  if ($obj->fk_user_author)
2285  {
2286  $cuser = new User($this->db);
2287  $cuser->fetch($obj->fk_user_author);
2288  $this->user_creation = $cuser;
2289  }
2290  if ($obj->fk_user_rappro)
2291  {
2292  $ruser = new User($this->db);
2293  $ruser->fetch($obj->fk_user_rappro);
2294  $this->user_rappro = $ruser;
2295  }
2296 
2297  $this->date_creation = $this->db->jdate($obj->datec);
2298  $this->date_modification = $this->db->jdate($obj->datem);
2299  //$this->date_rappro = $obj->daterappro; // Not yet managed
2300  }
2301  $this->db->free($result);
2302  } else {
2303  dol_print_error($this->db);
2304  }
2305  }
2306 
2307 
2317  public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0)
2318  {
2319  global $langs;
2320 
2321  $result = '';
2322 
2323  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Transaction").'</u>:<br>';
2324  $label .= '<b>'.$langs->trans("Ref").':</b> '.$this->ref;
2325 
2326  $linkstart = '<a href="'.DOL_URL_ROOT.'/compta/bank/line.php?rowid='.$this->id.'&save_lastsearch_values=1" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
2327  $linkend = '</a>';
2328 
2329  $result .= $linkstart;
2330  if ($withpicto) $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);
2331  if ($withpicto != 2) $result .= ($this->ref ? $this->ref : $this->id);
2332  $result .= $linkend;
2333 
2334  if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') $result .= ' <span class="opacitymedium">(';
2335  if ($option == 'showall')
2336  {
2337  $result .= $langs->trans("BankAccount").': ';
2338  $accountstatic = new Account($this->db);
2339  $accountstatic->id = $this->fk_account;
2340  $accountstatic->ref = $this->bank_account_ref;
2341  $accountstatic->label = $this->bank_account_label;
2342  $result .= $accountstatic->getNomUrl(0).', ';
2343  }
2344  if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted')
2345  {
2346  $result .= $langs->trans("BankLineConciliated").': ';
2347  $result .= yn($this->rappro);
2348  }
2349  if ($option == 'showall' || $option == 'showconciliatedandaccounted')
2350  {
2351  $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".$this->id;
2352  $resql = $this->db->query($sql);
2353  if ($resql) {
2354  $obj = $this->db->fetch_object($resql);
2355  if ($obj && $obj->nb) {
2356  $result .= ' - '.$langs->trans("Accounted").': '.yn(1);
2357  } else {
2358  $result .= ' - '.$langs->trans("Accounted").': '.yn(0);
2359  }
2360  }
2361  }
2362  if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') $result .= ')</span>';
2363 
2364  return $result;
2365  }
2366 
2367 
2374  public function getLibStatut($mode = 0)
2375  {
2376  return $this->LibStatut($this->status, $mode);
2377  }
2378 
2379  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2387  public function LibStatut($status, $mode = 0)
2388  {
2389  // phpcs:enable
2390  global $langs;
2391  //$langs->load('companies');
2392  /*
2393  if ($mode == 0)
2394  {
2395  if ($status==0) return $langs->trans("ActivityCeased");
2396  if ($status==1) return $langs->trans("InActivity");
2397  }
2398  if ($mode == 1)
2399  {
2400  if ($status==0) return $langs->trans("ActivityCeased");
2401  if ($status==1) return $langs->trans("InActivity");
2402  }
2403  if ($mode == 2)
2404  {
2405  if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2406  if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2407  }
2408  if ($mode == 3)
2409  {
2410  if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2411  if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2412  }
2413  if ($mode == 4)
2414  {
2415  if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2416  if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2417  }
2418  if ($mode == 5)
2419  {
2420  if ($status==0) return $langs->trans("ActivityCeased").' '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2421  if ($status==1) return $langs->trans("InActivity").' '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2422  }*/
2423  }
2424 
2425 
2431  public function getVentilExportCompta()
2432  {
2433  $alreadydispatched = 0;
2434 
2435  $type = 'bank';
2436 
2437  $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 = ".$this->id;
2438  $resql = $this->db->query($sql);
2439  if ($resql)
2440  {
2441  $obj = $this->db->fetch_object($resql);
2442  if ($obj)
2443  {
2444  $alreadydispatched = $obj->nb;
2445  }
2446  } else {
2447  $this->error = $this->db->lasterror();
2448  return -1;
2449  }
2450 
2451  if ($alreadydispatched)
2452  {
2453  return 1;
2454  }
2455  return 0;
2456  }
2457 }
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
static getAccountNumberOrder()
Returns the components of the bank account in order.
can_be_deleted()
Renvoi si un compte peut etre supprimer ou non (sans mouvements)
update_bban(User $user=null)
Update BBAN (RIB) account fields.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
useDetailedBBAN()
Return if a bank account is defined with detailed information (bank code, desk code, number and key).
load_board(User $user, $filteraccountid=0)
Load indicators for dashboard (this-&gt;nbtodo and this-&gt;nbtodolate)
Class to manage Dolibarr database access.
datev_next($id)
Increase value date of a rowid.
Class to manage bank transaction lines.
error()
Return error.
const TYPE_CURRENT
Current account.
checkSwiftForAccount($account)
Check SWIFT informations for a bank account.
Definition: bank.lib.php:251
canBeConciliated()
Return if a bank account need to be conciliated.
__construct(DoliDB $db)
Constructor.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage bank accounts.
getLibStatut($mode=0)
Return label of object status.
insert()
Inserts a transaction to a bank account.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
LibStatut($status, $mode=0)
Renvoi le libelle d&#39;un statut donne.
dateo_change($rowid, $sign=1)
Increase/decrease operation date of a rowid.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage categories.
needIBAN()
Return 1 if IBAN / BIC is mandatory (otherwise option)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dateo_previous($id)
Decrease operation date of a rowid.
setCategories($categories)
Sets object to supplied categories.
addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur= '', $banque= '', $accountancycode= '', $datev=null)
Add an entry into table &quot;.MAIN_DB_PREFIX.&quot;bank.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
getCountryCode()
Return account country code.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getLibStatut($mode=0)
Return label of status (activity, closed)
get_url($fk_bank= '', $url_id= '', $type= '')
TODO Move this into AccountLine Return array with links from llx_bank_url.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
delete_urls(User $user=null)
Delete bank line records.
datev_change($rowid, $sign=1)
Increase/decrease value date of a rowid.
update_conciliation(User $user, $cat, $conciliated=1)
Update conciliation field.
verif()
Return if an account has valid information for Direct debit payment.
update(User $user, $notrigger=0)
Update bank account record in database.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this-&gt;array_options This method is in most cases call...
getNomUrl($withpicto=0, $maxlen=0, $option= '', $notooltip=0)
Return clickable name (with picto eventually)
const TYPE_CASH
Cash account.
print $_SERVER["PHP_SELF"]
Edit parameters.
add_url_line($line_id, $url_id, $url, $label, $type)
Add a link between bank line record and its source.
__toString()
Shows the account number in the appropriate format.
create(User $user, $notrigger=0)
Create bank account into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
solde($option=0)
Return current sold.
checkIbanForAccount($account)
Check IBAN number informations for a bank account.
Definition: bank.lib.php:267
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
load_state_board($filteraccountid=0)
Charge indicateurs this-&gt;nb de tableau de bord.
getNomUrl($withpicto=0, $mode= '', $option= '', $save_lastsearch_value=-1, $notooltip=0)
Return clicable name (with picto eventually)
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getFieldsToShow($includeibanbic=0)
Returns the fields in order that this bank account should show to the user Will return an array with ...
update(User $user, $notrigger=0)
Update bank account card.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
const TYPE_SAVINGS
Savings account.
info($id)
Load miscellaneous information for tab &quot;Info&quot;.
info($id)
Load miscellaneous information for tab &quot;Info&quot;.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
dateo_next($id)
Increase operation date of a rowid.
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
getVentilExportCompta()
Return if a bank line was dispatched into bookkeeping.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
datev_previous($id)
Decrease value date of a rowid.
fetch($rowid, $ref= '', $num= '')
Load into memory content of a bank transaction line.
if(!empty($search_group)) natural_search(array("g.nom"g note
Definition: list.php:122
fetch($id, $ref= '')
Load a bank account into memory from database.
LibStatut($status, $mode=0)
Return label of given object status.
countAccountToReconcile()
Load indicators for dashboard (this-&gt;nbtodo and this-&gt;nbtodolate)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...