paymentexpensereport.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <?php
  2. /* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/expensereport/class/paymentexpensereport.class.php
  20. * \ingroup Expense Report
  21. * \brief File of class to manage payment of expense report
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  24. /**
  25. * Class to manage payments of expense report
  26. */
  27. class PaymentExpenseReport extends CommonObject
  28. {
  29. /**
  30. * @var string ID to identify managed object
  31. */
  32. public $element = 'payment_expensereport';
  33. /**
  34. * @var string Name of table without prefix where object is stored
  35. */
  36. public $table_element = 'payment_expensereport';
  37. /**
  38. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  39. */
  40. public $picto = 'payment';
  41. /**
  42. * @var int ID
  43. */
  44. public $rowid;
  45. /**
  46. * @var int ID
  47. */
  48. public $fk_expensereport;
  49. public $datec = '';
  50. public $tms = '';
  51. public $datep = '';
  52. public $amount; // Total amount of payment
  53. public $amounts = array(); // Array of amounts
  54. /**
  55. * @var int ID
  56. */
  57. public $fk_typepayment;
  58. public $num_payment;
  59. /**
  60. * @var int ID
  61. */
  62. public $fk_bank;
  63. /**
  64. * @var int ID
  65. */
  66. public $fk_user_creat;
  67. /**
  68. * @var int ID
  69. */
  70. public $fk_user_modif;
  71. public $type_code;
  72. public $type_label;
  73. /**
  74. * Constructor
  75. *
  76. * @param DoliDB $db Database handler
  77. */
  78. public function __construct($db)
  79. {
  80. $this->db = $db;
  81. }
  82. /**
  83. * Create payment of expense report into database.
  84. * Use this->amounts to have list of lines for the payment
  85. *
  86. * @param User $user User making payment
  87. * @return int <0 if KO, id of payment if OK
  88. */
  89. public function create($user)
  90. {
  91. global $conf, $langs;
  92. $error = 0;
  93. $now = dol_now();
  94. // Validate parameters
  95. if (!$this->datepaid) {
  96. $this->error = 'ErrorBadValueForParameterCreatePaymentExpenseReport';
  97. return -1;
  98. }
  99. // Clean parameters
  100. if (isset($this->fk_expensereport)) {
  101. $this->fk_expensereport = trim($this->fk_expensereport);
  102. }
  103. if (isset($this->amount)) {
  104. $this->amount = trim($this->amount);
  105. }
  106. if (isset($this->fk_typepayment)) {
  107. $this->fk_typepayment = trim($this->fk_typepayment);
  108. }
  109. if (isset($this->num_payment)) {
  110. $this->num_payment = trim($this->num_payment);
  111. }
  112. if (isset($this->note)) {
  113. $this->note = trim($this->note);
  114. }
  115. if (isset($this->note_public)) {
  116. $this->note_public = trim($this->note_public);
  117. }
  118. if (isset($this->note_private)) {
  119. $this->note_private = trim($this->note_private);
  120. }
  121. if (isset($this->fk_bank)) {
  122. $this->fk_bank = ((int) $this->fk_bank);
  123. }
  124. if (isset($this->fk_user_creat)) {
  125. $this->fk_user_creat = ((int) $this->fk_user_creat);
  126. }
  127. if (isset($this->fk_user_modif)) {
  128. $this->fk_user_modif = ((int) $this->fk_user_modif);
  129. }
  130. $totalamount = 0;
  131. foreach ($this->amounts as $key => $value) { // How payment is dispatch
  132. $newvalue = price2num($value, 'MT');
  133. $this->amounts[$key] = $newvalue;
  134. $totalamount += $newvalue;
  135. }
  136. $totalamount = price2num($totalamount);
  137. // Check parameters
  138. if ($totalamount == 0) {
  139. return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
  140. }
  141. $this->db->begin();
  142. if ($totalamount != 0) {
  143. $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_expensereport (fk_expensereport, datec, datep, amount,";
  144. $sql .= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
  145. $sql .= " VALUES ($this->fk_expensereport, '".$this->db->idate($now)."',";
  146. $sql .= " '".$this->db->idate($this->datepaid)."',";
  147. $sql .= " ".price2num($totalamount).",";
  148. $sql .= " ".((int) $this->fk_typepayment).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_public)."', ".((int) $user->id).",";
  149. $sql .= " 0)"; // fk_bank is ID of transaction into ll_bank
  150. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  151. $resql = $this->db->query($sql);
  152. if ($resql) {
  153. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_expensereport");
  154. } else {
  155. $error++;
  156. }
  157. }
  158. if ($totalamount != 0 && !$error) {
  159. $this->amount = $totalamount;
  160. $this->db->commit();
  161. return $this->id;
  162. } else {
  163. $this->error = $this->db->error();
  164. $this->db->rollback();
  165. return -1;
  166. }
  167. }
  168. /**
  169. * Load object in memory from database
  170. *
  171. * @param int $id Id object
  172. * @return int <0 if KO, >0 if OK
  173. */
  174. public function fetch($id)
  175. {
  176. $sql = "SELECT";
  177. $sql .= " t.rowid,";
  178. $sql .= " t.fk_expensereport,";
  179. $sql .= " t.datec,";
  180. $sql .= " t.tms,";
  181. $sql .= " t.datep,";
  182. $sql .= " t.amount,";
  183. $sql .= " t.fk_typepayment,";
  184. $sql .= " t.num_payment,";
  185. $sql .= " t.note as note_public,";
  186. $sql .= " t.fk_bank,";
  187. $sql .= " t.fk_user_creat,";
  188. $sql .= " t.fk_user_modif,";
  189. $sql .= " pt.code as type_code, pt.libelle as type_label,";
  190. $sql .= ' b.fk_account';
  191. $sql .= " FROM ".MAIN_DB_PREFIX."payment_expensereport as t";
  192. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
  193. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
  194. $sql .= " WHERE t.rowid = ".((int) $id);
  195. dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
  196. $resql = $this->db->query($sql);
  197. if ($resql) {
  198. if ($this->db->num_rows($resql)) {
  199. $obj = $this->db->fetch_object($resql);
  200. $this->id = $obj->rowid;
  201. $this->ref = $obj->rowid;
  202. $this->fk_expensereport = $obj->fk_expensereport;
  203. $this->datec = $this->db->jdate($obj->datec);
  204. $this->tms = $this->db->jdate($obj->tms);
  205. $this->datep = $this->db->jdate($obj->datep);
  206. $this->amount = $obj->amount;
  207. $this->fk_typepayment = $obj->fk_typepayment;
  208. $this->num_payment = $obj->num_payment;
  209. $this->note_public = $obj->note_public;
  210. $this->fk_bank = $obj->fk_bank;
  211. $this->fk_user_creat = $obj->fk_user_creat;
  212. $this->fk_user_modif = $obj->fk_user_modif;
  213. $this->type_code = $obj->type_code;
  214. $this->type_label = $obj->type_label;
  215. $this->bank_account = $obj->fk_account;
  216. $this->bank_line = $obj->fk_bank;
  217. }
  218. $this->db->free($resql);
  219. return 1;
  220. } else {
  221. $this->error = "Error ".$this->db->lasterror();
  222. return -1;
  223. }
  224. }
  225. // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter
  226. /**
  227. * Update database
  228. *
  229. * @param User $user User that modify
  230. * @param int $notrigger 0=launch triggers after, 1=disable triggers
  231. * @return int <0 if KO, >0 if OK
  232. */
  233. public function update($user = null, $notrigger = 0)
  234. {
  235. // phpcs:enable
  236. global $conf, $langs;
  237. $error = 0;
  238. // Clean parameters
  239. if (isset($this->fk_expensereport)) {
  240. $this->fk_expensereport = trim($this->fk_expensereport);
  241. }
  242. if (isset($this->amount)) {
  243. $this->amount = trim($this->amount);
  244. }
  245. if (isset($this->fk_typepayment)) {
  246. $this->fk_typepayment = trim($this->fk_typepayment);
  247. }
  248. if (isset($this->num_payment)) {
  249. $this->num_payment = trim($this->num_payment);
  250. }
  251. if (isset($this->note)) {
  252. $this->note = trim($this->note);
  253. }
  254. if (isset($this->fk_bank)) {
  255. $this->fk_bank = trim($this->fk_bank);
  256. }
  257. if (isset($this->fk_user_creat)) {
  258. $this->fk_user_creat = trim($this->fk_user_creat);
  259. }
  260. if (isset($this->fk_user_modif)) {
  261. $this->fk_user_modif = trim($this->fk_user_modif);
  262. }
  263. // Check parameters
  264. // Put here code to add control on parameters values
  265. // Update request
  266. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_expensereport SET";
  267. $sql .= " fk_expensereport=".(isset($this->fk_expensereport) ? $this->fk_expensereport : "null").",";
  268. $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
  269. $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
  270. $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
  271. $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").",";
  272. $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").",";
  273. $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").",";
  274. $sql .= " note=".(isset($this->note) ? "'".$this->db->escape($this->note)."'" : "null").",";
  275. $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").",";
  276. $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").",";
  277. $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null")."";
  278. $sql .= " WHERE rowid=".((int) $this->id);
  279. $this->db->begin();
  280. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  281. $resql = $this->db->query($sql);
  282. if (!$resql) {
  283. $error++; $this->errors[] = "Error ".$this->db->lasterror();
  284. }
  285. // Commit or rollback
  286. if ($error) {
  287. foreach ($this->errors as $errmsg) {
  288. dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
  289. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  290. }
  291. $this->db->rollback();
  292. return -1 * $error;
  293. } else {
  294. $this->db->commit();
  295. return 1;
  296. }
  297. }
  298. // phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter
  299. /**
  300. * Delete object in database
  301. *
  302. * @param User $user User that delete
  303. * @param int $notrigger 0=launch triggers after, 1=disable triggers
  304. * @return int <0 if KO, >0 if OK
  305. */
  306. public function delete($user, $notrigger = 0)
  307. {
  308. // phpcs:enable
  309. global $conf, $langs;
  310. $error = 0;
  311. $this->db->begin();
  312. if (!$error) {
  313. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
  314. $sql .= " WHERE type='payment_expensereport' AND url_id=".((int) $this->id);
  315. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  316. $resql = $this->db->query($sql);
  317. if (!$resql) {
  318. $error++; $this->errors[] = "Error ".$this->db->lasterror();
  319. }
  320. }
  321. if (!$error) {
  322. $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_expensereport";
  323. $sql .= " WHERE rowid=".((int) $this->id);
  324. dol_syslog(get_class($this)."::delete", LOG_DEBUG);
  325. $resql = $this->db->query($sql);
  326. if (!$resql) {
  327. $error++;
  328. $this->errors[] = "Error ".$this->db->lasterror();
  329. }
  330. }
  331. // Commit or rollback
  332. if ($error) {
  333. foreach ($this->errors as $errmsg) {
  334. dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
  335. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  336. }
  337. $this->db->rollback();
  338. return -1 * $error;
  339. } else {
  340. $this->db->commit();
  341. return 1;
  342. }
  343. }
  344. /**
  345. * Load an object from its id and create a new one in database
  346. *
  347. * @param User $user User making the clone
  348. * @param int $fromid Id of object to clone
  349. * @return int New id of clone
  350. */
  351. public function createFromClone(User $user, $fromid)
  352. {
  353. $error = 0;
  354. $object = new PaymentExpenseReport($this->db);
  355. $this->db->begin();
  356. // Load source object
  357. $object->fetch($fromid);
  358. $object->id = 0;
  359. $object->statut = 0;
  360. // Clear fields
  361. // ...
  362. // Create clone
  363. $object->context['createfromclone'] = 'createfromclone';
  364. $result = $object->create($user);
  365. // Other options
  366. if ($result < 0) {
  367. $this->error = $object->error;
  368. $error++;
  369. }
  370. unset($object->context['createfromclone']);
  371. // End
  372. if (!$error) {
  373. $this->db->commit();
  374. return $object->id;
  375. } else {
  376. $this->db->rollback();
  377. return -1;
  378. }
  379. }
  380. /**
  381. * Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
  382. *
  383. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
  384. * @return string Libelle
  385. */
  386. public function getLibStatut($mode = 0)
  387. {
  388. return '';
  389. }
  390. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  391. /**
  392. * Renvoi le libelle d'un statut donne
  393. *
  394. * @param int $status Id status
  395. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  396. * @return string Libelle du statut
  397. */
  398. public function LibStatut($status, $mode = 0)
  399. {
  400. // phpcs:enable
  401. global $langs;
  402. return '';
  403. }
  404. /**
  405. * Initialise an instance with random values.
  406. * Used to build previews or test instances.
  407. * id must be 0 if object instance is a specimen.
  408. *
  409. * @return void
  410. */
  411. public function initAsSpecimen()
  412. {
  413. $this->id = 0;
  414. $this->fk_expensereport = '';
  415. $this->datec = '';
  416. $this->tms = '';
  417. $this->datep = '';
  418. $this->amount = '';
  419. $this->fk_typepayment = '';
  420. $this->num_payment = '';
  421. $this->note = '';
  422. $this->fk_bank = '';
  423. $this->fk_user_creat = '';
  424. $this->fk_user_modif = '';
  425. }
  426. /**
  427. * Add record into bank for payment with links between this bank record and invoices of payment.
  428. * All payment properties must have been set first like after a call to create().
  429. *
  430. * @param User $user Object of user making payment
  431. * @param string $mode 'payment_expensereport'
  432. * @param string $label Label to use in bank record
  433. * @param int $accountid Id of bank account to do link with
  434. * @param string $emetteur_nom Name of transmitter
  435. * @param string $emetteur_banque Name of bank
  436. * @return int <0 if KO, >0 if OK
  437. */
  438. public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
  439. {
  440. global $langs, $conf;
  441. $error = 0;
  442. if (isModEnabled("banque")) {
  443. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  444. $acc = new Account($this->db);
  445. $acc->fetch($accountid);
  446. //Fix me field
  447. $total = $this->amount;
  448. if ($mode == 'payment_expensereport') {
  449. $amount = $total;
  450. }
  451. // Insert payment into llx_bank
  452. $bank_line_id = $acc->addline(
  453. $this->datepaid,
  454. $this->fk_typepayment, // Payment mode id or code ("CHQ or VIR for example")
  455. $label,
  456. -$amount,
  457. $this->num_payment,
  458. '',
  459. $user,
  460. $emetteur_nom,
  461. $emetteur_banque
  462. );
  463. // Update fk_bank in llx_paiement.
  464. // So we wil know the payment that have generated the bank transaction
  465. if ($bank_line_id > 0) {
  466. $result = $this->update_fk_bank($bank_line_id);
  467. if ($result <= 0) {
  468. $error++;
  469. dol_print_error($this->db);
  470. }
  471. // Add link 'payment', 'payment_supplier', 'payment_expensereport' in bank_url between payment and bank transaction
  472. $url = '';
  473. if ($mode == 'payment_expensereport') {
  474. $url = DOL_URL_ROOT.'/expensereport/payment/card.php?rowid=';
  475. }
  476. if ($url) {
  477. $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
  478. if ($result <= 0) {
  479. $error++;
  480. dol_print_error($this->db);
  481. }
  482. }
  483. // Add link 'user' in bank_url between user and bank transaction
  484. if (!$error) {
  485. foreach ($this->amounts as $key => $value) { // We should have always same user but we loop in case of.
  486. if ($mode == 'payment_expensereport') {
  487. $fuser = new User($this->db);
  488. $fuser->fetch($key);
  489. $result = $acc->add_url_line(
  490. $bank_line_id,
  491. $fuser->id,
  492. DOL_URL_ROOT.'/user/card.php?id=',
  493. $fuser->getFullName($langs),
  494. 'user'
  495. );
  496. if ($result <= 0) {
  497. $this->error = $this->db->lasterror();
  498. dol_syslog(get_class($this).'::addPaymentToBank '.$this->error);
  499. $error++;
  500. }
  501. }
  502. }
  503. }
  504. } else {
  505. $this->error = $acc->error;
  506. $this->errors = $acc->errors;
  507. $error++;
  508. }
  509. }
  510. if (!$error) {
  511. return 1;
  512. } else {
  513. return -1;
  514. }
  515. }
  516. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  517. /**
  518. * Update link between the expense report payment and the generated line in llx_bank
  519. *
  520. * @param int $id_bank Id if bank
  521. * @return int >0 if OK, <=0 if KO
  522. */
  523. public function update_fk_bank($id_bank)
  524. {
  525. // phpcs:enable
  526. $sql = "UPDATE ".MAIN_DB_PREFIX."payment_expensereport SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id);
  527. dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
  528. $result = $this->db->query($sql);
  529. if ($result) {
  530. return 1;
  531. } else {
  532. $this->error = $this->db->error();
  533. return 0;
  534. }
  535. }
  536. /**
  537. * Return clicable name (with picto eventually)
  538. *
  539. * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
  540. * @param int $maxlen Longueur max libelle
  541. * @return string Chaine avec URL
  542. */
  543. public function getNomUrl($withpicto = 0, $maxlen = 0)
  544. {
  545. global $langs, $hookmanager;
  546. $result = '';
  547. if (empty($this->ref)) {
  548. $this->ref = $this->label;
  549. }
  550. $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Payment").'</u>';
  551. if (isset($this->status)) {
  552. $label .= ' '.$this->getLibStatut(5);
  553. }
  554. if (!empty($this->ref)) {
  555. $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
  556. }
  557. if (!empty($this->datep)) {
  558. $label .= '<br><b>'.$langs->trans('Date').':</b> '.dol_print_date($this->datep, 'dayhour');
  559. }
  560. if (!empty($this->id)) {
  561. $link = '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
  562. $linkend = '</a>';
  563. if ($withpicto) {
  564. $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
  565. }
  566. if ($withpicto && $withpicto != 2) {
  567. $result .= ' ';
  568. }
  569. if ($withpicto != 2) {
  570. $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
  571. }
  572. }
  573. global $action;
  574. $hookmanager->initHooks(array($this->element . 'dao'));
  575. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  576. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  577. if ($reshook > 0) {
  578. $result = $hookmanager->resPrint;
  579. } else {
  580. $result .= $hookmanager->resPrint;
  581. }
  582. return $result;
  583. }
  584. /**
  585. * Tab information on object
  586. *
  587. * @param int $id Payment id
  588. * @return void
  589. */
  590. public function info($id)
  591. {
  592. $sql = 'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
  593. $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_expensereport as e';
  594. $sql .= ' WHERE e.rowid = '.((int) $id);
  595. dol_syslog(get_class($this).'::info', LOG_DEBUG);
  596. $result = $this->db->query($sql);
  597. if ($result) {
  598. if ($this->db->num_rows($result)) {
  599. $obj = $this->db->fetch_object($result);
  600. $this->id = $obj->rowid;
  601. if ($obj->fk_user_creat) {
  602. $cuser = new User($this->db);
  603. $cuser->fetch($obj->fk_user_creat);
  604. $this->user_creation = $cuser;
  605. }
  606. if ($obj->fk_user_modif) {
  607. $muser = new User($this->db);
  608. $muser->fetch($obj->fk_user_modif);
  609. $this->user_modification = $muser;
  610. }
  611. $this->date_creation = $this->db->jdate($obj->datec);
  612. $this->date_modification = $this->db->jdate($obj->tms);
  613. }
  614. $this->db->free($result);
  615. } else {
  616. dol_print_error($this->db);
  617. }
  618. }
  619. }