From 8235b67cd39a125b32ef8841f22004ec59883d8c Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sat, 22 Feb 2025 13:54:54 +0100 Subject: [PATCH] fix card calculation sql --- internal/repository/booking/pg_store.go | 12 ++++++------ internal/server/handle_pdf.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/repository/booking/pg_store.go b/internal/repository/booking/pg_store.go index 6e57c98..34cd746 100644 --- a/internal/repository/booking/pg_store.go +++ b/internal/repository/booking/pg_store.go @@ -65,14 +65,14 @@ func (ps *PgStore) List(from, to time.Time) ([]*booking.Line, error) { func (ps *PgStore) CardTotal(from, to time.Time) (float64, error) { var total float64 if err := ps.db.Raw(` - select sum(total) - from (select sum(price * quantity) as total - from bookings - join items on bookings.id = items.booking_id + select sum(total) + from (select sum(amount) as total + from bookings as b + join payments as p on b.id = p.booking_id where "to" between ? and ? and canceled = false - and payment_method = 'Card' - group by booking_id) as t; + and p.payment_method = 'Card' + group by b.id) as t; `, from, to). Scan(&total).Error; err != nil { return 0, fmt.Errorf("failed to get card total: %w", err) diff --git a/internal/server/handle_pdf.go b/internal/server/handle_pdf.go index dce1d0a..9ec729f 100644 --- a/internal/server/handle_pdf.go +++ b/internal/server/handle_pdf.go @@ -62,7 +62,7 @@ func handlePdfCreateReport(bs *booking.Service) echo.HandlerFunc { } report := bs.Report(period, month, year) - filePath,err := bs.BuildReport(report, period, month, year) + filePath, err := bs.BuildReport(report, period, month, year) if err != nil { return err }