Minor perf enhancement

This commit is contained in:
Laurent Destailleur 2021-05-03 12:32:31 +02:00
parent 18cbe4c93b
commit 39e27b6f38
2 changed files with 65 additions and 56 deletions

View File

@ -750,10 +750,10 @@ if (!empty($arrayfields['t.doc_ref']['checked'])) {
if (!empty($arrayfields['t.numero_compte']['checked'])) { if (!empty($arrayfields['t.numero_compte']['checked'])) {
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<div class="nowrap">'; 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>';
print '<div class="nowrap">'; 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 '</div>';
print '</td>'; 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 // 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. // use setup of keypress to select thirdparty and this hang browser on large database.
if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
print $langs->trans('From').' '; //print $langs->trans('From').' ';
print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', $langs->trans('From'), 'maxwidth250', 'subledgeraccount');
} else { } else {
print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_start" value="'.$search_accountancy_aux_code_start.'" placeholder="'.$langs->trans("From").'">'; 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 // 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. // use setup of keypress to select thirdparty and this hang browser on large database.
if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) { if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
print $langs->trans('to').' '; //print $langs->trans('to').' ';
print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', $langs->trans('to'), 'maxwidth250', 'subledgeraccount');
} else { } else {
print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_end" value="'.$search_accountancy_aux_code_end.'" placeholder="'.$langs->trans("to").'">'; print '<input type="text" class="maxwidth100" name="search_accountancy_aux_code_end" value="'.$search_accountancy_aux_code_end.'" placeholder="'.$langs->trans("to").'">';
} }

View File

@ -32,7 +32,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
*/ */
class FormAccounting extends Form class FormAccounting extends Form
{ {
private $options_cache = array(); private $options_cache = array();
/** /**
@ -87,7 +86,7 @@ class FormAccounting extends Form
$sql .= " WHERE active = 1"; $sql .= " WHERE active = 1";
$sql .= " AND entity = ".$conf->entity; $sql .= " AND entity = ".$conf->entity;
if ($nature && is_numeric($nature)) { if ($nature && is_numeric($nature)) {
$sql .= " AND nature = ".$nature; $sql .= " AND nature = ".((int) $nature);
} }
$sql .= " ORDER BY code"; $sql .= " ORDER BY code";
@ -167,7 +166,7 @@ class FormAccounting extends Form
$sql .= " WHERE active = 1"; $sql .= " WHERE active = 1";
$sql .= " AND entity = ".$conf->entity; $sql .= " AND entity = ".$conf->entity;
if ($nature && is_numeric($nature)) { if ($nature && is_numeric($nature)) {
$sql .= " AND nature = ".$nature; $sql .= " AND nature = ".((int) $nature);
} }
$sql .= " ORDER BY code"; $sql .= " ORDER BY code";
@ -437,23 +436,28 @@ class FormAccounting extends Form
* *
* @param string $selectid Preselected pcg_type * @param string $selectid Preselected pcg_type
* @param string $htmlname Name of field in html form * @param string $htmlname Name of field in html form
* @param int $showempty Add an empty field * @param int|string $showempty Add an empty field
* @param string $morecss More css * @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 * @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 // phpcs:enable
$aux_account = array(); $aux_account = array();
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 {
dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
// Auxiliary thirdparties account // Auxiliary thirdparties account
$sql = "SELECT code_compta, code_compta_fournisseur, nom as name"; $sql = "SELECT code_compta, code_compta_fournisseur, nom as name";
$sql .= " FROM ".MAIN_DB_PREFIX."societe"; $sql .= " FROM ".MAIN_DB_PREFIX."societe";
$sql .= " WHERE entity IN (".getEntity('societe').")"; $sql .= " WHERE entity IN (".getEntity('societe').")";
$sql .= " AND client IN (1,3) OR fournisseur = 1"; $sql .= " AND client IN (1,3) OR fournisseur = 1";
dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
while ($obj = $this->db->fetch_object($resql)) { while ($obj = $this->db->fetch_object($resql)) {
@ -479,7 +483,7 @@ class FormAccounting extends Form
$sql .= " FROM ".MAIN_DB_PREFIX."user"; $sql .= " FROM ".MAIN_DB_PREFIX."user";
$sql .= " WHERE entity IN (".getEntity('user').")"; $sql .= " WHERE entity IN (".getEntity('user').")";
$sql .= " ORDER BY accountancy_code"; $sql .= " ORDER BY accountancy_code";
dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
while ($obj = $this->db->fetch_object($resql)) { while ($obj = $this->db->fetch_object($resql)) {
@ -494,8 +498,13 @@ class FormAccounting extends Form
} }
$this->db->free($resql); $this->db->free($resql);
if ($usecache) {
$this->options_cache[$usecache] = $aux_account;
}
}
// Build select // 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; return $out;
} }