From 67c013799dcf532aa29c64d1c32f0fb8846c8b0a Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Thu, 3 Mar 2022 10:44:50 +0000 Subject: [PATCH 01/16] Calculate available balance locally --- web/src/pages/Budgeting.vue | 5 +++-- web/src/stores/budget-account.ts | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web/src/pages/Budgeting.vue b/web/src/pages/Budgeting.vue index ef235fe..77c1535 100644 --- a/web/src/pages/Budgeting.vue +++ b/web/src/pages/Budgeting.vue @@ -4,6 +4,7 @@ import Currency from "../components/Currency.vue"; import { useBudgetsStore } from "../stores/budget"; import { useAccountStore } from "../stores/budget-account"; import { useSessionStore } from "../stores/session"; +import Input from "../components/Input.vue"; const props = defineProps<{ budgetid: string, @@ -92,9 +93,9 @@ function getGroupState(group: { Name: string, Expand: boolean }): boolean { diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index 4c6d71e..0360411 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -31,7 +31,6 @@ export interface Category { AvailableLastMonth: number Assigned: number Activity: number - Available: number } export const useAccountStore = defineStore("budget/account", { @@ -51,6 +50,11 @@ export const useAccountStore = defineStore("budget/account", { const monthMap = yearMap?.get(month); return [...monthMap?.values() || []]; }, + GetCategoryAvailable(state) { + return (category : Category) : number => { + return category.AvailableLastMonth + Number(category.Assigned) + category.Activity; + } + }, CategoryGroupsForMonth(state) { return (year: number, month: number) => { const categories = this.AllCategoriesForMonth(year, month); -- 2.47.2 From 37951505087adb0c686616cca2510afabb76d353 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 4 Mar 2022 20:54:23 +0000 Subject: [PATCH 02/16] Implement numeric operations in-place --- postgres/numeric/numeric.go | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/postgres/numeric/numeric.go b/postgres/numeric/numeric.go index 8d0cc5e..4988f9e 100644 --- a/postgres/numeric/numeric.go +++ b/postgres/numeric/numeric.go @@ -53,6 +53,13 @@ func (n Numeric) IsZero() bool { return float == 0 } +func (n *Numeric) MatchExpI(exp int32) { + diffExp := n.Exp - exp + factor := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(diffExp)), nil) //nolint:gomnd + n.Exp = exp + n.Int = big.NewInt(0).Mul(n.Int, factor) +} + func (n Numeric) MatchExp(exp int32) Numeric { diffExp := n.Exp - exp factor := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(diffExp)), nil) //nolint:gomnd @@ -64,6 +71,22 @@ func (n Numeric) MatchExp(exp int32) Numeric { }} } +func (n *Numeric) SubI(other Numeric) *Numeric { + right := other + if n.Exp < other.Exp { + right = other.MatchExp(n.Exp) + } else if n.Exp > other.Exp { + n.MatchExpI(other.Exp) + } + + if n.Exp == right.Exp { + n.Int = big.NewInt(0).Sub(n.Int, right.Int) + return n + } + + panic("Cannot subtract with different exponents") +} + func (n Numeric) Sub(other Numeric) Numeric { left := n right := other @@ -106,6 +129,22 @@ func (n Numeric) Add(other Numeric) Numeric { panic("Cannot add with different exponents") } +func (n *Numeric) AddI(other Numeric) *Numeric { + right := other + if n.Exp < other.Exp { + right = other.MatchExp(n.Exp) + } else if n.Exp > other.Exp { + n.MatchExpI(other.Exp) + } + + if n.Exp == right.Exp { + n.Int = big.NewInt(0).Add(n.Int, right.Int) + return n + } + + panic("Cannot add with different exponents") +} + func (n Numeric) String() string { if n.Int == nil || n.Int.Int64() == 0 { return "0" -- 2.47.2 From d89e702669da2b08b1c6219a1a36ca24eca91e5b Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Fri, 4 Mar 2022 20:55:14 +0000 Subject: [PATCH 03/16] Move sidebar layout to BudgetSidebar --- web/src/App.vue | 10 +--- web/src/pages/BudgetSidebar.vue | 99 +++++++++++++++++++-------------- 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/web/src/App.vue b/web/src/App.vue index 2345236..057c1f2 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -8,7 +8,6 @@ import { useSettingsStore } from "./stores/settings"; export default defineComponent({ computed: { ...mapState(useBudgetsStore, ["CurrentBudgetName"]), - ...mapState(useSettingsStore, ["Menu"]), ...mapState(useSessionStore, ["LoggedIn"]), }, methods: { @@ -27,15 +26,10 @@ export default defineComponent({