
-- Deshabilitar verificación de llaves foráneas
-- 1 - Ejecutar esto solo primero
SET GLOBAL FOREIGN_KEY_CHECKS=0;

-- 2 - Verificar que el return es 0
SELECT @@FOREIGN_KEY_CHECKS;


-- 3 - Mandar consultas

TRUNCATE sessions;

-- Truncar las tablas necesarias
TRUNCATE sales;
TRUNCATE sale_details;
TRUNCATE sale_payment_types;
TRUNCATE cash_flows;
TRUNCATE cash_registers;
TRUNCATE product_option_sale_details;
TRUNCATE online_payments;

-- Importantes
TRUNCATE clients;
TRUNCATE client_addresses;
TRUNCATE categories;
TRUNCATE products;
TRUNCATE product_extras;
TRUNCATE product_options;
TRUNCATE product_price_lists;
TRUNCATE product_printers;

-- inventario
TRUNCATE purchases;
TRUNCATE purchase_details;
TRUNCATE suppliers;
TRUNCATE product_recipe_ingredients;
TRUNCATE input_ingredients;
TRUNCATE output_ingredients;
TRUNCATE output_ingredient_stocks;
TRUNCATE inventory_histories;

-- Update a tablas necesarias
UPDATE tables SET sale_id = NULL, status = 'Libre', created_at = NULL, deleted_at = NULL;
UPDATE `sales` SET `table_id` = NULL;

-- Rehabilitar verificación de llaves foráneas
-- Este paso es importante, no olvidarlo
SET GLOBAL FOREIGN_KEY_CHECKS=1;

-- 4 - Verificar que el return es 1
SELECT @@FOREIGN_KEY_CHECKS;
