diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index 516af988334..92c2df3ba0e 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -48,6 +48,7 @@ $action = GETPOST('action', 'aZ09'); $list = array( 'ACCOUNTING_LENGTH_GACCOUNT', 'ACCOUNTING_LENGTH_AACCOUNT', + 'ACCOUNTING_LIMIT_LIST_VENTILATION' // 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc // 'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', // adjust size displayed for select account description for dol_trunc ); @@ -248,7 +249,7 @@ if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL)) { print ''; */ -print ''; +/*print ''; print ''.$langs->trans("BANK_DISABLE_DIRECT_INPUT").''; if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) { print ''; @@ -259,7 +260,7 @@ if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) { print img_picto($langs->trans("Disabled"), 'switch_off'); print ''; } -print ''; +print '';*/ print ''; print ''.$langs->trans("ACCOUNTANCY_COMBO_FOR_AUX").''; @@ -313,6 +314,21 @@ print ''; print ''.$langs->trans('BindingOptions').''; print "\n"; + +// TO DO Mutualize code for yes/no constants +print ''; +print ''.$langs->trans("").''; +if (!empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) { + print ''; + print img_picto($langs->trans("Activated"), 'switch_on'); + print ''; +} else { + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; +} +print ''; + // TO DO Mutualize code for yes/no constants print ''; print ''.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO").''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 6d663edcf4e..7219136c2da 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -85,7 +85,7 @@ $search_mvt_label = GETPOST('search_mvt_label', 'alpha'); $search_direction = GETPOST('search_direction', 'alpha'); $search_debit = GETPOST('search_debit', 'alpha'); $search_credit = GETPOST('search_credit', 'alpha'); -$search_ledger_code = GETPOST('search_ledger_code', 'alpha'); +$search_ledger_code = GETPOST('search_ledger_code', 'array'); $search_lettering_code = GETPOST('search_lettering_code', 'alpha'); $search_not_reconciled = GETPOST('search_reconciled_option', 'alpha'); @@ -192,7 +192,7 @@ if (empty($reshook)) $search_accountancy_aux_code_end = ''; $search_mvt_label = ''; $search_direction = ''; - $search_ledger_code = ''; + $search_ledger_code = array(); $search_date_start = ''; $search_date_end = ''; $search_date_creation_start = ''; @@ -267,7 +267,9 @@ if (empty($reshook)) } if (!empty($search_ledger_code)) { $filter['t.code_journal'] = $search_ledger_code; - $param .= '&search_ledger_code='.urlencode($search_ledger_code); + foreach ($search_ledger_code as $code) { + $param .= '&search_ledger_code[]='.urlencode($code); + } } if (!empty($search_mvt_num)) { $filter['t.piece_num'] = $search_mvt_num; @@ -447,6 +449,8 @@ if (count($filter) > 0) { $sqlwhere[] = natural_search($key, $value, 1, 1); } elseif ($key == 't.reconciled_option') { $sqlwhere[] = 't.lettering_code IS NULL'; + } elseif ($key == 't.code_journal' && !empty($value)) { + $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1); } else { $sqlwhere[] = natural_search($key, $value, 0, 1); } @@ -756,7 +760,9 @@ if (!empty($arrayfields['t.lettering_code']['checked'])) // Code journal if (!empty($arrayfields['t.code_journal']['checked'])) { - print ''; + print ''; + print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1); + print ''; } // Fields from hook diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index d6f7b269da1..373501a7adf 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -59,7 +59,7 @@ class FormAccounting extends Form /** * Return list of journals with label by nature * - * @param string $selectid Preselected pcg_type + * @param string $selectid Preselected journal code * @param string $htmlname Name of field in html form * @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new) * @param int $showempty Add an empty field @@ -136,6 +136,86 @@ class FormAccounting extends Form return $out; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return list of journals with label by nature + * + * @param array $selectids Preselected journal code + * @param string $htmlname Name of field in html form + * @param int $nature Limit the list to a particular type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new) + * @param int $showempty Add an empty field + * @param int $select_in 0=selectid value is the journal rowid (default) or 1=selectid is journal code + * @param int $select_out Set value returned by select. 0=rowid (default), 1=code + * @param string $morecss More css non HTML object + * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache. + * @param int $disabledajaxcombo Disable ajax combo box. + * @return string String with HTML select + */ + public function multi_select_journal($selectedIds=array(), $htmlname = 'journal', $nature = 0, $showempty = 0, $select_in = 0, $select_out = 0, $morecss = '', $usecache = '', $disabledajaxcombo = 0) + { + // phpcs:enable + global $conf, $langs; + + $out = ''; + + $options = array(); + if ($usecache && !empty($this->options_cache[$usecache])) + { + $options = $this->options_cache[$usecache]; + $selected = $selectedIds; + } else { + $sql = "SELECT rowid, code, label, nature, entity, active"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal"; + $sql .= " WHERE active = 1"; + $sql .= " AND entity = ".$conf->entity; + if ($nature && is_numeric($nature)) $sql .= " AND nature = ".$nature; + $sql .= " ORDER BY code"; + + dol_syslog(get_class($this)."::multi_select_journal", LOG_DEBUG); + $resql = $this->db->query($sql); + + if (!$resql) { + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::multi_select_journal ".$this->error, LOG_ERR); + return -1; + } + + $selected = array(); + $langs->load('accountancy'); + while ($obj = $this->db->fetch_object($resql)) + { + $label = $langs->trans($obj->label); + + $select_value_in = $obj->rowid; + $select_value_out = $obj->rowid; + + // Try to guess if we have found default value + if ($select_in == 1) { + $select_value_in = $obj->code; + } + if ($select_out == 1) { + $select_value_out = $obj->code; + } + // Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid + if (!empty($selectedIds) && in_array($select_value_in, $selectedIds)) { + //var_dump("Found ".$selectid." ".$select_value_in); + $selected[] = $select_value_out; + } + $options[$select_value_out] = $label; + } + $this->db->free($resql); + + if ($usecache) + { + $this->options_cache[$usecache] = $options; + } + } + + $out .= Form::multiselectarray($htmlname, $options, $selected, $showempty, 0, $morecss, 0, 0, 0, 'code_journal', '',($disabledajaxcombo ? 0 : 1)); + + return $out; + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of accounting category. diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 811dd57544e..7eff70422ee 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -154,6 +154,12 @@ class modAccounting extends DolibarrModules "csv", "", 0, 'current', 0 ); + $this->const[14] = array( + "ACCOUNTING_LIMIT_LIST_VENTILATION", + "chaine", + "50", + "", 0, 'current', 0 + ); // Tabs $this->tabs = array(); diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 1d75fa153e8..c35d85e7bcb 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -144,7 +144,7 @@ NotVentilatedinAccount=Not bound to the accounting account XLineSuccessfullyBinded=%s products/services successfully bound to an accounting account XLineFailedToBeBinded=%s products/services were not bound to any accounting account -ACCOUNTING_LIMIT_LIST_VENTILATION=Number of elements to bind shown by page (maximum recommended: 50) +ACCOUNTING_LIMIT_LIST_VENTILATION=Number of elements to on list and bind shown by page (maximum recommended: 50) ACCOUNTING_LIST_SORT_VENTILATION_TODO=Begin the sorting of the page "Binding to do" by the most recent elements ACCOUNTING_LIST_SORT_VENTILATION_DONE=Begin the sorting of the page "Binding done" by the most recent elements diff --git a/htdocs/langs/fr_FR/accountancy.lang b/htdocs/langs/fr_FR/accountancy.lang index 6381caebbec..5309adfae93 100644 --- a/htdocs/langs/fr_FR/accountancy.lang +++ b/htdocs/langs/fr_FR/accountancy.lang @@ -137,7 +137,7 @@ NotVentilatedinAccount=Non lié au compte comptable XLineSuccessfullyBinded=%s produits/service correctement liés à un compte comptable XLineFailedToBeBinded=%s produits/services n'ont pu être liés à un compte comptable -ACCOUNTING_LIMIT_LIST_VENTILATION=Nombre d'éléments à lier représentés par page (maximum recommandé: 50) +ACCOUNTING_LIMIT_LIST_VENTILATION=Nombre de ligne des listes et d'éléments à lier représentés par page (maximum recommandé: 50) ACCOUNTING_LIST_SORT_VENTILATION_TODO=Commencez le tri de la page "Lien à réaliser" par les éléments les plus récents ACCOUNTING_LIST_SORT_VENTILATION_DONE=Commencez le tri de la page "Liens réalisés" par les éléments les plus récents