From 45697b56c3d0aa67bd9e4431bb761bf2eda421d1 Mon Sep 17 00:00:00 2001 From: HotelSync Date: Tue, 31 Mar 2026 21:11:15 +0300 Subject: [PATCH] fix: total_spent counts all non-cancelled bookings, not only checked_out MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- backend/src/routes/guests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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