-- DELIMITER //

CREATE PROCEDURE $procName(IN v_start VARCHAR(100), IN v_end VARCHAR(100))
    LANGUAGE SQL
    NOT DETERMINISTIC
    CONTAINS SQL
    SQL SECURITY DEFINER
    COMMENT ''

    BEGIN
        START TRANSACTION;
            DELETE t_credit, t_debit
            FROM transactions AS t_credit
            LEFT JOIN transactions AS t_debit ON t_credit.transaction_reference_id = t_debit.id
            WHERE t_credit.created_at BETWEEN v_start AND v_end
            AND t_credit.transaction_type_id IN(6,8,9,13,15); -- All the followng credit type: Win, Bonus Win, Bet Rollback, Win Rollback, Cancel Credit

            DELETE FROM transaction_users WHERE transaction_users.created_at BETWEEN v_start AND v_end;
        COMMIT;
    END;
-- //