From b8c83b2d2da1686ca4cdc2e488760eaae91c3279 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Wed, 28 Feb 2024 10:44:53 +0100 Subject: [PATCH] add card only revenue --- internal/booking/service.go | 40 +++++++++++++++-------- internal/server/handle_reports.go | 1 + internal/views/report_section.templ | 14 +++++++- internal/views/report_section_templ.go | 44 +++++++++++++++++--------- 4 files changed, 70 insertions(+), 29 deletions(-) diff --git a/internal/booking/service.go b/internal/booking/service.go index 01774f6..387c132 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -62,11 +62,12 @@ func (bs Service) CreateItem(bid int, item string, qty int, price float64, metho } type Report struct { + Lines []*Line Total float64 PlatformFees float64 Fee float64 Profit float64 - Lines []*Line + CardTotal float64 } type Line struct { @@ -109,25 +110,38 @@ func (bs Service) BuildReport(period string, month, year int) *Report { endDate = time.Date(year, time.December, 31, 0, 0, 0, 0, time.UTC) } - bs.db. - Raw(` - select id, customer_name, "from", "to", platform, total, platform_fees - from (select sum(price*quantity) 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")). + bs.db.Raw(` + select id, customer_name, "from", "to", platform, total, platform_fees + from (select sum(price*quantity) 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(&lines) + cardTotal := 0.0 + bs.db.Raw(` + select sum(total) + from (select sum(price * quantity) as total + from bookings + join items on bookings.id = items.booking_id + where "from" between ? and ? + and payment_method = 'Card' + group by booking_id); + `, + startDate.Format("2006-01-02"), endDate.Format("2006-01-02")). + Scan(&cardTotal) + return &Report{ Total: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.Total }, 0.0), PlatformFees: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.PlatformFees }, 0.0), Fee: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.Fee() }, 0.0), Profit: u.Reduce(lines, func(l *Line, sum float64) float64 { return sum + l.Profit() }, 0.0), Lines: lines, + CardTotal: cardTotal, } } diff --git a/internal/server/handle_reports.go b/internal/server/handle_reports.go index 26128f8..fd3463b 100644 --- a/internal/server/handle_reports.go +++ b/internal/server/handle_reports.go @@ -72,6 +72,7 @@ func handleComputeReport(bs *booking.Service, hc *config.Host) echo.HandlerFunc PlatformFees: strconv.FormatFloat(r.PlatformFees, 'f', 2, 64), Fee: strconv.FormatFloat(r.Fee, 'f', 2, 64), Profit: strconv.FormatFloat(r.Profit, 'f', 2, 64), + CardTotal: strconv.FormatFloat(r.CardTotal, 'f', 2, 64), Lines: u.Map(r.Lines, func(l *booking.Line) *views.ReportLine { return &views.ReportLine{ Id: l.InvoiceNumber(hc), diff --git a/internal/views/report_section.templ b/internal/views/report_section.templ index 4930cd8..bbd9a29 100644 --- a/internal/views/report_section.templ +++ b/internal/views/report_section.templ @@ -2,6 +2,7 @@ package views type ReportViewModel struct { Total string + CardTotal string PlatformFees string Fee string Profit string @@ -36,7 +37,7 @@ templ ReportSection(report *ReportViewModel) { Name From To - Total (€) + Revenue (€) Platform Platform Fees (€) Fees (€) @@ -74,6 +75,17 @@ templ ReportSection(report *ReportViewModel) { { report.Fee } { report.Profit } + + + + + Card-only: + { report.CardTotal } + + + + + diff --git a/internal/views/report_section_templ.go b/internal/views/report_section_templ.go index 96b93ed..279ae45 100644 --- a/internal/views/report_section_templ.go +++ b/internal/views/report_section_templ.go @@ -12,6 +12,7 @@ import "bytes" type ReportViewModel struct { Total string + CardTotal string PlatformFees string Fee string Profit string @@ -44,7 +45,7 @@ func ReportSection(report *ReportViewModel) templ.Component { templ_7745c5c3_Var1 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Your report

") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Your report

IDNameFromToTotal (€)PlatformPlatform Fees (€)Fees (€)Profit (€)
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -65,7 +66,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 50, Col: 16} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 51, Col: 16} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -78,7 +79,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 53, Col: 28} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 54, Col: 28} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -91,7 +92,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 54, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 55, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) if templ_7745c5c3_Err != nil { @@ -104,7 +105,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 55, Col: 18} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 56, Col: 18} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -117,7 +118,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 56, Col: 21} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 57, Col: 21} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -130,7 +131,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 57, Col: 24} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 58, Col: 24} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { @@ -143,7 +144,7 @@ func ReportSection(report *ReportViewModel) templ.Component { 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: 58, Col: 28} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 59, Col: 28} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { @@ -156,7 +157,7 @@ func ReportSection(report *ReportViewModel) templ.Component { var templ_7745c5c3_Var10 string templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(row.Fee) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 59, Col: 19} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 60, Col: 19} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) if templ_7745c5c3_Err != nil { @@ -169,7 +170,7 @@ func ReportSection(report *ReportViewModel) templ.Component { var templ_7745c5c3_Var11 string templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(row.Profit) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 60, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 61, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { @@ -187,7 +188,7 @@ func ReportSection(report *ReportViewModel) templ.Component { var templ_7745c5c3_Var12 string templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(report.Total) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 70, Col: 23} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 71, Col: 23} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) if templ_7745c5c3_Err != nil { @@ -200,7 +201,7 @@ func ReportSection(report *ReportViewModel) templ.Component { var templ_7745c5c3_Var13 string templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(report.PlatformFees) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 72, Col: 30} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 73, Col: 30} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil { @@ -213,7 +214,7 @@ func ReportSection(report *ReportViewModel) templ.Component { var templ_7745c5c3_Var14 string templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(report.Fee) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 73, Col: 21} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 74, Col: 21} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) if templ_7745c5c3_Err != nil { @@ -226,13 +227,26 @@ func ReportSection(report *ReportViewModel) templ.Component { var templ_7745c5c3_Var15 string templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(report.Profit) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 74, Col: 24} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 75, Col: 24} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
IDNameFromToRevenue (€)PlatformPlatform Fees (€)Fees (€)Profit (€)
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Card-only: ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var16 string + templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(report.CardTotal) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/views/report_section.templ`, Line: 82, Col: 27} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) + 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 }