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