fix: total_spent counts all non-cancelled bookings, not only checked_out
Previously guests showed 0 ₽ spent when they had confirmed/checked_in bookings with paid_amount > 0. Now paid_amount is summed for all statuses except cancelled and no_show. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user