From 9934d49b7cfd941bb0041aedebda6a1f36e42357 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 19 Jan 2024 23:11:18 +0100 Subject: [PATCH] Allow quick transfers from category sums Signed-off-by: Knut Ahlers --- frontend/components/budgetDashboard.vue | 55 +++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/frontend/components/budgetDashboard.vue b/frontend/components/budgetDashboard.vue index 55a6ae8..da93870 100644 --- a/frontend/components/budgetDashboard.vue +++ b/frontend/components/budgetDashboard.vue @@ -56,8 +56,15 @@ {{ formatNumber(activityByCategory[cat.id] || 0) }} € - - {{ formatNumber(cat.balance) }} € + + + {{ formatNumber(cat.balance) }} € + @@ -274,6 +281,39 @@ export default { formatNumber, + initTransfer(catId) { + const cat = this.categories.filter(cat => cat.id === catId)[0] || null + if (!cat) { + console.error(`init transfer from non existent category ${catId}`) + return + } + + this.modals.createTransfer = { + amount: 0, + from: '', + to: '', + } + + if (cat.balance <= 0) { + // Most likely scenario: Transfer in + this.modals.createTransfer.from = unallocatedMoneyAcc + this.modals.createTransfer.to = cat.id + } else { + // Most likely scenario: Transfer out + this.modals.createTransfer.from = cat.id + } + + Modal.getOrCreateInstance(this.$refs.transferMoneyModal).toggle() + }, + + resetTransfer() { + this.modals.createTransfer = { + amount: 0, + from: unallocatedMoneyAcc, + to: '', + } + }, + transferMoney() { const params = new URLSearchParams() params.set('amount', this.modals.createTransfer.amount.toFixed(2)) @@ -285,16 +325,15 @@ export default { this.$emit('update-accounts') this.fetchTransactions() Modal.getInstance(this.$refs.transferMoneyModal).toggle() - - this.modals.createTransfer = { - amount: 0, - from: unallocatedMoneyAcc, - to: '', - } }) }, }, + mounted() { + this.$refs.transferMoneyModal + .addEventListener('hidden.bs.modal', () => this.resetTransfer()) + }, + name: 'AccountingAppBudgetDashboard', props: {