Add receivable/payable filtering with database-level query optimization
Add account type filtering to Recent Transactions table and fix pagination issue where filters were applied after fetching results, causing incomplete data display.
Database layer (crud.py):
- Add get_journal_entries_by_user_and_account_type() to filter entries by
both user_id and account_type at SQL query level
- Add count_journal_entries_by_user_and_account_type() for accurate counts
- Filters apply before pagination, ensuring all matching records are fetched
API layer (views_api.py):
- Add filter_account_type parameter ('asset' for receivable, 'liability' for payable)
- Refactor filtering logic to use new database-level filter functions
- Support filter combinations: user only, account_type only, user+account_type, or all
- Enrich entries with account_type metadata for UI display
Frontend (index.js):
- Add account_type to transactionFilter state
- Add accountTypeOptions computed property with receivable/payable choices
- Reorder table columns to show User before Date
- Update loadTransactions to send account_type filter parameter
- Update clearTransactionFilter to clear both user and account_type filters
UI (index.html):
- Add second filter dropdown for account type (Receivable/Payable)
- Show clear button when either filter is active
- Update button label from "Clear Filter" to "Clear Filters"
This fixes the critical bug where filtering for receivables would only show a subset of results (e.g., 2 out of 20 entries fetched) instead of all matching receivables. Now filters are applied at the database level before pagination, ensuring users see all relevant transactions.
This commit is contained in:
parent
f3d0d8652b
commit
3af93c3479
4 changed files with 163 additions and 22 deletions
|
|
@ -18,7 +18,8 @@ window.app = Vue.createApp({
|
|||
has_prev: false
|
||||
},
|
||||
transactionFilter: {
|
||||
user_id: null // For filtering by user
|
||||
user_id: null, // For filtering by user
|
||||
account_type: null // For filtering by receivable/payable (asset/liability)
|
||||
},
|
||||
accounts: [],
|
||||
currencies: [],
|
||||
|
|
@ -189,14 +190,21 @@ window.app = Vue.createApp({
|
|||
transactionColumns() {
|
||||
return [
|
||||
{ name: 'flag', label: 'Status', field: 'flag', align: 'left', sortable: true },
|
||||
{ name: 'username', label: 'User', field: 'username', align: 'left', sortable: true },
|
||||
{ name: 'date', label: 'Date', field: 'entry_date', align: 'left', sortable: true },
|
||||
{ name: 'description', label: 'Description', field: 'description', align: 'left', sortable: false },
|
||||
{ name: 'username', label: 'User', field: 'username', align: 'left', sortable: true },
|
||||
{ name: 'amount', label: 'Amount (sats)', field: 'amount', align: 'right', sortable: false },
|
||||
{ name: 'fiat', label: 'Fiat Amount', field: 'fiat', align: 'right', sortable: false },
|
||||
{ name: 'reference', label: 'Reference', field: 'reference', align: 'left', sortable: false }
|
||||
]
|
||||
},
|
||||
accountTypeOptions() {
|
||||
return [
|
||||
{ label: 'All Types', value: null },
|
||||
{ label: 'Receivable (User owes Castle)', value: 'asset' },
|
||||
{ label: 'Payable (Castle owes User)', value: 'liability' }
|
||||
]
|
||||
},
|
||||
expenseAccounts() {
|
||||
return this.accounts.filter(a => a.account_type === 'expense')
|
||||
},
|
||||
|
|
@ -344,11 +352,14 @@ window.app = Vue.createApp({
|
|||
|
||||
const limit = parseInt(this.transactionPagination.limit) || 20
|
||||
|
||||
// Build query params with filter
|
||||
// Build query params with filters
|
||||
let queryParams = `limit=${limit}&offset=${currentOffset}`
|
||||
if (this.transactionFilter.user_id) {
|
||||
queryParams += `&filter_user_id=${this.transactionFilter.user_id}`
|
||||
}
|
||||
if (this.transactionFilter.account_type) {
|
||||
queryParams += `&filter_account_type=${this.transactionFilter.account_type}`
|
||||
}
|
||||
|
||||
const response = await LNbits.api.request(
|
||||
'GET',
|
||||
|
|
@ -373,6 +384,7 @@ window.app = Vue.createApp({
|
|||
},
|
||||
clearTransactionFilter() {
|
||||
this.transactionFilter.user_id = null
|
||||
this.transactionFilter.account_type = null
|
||||
this.transactionPagination.offset = 0
|
||||
this.loadTransactions(0)
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue