Implement summing per category group
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2022-03-05 22:23:41 +00:00
parent 97de326527
commit b176ce26ba
2 changed files with 27 additions and 10 deletions

View File

@ -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);
}
},