html.formventilation.class.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  3. * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  4. * Copyright (C) 2013-2014 Alexandre Spangaro <alexandre.spangaro@gmail.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 3 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/accountancy/class/html.formventilation.class.php
  21. * \ingroup Accounting Expert
  22. * \brief Class for HML form
  23. */
  24. class FormVentilation extends Form {
  25. var $db;
  26. var $error;
  27. /**
  28. * Constructor
  29. *
  30. * @param DoliDB $db handler
  31. */
  32. function __construct($db) {
  33. $this->db = $db;
  34. return 1;
  35. }
  36. /**
  37. * Return select filter with date of transaction
  38. *
  39. * @param string $htmlname of input
  40. * @param string $selectedkey value
  41. * @return string select input
  42. */
  43. function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey) {
  44. global $langs;
  45. $date_array = array ();
  46. $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
  47. $sql .= ' ORDER BY import_key DESC';
  48. $out = '<SELECT name="' . $htmlname . '">';
  49. dol_syslog(get_class($this) . "::select_bookkeeping_importkey sql=" . $sql, LOG_DEBUG);
  50. $resql = $this->db->query($sql);
  51. if ($resql) {
  52. $i = 0;
  53. $num = $this->db->num_rows($resql);
  54. while ( $i < $num ) {
  55. $obj = $this->db->fetch_object($resql);
  56. $selected = '';
  57. if ($selectedkey == $obj->import_key) {
  58. $selected = ' selected="selected" ';
  59. }
  60. $out .= '<OPTION value="' . $obj->import_key . '"' . $selected . '>' . $obj->import_key . '</OPTION>';
  61. $i ++;
  62. }
  63. } else {
  64. $this->error = "Error " . $this->db->lasterror();
  65. dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
  66. return - 1;
  67. }
  68. $out .= '</SELECT>';
  69. return $out;
  70. }
  71. /**
  72. * Return list of the accounts with label
  73. *
  74. * @param string $selectedid pcg_type
  75. * @param string $htmlname of combo list
  76. * @param int $showempty en empty line
  77. *
  78. * @return string with HTML select
  79. */
  80. function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array()) {
  81. global $conf, $user, $langs;
  82. $out = '';
  83. $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
  84. $sql .= " FROM " . MAIN_DB_PREFIX . "accountingaccount as aa";
  85. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  86. $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
  87. $sql .= " AND aa.active = 1";
  88. $sql .= " ORDER BY aa.account_number";
  89. dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
  90. $resql = $this->db->query($sql);
  91. if ($resql) {
  92. $out .= ajax_combobox($htmlname, $event);
  93. $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
  94. if ($showempty)
  95. $out .= '<option value="-1"></option>';
  96. $num = $this->db->num_rows($resql);
  97. $i = 0;
  98. if ($num) {
  99. while ( $i < $num ) {
  100. $obj = $this->db->fetch_object($resql);
  101. $label = $obj->account_number . ' - ' . $obj->label;
  102. // Remember guy's we store in database llx_facturedet the rowid of accountingaccount and not the account_number
  103. // Bacause same account_number can be share between different accounting_system and do have the same meaning
  104. if (($selectid != '') && $selectid == $obj->rowid) {
  105. // $out .= '<option value="' . $obj->account_number . '" selected="selected">' . $label . '</option>';
  106. $out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>';
  107. } else {
  108. // $out .= '<option value="' . $obj->account_number . '">' . $label . '</option>';
  109. $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>';
  110. }
  111. $i ++;
  112. }
  113. }
  114. $out .= '</select>';
  115. } else {
  116. $this->error = "Error " . $this->db->lasterror();
  117. dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
  118. return - 1;
  119. }
  120. $this->db->free($resql);
  121. return $out;
  122. }
  123. /**
  124. * Return list of pcg with label
  125. *
  126. * @param string $selectedid pcg_type
  127. * @param string $htmlname of combo list
  128. * @param int $showempty en empty line
  129. *
  130. * @return string with HTML select
  131. */
  132. function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) {
  133. global $conf, $user, $langs;
  134. $out = '';
  135. $sql = "SELECT DISTINCT pcg_type ";
  136. $sql .= " FROM " . MAIN_DB_PREFIX . "accountingaccount ";
  137. $sql .= " ORDER BY pcg_type";
  138. dol_syslog(get_class($this) . "::select_pcgtype sql=" . $sql, LOG_DEBUG);
  139. $resql = $this->db->query($sql);
  140. if ($resql) {
  141. $out .= ajax_combobox($htmlname, $event);
  142. $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
  143. if ($showempty)
  144. $out .= '<option value="-1"></option>';
  145. $num = $this->db->num_rows($resql);
  146. $i = 0;
  147. if ($num) {
  148. while ( $i < $num ) {
  149. $obj = $this->db->fetch_object($resql);
  150. $label = $obj->pcg_type;
  151. if (($selectid != '') && $selectid == $obj->pcg_type) {
  152. $out .= '<option value="' . $obj->pcg_type . '" selected="selected">' . $label . '</option>';
  153. } else {
  154. $out .= '<option value="' . $obj->pcg_type . '">' . $label . '</option>';
  155. }
  156. $i ++;
  157. }
  158. }
  159. $out .= '</select>';
  160. } else {
  161. $this->error = "Error " . $this->db->lasterror();
  162. dol_syslog(get_class($this) . "::select_pcgtype " . $this->error, LOG_ERR);
  163. return - 1;
  164. }
  165. $this->db->free($resql);
  166. return $out;
  167. }
  168. /**
  169. * Return subtype list of pcg with label
  170. *
  171. * @param string $selectedid pcg_type
  172. * @param string $htmlname of combo list
  173. * @param int $showempty en empty line
  174. *
  175. * @return string with HTML select
  176. */
  177. function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) {
  178. global $conf, $user, $langs;
  179. $out = '';
  180. $sql = "SELECT DISTINCT pcg_subtype ";
  181. $sql .= " FROM " . MAIN_DB_PREFIX . "accountingaccount ";
  182. $sql .= " ORDER BY pcg_subtype";
  183. dol_syslog(get_class($this) . "::select_pcgsubtype sql=" . $sql, LOG_DEBUG);
  184. $resql = $this->db->query($sql);
  185. if ($resql) {
  186. $out .= ajax_combobox($htmlname, $event);
  187. $out .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
  188. if ($showempty)
  189. $out .= '<option value="-1"></option>';
  190. $num = $this->db->num_rows($resql);
  191. $i = 0;
  192. if ($num) {
  193. while ( $i < $num ) {
  194. $obj = $this->db->fetch_object($resql);
  195. $label = $obj->pcg_subtype;
  196. if (($selectid != '') && $selectid == $obj->pcg_subtype) {
  197. $out .= '<option value="' . $obj->pcg_subtype . '" selected="selected">' . $label . '</option>';
  198. } else {
  199. $out .= '<option value="' . $obj->pcg_subtype . '">' . $label . '</option>';
  200. }
  201. $i ++;
  202. }
  203. }
  204. $out .= '</select>';
  205. } else {
  206. $this->error = "Error " . $this->db->lasterror();
  207. dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR);
  208. return - 1;
  209. }
  210. $this->db->free($resql);
  211. return $out;
  212. }
  213. }