Commit fa94e5b8 authored by DevPilot's avatar DevPilot

fix(accounting): gap detail queries referenced columns that do not exist

The drill-down queries were written against assumed column names and
every one of them failed, so "عرض التفاصيل" always answered "لا توجد
تفاصيل متاحة". Corrected against the real schema: pool zone bookings
have label/zone_row/zone_col and no zone table, player cards use
valid_from/issued_at and card_number, pool bookings carry booker_name
rather than a member join, and private match bookings store total_cost
rather than total_amount.
parent b16d18aa
......@@ -42,15 +42,14 @@ final class GapToolService
FROM sa_pool_zone_bookings
WHERE COALESCE(status,'') NOT IN ('cancelled')",
'detail_sql' => "SELECT b.id,
COALESCE(b.booking_date, DATE(b.created_at)) AS the_date,
COALESCE(z.name_ar, CONCAT('منطقة #', b.zone_id)) AS party,
b.booking_date AS the_date,
COALESCE(NULLIF(b.label,''), CONCAT('منطقة ', b.zone_row, '-', b.zone_col)) AS party,
b.current_occupancy AS qty,
NULL AS amount,
b.status AS status
FROM sa_pool_zone_bookings b
LEFT JOIN sa_pool_zones z ON z.id = b.zone_id
WHERE COALESCE(b.status,'') NOT IN ('cancelled')
ORDER BY the_date DESC, b.id DESC
ORDER BY b.booking_date DESC, b.id DESC
LIMIT 300",
'amount_sql' => null,
'note' => 'العدّاد شغّال على الحجوزات غير الملغية. لو اخترت «لكل حاضر» '
......@@ -65,8 +64,8 @@ final class GapToolService
FROM sa_player_cards
WHERE COALESCE(status,'') NOT IN ('cancelled','expired')",
'detail_sql' => "SELECT c.id,
COALESCE(c.issue_date, DATE(c.created_at)) AS the_date,
COALESCE(m.full_name_ar, CONCAT('لاعب #', c.player_id)) AS party,
COALESCE(c.valid_from, DATE(c.issued_at)) AS the_date,
CONCAT(c.card_number, COALESCE(CONCAT(' — ', m.full_name_ar), '')) AS party,
1 AS qty,
NULL AS amount,
c.status AS status
......@@ -90,16 +89,15 @@ final class GapToolService
WHERE COALESCE(status,'') NOT IN ('cancelled')
AND payment_id IS NULL",
'detail_sql' => "SELECT b.id,
COALESCE(b.booking_date, DATE(b.created_at)) AS the_date,
COALESCE(m.full_name_ar, b.guest_name, 'زائر') AS party,
b.booking_date AS the_date,
COALESCE(NULLIF(b.booker_name,''), 'زائر') AS party,
COALESCE(b.actual_swimmers, b.expected_swimmers, 0) AS qty,
b.total_amount AS amount,
b.status AS status
FROM pool_bookings b
LEFT JOIN members m ON m.id = b.member_id
WHERE COALESCE(b.status,'') NOT IN ('cancelled')
AND b.payment_id IS NULL
ORDER BY the_date DESC, b.id DESC
ORDER BY b.booking_date DESC, b.id DESC
LIMIT 300",
'amount_sql' => "SELECT COALESCE(SUM(total_amount),0) AS total
FROM pool_bookings
......@@ -118,15 +116,14 @@ final class GapToolService
WHERE COALESCE(status,'') NOT IN ('cancelled')
AND COALESCE(payment_status,'') <> 'paid'",
'detail_sql' => "SELECT b.id,
COALESCE(b.booking_date, DATE(b.created_at)) AS the_date,
COALESCE(m.full_name_ar, b.guest_name, 'زائر') AS party,
1 AS qty,
b.total_amount AS amount,
b.booking_date AS the_date,
COALESCE(NULLIF(b.booked_by_name,''), 'زائر') AS party,
b.players_count AS qty,
b.total_cost AS amount,
b.status AS status
FROM private_match_bookings b
LEFT JOIN members m ON m.id = b.member_id
WHERE COALESCE(b.status,'') NOT IN ('cancelled')
ORDER BY the_date DESC, b.id DESC
ORDER BY b.booking_date DESC, b.id DESC
LIMIT 300",
'amount_sql' => "SELECT COALESCE(SUM(COALESCE(total_cost, deposit_paid, 0)),0) AS total
FROM private_match_bookings
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment