<?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);
$PO_Number = $array['PO_Number'];
//$test = array('a' => 1, 'b' => 2);
//$test = array();
$get_PO_Number = array();
$get_Date = array();
$get_Amount = array();
$len = 0;

// menghitung total amount perPO yang ditemukan        
	$sql = "SELECT * FROM payment WHERE PO_Number = '$PO_Number'";	
	$rs_result = $conn->query($sql);
	
// menghitung jumlah data yang ditemukan    
    $data = "SELECT * FROM payment WHERE PO_Number = '$PO_Number'";
    $result = mysqli_query($conn, $data);
    $cek = mysqli_num_rows($result);       
		
if($cek > 0){	
	 while($row = $rs_result->fetch_assoc()) {	
		$get_PO_Number[] = $row['PO_Number'];
		$get_Date[] = $row['Date'];
		$get_Amount[] = $row['Amount'];
		$len++;		
		//$test[] = $row['Amount'];
		$resp_payment = array('PO_Number' => $get_PO_Number, 'Date' => $get_Date, 'Amount' => $get_Amount, 'len' => $len);
     }
}
else{
	$resp_payment = array('len' => $len);
}	
	 	 	 
	 //$sukses = "sukses";
	 //$res = array("result" => $sukses);
	 $res = array("result" => $resp_payment);
	 echo json_encode($res);	     
?>
