Exemple #1
0
    /**
     * Get DTR by offices and range of date
     *
     * @since Version 1.0
     * @param int $office_id
     * @param string(date) $date
     * @param string(date) $date2
     * @param varchar $employee_id
     * @param bool $flex
     * @return array
     */
    function get_office_dtr($office_id, $date, $date2 = '', $employee_id = '', $flex = '')
    {
        $data = array();
        $rows = array();
        $this->Employee->fields = array('employee_id', 'office_id');
        $employees = $this->Employee->get_employee_list($office_id, '');
        $days = $this->Helps->get_days_in_between($date, $date2);
        // If uses for single employee only
        if ($employee_id != '') {
            $employees = array(array('employee_id' => $employee_id));
        }
        // Add new dates in the view dtr even if this is blank
        foreach ($employees as $employee) {
            $office_id2 = $this->Employee->get_single_field('office_id', $employee['employee_id']);
            foreach ($days as $day) {
                // Insert to dtr if the log_date and employee id
                // is not in the dtr table
                $is_log_date_exists = $this->is_log_date_exists($employee['employee_id'], $day);
                if ($is_log_date_exists === FALSE) {
                    // Insert blank dtr
                    $this->insert_blank_dtr($office_id2, $employee['employee_id'], $day);
                }
            }
        }
        $this->db->select('dtr.id, 
						   dtr.employee_id, 
						   dtr.am_login,
						   dtr.am_logout, 
						   dtr.pm_login, 
						   dtr.pm_logout, 
						   dtr.ot_login, 
						   dtr.ot_logout, 
						   dtr.log_date, 
						   dtr.manual_log_id, 
						   dtr.office_id, 
						   dtr.orig_dtr, 
						   employee.lname,  
						   employee.fname,
						   employee.shift_type');
        $this->db->from('dtr');
        $this->db->join('employee', 'dtr.employee_id = employee.employee_id');
        //$this->db->where('dtr.employee_id', $employee_id);
        //
        if ($this->double_incomplete == FALSE) {
            $this->db->where('employee.office_id', $office_id);
        }
        $this->db->where("dtr.log_date BETWEEN '{$date}' AND '{$date2}'");
        if ($this->double_incomplete == TRUE) {
            // Get offices(internal)
            $o = new Office_m();
            $o->where('office_location', 'internal');
            $offices = $o->get();
            foreach ($offices as $office) {
                $off[] = $office->office_id;
            }
            $this->db->where_in('employee.office_id', $off);
            $this->db->where("(ats_dtr.am_login = '' OR `ats_dtr`.`pm_login` = '' OR `ats_dtr`.`am_logout` = '' OR `ats_dtr`.`pm_logout` = '')");
        }
        $this->db->order_by('dtr.office_id, employee.lname, employee.fname, dtr.log_date');
        $q = $this->db->get();
        //echo $this->db->last_query();
        // GSO LAGUNA
        // ORDER BY ".TABLEPREF."dtr.am_login, ".TABLEPREF."employee.lname";
        // $this->db->order_by('dtr.am_login, employee.lname');
        // If uses for single employee only
        if ($employee_id != '') {
            $this->db->select('dtr.id, 
							   dtr.employee_id, 
							   dtr.am_login,
							   dtr.am_logout, 
							   dtr.pm_login, 
							   dtr.pm_logout, 
							   dtr.ot_login, 
							   dtr.ot_logout, 
							   dtr.log_date, 
							   dtr.manual_log_id, 
							   dtr.office_id, 
							   dtr.orig_dtr, 
							   employee.lname,  
							   employee.fname,
							   employee.shift_type');
            $this->db->from('dtr');
            $this->db->join('employee', 'dtr.employee_id = employee.employee_id');
            $this->db->where('dtr.employee_id', $employee_id);
            $this->db->where("dtr.log_date BETWEEN '{$date}' AND '{$date2}'");
            $this->db->order_by('dtr.log_date');
            $q = $this->db->get();
            // Check what type of user is logged
            // If leave manager
            $this->load->library('session');
            if (Session::get('user_type') == 5) {
                // If the office is not equal to office id of user logged
                if (Session::get('office_id') != $employee['office_id']) {
                    //echo '<font color="red">You are not allowed to view this records!</font>';
                    //return ;
                    $this->db->where('id', 0);
                    $q = $this->db->get('dtr');
                }
            }
        }
        if ($q->num_rows() > 0) {
            foreach ($q->result_array() as $row) {
                $data[] = $row;
            }
        }
        return $data;
        $q->free_result();
    }