-- Read-only legacy review before upgrade. Never guess business dates or delete financial history.
SELECT i.id,i.sku,COUNT(DISTINCT st.property_id) AS property_count
FROM inventory_items i LEFT JOIN store_stock ss ON ss.item_id=i.id
LEFT JOIN stores st ON st.id=ss.store_id GROUP BY i.id HAVING property_count<>1;
SELECT reservation_id,DATE(posted_at),COUNT(*) AS entries
FROM folio_charges WHERE charge_type='room' GROUP BY reservation_id,DATE(posted_at) HAVING entries>1;
SELECT entry_id,SUM(debit) AS debit,SUM(credit) AS credit
FROM journal_lines GROUP BY entry_id HAVING debit<>credit;
