NEW: Multiselect ledger account code filter on book keeping list

This commit is contained in:
Florian HENRY
2020-11-07 15:31:27 +01:00
parent 2fdba3ad46
commit 1bdd617feb
6 changed files with 117 additions and 9 deletions

View File

@@ -48,6 +48,7 @@ $action = GETPOST('action', 'aZ09');
$list = array( $list = array(
'ACCOUNTING_LENGTH_GACCOUNT', 'ACCOUNTING_LENGTH_GACCOUNT',
'ACCOUNTING_LENGTH_AACCOUNT', 'ACCOUNTING_LENGTH_AACCOUNT',
'ACCOUNTING_LIMIT_LIST_VENTILATION'
// 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc // '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 // '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 '</tr>'; print '</tr>';
*/ */
print '<tr class="oddeven">'; /*print '<tr class="oddeven">';
print '<td>'.$langs->trans("BANK_DISABLE_DIRECT_INPUT").'</td>'; print '<td>'.$langs->trans("BANK_DISABLE_DIRECT_INPUT").'</td>';
if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) { if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disabledirectinput&value=0">'; print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disabledirectinput&value=0">';
@@ -259,7 +260,7 @@ if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
print img_picto($langs->trans("Disabled"), 'switch_off'); print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>'; print '</a></td>';
} }
print '</tr>'; print '</tr>';*/
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$langs->trans("ACCOUNTANCY_COMBO_FOR_AUX").'</td>'; print '<td>'.$langs->trans("ACCOUNTANCY_COMBO_FOR_AUX").'</td>';
@@ -313,6 +314,21 @@ print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans('BindingOptions').'</td>'; print '<td colspan="2">'.$langs->trans('BindingOptions').'</td>';
print "</tr>\n"; print "</tr>\n";
// TO DO Mutualize code for yes/no constants
print '<tr class="oddeven">';
print '<td>'.$langs->trans("").'</td>';
if (!empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) {
print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&listsorttodo&value=0">';
print img_picto($langs->trans("Activated"), 'switch_on');
print '</a></td>';
} else {
print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&listsorttodo&value=1">';
print img_picto($langs->trans("Disabled"), 'switch_off');
print '</a></td>';
}
print '</tr>';
// TO DO Mutualize code for yes/no constants // TO DO Mutualize code for yes/no constants
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO").'</td>'; print '<td>'.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO").'</td>';

View File

@@ -85,7 +85,7 @@ $search_mvt_label = GETPOST('search_mvt_label', 'alpha');
$search_direction = GETPOST('search_direction', 'alpha'); $search_direction = GETPOST('search_direction', 'alpha');
$search_debit = GETPOST('search_debit', 'alpha'); $search_debit = GETPOST('search_debit', 'alpha');
$search_credit = GETPOST('search_credit', '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_lettering_code = GETPOST('search_lettering_code', 'alpha');
$search_not_reconciled = GETPOST('search_reconciled_option', 'alpha'); $search_not_reconciled = GETPOST('search_reconciled_option', 'alpha');
@@ -192,7 +192,7 @@ if (empty($reshook))
$search_accountancy_aux_code_end = ''; $search_accountancy_aux_code_end = '';
$search_mvt_label = ''; $search_mvt_label = '';
$search_direction = ''; $search_direction = '';
$search_ledger_code = ''; $search_ledger_code = array();
$search_date_start = ''; $search_date_start = '';
$search_date_end = ''; $search_date_end = '';
$search_date_creation_start = ''; $search_date_creation_start = '';
@@ -267,7 +267,9 @@ if (empty($reshook))
} }
if (!empty($search_ledger_code)) { if (!empty($search_ledger_code)) {
$filter['t.code_journal'] = $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)) { if (!empty($search_mvt_num)) {
$filter['t.piece_num'] = $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); $sqlwhere[] = natural_search($key, $value, 1, 1);
} elseif ($key == 't.reconciled_option') { } elseif ($key == 't.reconciled_option') {
$sqlwhere[] = 't.lettering_code IS NULL'; $sqlwhere[] = 't.lettering_code IS NULL';
} elseif ($key == 't.code_journal' && !empty($value)) {
$sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1);
} else { } else {
$sqlwhere[] = natural_search($key, $value, 0, 1); $sqlwhere[] = natural_search($key, $value, 0, 1);
} }
@@ -756,7 +760,9 @@ if (!empty($arrayfields['t.lettering_code']['checked']))
// Code journal // Code journal
if (!empty($arrayfields['t.code_journal']['checked'])) if (!empty($arrayfields['t.code_journal']['checked']))
{ {
print '<td class="liste_titre center"><input type="text" name="search_ledger_code" size="3" value="'.$search_ledger_code.'"></td>'; print '<td class="liste_titre center">';
print $formaccounting->multi_select_journal($search_ledger_code, 'search_ledger_code', 0, 1, 1, 1);
print '</td>';
} }
// Fields from hook // Fields from hook

View File

@@ -59,7 +59,7 @@ class FormAccounting extends Form
/** /**
* Return list of journals with label by nature * 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 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 $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 $showempty Add an empty field
@@ -136,6 +136,86 @@ class FormAccounting extends Form
return $out; 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 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Return list of accounting category. * Return list of accounting category.

View File

@@ -154,6 +154,12 @@ class modAccounting extends DolibarrModules
"csv", "csv",
"", 0, 'current', 0 "", 0, 'current', 0
); );
$this->const[14] = array(
"ACCOUNTING_LIMIT_LIST_VENTILATION",
"chaine",
"50",
"", 0, 'current', 0
);
// Tabs // Tabs
$this->tabs = array(); $this->tabs = array();

View File

@@ -144,7 +144,7 @@ NotVentilatedinAccount=Not bound to the accounting account
XLineSuccessfullyBinded=%s products/services successfully bound to an accounting account XLineSuccessfullyBinded=%s products/services successfully bound to an accounting account
XLineFailedToBeBinded=%s products/services were not bound to any 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_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 ACCOUNTING_LIST_SORT_VENTILATION_DONE=Begin the sorting of the page "Binding done" by the most recent elements

View File

@@ -137,7 +137,7 @@ NotVentilatedinAccount=Non lié au compte comptable
XLineSuccessfullyBinded=%s produits/service correctement liés à un 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 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_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 ACCOUNTING_LIST_SORT_VENTILATION_DONE=Commencez le tri de la page "Liens réalisés" par les éléments les plus récents