SELECT CIN.event_id         AS checkin_id,
       COUT.event_id        AS checkout_id,
       T.system_id          AS task_system_id,
       T.name               AS task_name,
       P.system_id          AS person_system_id,
       P.employee_code      AS employee_code,
       CIN.event_time       AS checkin_time,
       COUT.event_time      AS checkout_time,
       CIN.shift_start,
       CIN.ot_start,

       CIN.latitude         AS checkin_latitude,
       CIN.longitude        AS checkin_longitude,
       CIN.address          AS checkin_address,
       CIN.description      AS checkin_description,
       CIN.event_time_zone  AS checkin_timezone,

       COUT.latitude        AS checkout_latitude,
       COUT.longitude       AS checkout_longitude,
       COUT.address         AS checkout_address,
       COUT.description     AS checkout_description,
       COUT.event_time_zone AS checkout_timezone,

       CIN.shift_span_seconds,
       CIN.work_hours,
       CIN.is_ot_enabled,
       CIN.ot_span_seconds,
       CIN.is_limitOT,
       CIN.maxOT,
       CIN_VA.system_id     AS appointment_system_id,
       CIN.event_origin     AS checkin_origin,
       COUT.event_origin    AS checkout_origin
FROM eventlog CIN
         INNER JOIN
     person P
     ON
             CIN.person_id = P.person_id

         LEFT JOIN
     eventlog COUT
     ON
             CIN.next_event = COUT.event_id
         LEFT JOIN
     task T
     ON
             CIN.task_id = T.task_id
         LEFT JOIN visitor_appointments CIN_VA ON
        CIN.visit_appointment = CIN_VA.id
WHERE CIN.event_type = 0
  AND CIN.is_deleted = 0
  AND CIN.event_time > :fromparam
  AND P.customer_id = :customerparam
    :GROUP_FILTER
    :PERSON_FILTER