Split activity into income and spending
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Jan Bader 2022-04-08 18:56:36 +00:00
parent c4fc80e47d
commit 08f48a63ad
2 changed files with 25 additions and 15 deletions

View File

@ -72,28 +72,33 @@ function assignedChanged(e : Event, category : Category){
POST("/budget/"+CurrentBudgetID.value+"/category/" + category.ID + "/" + selected.value.Year + "/" + (selected.value.Month+1), POST("/budget/"+CurrentBudgetID.value+"/category/" + category.ID + "/" + selected.value.Year + "/" + (selected.value.Month+1),
JSON.stringify({Assigned: category.Assigned})); JSON.stringify({Assigned: category.Assigned}));
} }
const budgeted = computed(() => accountStore.GetBudgeted(selected.value.Year, selected.value.Month))
</script> </script>
<template> <template>
<h1>Budget for {{ selected.Month + 1 }}/{{ selected.Year }}</h1> <h1>Budget for {{ selected.Month + 1 }}/{{ selected.Year }}</h1>
<span>
Available last month:
<Currency
:value="accountStore.GetIncomeAvailable(previous.Year, previous.Month)"
/>
</span><br />
<span>Available balance: <span>Available balance:
<Currency <Currency
:value="accountStore.GetIncomeAvailable(selected.Year, selected.Month)" :value="accountStore.GetIncomeAvailable(selected.Year, selected.Month)"
/> />
</span><br /> </span><br />
<span>Budgeted this month: <span>Budgeted this month:
<Currency <Currency :value="budgeted.Assigned"/> - <Currency :value="-budgeted.Deassigned"/> = <Currency :value="budgeted.Assigned+budgeted.Deassigned" />
:value="accountStore.GetBudgeted(selected.Year, selected.Month).Assigned"
/>
</span><br /> </span><br />
<span>Deassigned this month: <span>Income:
<Currency <Currency
:value="accountStore.GetBudgeted(selected.Year, selected.Month).Deassigned" :value="budgeted.Income"
/> /> <Currency
</span><br /> :value="budgeted.Spent"
<span>Spent this month: /> = <Currency
<Currency :value="budgeted.Income + budgeted.Spent"
:value="accountStore.GetBudgeted(selected.Year, selected.Month).Activity"
/> />
</span><br /> </span><br />
<div> <div>

View File

@ -42,7 +42,8 @@ export interface Category {
interface BudgetedAmounts { interface BudgetedAmounts {
Assigned: number, Assigned: number,
Deassigned: number, Deassigned: number,
Activity: number, Spent: number,
Income: number,
} }
export const useAccountStore = defineStore("budget/account", { export const useAccountStore = defineStore("budget/account", {
@ -79,17 +80,20 @@ export const useAccountStore = defineStore("budget/account", {
GetBudgeted(state) { GetBudgeted(state) {
return (year: number, month: number) : BudgetedAmounts => { return (year: number, month: number) : BudgetedAmounts => {
const IncomeCategoryID = this.GetIncomeCategoryID; const IncomeCategoryID = this.GetIncomeCategoryID;
if (IncomeCategoryID == null) return {Activity: 0, Assigned: 0, Deassigned: 0}; if (IncomeCategoryID == null) return {Spent: 0, Income: 0, Assigned: 0, Deassigned: 0};
const categories = this.AllCategoriesForMonth(year, month); const categories = this.AllCategoriesForMonth(year, month);
let assigned = 0, deassigned = 0; let assigned = 0, deassigned = 0;
let activity = 0; let spent = 0, income = 0;
for (const category of categories) { for (const category of categories) {
if (category.ID == IncomeCategoryID) if (category.ID == IncomeCategoryID)
continue; continue;
activity += category.Activity; if(category.Activity > 0)
income += category.Activity;
else
spent += category.Activity;
if(category.Assigned > 0) if(category.Assigned > 0)
assigned += category.Assigned; assigned += category.Assigned;
else else
@ -98,7 +102,8 @@ export const useAccountStore = defineStore("budget/account", {
return { return {
Assigned: assigned, Assigned: assigned,
Deassigned: deassigned, Deassigned: deassigned,
Activity: activity Spent: spent,
Income: income
}; };
}; };
}, },