Skip to content
Snippets Groups Projects
Commit 3722fc10 authored by Marcos García de La Fuente's avatar Marcos García de La Fuente
Browse files

Refactored FormVentilation class

parent 7163ee55
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
*
* 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 = '<SELECT name="' . $htmlname . '">';
dol_syslog(get_class($this) . "::select_bookkeeping_importkey sql=" . $sql, LOG_DEBUG);
dol_syslog(get_class($this) . "::select_bookkeeping_importkey", 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);
$selected = '';
if ($selectedkey == $obj->import_key) {
$selected = ' selected ';
}
$out .= '<OPTION value="' . $obj->import_key . '"' . $selected . '>' . dol_print_date($obj->import_key, 'dayhourtext') . '</OPTION>';
$i ++;
}
} else {
if (!$resql) {
$this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . "::select_bookkeeping_importkey " . $this->error, LOG_ERR);
return - 1;
}
$out .= '</SELECT>';
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 .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
if ($showempty)
$out .= '<option value="-1"></option>';
$num = $this->db->num_rows($resql);
$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : '50';
$i = 0;
if ($num) {
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
$label = length_accountg($obj->account_number) . ' - ' . $obj->label;
$label = dol_trunc($label, $trunclength);
if ($select_in == 0)
$select_value_in = $obj->rowid;
if ($select_in == 1)
$select_value_in = $obj->account_number;
if ($select_out == 0)
$select_value_out = $obj->rowid;
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) {
// $out .= '<option value="' . $obj->account_number . '" selected>' . $label . '</option>';
$out .= '<option value="' . $select_value_out . '" selected>' . $label . '</option>';
} else {
// $out .= '<option value="' . $obj->account_number . '">' . $label . '</option>';
$out .= '<option value="' . $select_value_out . '">' . $label . '</option>';
}
$i ++;
}
}
$out .= '</select>';
} 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 .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
if ($showempty)
$out .= '<option value="-1"></option>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num) {
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
$label = $obj->pcg_type;
if (($selectid != '') && $selectid == $obj->pcg_type) {
$out .= '<option value="' . $obj->pcg_type . '" selected>' . $label . '</option>';
} else {
$out .= '<option value="' . $obj->pcg_type . '">' . $label . '</option>';
}
$i ++;
}
}
$out .= '</select>';
} 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 .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
if ($showempty)
$out .= '<option value="-1"></option>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num) {
while ( $i < $num ) {
$obj = $this->db->fetch_object($resql);
$label = $obj->pcg_subtype;
if (($selectid != '') && $selectid == $obj->pcg_subtype) {
$out .= '<option value="' . $obj->pcg_subtype . '" selected>' . $label . '</option>';
} else {
$out .= '<option value="' . $obj->pcg_subtype . '">' . $label . '</option>';
}
$i ++;
}
}
$out .= '</select>';
} 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 .= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
if ($showempty)
$out .= '<option value="-1"></option>';
foreach ( $aux_account as $key => $val ) {
if (($selectid != '') && $selectid == $key) {
$out .= '<option value="' . $key . '" selected>' . $val . '</option>';
} else {
$out .= '<option value="' . $key . '">' . $val . '</option>';
}
}
$out .= '</select>';
}
$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 .= '<select class="flat" placeholder="aa" id="' . $htmlname . '" name="' . $htmlname . '"' . $option . ' >';
}
if ($useempty) {
$selected_html = '';
if ($selected == '') {
$selected_html = ' selected';
}
if ($output_format == 'html' || $output_format == 'options') {
$out .= '<option value=""' . $selected_html . '>&nbsp;</option>';
} elseif ($output_format == 'array') {
$out_array[''] = '';
}
}
function selectyear_accountancy_bookkepping($selected = '', $htmlname = 'yearid', $useempty = 0, $output_format = 'html')
{
$out_array = array();
$sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear";
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping";
$sql .= " ORDER BY doc_date";
dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG);
dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
while ( $obj = $this->db->fetch_object($resql) ) {
$selected_html = '';
if ($selected > 0 && $obj->dtyear == $selected)
$selected_html = ' selected';
if ($output_format == 'html' || $output_format == 'options') {
$out .= '<option value="' . $obj->dtyear . '"' . $selected_html . ' >' . $obj->dtyear . '</option>';
} elseif ($output_format == 'array') {
$out_array[$obj->dtyear] = $obj->dtyear;
}
}
} else {
$this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR);
return - 1;
if (!$resql) {
$this->error = "Error ".$this->db->lasterror();
dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR);
return -1;
}
while ($obj = $this->db->fetch_object($resql)) {
$out_array[$obj->dtyear] = $obj->dtyear;
}
$this->db->free($resql);
if ($output_format == 'html') {
$out .= "</select>\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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment