-
Notifications
You must be signed in to change notification settings - Fork 12
/
console_report.go
49 lines (39 loc) · 1.5 KB
/
console_report.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
package report
import (
"fmt"
"time"
)
type consoleReport struct {
currency string
}
const (
blankLine = ""
separator = " -------------------------------------------------------------------------------------------------------------------------------"
rowFormat = "| %-25s || %7v | %7v | %12v | %13v | %13v | %18v | %8v |"
)
func NewConsoleReport(currency string) Writer {
return &consoleReport{
currency: currency,
}
}
func (r *consoleReport) GenerateReport(data *PrintableData) (string, error) {
fmt.Println(separator)
fmt.Println(fmt.Sprintf("| Generating report(s) from '%s' to '%s'", data.Start.Format("Mon Jan _2 15:04:05 2006"), data.End.Add(time.Second*-1).Format("Mon Jan _2 15:04:05 2006")))
fmt.Println(separator)
for _, scheduleData := range data.SchedulesData {
fmt.Println(blankLine)
fmt.Println(separator)
fmt.Println(fmt.Sprintf("| Schedule: '%s' (%s)", scheduleData.Name, scheduleData.ID))
fmt.Println(separator)
fmt.Println(fmt.Sprintf(rowFormat, "USER", "WEEKDAY", "WEEKEND", "BANK HOLIDAY", "TOTAL WEEKDAY", "TOTAL WEEKEND", "TOTAL BANK HOLIDAY", "TOTAL"))
fmt.Println(separator)
for _, userData := range scheduleData.RotaUsers {
fmt.Println(fmt.Sprintf(rowFormat, userData.Name,
userData.NumWorkDays, userData.NumWeekendDays, userData.NumBankHolidaysDays,
userData.TotalAmountWorkDays, userData.TotalAmountWeekendDays, userData.TotalAmountBankHolidaysDays,
fmt.Sprintf("%s%d", r.currency, userData.TotalAmount)))
}
}
fmt.Println(separator)
return "", nil
}