<?php

class Purpayment {

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

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


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

	public static function GetPurpaymentSetupByNumber($number) {

		global $db;
		$query = "SELECT * from ".TABLE_PURPAYMENT." WHERE code ='$number'";
		//print($query);exit;
		$rows = $db->query_first($query);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//Payment
	
	/**********************************************************
	/ This function will return Payment
	**********************************************************/
		
	public static function GetPurpaymentList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_PURPAYMENT." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Payment

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

		global $db;
		$query = "SELECT purcat.name AS catname, pur.id AS id, pur.description AS descr, pur.amount AS purchaseamount, pur.lastupdated AS purchasedate,
				'purchase' AS nameTable, '' AS code, '' AS supplier_id, '' AS payment_type, '' AS amount,
				'' AS cheque_bank_name, '' AS cheque_number, '' AS cheque_payee_name, '' AS cheque_date, '' AS bank_name,
				'' AS bank_account_number, '' AS party_name, '' AS from_bank_name, '' AS create_date, '' AS description
 				from ".TABLE_PURCHASE." AS pur JOIN ".TABLE_PURCHASECATEGORYSETUP." AS purcat
 				ON pur.category_id = purcat.id ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//Payment

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

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

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//Payment

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

?>
