CREATE DEFINER=`computraceqa`@`%` PROCEDURE `computraceqa`.`GetLogInChart`(
    IN p_started_on DATETIME,
    IN p_ended_on DATETIME, 
    IN ChartType VARCHAR(100)
)
BEGIN
    IF ChartType = 'Log In' THEN
        SELECT 
                       
            DATE(login_time) AS LogInDate,
            count(*) AS LogInCount,
            0 AS LogOutCount
        FROM 
            system_login_details
        WHERE 
            (p_started_on IS NULL OR login_time >= p_started_on)
            AND (p_ended_on IS NULL OR login_time <= p_ended_on)
            AND system_status IN ('Active', 'Idle')
        GROUP BY 
             DATE(login_time);
    ELSEIF ChartType = 'Log Out' THEN
        SELECT 
           
            DATE(login_time) AS LogInDate,
            count(*) AS LogOutCount,
            0 AS LogInCount
        FROM 
            system_login_details
        WHERE 
            (p_started_on IS NULL OR login_time >= p_started_on)
            AND (p_ended_on IS NULL OR login_time <= p_ended_on)
            AND system_status = 'Sleep'
        GROUP BY 
            DATE(login_time);
    END IF;
END