<?php

class Payment {

	/*************************************************
	/ This function add new Payment
	*************************************************/
	
	public static function AddPayment($data) {
		global $db;
				
		$id = $db->query_insert(TABLE_PAYMENT, $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,$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." 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." 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." ". $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, sum(pay.goods_return) AS goods_return,
				sum(pay.shelf_rent) AS shelf_rent, sum(pay.builty_charges) AS builty_charges,
				sum(pay.other_expense) AS other_expense 
                FROM ".TABLE_PAYMENT." 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." ". $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(); }
		
	
}

?>
