Use available from API instead of category

This commit is contained in:
Jan Bader 2022-04-07 08:06:58 +00:00
parent 4f681d6d89
commit bb664494f6

View File

@ -9,6 +9,7 @@ interface State {
CurrentAccountID: string | null;
Categories: Map<string, Category>;
Months: Map<number, Map<number, Map<string, Category>>>;
Available: Map<number, Map<number, number>>;
Assignments: [];
}
@ -43,6 +44,7 @@ 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>>(),
Categories: new Map<string, Category>(),
Assignments: [],
}),
@ -96,15 +98,8 @@ export const useAccountStore = defineStore("budget/account", {
},
GetIncomeAvailable(state) {
return (year: number, month: number) => {
const IncomeCategoryID = this.GetIncomeCategoryID;
if (IncomeCategoryID == null) return 0;
const categories = this.AllCategoriesForMonth(year, month);
const category = categories.filter(
(x) => x.ID == IncomeCategoryID
)[0];
if (category == null) return 0;
return category.AvailableLastMonth;
const yearMapAv = this.Available.get(year);
return yearMapAv?.get(month);
};
},
CategoryGroupsForMonth(state) {
@ -210,7 +205,7 @@ export const useAccountStore = defineStore("budget/account", {
response.Categories.length <= 0
)
return;
this.addCategoriesForMonth(year, month, response.Categories);
this.addCategoriesForMonth(year, month, response.Categories, response.AvailableBalance);
},
async EditAccount(
accountid: string,
@ -236,7 +231,8 @@ export const useAccountStore = defineStore("budget/account", {
addCategoriesForMonth(
year: number,
month: number,
categories: Category[]
categories: Category[],
available: number
): void {
this.$patch((state) => {
const yearMap =
@ -250,6 +246,12 @@ 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);
});
},
logout() {