PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/bank/class/account.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 1467 lines | 998 code | 186 blank | 283 comment | 136 complexity | 6144c3c58777626af59d0237b5ec8954 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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@capnetworks.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/bank/class/account.class.php
  23. * \ingroup banque
  24. * \brief File of class to manage bank accounts
  25. */
  26. require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
  27. /**
  28. * Class to manage bank accounts
  29. */
  30. class Account extends CommonObject
  31. {
  32. public $element='bank_account';
  33. public $table_element='bank_account';
  34. var $rowid; // deprecated
  35. var $id;
  36. var $ref;
  37. var $label;
  38. //! 1=Compte courant/check/carte, 2=Compte liquide, 0=Compte épargne
  39. var $courant;
  40. var $type; // same as courant
  41. //! Name
  42. var $bank;
  43. var $clos;
  44. var $rappro=1; // If bank need to be conciliated
  45. var $url;
  46. //! BBAN field for French Code banque
  47. var $code_banque;
  48. //! BBAN field for French Code guichet
  49. var $code_guichet;
  50. //! BBAN main account number
  51. var $number;
  52. //! BBAN field for French Cle de controle
  53. var $cle_rib;
  54. //! BIC/SWIFT number
  55. var $bic;
  56. //! IBAN number (International Bank Account Number)
  57. var $iban_prefix;
  58. var $proprio;
  59. var $adresse_proprio;
  60. var $fk_departement; // deprecated
  61. var $departement_code; // deprecated
  62. var $departement; // deprecated
  63. var $state_id;
  64. var $state_code;
  65. var $state;
  66. var $fk_pays; // deprecated
  67. var $pays_code; // deprecated
  68. var $pays; // deprecated
  69. var $country_id;
  70. var $country_code;
  71. var $country;
  72. var $type_lib=array();
  73. var $account_number;
  74. var $currency_code;
  75. var $min_allowed;
  76. var $min_desired;
  77. var $comment;
  78. /**
  79. * Constructor
  80. *
  81. * @param DoliDB $db Database handler
  82. */
  83. function __construct($db = '')
  84. {
  85. global $langs;
  86. $this->db = $db;
  87. $this->clos = 0;
  88. $this->solde = 0;
  89. $this->type_lib[0]=$langs->trans("BankType0");
  90. $this->type_lib[1]=$langs->trans("BankType1");
  91. $this->type_lib[2]=$langs->trans("BankType2");
  92. $this->status[0]=$langs->trans("StatusAccountOpened");
  93. $this->status[1]=$langs->trans("StatusAccountClosed");
  94. return 1;
  95. }
  96. /**
  97. * Return if a bank account need to be conciliated
  98. *
  99. * @return int 1 if need to be concialiated, < 0 otherwise.
  100. */
  101. function canBeConciliated()
  102. {
  103. if (empty($this->rappro)) return -1;
  104. if ($this->courant == 2) return -2;
  105. if ($this->clos) return -3;
  106. return 1;
  107. }
  108. /**
  109. * Add a link between bank line record and its source
  110. *
  111. * @param int $line_id Id ecriture bancaire
  112. * @param int $url_id Id parametre url
  113. * @param string $url Url
  114. * @param string $label Link label
  115. * @param string $type Type of link ('payment', 'company', 'member', ...)
  116. * @return int <0 if KO, id line if OK
  117. */
  118. function add_url_line($line_id, $url_id, $url, $label, $type)
  119. {
  120. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
  121. $sql.= "fk_bank";
  122. $sql.= ", url_id";
  123. $sql.= ", url";
  124. $sql.= ", label";
  125. $sql.= ", type";
  126. $sql.= ") VALUES (";
  127. $sql.= "'".$line_id."'";
  128. $sql.= ", '".$url_id."'";
  129. $sql.= ", '".$url."'";
  130. $sql.= ", '".$this->db->escape($label)."'";
  131. $sql.= ", '".$type."'";
  132. $sql.= ")";
  133. dol_syslog(get_class($this)."::add_url_line sql=".$sql);
  134. if ($this->db->query($sql))
  135. {
  136. $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_url");
  137. return $rowid;
  138. }
  139. else
  140. {
  141. $this->error=$this->db->lasterror();
  142. dol_syslog(get_class($this)."::add_url_line ".$this->error, LOG_ERR);
  143. return -1;
  144. }
  145. }
  146. /**
  147. * TODO Move this into AccountLine
  148. * Return array with links from llx_bank_url
  149. *
  150. * @param int $fk_bank To search using bank transaction id
  151. * @param int $url_id To search using link to
  152. * @param string $type To search using type
  153. * @return array Array of links
  154. */
  155. function get_url($fk_bank='', $url_id='', $type='')
  156. {
  157. $lines = array();
  158. // Check parameters
  159. if (! empty($fk_bank) && (! empty($url_id) || ! empty($type)))
  160. {
  161. $this->error="ErrorBadParameter";
  162. return -1;
  163. }
  164. $sql = "SELECT fk_bank, url_id, url, label, type";
  165. $sql.= " FROM ".MAIN_DB_PREFIX."bank_url";
  166. if ($fk_bank > 0) {
  167. $sql.= " WHERE fk_bank = ".$fk_bank;
  168. }
  169. else { $sql.= " WHERE url_id = ".$url_id." AND type = '".$type."'";
  170. }
  171. $sql.= " ORDER BY type, label";
  172. dol_syslog(get_class($this)."::get_url sql=".$sql);
  173. $result = $this->db->query($sql);
  174. if ($result)
  175. {
  176. $i = 0;
  177. $num = $this->db->num_rows($result);
  178. while ($i < $num)
  179. {
  180. $obj = $this->db->fetch_object($result);
  181. // Anciens liens (pour compatibilite)
  182. $lines[$i][0] = $obj->url;
  183. $lines[$i][1] = $obj->url_id;
  184. $lines[$i][2] = $obj->label;
  185. $lines[$i][3] = $obj->type;
  186. // Nouveaux liens
  187. $lines[$i]['url'] = $obj->url;
  188. $lines[$i]['url_id'] = $obj->url_id;
  189. $lines[$i]['label'] = $obj->label;
  190. $lines[$i]['type'] = $obj->type;
  191. $lines[$i]['fk_bank'] = $obj->fk_bank;
  192. $i++;
  193. }
  194. }
  195. else dol_print_error($this->db);
  196. return $lines;
  197. }
  198. /**
  199. * Add an entry into table ".MAIN_DB_PREFIX."bank
  200. *
  201. * @param timsestmap $date Date operation
  202. * @param string $oper 1,2,3,4... (deprecated) or TYP,VIR,PRE,LIQ,VAD,CB,CHQ...
  203. * @param string $label Descripton
  204. * @param float $amount Amount
  205. * @param string $num_chq Numero cheque ou virement
  206. * @param string $categorie Categorie optionnelle
  207. * @param User $user User that create
  208. * @param string $emetteur Name of cheque writer
  209. * @param string $banque Bank of cheque writer
  210. * @return int Rowid of added entry, <0 if KO
  211. */
  212. function addline($date, $oper, $label, $amount, $num_chq, $categorie, $user, $emetteur='',$banque='')
  213. {
  214. // Clean parameters
  215. $emetteur=trim($emetteur);
  216. $banque=trim($banque);
  217. $now=dol_now();
  218. if (is_numeric($oper)) // Clean oper to have a code instead of a rowid
  219. {
  220. $sql ="SELECT code FROM ".MAIN_DB_PREFIX."c_paiement";
  221. $sql.=" WHERE id=".$oper;
  222. $resql=$this->db->query($sql);
  223. if ($resql)
  224. {
  225. $obj=$this->db->fetch_object($resql);
  226. $oper=$obj->code;
  227. }
  228. else
  229. {
  230. dol_print_error($this->db,'Failed to get payment type code');
  231. return -1;
  232. }
  233. }
  234. // Check parameters
  235. if (! $oper)
  236. {
  237. $this->error="oper not defined";
  238. return -1;
  239. }
  240. if (! $this->rowid)
  241. {
  242. $this->error="this->rowid not defined";
  243. return -2;
  244. }
  245. if ($this->courant == 2 && $oper != 'LIQ')
  246. {
  247. $this->error="ErrorCashAccountAcceptsOnlyCashMoney";
  248. return -3;
  249. }
  250. $this->db->begin();
  251. $datev = $date;
  252. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (";
  253. $sql.= "datec";
  254. $sql.= ", dateo";
  255. $sql.= ", datev";
  256. $sql.= ", label";
  257. $sql.= ", amount";
  258. $sql.= ", fk_user_author";
  259. $sql.= ", num_chq";
  260. $sql.= ", fk_account";
  261. $sql.= ", fk_type";
  262. $sql.= ",emetteur,banque";
  263. $sql.= ") VALUES (";
  264. $sql.= "'".$this->db->idate($now)."'";
  265. $sql.= ", '".$this->db->idate($date)."'";
  266. $sql.= ", '".$this->db->idate($datev)."'";
  267. $sql.= ", '".$this->db->escape($label)."'";
  268. $sql.= ", ".price2num($amount);
  269. $sql.= ", '".$user->id."'";
  270. $sql.= ", ".($num_chq?"'".$num_chq."'":"null");
  271. $sql.= ", '".$this->rowid."'";
  272. $sql.= ", '".$oper."'";
  273. $sql.= ", ".($emetteur?"'".$this->db->escape($emetteur)."'":"null");
  274. $sql.= ", ".($banque?"'".$this->db->escape($banque)."'":"null");
  275. $sql.= ")";
  276. dol_syslog(get_class($this)."::addline sql=".$sql);
  277. if ($this->db->query($sql))
  278. {
  279. $rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank");
  280. if ($categorie)
  281. {
  282. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (";
  283. $sql.= "lineid";
  284. $sql.= ", fk_categ";
  285. $sql.= ") VALUES (";
  286. $sql.= "'".$rowid."'";
  287. $sql.= ", '".$categorie."'";
  288. $sql.= ")";
  289. $result = $this->db->query($sql);
  290. if (! $result)
  291. {
  292. $this->db->rollback();
  293. $this->error=$this->db->error();
  294. return -3;
  295. }
  296. }
  297. $this->db->commit();
  298. return $rowid;
  299. }
  300. else
  301. {
  302. $this->error=$this->db->lasterror();
  303. dol_syslog(get_class($this)."::addline ".$this->error, LOG_ERR);
  304. $this->db->rollback();
  305. return -2;
  306. }
  307. }
  308. /**
  309. * Create bank account into database
  310. *
  311. * @return int < 0 if KO, > 0 if OK
  312. */
  313. function create()
  314. {
  315. global $langs,$conf;
  316. // Clean parameters
  317. if (! $this->min_allowed) $this->min_allowed=0;
  318. if (! $this->min_desired) $this->min_desired=0;
  319. $this->state_id = ($this->state_id?$this->state_id:$this->fk_departement);
  320. $this->country_id = ($this->country_id?$this->country_id:$this->fk_pays);
  321. // Check parameters
  322. if (empty($this->country_id))
  323. {
  324. $this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Country"));
  325. dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
  326. return -1;
  327. }
  328. if (empty($this->ref))
  329. {
  330. $this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref"));
  331. dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
  332. return -1;
  333. }
  334. if (empty($this->date_solde))
  335. {
  336. $this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateInitialBalance"));
  337. dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
  338. return -1;
  339. }
  340. // Chargement librairie pour acces fonction controle RIB
  341. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  342. $now=dol_now();
  343. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (";
  344. $sql.= "datec";
  345. $sql.= ", ref";
  346. $sql.= ", label";
  347. $sql.= ", entity";
  348. $sql.= ", account_number";
  349. $sql.= ", currency_code";
  350. $sql.= ", rappro";
  351. $sql.= ", min_allowed";
  352. $sql.= ", min_desired";
  353. $sql.= ", comment";
  354. $sql.= ", fk_departement";
  355. $sql.= ", fk_pays";
  356. $sql.= ") VALUES (";
  357. $sql.= "'".$this->db->idate($now)."'";
  358. $sql.= ", '".$this->db->escape($this->ref)."'";
  359. $sql.= ", '".$this->db->escape($this->label)."'";
  360. $sql.= ", ".$conf->entity;
  361. $sql.= ", '".$this->db->escape($this->account_number)."'";
  362. $sql.= ", '".$this->currency_code."'";
  363. $sql.= ", ".$this->rappro;
  364. $sql.= ", ".price2num($this->min_allowed);
  365. $sql.= ", ".price2num($this->min_desired);
  366. $sql.= ", '".$this->db->escape($this->comment)."'";
  367. $sql.= ", ".($this->state_id>0?"'".$this->state_id."'":"null");
  368. $sql.= ", ".$this->country_id;
  369. $sql.= ")";
  370. dol_syslog(get_class($this)."::create sql=".$sql);
  371. $resql=$this->db->query($sql);
  372. if ($resql)
  373. {
  374. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
  375. $result=$this->update();
  376. if ($result > 0)
  377. {
  378. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (";
  379. $sql.= "datec";
  380. $sql.= ", label";
  381. $sql.= ", amount";
  382. $sql.= ", fk_account";
  383. $sql.= ", datev";
  384. $sql.= ", dateo";
  385. $sql.= ", fk_type";
  386. $sql.= ", rappro";
  387. $sql.= ") VALUES (";
  388. $sql.= "'".$this->db->idate($now)."'";
  389. $sql.= ", '(".$langs->trans("InitialBankBalance").")'";
  390. $sql.= ", ".price2num($this->solde);
  391. $sql.= ", '".$this->id."'";
  392. $sql.= ", '".$this->db->idate($this->date_solde)."'";
  393. $sql.= ", '".$this->db->idate($this->date_solde)."'";
  394. $sql.= ", 'SOLD'";
  395. $sql.= ", 0"; // Not conciliated by default
  396. $sql.= ")";
  397. $resql=$this->db->query($sql);
  398. if (! $resql)
  399. {
  400. $this->error=$this->db->lasterror();
  401. dol_syslog($this->error, LOG_ERR);
  402. return -3;
  403. }
  404. }
  405. return $this->id;
  406. }
  407. else
  408. {
  409. if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  410. {
  411. $this->error=$langs->trans("ErrorBankLabelAlreadyExists");
  412. dol_syslog($this->error, LOG_ERR);
  413. return -1;
  414. }
  415. else {
  416. $this->error=$this->db->error()." sql=".$sql;
  417. dol_syslog($this->error, LOG_ERR);
  418. return -2;
  419. }
  420. }
  421. }
  422. /**
  423. * Update bank account card
  424. *
  425. * @param User $user Object user making action
  426. * @return int <0 si ko, >0 si ok
  427. */
  428. function update($user='')
  429. {
  430. global $langs,$conf;
  431. // Clean parameters
  432. if (! $this->min_allowed) $this->min_allowed=0;
  433. if (! $this->min_desired) $this->min_desired=0;
  434. $this->state_id = ($this->state_id?$this->state_id:$this->fk_departement);
  435. $this->country_id = ($this->country_id?$this->country_id:$this->fk_pays);
  436. // Check parameters
  437. if (empty($this->country_id))
  438. {
  439. $this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Country"));
  440. dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
  441. return -1;
  442. }
  443. if (empty($this->ref))
  444. {
  445. $this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref"));
  446. dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
  447. return -1;
  448. }
  449. if (! $this->label) $this->label = "???";
  450. $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET ";
  451. $sql.= " ref = '".$this->db->escape($this->ref)."'";
  452. $sql.= ",label = '".$this->db->escape($this->label)."'";
  453. $sql.= ",courant = ".$this->courant;
  454. $sql.= ",clos = ".$this->clos;
  455. $sql.= ",rappro = ".$this->rappro;
  456. $sql.= ",url = ".($this->url?"'".$this->url."'":"null");
  457. $sql.= ",account_number = '".$this->account_number."'";
  458. $sql.= ",currency_code = '".$this->currency_code."'";
  459. $sql.= ",min_allowed = '".price2num($this->min_allowed)."'";
  460. $sql.= ",min_desired = '".price2num($this->min_desired)."'";
  461. $sql.= ",comment = '".$this->db->escape($this->comment)."'";
  462. $sql.= ",fk_departement = ".($this->state_id>0?"'".$this->state_id."'":"null");
  463. $sql.= ",fk_pays = ".$this->country_id;
  464. $sql.= " WHERE rowid = ".$this->id;
  465. $sql.= " AND entity = ".$conf->entity;
  466. dol_syslog(get_class($this)."::update sql=".$sql);
  467. $result = $this->db->query($sql);
  468. if ($result)
  469. {
  470. return 1;
  471. }
  472. else
  473. {
  474. $this->error=$this->db->lasterror();
  475. dol_print_error($this->db);
  476. return -1;
  477. }
  478. }
  479. /**
  480. * Update BBAN (RIB) account fields
  481. *
  482. * @param User $user Object user making update
  483. * @return int <0 if KO, >0 if OK
  484. */
  485. function update_bban($user='')
  486. {
  487. global $conf,$langs;
  488. // Clean parameters
  489. $this->state_id = ($this->state_id?$this->state_id:$this->fk_departement);
  490. $this->country_id = ($this->country_id?$this->country_id:$this->fk_pays);
  491. // Chargement librairie pour acces fonction controle RIB
  492. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  493. dol_syslog(get_class($this)."::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
  494. // Check parameters
  495. if (! $this->ref)
  496. {
  497. $this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->trans("Ref"));
  498. return -2;
  499. }
  500. $sql = "UPDATE ".MAIN_DB_PREFIX."bank_account SET ";
  501. $sql.= " bank = '".$this->db->escape($this->bank)."'";
  502. $sql.= ",code_banque='".$this->code_banque."'";
  503. $sql.= ",code_guichet='".$this->code_guichet."'";
  504. $sql.= ",number='".$this->number."'";
  505. $sql.= ",cle_rib='".$this->cle_rib."'";
  506. $sql.= ",bic='".$this->bic."'";
  507. $sql.= ",iban_prefix = '".$this->iban."'";
  508. $sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
  509. $sql.= ",proprio = '".$this->db->escape($this->proprio)."'";
  510. $sql.= ",adresse_proprio = '".$this->db->escape($this->adresse_proprio)."'";
  511. $sql.= ",fk_departement = ".($this->state_id>0?"'".$this->state_id."'":"null");
  512. $sql.= ",fk_pays = ".$this->country_id;
  513. $sql.= " WHERE rowid = ".$this->id;
  514. $sql.= " AND entity = ".$conf->entity;
  515. dol_syslog(get_class($this)."::update_bban sql=$sql");
  516. $result = $this->db->query($sql);
  517. if ($result)
  518. {
  519. return 1;
  520. }
  521. else
  522. {
  523. $this->error=$this->db->lasterror();
  524. dol_print_error($this->db);
  525. return -1;
  526. }
  527. }
  528. /**
  529. * Load a bank account into memory from database
  530. *
  531. * @param int $id Id of bank account to get
  532. * @param string $ref Ref of bank account to get
  533. * @return int <0 if KO, >0 if OK
  534. */
  535. function fetch($id,$ref='')
  536. {
  537. global $conf;
  538. if (empty($id) && empty($ref))
  539. {
  540. $this->error="ErrorBadParameters";
  541. return -1;
  542. }
  543. $sql = "SELECT ba.rowid, ba.ref, ba.label, ba.bank, ba.number, ba.courant, ba.clos, ba.rappro, ba.url,";
  544. $sql.= " ba.code_banque, ba.code_guichet, ba.cle_rib, ba.bic, ba.iban_prefix as iban,";
  545. $sql.= " ba.domiciliation, ba.proprio, ba.adresse_proprio, ba.fk_departement, ba.fk_pays as country_id,";
  546. $sql.= " ba.account_number, ba.currency_code,";
  547. $sql.= " ba.min_allowed, ba.min_desired, ba.comment,";
  548. $sql.= ' p.code as country_code, p.libelle as country,';
  549. $sql.= ' d.code_departement as state_code, d.nom as state';
  550. $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
  551. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_pays as p ON ba.fk_pays = p.rowid';
  552. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON ba.fk_departement = d.rowid';
  553. $sql.= " WHERE entity = ".$conf->entity;
  554. if ($id) $sql.= " AND ba.rowid = ".$id;
  555. if ($ref) $sql.= " AND ba.ref = '".$this->db->escape($ref)."'";
  556. dol_syslog(get_class($this)."::fetch sql=".$sql);
  557. $result = $this->db->query($sql);
  558. if ($result)
  559. {
  560. if ($this->db->num_rows($result))
  561. {
  562. $obj = $this->db->fetch_object($result);
  563. $this->id = $obj->rowid;
  564. $this->rowid = $obj->rowid; // deprecated
  565. $this->ref = $obj->ref;
  566. $this->label = $obj->label;
  567. $this->type = $obj->courant;
  568. $this->courant = $obj->courant;
  569. $this->bank = $obj->bank;
  570. $this->clos = $obj->clos;
  571. $this->rappro = $obj->rappro;
  572. $this->url = $obj->url;
  573. $this->code_banque = $obj->code_banque;
  574. $this->code_guichet = $obj->code_guichet;
  575. $this->number = $obj->number;
  576. $this->cle_rib = $obj->cle_rib;
  577. $this->bic = $obj->bic;
  578. $this->iban = $obj->iban;
  579. $this->iban_prefix = $obj->iban; // deprecated
  580. $this->domiciliation = $obj->domiciliation;
  581. $this->proprio = $obj->proprio;
  582. $this->adresse_proprio = $obj->adresse_proprio;
  583. $this->fk_departement = $obj->fk_departement; // deprecated
  584. $this->departement_code= $obj->state_code; // deprecated
  585. $this->departement = $obj->state; // deprecated
  586. $this->state_id = $obj->fk_departement;
  587. $this->state_code = $obj->state_code;
  588. $this->state = $obj->state;
  589. $this->fk_pays = $obj->country_id; // deprecated
  590. $this->pays_code = $obj->country_code; // deprecated
  591. $this->pays = $obj->country; // deprecated
  592. $this->country_id = $obj->country_id;
  593. $this->country_code = $obj->country_code;
  594. $this->country = $obj->country;
  595. $this->account_number = $obj->account_number;
  596. $this->currency_code = $obj->currency_code;
  597. $this->account_currency_code = $obj->currency_code;
  598. $this->min_allowed = $obj->min_allowed;
  599. $this->min_desired = $obj->min_desired;
  600. $this->comment = $obj->comment;
  601. return 1;
  602. }
  603. else
  604. {
  605. return 0;
  606. }
  607. $this->db->free($result);
  608. }
  609. else
  610. {
  611. dol_print_error($this->db);
  612. return -1;
  613. }
  614. }
  615. /**
  616. * Delete bank account from database
  617. *
  618. * @return int <0 if KO, >0 if OK
  619. */
  620. function delete()
  621. {
  622. global $conf;
  623. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
  624. $sql.= " WHERE rowid = ".$this->rowid;
  625. $sql.= " AND entity = ".$conf->entity;
  626. dol_syslog(get_class($this)."::delete sql=".$sql);
  627. $result = $this->db->query($sql);
  628. if ($result) {
  629. return 1;
  630. }
  631. else {
  632. dol_print_error($this->db);
  633. return -1;
  634. }
  635. }
  636. /**
  637. * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
  638. *
  639. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
  640. * @return string Libelle
  641. */
  642. function getLibStatut($mode=0)
  643. {
  644. return $this->LibStatut($this->clos,$mode);
  645. }
  646. /**
  647. * Renvoi le libelle d'un statut donne
  648. *
  649. * @param int $statut Id statut
  650. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  651. * @return string Libelle du statut
  652. */
  653. function LibStatut($statut,$mode=0)
  654. {
  655. global $langs;
  656. $langs->load('banks');
  657. if ($mode == 0)
  658. {
  659. if ($statut==0) return $langs->trans("StatusAccountOpened");
  660. if ($statut==1) return $langs->trans("StatusAccountClosed");
  661. }
  662. if ($mode == 1)
  663. {
  664. if ($statut==0) return $langs->trans("StatusAccountOpened");
  665. if ($statut==1) return $langs->trans("StatusAccountClosed");
  666. }
  667. if ($mode == 2)
  668. {
  669. if ($statut==0) return img_picto($langs->trans("StatusAccountOpened"),'statut4').' '.$langs->trans("StatusAccountOpened");
  670. if ($statut==1) return img_picto($langs->trans("StatusAccountClosed"),'statut5').' '.$langs->trans("StatusAccountClosed");
  671. }
  672. if ($mode == 3)
  673. {
  674. if ($statut==0) return img_picto($langs->trans("StatusAccountOpened"),'statut4');
  675. if ($statut==1) return img_picto($langs->trans("StatusAccountClosed"),'statut5');
  676. }
  677. if ($mode == 4)
  678. {
  679. if ($statut==0) return img_picto($langs->trans("StatusAccountOpened"),'statut4').' '.$langs->trans("StatusAccountOpened");
  680. if ($statut==1) return img_picto($langs->trans("StatusAccountClosed"),'statut5').' '.$langs->trans("StatusAccountClosed");
  681. }
  682. if ($mode == 5)
  683. {
  684. if ($statut==0) return $langs->trans("StatusAccountOpened").' '.img_picto($langs->trans("StatusAccountOpened"),'statut4');
  685. if ($statut==1) return $langs->trans("StatusAccountClosed").' '.img_picto($langs->trans("StatusAccountClosed"),'statut5');
  686. }
  687. }
  688. /**
  689. * Renvoi si un compte peut etre supprimer ou non (sans mouvements)
  690. *
  691. * @return boolean vrai si peut etre supprime, faux sinon
  692. */
  693. function can_be_deleted()
  694. {
  695. $can_be_deleted=false;
  696. $sql = "SELECT COUNT(rowid) as nb";
  697. $sql.= " FROM ".MAIN_DB_PREFIX."bank";
  698. $sql.= " WHERE fk_account=".$this->id;
  699. $resql = $this->db->query($sql);
  700. if ($resql) {
  701. $obj=$this->db->fetch_object($resql);
  702. if ($obj->nb <= 1) $can_be_deleted=true; // Juste le solde
  703. }
  704. else {
  705. dol_print_error($this->db);
  706. }
  707. return $can_be_deleted;
  708. }
  709. /**
  710. * Return error
  711. *
  712. * @return string Error string
  713. */
  714. function error()
  715. {
  716. return $this->error;
  717. }
  718. /**
  719. * Return current sold
  720. *
  721. * @param int $option 1=Exclude future operation date (this is to exclude input made in advance and have real account sold)
  722. * @return int Current sold (value date <= today)
  723. */
  724. function solde($option=0)
  725. {
  726. $sql = "SELECT sum(amount) as amount";
  727. $sql.= " FROM ".MAIN_DB_PREFIX."bank";
  728. $sql.= " WHERE fk_account = ".$this->id;
  729. if ($option == 1) $sql.= " AND dateo <= ".$this->db->idate(time());
  730. $resql = $this->db->query($sql);
  731. if ($resql)
  732. {
  733. if ($this->db->num_rows($resql))
  734. {
  735. $obj=$this->db->fetch_object($resql);
  736. $solde = $obj->amount;
  737. }
  738. $this->db->free($resql);
  739. return $solde;
  740. }
  741. }
  742. /**
  743. * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
  744. *
  745. * @param User $user Objet user
  746. * @param int $filteraccountid To get info for a particular account id
  747. * @return int <0 if KO, 0=Nothing to show, >0 if OK
  748. */
  749. function load_board($user,$filteraccountid=0)
  750. {
  751. global $conf;
  752. if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
  753. $now=dol_now();
  754. $this->nbtodo=$this->nbtodolate=0;
  755. $sql = "SELECT b.rowid, b.datev as datefin";
  756. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b,";
  757. $sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
  758. $sql.= " WHERE b.rappro=0";
  759. $sql.= " AND b.fk_account = ba.rowid";
  760. $sql.= " AND ba.entity = ".$conf->entity;
  761. $sql.= " AND (ba.rappro = 1 AND ba.courant != 2)"; // Compte rapprochable
  762. if ($filteraccountid) $sql.=" AND ba.rowid = ".$filteraccountid;
  763. //print $sql;
  764. $resql=$this->db->query($sql);
  765. if ($resql)
  766. {
  767. $num=$this->db->num_rows($resql);
  768. while ($obj=$this->db->fetch_object($resql))
  769. {
  770. $this->nbtodo++;
  771. if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->rappro->warning_delay)) $this->nbtodolate++;
  772. }
  773. return $num;
  774. }
  775. else
  776. {
  777. dol_print_error($this->db);
  778. $this->error=$this->db->error();
  779. return -1;
  780. }
  781. }
  782. /**
  783. * Renvoie nom clicable (avec eventuellement le picto)
  784. *
  785. * @param int $withpicto Inclut le picto dans le lien
  786. * @param string $mode ''=Link to card, 'transactions'=Link to transactions card
  787. * @return string Chaine avec URL
  788. */
  789. function getNomUrl($withpicto=0, $mode='')
  790. {
  791. global $langs;
  792. $result='';
  793. if (empty($mode))
  794. {
  795. $lien = '<a href="'.DOL_URL_ROOT.'/compta/bank/fiche.php?id='.$this->id.'">';
  796. $lienfin='</a>';
  797. }
  798. else if ($mode == 'transactions')
  799. {
  800. $lien = '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$this->id.'">';
  801. $lienfin='</a>';
  802. }
  803. if ($withpicto) $result.=($lien.img_object($langs->trans("ShowAccount"),'account').$lienfin.' ');
  804. $result.=$lien.$this->label.$lienfin;
  805. return $result;
  806. }
  807. // Method after here are common to Account and CompanyBankAccount
  808. /**
  809. * Return if an account has valid information
  810. *
  811. * @return int 1 if correct, <=0 if wrong
  812. */
  813. function verif()
  814. {
  815. require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
  816. // Call function to check BAN
  817. if (! checkBanForAccount($this))
  818. {
  819. $this->error_number = 12;
  820. $this->error_message = 'RIBControlError';
  821. }
  822. if ($this->error_number == 0)
  823. {
  824. return 1;
  825. }
  826. else
  827. {
  828. return 0;
  829. }
  830. }
  831. /**
  832. * Return account country code
  833. *
  834. * @return string country code
  835. */
  836. function getCountryCode()
  837. {
  838. global $mysoc;
  839. // We return country code of bank account
  840. if (! empty($this->country_code)) return $this->country_code;
  841. // For backward compatibility, we try to guess country from other information
  842. if (! empty($this->iban))
  843. {
  844. if ($mysoc->country_code === 'IN') return $mysoc->country_code; // Test to know if we can trust IBAN
  845. // If IBAN defined, we can know country of account from it
  846. if (preg_match("/^([a-zA-Z][a-zA-Z])/i",$this->iban,$reg)) return $reg[1];
  847. }
  848. // If this class is linked to a third party
  849. if (! empty($this->socid))
  850. {
  851. require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php';
  852. $company=new Societe($this->db);
  853. $result=$company->fetch($this->socid);
  854. if (! empty($company->country_code)) return $company->country_code;
  855. }
  856. // We return country code of managed company
  857. if (! empty($mysoc->country_code)) return $mysoc->country_code;
  858. return '';
  859. }
  860. /**
  861. * Return if a bank account is defined with detailed information (bank code, desk code, number and key)
  862. *
  863. * @return int 0=Use only an account number
  864. * 1=Need Bank, Desk, Number and Key (France, Spain, ...)
  865. * 2=Neek Bank only (BSB for Australia)
  866. */
  867. function useDetailedBBAN()
  868. {
  869. $country_code=$this->getCountryCode();
  870. if (in_array($country_code,array('FR','ES','GA'))) return 1; // France, Spain, Gabon
  871. if (in_array($country_code,array('AU'))) return 2; // Australia
  872. return 0;
  873. }
  874. /**
  875. * Load miscellaneous information for tab "Info"
  876. *
  877. * @param int $id Id of object to load
  878. * @return void
  879. */
  880. function info($id)
  881. {
  882. }
  883. /**
  884. * Initialise an instance with random values.
  885. * Used to build previews or test instances.
  886. * id must be 0 if object instance is a specimen.
  887. *
  888. * @return void
  889. */
  890. function initAsSpecimen()
  891. {
  892. $this->ref = 'MBA';
  893. $this->label = 'My Bank account';
  894. $this->bank = 'MyBank';
  895. $this->courant = 1;
  896. $this->clos = 0;
  897. $this->code_banque = '123';
  898. $this->code_guichet = '456';
  899. $this->number = 'ABC12345';
  900. $this->cle_rib = 50;
  901. $this->bic = 'AA12';
  902. $this->iban = 'FR999999999';
  903. $this->iban_prefix = 'FR'; // deprecated
  904. $this->domiciliation = 'The bank addresse';
  905. $this->proprio = 'Owner';
  906. $this->adresse_proprio = 'Owner address';
  907. $this->country_id = 1;
  908. }
  909. }
  910. /**
  911. * Class to manage bank transaction lines
  912. */
  913. class AccountLine extends CommonObject
  914. {
  915. var $error;
  916. var $db;
  917. var $element='bank';
  918. var $table_element='bank';
  919. var $id;
  920. var $ref;
  921. var $datec;
  922. var $dateo;
  923. var $datev;
  924. var $amount;
  925. var $label;
  926. var $note;
  927. var $fk_user_author;
  928. var $fk_user_rappro;
  929. var $fk_type;
  930. var $rappro; // Is it conciliated
  931. var $num_releve; // If conciliated, what is bank receipt
  932. var $num_chq; // Num of cheque
  933. var $bank_chq; // Bank of cheque
  934. var $fk_bordereau; // Id of cheque receipt
  935. var $fk_account; // Id of bank account
  936. var $bank_account_label; // Label of bank account
  937. /**
  938. * Constructor
  939. *
  940. * @param DoliDB $db Database handler
  941. */
  942. function __construct($db = '')
  943. {
  944. $this->db = $db;
  945. }
  946. /**
  947. * Load into memory content of a bank transaction line
  948. *
  949. * @param int $rowid Id of bank transaction to load
  950. * @param string $ref Ref of bank transaction to load
  951. * @param string $num External num to load (ex: num of transaction for paypal fee)
  952. * @return int <0 if KO, 0 if OK but not found, >0 if OK and found
  953. */
  954. function fetch($rowid,$ref='',$num='')
  955. {
  956. global $conf;
  957. // Check parameters
  958. if (empty($rowid) && empty($ref) && empty($num)) return -1;
  959. $sql = "SELECT b.rowid, b.datec, b.datev, b.dateo, b.amount, b.label as label, b.fk_account,";
  960. $sql.= " b.fk_user_author, b.fk_user_rappro,";
  961. $sql.= " b.fk_type, b.num_releve, b.num_chq, b.rappro, b.note,";
  962. $sql.= " b.fk_bordereau, b.banque, b.emetteur,";
  963. //$sql.= " b.author"; // Is this used ?
  964. $sql.= " ba.label as bank_account_label";
  965. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b,";
  966. $sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
  967. $sql.= " WHERE b.fk_account = ba.rowid";
  968. $sql.= " AND ba.entity = ".$conf->entity;
  969. if ($num) $sql.= " AND b.num_chq='".$this->db->escape($num)."'";
  970. else if ($ref) $sql.= " AND b.rowid='".$this->db->escape($ref)."'";
  971. else $sql.= " AND b.rowid=".$rowid;
  972. dol_syslog(get_class($this)."::fetch sql=".$sql);
  973. $result = $this->db->query($sql);
  974. if ($result)
  975. {
  976. $ret=0;
  977. $obj = $this->db->fetch_object($result);
  978. if ($obj)
  979. {
  980. $this->id = $obj->rowid;
  981. $this->rowid = $obj->rowid;
  982. $this->ref = $obj->rowid;
  983. $this->datec = $obj->datec;
  984. $this->datev = $obj->datev;
  985. $this->dateo = $obj->dateo;
  986. $this->amount = $obj->amount;
  987. $this->label = $obj->label;
  988. $this->note = $obj->note;
  989. $this->fk_user_author = $obj->fk_user_author;
  990. $this->fk_user_rappro = $obj->fk_user_rappro;
  991. $this->fk_type = $obj->fk_type; // Type of transaction
  992. $this->rappro = $obj->rappro;
  993. $this->num_releve = $obj->num_releve;
  994. $this->num_chq = $obj->num_chq;
  995. $this->bank_chq = $obj->bank_chq;
  996. $this->fk_bordereau = $obj->fk_bordereau;
  997. $this->fk_account = $obj->fk_account;
  998. $this->bank_account_label = $obj->bank_account_label;
  999. $ret=1;
  1000. }
  1001. $this->db->free($result);
  1002. return $ret;
  1003. }
  1004. else
  1005. {
  1006. dol_print_error($this->db);
  1007. return -1;
  1008. }
  1009. }
  1010. /**
  1011. * Delete transaction bank line record
  1012. *
  1013. * @param User $user User object that delete
  1014. * @return int <0 if KO, >0 if OK
  1015. */
  1016. function delete($user=0)
  1017. {
  1018. $nbko=0;
  1019. if ($this->rappro)
  1020. {
  1021. // Protection to avoid any delete of consolidated lines
  1022. $this->error="DeleteNotPossibleLineIsConsolidated";
  1023. return -1;
  1024. }
  1025. $this->db->begin();
  1026. // Delete urls
  1027. $result=$this->delete_urls();
  1028. if ($result < 0)
  1029. {
  1030. $nbko++;
  1031. }
  1032. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$this->rowid;
  1033. dol_syslog(get_class($this)."::delete sql=".$sql);
  1034. $result = $this->db->query($sql);
  1035. if (! $result) $nbko++;
  1036. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$this->rowid;
  1037. dol_syslog(get_class($this)."::delete sql=".$sql);
  1038. $result = $this->db->query($sql);
  1039. if (! $result) $nbko++;
  1040. if (! $nbko)
  1041. {
  1042. $this->db->commit();
  1043. return 1;
  1044. }
  1045. else
  1046. {
  1047. $this->db->rollback();
  1048. return -$nbko;
  1049. }
  1050. }
  1051. /**
  1052. * Delete bank line records
  1053. *
  1054. * @param User $user User object that delete
  1055. * @return int <0 if KO, >0 if OK
  1056. */
  1057. function delete_urls($user=0)
  1058. {
  1059. $nbko=0;
  1060. if ($this->rappro)
  1061. {
  1062. // Protection to avoid any delete of consolidated lines
  1063. $this->error="ErrorDeleteNotPossibleLineIsConsolidated";
  1064. return -1;
  1065. }
  1066. $this->db->begin();
  1067. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$this->rowid;
  1068. dol_syslog(get_class($this)."::delete_urls sql=".$sql);
  1069. $result = $this->db->query($sql);
  1070. if (! $result) $nbko++;
  1071. if (! $nbko)
  1072. {
  1073. $this->db->commit();
  1074. return 1;
  1075. }
  1076. else
  1077. {
  1078. $this->db->rollback();
  1079. return -$nbko;
  1080. }
  1081. }
  1082. /**
  1083. * Update bank account record in database
  1084. *
  1085. * @param User $user Object user making update
  1086. * @param int $notrigger 0=Disable all triggers
  1087. * @return int <0 if KO, >0 if OK
  1088. */
  1089. function update($user,$notrigger=0)
  1090. {
  1091. $this->db->begin();
  1092. $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
  1093. $sql.= " amount = ".price2num($this->amount).",";
  1094. $sql.= " datev='".$this->db->idate($this->datev)."',";
  1095. $sql.= " dateo='".$this->db->idate($this->dateo)."'";
  1096. $sql.= " WHERE rowid = ".$this->rowid;
  1097. dol_syslog(get_class($this)."::update sql=".$sql);
  1098. $resql = $this->db->query($sql);
  1099. if ($resql)
  1100. {
  1101. $this->db->commit();
  1102. return 1;
  1103. }
  1104. else
  1105. {
  1106. $this->db->rollback();
  1107. $this->error=$this->db->error();
  1108. dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
  1109. return -1;
  1110. }
  1111. }
  1112. /**
  1113. * Update conciliation field
  1114. *
  1115. * @param User $user Objet user making update
  1116. * @param int $cat Category id
  1117. * @return int <0 if KO, >0 if OK
  1118. */
  1119. function update_conciliation($user,$cat)
  1120. {
  1121. $this->db->begin();
  1122. $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
  1123. $sql.= " rappro = 1";
  1124. $sql.= ", num_releve = '".$this->num_releve."'";
  1125. $sql.= ", fk_user_rappro = ".$user->id;
  1126. $sql.= " WHERE rowid = ".$this->id;
  1127. dol_syslog(get_class($this)."::update_conciliation sql=".$sql, LOG_DEBUG);
  1128. $resql = $this->db->query($sql);
  1129. if ($resql)
  1130. {
  1131. if (! empty($cat))
  1132. {
  1133. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (";
  1134. $sql.= "lineid";
  1135. $sql.= ", fk_categ";
  1136. $sql.= ") VALUES (";
  1137. $sql.= $this->id;
  1138. $sql.= ", ".$cat;
  1139. $sql.= ")";
  1140. dol_syslog(get_class($this)."::update_conciliation sql=".$sql, LOG_DEBUG);
  1141. $resql = $this->db->query($sql);
  1142. // No error check. Can fail if category already affected
  1143. }
  1144. $bankline->rappro=1;
  1145. $this->db->commit();
  1146. return 1;
  1147. }
  1148. else
  1149. {
  1150. $this->db->rollback();
  1151. return -1;
  1152. }
  1153. }
  1154. /**
  1155. * Increase/decrease value date of a rowid
  1156. *
  1157. * @param int $rowid Id of line
  1158. * @param int $sign 1 or -1
  1159. * @return int >0 if OK, 0 if KO
  1160. */
  1161. function datev_change($rowid,$sign=1)
  1162. {
  1163. $sql = "SELECT datev FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid;
  1164. $resql = $this->db->query($sql);
  1165. if ($resql)
  1166. {
  1167. $obj=$this->db->fetch_object($resql);
  1168. $newdate=$this->db->jdate($obj->datev)+(3600*24*$sign);
  1169. $sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
  1170. $sql.= " datev = '".$this->db->idate($newdate)."'";
  1171. $sql.= " WHERE rowid = ".$rowid;
  1172. $result = $this->db->query($sql);
  1173. if ($result)
  1174. {
  1175. if ($this->db->affected_rows($result))
  1176. {
  1177. return 1;
  1178. }
  1179. }
  1180. else
  1181. {
  1182. dol_print_error($this->db);
  1183. return 0;
  1184. }
  1185. }
  1186. else dol_print_error($this->db);
  1187. return 0;
  1188. }
  1189. /**
  1190. * Increase value date of a rowid
  1191. *
  1192. * @param int $id Id of line to change
  1193. * @return int >0 if OK, 0 if KO
  1194. */
  1195. function datev_next($id)
  1196. {
  1197. return $this->datev_change($id,1);
  1198. }
  1199. /**
  1200. * Decrease value date of a rowid
  1201. *
  1202. * @param int $id Id of line to change
  1203. * @return int >0 if OK, 0 if KO
  1204. */
  1205. function datev_previous($id)
  1206. {
  1207. return $this->datev_change($id,-1);
  1208. }
  1209. /**
  1210. * Load miscellaneous information for tab "Info"
  1211. *
  1212. * @param int $id Id of object to load
  1213. * @return void
  1214. */
  1215. function info($id)
  1216. {
  1217. $sql = 'SELECT b.rowid, b.datec,';
  1218. $sql.= ' b.fk_user_author, b.fk_user_rappro';
  1219. $sql.= ' FROM '.MAIN_DB_PREFIX.'bank as b';
  1220. $sql.= ' WHERE b.rowid = '.$id;
  1221. $result=$this->db->query($sql);
  1222. if ($result)
  1223. {
  1224. if ($this->db->num_rows($result))
  1225. {
  1226. $obj = $this->db->fetch_object($result);
  1227. $this->id = $obj->rowid;
  1228. if ($obj->fk_user_author)
  1229. {
  1230. $cuser = new User($this->db);
  1231. $cuser->fetch($obj->fk_user_author);
  1232. $this->user_creation = $cuser;
  1233. }
  1234. if ($obj->fk_user_rappro)
  1235. {
  1236. $ruser = new User($this->db);
  1237. $ruser->fetch($obj->fk_user_rappro);
  1238. $this->user_rappro = $ruser;
  1239. }
  1240. $this->date_creation = $this->db->jdate($obj->datec);
  1241. //$this->date_rappro = $obj->daterappro; // Not yet managed
  1242. }
  1243. $this->db->free($result);
  1244. }
  1245. else
  1246. {
  1247. dol_print_error($this->db);
  1248. }
  1249. }
  1250. /**
  1251. * Renvoie nom clicable (avec eventuellement le picto)
  1252. *
  1253. * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
  1254. * @param int $maxlen Longueur max libelle
  1255. * @param string $option Option ('showall')
  1256. * @return string Chaine avec URL
  1257. */
  1258. function getNomUrl($withpicto=0,$maxlen=0,$option='')
  1259. {
  1260. global $langs;
  1261. $result='';
  1262. $lien = '<a href="'.DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$this->rowid.'">';
  1263. $lienfin='</a>';
  1264. if ($withpicto) $result.=($lien.img_object($langs->trans("ShowTransaction"),'account').$lienfin.' ');
  1265. $result.=$lien.$this->rowid.$lienfin;
  1266. if ($option == 'showall')
  1267. {
  1268. $result.=' (';
  1269. $result.=$langs->trans("BankAccount").': ';
  1270. $accountstatic=new Account($this->db);
  1271. $accountstatic->id=$this->fk_account;
  1272. $accountstatic->label=$this->bank_account_label;
  1273. $result.=$accountstatic->getNomUrl(0).', ';
  1274. $result.=$langs->trans("BankLineConciliated").': ';
  1275. $result.=yn($this->rappro);
  1276. $result.=')';
  1277. }
  1278. return $result;
  1279. }
  1280. }
  1281. ?>