<?php

function view_employee_attendances_details($date, $status_array=array()) {
    $sql = "SELECT emp.employee_code, 
                    a.from_date_time1,
                    a.to_date_time1,
                    a.id,
                    a.shift_id,
                    a.calculated_deficit_time, 
                    a.comment,
                    a.ot_status_code,
                    sn.value_name shift_name 
            FROM ".TB_PREF."attendance a 
                JOIN ".TB_PREF."employee_master emp                 
                    ON a.employee_code = emp.employee_code                     
                JOIN ".TB_PREF."shifts s                  
                    ON s.id = a.shift_id                      
                JOIN ".TB_PREF."list_values sn                  
                    ON sn.id = s.shift_list_value_id                      
                JOIN ".TB_PREF."employee_attendances_header hd                   
                    ON a.entry_date = hd.date                       
            WHERE a.entry_date = ".db_escape($date);
    
        if (count($status_array) > 0) {
            $sql .= " AND hd.attendance_status_code IN (".implode(',', $status_array).")";
        }

    $sql .= " ORDER BY emp.employee_code";

    return db_query($sql, "view_employee_attendances_details");
}
