Extract NewCategoryWithBalance
This commit is contained in:
parent
c3175b9be6
commit
fffc91269e
@ -30,6 +30,16 @@ type CategoryWithBalance struct {
|
||||
Assigned postgres.Numeric
|
||||
}
|
||||
|
||||
func NewCategoryWithBalance(category *postgres.GetCategoriesRow) CategoryWithBalance {
|
||||
return CategoryWithBalance{
|
||||
GetCategoriesRow: category,
|
||||
Available: postgres.NewZeroNumeric(),
|
||||
AvailableLastMonth: postgres.NewZeroNumeric(),
|
||||
Activity: postgres.NewZeroNumeric(),
|
||||
Assigned: postgres.NewZeroNumeric(),
|
||||
}
|
||||
}
|
||||
|
||||
func getDate(c *gin.Context) (time.Time, error) {
|
||||
var year, month int
|
||||
yearString := c.Param("year")
|
||||
@ -153,16 +163,10 @@ func (h *Handler) calculateBalances(budget postgres.Budget,
|
||||
firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow,
|
||||
cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, postgres.Numeric) {
|
||||
categoriesWithBalance := []CategoryWithBalance{}
|
||||
hiddenCategory := CategoryWithBalance{
|
||||
GetCategoriesRow: &postgres.GetCategoriesRow{
|
||||
hiddenCategory := NewCategoryWithBalance(&postgres.GetCategoriesRow{
|
||||
Name: "",
|
||||
Group: "Hidden Categories",
|
||||
},
|
||||
Available: postgres.NewZeroNumeric(),
|
||||
AvailableLastMonth: postgres.NewZeroNumeric(),
|
||||
Activity: postgres.NewZeroNumeric(),
|
||||
Assigned: postgres.NewZeroNumeric(),
|
||||
}
|
||||
})
|
||||
|
||||
moneyUsed := postgres.NewZeroNumeric()
|
||||
for i := range categories {
|
||||
@ -194,13 +198,7 @@ func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
||||
cumultativeBalances []postgres.GetCumultativeBalancesRow, firstOfNextMonth time.Time,
|
||||
moneyUsed *postgres.Numeric, firstOfMonth time.Time, hiddenCategory CategoryWithBalance,
|
||||
budget postgres.Budget) CategoryWithBalance {
|
||||
categoryWithBalance := CategoryWithBalance{
|
||||
GetCategoriesRow: cat,
|
||||
Available: postgres.NewZeroNumeric(),
|
||||
AvailableLastMonth: postgres.NewZeroNumeric(),
|
||||
Activity: postgres.NewZeroNumeric(),
|
||||
Assigned: postgres.NewZeroNumeric(),
|
||||
}
|
||||
categoryWithBalance := NewCategoryWithBalance(cat)
|
||||
for _, bal := range cumultativeBalances {
|
||||
if bal.CategoryID != cat.ID {
|
||||
continue
|
||||
|
Loading…
x
Reference in New Issue
Block a user