-- =========================================================
-- cleanup_data.sql (v2) — Remove all demo data, keep schema + Owner login only
-- Uses DELETE (FK-safe) instead of TRUNCATE.
-- Run on reoeykis_velo via phpMyAdmin SQL tab — paste whole file, click Go.
-- =========================================================


DELETE FROM lead_status_history;
DELETE FROM call_logs;
DELETE FROM installations;
DELETE FROM leads;
DELETE FROM service_zone_mapping;

DELETE FROM leave_requests;
DELETE FROM leave_balances;
DELETE FROM attendance;
DELETE FROM employee_incentives;
DELETE FROM employee_documents;
DELETE FROM incentive_rules;
DELETE FROM holidays;

DELETE FROM payslips;
DELETE FROM payroll_runs;
DELETE FROM salary_structures;

DELETE FROM login_logs;
DELETE FROM daily_stats;

DELETE FROM team_members;
DELETE FROM teams;

-- Remove all employees except Owner (id=1)
DELETE FROM employees WHERE id != 1;

-- Reset Owner's reporting_to to clean default
UPDATE employees SET reporting_to = NULL WHERE id = 1;


-- Reset auto-increment counters
ALTER TABLE employees AUTO_INCREMENT = 2;
ALTER TABLE teams AUTO_INCREMENT = 1;
ALTER TABLE team_members AUTO_INCREMENT = 1;
ALTER TABLE leads AUTO_INCREMENT = 1;
ALTER TABLE lead_status_history AUTO_INCREMENT = 1;
ALTER TABLE call_logs AUTO_INCREMENT = 1;
ALTER TABLE installations AUTO_INCREMENT = 1;
ALTER TABLE service_zone_mapping AUTO_INCREMENT = 1;
ALTER TABLE salary_structures AUTO_INCREMENT = 1;
ALTER TABLE payroll_runs AUTO_INCREMENT = 1;
ALTER TABLE payslips AUTO_INCREMENT = 1;
ALTER TABLE leave_balances AUTO_INCREMENT = 1;
ALTER TABLE leave_requests AUTO_INCREMENT = 1;
ALTER TABLE login_logs AUTO_INCREMENT = 1;
ALTER TABLE daily_stats AUTO_INCREMENT = 1;

-- =========================================================
-- After this: only employee #1 (Owner, owner@velowox.com / Demo@123) remains.
-- Departments table (Sales/Service/Admin-HR/Owner Office) is untouched.
-- =========================================================
