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
        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 P.person_id = :personparam
        AND (:modifiedparam=0 OR (:modifiedparam=1 AND (CIN.modified_at BETWEEN TO_DATE(:fromparam,'yyyy-mm-dd hh24:mi:ss') AND TO_DATE(:toparam,'yyyy-mm-dd hh24:mi:ss'))))
        AND (CIN.event_time BETWEEN TO_DATE(:fromparam,'yyyy-mm-dd hh24:mi:ss') AND TO_DATE(:toparam,'yyyy-mm-dd hh24:mi:ss'))
        AND CIN.is_deleted = 0
        AND CIN.event_type = 0
        AND (COUT.event_type IS NULL OR COUT.event_type = 1)
