From b812b19b34a424ab7fd2e95c552dc9b104de7709 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sat, 23 Apr 2022 20:11:52 +0000 Subject: [PATCH 1/5] Indentation --- postgres/queries/transactions.sql | 8 ++++---- postgres/transactions.sql.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/postgres/queries/transactions.sql b/postgres/queries/transactions.sql index aebc7ff..e39e3e2 100644 --- a/postgres/queries/transactions.sql +++ b/postgres/queries/transactions.sql @@ -11,10 +11,10 @@ RETURNING id; -- name: UpdateTransaction :exec UPDATE transactions SET date = $1, - memo = $2, - amount = $3, - payee_id = $4, - category_id = $5 + memo = $2, + amount = $3, + payee_id = $4, + category_id = $5 WHERE id = $6; -- name: SetTransactionReconciled :exec diff --git a/postgres/transactions.sql.go b/postgres/transactions.sql.go index 60fcf1d..f110a70 100644 --- a/postgres/transactions.sql.go +++ b/postgres/transactions.sql.go @@ -294,10 +294,10 @@ func (q *Queries) SetTransactionReconciled(ctx context.Context, id uuid.UUID) er const updateTransaction = `-- name: UpdateTransaction :exec UPDATE transactions SET date = $1, - memo = $2, - amount = $3, - payee_id = $4, - category_id = $5 + memo = $2, + amount = $3, + payee_id = $4, + category_id = $5 WHERE id = $6 ` -- 2.47.2 From a48509e041f7958956bd776e33734a12fa60703e Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sat, 23 Apr 2022 20:12:05 +0000 Subject: [PATCH 2/5] Calculate overspent for last month --- server/budgeting.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server/budgeting.go b/server/budgeting.go index 8ab0cae..0527ce0 100644 --- a/server/budgeting.go +++ b/server/budgeting.go @@ -66,16 +66,17 @@ func (h *Handler) getBudgetingViewForMonth(ctx context.Context, budget postgres. return BudgetingForMonthResponse{}, fmt.Errorf("error loading balances: %w", err) } - categoriesWithBalance, moneyUsed := h.calculateBalances(budget, month, categories, cumultativeBalances) + categoriesWithBalance, moneyUsed, overspentLastMonth := h.calculateBalances(budget, month, categories, cumultativeBalances) availableBalance := h.getAvailableBalance(budget, month, moneyUsed, cumultativeBalances) - data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance} + data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance, overspentLastMonth} return data, nil } type BudgetingForMonthResponse struct { - Categories []CategoryWithBalance - AvailableBalance numeric.Numeric + Categories []CategoryWithBalance + AvailableBalance numeric.Numeric + OverspentLastMonth numeric.Numeric } func (*Handler) getAvailableBalance(budget postgres.Budget, month Month, @@ -135,10 +136,11 @@ func (h *Handler) getBudget(c *gin.Context, budgetUUID uuid.UUID) { func (h *Handler) calculateBalances(budget postgres.Budget, month Month, categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow, -) ([]CategoryWithBalance, numeric.Numeric) { +) ([]CategoryWithBalance, numeric.Numeric, numeric.Numeric) { categoriesWithBalance := []CategoryWithBalance{} moneyUsed := numeric.Zero() + overspentLastMonth := numeric.Zero() categories = append(categories, postgres.GetCategoriesRow{ Group: "Income", Name: "No Category", @@ -172,6 +174,9 @@ func (h *Handler) calculateBalances(budget postgres.Budget, month Month, categoryWithBalance.AvailableLastMonth.AddI(bal.Transactions) if !categoryWithBalance.AvailableLastMonth.IsPositive() { moneyUsed.AddI(categoryWithBalance.AvailableLastMonth) + if month.Previous().InPresent(bal.Date) { + overspentLastMonth.AddI(categoryWithBalance.AvailableLastMonth) + } categoryWithBalance.AvailableLastMonth = numeric.Zero() } } @@ -179,5 +184,5 @@ func (h *Handler) calculateBalances(budget postgres.Budget, month Month, categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance) } - return categoriesWithBalance, moneyUsed + return categoriesWithBalance, moneyUsed, overspentLastMonth } -- 2.47.2 From 704a5209937cc27340bccdafd7ae3f50aa59a8fe Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sat, 23 Apr 2022 20:12:20 +0000 Subject: [PATCH 3/5] Implement Next and Previous for month datatype --- server/month.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/month.go b/server/month.go index 4d46f3e..bd0c23d 100644 --- a/server/month.go +++ b/server/month.go @@ -22,6 +22,22 @@ func (m Month) FirstOfMonth() time.Time { return time.Date(m.Year, time.Month(m.Month), 1, 0, 0, 0, 0, time.Now().Location()) } +func (m Month) Previous() Month { + if m.Month == 1 { + return Month{Year: m.Year - 1, Month: 12} + } + + return Month{Year: m.Year, Month: m.Month - 1} +} + +func (m Month) Next() Month { + if m.Month == 12 { + return Month{Year: m.Year + 1, Month: 1} + } + + return Month{Year: m.Year, Month: m.Month + 1} +} + func (m Month) InFuture(date time.Time) bool { if m.Year < date.Year() { return true -- 2.47.2 From 0817f18e3345d5e35bc9042b11ce26c205112121 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sat, 23 Apr 2022 20:12:37 +0000 Subject: [PATCH 4/5] Only save available for last month and add overspent --- web/src/pages/Budgeting.vue | 71 +++++++++++++++++++++----------- web/src/stores/budget-account.ts | 24 ++++------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/web/src/pages/Budgeting.vue b/web/src/pages/Budgeting.vue index 09fc432..34fbd8e 100644 --- a/web/src/pages/Budgeting.vue +++ b/web/src/pages/Budgeting.vue @@ -78,29 +78,54 @@ const budgeted = computed(() => accountStore.GetBudgeted(selected.value.Year, se