diff --git a/README.md b/README.md index df22e05..7074f27 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ - [Rentease](#rentease) - - [Features](#features) - - [Getting Started](#getting-started) - - [Prerequisites](#prerequisites) - - [Installation](#installation) - - [Built With](#built-with) - - [Roadmap](#roadmap) - - [Contributing](#contributing) - - [License](#license) + - [Features](#features) + - [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Built With](#built-with) + - [Roadmap](#roadmap) + - [Contributing](#contributing) + - [License](#license) Rentease is a property-management application to help landlords to manage your rental diff --git a/internal/repository/booking/pg_store.go b/internal/repository/booking/pg_store.go index 3a88d8c..0807b23 100644 --- a/internal/repository/booking/pg_store.go +++ b/internal/repository/booking/pg_store.go @@ -64,12 +64,13 @@ 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(price * quantity) - from bookings - join items on bookings.id = items.booking_id - join payments on bookings.id = payments.booking_id - where payments.method = 'card' - and "to" between ? and ?; + select sum(total) + from (select sum(price * quantity) as total + from bookings + join items on bookings.id = items.booking_id + where "to" between ? and ? + and payment_method = 'Card' + group by booking_id) as t; `, from, to). Scan(&total).Error; err != nil { return 0, fmt.Errorf("failed to get card total: %w", err)