diff --git a/postgres/assignments.sql.go b/postgres/assignments.sql.go
index 52bd45d..633b6d0 100644
--- a/postgres/assignments.sql.go
+++ b/postgres/assignments.sql.go
@@ -148,3 +148,22 @@ func (q *Queries) UpdateAssignment(ctx context.Context, arg UpdateAssignmentPara
_, err := q.db.ExecContext(ctx, updateAssignment, arg.CategoryID, arg.Date, arg.Amount)
return err
}
+
+const updateAssignmentWithDifference = `-- name: UpdateAssignmentWithDifference :exec
+INSERT INTO assignments (category_id, date, amount)
+VALUES($1, $2, $3)
+ON CONFLICT (category_id, date)
+DO
+ UPDATE SET amount = assignments.amount + $3
+`
+
+type UpdateAssignmentWithDifferenceParams struct {
+ CategoryID uuid.UUID
+ Date time.Time
+ Amount numeric.Numeric
+}
+
+func (q *Queries) UpdateAssignmentWithDifference(ctx context.Context, arg UpdateAssignmentWithDifferenceParams) error {
+ _, err := q.db.ExecContext(ctx, updateAssignmentWithDifference, arg.CategoryID, arg.Date, arg.Amount)
+ return err
+}
diff --git a/postgres/queries/assignments.sql b/postgres/queries/assignments.sql
index cb0687d..145eee7 100644
--- a/postgres/queries/assignments.sql
+++ b/postgres/queries/assignments.sql
@@ -29,4 +29,11 @@ INSERT INTO assignments (category_id, date, amount)
VALUES($1, $2, $3)
ON CONFLICT (category_id, date)
DO
- UPDATE SET amount = $3;
\ No newline at end of file
+ UPDATE SET amount = $3;
+
+-- name: UpdateAssignmentWithDifference :exec
+INSERT INTO assignments (category_id, date, amount)
+VALUES($1, $2, $3)
+ON CONFLICT (category_id, date)
+DO
+ UPDATE SET amount = assignments.amount + $3;
\ No newline at end of file
diff --git a/postgres/ynab-import.go b/postgres/ynab-import.go
index 83c5f9d..13f6afa 100644
--- a/postgres/ynab-import.go
+++ b/postgres/ynab-import.go
@@ -91,12 +91,12 @@ func (ynab *YNABImport) ImportAssignments(context context.Context, r io.Reader)
continue
}
- assignment := CreateAssignmentParams{
+ assignment := UpdateAssignmentWithDifferenceParams{
Date: date,
CategoryID: category.UUID,
Amount: amount,
}
- _, err = ynab.queries.CreateAssignment(context, assignment)
+ err = ynab.queries.UpdateAssignmentWithDifference(context, assignment)
if err != nil {
return fmt.Errorf("save assignment %v: %w", assignment, err)
}
@@ -226,7 +226,8 @@ func (ynab *YNABImport) GetTransaction(context context.Context, record []string)
}
func (ynab *YNABImport) ImportRegularTransaction(context context.Context, payeeName string,
- transaction CreateTransactionParams) error {
+ transaction CreateTransactionParams,
+) error {
payeeID, err := ynab.GetPayee(context, payeeName)
if err != nil {
return fmt.Errorf("get payee %s: %w", payeeName, err)
@@ -242,7 +243,8 @@ func (ynab *YNABImport) ImportRegularTransaction(context context.Context, payeeN
func (ynab *YNABImport) ImportTransferTransaction(context context.Context, payeeName string,
transaction CreateTransactionParams, openTransfers *[]Transfer,
- account *Account, amount numeric.Numeric) error {
+ account *Account, amount numeric.Numeric,
+) error {
transferToAccountName := payeeName[11:]
transferToAccount, err := ynab.GetAccount(context, transferToAccountName)
if err != nil {
diff --git a/web/src/components/Currency.vue b/web/src/components/Currency.vue
index 5f09804..809df4f 100644
--- a/web/src/components/Currency.vue
+++ b/web/src/components/Currency.vue
@@ -1,7 +1,11 @@
- {{ formattedValue }} €
+ {{ formattedValue }} €
\ No newline at end of file
diff --git a/web/src/pages/Budgeting.vue b/web/src/pages/Budgeting.vue
index c796090..13a0c7b 100644
--- a/web/src/pages/Budgeting.vue
+++ b/web/src/pages/Budgeting.vue
@@ -95,10 +95,14 @@ function assignedChanged(e : Event, category : Category){
Activity
Available
- {{ (getGroupState(group) ? "−" : "+") + " " + group.Name }}
+ >{{ (getGroupState(group) ? "−" : "+") + " " + group.Name }}
+
+
+
+
{{ category.Name }}
diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts
index becea06..bf64694 100644
--- a/web/src/stores/budget-account.ts
+++ b/web/src/stores/budget-account.ts
@@ -51,7 +51,7 @@ export const useAccountStore = defineStore("budget/account", {
return [...monthMap?.values() || []];
},
GetCategoryAvailable(state) {
- return (category : Category) : number => {
+ return (category: Category): number => {
return category.AvailableLastMonth + Number(category.Assigned) + category.Activity;
}
},
@@ -62,7 +62,7 @@ export const useAccountStore = defineStore("budget/account", {
GetIncomeAvailable(state) {
return (year: number, month: number) => {
const IncomeCategoryID = this.GetIncomeCategoryID;
- if(IncomeCategoryID == null)
+ if (IncomeCategoryID == null)
return 0;
const categories = this.AllCategoriesForMonth(year, month);
@@ -80,13 +80,26 @@ export const useAccountStore = defineStore("budget/account", {
for (const category of categories) {
if (category.ID == this.GetIncomeCategoryID)
continue;
-
- if (category.Group != prev)
- categoryGroups.push({
+
+ if (prev == undefined || category.Group != prev.Name) {
+ prev = {
Name: category.Group,
- Expand: category.Group != "Hidden Categories",
+ Available: this.GetCategoryAvailable(category),
+ AvailableLastMonth: category.AvailableLastMonth,
+ Activity: category.Activity,
+ Assigned: category.Assigned,
+ }
+ categoryGroups.push({
+ ...prev,
+ Expand: prev.Name != "Hidden Categories",
});
- prev = category.Group;
+ } else {
+ categoryGroups[categoryGroups.length-1].Available += this.GetCategoryAvailable(category);
+ categoryGroups[categoryGroups.length-1].AvailableLastMonth += category.AvailableLastMonth;
+ categoryGroups[categoryGroups.length-1].Activity += category.Activity;
+ categoryGroups[categoryGroups.length-1].Assigned += category.Assigned;
+ continue;
+ }
}
return categoryGroups;
}
@@ -142,7 +155,7 @@ export const useAccountStore = defineStore("budget/account", {
account.Transactions = transactions;
},
async FetchMonthBudget(budgetid: string, year: number, month: number) {
- const result = await GET("/budget/" + budgetid + "/" + year + "/" + (month+1));
+ const result = await GET("/budget/" + budgetid + "/" + year + "/" + (month + 1));
const response = await result.json();
if (response.Categories == undefined || response.Categories.length <= 0)
return;
@@ -153,7 +166,7 @@ export const useAccountStore = defineStore("budget/account", {
const response = await result.json();
useBudgetsStore().MergeBudgetingData(response);
- if(!isOpen) {
+ if (!isOpen) {
this.Accounts.delete(accountid);
}
},