feat: recurring transactions
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m36s
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m36s
This commit is contained in:
parent
f0a309ea20
commit
448b6f6262
16 changed files with 1956 additions and 4 deletions
57
internal/ui/pages/recurring_event_helpers.go
Normal file
57
internal/ui/pages/recurring_event_helpers.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.juancwu.dev/juancwu/budgit/internal/model"
|
||||
)
|
||||
|
||||
func accountLabel(ev *model.RecurringEvent, accountByID map[string]string) string {
|
||||
src := accountByID[ev.SourceAccountID]
|
||||
if src == "" {
|
||||
src = ev.SourceAccountID
|
||||
}
|
||||
return src
|
||||
}
|
||||
|
||||
var weekdayLabels = []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
|
||||
|
||||
func recurrenceSummary(ev *model.RecurringEvent) string {
|
||||
timePart := fmt.Sprintf(" at %02d:%02d", ev.FireHour, ev.FireMinute)
|
||||
switch ev.Frequency {
|
||||
case model.RecurringFrequencyDaily:
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Daily" + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d days%s", ev.IntervalCount, timePart)
|
||||
case model.RecurringFrequencyWeekly:
|
||||
dow := ""
|
||||
if ev.DayOfWeek != nil && *ev.DayOfWeek >= 0 && *ev.DayOfWeek < len(weekdayLabels) {
|
||||
dow = " on " + weekdayLabels[*ev.DayOfWeek]
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Weekly" + dow + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d weeks%s%s", ev.IntervalCount, dow, timePart)
|
||||
case model.RecurringFrequencyMonthly:
|
||||
dom := ""
|
||||
if ev.DayOfMonth != nil {
|
||||
dom = fmt.Sprintf(" on day %d", *ev.DayOfMonth)
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Monthly" + dom + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d months%s%s", ev.IntervalCount, dom, timePart)
|
||||
case model.RecurringFrequencyYearly:
|
||||
date := ""
|
||||
if ev.MonthOfYear != nil && ev.DayOfMonth != nil {
|
||||
date = fmt.Sprintf(" on %s %d", time.Month(*ev.MonthOfYear).String(), *ev.DayOfMonth)
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Yearly" + date + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d years%s%s", ev.IntervalCount, date, timePart)
|
||||
}
|
||||
return string(ev.Frequency)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue