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 @@ + + + + +