Budget for {{ selected.Month + 1 }}/{{ selected.Year }}
+
+ Available last month:
+
+
Available balance:
+ />
+
+ Budgeted this month:
+ - =
+
+ Income:
+ =
+
(undefined);
const assignmentsFile = ref(undefined);
@@ -39,7 +41,7 @@ function deleteBudget() {
const budgetStore = useSessionStore();
budgetStore.Budgets.delete(CurrentBudgetID.value);
- useRouter().push("/")
+ router.push("/dashboard")
};
function clearBudget() {
POST("/budget/" + CurrentBudgetID.value + "/settings/clear", null)
diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts
index d5b2c30..0259e80 100644
--- a/web/src/stores/budget-account.ts
+++ b/web/src/stores/budget-account.ts
@@ -9,6 +9,7 @@ interface State {
CurrentAccountID: string | null;
Categories: Map;
Months: Map>>;
+ Available: Map>;
Assignments: [];
}
@@ -38,11 +39,19 @@ export interface Category {
Activity: number;
}
+interface BudgetedAmounts {
+ Assigned: number,
+ Deassigned: number,
+ Spent: number,
+ Income: number,
+}
+
export const useAccountStore = defineStore("budget/account", {
state: (): State => ({
Accounts: new Map(),
CurrentAccountID: null,
Months: new Map>>(),
+ Available: new Map>(),
Categories: new Map(),
Assignments: [],
}),
@@ -59,7 +68,7 @@ export const useAccountStore = defineStore("budget/account", {
return (category: Category): number => {
return (
category.AvailableLastMonth +
- Number(category.Assigned) +
+ category.Assigned +
category.Activity
);
};
@@ -68,17 +77,40 @@ export const useAccountStore = defineStore("budget/account", {
const budget = useBudgetsStore();
return budget.CurrentBudget?.IncomeCategoryID;
},
- GetIncomeAvailable(state) {
- return (year: number, month: number) => {
+ GetBudgeted(state) {
+ return (year: number, month: number) : BudgetedAmounts => {
const IncomeCategoryID = this.GetIncomeCategoryID;
- if (IncomeCategoryID == null) return 0;
+ if (IncomeCategoryID == null) return {Spent: 0, Income: 0, Assigned: 0, Deassigned: 0};
const categories = this.AllCategoriesForMonth(year, month);
- const category = categories.filter(
- (x) => x.ID == IncomeCategoryID
- )[0];
- if (category == null) return 0;
- return category.AvailableLastMonth;
+
+ let assigned = 0, deassigned = 0;
+ let spent = 0, income = 0;
+ for (const category of categories) {
+ if (category.ID == IncomeCategoryID)
+ continue;
+
+ if(category.Activity > 0)
+ income += category.Activity;
+ else
+ spent += category.Activity;
+ if(category.Assigned > 0)
+ assigned += category.Assigned;
+ else
+ deassigned += category.Assigned;
+ }
+ return {
+ Assigned: assigned,
+ Deassigned: deassigned,
+ Spent: spent,
+ Income: income
+ };
+ };
+ },
+ GetIncomeAvailable(state) {
+ return (year: number, month: number) => {
+ const yearMapAv = this.Available.get(year);
+ return yearMapAv?.get(month);
};
},
CategoryGroupsForMonth(state) {
@@ -87,7 +119,7 @@ export const useAccountStore = defineStore("budget/account", {
const categoryGroups = [];
let prev = undefined;
for (const category of categories) {
- if (category.ID == this.GetIncomeCategoryID) continue;
+ //if (category.ID == this.GetIncomeCategoryID) continue;
if (prev == undefined || category.Group != prev.Name) {
prev = {
@@ -184,7 +216,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,
@@ -210,7 +242,8 @@ export const useAccountStore = defineStore("budget/account", {
addCategoriesForMonth(
year: number,
month: number,
- categories: Category[]
+ categories: Category[],
+ available: number
): void {
this.$patch((state) => {
const yearMap =
@@ -224,6 +257,12 @@ export const useAccountStore = defineStore("budget/account", {
yearMap.set(month, monthMap);
state.Months.set(year, yearMap);
+
+ const yearMapAv =
+ state.Available.get(year) ||
+ new Map();
+ yearMapAv.set(month, available);
+ state.Available.set(year, yearMapAv);
});
},
logout() {