<?php

class LoanSetupMart {

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

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


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

	public static function CheckLoan($id, $employee_id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_LOAN_MART." WHERE employee_id = '$employee_id' AND id <> '$id' AND status NOT IN ('completed', 'hold')";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Loan
	
	/**********************************************************
	/ This function will return LoanSetup
	**********************************************************/
		
	public static function GetLoanList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_LOAN_MART." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Loan

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

?>
