<?php

class InvoiceRate {

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

	/*************************************************
	/ This function add new InvoiceRate
	 *************************************************/

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

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

	} // AddInvoiceRate

	/*************************************************
	/ This function update Check InvoiceRate
	 *************************************************/

	public static function CheckInvoiceRate($customerCatid, $id) {

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

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//CheckInvoiceRate

	/*************************************************
	/ This function update InvoiceRate
	 *************************************************/

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

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

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

	} // UpdateInvoiceRate


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

	/**********************************************************
	/ This function will return InvoiceRate
	 **********************************************************/

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

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

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//InvoiceRate

	/**********************************************************
	/ This function will return Invoice Rate Detail
	 **********************************************************/

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

		global $db;
		$query = "SELECT * from ".TABLE_INVOICE_RATE_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;
		}
	}//InvoiceRateDetail

	/**********************************************************
	/ This function will delete the Invoice Rate Detail
	 **********************************************************/

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


/**********************************************************
/ This function will delete the Invoice Rate 
 **********************************************************/

public static function DeleteInvoiceRate($invoice_rate_id) {
    global $db;
    // Primary key column is `id`
    $query = "DELETE FROM " . TABLE_INVOICE_RATE . " WHERE id='$invoice_rate_id'";
    $rows = $db->query_first($query);
    if ($db->affected_rows > 0) {
        return true;
    } else {
        return false;
    }
} // DeleteInvoiceRate

  
  

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

?>
