From aff795745c33eb638ec84b27a552c79fa2e7a375 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 16 Nov 2024 21:17:46 +1100 Subject: [PATCH] Implement account transactions with commodity detail view --- src/{commodities.ts => amounts.ts} | 31 ++++ src/pages/GeneralLedgerView.vue | 2 +- src/pages/TransactionsView.vue | 119 ++------------ src/pages/TransactionsWithCommodityView.vue | 151 ++++++++++++++++++ .../TransactionsWithoutCommodityView.vue | 139 ++++++++++++++++ 5 files changed, 335 insertions(+), 107 deletions(-) rename src/{commodities.ts => amounts.ts} (68%) create mode 100644 src/pages/TransactionsWithCommodityView.vue create mode 100644 src/pages/TransactionsWithoutCommodityView.vue diff --git a/src/commodities.ts b/src/amounts.ts similarity index 68% rename from src/commodities.ts rename to src/amounts.ts index 8a27866..7f25600 100644 --- a/src/commodities.ts +++ b/src/amounts.ts @@ -18,6 +18,37 @@ import { db } from './db.ts'; +export interface Amount { + quantity: number; + commodity: string; +} + +export class Balance { + // A collection of Amount's + amounts: Amount[] = []; + + add(quantity: number, commodity: string) { + const existingAmount = this.amounts.find((a) => a.commodity === commodity); + if (existingAmount) { + existingAmount.quantity += quantity; + } else { + this.amounts.push({ quantity: quantity, commodity: commodity }); + } + } + + clone(): Balance { + const newBalance = new Balance(); + for (const amount of this.amounts) { + newBalance.amounts.push({ quantity: amount.quantity, commodity: amount.commodity }); + } + return newBalance; + } + + clean() { + this.amounts = this.amounts.filter((a) => a.quantity !== 0); + } +} + export function asCost(quantity: number, commodity: string): number { // Convert the amount to cost price in the reporting commodity diff --git a/src/pages/GeneralLedgerView.vue b/src/pages/GeneralLedgerView.vue index c8d9eaf..29c3468 100644 --- a/src/pages/GeneralLedgerView.vue +++ b/src/pages/GeneralLedgerView.vue @@ -56,7 +56,7 @@ import { onUnmounted, ref } from 'vue'; - import { asCost } from '../commodities.ts'; + import { asCost } from '../amounts.ts'; import { JoinedTransactionPosting, Transaction, db, joinedToTransactions } from '../db.ts'; import { pp, ppWithCommodity } from '../display.ts'; diff --git a/src/pages/TransactionsView.vue b/src/pages/TransactionsView.vue index 411a629..9873b91 100644 --- a/src/pages/TransactionsView.vue +++ b/src/pages/TransactionsView.vue @@ -18,55 +18,36 @@ diff --git a/src/pages/TransactionsWithCommodityView.vue b/src/pages/TransactionsWithCommodityView.vue new file mode 100644 index 0000000..ac2a463 --- /dev/null +++ b/src/pages/TransactionsWithCommodityView.vue @@ -0,0 +1,151 @@ + + + + + diff --git a/src/pages/TransactionsWithoutCommodityView.vue b/src/pages/TransactionsWithoutCommodityView.vue new file mode 100644 index 0000000..f18131d --- /dev/null +++ b/src/pages/TransactionsWithoutCommodityView.vue @@ -0,0 +1,139 @@ + + + + +