Split activity into income and spending
This commit is contained in:
parent
c4fc80e47d
commit
08f48a63ad
@ -72,28 +72,33 @@ function assignedChanged(e : Event, category : Category){
|
||||
POST("/budget/"+CurrentBudgetID.value+"/category/" + category.ID + "/" + selected.value.Year + "/" + (selected.value.Month+1),
|
||||
JSON.stringify({Assigned: category.Assigned}));
|
||||
}
|
||||
|
||||
const budgeted = computed(() => accountStore.GetBudgeted(selected.value.Year, selected.value.Month))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<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:
|
||||
<Currency
|
||||
:value="accountStore.GetIncomeAvailable(selected.Year, selected.Month)"
|
||||
/>
|
||||
</span><br />
|
||||
<span>Budgeted this month:
|
||||
<Currency
|
||||
:value="accountStore.GetBudgeted(selected.Year, selected.Month).Assigned"
|
||||
/>
|
||||
<Currency :value="budgeted.Assigned"/> - <Currency :value="-budgeted.Deassigned"/> = <Currency :value="budgeted.Assigned+budgeted.Deassigned" />
|
||||
</span><br />
|
||||
<span>Deassigned this month:
|
||||
<span>Income:
|
||||
<Currency
|
||||
:value="accountStore.GetBudgeted(selected.Year, selected.Month).Deassigned"
|
||||
/>
|
||||
</span><br />
|
||||
<span>Spent this month:
|
||||
<Currency
|
||||
:value="accountStore.GetBudgeted(selected.Year, selected.Month).Activity"
|
||||
:value="budgeted.Income"
|
||||
/> <Currency
|
||||
:value="budgeted.Spent"
|
||||
/> = <Currency
|
||||
:value="budgeted.Income + budgeted.Spent"
|
||||
/>
|
||||
</span><br />
|
||||
<div>
|
||||
|
@ -42,7 +42,8 @@ export interface Category {
|
||||
interface BudgetedAmounts {
|
||||
Assigned: number,
|
||||
Deassigned: number,
|
||||
Activity: number,
|
||||
Spent: number,
|
||||
Income: number,
|
||||
}
|
||||
|
||||
export const useAccountStore = defineStore("budget/account", {
|
||||
@ -79,17 +80,20 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
GetBudgeted(state) {
|
||||
return (year: number, month: number) : BudgetedAmounts => {
|
||||
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);
|
||||
|
||||
let assigned = 0, deassigned = 0;
|
||||
let activity = 0;
|
||||
let spent = 0, income = 0;
|
||||
for (const category of categories) {
|
||||
if (category.ID == IncomeCategoryID)
|
||||
continue;
|
||||
|
||||
activity += category.Activity;
|
||||
if(category.Activity > 0)
|
||||
income += category.Activity;
|
||||
else
|
||||
spent += category.Activity;
|
||||
if(category.Assigned > 0)
|
||||
assigned += category.Assigned;
|
||||
else
|
||||
@ -98,7 +102,8 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
return {
|
||||
Assigned: assigned,
|
||||
Deassigned: deassigned,
|
||||
Activity: activity
|
||||
Spent: spent,
|
||||
Income: income
|
||||
};
|
||||
};
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user