ALTER TABLE payments ADD COLUMN cash_session_id BIGINT UNSIGNED NULL AFTER sale_id, ADD KEY idx_payment_cash_session(cash_session_id);
CREATE TABLE cash_movements (id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,business_id BIGINT UNSIGNED NOT NULL,branch_id BIGINT UNSIGNED NOT NULL,cash_session_id BIGINT UNSIGNED NOT NULL,user_id BIGINT UNSIGNED NOT NULL,type ENUM('sale','refund','deposit','withdrawal') NOT NULL,amount DECIMAL(15,2) NOT NULL,reference_type VARCHAR(50),reference_id BIGINT UNSIGNED,note VARCHAR(255),created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,KEY idx_cash_movement_session(cash_session_id,created_at)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;