<?php
//open connection
include 'db_Connection.php';

//get parameters
$data_post = $_POST['data_post'];

//get array value
$json = $data_post;
$array = json_decode($json, true);
$Invoice_Number = $array['Invoice_Number'];
$get_Invoice_Number = array();
$get_Date = array();
$get_Amount = array();
$len = 0;

// menghitung total amount perSI yang ditemukan        
	$sql = "SELECT * FROM payment_receive WHERE Invoice_Number = '$Invoice_Number'";	
	$rs_result = $conn->query($sql);
	
// menghitung jumlah data yang ditemukan    
    $data = "SELECT * FROM payment_receive WHERE Invoice_Number = '$Invoice_Number'";
    $result = mysqli_query($conn, $data);
    $cek = mysqli_num_rows($result);

// menghitung jumlah data yang ditemukan di tbl sales_invoice   
    $data1 = "SELECT * FROM sales_invoice WHERE Invoice_Number = '$Invoice_Number'";
    $result1 = mysqli_query($conn, $data);
    $cek1 = mysqli_num_rows($result);       	
		
if($cek > 0){	
	 while($row = $rs_result->fetch_assoc()) {	
		$get_Invoice_Number[] = $row['Invoice_Number'];
		$get_Date[] = $row['Date'];
		$get_Amount[] = $row['Amount'];
		$len++;		
		//$test[] = $row['Amount'];
		$resp_payment = array('Invoice_Number' => $get_Invoice_Number, 'Date' => $get_Date, 'Amount' => $get_Amount, 'len' => $len);
     }
}
else{
	$resp_payment = array('len' => $len, 'cek' => $cek);
}	
	 	 	 
	 //$sukses = "sukses";
	 //$res = array("result" => $sukses);
	 $res = array("result" => $resp_payment);
	 echo json_encode($res);	     
?>
