<?php

class RateList {

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

	/*************************************************
	/ This function add new RateList
	 *************************************************/

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

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

	} // AddRateList

	/*************************************************
	/ This function update Check RateList
	 *************************************************/

	public static function CheckRateList($customername, $id) {

		global $db;
		$query = "SELECT * from ".TABLE_RATE_LIST." WHERE customer_name = '$customername' AND id <> $id";
		//print($query);exit;
		$rows = $db->query_first($query);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//CheckRateList

	/*************************************************
	/ This function update RateList
	 *************************************************/

	public static function UpdateRateListSetup($pid,$data) {
		global $db;

		$id = $db->query_update(TABLE_RATE_LIST,$data,"id='$pid'");

		if($db->affected_rows > 0){
			return $id;
		}else{
			return $id;
		}

	} // UpdateRateList


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

	/**********************************************************
	/ This function will return RateList
	 **********************************************************/

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

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

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//InvoiceRate

	/**********************************************************
	/ This function will return RateList Detail
	 **********************************************************/

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

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

	/**********************************************************
	/ This function will delete the RateList Detail
	 **********************************************************/

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

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

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

?>
