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 1/2] 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; } } From 863efcbc5d4b96d1212ca3babee9f379d15ad1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sat, 16 Apr 2016 21:33:23 +0200 Subject: [PATCH 2/2] NEW Removed unused FormOrder::selectSourcesCommande function Also refactored select functions to avoid using HTML and encourage using Form::selectarray function --- htdocs/core/class/dolreceiptprinter.class.php | 44 +++---- htdocs/core/class/html.formcompany.class.php | 33 +++--- htdocs/core/class/html.formmailing.class.php | 34 +----- htdocs/core/class/html.formorder.class.php | 111 ++++++------------ htdocs/margin/admin/margin.php | 21 ++-- htdocs/product/document.php | 36 +----- .../canvas/actions_card_common.class.php | 12 +- 7 files changed, 91 insertions(+), 200 deletions(-) diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 90bf948e215..2499176b58b 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -300,17 +300,17 @@ class dolReceiptPrinter extends Escpos function selectTypePrinter($selected='', $htmlname='printertypeid') { global $langs; - $error = 0; - $html = ''; - - $this->resprint = $html; - return $error; + + $options = array( + 1 => $langs->trans('CONNECTOR_DUMMY'), + 2 => $langs->trans('CONNECTOR_FILE_PRINT'), + 3 => $langs->trans('CONNECTOR_NETWORK_PRINT'), + 4 => $langs->trans('CONNECTOR_WINDOWS_PRINT') + ); + + $this->resprint = Form::selectarray($htmlname, $options, $selected); + + return 0; } @@ -324,17 +324,17 @@ class dolReceiptPrinter extends Escpos function selectProfilePrinter($selected='', $htmlname='printerprofileid') { global $langs; - $error = 0; - $html = ''; - - $this->profileresprint = $html; - return $error; + + $options = array( + 0 => $langs->trans('PROFILE_DEFAULT'), + 1 => $langs->trans('PROFILE_SIMPLE'), + 2 => $langs->trans('PROFILE_EPOSTEP'), + 3 => $langs->trans('PROFILE_P822D'), + 4 => $langs->trans('PROFILE_STAR') + ); + + $this->profileresprint = Form::selectarray($htmlname, $options, $selected); + return 0; } diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 9091b4aead0..d51765e2a16 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -146,9 +146,6 @@ class FormCompany print ''; print ''; print ''; diff --git a/htdocs/core/class/html.formmailing.class.php b/htdocs/core/class/html.formmailing.class.php index 3c47aceee8a..0c63049f9d8 100644 --- a/htdocs/core/class/html.formmailing.class.php +++ b/htdocs/core/class/html.formmailing.class.php @@ -27,22 +27,8 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php'; */ class FormMailing extends Form { - public $db; - public $error; public $errors=array(); - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - return 1; - } - /** * Output a select with destinaries status * @@ -59,26 +45,14 @@ class FormMailing extends Form require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php'; $mailing = new Mailing($this->db); - - $array = $mailing->statut_dest; - //Cannot use form->selectarray because empty value is defaulted to -1 in this method and we use here status -1... - - $out = ''; - return $out; + return Form::selectarray($htmlname, $options, $selectedid, 0, 0, 0, '', 1); } } diff --git a/htdocs/core/class/html.formorder.class.php b/htdocs/core/class/html.formorder.class.php index 4ecbef60b58..68fa96e03ee 100644 --- a/htdocs/core/class/html.formorder.class.php +++ b/htdocs/core/class/html.formorder.class.php @@ -1,5 +1,6 @@ + * 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 @@ -21,29 +22,14 @@ * \brief File of predefined functions for HTML forms for order module */ +require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php'; /** * Class to manage HTML output components for orders * Before adding component here, check they are not into common part Form.class.php */ -class FormOrder +class FormOrder extends Form { - var $db; - var $error; - - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - return 1; - } - /** * Return combo list of differents status of a orders @@ -53,51 +39,32 @@ class FormOrder * @param string $hmlname Name of HTML select element * @return void */ - function selectSupplierOrderStatus($selected='', $short=0, $hmlname='order_status') + public function selectSupplierOrderStatus($selected='', $short=0, $hmlname='order_status') { - $tmpsupplierorder=new CommandeFournisseur($db); - - print ''; + // 7 is same label than 6. 8 does not exists (billed is another field) + $statustohow = array( + '0' => '0', + '1' => '1', + '2' => '2', + '3' => '3', + '4' => '4', + '5' => '5', + '6' => '6,7', + '9' => '9' + ); + + $tmpsupplierorder = new CommandeFournisseur($this->db); + + foreach ($statustohow as $key => $value) { + $tmpsupplierorder->statut = $key; + $options[$value] = $tmpsupplierorder->getLibStatut($short); + } + + print Form::selectarray($hmlname, $options, $selected, 1); } - /** - * Return list of way to order - * - * @param string $selected Id of preselected order origin - * @param string $htmlname Name of HTML select list - * @param int $addempty 0=liste sans valeur nulle, 1=ajoute valeur inconnue - * @return array Tableau des sources de commandes - */ - function selectSourcesCommande($selected='',$htmlname='source_id',$addempty=0) - { - global $conf,$langs; - print ''; - } - - /** * Return list of input method (mode used to receive order, like order received by email, fax, online) * List found into table c_input_method. @@ -107,11 +74,9 @@ class FormOrder * @param int $addempty 0=list with no empty value, 1=list with empty value * @return array Tableau des sources de commandes */ - function selectInputMethod($selected='',$htmlname='source_id',$addempty=0) + public function selectInputMethod($selected='',$htmlname='source_id',$addempty=0) { - global $conf,$langs,$form; - - if (! is_object($form)) $form=new Form($this->db); + global $langs; $listofmethods=array(); @@ -121,24 +86,18 @@ class FormOrder dol_syslog(get_class($this)."::selectInputMethod", LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) - { - $i = 0; - $num = $this->db->num_rows($resql); - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $listofmethods[$obj->rowid] = $langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):$obj->label; - $i++; - } - } - else - { + + if (!$resql) { dol_print_error($this->db); return -1; } - print $form->selectarray($htmlname,$listofmethods,$selected,$addempty); + while ($obj = $this->db->fetch_object($resql)) { + $listofmethods[$obj->rowid] = $langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : $obj->label; + } + + print Form::selectarray($htmlname,$listofmethods,$selected,$addempty); + return 1; } diff --git a/htdocs/margin/admin/margin.php b/htdocs/margin/admin/margin.php index 6e84b13e286..3a61ee0e72e 100644 --- a/htdocs/margin/admin/margin.php +++ b/htdocs/margin/admin/margin.php @@ -236,6 +236,12 @@ print ''; print ''; // GLOBAL DISCOUNT MANAGEMENT +$methods = array( + 1 => $langs->trans('UseDiscountAsProduct'), + 2 => $langs->trans('UseDiscountAsService'), + 3 => $langs->trans('UseDiscountOnTotal') +); + $var=!$var; print ''; print ''; @@ -243,20 +249,7 @@ print ""; print ''; print ''; print ''; print '
'; - print ''; print ''.$langs->trans('ForceBuyingPriceIfNullDetails').'
'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").''; -print ''; +print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, $conf->global->MARGIN_METHODE_FOR_DISCOUNT); print ''; print ''; diff --git a/htdocs/product/document.php b/htdocs/product/document.php index facff9f9a52..ca207f8429f 100644 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -262,43 +262,11 @@ if ($object->id) print '
'; - $delauft_lang = (empty($lang_id)) ? $langs->getDefaultLang() : $lang_id; + $delauft_lang = empty($lang_id) ? $langs->getDefaultLang() : $lang_id; $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12); - print ''; + print Form::selectarray('lang_id', $langs_available, $delauft_lang, 0, 0, 0, '', 0, 0, 0, 'ASC'); if ($conf->global->MAIN_MULTILANGS) { print ''; diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 782a7f070c4..74a05cba39d 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -439,12 +439,12 @@ abstract class ActionsCardCommon if ($modCodeClient->code_auto) $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed(); // TODO create a function - $this->tpl['select_customertype'] = ''; + $this->tpl['select_customertype'] = Form::selectarray('client', array( + 0 => $langs->trans('NorProspectNorCustomer'), + 1 => $langs->trans('Customer'), + 2 => $langs->trans('Prospect'), + 3 => $langs->trans('ProspectCustomer') + ), $this->object->client); // Customer $this->tpl['customercode'] = $this->object->code_client;