<?php
/**
 * This is a class file used for Employee operations.
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */

/**
 * This is a class named EmployeeMgmt.
 *
 * @category Employee Management System
 * @package  Employee Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class EmployeeMgmt
{
    /**
     * @var public $employee_id This is the Employee Id feteched from the database(employee_master).
     */
    public $employee_id;
	
	/**
     * @var public $employee_name This is the Employee name.
     */
	public $employee_name;
	
	/**
     * @var public $employee_curaddress This is the Employee current address.
     */
	public $employee_address;
	
	/**
     * @var public $employee_phone This is the Employee phone.
     */
	public $employee_phone;

	/**
     * @var public $employee_mobile This is the Employee mobile.
     */
	public $employee_mobile;

	/**
     * @var public $employee_email This is the Employee email id.
     */
	public $employee_email;

	/**
     * @var public $employee_salary This is the Employee Basic salary.
     */
	public $employee_salary;
	
	/**
     * @var public $employee_photo This is the Employee Photo.
     */
	public $employee_photo;

	/**
     * @var public $employee_birthdate This is the Employee birthdate.
     */
	public $employee_birthdate;

	/**
     * @var public $employee_schooljoindate This is the Employee school join date.
     */
	public $employee_joindate;

	/**
     * @var public $designation_id This is the Employee designation.
     */
	public $designation_id;

	/**
     * @var public $company_id This is the school id.
     */
	public $company_id;
	
	/**
     * @var public $login_id This is the Employee login id.
     */
	public $createdby;
	
	/**
     * @var public $createdon This is the Employee createdon.
     */
	public $createdon;
	
	/**
     * Constructor to inialize employee_count to zero
     *
     */
    function EmployeeMgmt()
    {
        $this->bullet = "<font size='2'>&raquo;</font>";
        $this->bullet = htmlentities($this->bullet);
        $this->employee_count=0;
    }

    /**
     * This function is used to get a particular record.
     *
     * @param integer $employee_id This is the database employee_id.
     *
     * @return array
     */
    /*function getRecordById($employee_id,$company_id)
    {
        $qry = "select * from employee_master where 1=1 ";

        if ($employee_id!="") {
            $qry.=" and employee_id=$employee_id ";
        }
		if ($company_id!="") {
            $condition=" and company_id=$company_id ";
        }
		$qry.=$condition;

        $out=dbQuery($qry);

		if(dbRows($out)>0) {
            $this->employee_count=1;

            $row=dbArray($out);
            extract($row);

			$this->employee_id			= ($employee_id);
			$this->company_id			= ($company_id);
			$this->employee_name		= ($employee_name);
			$this->designation_id		= ($designation_id);
			$this->employee_birthdate	= ($employee_birthdate);
			$this->employee_joindate	= ($employee_joindate);
			$this->employee_salary		= ($employee_salary);
			$this->employee_address		= ($employee_address);
			$this->employee_mobile		= ($employee_mobile);
			$this->employee_phone		= ($employee_phone);
			$this->employee_email		= ($employee_email);

			dbFreeResult($out);
        }
    }*/
		
	/**
     * This is a function for getting the total no of records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Total Records Found
     */
    /*function getCountRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->employee_count=0;
		
       	$qry = "SELECT COUNT(*) AS Count
				FROM employee_master em 
				WHERE em.company_id   = '".$_SESSION["cCompany_id"]."' ";
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->employee_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->employee_count;
    }*/
	
	/**
     * This is a function for getting the all records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Mix Result Set
     */
    function getAllRecords($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
		$this->employee_count=0;
		
		$qry = "SELECT 
					lm.*,ld.*
				FROM 
			  		lms_employeemaster lm LEFT JOIN lms_designation ld 
					ON ld.designation_id=lm.designation_id			  
			  	WHERE    							
					lm.company_id   = '".$_SESSION["cCompany_id"]."' "; 
					   					   				
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		if ($order_field !="" && $order_type !="") {
            $qry.= " order by $order_field $order_type";
        }

        if (intval($limit) > 0 && intval($start) >=0) {
            $qry.= " Limit $start , $limit";
        }
		
		//print $qry;
		$out=dbQuery($qry);
		
        if (dbRows($out)>0) {
            $this->employee_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
		
		
		
	/**
     * This is a function for getting the all records with/without condition
     *
     * @param integer $limit This is the limit of number or records.
     * @param integer $start This is the starting location of records.
     * @param string  $condition This is the condition for fetching records.	 
     * @param string  $order_field This is the field for fetching records orderby.	 
     * @param string  $order_type This is the order direction to fetch records orderby.	 	 
     *
     * @return Mix Result Set
     */
	function cscGridFiltertally($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		
	  $qry = "SELECT 	
	  			*		  
			  FROM 
			  	csc_customer_tally
			  WHERE    							
				1=1"; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		if ($order_field !="" && $order_type !="") {
            $qry.= " order by $order_field $order_type";
        }

        if (intval($limit) > 0 && intval($start) >=0) {
           $qry.= " Limit $start , $limit";
        }
		
		//echo $qry;
		$out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->employee_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }

	
	    function cscGridFilter($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		
	  $qry = "SELECT 	
	  			*		  
			  FROM 
			  	csc_customer
			  WHERE    							
				1=1"; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		if ($order_field !="" && $order_type !="") {
            $qry.= " order by $order_field $order_type";
        }

        if (intval($limit) > 0 && intval($start) >=0) {
           $qry.= " Limit $start , $limit";
        }
		
		
		$out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->employee_count=dbRows($out);
			return $out;							
        }
		return $out;		
    } 
	 
    function employeeGridFilter($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		
	  $qry = "SELECT 	
	  			lm.*,ld.* 		  
			  FROM 
			  	lms_employeemaster lm LEFT JOIN lms_designation ld 
				ON ld.designation_id = lm.designation_id			  
			  WHERE    							
				lm.company_id   = '".$_SESSION["cCompany_id"]."' "; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		if ($order_field !="" && $order_type !="") {
            $qry.= " order by $order_field $order_type";
        }

        if (intval($limit) > 0 && intval($start) >=0) {
           $qry.= " Limit $start , $limit";
        }
		
		//echo $qry;
		$out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->employee_count=dbRows($out);
			return $out;							
        }
		return $out;		
    }
			function cscGridFilterCount($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		
	  $qry = "SELECT 	
	  			Count(*) AS Count	  
			  FROM 
			  	csc_customer
			  WHERE    							
				1=1 "; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		 $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->employee_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->employee_count;	
    }
	
		function cscGridFilterCounttally($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		
	  $qry = "SELECT 	
	  			Count(*) AS Count	  
			  FROM 
			  	csc_customer_tally
			  WHERE    							
				1=1 "; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		 $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->employee_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->employee_count;	
    }	
	
	function employeeGridFilterCount($limit=0,$start=0,$condition="",$order_field="",$order_type="")
    {
	  $this->employee_count=0;
		
	  $qry = "SELECT 	
	  			Count(*) AS Count	  
			  FROM 
			  	lms_employeemaster lm LEFT JOIN	lms_designation ld 
				ON ld.designation_id=lm.designation_id			  
			  WHERE    							
				lm.company_id   = '".$_SESSION["cCompany_id"]."' "; 
		
		if ($condition != "" ) {
            $qry.= $condition;
        }
		
		 $out=dbQuery($qry);

        if (dbRows($out)>0) {
			$row=dbArray($out);
            extract($row);		
            $this->employee_count=$Count;            
			dbFreeResult($out);	
        }
		return $this->employee_count;	
    }	

    /**
     * This is a function for adding new record for Employee.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function add()
    {
		global $SQLDateFormat;
		
		$Qry1 = "";
		$Qry1 .= "employee_name='"	  .Escape($this->employee_name)."',";
		$Qry1 .= "employee_address='" .replaceHtmlEditor(Escape($this->employee_address))."',";	
		$Qry1 .= "employee_phone='"	  .Escape($this->employee_phone)."',";	
		$Qry1 .= "employee_mobile='"  .Escape($this->employee_mobile)."',";	
		$Qry1 .= "employee_email='"	  .Escape($this->employee_email)."',";
		$Qry1 .= "employee_salary='"  .Escape($this->employee_salary)."',";
		$Qry1 .= "employee_birthdate= STR_TO_DATE('".Escape($this->employee_birthdate)."','$SQLDateFormat'),";			
		$Qry1 .= "employee_joindate=  STR_TO_DATE('".Escape($this->employee_joindate)."','$SQLDateFormat'),";			
		$Qry1 .= "designation_id='"   .Escape($this->designation_id)."',";		
		$Qry1 .= "company_id='"	      .Escape($this->company_id)."',";			
		$Qry1 .= "createdby='"	      .Escape($_SESSION['cUserId'])."',";			
		$Qry1 .= "createdon='"	      .Escape(date('Y-m-d h:i:s'))."',";
					
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
			$qry = "insert into lms_employeemaster set " . $Qry1 . " ";
					
			dbQuery($qry);
			$this->employee_id=dbInsertedId();
		}
	}

    /**
     * This is a function for editing a Employee record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function edit()
    {
			global $SQLDateFormat;
			$Qry1 = "";
			
			$Qry1 .= "employee_name='"	    .Escape($this->employee_name)."',";
			$Qry1 .= "employee_address='"	.replaceHtmlEditor(Escape($this->employee_address))."',";
			$Qry1 .= "employee_phone='"	    .Escape($this->employee_phone)."',";
			$Qry1 .= "employee_mobile='"	.Escape($this->employee_mobile)."',";
			$Qry1 .= "employee_email='"	    .Escape($this->employee_email)."',";
			$Qry1 .= "employee_salary='"	.Escape($this->employee_salary)."',";
			$Qry1 .= "employee_birthdate=	STR_TO_DATE('".Escape($this->employee_birthdate)."','$SQLDateFormat'),";
			$Qry1 .= "employee_joindate=	STR_TO_DATE('".Escape($this->employee_joindate)."','$SQLDateFormat'),";
			$Qry1 .= "designation_id='"	    .Escape($this->designation_id)."',";
			$Qry1 .= "company_id='"	        .Escape($this->company_id)."',";
			$Qry1 .= "createdby='"	.Escape($_SESSION['cUserId'])."',";			
            $Qry1 .= "createdon='"	.Escape(date('Y-m-d h:i:s'))."',";	
					
            if ($Qry1 != "") {
                $Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
                $qry = "update lms_employeemaster set " . $Qry1 . " where employee_id=".$this->employee_id. " and company_id = '".$_SESSION['cCompany_id']."' ";
                dbQuery($qry);
            }
	}
	
	/**
     * This is a function for deleting the Employee record.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function delete()
    {		
		$qry = "delete from  lms_employeemaster 
             	where designation_id in (".$this->designation_id.") 
				and company_id='".$_SESSION["cCompany_id"]."'";
        dbQuery($qry);
   	}
	
	/**
     * This is a function for update the Employee Photo.
     *
     * @return void The redirect file name and the message are passed.
     *
     */
    function updatePhoto()
    {		
		$qry = "update lms_employeemaster 
				set employee_photo = '".$this->employee_photo."'
             	where employee_id =   ".$this->employee_id." and company_id='".$_SESSION["cCompany_id"]."'";
        dbQuery($qry);
   	}
	
	/**
     * This function is used to remove duplication of Designation.
     *
     * @param integer $company_id This is the database school id.
     *
     * @return array
     */
   /* function getDistinctDesignation()
    {
        $this->trustee_count=0;
		
        $qry = "SELECT DISTINCT designation_id 
				FROM employee_master where company_id='".$_SESSION['cCompany_id']."' ";
        $out=dbQuery($qry);

        if (dbRows($out)>0) {
            $this->employee_count=dbRows($out);
			return $out;							
        }
		return $out;
	
	}*/
}
?>