fix card calculation sql (#44)

This commit is contained in:
Ruidy 2025-02-22 14:19:48 +01:00 committed by GitHub
parent 44cf04bac7
commit 6bdbd36869
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View file

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

View file

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