summaryrefslogtreecommitdiff
path: root/internal/tui/commands.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-08-13 15:25:23 -0600
committerT <t@tjp.lol>2025-08-13 16:02:05 -0600
commite9e6eb4e456ee53da5a6ef743251410d4d3d8381 (patch)
treed722145a5f7a3dd07623e96045078983b3a14e4c /internal/tui/commands.go
parentd6781f3e5b431057c23b2deaa943f273699e37f5 (diff)
report generation modal
Diffstat (limited to 'internal/tui/commands.go')
-rw-r--r--internal/tui/commands.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/internal/tui/commands.go b/internal/tui/commands.go
index aa5cc79..9a836c5 100644
--- a/internal/tui/commands.go
+++ b/internal/tui/commands.go
@@ -2,8 +2,13 @@ package tui
import (
"context"
+ "fmt"
+ "strings"
+ "time"
"punchcard/internal/actions"
+ "punchcard/internal/queries"
+ "punchcard/internal/reports"
tea "github.com/charmbracelet/bubbletea"
)
@@ -22,6 +27,7 @@ type (
openCreateClientModal struct{}
openCreateProjectModal struct{}
openHistoryFilterModal struct{}
+ openReportModal struct{}
updateHistoryFilter HistoryFilter
)
@@ -113,3 +119,56 @@ func createProjectModal() tea.Cmd {
func createHistoryFilterModal() tea.Cmd {
return func() tea.Msg { return openHistoryFilterModal{} }
}
+
+func createReportModal() tea.Cmd {
+ return func() tea.Msg { return openReportModal{} }
+}
+
+func generateReport(m *ModalBoxModel, am AppModel) tea.Cmd {
+ return func() tea.Msg {
+ form := &m.form
+
+ dateRange, err := reports.ParseDateRange(form.fields[1].Value())
+ if err != nil {
+ form.fields[1].Err = fmt.Errorf("invalid date range: %v", err)
+ return reOpenModal()
+ }
+
+ var tz *time.Location
+ tzstr := form.fields[5].Value()
+ if tzstr == "" {
+ tz = time.Local
+ } else {
+ zone, err := time.LoadLocation(tzstr)
+ if err != nil {
+ form.fields[5].Err = err
+ return reOpenModal()
+ }
+ tz = zone
+ }
+
+ var genFunc func(context.Context, *queries.Queries, reports.ReportParams) (*reports.ReportResult, error)
+ switch strings.ToLower(form.fields[0].Value()) {
+ case "invoice":
+ genFunc = reports.GenerateInvoice
+ case "timesheet":
+ genFunc = reports.GenerateTimesheet
+ case "unified":
+ genFunc = reports.GenerateUnifiedReport
+ }
+
+ params := reports.ReportParams{
+ ClientName: form.fields[2].Value(),
+ ProjectName: form.fields[3].Value(),
+ DateRange: dateRange,
+ OutputPath: form.fields[4].Value(),
+ Timezone: tz,
+ }
+ if _, err := genFunc(context.Background(), am.queries, params); err != nil {
+ form.err = err
+ return reOpenModal()
+ }
+
+ return nil
+ }
+}