Move logic for hidden categories to client

This commit is contained in:
Jan Bader 2022-02-23 13:42:33 +00:00
parent 674bef667b
commit f93888cbbc
3 changed files with 34 additions and 18 deletions

View File

@ -163,24 +163,13 @@ func (h *Handler) calculateBalances(budget postgres.Budget,
firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow, firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow,
cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, postgres.Numeric) { cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, postgres.Numeric) {
categoriesWithBalance := []CategoryWithBalance{} categoriesWithBalance := []CategoryWithBalance{}
hiddenCategory := NewCategoryWithBalance(&postgres.GetCategoriesRow{
Name: "",
Group: "Hidden Categories",
})
moneyUsed := postgres.NewZeroNumeric() moneyUsed := postgres.NewZeroNumeric()
for i := range categories { for i := range categories {
cat := &categories[i] cat := &categories[i]
// do not show hidden categories // do not show hidden categories
categoryWithBalance := h.CalculateCategoryBalances(cat, cumultativeBalances, categoryWithBalance := h.CalculateCategoryBalances(cat, cumultativeBalances,
firstOfNextMonth, &moneyUsed, firstOfMonth, hiddenCategory, budget) firstOfNextMonth, &moneyUsed, firstOfMonth, budget)
if cat.Group == "Hidden Categories" {
hiddenCategory.Available = hiddenCategory.Available.Add(categoryWithBalance.Available)
hiddenCategory.AvailableLastMonth = hiddenCategory.AvailableLastMonth.Add(categoryWithBalance.AvailableLastMonth)
hiddenCategory.Activity = hiddenCategory.Activity.Add(categoryWithBalance.Activity)
hiddenCategory.Assigned = hiddenCategory.Assigned.Add(categoryWithBalance.Assigned)
continue
}
if cat.ID == budget.IncomeCategoryID { if cat.ID == budget.IncomeCategoryID {
continue continue
@ -189,15 +178,12 @@ func (h *Handler) calculateBalances(budget postgres.Budget,
categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance) categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance)
} }
categoriesWithBalance = append(categoriesWithBalance, hiddenCategory)
return categoriesWithBalance, moneyUsed return categoriesWithBalance, moneyUsed
} }
func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow, func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
cumultativeBalances []postgres.GetCumultativeBalancesRow, firstOfNextMonth time.Time, cumultativeBalances []postgres.GetCumultativeBalancesRow, firstOfNextMonth time.Time,
moneyUsed *postgres.Numeric, firstOfMonth time.Time, hiddenCategory CategoryWithBalance, moneyUsed *postgres.Numeric, firstOfMonth time.Time, budget postgres.Budget) CategoryWithBalance {
budget postgres.Budget) CategoryWithBalance {
categoryWithBalance := NewCategoryWithBalance(cat) categoryWithBalance := NewCategoryWithBalance(cat)
for _, bal := range cumultativeBalances { for _, bal := range cumultativeBalances {
if bal.CategoryID != cat.ID { if bal.CategoryID != cat.ID {

View File

@ -14,10 +14,16 @@ const props = defineProps<{
const budgetsStore = useBudgetsStore(); const budgetsStore = useBudgetsStore();
const CurrentBudgetID = computed(() => budgetsStore.CurrentBudgetID); const CurrentBudgetID = computed(() => budgetsStore.CurrentBudgetID);
const categoriesForMonth = useAccountStore().CategoriesForMonth; const accountStore = useAccountStore();
const categoriesForMonth = accountStore.CategoriesForMonth;
const Categories = computed(() => { const Categories = computed(() => {
return [...categoriesForMonth(selected.value.Year, selected.value.Month)]; return [...categoriesForMonth(selected.value.Year, selected.value.Month)];
}); });
const hiddenCategoriesForMonth = accountStore.HiddenCategoriesForMonth;
const HiddenCategories = computed(() => {
return [...hiddenCategoriesForMonth(selected.value.Year, selected.value.Month)];
});
const previous = computed(() => ({ const previous = computed(() => ({
Year: new Date(selected.value.Year, selected.value.Month - 1, 1).getFullYear(), Year: new Date(selected.value.Year, selected.value.Month - 1, 1).getFullYear(),
@ -88,5 +94,23 @@ onMounted(() => {
<Currency :value="category.Available" /> <Currency :value="category.Available" />
</td> </td>
</tr> </tr>
<tr v-for="category in HiddenCategories">
<td>{{ category.Group }}</td>
<td>{{ category.Name }}</td>
<td></td>
<td></td>
<td class="text-right">
<Currency :value="category.AvailableLastMonth" />
</td>
<td class="text-right">
<Currency :value="category.Assigned" />
</td>
<td class="text-right">
<Currency :value="category.Activity" />
</td>
<td class="text-right">
<Currency :value="category.Available" />
</td>
</tr>
</table> </table>
</template> </template>

View File

@ -58,7 +58,13 @@ export const useAccountStore = defineStore("budget/account", {
const yearMap = state.Months.get(year); const yearMap = state.Months.get(year);
const monthMap = yearMap?.get(month); const monthMap = yearMap?.get(month);
console.log("MTH", monthMap) console.log("MTH", monthMap)
return [...monthMap?.values() || []]; return [...monthMap?.values() || []].filter(x => x.Group != "Hidden Categories");
},
HiddenCategoriesForMonth: (state) => (year: number, month: number) => {
const yearMap = state.Months.get(year);
const monthMap = yearMap?.get(month);
console.log("MTH", monthMap)
return [...monthMap?.values() || []].filter(x => x.Group == "Hidden Categories");
}, },
CurrentAccount(state): Account | undefined { CurrentAccount(state): Account | undefined {
if (state.CurrentAccountID == null) if (state.CurrentAccountID == null)