paymentloan.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. /* Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2015-2018 Frederic France <frederic.france@netlogic.fr>
  4. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/loan/class/paymentloan.class.php
  21. * \ingroup loan
  22. * \brief File of class to manage payment of loans
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  25. /**
  26. * Class to manage payments of loans
  27. */
  28. class PaymentLoan extends CommonObject
  29. {
  30. /**
  31. * @var string ID to identify managed object
  32. */
  33. public $element = 'payment_loan';
  34. /**
  35. * @var string Name of table without prefix where object is stored
  36. */
  37. public $table_element = 'payment_loan';
  38. /**
  39. * @var string String with name of icon for PaymentLoan
  40. */
  41. public $picto = 'money-bill-alt';
  42. /**
  43. * @var int Loan ID
  44. */
  45. public $fk_loan;
  46. /**
  47. * @var string Create date
  48. */
  49. public $datec = '';
  50. public $tms = '';
  51. /**
  52. * @var string Payment date
  53. */
  54. public $datep = '';
  55. public $amounts = array(); // Array of amounts
  56. public $amount_capital; // Total amount of payment
  57. public $amount_insurance;
  58. public $amount_interest;
  59. /**
  60. * @var int Payment mode ID
  61. */
  62. public $fk_typepayment;
  63. /**
  64. * @var int Payment ID
  65. */
  66. public $num_payment;
  67. /**
  68. * @var int Bank ID
  69. */
  70. public $fk_bank;
  71. /**
  72. * @var int User ID
  73. */
  74. public $fk_user_creat;
  75. /**
  76. * @var int user ID
  77. */
  78. public $fk_user_modif;
  79. public $type_code;
  80. public $type_label;
  81. /**
  82. * Constructor
  83. *
  84. * @param DoliDB $db Database handler
  85. */
  86. public function __construct($db)
  87. {
  88. $this->db = $db;
  89. }
  90. /**
  91. * Create payment of loan into database.
  92. * Use this->amounts to have list of lines for the payment
  93. *
  94. * @param User $user User making payment
  95. * @return int <0 if KO, id of payment if OK
  96. */
  97. public function create($user)
  98. {
  99. global $conf, $langs;
  100. $error = 0;
  101. $now = dol_now();
  102. // Validate parameters
  103. if (!$this->datep) {
  104. $this->error = 'ErrorBadValueForParameter';
  105. return -1;
  106. }
  107. // Clean parameters
  108. if (isset($this->fk_loan)) {
  109. $this->fk_loan = (int) $this->fk_loan;
  110. }
  111. if (isset($this->amount_capital)) {
  112. $this->amount_capital = price2num($this->amount_capital ? $this->amount_capital : 0);
  113. }
  114. if (isset($this->amount_insurance)) {
  115. $this->amount_insurance = price2num($this->amount_insurance ? $this->amount_insurance : 0);
  116. }
  117. if (isset($this->amount_interest)) {
  118. $this->amount_interest = price2num($this->amount_interest ? $this->amount_interest : 0);
  119. }
  120. if (isset($this->fk_typepayment)) {
  121. $this->fk_typepayment = (int) $this->fk_typepayment;
  122. }
  123. if (isset($this->num_payment)) {
  124. $this->num_payment = (int) $this->num_payment;
  125. }
  126. if (isset($this->note_private)) {
  127. $this->note_private = trim($this->note_private);
  128. }
  129. if (isset($this->note_public)) {
  130. $this->note_public = trim($this->note_public);
  131. }
  132. if (isset($this->fk_bank)) {
  133. $this->fk_bank = (int) $this->fk_bank;
  134. }
  135. if (isset($this->fk_user_creat)) {
  136. $this->fk_user_creat = (int) $this->fk_user_creat;
  137. }
  138. if (isset($this->fk_user_modif)) {
  139. $this->fk_user_modif = (int) $this->fk_user_modif;
  140. }
  141. $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
  142. $totalamount = price2num($totalamount);
  143. // Check parameters
  144. if ($totalamount == 0) {
  145. return -1; // Negative amounts are accepted for reject prelevement but not null
  146. }
  147. $this->db->begin();
  148. if ($totalamount != 0) {
  149. $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
  150. $sql .= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)";
  151. $sql .= " VALUES (".$this->chid.", '".$this->db->idate($now)."',";
  152. $sql .= " '".$this->db->idate($this->datep)."',";
  153. $sql .= " ".price2num($this->amount_capital).",";
  154. $sql .= " ".price2num($this->amount_insurance).",";
  155. $sql .= " ".price2num($this->amount_interest).",";
  156. $sql .= " ".((int) $this->paymenttype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.",";
  157. $sql .= " 0)";
  158. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  159. $resql = $this->db->query($sql);
  160. if ($resql) {
  161. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_loan");
  162. } else {
  163. $this->error = $this->db->lasterror();
  164. $error++;
  165. }
  166. }
  167. if ($totalamount != 0 && !$error) {
  168. $this->amount_capital = $totalamount;
  169. $this->db->commit();
  170. return $this->id;
  171. } else {
  172. $this->error = $this->db->lasterror();
  173. $this->db->rollback();
  174. return -1;
  175. }
  176. }
  177. /**
  178. * Load object in memory from database
  179. *
  180. * @param int $id Id object
  181. * @return int <0 if KO, >0 if OK
  182. */
  183. public function fetch($id)
  184. {
  185. global $langs;
  186. $sql = "SELECT";
  187. $sql .= " t.rowid,";
  188. $sql .= " t.fk_loan,";
  189. $sql .= " t.datec,";
  190. $sql .= " t.tms,";
  191. $sql .= " t.datep,";
  192. $sql .= " t.amount_capital,";
  193. $sql .= " t.amount_insurance,";
  194. $sql .= " t.amount_interest,";
  195. $sql .= " t.fk_typepayment,";
  196. $sql .= " t.num_payment,";
  197. $sql .= " t.note_private,";
  198. $sql .= " t.note_public,";
  199. $sql .= " t.fk_bank,";
  200. $sql .= " t.fk_user_creat,";
  201. $sql .= " t.fk_user_modif,";
  202. $sql .= " pt.code as type_code, pt.libelle as type_label,";
  203. $sql .= ' b.fk_account';
  204. $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan as t";
  205. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
  206. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
  207. $sql .= " WHERE t.rowid = ".((int) $id);
  208. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  209. $resql = $this->db->query($sql);
  210. if ($resql) {
  211. if ($this->db->num_rows($resql)) {
  212. $obj = $this->db->fetch_object($resql);
  213. $this->id = $obj->rowid;
  214. $this->ref = $obj->rowid;
  215. $this->fk_loan = $obj->fk_loan;
  216. $this->datec = $this->db->jdate($obj->datec);
  217. $this->tms = $this->db->jdate($obj->tms);
  218. $this->datep = $this->db->jdate($obj->datep);
  219. $this->amount_capital = $obj->amount_capital;
  220. $this->amount_insurance = $obj->amount_insurance;
  221. $this->amount_interest = $obj->amount_interest;
  222. $this->fk_typepayment = $obj->fk_typepayment;
  223. $this->num_payment = $obj->num_payment;
  224. $this->note_private = $obj->note_private;
  225. $this->note_public = $obj->note_public;
  226. $this->fk_bank = $obj->fk_bank;
  227. $this->fk_user_creat = $obj->fk_user_creat;
  228. $this->fk_user_modif = $obj->fk_user_modif;
  229. $this->type_code = $obj->type_code;
  230. $this->type_label = $obj->type_label;
  231. $this->bank_account = $obj->fk_account;
  232. $this->bank_line = $obj->fk_bank;
  233. }
  234. $this->db->free($resql);
  235. return 1;
  236. } else {
  237. $this->error = "Error ".$this->db->lasterror();
  238. return -1;
  239. }
  240. }
  241. /**
  242. * Update database
  243. *
  244. * @param User $user User that modify
  245. * @param int $notrigger 0=launch triggers after, 1=disable triggers
  246. * @return int <0 if KO, >0 if OK
  247. */
  248. public function update($user = 0, $notrigger = 0)
  249. {
  250. global $conf, $langs;
  251. $error = 0;
  252. // Clean parameters
  253. if (isset($this->fk_loan)) {
  254. $this->fk_loan = (int) $this->fk_loan;
  255. }
  256. if (isset($this->amount_capital)) {
  257. $this->amount_capital = trim($this->amount_capital);
  258. }
  259. if (isset($this->amount_insurance)) {
  260. $this->amount_insurance = trim($this->amount_insurance);
  261. }
  262. if (isset($this->amount_interest)) {
  263. $this->amount_interest = trim($this->amount_interest);
  264. }
  265. if (isset($this->fk_typepayment)) {
  266. $this->fk_typepayment = (int) $this->fk_typepayment;
  267. }
  268. if (isset($this->num_payment)) {
  269. $this->num_payment = (int) $this->num_payment;
  270. }
  271. if (isset($this->note_private)) {
  272. $this->note = trim($this->note_private);
  273. }
  274. if (isset($this->note_public)) {
  275. $this->note = trim($this->note_public);
  276. }
  277. if (isset($this->fk_bank)) {
  278. $this->fk_bank = (int) $this->fk_bank;
  279. }
  280. if (isset($this->fk_user_creat)) {
  281. $this->fk_user_creat = (int) $this->fk_user_creat;
  282. }
  283. if (isset($this->fk_user_modif)) {
  284. $this->fk_user_modif = (int) $this->fk_user_modif;
  285. }
  286. // Check parameters
  287. // Update request
  288. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET";
  289. $sql .= " fk_loan=".(isset($this->fk_loan) ? $this->fk_loan : "null").",";
  290. $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
  291. $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
  292. $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
  293. $sql .= " amount_capital=".(isset($this->amount_capital) ? $this->amount_capital : "null").",";
  294. $sql .= " amount_insurance=".(isset($this->amount_insurance) ? $this->amount_insurance : "null").",";
  295. $sql .= " amount_interest=".(isset($this->amount_interest) ? $this->amount_interest : "null").",";
  296. $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
  297. $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
  298. $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
  299. $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").",";
  300. $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").",";
  301. $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").",";
  302. $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null")."";
  303. $sql .= " WHERE rowid=".((int) $this->id);
  304. $this->db->begin();
  305. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  306. $resql = $this->db->query($sql);
  307. if (!$resql) {
  308. $error++; $this->errors[] = "Error ".$this->db->lasterror();
  309. }
  310. // Commit or rollback
  311. if ($error) {
  312. foreach ($this->errors as $errmsg) {
  313. dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
  314. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  315. }
  316. $this->db->rollback();
  317. return -1 * $error;
  318. } else {
  319. $this->db->commit();
  320. return 1;
  321. }
  322. }
  323. /**
  324. * Delete object in database
  325. *
  326. * @param User $user User that delete
  327. * @param int $notrigger 0=launch triggers after, 1=disable triggers
  328. * @return int <0 if KO, >0 if OK
  329. */
  330. public function delete($user, $notrigger = 0)
  331. {
  332. global $conf, $langs;
  333. $error = 0;
  334. $this->db->begin();
  335. if (!$error) {
  336. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
  337. $sql .= " WHERE type='payment_loan' AND url_id=".((int) $this->id);
  338. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  339. $resql = $this->db->query($sql);
  340. if (!$resql) {
  341. $error++; $this->errors[] = "Error ".$this->db->lasterror();
  342. }
  343. }
  344. if (!$error) {
  345. $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan";
  346. $sql .= " WHERE rowid=".((int) $this->id);
  347. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  348. $resql = $this->db->query($sql);
  349. if (!$resql) {
  350. $error++; $this->errors[] = "Error ".$this->db->lasterror();
  351. }
  352. }
  353. // Set loan unpaid if loan has no other payment
  354. if (!$error) {
  355. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  356. $loan = new Loan($this->db);
  357. $loan->fetch($this->fk_loan);
  358. $sum_payment = $loan->getSumPayment();
  359. if ($sum_payment == 0) {
  360. dol_syslog(get_class($this)."::delete : set loan to unpaid", LOG_DEBUG);
  361. if ($loan->setUnpaid($user) < 1) {
  362. $error++;
  363. dol_print_error($this->db);
  364. }
  365. }
  366. }
  367. //if (! $error)
  368. //{
  369. // if (! $notrigger)
  370. // {
  371. // Uncomment this and change MYOBJECT to your own tag if you
  372. // want this action call a trigger.
  373. //// Call triggers
  374. //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  375. //$interface=new Interfaces($this->db);
  376. //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
  377. //if ($result < 0) { $error++; $this->errors=$interface->errors; }
  378. //// End call triggers
  379. // }
  380. //}
  381. // Commit or rollback
  382. if ($error) {
  383. foreach ($this->errors as $errmsg) {
  384. dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
  385. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  386. }
  387. $this->db->rollback();
  388. return -1 * $error;
  389. } else {
  390. $this->db->commit();
  391. return 1;
  392. }
  393. }
  394. /**
  395. * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
  396. *
  397. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  398. * @return string Libelle
  399. */
  400. public function getLibStatut($mode = 0)
  401. {
  402. return $this->LibStatut($this->statut, $mode);
  403. }
  404. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  405. /**
  406. * Renvoi le libelle d'un statut donne
  407. *
  408. * @param int $status Statut
  409. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  410. * @return string Libelle du statut
  411. */
  412. public function LibStatut($status, $mode = 0)
  413. {
  414. // phpcs:enable
  415. return '';
  416. }
  417. /**
  418. * Add record into bank for payment with links between this bank record and invoices of payment.
  419. * All payment properties must have been set first like after a call to create().
  420. *
  421. * @param User $user Object of user making payment
  422. * @param int $fk_loan Id of fk_loan to do link with this payment
  423. * @param string $mode 'payment_loan'
  424. * @param string $label Label to use in bank record
  425. * @param int $accountid Id of bank account to do link with
  426. * @param string $emetteur_nom Name of transmitter
  427. * @param string $emetteur_banque Name of bank
  428. * @return int <0 if KO, >0 if OK
  429. */
  430. public function addPaymentToBank($user, $fk_loan, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
  431. {
  432. global $conf;
  433. $error = 0;
  434. $this->db->begin();
  435. if (isModEnabled("banque")) {
  436. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  437. $acc = new Account($this->db);
  438. $acc->fetch($accountid);
  439. $total = $this->amount_capital;
  440. if ($mode == 'payment_loan') {
  441. $total = -$total;
  442. }
  443. // Insert payment into llx_bank
  444. $bank_line_id = $acc->addline(
  445. $this->datep,
  446. $this->paymenttype, // Payment mode ID or code ("CHQ or VIR for example")
  447. $label,
  448. $total,
  449. $this->num_payment,
  450. '',
  451. $user,
  452. $emetteur_nom,
  453. $emetteur_banque
  454. );
  455. // Update fk_bank into llx_paiement.
  456. // We know the payment who generated the account write
  457. if ($bank_line_id > 0) {
  458. $result = $this->update_fk_bank($bank_line_id);
  459. if ($result <= 0) {
  460. $error++;
  461. dol_print_error($this->db);
  462. }
  463. // Add link 'payment_loan' in bank_url between payment and bank transaction
  464. $url = '';
  465. if ($mode == 'payment_loan') {
  466. $url = DOL_URL_ROOT.'/loan/payment/card.php?id=';
  467. }
  468. if ($url) {
  469. $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $mode);
  470. if ($result <= 0) {
  471. $error++;
  472. dol_print_error($this->db);
  473. }
  474. }
  475. // Add link 'loan' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
  476. if ($mode == 'payment_loan') {
  477. $result = $acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.'/loan/card.php?id=', ($this->label ? $this->label : ''), 'loan');
  478. if ($result <= 0) {
  479. dol_print_error($this->db);
  480. }
  481. }
  482. } else {
  483. $this->error = $acc->error;
  484. $error++;
  485. }
  486. }
  487. // Set loan payment started if no set
  488. if (!$error) {
  489. require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  490. $loan = new Loan($this->db);
  491. $loan->fetch($fk_loan);
  492. if ($loan->paid == $loan::STATUS_UNPAID) {
  493. dol_syslog(get_class($this)."::addPaymentToBank : set loan payment to started", LOG_DEBUG);
  494. if ($loan->setStarted($user) < 1) {
  495. $error++;
  496. dol_print_error($this->db);
  497. }
  498. }
  499. }
  500. if (!$error) {
  501. $this->db->commit();
  502. return 1;
  503. } else {
  504. $this->db->rollback();
  505. return -1;
  506. }
  507. }
  508. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  509. /**
  510. * Update link between loan's payment and the line generate in llx_bank
  511. *
  512. * @param int $id_bank Id if bank
  513. * @return int >0 if OK, <=0 if KO
  514. */
  515. public function update_fk_bank($id_bank)
  516. {
  517. // phpcs:enable
  518. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
  519. dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
  520. $result = $this->db->query($sql);
  521. if ($result) {
  522. $this->fk_bank = ((int) $id_bank);
  523. return 1;
  524. } else {
  525. $this->error = $this->db->error();
  526. return 0;
  527. }
  528. }
  529. /**
  530. * Return clicable name (with eventually a picto)
  531. *
  532. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=No picto
  533. * @param int $maxlen Max length label
  534. * @param int $notooltip 1=Disable tooltip
  535. * @param string $moretitle Add more text to title tooltip
  536. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  537. * @return string String with URL
  538. */
  539. public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $moretitle = '', $save_lastsearch_value = -1)
  540. {
  541. global $langs, $conf, $hookmanager;
  542. if (!empty($conf->dol_no_mouse_hover)) {
  543. $notooltip = 1; // Force disable tooltips
  544. }
  545. $result = '';
  546. $label = '<u>'.$langs->trans("Loan").'</u>';
  547. if (!empty($this->id)) {
  548. $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->id;
  549. }
  550. if ($moretitle) {
  551. $label .= ' - '.$moretitle;
  552. }
  553. $url = DOL_URL_ROOT.'/loan/payment/card.php?id='.$this->id;
  554. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  555. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  556. $add_save_lastsearch_values = 1;
  557. }
  558. if ($add_save_lastsearch_values) {
  559. $url .= '&save_lastsearch_values=1';
  560. }
  561. $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
  562. $linkend = '</a>';
  563. $result .= $linkstart;
  564. if ($withpicto) {
  565. $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
  566. }
  567. if ($withpicto != 2) {
  568. $result .= $this->ref;
  569. }
  570. $result .= $linkend;
  571. global $action;
  572. $hookmanager->initHooks(array($this->element . 'dao'));
  573. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  574. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  575. if ($reshook > 0) {
  576. $result = $hookmanager->resPrint;
  577. } else {
  578. $result .= $hookmanager->resPrint;
  579. }
  580. return $result;
  581. }
  582. }