From 3d36e3ee49e6524c11c2b47dd7867f92b7f005fa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 8 Apr 2018 12:41:03 +0200 Subject: [PATCH] Fix search criteria in bookkeeping table --- htdocs/accountancy/bookkeeping/list.php | 32 ++++++++++--------- .../accountancy/class/bookkeeping.class.php | 7 ++-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 7f9509921f9..57f52a4a77f 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -75,6 +75,8 @@ if ($search_accountancy_aux_code_end == - 1) { } $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'); // Load variable for pagination @@ -98,7 +100,7 @@ $form = new Form($db); if (! in_array($action, array('export_file', 'delmouv', 'delmouvconfirm')) && ! isset($_POST['begin']) && ! isset($_GET['begin']) && ! isset($_POST['formfilteraction']) && GETPOST('page','int') == '' && ! GETPOST('noreset','int')) { - if (empty($search_date_start) && empty($search_date_end)) + if (empty($search_date_start) && empty($search_date_end) && ! GETPOSTISSET('restore_lastsearch_values')) { $query = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear "; $query.= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."' limit 1"; @@ -195,51 +197,51 @@ if (! empty($search_doc_date)) { } if (! empty($search_doc_type)) { $filter['t.doc_type'] = $search_doc_type; - $param .= '&search_doc_type=' . $search_doc_type; + $param .= '&search_doc_type=' . urlencode($search_doc_type); } if (! empty($search_doc_ref)) { $filter['t.doc_ref'] = $search_doc_ref; - $param .= '&search_doc_ref=' . $search_doc_ref; + $param .= '&search_doc_ref=' . urlencode($search_doc_ref); } if (! empty($search_accountancy_code)) { $filter['t.numero_compte'] = $search_accountancy_code; - $param .= '&search_accountancy_code=' . $search_accountancy_code; + $param .= '&search_accountancy_code=' . urlencode($search_accountancy_code); } if (! empty($search_accountancy_code_start)) { $filter['t.numero_compte>='] = $search_accountancy_code_start; - $param .= '&search_accountancy_code_start=' . $search_accountancy_code_start; + $param .= '&search_accountancy_code_start=' . urlencode($search_accountancy_code_start); } if (! empty($search_accountancy_code_end)) { $filter['t.numero_compte<='] = $search_accountancy_code_end; - $param .= '&search_accountancy_code_end=' . $search_accountancy_code_end; + $param .= '&search_accountancy_code_end=' . urlencode($search_accountancy_code_end); } if (! empty($search_accountancy_aux_code)) { $filter['t.subledger_account'] = $search_accountancy_aux_code; - $param .= '&search_accountancy_aux_code=' . $search_accountancy_aux_code; + $param .= '&search_accountancy_aux_code=' . urlencode($search_accountancy_aux_code); } if (! empty($search_accountancy_aux_code_start)) { $filter['t.subledger_account>='] = $search_accountancy_aux_code_start; - $param .= '&search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start; + $param .= '&search_accountancy_aux_code_start=' . urlencode($search_accountancy_aux_code_start); } if (! empty($search_accountancy_aux_code_end)) { $filter['t.subledger_account<='] = $search_accountancy_aux_code_end; - $param .= '&search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end; + $param .= '&search_accountancy_aux_code_end=' . urlencode($search_accountancy_aux_code_end); } if (! empty($search_mvt_label)) { $filter['t.label_operation'] = $search_mvt_label; - $param .= '&search_mvt_label=' . $search_mvt_label; + $param .= '&search_mvt_label=' . urlencode($search_mvt_label); } if (! empty($search_direction)) { $filter['t.sens'] = $search_direction; - $param .= '&search_direction=' . $search_direction; + $param .= '&search_direction=' . urlencode($search_direction); } if (! empty($search_ledger_code)) { $filter['t.code_journal'] = $search_ledger_code; - $param .= '&search_ledger_code=' . $search_ledger_code; + $param .= '&search_ledger_code=' . urlencode($search_ledger_code); } if (! empty($search_mvt_num)) { $filter['t.piece_num'] = $search_mvt_num; - $param .= '&search_mvt_num=' . $search_mvt_num; + $param .= '&search_mvt_num=' . urlencode($search_mvt_num); } if (! empty($search_date_creation_start)) { $filter['t.date_creation>='] = $search_date_creation_start; @@ -263,11 +265,11 @@ if (! empty($search_date_modification_end)) { } if (! empty($search_debit)) { $filter['t.debit'] = $search_debit; - $param .= '&search_debit=' . $search_debit; + $param .= '&search_debit=' . urlencode($search_debit); } if (! empty($search_credit)) { $filter['t.credit'] = $search_credit; - $param .= '&search_credit=' . $search_credit; + $param .= '&search_credit=' . urlencode($search_credit); } if ($action == 'delbookkeeping') { diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index a1c4ba080ee..0ad91a30f56 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -865,13 +865,14 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; } elseif ($key == 't.tms>=' || $key == 't.tms<=') { $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; + } elseif ($key == 't.credit' || $key == 't.debit') { + $sqlwhere[] = natural_search($key, $value, 1, 1); } else { - $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + $sqlwhere[] = natural_search($key, $value, 0, 1); } } } - $sql.= ' WHERE 1 = 1'; - $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; + $sql.= ' WHERE entity IN (' . getEntity('accountancy') . ')'; if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); }