From 8c9886991e46d3c0b147bf74054e528f59d97ec3 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Mon, 26 Feb 2024 17:28:55 +0100 Subject: [PATCH] fix booking total in report preview --- internal/booking/service.go | 2 +- internal/server/handle_reports.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/booking/service.go b/internal/booking/service.go index a77b112..7cb0bd0 100644 --- a/internal/booking/service.go +++ b/internal/booking/service.go @@ -88,7 +88,7 @@ func (bs Service) BuildReport(period string, month, year int) []*Line { bs.db. Raw(` select id, customer_name, "from", "to", platform, total, platform_fees - from (select sum(price) as total, booking_id + from (select sum(price*quantity) as total, booking_id from bookings join items on bookings.id = items.booking_id where "from" between ? and ? diff --git a/internal/server/handle_reports.go b/internal/server/handle_reports.go index fd620d5..e3ecbc1 100644 --- a/internal/server/handle_reports.go +++ b/internal/server/handle_reports.go @@ -2,6 +2,7 @@ package server import ( "fmt" + "log" "net/http" "strconv" "time" @@ -68,10 +69,10 @@ func handleComputeReport(bs *booking.Service, hc *config.Host) echo.HandlerFunc res := bs.BuildReport(period, month, year) reportVm := u.Map(res, func(r *booking.Line) *views.ReportViewModel { + log.Printf("%+v", r) return &views.ReportViewModel{ - Id: r.InvoiceNumber(hc), - Url: templ.SafeURL(fmt.Sprintf("%s/%s", constants.RouteBooking, r.Id)), - // TODO: return the full invoice amount including lines + Id: r.InvoiceNumber(hc), + 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"),