PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/paiement/cheque/class/remisecheque.class.php

https://github.com/asterix14/dolibarr
PHP | 796 lines | 578 code | 98 blank | 120 comment | 107 complexity | aaeb6c10c9153d86ecd22bf88830e3c2 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/paiement/cheque/class/remisecheque.class.php
  22. * \ingroup compta
  23. * \brief Fichier de la classe des bordereau de remise de cheque
  24. */
  25. require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
  26. /**
  27. * \class RemiseCheque
  28. * \brief Classe permettant la gestion des remises de cheque
  29. */
  30. class RemiseCheque extends CommonObject
  31. {
  32. public $element='chequereceipt';
  33. public $table_element='bordereau_cheque';
  34. var $id;
  35. var $num;
  36. var $intitule;
  37. //! Numero d'erreur Plage 1024-1279
  38. var $errno;
  39. /**
  40. * Constructor
  41. *
  42. * @param DoliDB $DB Database handler
  43. */
  44. function RemiseCheque($DB)
  45. {
  46. $this->db = $DB;
  47. $this->next_id = 0;
  48. $this->previous_id = 0;
  49. }
  50. /**
  51. * Load record
  52. *
  53. * @param int $id Id record
  54. * @param string $ref Ref record
  55. * @return int <0 if KO, > 0 if OK
  56. */
  57. function fetch($id,$ref='')
  58. {
  59. global $conf;
  60. $sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.number, bc.statut, bc.nbcheque";
  61. $sql.= ", bc.date_bordereau as date_bordereau";
  62. $sql.= ", ba.label as account_label";
  63. $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
  64. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
  65. $sql.= " WHERE bc.entity = ".$conf->entity;
  66. if ($id) $sql.= " AND bc.rowid = ".$id;
  67. if ($ref) $sql.= " AND bc.number = '".$this->db->escape($ref)."'";
  68. dol_syslog("RemiseCheque::fetch sql=".$sql, LOG_DEBUG);
  69. $resql = $this->db->query($sql);
  70. if ($resql)
  71. {
  72. if ($obj = $this->db->fetch_object($resql) )
  73. {
  74. $this->id = $obj->rowid;
  75. $this->amount = $obj->amount;
  76. $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
  77. $this->account_id = $obj->fk_bank_account;
  78. $this->account_label = $obj->account_label;
  79. $this->author_id = $obj->fk_user_author;
  80. $this->nbcheque = $obj->nbcheque;
  81. $this->statut = $obj->statut;
  82. if ($this->statut == 0)
  83. {
  84. $this->number = "(PROV".$this->id.")";
  85. }
  86. else
  87. {
  88. $this->number = $obj->number;
  89. }
  90. $this->ref = $this->number;
  91. }
  92. $this->db->free($resql);
  93. return 1;
  94. }
  95. else
  96. {
  97. $this->error=$this->db->lasterror();
  98. return -1;
  99. }
  100. }
  101. /**
  102. * Create a receipt to send cheques
  103. *
  104. * @param user User making creation
  105. * @param account_id Bank account for cheque receipt
  106. * @param limit Limit number of cheque to this
  107. * @param toRemise array with cheques to remise
  108. * @return int <0 if KO, >0 if OK
  109. */
  110. function create($user, $account_id, $limit=40,$toRemise)
  111. {
  112. global $conf;
  113. $this->errno = 0;
  114. $this->id = 0;
  115. $now=dol_now();
  116. $this->db->begin();
  117. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
  118. $sql.= "datec";
  119. $sql.= ", date_bordereau";
  120. $sql.= ", fk_user_author";
  121. $sql.= ", fk_bank_account";
  122. $sql.= ", statut";
  123. $sql.= ", amount";
  124. $sql.= ", number";
  125. $sql.= ", entity";
  126. $sql.= ", nbcheque";
  127. $sql.= ") VALUES (";
  128. $sql.= $this->db->idate($now);
  129. $sql.= ", ".$this->db->idate($now);
  130. $sql.= ", ".$user->id;
  131. $sql.= ", ".$account_id;
  132. $sql.= ", 0";
  133. $sql.= ", 0";
  134. $sql.= ", 0";
  135. $sql.= ", ".$conf->entity;
  136. $sql.= ", 0";
  137. $sql.= ")";
  138. dol_syslog("RemiseCheque::Create sql=".$sql, LOG_DEBUG);
  139. $resql = $this->db->query($sql);
  140. if ( $resql )
  141. {
  142. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
  143. if ($this->id == 0)
  144. {
  145. $this->errno = -1024;
  146. dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
  147. }
  148. if ($this->id > 0 && $this->errno == 0)
  149. {
  150. $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
  151. $sql.= " SET number='(PROV".$this->id.")'";
  152. $sql.= " WHERE rowid='".$this->id."';";
  153. dol_syslog("RemiseCheque::Create sql=".$sql, LOG_DEBUG);
  154. $resql = $this->db->query($sql);
  155. if (! $resql)
  156. {
  157. $this->errno = -1025;
  158. dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
  159. }
  160. }
  161. if ($this->id > 0 && $this->errno == 0)
  162. {
  163. $lines = array();
  164. $sql = "SELECT b.rowid";
  165. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  166. $sql.= " WHERE b.fk_type = 'CHQ'";
  167. $sql.= " AND b.amount > 0";
  168. $sql.= " AND b.fk_bordereau = 0";
  169. $sql.= " AND b.fk_account='".$account_id."'";
  170. if ($limit) $sql.= $this->db->plimit($limit);
  171. dol_syslog("RemiseCheque::Create sql=".$sql, LOG_DEBUG);
  172. $resql = $this->db->query($sql);
  173. if ($resql)
  174. {
  175. while ($row = $this->db->fetch_row($resql) )
  176. {
  177. array_push($lines, $row[0]);
  178. }
  179. $this->db->free($resql);
  180. }
  181. else
  182. {
  183. $this->errno = -1026;
  184. dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
  185. }
  186. }
  187. if ($this->id > 0 && $this->errno == 0)
  188. {
  189. foreach ($lines as $lineid)
  190. {
  191. $checkremise=false;
  192. foreach ($toRemise as $linetoremise)
  193. {
  194. if($linetoremise==$lineid) $checkremise=true;
  195. }
  196. if($checkremise==true)
  197. {
  198. $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
  199. $sql.= " SET fk_bordereau = ".$this->id;
  200. $sql.= " WHERE rowid = ".$lineid;
  201. dol_syslog("RemiseCheque::Create sql=".$sql, LOG_DEBUG);
  202. $resql = $this->db->query($sql);
  203. if (!$resql)
  204. {
  205. $this->errno = -18;
  206. dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
  207. }
  208. }
  209. }
  210. }
  211. if ($this->id > 0 && $this->errno == 0)
  212. {
  213. if ($this->updateAmount() <> 0)
  214. {
  215. $this->errno = -1027;
  216. dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
  217. }
  218. }
  219. }
  220. else
  221. {
  222. $this->errno = -1;
  223. $this->error=$this->db->lasterror();
  224. $this->errno=$this->db->lasterrno();
  225. dol_syslog("RemiseCheque::Create Error ".$this->error, LOG_ERR);
  226. }
  227. if (! $this->errno && ! empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
  228. {
  229. $res=$this->validate($user);
  230. //if ($res < 0) $error++;
  231. }
  232. if (! $this->errno)
  233. {
  234. $this->db->commit();
  235. return $this->id;
  236. }
  237. else
  238. {
  239. $this->db->rollback();
  240. return $this->errno;
  241. }
  242. }
  243. /**
  244. * Supprime la remise en base
  245. *
  246. * @param user utilisateur qui effectue l'operation
  247. */
  248. function delete($user='')
  249. {
  250. global $conf;
  251. $this->errno = 0;
  252. $this->db->begin();
  253. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
  254. $sql.= " WHERE rowid = ".$this->id;
  255. $sql.= " AND entity = ".$conf->entity;
  256. $resql = $this->db->query($sql);
  257. if ( $resql )
  258. {
  259. $num = $this->db->affected_rows($resql);
  260. if ($num <> 1)
  261. {
  262. $this->errno = -2;
  263. dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
  264. }
  265. if ( $this->errno === 0)
  266. {
  267. $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
  268. $sql.= " SET fk_bordereau = 0";
  269. $sql.= " WHERE fk_bordereau = '".$this->id."'";
  270. $resql = $this->db->query($sql);
  271. if (!$resql)
  272. {
  273. $this->errno = -1028;
  274. dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
  275. }
  276. }
  277. }
  278. if ($this->errno === 0)
  279. {
  280. $this->db->commit();
  281. }
  282. else
  283. {
  284. $this->db->rollback();
  285. dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
  286. }
  287. return $this->errno;
  288. }
  289. /**
  290. * Validate a receipt
  291. *
  292. * @param user User
  293. * @return int <0 if KO, >0 if OK
  294. */
  295. function validate($user)
  296. {
  297. global $langs,$conf;
  298. $this->errno = 0;
  299. $this->db->begin();
  300. $numref=$this->getNextNumber();
  301. if ($this->errno == 0 && $numref)
  302. {
  303. $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
  304. $sql.= " SET statut = 1, number = '".$numref."'";
  305. $sql.= " WHERE rowid = ".$this->id;
  306. $sql.= " AND entity = ".$conf->entity;
  307. $sql.= " AND statut = 0";
  308. dol_syslog("RemiseCheque::Validate sql=".$sql, LOG_DEBUG);
  309. $resql = $this->db->query($sql);
  310. if ( $resql )
  311. {
  312. $num = $this->db->affected_rows($resql);
  313. if ($num == 1)
  314. {
  315. $this->number = $numref;
  316. $this->statut = 1;
  317. }
  318. else
  319. {
  320. $this->errno = -1029;
  321. dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
  322. }
  323. }
  324. else
  325. {
  326. $this->errno = -1033;
  327. dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
  328. }
  329. }
  330. // Commit/Rollback
  331. if ($this->errno == 0)
  332. {
  333. $this->db->commit();
  334. return 1;
  335. }
  336. else
  337. {
  338. $this->db->rollback();
  339. dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
  340. return $this->errno;
  341. }
  342. }
  343. /**
  344. * Old module for cheque receipt numbering
  345. *
  346. * @return int Next number of cheque
  347. */
  348. function getNextNumber()
  349. {
  350. global $conf;
  351. $num=0;
  352. // We use +0 to convert varchar to number for mysql, use ::integer for postgres.
  353. // We must found a generic solution (Use a $db->toint function ?)
  354. $sql = "SELECT ";
  355. if ($this->db->type == 'pgsql') $sql.="MAX(number::integer)";
  356. else $sql.="MAX(number+0)";
  357. $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
  358. $sql.= " WHERE entity = ".$conf->entity;
  359. $sql.= " AND number not like '(%'";
  360. dol_syslog("Remisecheque::getNextNumber sql=".$sql);
  361. $resql = $this->db->query($sql);
  362. if ($resql)
  363. {
  364. $row = $this->db->fetch_row($resql);
  365. $num = $row[0];
  366. $this->db->free($resql);
  367. }
  368. else
  369. {
  370. $this->errno = -1034;
  371. dol_syslog("Remisecheque::Validate Erreur SELECT ($this->errno)", LOG_ERR);
  372. }
  373. $num++;
  374. return $num;
  375. }
  376. /**
  377. * Load indicators for dashboard (this->nbtodo and this->nbtodolate)
  378. *
  379. * @param User $user Objet user
  380. * @return int <0 if KO, >0 if OK
  381. */
  382. function load_board($user)
  383. {
  384. global $conf;
  385. if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
  386. $now=dol_now();
  387. $this->nbtodo=$this->nbtodolate=0;
  388. $sql = "SELECT b.rowid, b.datev as datefin";
  389. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  390. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  391. $sql.= " WHERE b.fk_account = ba.rowid";
  392. $sql.= " AND ba.entity = ".$conf->entity;
  393. $sql.= " AND b.fk_type = 'CHQ'";
  394. $sql.= " AND b.fk_bordereau = 0";
  395. $sql.= " AND b.amount > 0";
  396. $resql=$this->db->query($sql);
  397. if ($resql)
  398. {
  399. while ($obj=$this->db->fetch_object($resql))
  400. {
  401. $this->nbtodo++;
  402. if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) $this->nbtodolate++;
  403. }
  404. return 1;
  405. }
  406. else
  407. {
  408. dol_print_error($this->db);
  409. $this->error=$this->db->error();
  410. return -1;
  411. }
  412. }
  413. /**
  414. * Build document
  415. * @param model Model name
  416. * @param outputlangs Object langs
  417. * @return int <0 if KO, >0 if OK
  418. */
  419. function generatePdf($model='blochet', $outputlangs)
  420. {
  421. global $langs,$conf;
  422. if (empty($model)) $model='blochet';
  423. dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
  424. $dir=DOL_DOCUMENT_ROOT ."/core/modules/cheque/pdf/";
  425. // Charge le modele
  426. $file = "pdf_".$model.".class.php";
  427. if (file_exists($dir.$file))
  428. {
  429. require_once(DOL_DOCUMENT_ROOT ."/compta/bank/class/account.class.php");
  430. require_once($dir.$file);
  431. $classname='BordereauCheque'.ucfirst($model);
  432. $docmodel = new $classname($db);
  433. $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
  434. $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
  435. $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
  436. $sql.= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
  437. $sql.= " WHERE b.fk_account = ba.rowid";
  438. $sql.= " AND b.fk_bordereau = bc.rowid";
  439. $sql.= " AND bc.rowid = ".$this->id;
  440. $sql.= " AND bc.entity = ".$conf->entity;
  441. $sql.= " ORDER BY b.dateo ASC, b.rowid ASC";
  442. dol_syslog("RemiseCheque::generatePdf sql=".$sql, LOG_DEBUG);
  443. $result = $this->db->query($sql);
  444. if ($result)
  445. {
  446. $i = 0;
  447. while ($objp = $this->db->fetch_object($result))
  448. {
  449. $docmodel->lines[$i]->bank_chq = $objp->banque;
  450. $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
  451. $docmodel->lines[$i]->amount_chq = $objp->amount;
  452. $docmodel->lines[$i]->num_chq = $objp->num_chq;
  453. $i++;
  454. }
  455. }
  456. $docmodel->nbcheque = $this->nbcheque;
  457. $docmodel->number = $this->number;
  458. $docmodel->amount = $this->amount;
  459. $docmodel->date = $this->date_bordereau;
  460. $account = new Account($this->db);
  461. $account->fetch($this->account_id);
  462. $docmodel->account = &$account;
  463. // We save charset_output to restore it because write_file can change it if needed for
  464. // output format that does not support UTF8.
  465. $sav_charseSupprimert_output=$outputlangs->charset_output;
  466. $result=$docmodel->write_file($conf->banque->dir_output.'/bordereau', $this->number, $outputlangs);
  467. if ($result > 0)
  468. {
  469. $outputlangs->charset_output=$sav_charset_output;
  470. return 1;
  471. }
  472. else
  473. {
  474. $outputlangs->charset_output=$sav_charset_output;
  475. dol_syslog("Error");
  476. dol_print_error($db,$docmodel->error);
  477. return 0;
  478. }
  479. }
  480. else
  481. {
  482. $this->error=$langs->trans("ErrorFileDoesNotExists",$dir.$file);
  483. return -1;
  484. }
  485. }
  486. /**
  487. * \brief Mets a jour le montant total
  488. * \return int 0 en cas de succes
  489. */
  490. function updateAmount()
  491. {
  492. global $conf;
  493. $this->errno = 0;
  494. $this->db->begin();
  495. $total = 0;
  496. $nb = 0;
  497. $sql = "SELECT amount ";
  498. $sql.= " FROM ".MAIN_DB_PREFIX."bank";
  499. $sql.= " WHERE fk_bordereau = ".$this->id;
  500. $resql = $this->db->query($sql);
  501. if ( $resql )
  502. {
  503. while ( $row = $this->db->fetch_row($resql) )
  504. {
  505. $total += $row[0];
  506. $nb++;
  507. }
  508. $this->db->free($resql);
  509. $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
  510. $sql.= " SET amount = '".price2num($total)."'";
  511. $sql.= ", nbcheque = ".$nb;
  512. $sql.= " WHERE rowid = ".$this->id;
  513. $sql.= " AND entity = ".$conf->entity;
  514. $resql = $this->db->query($sql);
  515. if (!$resql)
  516. {
  517. $this->errno = -1030;
  518. dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
  519. }
  520. }
  521. else
  522. {
  523. $this->errno = -1031;
  524. dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
  525. }
  526. if ($this->errno === 0)
  527. {
  528. $this->db->commit();
  529. }
  530. else
  531. {
  532. $this->db->rollback();
  533. dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
  534. }
  535. return $this->errno;
  536. }
  537. /**
  538. * \brief Insere la remise en base
  539. * \param account_id Compte bancaire concerne
  540. * \return int
  541. */
  542. function removeCheck($account_id)
  543. {
  544. $this->errno = 0;
  545. if ($this->id > 0)
  546. {
  547. $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
  548. $sql.= " SET fk_bordereau = 0";
  549. $sql.= " WHERE rowid = '".$account_id."'";
  550. $sql.= " AND fk_bordereau = ".$this->id;
  551. $resql = $this->db->query($sql);
  552. if ($resql)
  553. {
  554. $this->updateAmount();
  555. }
  556. else
  557. {
  558. $this->errno = -1032;
  559. dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
  560. }
  561. }
  562. return 0;
  563. }
  564. /**
  565. * \brief Charge les proprietes ref_previous et ref_next
  566. * \return int <0 si ko, 0 si ok
  567. */
  568. function load_previous_next_id()
  569. {
  570. global $conf;
  571. $this->errno = 0;
  572. $sql = "SELECT MAX(rowid)";
  573. $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
  574. $sql.= " WHERE rowid < ".$this->id;
  575. $sql.= " AND entity = ".$conf->entity;
  576. $result = $this->db->query($sql);
  577. if (! $result)
  578. {
  579. $this->errno = -1035;
  580. }
  581. $row = $this->db->fetch_row($result);
  582. $this->previous_id = $row[0];
  583. $sql = "SELECT MIN(rowid)";
  584. $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
  585. $sql.= " WHERE rowid > ".$this->id;
  586. $sql.= " AND entity = ".$conf->entity;
  587. $result = $this->db->query($sql);
  588. if (! $result)
  589. {
  590. $this->errno = -1035;
  591. }
  592. $row = $this->db->fetch_row($result);
  593. $this->next_id = $row[0];
  594. return $this->errno;
  595. }
  596. /**
  597. * Set the creation date
  598. * @param user Object user
  599. * @param date Date creation
  600. * @return int <0 if KO, >0 if OK
  601. */
  602. function set_date($user, $date)
  603. {
  604. if ($user->rights->banque->cheque)
  605. {
  606. $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
  607. $sql.= " SET date_bordereau = ".($date ? $this->db->idate($date) : 'null');
  608. $sql.= " WHERE rowid = ".$this->id;
  609. dol_syslog("RemiseCheque::set_date sql=$sql",LOG_DEBUG);
  610. $resql=$this->db->query($sql);
  611. if ($resql)
  612. {
  613. $this->date_bordereau = $date;
  614. return 1;
  615. }
  616. else
  617. {
  618. $this->error=$this->db->error();
  619. dol_syslog("RemiseCheque::set_date ".$this->error,LOG_ERR);
  620. return -1;
  621. }
  622. }
  623. else
  624. {
  625. return -2;
  626. }
  627. }
  628. /**
  629. * Renvoie nom clicable (avec eventuellement le picto)
  630. * @param withpicto Inclut le picto dans le lien
  631. * @param option Sur quoi pointe le lien
  632. * @return string Chaine avec URL
  633. */
  634. function getNomUrl($withpicto=0,$option='')
  635. {
  636. global $langs;
  637. $result='';
  638. $number=$this->ref;
  639. if ($this->statut == 0) $number='(PROV'.$this->id.')';
  640. $lien = '<a href="'.DOL_URL_ROOT.'/compta/paiement/cheque/fiche.php?id='.$this->id.'">';
  641. $lienfin='</a>';
  642. if ($withpicto) $result.=($lien.img_object($langs->trans("ShowCheckReceipt"),'payment').$lienfin.' ');
  643. $result.=$lien.$number.$lienfin;
  644. return $result;
  645. }
  646. /**
  647. * \brief Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
  648. * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  649. * \return string Libelle
  650. */
  651. function getLibStatut($mode=0)
  652. {
  653. return $this->LibStatut($this->statut,$mode);
  654. }
  655. /**
  656. * Return label of a status
  657. * @param status Statut
  658. * @param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  659. * @return string Libelle du statut
  660. */
  661. function LibStatut($status,$mode=0)
  662. {
  663. global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
  664. $langs->load('compta');
  665. if ($mode == 0)
  666. {
  667. if ($status == 0) return $langs->trans('ToValidate');
  668. if ($status == 1) return $langs->trans('Validated');
  669. }
  670. if ($mode == 1)
  671. {
  672. if ($status == 0) return $langs->trans('ToValidate');
  673. if ($status == 1) return $langs->trans('Validated');
  674. }
  675. if ($mode == 2)
  676. {
  677. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0').' '.$langs->trans('ToValidate');
  678. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
  679. }
  680. if ($mode == 3)
  681. {
  682. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0');
  683. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
  684. }
  685. if ($mode == 4)
  686. {
  687. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0').' '.$langs->trans('ToValidate');
  688. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
  689. }
  690. if ($mode == 5)
  691. {
  692. if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut0');
  693. if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
  694. }
  695. return $langs->trans('Unknown');
  696. }
  697. }
  698. ?>