-- Wipe all transactional data (in batches to avoid long lists)
TRUNCATE TABLE payroll_items CASCADE;
TRUNCATE TABLE payroll_runs CASCADE;
TRUNCATE TABLE loans CASCADE;
TRUNCATE TABLE loan_appraisals CASCADE;
TRUNCATE TABLE loan_approvals CASCADE;
TRUNCATE TABLE loan_collaterals CASCADE;
TRUNCATE TABLE loan_guarantors CASCADE;
TRUNCATE TABLE loan_recoveries CASCADE;
TRUNCATE TABLE loan_repayments CASCADE;
TRUNCATE TABLE loan_schedules CASCADE;
TRUNCATE TABLE loan_status_history CASCADE;
TRUNCATE TABLE loan_top_ups CASCADE;
TRUNCATE TABLE loan_waivers CASCADE;
TRUNCATE TABLE loan_write_offs CASCADE;
TRUNCATE TABLE journal_entries CASCADE;
TRUNCATE TABLE cash_advances CASCADE;
TRUNCATE TABLE cash_advance_repayments CASCADE;
TRUNCATE TABLE savings_transactions CASCADE;
TRUNCATE TABLE share_transactions CASCADE;
TRUNCATE TABLE audit_logs CASCADE;
TRUNCATE TABLE notifications CASCADE;
TRUNCATE TABLE user_login_history CASCADE;
TRUNCATE TABLE promise_to_pay CASCADE;
TRUNCATE TABLE provision_records CASCADE;
TRUNCATE TABLE standing_orders CASCADE;
TRUNCATE TABLE expenses CASCADE;
TRUNCATE TABLE group_meetings CASCADE;
TRUNCATE TABLE group_meeting_attendance CASCADE;
TRUNCATE TABLE collection_schedules CASCADE;
TRUNCATE TABLE collection_targets CASCADE;
TRUNCATE TABLE collection_activities CASCADE;
TRUNCATE TABLE cashbook_entries CASCADE;
TRUNCATE TABLE inter_branch_transfers CASCADE;
TRUNCATE TABLE budgets CASCADE;
TRUNCATE TABLE budget_lines CASCADE;
TRUNCATE TABLE member_contact_history CASCADE;
TRUNCATE TABLE member_documents CASCADE;
TRUNCATE TABLE member_bank_accounts CASCADE;
TRUNCATE TABLE member_next_of_kin CASCADE;

-- Reset all COA balances to 0
UPDATE chart_of_accounts SET balance = 0, "ytdBalance" = 0;
