-
Notifications
You must be signed in to change notification settings - Fork 0
/
showInAndOut.go
69 lines (53 loc) · 1.66 KB
/
showInAndOut.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"net/http"
"time"
log "github.com/Sirupsen/logrus"
)
func showInAndOut(w http.ResponseWriter, r *http.Request) {
log.Info("In the showInAndOut")
t := time.Now()
yearNow := t.Year()
monthNow := t.Month()
// --------- To make needed category lists ---------
// To make the catogory lists for the expenses overview table
allCatNames := make([]string, 0)
allCatNames = categoryNames()
// To make the catogory lists for the filtering expenses table
catNames := catNames
subCatNames := make([]string, 0)
subCatNames = append(subCatNames, catNamesFood...)
subCatNames = append(subCatNames, catNamesRegular...)
subCatNames = append(subCatNames, catNamesIrregular...)
// --------- To filter Income for this year and months ---------
tmpIncome := make([]entries, 0)
for _, val := range income {
monthEntry := val.EntryDate.Month()
yearEntry := val.EntryDate.Year()
if monthNow == monthEntry && yearNow == yearEntry {
tmpIncome = append(tmpIncome, val)
}
}
// --------- To filter Expenses for this year and months ---------
tmpExpenses := make([]entries, 0)
for _, val := range expenses {
monthEntry := val.EntryDate.Month()
yearEntry := val.EntryDate.Year()
if monthNow == monthEntry && yearNow == yearEntry {
tmpExpenses = append(tmpExpenses, val)
}
}
//
catSumCalc := catSumNowMonth(tmpExpenses, allCatNames)
money := map[string]interface{}{
"YearNow": yearNow,
"MonthNow": monthNow,
"Income": tmpIncome,
"Expenses": tmpExpenses,
"CatNames": catNames,
"SubCatNames": subCatNames,
"AllCatNames": allCatNames,
"CatSumCalc": catSumCalc,
}
render(w, r, tpl, "showInAndOut.html", money)
}