<?php

class Attendance {

	/*************************************************
	/ This function add new Attendance
	*************************************************/
	
	public static function AddAttendance($data) {
		global $db;
				
		$id = $db->query_insert(TABLE_ATTENDANCE, $data);
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			return $id;
		}else{
			return false;
		}
	
	} // AddAttendance

	/*************************************************
	/ This function update Attendance
	*************************************************/
	
	public static function UpdateAttendance($pid,$data) {
		global $db;
				
		$id = $db->query_update(TABLE_ATTENDANCE,$data,"id='$pid'");
		
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			
			return $id;
		}else{
			return $id;
		}
	
	} // UpdateAttendance


	public static function GetAttendanceById($id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_ATTENDANCE." WHERE id ='$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Attendance

	public static function GetMaxAttendance($filter="") {

		global $db;
		$query = "SELECT *,MAX(time_in) AS maxtimein, Max(time_out) AS maxtimeout from ".TABLE_ATTENDANCE." ".$filter." ";
		//print($query);exit;
		$rows = $db->query_first($query);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//Attendance

	public static function GetAttendanceByEmployeeId($id, $filter="",$pageno="null",$pagesize="null") {

		global $db;
		$query = "SELECT * from ".TABLE_ATTENDANCE." WHERE employee_id ='$id' ".$filter." ";
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//Attendance


	public static function CheckAttendance($employee_id, $id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_ATTENDANCE." WHERE employee_id ='$employee_id' && id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Attendance
	
	/**********************************************************
	/ This function will return Attendance
	**********************************************************/
		
	public static function GetAttendanceList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_ATTENDANCE." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Attendance


	public static function DeleteAttendance($id) {

		global $db;
		$query = "DELETE  FROM ".TABLE_ATTENDANCE." WHERE id ='$id'";
		//print($query);exit;
		$rows = $db->fetch_all_array($query);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//GetBranch

	public static function GetNumRows() { global $db; return $db->GetNumRows(); }
	public static function GetNumberOfPages() { global $db; return $db->GetNumberOfPages(); }
		
	
}

?>
