Adds expense approval workflow

Implements expense approval functionality, allowing superusers to review and approve or reject expense entries.

This includes:
- Filtering account balance calculations and user balance calculations to only include cleared journal entries.
- Adding API endpoints to retrieve pending expense entries and approve/reject them.
- Updating the UI to display pending expenses to superusers and provide actions to approve or reject them.

This ensures better control over expenses within the system.
This commit is contained in:
padreug 2025-10-23 00:26:52 +02:00
parent 8221feec20
commit 018a074915
4 changed files with 232 additions and 8 deletions

View file

@ -64,7 +64,8 @@ window.app = Vue.createApp({
description: '',
loading: false
},
manualPaymentRequests: []
manualPaymentRequests: [],
pendingExpenses: []
}
},
watch: {
@ -493,6 +494,20 @@ window.app = Vue.createApp({
console.error('Error loading manual payment requests:', error)
}
},
async loadPendingExpenses() {
try {
if (!this.isSuperUser) return
const response = await LNbits.api.request(
'GET',
'/castle/api/v1/entries/pending',
this.g.user.wallets[0].adminkey
)
this.pendingExpenses = response.data
} catch (error) {
console.error('Error loading pending expenses:', error)
}
},
async approveManualPaymentRequest(requestId) {
try {
await LNbits.api.request(
@ -527,6 +542,42 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(error)
}
},
async approveExpense(entryId) {
try {
await LNbits.api.request(
'POST',
`/castle/api/v1/entries/${entryId}/approve`,
this.g.user.wallets[0].adminkey
)
this.$q.notify({
type: 'positive',
message: 'Expense approved!'
})
await this.loadPendingExpenses()
await this.loadBalance()
await this.loadTransactions()
await this.loadAllUserBalances()
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
async rejectExpense(entryId) {
try {
await LNbits.api.request(
'POST',
`/castle/api/v1/entries/${entryId}/reject`,
this.g.user.wallets[0].adminkey
)
this.$q.notify({
type: 'warning',
message: 'Expense rejected'
})
await this.loadPendingExpenses()
await this.loadTransactions()
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
copyToClipboard(text) {
navigator.clipboard.writeText(text)
this.$q.notify({
@ -674,9 +725,10 @@ window.app = Vue.createApp({
await this.loadAccounts()
await this.loadCurrencies()
await this.loadManualPaymentRequests()
// Load users if super user (for receivable dialog)
// Load users and pending expenses if super user
if (this.isSuperUser) {
await this.loadUsers()
await this.loadPendingExpenses()
}
}
})