SELECT 
    CIN.event_id AS checkin_id,
    CIN.event_time AS checkin_time,
    CIN.event_time_zone AS checkin_timezone,
    CIN.latitude AS checkin_latitude,
    CIN.longitude AS checkin_longitude,
    CIN.address AS checkin_address,
    CIN.description AS checkin_description,
    COUT.event_id AS checkout_id,
    COUT.event_time AS checkout_time,
    COUT.event_time_zone AS checkout_timezone,
    COUT.latitude AS checkout_latitude,
    COUT.longitude AS checkout_longitude,
    COUT.address AS checkout_address,
    COUT.description AS checkout_description,
    COUT.event_origin AS checkout_origin,
    P.system_id AS person_system_id,
    T.system_id AS task_system_id,
    P.employee_code AS employee_code,
    T.name AS task_name,
    CIN.shift_start AS shift_start,
    CIN.shift_span_seconds AS shift_span_seconds,
    CIN.work_hours AS work_hours,
    CIN.is_ot_enabled AS is_ot_enabled,
    CIN.ot_start AS ot_start,
    CIN.ot_span_seconds AS ot_span_seconds,
    CIN.is_limitot AS is_limitOT,
    CIN.maxot AS maxOT,
    CIN.event_origin AS checkin_origin
FROM
    eventlog CIN
        INNER JOIN
    person P ON CIN.person_id = P.person_id
    INNER JOIN
    user_group_membership UGM ON P.person_id = UGM.member
        AND UGM.assigned_group_id = :usergroupparam
        LEFT JOIN
    task T ON CIN.task_id = T.task_id
        LEFT JOIN
    eventlog COUT ON CIN.next_event = COUT.event_id
WHERE
    P.customer_id = :customerparam
        AND (CIN.modified_at > :updateafterparam OR COUT.modified_at > :updateafterparam)
        AND CIN.event_time > :mintimeparam
        AND CIN.is_deleted = 0
    	AND CIN.event_type = 0
        AND (COUT.event_type IS NULL OR COUT.event_type = 1)
