Clean up: remove unused packages, switch to slog, tidy Makefile

This commit is contained in:
2026-06-23 22:34:01 +03:30
parent 32446a99d1
commit b4fab29d45
7 changed files with 122 additions and 60 deletions

View File

@@ -46,6 +46,17 @@ func GenerateMonthlyReport(store *db.Store, year int, month time.Month) ([]byte,
},
Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
})
totalStyle, _ := f.NewStyle(&excelize.Style{
Font: &excelize.Font{Bold: true, Size: 11},
Fill: excelize.Fill{Type: "pattern", Pattern: 1, Color: []string{"D9E2F3"}},
Border: []excelize.Border{
{Type: "left", Color: "D9D9D9", Style: 1},
{Type: "right", Color: "D9D9D9", Style: 1},
{Type: "top", Color: "D9D9D9", Style: 1},
{Type: "bottom", Color: "D9D9D9", Style: 2},
},
Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
})
monthName := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC).Format("January 2006")
@@ -54,7 +65,7 @@ func GenerateMonthlyReport(store *db.Store, year int, month time.Month) ([]byte,
f.SetCellStyle(sheet, "A1", "E1", titleStyle)
f.SetRowHeight(sheet, 1, 30)
headers := []string{"Date", "Clock In", "Clock Out", "Work (h)", "Break (m)"}
headers := []string{"Date", "Clock In", "Clock Out", "Work", "Break"}
for i, h := range headers {
cell, _ := excelize.CoordinatesToCellName(i+1, 2)
f.SetCellValue(sheet, cell, h)
@@ -73,6 +84,8 @@ func GenerateMonthlyReport(store *db.Store, year int, month time.Month) ([]byte,
firstDay := time.Date(year, month, 1, 0, 0, 0, 0, loc)
lastDay := firstDay.AddDate(0, 1, -1)
var totalWork, totalBreak int64
for d := firstDay; !d.After(lastDay); d = d.AddDate(0, 0, 1) {
dateStr := d.Format("2006-01-02")
@@ -90,6 +103,9 @@ func GenerateMonthlyReport(store *db.Store, year int, month time.Month) ([]byte,
}
totals := ComputeDailyTotals(events)
totalWork += totals.TotalSeconds
totalBreak += totals.BreakSeconds
cellDate, _ := excelize.CoordinatesToCellName(1, row)
f.SetCellValue(sheet, cellDate, dateStr)
f.SetCellStyle(sheet, cellDate, cellDate, dataStyle)
@@ -99,28 +115,49 @@ func GenerateMonthlyReport(store *db.Store, year int, month time.Month) ([]byte,
cellOut, _ := excelize.CoordinatesToCellName(3, row)
f.SetCellValue(sheet, cellIn, time.Unix(events[0].OccurredAt, 0).Format("15:04"))
f.SetCellStyle(sheet, cellIn, cellIn, dataStyle)
if len(events) > 1 && events[len(events)-1].EventType == "out" {
if events[len(events)-1].EventType == "out" {
f.SetCellValue(sheet, cellOut, time.Unix(events[len(events)-1].OccurredAt, 0).Format("15:04"))
}
f.SetCellStyle(sheet, cellOut, cellOut, dataStyle)
}
cellWork, _ := excelize.CoordinatesToCellName(4, row)
hours := float64(totals.TotalSeconds) / 3600.0
f.SetCellValue(sheet, cellWork, fmt.Sprintf("%.2f", hours))
f.SetCellValue(sheet, cellWork, fmtHHMM(totals.TotalSeconds))
f.SetCellStyle(sheet, cellWork, cellWork, dataStyle)
cellBreak, _ := excelize.CoordinatesToCellName(5, row)
breakMin := totals.BreakSeconds / 60
f.SetCellValue(sheet, cellBreak, breakMin)
f.SetCellValue(sheet, cellBreak, fmtHHMM(totals.BreakSeconds))
f.SetCellStyle(sheet, cellBreak, cellBreak, dataStyle)
row++
}
row++
f.SetCellValue(sheet, fmt.Sprintf("A%d", row), "Total")
f.SetCellStyle(sheet, fmt.Sprintf("A%d", row), fmt.Sprintf("A%d", row), totalStyle)
f.SetCellValue(sheet, fmt.Sprintf("D%d", row), fmtDDHHMM(totalWork))
f.SetCellStyle(sheet, fmt.Sprintf("D%d", row), fmt.Sprintf("D%d", row), totalStyle)
f.SetCellValue(sheet, fmt.Sprintf("E%d", row), fmtDDHHMM(totalBreak))
f.SetCellStyle(sheet, fmt.Sprintf("E%d", row), fmt.Sprintf("E%d", row), totalStyle)
buf, err := f.WriteToBuffer()
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func fmtHHMM(seconds int64) string {
hours := seconds / 3600
mins := (seconds % 3600) / 60
return fmt.Sprintf("%d:%02d", hours, mins)
}
func fmtDDHHMM(seconds int64) string {
days := seconds / 86400
rem := seconds % 86400
hours := rem / 3600
mins := (rem % 3600) / 60
return fmt.Sprintf("%d:%02d:%02d", days, hours, mins)
}