<?php

class PaymentCustomer {

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

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


	public static function GetPaymentSetupById($id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_PAYMENT_CUSTOMER." 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 GetPaymentSetupByNumber($number) {

		global $db;
		$query = "SELECT * from ".TABLE_PAYMENT_CUSTOMER." 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 GetPaymentList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_PAYMENT_CUSTOMER." ". $filter;
		//print($query);exit;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
	
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Payment

	/**********************************************************
	/ This function will return Invoice
	 **********************************************************/

	public static function GetTotalPaymentLists($filter="", $customer_id="") {

		global $db;
		$query = "SELECT 'payment' AS type, sum(pay.amount) AS amount, sum(pay.withholding_tax) AS withholding_tax,
				sum(pay.sales_tax) AS sales_tax, cus.name AS name, pay.goods_return
                FROM ".TABLE_PAYMENT_CUSTOMER." AS pay
                JOIN ".TABLE_CUSTOMERSETUP." AS cus ON cus.id = pay.customer_id ".$filter;
		//print($query);exit;
		$rows = $db->query_first($query);

		if($db->affected_rows > 0){

			return $rows;
		}else{

			return false;
		}
	}//Invoice

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

		global $db;
		$query = "SELECT * from ".TABLE_PAYMENT_CUSTOMER." ". $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(); }
		
	
}

?>
