<?php

class PurchaseSetup {

	/*************************************************
	/ This function add new Purchase Setup
	*************************************************/
	
	public static function AddPurchaseSetup($data) {
		global $db;
				
		$id = $db->query_insert(TABLE_PURCHASE, $data);
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			return $id;
		}else{
			return false;
		}
	
	} // AddPurchase

	/*************************************************
	/ This function add new Purchase Item
	 *************************************************/

	public static function AddPurchaseItem($data) {
		global $db;

		$id = $db->query_insert(TABLE_PURCHASE_ITEM, $data);
		if($db->affected_rows > 0){
			//$db->query_insert("vrs_logs", $data);
			return $id;
		}else{
			return false;
		}

	} // AddPurchaseItem

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


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


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

		global $db;
		$query = "SELECT * from ".TABLE_PURCHASE_ITEM." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
		//print($rows);
		if($db->affected_rows > 0){
			return $rows;
		}else{
			return false;
		}
	}//InvoiceProducts



	public static function CheckPurchase($name, $id) {
		global $db;
		$query = "SELECT * from ".TABLE_PURCHASE." WHERE name ='$name' && id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
                if($db->affected_rows > 0){
                        return $rows;
                }else{
                        return false;
                }
	}//PurchaseSetupSetup
	
	/**********************************************************
	/ This function will return PurchaseSetupSetup
	**********************************************************/

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

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

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//PurchaseSetupSetup

	/**********************************************************
	/ This function will delete the Purchase Items
	 **********************************************************/

	public static function DeletePurchaseItems($purchase_id) {
		global $db;
		$query = "Delete from " . TABLE_PURCHASE_ITEM . "  WHERE purchase_id='$purchase_id'";
		$rows = $db->query_first($query);
		if($db->affected_rows > 0){
			return true;
		}else{
			return false;
		}
	}//DeletePurchaseItems

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

?>
