diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php
index 498c513b761..e5edeaa0852 100644
--- a/htdocs/accountancy/bookkeeping/list.php
+++ b/htdocs/accountancy/bookkeeping/list.php
@@ -750,10 +750,10 @@ if (!empty($arrayfields['t.doc_ref']['checked'])) {
if (!empty($arrayfields['t.numero_compte']['checked'])) {
print '
';
print ' ';
- 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 ' ';
print '';
- 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 ' ';
print ' | ';
}
@@ -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 '';
}
@@ -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 '';
}
diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php
index afbda03be8e..a57e39f1779 100644
--- a/htdocs/core/class/html.formaccounting.class.php
+++ b/htdocs/core/class/html.formaccounting.class.php
@@ -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.' ('.$obj->name.')';
- }
- if (!empty($obj->code_compta_fournisseur)) {
- $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->name.')';
- }
- }
+ 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.' ('.dolGetFirstLastname($obj->firstname, $obj->lastname).')';
+ $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->name.')';
+ }
+ if (!empty($obj->code_compta_fournisseur)) {
+ $aux_account[$obj->code_compta_fournisseur] = $obj->code_compta_fournisseur.' ('.$obj->name.')';
+ }
}
+ } 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.' ('.dolGetFirstLastname($obj->firstname, $obj->lastname).')';
+ }
+ }
+ } 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;
}