fix: the card total reporting

This commit is contained in:
Ruidy 2024-12-24 18:13:19 +01:00
parent aa436542c4
commit 106aa475d6
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 15 additions and 14 deletions

View file

@ -5,14 +5,14 @@
<!--toc:start-->
- [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)
<!--toc:end-->
Rentease is a property-management application to help landlords to manage your rental

View file

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