-- =====================================================
-- DELETE ALL CALCULATED/SHORTFALL DATA
-- This script deletes all calculated shortfall and analytics data
-- while preserving all raw data (invoices, orders, products, etc.)
-- =====================================================

-- Step 1: Delete all shortfall analytics daily records
-- (No dependencies on other calculated tables)
DELETE FROM "shortfall_analytics_daily";

-- Step 2: Delete all product shortfall records
-- (These reference orders and products, but we're keeping those)
DELETE FROM "product_shortfalls";

-- =====================================================
-- Verification queries (optional - run after deletion)
-- =====================================================

-- Check remaining records in calculated tables (should be 0)
-- SELECT COUNT(*) as shortfall_analytics_count FROM "shortfall_analytics_daily";
-- SELECT COUNT(*) as product_shortfalls_count FROM "product_shortfalls";

-- Verify raw data is still intact (should show counts > 0)
-- SELECT COUNT(*) as orders_count FROM "orders";
-- SELECT COUNT(*) as invoices_count FROM "invoices";
-- SELECT COUNT(*) as products_count FROM "products";
-- SELECT COUNT(*) as branches_count FROM "branches";
-- SELECT COUNT(*) as units_count FROM "units";

