fix booking total in report preview

This commit is contained in:
Ruidy 2024-02-26 17:28:55 +01:00
parent d5654f808c
commit 8c9886991e
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 5 additions and 4 deletions

View file

@ -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 ?

View file

@ -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"),