html.formventilation.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. /* Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
  3. * Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  4. * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  5. * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  6. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/accountancy/class/html.formventilation.class.php
  23. * \ingroup Advanced accountancy
  24. * \brief File of class with all html predefined components
  25. */
  26. /**
  27. * Class to manage generation of HTML components for bank module
  28. */
  29. class FormVentilation extends Form
  30. {
  31. /**
  32. * Return select filter with date of transaction
  33. *
  34. * @param string $htmlname Name of select field
  35. * @param string $selectedkey Value
  36. * @return string HTML edit field
  37. */
  38. function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '') {
  39. $options = array();
  40. $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping';
  41. if (! empty($conf->multicompany->enabled)) {
  42. $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
  43. }
  44. $sql .= ' ORDER BY import_key DESC';
  45. dol_syslog(get_class($this) . "::select_bookkeeping_importkey", LOG_DEBUG);
  46. $resql = $this->db->query($sql);
  47. if (!$resql) {
  48. $this->error = "Error " . $this->db->lasterror();
  49. dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
  50. return - 1;
  51. }
  52. while ($obj = $this->db->fetch_object($resql)) {
  53. $options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext');
  54. }
  55. return Form::selectarray($htmlname, $options, $selectedkey);
  56. }
  57. /**
  58. * Return list of accounts with label by chart of accounts
  59. *
  60. * @param string $selectid Preselected chart of accounts
  61. * @param string $htmlname Name of field in html form
  62. * @param int $showempty Add an empty field
  63. * @param array $event Event options
  64. * @param int $select_in selectid value is a aa.rowid (0 default) or aa.account_number (1)
  65. * @param int $select_out set value returned by select 0=rowid (default), 1=account_number
  66. * @param string $morecss More css non HTML object
  67. * @return string String with HTML select
  68. */
  69. function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone') {
  70. global $conf;
  71. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  72. $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50;
  73. $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
  74. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
  75. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  76. $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
  77. $sql .= " AND aa.active = 1";
  78. $sql .= " ORDER BY aa.account_number";
  79. dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
  80. $resql = $this->db->query($sql);
  81. if (!$resql) {
  82. $this->error = "Error " . $this->db->lasterror();
  83. dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
  84. return -1;
  85. }
  86. $out = ajax_combobox($htmlname, $event);
  87. $options = array();
  88. $selected = null;
  89. while ($obj = $this->db->fetch_object($resql)) {
  90. $label = length_accountg($obj->account_number) . ' - ' . $obj->label;
  91. $label = dol_trunc($label, $trunclength);
  92. $select_value_in = $obj->rowid;
  93. $select_value_out = $obj->rowid;
  94. if ($select_in == 1) {
  95. $select_value_in = $obj->account_number;
  96. }
  97. if ($select_out == 1) {
  98. $select_value_out = $obj->account_number;
  99. }
  100. // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
  101. // Because same account_number can be share between different accounting_system and do have the same meaning
  102. if (($selectid != '') && $selectid == $select_value_in) {
  103. $selected = $select_value_out;
  104. }
  105. $options[$select_value_out] = $label;
  106. }
  107. $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
  108. $this->db->free($resql);
  109. return $out;
  110. }
  111. /**
  112. * Return list of accounts with label by class of accounts
  113. *
  114. * @param string $selectid Preselected pcg_type
  115. * @param string $htmlname Name of field in html form
  116. * @param int $showempty Add an empty field
  117. * @param array $event Event options
  118. *
  119. * @return string String with HTML select
  120. */
  121. function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) {
  122. global $conf;
  123. $sql = "SELECT DISTINCT pcg_type ";
  124. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
  125. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  126. $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
  127. $sql .= " ORDER BY pcg_type";
  128. dol_syslog(get_class($this) . "::select_pcgtype", LOG_DEBUG);
  129. $resql = $this->db->query($sql);
  130. if (!$resql) {
  131. $this->error = "Error ".$this->db->lasterror();
  132. dol_syslog(get_class($this)."::select_pcgtype ".$this->error, LOG_ERR);
  133. return -1;
  134. }
  135. $options = array();
  136. $out = ajax_combobox($htmlname, $event);
  137. while ($obj = $this->db->fetch_object($resql)) {
  138. $options[$obj->pcg_type] = $obj->pcg_type;
  139. }
  140. $out .= Form::selectarray($htmlname, $options, $selectid, $showempty);
  141. $this->db->free($resql);
  142. return $out;
  143. }
  144. /**
  145. * Return list of accounts with label by sub_class of accounts
  146. *
  147. * @param string $selectid Preselected pcg_type
  148. * @param string $htmlname Name of field in html form
  149. * @param int $showempty Add an empty field
  150. * @param array $event Event options
  151. *
  152. * @return string String with HTML select
  153. */
  154. function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) {
  155. global $conf;
  156. $sql = "SELECT DISTINCT pcg_subtype ";
  157. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
  158. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  159. $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
  160. $sql .= " ORDER BY pcg_subtype";
  161. dol_syslog(get_class($this) . "::select_pcgsubtype", LOG_DEBUG);
  162. $resql = $this->db->query($sql);
  163. if (!$resql) {
  164. $this->error = "Error ".$this->db->lasterror();
  165. dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
  166. return -1;
  167. }
  168. $options = array();
  169. $out = ajax_combobox($htmlname, $event);
  170. while ($obj = $this->db->fetch_object($resql)) {
  171. $options[$obj->pcg_subtype] = $obj->pcg_subtype;
  172. }
  173. $out .= Form::selectarray($htmlname, $options, $selectid, $showempty);
  174. $this->db->free($resql);
  175. return $out;
  176. }
  177. /**
  178. * Return list of auxilary thirdparty accounts
  179. *
  180. * @param string $selectid Preselected pcg_type
  181. * @param string $htmlname Name of field in html form
  182. * @param int $showempty Add an empty field
  183. * @param array $event Event options
  184. *
  185. * @return string String with HTML select
  186. */
  187. function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) {
  188. $aux_account = array();
  189. // Auxiliary customer account
  190. $sql = "SELECT DISTINCT code_compta, nom ";
  191. $sql .= " FROM ".MAIN_DB_PREFIX."societe";
  192. if (! empty($conf->multicompany->enabled)) {
  193. $sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
  194. }
  195. $sql .= " ORDER BY code_compta";
  196. dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
  197. $resql = $this->db->query($sql);
  198. if ($resql) {
  199. while ($obj = $this->db->fetch_object($resql)) {
  200. if (!empty($obj->code_compta)) {
  201. $aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')';
  202. }
  203. }
  204. } else {
  205. $this->error = "Error ".$this->db->lasterror();
  206. dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
  207. return -1;
  208. }
  209. $this->db->free($resql);
  210. // Auxiliary supplier account
  211. $sql = "SELECT DISTINCT code_compta_fournisseur, nom ";
  212. $sql .= " FROM ".MAIN_DB_PREFIX."societe";
  213. if (! empty($conf->multicompany->enabled)) {
  214. $sql .= " WHERE entity IN (" . getEntity("societe", 1) . ")";
  215. }
  216. $sql .= " ORDER BY code_compta_fournisseur";
  217. dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
  218. $resql = $this->db->query($sql);
  219. if ($resql) {
  220. while ($obj = $this->db->fetch_object($resql)) {
  221. if (!empty($obj->code_compta_fournisseur)) {
  222. $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')';
  223. }
  224. }
  225. } else {
  226. $this->error = "Error ".$this->db->lasterror();
  227. dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR);
  228. return -1;
  229. }
  230. $this->db->free($resql);
  231. // Build select
  232. $out = ajax_combobox($htmlname, $event);
  233. $out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
  234. return $out;
  235. }
  236. /**
  237. * Return HTML combo list of years existing into book keepping
  238. *
  239. * @param string $selected Preselected value
  240. * @param string $htmlname Name of HTML select object
  241. * @param int $useempty Affiche valeur vide dans liste
  242. * @param string $output_format (html/opton (for option html only)/array (to return options arrays
  243. * @return string/array
  244. */
  245. function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
  246. {
  247. global $conf;
  248. $out_array = array();
  249. $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
  250. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
  251. if (! empty($conf->multicompany->enabled)) {
  252. $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
  253. }
  254. $sql .= " ORDER BY date_format(doc_date,'%Y')";
  255. dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
  256. $resql = $this->db->query($sql);
  257. if (!$resql) {
  258. $this->error = "Error ".$this->db->lasterror();
  259. dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
  260. return -1;
  261. }
  262. while ($obj = $this->db->fetch_object($resql)) {
  263. $out_array[$obj->dtyear] = $obj->dtyear;
  264. }
  265. $this->db->free($resql);
  266. if ($output_format == 'html') {
  267. return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
  268. } else {
  269. return $out_array;
  270. }
  271. }
  272. /**
  273. * Return HTML combo list of years existing into book keepping
  274. *
  275. * @param string $selected Preselected value
  276. * @param string $htmlname Name of HTML select object
  277. * @param int $useempty Affiche valeur vide dans liste
  278. * @param string $output_format Html/option (for option html only)/array (to return options arrays
  279. * @return string/array
  280. */
  281. function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html')
  282. {
  283. global $conf,$langs;
  284. $out_array = array();
  285. $sql = "SELECT DISTINCT code_journal";
  286. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
  287. if (! empty($conf->multicompany->enabled)) {
  288. $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")";
  289. }
  290. $sql .= " ORDER BY code_journal";
  291. dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
  292. $resql = $this->db->query($sql);
  293. if (!$resql) {
  294. $this->error = "Error ".$this->db->lasterror();
  295. dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
  296. return -1;
  297. }
  298. while ($obj = $this->db->fetch_object($resql)) {
  299. $out_array[$obj->code_journal] = $obj->code_journal?$obj->code_journal:$langs->trans("NotDefined"); // TODO Not defined is accepted ? We should avoid this, shouldn't we ?
  300. }
  301. $this->db->free($resql);
  302. if ($output_format == 'html') {
  303. return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"');
  304. } else {
  305. return $out_array;
  306. }
  307. }
  308. }