PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/compta/paiement/class/paiement.class.php

https://github.com/asterix14/dolibarr
PHP | 775 lines | 556 code | 73 blank | 146 comment | 119 complexity | 0d6630c8f1c77afaf96a37f44b811171 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  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 2 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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/paiement/class/paiement.class.php
  21. * \ingroup facture
  22. * \brief File of class to manage payments of customers invoices
  23. */
  24. require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
  25. /** \class Paiement
  26. * \brief Classe permettant la gestion des paiements des factures clients
  27. */
  28. class Paiement extends CommonObject
  29. {
  30. public $element='payment';
  31. public $table_element='paiement';
  32. var $id;
  33. var $ref;
  34. var $facid;
  35. var $datepaye;
  36. var $total; // deprecated
  37. var $amount; // Total amount of payment
  38. var $amounts=array(); // Array of amounts
  39. var $author;
  40. var $paiementid; // Type de paiement. Stocke dans fk_paiement
  41. // de llx_paiement qui est lie aux types de
  42. //paiement de llx_c_paiement
  43. var $num_paiement; // Numero du CHQ, VIR, etc...
  44. var $bank_account; // Id compte bancaire du paiement
  45. var $bank_line; // Id de la ligne d'ecriture bancaire
  46. var $fk_account; // Id of bank account
  47. var $note;
  48. // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
  49. // fk_paiement dans llx_paiement_facture est le rowid du paiement
  50. /**
  51. * Constructor
  52. *
  53. * @param DoliDB $DB Database handler
  54. */
  55. function Paiement($DB)
  56. {
  57. $this->db = $DB ;
  58. }
  59. /**
  60. * Load payment from database
  61. *
  62. * @param int $id Id of payment to get
  63. * @return int <0 if KO, 0 if not found, >0 if OK
  64. */
  65. function fetch($id)
  66. {
  67. $sql = 'SELECT p.rowid, p.datep as dp, p.amount, p.statut, p.fk_bank,';
  68. $sql.= ' c.code as type_code, c.libelle as type_libelle,';
  69. $sql.= ' p.num_paiement, p.note,';
  70. $sql.= ' b.fk_account';
  71. $sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p';
  72. $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid ';
  73. $sql.= ' WHERE p.fk_paiement = c.id';
  74. $sql.= ' AND p.rowid = '.$id;
  75. dol_syslog(get_class($this)."::fetch sql=".$sql);
  76. $result = $this->db->query($sql);
  77. if ($result)
  78. {
  79. if ($this->db->num_rows($result))
  80. {
  81. $obj = $this->db->fetch_object($result);
  82. $this->id = $obj->rowid;
  83. $this->ref = $obj->rowid;
  84. $this->date = $this->db->jdate($obj->dp);
  85. $this->datepaye = $this->db->jdate($obj->dp);
  86. $this->numero = $obj->num_paiement;
  87. $this->montant = $obj->amount; // deprecated
  88. $this->amount = $obj->amount;
  89. $this->note = $obj->note;
  90. $this->type_libelle = $obj->type_libelle;
  91. $this->type_code = $obj->type_code;
  92. $this->statut = $obj->statut;
  93. $this->bank_account = $obj->fk_account;
  94. $this->bank_line = $obj->fk_bank;
  95. $this->db->free($result);
  96. return 1;
  97. }
  98. else
  99. {
  100. $this->db->free($result);
  101. return 0;
  102. }
  103. }
  104. else
  105. {
  106. dol_print_error($this->db);
  107. return -1;
  108. }
  109. }
  110. /**
  111. * Create payment of invoices into database.
  112. * Use this->amounts to have list of invoices for the payment
  113. *
  114. * @param User $user Object user
  115. * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more
  116. * @return int id of created payment, < 0 if error
  117. */
  118. function create($user,$closepaidinvoices=0)
  119. {
  120. global $langs,$conf;
  121. $error = 0;
  122. $now=dol_now();
  123. // Clean parameters
  124. $totalamount = 0;
  125. foreach ($this->amounts as $key => $value) // How payment is dispatch
  126. {
  127. $newvalue = price2num($value,'MT');
  128. $this->amounts[$key] = $newvalue;
  129. $totalamount += $newvalue;
  130. }
  131. $totalamount = price2num($totalamount);
  132. // Check parameters
  133. if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
  134. $this->db->begin();
  135. $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
  136. $sql.= " VALUES ('".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$totalamount."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")";
  137. dol_syslog(get_class($this)."::Create insert paiement sql=".$sql);
  138. $resql = $this->db->query($sql);
  139. if ($resql)
  140. {
  141. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
  142. // Insert links amount / invoices
  143. foreach ($this->amounts as $key => $amount)
  144. {
  145. $facid = $key;
  146. if (is_numeric($amount) && $amount <> 0)
  147. {
  148. $amount = price2num($amount);
  149. $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount)';
  150. $sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\')';
  151. dol_syslog(get_class($this).'::Create Amount line '.$key.' insert paiement_facture sql='.$sql);
  152. $resql=$this->db->query($sql);
  153. if ($resql)
  154. {
  155. // If we want to closed payed invoices
  156. if ($closepaidinvoices)
  157. {
  158. $invoice=new Facture($this->db);
  159. $invoice->fetch($facid);
  160. $paiement = $invoice->getSommePaiement();
  161. $creditnotes=$invoice->getSumCreditNotesUsed();
  162. $deposits=$invoice->getSumDepositsUsed();
  163. $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
  164. $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
  165. // If there is withdrawals request to do and not done yet, we wait before closing.
  166. $mustwait=0;
  167. $listofpayments=$invoice->getListOfPayments();
  168. foreach($listofpayments as $paym)
  169. {
  170. // This payment might be this one or a previous one
  171. if ($paym['type']=='PRE')
  172. {
  173. if ($conf->prelevement->enabled)
  174. {
  175. // TODO Check if this payment has a withdraw request
  176. // if not, $mustwait++; // This will disable automatic close on invoice to allow to process
  177. }
  178. }
  179. }
  180. if ($invoice->type != 0 && $invoice->type != 1) dol_syslog("Invoice ".$facid." is not a standard nor replacement invoice. We do nothing more.");
  181. else if ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
  182. else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
  183. else $result=$invoice->set_paid($user,'','');
  184. }
  185. }
  186. else
  187. {
  188. $this->error=$this->db->lasterror();
  189. dol_syslog(get_class($this).'::Create insert paiement_facture error='.$this->error, LOG_ERR);
  190. $error++;
  191. }
  192. }
  193. else
  194. {
  195. dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
  196. }
  197. }
  198. if (! $error)
  199. {
  200. // Appel des triggers
  201. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  202. $interface=new Interfaces($this->db);
  203. $result=$interface->run_triggers('PAYMENT_CUSTOMER_CREATE',$this,$user,$langs,$conf);
  204. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  205. // Fin appel triggers
  206. }
  207. }
  208. else
  209. {
  210. $this->error=$this->db->lasterror();
  211. dol_syslog(get_class($this).'::Create insert paiement error='.$this->error, LOG_ERR);
  212. $error++;
  213. }
  214. if (! $error)
  215. {
  216. $this->amount=$totalamount;
  217. $this->total=$totalamount; // deprecated
  218. $this->db->commit();
  219. return $this->id;
  220. }
  221. else
  222. {
  223. $this->db->rollback();
  224. return -1;
  225. }
  226. }
  227. /**
  228. * Supprime un paiement ainsi que les lignes qu'il a genere dans comptes
  229. * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse
  230. * Si le paiement porte sur au moins une facture a "payee", on refuse
  231. *
  232. * @param int $notrigger No trigger
  233. * @return int <0 si ko, >0 si ok
  234. */
  235. function delete($notrigger=0)
  236. {
  237. global $conf, $user, $langs;
  238. $error=0;
  239. $bank_line_id = $this->bank_line;
  240. $this->db->begin();
  241. // Verifier si paiement porte pas sur une facture classee
  242. // Si c'est le cas, on refuse la suppression
  243. $billsarray=$this->getBillsArray('fk_statut > 1');
  244. if (is_array($billsarray))
  245. {
  246. if (count($billsarray))
  247. {
  248. $this->error="ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
  249. $this->db->rollback();
  250. return -1;
  251. }
  252. }
  253. else
  254. {
  255. $this->db->rollback();
  256. return -2;
  257. }
  258. // Delete bank urls. If payment if on a conciliated line, return error.
  259. if ($bank_line_id)
  260. {
  261. $accline = new AccountLine($this->db);
  262. $accline->fetch($bank_line_id);
  263. $result=$accline->delete_urls($user);
  264. if ($result < 0)
  265. {
  266. $this->error=$accline->error;
  267. $this->db->rollback();
  268. return -3;
  269. }
  270. }
  271. // Delete payment (into paiement_facture and paiement)
  272. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
  273. $sql.= ' WHERE fk_paiement = '.$this->id;
  274. $result = $this->db->query($sql);
  275. if ($result)
  276. {
  277. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
  278. $sql.= ' WHERE rowid = '.$this->id;
  279. $result = $this->db->query($sql);
  280. if (! $result)
  281. {
  282. $this->error=$this->db->lasterror();
  283. $this->db->rollback();
  284. return -3;
  285. }
  286. // Supprimer l'ecriture bancaire si paiement lie a ecriture
  287. if ($bank_line_id)
  288. {
  289. $accline = new AccountLine($this->db);
  290. $accline->fetch($bank_line_id);
  291. $result=$accline->delete();
  292. if ($result < 0)
  293. {
  294. $this->error=$accline->error;
  295. $this->db->rollback();
  296. return -4;
  297. }
  298. }
  299. if (! $notrigger)
  300. {
  301. // Appel des triggers
  302. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  303. $interface=new Interfaces($this->db);
  304. $result=$interface->run_triggers('PAYMENT_DELETE',$this,$user,$langs,$conf);
  305. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  306. // Fin appel triggers
  307. }
  308. $this->db->commit();
  309. return 1;
  310. }
  311. else
  312. {
  313. $this->error=$this->db->error;
  314. $this->db->rollback();
  315. return -5;
  316. }
  317. }
  318. /**
  319. * A record into bank for payment with links between this bank record and invoices of payment.
  320. * All payment properties must have been set first like after a call to create().
  321. *
  322. * @param User $user Object of user making payment
  323. * @param string $mode 'payment', 'payment_supplier'
  324. * @param string $label Label to use in bank record
  325. * @param int $accountid Id of bank account to do link with
  326. * @param string $emetteur_nom Name of transmitter
  327. * @param string $emetteur_banque Name of bank
  328. * @param int $notrigger No trigger
  329. * @return int <0 if KO, bank_line_id if OK
  330. */
  331. function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque,$notrigger=0)
  332. {
  333. global $conf,$langs,$user;
  334. $error=0;
  335. $bank_line_id=0;
  336. $this->fk_account=$accountid;
  337. if ($conf->banque->enabled)
  338. {
  339. require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  340. dol_syslog("$user->id,$mode,$label,$this->fk_account,$emetteur_nom,$emetteur_banque");
  341. $acc = new Account($this->db);
  342. $acc->fetch($this->fk_account);
  343. $totalamount=$this->amount;
  344. if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility
  345. if ($mode == 'payment') $totalamount=$totalamount;
  346. if ($mode == 'payment_supplier') $totalamount=-$totalamount;
  347. // Insert payment into llx_bank
  348. $bank_line_id = $acc->addline(
  349. $this->datepaye,
  350. $this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
  351. $label,
  352. $totalamount,
  353. $this->num_paiement,
  354. '',
  355. $user,
  356. $emetteur_nom,
  357. $emetteur_banque
  358. );
  359. // Mise a jour fk_bank dans llx_paiement
  360. // On connait ainsi le paiement qui a genere l'ecriture bancaire
  361. if ($bank_line_id > 0)
  362. {
  363. $result=$this->update_fk_bank($bank_line_id);
  364. if ($result <= 0)
  365. {
  366. $error++;
  367. dol_print_error($this->db);
  368. }
  369. // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
  370. if ( ! $error)
  371. {
  372. $url='';
  373. if ($mode == 'payment') $url=DOL_URL_ROOT.'/compta/paiement/fiche.php?id=';
  374. if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=';
  375. if ($url)
  376. {
  377. $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
  378. if ($result <= 0)
  379. {
  380. $error++;
  381. dol_print_error($this->db);
  382. }
  383. }
  384. }
  385. // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
  386. if (! $error)
  387. {
  388. $linkaddedforthirdparty=array();
  389. foreach ($this->amounts as $key => $value) // We should have always same third party but we loop in case of.
  390. {
  391. if ($mode == 'payment')
  392. {
  393. $fac = new Facture($this->db);
  394. $fac->fetch($key);
  395. $fac->fetch_thirdparty();
  396. if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
  397. {
  398. $result=$acc->add_url_line(
  399. $bank_line_id,
  400. $fac->thirdparty->id,
  401. DOL_URL_ROOT.'/comm/fiche.php?socid=',
  402. $fac->thirdparty->nom,
  403. 'company'
  404. );
  405. if ($result <= 0) dol_print_error($this->db);
  406. $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
  407. }
  408. }
  409. if ($mode == 'payment_supplier')
  410. {
  411. $fac = new FactureFournisseur($this->db);
  412. $fac->fetch($key);
  413. $fac->fetch_thirdparty();
  414. if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
  415. {
  416. $result=$acc->add_url_line(
  417. $bank_line_id,
  418. $fac->thirdparty->id,
  419. DOL_URL_ROOT.'/fourn/fiche.php?socid=',
  420. $fac->thirdparty->nom,
  421. 'company'
  422. );
  423. if ($result <= 0) dol_print_error($this->db);
  424. $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
  425. }
  426. }
  427. }
  428. }
  429. if (! $error && ! $notrigger)
  430. {
  431. // Appel des triggers
  432. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  433. $interface=new Interfaces($this->db);
  434. $result=$interface->run_triggers('PAYMENT_ADD_TO_BANK',$this,$user,$langs,$conf);
  435. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  436. // Fin appel triggers
  437. }
  438. }
  439. else
  440. {
  441. $this->error=$acc->error;
  442. $error++;
  443. }
  444. }
  445. if (! $error)
  446. {
  447. return $bank_line_id;
  448. }
  449. else
  450. {
  451. return -1;
  452. }
  453. }
  454. /**
  455. * Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
  456. *
  457. * @param int $id_bank Id compte bancaire
  458. * @return int <0 if KO, >0 if OK
  459. */
  460. function update_fk_bank($id_bank)
  461. {
  462. $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.$id_bank;
  463. $sql.= ' WHERE rowid = '.$this->id;
  464. dol_syslog(get_class($this).'::update_fk_bank sql='.$sql);
  465. $result = $this->db->query($sql);
  466. if ($result)
  467. {
  468. return 1;
  469. }
  470. else
  471. {
  472. $this->error=$this->db->lasterror();
  473. dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
  474. return -1;
  475. }
  476. }
  477. /**
  478. * Updates the payment date
  479. *
  480. * @param timestamp $date New date
  481. * @return int <0 if KO, 0 if OK
  482. */
  483. function update_date($date)
  484. {
  485. if (!empty($date) && $this->statut!=1)
  486. {
  487. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  488. $sql.= " SET datep = ".$this->db->idate($date);
  489. $sql.= " WHERE rowid = ".$this->id;
  490. dol_syslog(get_class($this)."::update_date sql=".$sql);
  491. $result = $this->db->query($sql);
  492. if ($result)
  493. {
  494. $this->datepaye = $date;
  495. $this->date = $date;
  496. return 0;
  497. }
  498. else
  499. {
  500. $this->error='Error -1 '.$this->db->error();
  501. dol_syslog(get_class($this)."::update_date ".$this->error, LOG_ERR);
  502. return -2;
  503. }
  504. }
  505. return -1; //no date given or already validated
  506. }
  507. /**
  508. * Updates the payment number
  509. *
  510. * @param string $num New num
  511. * @return int <0 if KO, 0 if OK
  512. */
  513. function update_num($num)
  514. {
  515. if(!empty($num) && $this->statut!=1)
  516. {
  517. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  518. $sql.= " SET num_paiement = '".$this->db->escape($num)."'";
  519. $sql.= " WHERE rowid = ".$this->id;
  520. dol_syslog(get_class($this)."::update_num sql=".$sql);
  521. $result = $this->db->query($sql);
  522. if ($result)
  523. {
  524. $this->numero = $this->db->escape($num);
  525. return 0;
  526. }
  527. else
  528. {
  529. $this->error='Error -1 '.$this->db->error();
  530. dol_syslog(get_class($this)."::update_num ".$this->error, LOG_ERR);
  531. return -2;
  532. }
  533. }
  534. return -1; //no num given or already validated
  535. }
  536. /**
  537. * Validate payment
  538. *
  539. * @return int <0 if KO, >0 if OK
  540. */
  541. function valide()
  542. {
  543. $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.$this->id;
  544. dol_syslog(get_class($this).'::valide sql='.$sql);
  545. $result = $this->db->query($sql);
  546. if ($result)
  547. {
  548. return 1;
  549. }
  550. else
  551. {
  552. $this->error=$this->db->lasterror();
  553. dol_syslog(get_class($this).'::valide '.$this->error);
  554. return -1;
  555. }
  556. }
  557. /*
  558. * \brief Information sur l'objet
  559. * \param id id du paiement dont il faut afficher les infos
  560. */
  561. function info($id)
  562. {
  563. $sql = 'SELECT c.rowid, c.datec, c.fk_user_creat, c.fk_user_modif,';
  564. $sql.= ' c.tms';
  565. $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as c';
  566. $sql.= ' WHERE c.rowid = '.$id;
  567. dol_syslog(get_class($this).'::info sql='.$sql);
  568. $result = $this->db->query($sql);
  569. if ($result)
  570. {
  571. if ($this->db->num_rows($result))
  572. {
  573. $obj = $this->db->fetch_object($result);
  574. $this->id = $obj->rowid;
  575. if ($obj->fk_user_creat)
  576. {
  577. $cuser = new User($this->db);
  578. $cuser->fetch($obj->fk_user_creat);
  579. $this->user_creation = $cuser;
  580. }
  581. if ($obj->fk_user_modif)
  582. {
  583. $muser = new User($this->db);
  584. $muser->fetch($obj->fk_user_modif);
  585. $this->user_modification = $muser;
  586. }
  587. $this->date_creation = $this->db->jdate($obj->datec);
  588. $this->date_modification = $this->db->jdate($obj->tms);
  589. }
  590. $this->db->free($result);
  591. }
  592. else
  593. {
  594. dol_print_error($this->db);
  595. }
  596. }
  597. /**
  598. * Retourne la liste des factures sur lesquels porte le paiement
  599. *
  600. * @param string $filter Critere de filtre
  601. * @return array Tableau des id de factures
  602. */
  603. function getBillsArray($filter='')
  604. {
  605. $sql = 'SELECT fk_facture';
  606. $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f';
  607. $sql.= ' WHERE pf.fk_facture = f.rowid AND fk_paiement = '.$this->id;
  608. if ($filter) $sql.= ' AND '.$filter;
  609. $resql = $this->db->query($sql);
  610. if ($resql)
  611. {
  612. $i=0;
  613. $num=$this->db->num_rows($resql);
  614. $billsarray=array();
  615. while ($i < $num)
  616. {
  617. $obj = $this->db->fetch_object($resql);
  618. $billsarray[$i]=$obj->fk_facture;
  619. $i++;
  620. }
  621. return $billsarray;
  622. }
  623. else
  624. {
  625. $this->error=$this->db->error();
  626. dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' - sql='.$sql);
  627. return -1;
  628. }
  629. }
  630. /**
  631. * Renvoie nom clicable (avec eventuellement le picto)
  632. *
  633. * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
  634. * @param string $option Sur quoi pointe le lien
  635. * @return string Chaine avec URL
  636. */
  637. function getNomUrl($withpicto=0,$option='')
  638. {
  639. global $langs;
  640. $result='';
  641. $lien = '<a href="'.DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$this->id.'">';
  642. $lienfin='</a>';
  643. if ($withpicto) $result.=($lien.img_object($langs->trans("ShowPayment"),'payment').$lienfin);
  644. if ($withpicto && $withpicto != 2) $result.=' ';
  645. if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin;
  646. return $result;
  647. }
  648. /**
  649. * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
  650. *
  651. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  652. * @return string Libelle
  653. */
  654. function getLibStatut($mode=0)
  655. {
  656. return $this->LibStatut($this->statut,$mode);
  657. }
  658. /**
  659. * Renvoi le libelle d'un statut donne
  660. *
  661. * @param int $status Statut
  662. * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
  663. * @return string Libelle du statut
  664. */
  665. function LibStatut($status,$mode=0)
  666. {
  667. global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
  668. $langs->load('compta');
  669. if ($mode == 0)
  670. {
  671. if ($status == 0) return $langs->trans('ToValidate');
  672. if ($status == 1) return $langs->trans('Validated');
  673. }
  674. if ($mode == 1)
  675. {
  676. if ($status == 0) return $langs->trans('ToValidate');
  677. if ($status == 1) return $langs->trans('Validated');
  678. }
  679. if ($mode == 2)
  680. {
  681. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
  682. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
  683. }
  684. if ($mode == 3)
  685. {
  686. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
  687. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
  688. }
  689. if ($mode == 4)
  690. {
  691. if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
  692. if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
  693. }
  694. if ($mode == 5)
  695. {
  696. if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
  697. if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
  698. }
  699. return $langs->trans('Unknown');
  700. }
  701. }
  702. ?>