<?php

class SupplierPayment {

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

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


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


	public static function CheckSupplierPaymentAccount($account_number, $id) {
	
		global $db;
		$query = "SELECT * from ".TABLE_SUPPLIER_PAYMENT." WHERE bank_account_number ='$account_number' && id <> '$id'";
		//print($query);exit;
		$rows = $db->query_first($query);
	
                if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//Bank
	
	/**********************************************************
	/ This function will return BankSetup
	**********************************************************/
		
	public static function GetSupplierPaymentList($filter="",$pageno="null",$pagesize="null") {
	
		global $db;
		$query = "SELECT * from ".TABLE_SUPPLIER_PAYMENT." ". $filter;
		//echo $query;
		$rows = $db->fetch_all_array($query,$pageno,$pagesize);
    
//	echo '<pre>';
//print_r($rows);  // print_r is used to output the array or object in a human-readable format
// echo '</pre>';
			if($db->affected_rows > 0){
			
                        return $rows;
                }else{
			
                        return false;
                }
	}//BankSetup
  
  /**********************************************************
	/ This function will return BankSetup
	**********************************************************/
		
	public static function GetUnmatchedPurchasePayments($pageno = "null", $pagesize = "null") {
    global $db;

    $query = "SELECT 
                pp.id AS purchase_payment_id,
                pp.code AS purchase_payment_code,
                pp.amount_payable,
                pp.purchase_reference_code,
                ps.purchase_invoice_no,
                ps.total_ex_amount,
                ss.name AS supplier_name,
				ss.id AS supplier_id
              FROM " . TABLE_PURPAYMENT . " pp
              LEFT JOIN " . TABLE_SUPPLIER_PAYMENT . " sp ON pp.id = sp.purchase_payment_id
              INNER JOIN " . TABLE_SUPPLIERSETUP . " ss ON pp.supplier_id = ss.id
              LEFT JOIN " . TABLE_PURCHASE . " ps ON pp.purchase_reference_code = ps.id
              WHERE sp.purchase_payment_id IS NULL
              AND pp.status <> 'Cancelled'
              AND ss.status = 'active' 
              ";
	//echo $query;
    $rows = $db->fetch_all_array($query, $pageno, $pagesize);
	//echo '<pre>';
//print_r($rows);  // print_r is used to output the array or object in a human-readable format
// echo '</pre>';
    if ($db->affected_rows > 0) {
        return $rows;
    } else {
        return false;
    }
}

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

?>
