diff --git a/internal/server/handlers.go b/internal/server/handlers.go
index 5511dc3..e387645 100644
--- a/internal/server/handlers.go
+++ b/internal/server/handlers.go
@@ -191,18 +191,54 @@ func (s Server) handleComputeReport() echo.HandlerFunc {
}
}
- // TODO: compute report view model
- // fetch bookings with From started this month, or year
- bs := make([]*booking.Booking, 0)
+ type Result struct {
+ Id string
+ Total float64
+ CustomerName string
+ From time.Time
+ To time.Time
+ Platform string
+ PlatformFees float64
+ }
+ res := make([]*Result, 0)
var startDate time.Time
var endDate time.Time
+
if period == "month" {
startDate = time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC)
endDate = time.Date(year, time.Month(month), 31, 0, 0, 0, 0, time.UTC)
+ } else {
+ startDate = time.Date(year, time.January, 1, 0, 0, 0, 0, time.UTC)
+ endDate = time.Date(year, time.December, 31, 0, 0, 0, 0, time.UTC)
}
- _ = s.db.Where("\"from\" BETWEEN ? AND ?", startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).Find(&bs)
- return s.renderTempl(c, http.StatusOK, views.ReportSection())
+ s.db.
+ Raw(`
+ select id, customer_name, "from", "to", platform, total, platform_fees
+ from (select sum(price) as total, booking_id
+ from bookings
+ join items on bookings.id = items.booking_id
+ where "from" between ? and ?
+ group by booking_id) as sbi,
+ (select * from bookings) as b
+ where sbi.booking_id = b.id;
+ `,
+ startDate.Format("2006-01-02"), endDate.Format("2006-01-02")).
+ Scan(&res)
+
+ reportVm := u.Map(res, func(r *Result) *views.ReportViewModel {
+ return &views.ReportViewModel{
+ Id: r.Id,
+ Url: templ.SafeURL(fmt.Sprintf("%s/%s", constants.RouteBooking, r.Id)),
+ Total: strconv.FormatFloat(r.Total, 'f', 2, 64),
+ CustomerName: r.CustomerName,
+ From: r.From.Format("2006-01-02"),
+ To: r.To.Format("2006-01-02"),
+ Platform: r.Platform,
+ PlatformFees: strconv.FormatFloat(r.PlatformFees, 'f', 2, 64),
+ }
+ })
+ return s.renderTempl(c, http.StatusOK, views.ReportSection(reportVm))
}
}
diff --git a/internal/views/report_section.templ b/internal/views/report_section.templ
index ccc6269..97d6832 100644
--- a/internal/views/report_section.templ
+++ b/internal/views/report_section.templ
@@ -1,6 +1,17 @@
package views
-templ ReportSection() {
+type ReportViewModel struct {
+ Id string
+ Url templ.SafeURL
+ Total string
+ CustomerName string
+ From string
+ To string
+ Platform string
+ PlatformFees string
+}
+
+templ ReportSection(report []*ReportViewModel) {
Your report
@@ -13,25 +24,29 @@ templ ReportSection() {
| ID |
Name |
- Total (€) |
From |
To |
+ Total (€) |
Platform |
+ Platform Fees |
-
- |
-
- 12
-
- |
- joe |
- |
- fgsdkjf |
- jjxlkvj |
- jjxlkvj |
-
+ for _, row := range report {
+
+ |
+
+ { row.Id }
+
+ |
+ { row.CustomerName } |
+ { row.From } |
+ { row.To } |
+ { row.Total } |
+ { row.Platform } |
+ { row.PlatformFees } |
+
+ }
diff --git a/internal/views/report_section_templ.go b/internal/views/report_section_templ.go
index 24c6ff8..e6de19e 100644
--- a/internal/views/report_section_templ.go
+++ b/internal/views/report_section_templ.go
@@ -10,7 +10,18 @@ import "context"
import "io"
import "bytes"
-func ReportSection() templ.Component {
+type ReportViewModel struct {
+ Id string
+ Url templ.SafeURL
+ Total string
+ CustomerName string
+ From string
+ To string
+ Platform string
+ PlatformFees string
+}
+
+func ReportSection(report []*ReportViewModel) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@@ -23,7 +34,117 @@ func ReportSection() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
| ID | Name | Total (€) | From | To | Platform |
| 12 | joe | | fgsdkjf | jjxlkvj | jjxlkvj |
|---|
")
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
| ID | Name | From | To | Total (€) | Platform | Platform Fees |
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, row := range report {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("| ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var3 string
+ templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(row.Id)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 38, Col: 16}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var4 string
+ templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(row.CustomerName)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 41, Col: 28}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var5 string
+ templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(row.From)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 42, Col: 20}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var6 string
+ templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(row.To)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 43, Col: 18}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var7 string
+ templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(row.Total)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 44, Col: 21}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var8 string
+ templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(row.Platform)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 45, Col: 24}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var9 string
+ templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(row.PlatformFees)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 46, Col: 28}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" |
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}