PageRenderTime 60ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/zeert/dolibarr
PHP | 777 lines | 556 code | 75 blank | 146 comment | 121 complexity | 45a7c35e7415b10d0bbfd4578578d154 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 __construct($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 $conf, $langs;
  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 (entity, datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
  136. $sql.= " VALUES (".$conf->entity.", '".$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. $accline = new AccountLine($this->db);
  259. // Delete bank urls. If payment is on a conciliated line, return error.
  260. if ($bank_line_id)
  261. {
  262. $result=$accline->fetch($bank_line_id);
  263. if ($result == 0) $accline->rowid=$bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
  264. $result=$accline->delete_urls($user);
  265. if ($result < 0)
  266. {
  267. $this->error=$accline->error;
  268. $this->db->rollback();
  269. return -3;
  270. }
  271. }
  272. // Delete payment (into paiement_facture and paiement)
  273. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
  274. $sql.= ' WHERE fk_paiement = '.$this->id;
  275. dol_syslog($sql);
  276. $result = $this->db->query($sql);
  277. if ($result)
  278. {
  279. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
  280. $sql.= ' WHERE rowid = '.$this->id;
  281. dol_syslog($sql);
  282. $result = $this->db->query($sql);
  283. if (! $result)
  284. {
  285. $this->error=$this->db->lasterror();
  286. $this->db->rollback();
  287. return -3;
  288. }
  289. // Supprimer l'ecriture bancaire si paiement lie a ecriture
  290. if ($bank_line_id)
  291. {
  292. $result=$accline->delete($user);
  293. if ($result < 0)
  294. {
  295. $this->error=$accline->error;
  296. $this->db->rollback();
  297. return -4;
  298. }
  299. }
  300. if (! $notrigger)
  301. {
  302. // Appel des triggers
  303. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  304. $interface=new Interfaces($this->db);
  305. $result=$interface->run_triggers('PAYMENT_DELETE',$this,$user,$langs,$conf);
  306. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  307. // Fin appel triggers
  308. }
  309. $this->db->commit();
  310. return 1;
  311. }
  312. else
  313. {
  314. $this->error=$this->db->error;
  315. $this->db->rollback();
  316. return -5;
  317. }
  318. }
  319. /**
  320. * A record into bank for payment with links between this bank record and invoices of payment.
  321. * All payment properties must have been set first like after a call to create().
  322. *
  323. * @param User $user Object of user making payment
  324. * @param string $mode 'payment', 'payment_supplier'
  325. * @param string $label Label to use in bank record
  326. * @param int $accountid Id of bank account to do link with
  327. * @param string $emetteur_nom Name of transmitter
  328. * @param string $emetteur_banque Name of bank
  329. * @param int $notrigger No trigger
  330. * @return int <0 if KO, bank_line_id if OK
  331. */
  332. function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque,$notrigger=0)
  333. {
  334. global $conf,$langs,$user;
  335. $error=0;
  336. $bank_line_id=0;
  337. $this->fk_account=$accountid;
  338. if ($conf->banque->enabled)
  339. {
  340. require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  341. dol_syslog("$user->id,$mode,$label,$this->fk_account,$emetteur_nom,$emetteur_banque");
  342. $acc = new Account($this->db);
  343. $acc->fetch($this->fk_account);
  344. $totalamount=$this->amount;
  345. if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility
  346. if ($mode == 'payment') $totalamount=$totalamount;
  347. if ($mode == 'payment_supplier') $totalamount=-$totalamount;
  348. // Insert payment into llx_bank
  349. $bank_line_id = $acc->addline(
  350. $this->datepaye,
  351. $this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
  352. $label,
  353. $totalamount,
  354. $this->num_paiement,
  355. '',
  356. $user,
  357. $emetteur_nom,
  358. $emetteur_banque
  359. );
  360. // Mise a jour fk_bank dans llx_paiement
  361. // On connait ainsi le paiement qui a genere l'ecriture bancaire
  362. if ($bank_line_id > 0)
  363. {
  364. $result=$this->update_fk_bank($bank_line_id);
  365. if ($result <= 0)
  366. {
  367. $error++;
  368. dol_print_error($this->db);
  369. }
  370. // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
  371. if ( ! $error)
  372. {
  373. $url='';
  374. if ($mode == 'payment') $url=DOL_URL_ROOT.'/compta/paiement/fiche.php?id=';
  375. if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=';
  376. if ($url)
  377. {
  378. $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
  379. if ($result <= 0)
  380. {
  381. $error++;
  382. dol_print_error($this->db);
  383. }
  384. }
  385. }
  386. // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
  387. if (! $error)
  388. {
  389. $linkaddedforthirdparty=array();
  390. foreach ($this->amounts as $key => $value) // We should have always same third party but we loop in case of.
  391. {
  392. if ($mode == 'payment')
  393. {
  394. $fac = new Facture($this->db);
  395. $fac->fetch($key);
  396. $fac->fetch_thirdparty();
  397. if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
  398. {
  399. $result=$acc->add_url_line(
  400. $bank_line_id,
  401. $fac->thirdparty->id,
  402. DOL_URL_ROOT.'/comm/fiche.php?socid=',
  403. $fac->thirdparty->nom,
  404. 'company'
  405. );
  406. if ($result <= 0) dol_print_error($this->db);
  407. $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
  408. }
  409. }
  410. if ($mode == 'payment_supplier')
  411. {
  412. $fac = new FactureFournisseur($this->db);
  413. $fac->fetch($key);
  414. $fac->fetch_thirdparty();
  415. if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
  416. {
  417. $result=$acc->add_url_line(
  418. $bank_line_id,
  419. $fac->thirdparty->id,
  420. DOL_URL_ROOT.'/fourn/fiche.php?socid=',
  421. $fac->thirdparty->nom,
  422. 'company'
  423. );
  424. if ($result <= 0) dol_print_error($this->db);
  425. $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
  426. }
  427. }
  428. }
  429. }
  430. if (! $error && ! $notrigger)
  431. {
  432. // Appel des triggers
  433. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  434. $interface=new Interfaces($this->db);
  435. $result=$interface->run_triggers('PAYMENT_ADD_TO_BANK',$this,$user,$langs,$conf);
  436. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  437. // Fin appel triggers
  438. }
  439. }
  440. else
  441. {
  442. $this->error=$acc->error;
  443. $error++;
  444. }
  445. }
  446. if (! $error)
  447. {
  448. return $bank_line_id;
  449. }
  450. else
  451. {
  452. return -1;
  453. }
  454. }
  455. /**
  456. * Mise a jour du lien entre le paiement et la ligne generee dans llx_bank
  457. *
  458. * @param int $id_bank Id compte bancaire
  459. * @return int <0 if KO, >0 if OK
  460. */
  461. function update_fk_bank($id_bank)
  462. {
  463. $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.$id_bank;
  464. $sql.= ' WHERE rowid = '.$this->id;
  465. dol_syslog(get_class($this).'::update_fk_bank sql='.$sql);
  466. $result = $this->db->query($sql);
  467. if ($result)
  468. {
  469. return 1;
  470. }
  471. else
  472. {
  473. $this->error=$this->db->lasterror();
  474. dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
  475. return -1;
  476. }
  477. }
  478. /**
  479. * Updates the payment date
  480. *
  481. * @param timestamp $date New date
  482. * @return int <0 if KO, 0 if OK
  483. */
  484. function update_date($date)
  485. {
  486. if (!empty($date) && $this->statut!=1)
  487. {
  488. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  489. $sql.= " SET datep = ".$this->db->idate($date);
  490. $sql.= " WHERE rowid = ".$this->id;
  491. dol_syslog(get_class($this)."::update_date sql=".$sql);
  492. $result = $this->db->query($sql);
  493. if ($result)
  494. {
  495. $this->datepaye = $date;
  496. $this->date = $date;
  497. return 0;
  498. }
  499. else
  500. {
  501. $this->error='Error -1 '.$this->db->error();
  502. dol_syslog(get_class($this)."::update_date ".$this->error, LOG_ERR);
  503. return -2;
  504. }
  505. }
  506. return -1; //no date given or already validated
  507. }
  508. /**
  509. * Updates the payment number
  510. *
  511. * @param string $num New num
  512. * @return int <0 if KO, 0 if OK
  513. */
  514. function update_num($num)
  515. {
  516. if(!empty($num) && $this->statut!=1)
  517. {
  518. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  519. $sql.= " SET num_paiement = '".$this->db->escape($num)."'";
  520. $sql.= " WHERE rowid = ".$this->id;
  521. dol_syslog(get_class($this)."::update_num sql=".$sql);
  522. $result = $this->db->query($sql);
  523. if ($result)
  524. {
  525. $this->numero = $this->db->escape($num);
  526. return 0;
  527. }
  528. else
  529. {
  530. $this->error='Error -1 '.$this->db->error();
  531. dol_syslog(get_class($this)."::update_num ".$this->error, LOG_ERR);
  532. return -2;
  533. }
  534. }
  535. return -1; //no num given or already validated
  536. }
  537. /**
  538. * Validate payment
  539. *
  540. * @return int <0 if KO, >0 if OK
  541. */
  542. function valide()
  543. {
  544. $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.$this->id;
  545. dol_syslog(get_class($this).'::valide sql='.$sql);
  546. $result = $this->db->query($sql);
  547. if ($result)
  548. {
  549. return 1;
  550. }
  551. else
  552. {
  553. $this->error=$this->db->lasterror();
  554. dol_syslog(get_class($this).'::valide '.$this->error);
  555. return -1;
  556. }
  557. }
  558. /*
  559. * \brief Information sur l'objet
  560. * \param id id du paiement dont il faut afficher les infos
  561. */
  562. function info($id)
  563. {
  564. $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
  565. $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
  566. $sql.= ' WHERE p.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. ?>