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