Minor perf enhancement
This commit is contained in:
parent
18cbe4c93b
commit
39e27b6f38
@ -750,10 +750,10 @@ if (!empty($arrayfields['t.doc_ref']['checked'])) {
|
||||
if (!empty($arrayfields['t.numero_compte']['checked'])) {
|
||||
print '<td class="liste_titre">';
|
||||
print '<div class="nowrap">';
|
||||
print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200', 1);
|
||||
print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', $langs->trans('From'), array(), 1, 1, 'maxwidth200', 'account');
|
||||
print '</div>';
|
||||
print '<div class="nowrap">';
|
||||
print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200', 1);
|
||||
print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', $langs->trans('to'), array(), 1, 1, 'maxwidth200', 'account');
|
||||
print '</div>';
|
||||
print '</td>';
|
||||
}
|
||||
@ -764,8 +764,8 @@ if (!empty($arrayfields['t.subledger_account']['checked'])) {
|
||||
// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
|
||||
// use setup of keypress to select thirdparty and this hang browser on large database.
|
||||
if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
|
||||
print $langs->trans('From').' ';
|
||||
print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1);
|
||||
//print $langs->trans('From').' ';
|
||||
print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', $langs->trans('From'), 'maxwidth250', 'subledgeraccount');
|
||||
} else {
|
||||
print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_start" value="'.$search_accountancy_aux_code_start.'" placeholder="'.$langs->trans("From").'">';
|
||||
}
|
||||
@ -774,8 +774,8 @@ if (!empty($arrayfields['t.subledger_account']['checked'])) {
|
||||
// TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because it does not
|
||||
// use setup of keypress to select thirdparty and this hang browser on large database.
|
||||
if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
|
||||
print $langs->trans('to').' ';
|
||||
print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1);
|
||||
//print $langs->trans('to').' ';
|
||||
print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', $langs->trans('to'), 'maxwidth250', 'subledgeraccount');
|
||||
} else {
|
||||
print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_end" value="'.$search_accountancy_aux_code_end.'" placeholder="'.$langs->trans("to").'">';
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
|
||||
*/
|
||||
class FormAccounting extends Form
|
||||
{
|
||||
|
||||
private $options_cache = array();
|
||||
|
||||
/**
|
||||
@ -87,7 +86,7 @@ class FormAccounting extends Form
|
||||
$sql .= " WHERE active = 1";
|
||||
$sql .= " AND entity = ".$conf->entity;
|
||||
if ($nature && is_numeric($nature)) {
|
||||
$sql .= " AND nature = ".$nature;
|
||||
$sql .= " AND nature = ".((int) $nature);
|
||||
}
|
||||
$sql .= " ORDER BY code";
|
||||
|
||||
@ -167,7 +166,7 @@ class FormAccounting extends Form
|
||||
$sql .= " WHERE active = 1";
|
||||
$sql .= " AND entity = ".$conf->entity;
|
||||
if ($nature && is_numeric($nature)) {
|
||||
$sql .= " AND nature = ".$nature;
|
||||
$sql .= " AND nature = ".((int) $nature);
|
||||
}
|
||||
$sql .= " ORDER BY code";
|
||||
|
||||
@ -435,67 +434,77 @@ class FormAccounting extends Form
|
||||
/**
|
||||
* Return list of auxilary accounts. Cumulate list from customers, suppliers and users.
|
||||
*
|
||||
* @param string $selectid Preselected pcg_type
|
||||
* @param string $htmlname Name of field in html form
|
||||
* @param int $showempty Add an empty field
|
||||
* @param string $morecss More css
|
||||
* @return string String with HTML select
|
||||
* @param string $selectid Preselected pcg_type
|
||||
* @param string $htmlname Name of field in html form
|
||||
* @param int|string $showempty Add an empty field
|
||||
* @param string $morecss More css
|
||||
* @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache.
|
||||
* @return string String with HTML select
|
||||
*/
|
||||
public function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $morecss = 'maxwidth250')
|
||||
public function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $morecss = 'maxwidth250', $usecache = '')
|
||||
{
|
||||
// phpcs:enable
|
||||
|
||||
$aux_account = array();
|
||||
|
||||
// Auxiliary thirdparties account
|
||||
$sql = "SELECT code_compta, code_compta_fournisseur, nom as name";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe";
|
||||
$sql .= " WHERE entity IN (".getEntity('societe').")";
|
||||
$sql .= " AND client IN (1,3) OR fournisseur = 1";
|
||||
|
||||
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.' <span class="opacitymedium">('.$obj->name.')</span>';
|
||||
}
|
||||
if (!empty($obj->code_compta_fournisseur)) {
|
||||
$aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' <span class="opacitymedium">('.$obj->name.')</span>';
|
||||
}
|
||||
}
|
||||
if ($usecache && !empty($this->options_cache[$usecache])) {
|
||||
$aux_account = $aux_account + $this->options_cache[$usecache]; // We use + instead of array_merge because we don't want to reindex key from 0
|
||||
} else {
|
||||
$this->error = "Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::select_auxaccount ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
|
||||
|
||||
ksort($aux_account);
|
||||
// Auxiliary thirdparties account
|
||||
$sql = "SELECT code_compta, code_compta_fournisseur, nom as name";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe";
|
||||
$sql .= " WHERE entity IN (".getEntity('societe').")";
|
||||
$sql .= " AND client IN (1,3) OR fournisseur = 1";
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
// Auxiliary user account
|
||||
$sql = "SELECT DISTINCT accountancy_code, lastname, firstname ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " WHERE entity IN (".getEntity('user').")";
|
||||
$sql .= " ORDER BY accountancy_code";
|
||||
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->accountancy_code)) {
|
||||
$aux_account[$obj->accountancy_code] = $obj->accountancy_code.' <span class="opacitymedium">('.dolGetFirstLastname($obj->firstname, $obj->lastname).')</span>';
|
||||
$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.' <span class="opacitymedium">('.$obj->name.')</span>';
|
||||
}
|
||||
if (!empty($obj->code_compta_fournisseur)) {
|
||||
$aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' <span class="opacitymedium">('.$obj->name.')</span>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->error = "Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::select_auxaccount ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ksort($aux_account);
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
// Auxiliary user account
|
||||
$sql = "SELECT DISTINCT accountancy_code, lastname, firstname ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user";
|
||||
$sql .= " WHERE entity IN (".getEntity('user').")";
|
||||
$sql .= " ORDER BY accountancy_code";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
if (!empty($obj->accountancy_code)) {
|
||||
$aux_account[$obj->accountancy_code] = $obj->accountancy_code.' <span class="opacitymedium">('.dolGetFirstLastname($obj->firstname, $obj->lastname).')</span>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->error = "Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::select_auxaccount ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
if ($usecache) {
|
||||
$this->options_cache[$usecache] = $aux_account;
|
||||
}
|
||||
} else {
|
||||
$this->error = "Error ".$this->db->lasterror();
|
||||
dol_syslog(get_class($this)."::select_auxaccount ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
// Build select
|
||||
$out .= Form::selectarray($htmlname, $aux_account, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
|
||||
$out .= Form::selectarray($htmlname, $aux_account, $selectid, ($showempty ? (is_numeric($showempty) ? 1 : $showempty): 0), 0, 0, '', 0, 0, 0, '', $morecss, 1);
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user