<?php
class MEmployees extends CI_Model
{
    function getDepartments()
    {
        $TableData=$this->db->query("select * from tbl_departments where status='1'")->result();
        return $TableData;
    }
    function getDepartmentByAlias($department_alias)
    {
        $department_alias=str_replace("_","-",$department_alias);
        $t="SELECT * FROM tbl_departments WHERE department_alias='$department_alias'";
//        echo $t;
        $TableData=$this->db->query($t)->row();
        return $TableData;
    }
    function prepareEmployee($Employee)
    {
        $Employee->Type=$this->db->query("select * from tbl_employeetype where employeetype_id='$Employee->employeetype_id'")->row();
        $Employee->Department=$this->db->query("select * from tbl_departments where department_id='$Employee->department_id'")->row();
        return $Employee;
    }
    function getEmployee($employee_id)
    {
        $TableData=$this->db->query("select * from tbl_employees where employee_id='$employee_id'")->row();
        return $this->prepareEmployee($TableData);
    }
    function getEmployees($employeetype_id="",$department_id="")
    {
        $t="select * from tbl_employees where status=1";
        if($employeetype_id!="") $t.=" and employeetype_id='$employeetype_id'";
        if($department_id!="") $t.=" and department_id='$department_id'";
        $TableData=$this->db->query($t)->result();
        foreach ($TableData as $T)
        {
            $T=$this->prepareEmployee($T);
        }
        return $TableData;
    }
    function getSalaryAllocations()
    {
      $TableData= $this->db->query("select * from tbl_salaryallocations where status=1")->result();
      foreach($TableData as $T)
      {
          $T->Employee=$this->prepareEmployee($this->getEmployee($T->employee_id));
          $T->SalaryType=$this->db->query("select * from tbl_salarytypes where salarytype_id='$T->salarytype_id'")->row();
      }
      return $TableData;
    }
    function getWorkshifts()
    {
        $TableData= $this->db->query("select * from tbl_workshifts where status=1")->result();
        return $TableData;
    }
}