Only save available for last month and add overspent
This commit is contained in:
@ -9,7 +9,8 @@ interface State {
|
||||
CurrentAccountID: string | null;
|
||||
Categories: Map<string, Category>;
|
||||
Months: Map<number, Map<number, Map<string, Category>>>;
|
||||
Available: Map<number, Map<number, number>>;
|
||||
Available: number,
|
||||
OverspentLastMonth: number,
|
||||
Assignments: [];
|
||||
}
|
||||
|
||||
@ -51,7 +52,8 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
Accounts: new Map<string, Account>(),
|
||||
CurrentAccountID: null,
|
||||
Months: new Map<number, Map<number, Map<string, Category>>>(),
|
||||
Available: new Map<number, Map<number, number>>(),
|
||||
Available: 0,
|
||||
OverspentLastMonth: 0,
|
||||
Categories: new Map<string, Category>(),
|
||||
Assignments: [],
|
||||
}),
|
||||
@ -107,12 +109,6 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
};
|
||||
};
|
||||
},
|
||||
GetIncomeAvailable(state) {
|
||||
return (year: number, month: number) => {
|
||||
const yearMapAv = this.Available.get(year);
|
||||
return yearMapAv?.get(month);
|
||||
};
|
||||
},
|
||||
CategoryGroupsForMonth(state) {
|
||||
return (year: number, month: number) => {
|
||||
const categories = this.AllCategoriesForMonth(year, month);
|
||||
@ -215,7 +211,7 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
response.Categories.length <= 0
|
||||
)
|
||||
return;
|
||||
this.addCategoriesForMonth(year, month, response.Categories, response.AvailableBalance);
|
||||
this.addCategoriesForMonth(year, month, response.Categories, response.AvailableBalance, response.OverspentLastMonth);
|
||||
},
|
||||
async EditAccount(
|
||||
accountid: string,
|
||||
@ -242,7 +238,8 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
year: number,
|
||||
month: number,
|
||||
categories: Category[],
|
||||
available: number
|
||||
available: number,
|
||||
overspentLastMonth: number,
|
||||
): void {
|
||||
this.$patch((state) => {
|
||||
const yearMap =
|
||||
@ -257,11 +254,8 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
yearMap.set(month, monthMap);
|
||||
state.Months.set(year, yearMap);
|
||||
|
||||
const yearMapAv =
|
||||
state.Available.get(year) ||
|
||||
new Map<number, number>();
|
||||
yearMapAv.set(month, available);
|
||||
state.Available.set(year, yearMapAv);
|
||||
state.Available = available;
|
||||
state.OverspentLastMonth = overspentLastMonth;
|
||||
});
|
||||
},
|
||||
logout() {
|
||||
|
Reference in New Issue
Block a user