From 3722fc1014245c2e5622d909fbd5bd1a44228a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sat, 16 Apr 2016 20:16:38 +0200 Subject: [PATCH] Refactored FormVentilation class --- .../class/html.formventilation.class.php | 344 +++++++----------- 1 file changed, 122 insertions(+), 222 deletions(-) diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index b0b58a7a921..e17e4406376 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2013-2014 Olivier Geffroy * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2015 Ari Elbaz (elarifr) + * Copyright (C) 2016 Marcos GarcĂ­a * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,18 +30,6 @@ */ class FormVentilation extends Form { - var $db; - var $error; - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) { - $this->db = $db; - } - /** * Return select filter with date of transaction * @@ -49,38 +38,25 @@ class FormVentilation extends Form * @return string HTML edit field */ function select_bookkeeping_importkey($htmlname = 'importkey', $selectedkey = '') { + $options = array(); + $sql = 'SELECT DISTINCT import_key from ' . MAIN_DB_PREFIX . 'accounting_bookkeeping'; $sql .= ' ORDER BY import_key DESC'; - - $out = ''; - - return $out; + + while ($obj = $this->db->fetch_object($resql)) { + $options[$obj->import_key] = dol_print_date($obj->import_key, 'dayhourtext'); + } + + return Form::selectarray($htmlname, $options, $selectedkey); } /** @@ -100,8 +76,8 @@ class FormVentilation extends Form global $conf; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; - - $out = ''; + + $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50; $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; @@ -110,49 +86,44 @@ class FormVentilation extends Form $sql .= " AND aa.active = 1"; $sql .= " ORDER BY aa.account_number"; - dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { - - $out .= ajax_combobox($htmlname, $event); - $out .= ''; - } else { + + if (!$resql) { $this->error = "Error " . $this->db->lasterror(); dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); - return - 1; + return -1; } + + $out = ajax_combobox($htmlname, $event); + + $options = array(); + $selected = null; + + while ($obj = $this->db->fetch_object($resql)) { + $label = length_accountg($obj->account_number) . ' - ' . $obj->label; + $label = dol_trunc($label, $trunclength); + + $select_value_in = $obj->rowid; + $select_value_out = $obj->rowid; + + if ($select_in == 1) { + $select_value_in = $obj->account_number; + } + if ($select_out == 1) { + $select_value_out = $obj->account_number; + } + + // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number + // Because same account_number can be share between different accounting_system and do have the same meaning + if (($selectid != '') && $selectid == $select_value_in) { + $selected = $select_value_out; + } + + $options[$select_value_out] = $label; + } + + $out .= Form::selectarray($htmlname, $options, $selected, $showempty); $this->db->free($resql); return $out; } @@ -170,44 +141,30 @@ class FormVentilation extends Form function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) { global $conf; - $out = ''; - $sql = "SELECT DISTINCT pcg_type "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_type"; - dol_syslog(get_class($this) . "::select_pcgtype sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::select_pcgtype", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { - - $out .= ajax_combobox($htmlname, $event); - - $out .= ''; - } else { - $this->error = "Error " . $this->db->lasterror(); - dol_syslog(get_class($this) . "::select_pcgtype " . $this->error, LOG_ERR); - return - 1; + + if (!$resql) { + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::select_pcgtype ".$this->error, LOG_ERR); + return -1; } + + $options = array(); + $out = ajax_combobox($htmlname, $event); + + while ($obj = $this->db->fetch_object($resql)) { + $options[$obj->pcg_type] = $obj->pcg_type; + } + + $out .= Form::selectarray($htmlname, $options, $selectid, $showempty); + $this->db->free($resql); return $out; } @@ -225,44 +182,30 @@ class FormVentilation extends Form function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) { global $conf; - $out = ''; - $sql = "SELECT DISTINCT pcg_subtype "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_subtype"; - dol_syslog(get_class($this) . "::select_pcgsubtype sql=" . $sql, LOG_DEBUG); + dol_syslog(get_class($this) . "::select_pcgsubtype", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) { - - $out .= ajax_combobox($htmlname, $event); - - $out .= ''; - } else { - $this->error = "Error " . $this->db->lasterror(); - dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); - return - 1; + + if (!$resql) { + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); + return -1; } + + $options = array(); + $out = ajax_combobox($htmlname, $event); + + while ($obj = $this->db->fetch_object($resql)) { + $options[$obj->pcg_subtype] = $obj->pcg_subtype; + } + + $out .= Form::selectarray($htmlname, $options, $selectid, $showempty); + $this->db->free($resql); return $out; } @@ -278,68 +221,51 @@ class FormVentilation extends Form * @return string String with HTML select */ function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) { - global $conf; - - $out = ''; - - $aux_account = array (); - + + $aux_account = array(); + // Auxiliary customer account $sql = "SELECT DISTINCT code_compta, nom "; - $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe"; $sql .= " ORDER BY code_compta"; - dol_syslog(get_class($this) . "::select_auxaccount", LOG_DEBUG); + dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - while ( $obj = $this->db->fetch_object($resql) ) { - if (! empty($obj->code_compta)) { - $aux_account[$obj->code_compta] = $obj->code_compta . ' (' . $obj->nom . ')'; + while ($obj = $this->db->fetch_object($resql)) { + if (!empty($obj->code_compta)) { + $aux_account[$obj->code_compta] = $obj->code_compta.' ('.$obj->nom.')'; } } } else { - $this->error = "Error " . $this->db->lasterror(); - dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); - return - 1; + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); + return -1; } $this->db->free($resql); - + // Auxiliary supplier account $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; - $sql .= " FROM " . MAIN_DB_PREFIX . "societe"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe"; $sql .= " ORDER BY code_compta"; - dol_syslog(get_class($this) . "::select_auxaccount", LOG_DEBUG); + dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - while ( $obj = $this->db->fetch_object($resql) ) { - if (! empty($obj->code_compta_fournisseur)) { - $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur . ' (' . $obj->nom . ')'; + while ($obj = $this->db->fetch_object($resql)) { + if (!empty($obj->code_compta_fournisseur)) { + $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->nom.')'; } } } else { - $this->error = "Error " . $this->db->lasterror(); - dol_syslog(get_class($this) . "::select_pcgsubtype " . $this->error, LOG_ERR); - return - 1; + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::select_pcgsubtype ".$this->error, LOG_ERR); + return -1; } $this->db->free($resql); - + // Build select - if (count($aux_account) > 0) { - - $out .= ajax_combobox($htmlname, $event); - - $out .= ''; - } - + $out = ajax_combobox($htmlname, $event); + $out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty); + return $out; } @@ -352,55 +278,29 @@ class FormVentilation extends Form * @param string $output_format (html/opton (for option html only)/array (to return options arrays * @return string/array */ - function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html') { - $out = ''; - $out_array = array (); - - if ($output_format == 'html') { - $out .= '\n"; - } - - if ($output_format == 'html' || $output_format == 'options') { - return $out; - } elseif ($output_format == 'array') { + return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"'); + } else { return $out_array; } }