ligneprelevement.class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  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 3 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 <https://www.gnu.org/licenses/>.
  19. *
  20. */
  21. /**
  22. * \file htdocs/compta/prelevement/class/ligneprelevement.class.php
  23. * \ingroup prelevement
  24. * \brief File of class to manage lines of Direct Debit orders
  25. */
  26. /**
  27. * Class to manage withdrawals
  28. */
  29. class LignePrelevement
  30. {
  31. /**
  32. * @var int ID
  33. */
  34. public $id;
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $statuts = array();
  40. /**
  41. * Constructor
  42. *
  43. * @param DoliDb $db Database handler
  44. */
  45. public function __construct($db)
  46. {
  47. global $conf, $langs;
  48. $this->db = $db;
  49. // List of language codes for status
  50. $langs->load("withdrawals");
  51. $this->statuts[0] = $langs->trans("StatusWaiting");
  52. $this->statuts[2] = $langs->trans("StatusPaid");
  53. $this->statuts[3] = $langs->trans("StatusRefused");
  54. }
  55. /**
  56. * Recupere l'objet prelevement
  57. *
  58. * @param int $rowid Id de la facture a recuperer
  59. * @return integer <0 if KO, >=0 if OK
  60. */
  61. public function fetch($rowid)
  62. {
  63. global $conf;
  64. $error = 0;
  65. $sql = "SELECT pl.rowid, pl.amount, p.ref, p.rowid as bon_rowid";
  66. $sql .= ", pl.statut, pl.fk_soc";
  67. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
  68. $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as p";
  69. $sql .= " WHERE pl.rowid=".((int) $rowid);
  70. $sql .= " AND p.rowid = pl.fk_prelevement_bons";
  71. $sql .= " AND p.entity = ".$conf->entity;
  72. $resql = $this->db->query($sql);
  73. if ($resql) {
  74. if ($this->db->num_rows($resql)) {
  75. $obj = $this->db->fetch_object($resql);
  76. $this->id = $obj->rowid;
  77. $this->amount = $obj->amount;
  78. $this->socid = $obj->fk_soc;
  79. $this->statut = $obj->statut;
  80. $this->bon_ref = $obj->ref;
  81. $this->bon_rowid = $obj->bon_rowid;
  82. } else {
  83. $error++;
  84. dol_syslog("LignePrelevement::Fetch rowid=$rowid numrows=0");
  85. }
  86. $this->db->free($resql);
  87. } else {
  88. $error++;
  89. dol_syslog("LignePrelevement::Fetch rowid=$rowid");
  90. dol_syslog($this->db->error());
  91. }
  92. return $error;
  93. }
  94. /**
  95. * Return status label of object
  96. *
  97. * @param int $mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto
  98. * @return string Label
  99. */
  100. public function getLibStatut($mode = 0)
  101. {
  102. return $this->LibStatut($this->statut, $mode);
  103. }
  104. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  105. /**
  106. * Return status label for a status
  107. *
  108. * @param int $status Id status
  109. * @param int $mode 0=Label, 1=Picto + label, 2=Picto, 3=Label + Picto
  110. * @return string Label
  111. */
  112. public function LibStatut($status, $mode = 0)
  113. {
  114. // phpcs:enable
  115. global $langs;
  116. if ($mode == 0) {
  117. return $langs->trans($this->statuts[$status]);
  118. } elseif ($mode == 1) {
  119. if ($status == 0) {
  120. return img_picto($langs->trans($this->statuts[$status]), 'statut1', 'class="valignmiddle"').' '.$langs->transnoentitiesnoconv($this->statuts[$status]); // Waiting
  121. } elseif ($status == 2) {
  122. return img_picto($langs->trans($this->statuts[$status]), 'statut6', 'class="valignmiddle"').' '.$langs->transnoentitiesnoconv($this->statuts[$status]); // Credited
  123. } elseif ($status == 3) {
  124. return img_picto($langs->trans($this->statuts[$status]), 'statut8', 'class="valignmiddle"').' '.$langs->transnoentitiesnoconv($this->statuts[$status]); // Refused
  125. }
  126. } elseif ($mode == 2) {
  127. if ($status == 0) {
  128. return img_picto($langs->trans($this->statuts[$status]), 'statut1', 'class="valignmiddle"');
  129. } elseif ($status == 2) {
  130. return img_picto($langs->trans($this->statuts[$status]), 'statut6', 'class="valignmiddle"');
  131. } elseif ($status == 3) {
  132. return img_picto($langs->trans($this->statuts[$status]), 'statut8', 'class="valignmiddle"');
  133. }
  134. } elseif ($mode == 3) {
  135. if ($status == 0) {
  136. return $langs->trans($this->statuts[$status]).' '.img_picto($langs->transnoentitiesnoconv($this->statuts[$status]), 'statut1', 'class="valignmiddle"');
  137. } elseif ($status == 2) {
  138. return $langs->trans($this->statuts[$status]).' '.img_picto($langs->transnoentitiesnoconv($this->statuts[$status]), 'statut6', 'class="valignmiddle"');
  139. } elseif ($status == 3) {
  140. return $langs->trans($this->statuts[$status]).' '.img_picto($langs->transnoentitiesnoconv($this->statuts[$status]), 'statut8', 'class="valignmiddle"');
  141. }
  142. }
  143. //return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  144. }
  145. /**
  146. * Function used to replace a thirdparty id with another one.
  147. *
  148. * @param DoliDB $db Database handler
  149. * @param int $origin_id Old thirdparty id
  150. * @param int $dest_id New thirdparty id
  151. * @return bool
  152. */
  153. public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
  154. {
  155. $tables = array(
  156. 'prelevement_lignes'
  157. );
  158. return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
  159. }
  160. }