diff --git a/backend/src/routes/guests.ts b/backend/src/routes/guests.ts index 884ac43..bf6d7f5 100644 --- a/backend/src/routes/guests.ts +++ b/backend/src/routes/guests.ts @@ -18,8 +18,8 @@ const STATS_JOIN = ` SELECT guest_id, COUNT(*) FILTER (WHERE status NOT IN ('cancelled', 'no_show')) AS total_stays, - COALESCE(SUM(paid_amount) FILTER (WHERE status = 'checked_out'), 0) AS total_spent, - MAX(check_out) FILTER (WHERE status = 'checked_out') AS last_visit + COALESCE(SUM(paid_amount) FILTER (WHERE status NOT IN ('cancelled', 'no_show')), 0) AS total_spent, + MAX(check_out) FILTER (WHERE status NOT IN ('cancelled', 'no_show')) AS last_visit FROM bookings WHERE hotel_id = $1 GROUP BY guest_id