<?php

$connect = new mysqli("localhost", "sooggoo", "4Compassion*", "evergreenint"); 

		$_SESSION['ref'] = $_POST['ref'];
	
	$ref= $_SESSION['ref'];
//$_SESSION['date'] = $_POST['date'];
	
	//$date= $_SESSION['date'];



	/*now get all the outstanding transaction ie Settled=0 */
		
		$sql = "SELECT 
					banktrans.transno,
					banktrans.client_account_number,
					banktrans.banktranstype,
					banktrans.amount,
					banktrans.drawer_bank,
					banktrans.drawer_accountnumber,
					banktrans.drawer_chqnumber,
					debtoraccount.billing_name
				FROM banktrans INNER JOIN debtoraccount
				ON banktrans.client_account_number=debtoraccount.account_number
				WHERE banktrans.ref ='" . $ref. "'
				AND banktrans.type = 12
				
				
				";

		$OstdgTrans=mysqli_query($connect,$sql);

	  $returnarray = array();
$tamount =0;
	while ($myrow=mysqli_fetch_array($OstdgTrans)){

				$receiptno= $myrow['transno'];
				$account = $myrow['client_account_number'];
				$accountname = $myrow['billing_name'];
				
				$banktranstype= $myrow['banktranstype'];
				$amount= $myrow['amount'];
				$dbank= $myrow['drawer_bank'];
				$daccount= $myrow['drawer_accountnumber'];
				$dchq= $myrow['drawer_chqnumber'];

			
					

		$tamount += $amount;	
	 $rowarray = array(
 		"ReceiptNo"=> $receiptno,
 		"Account"=> $account,
 		"BillName"=>$accountname,
		 "PaymentType"=> $banktranstype,
		 "Amount"=> $amount,
 		"DBank"=> $dbank,
		 "DAccount"=> $daccount,
		 "DChq"=> $dchq,
		 "Tamount"=>$tamount
 	);	
 	$returnarray[] = $rowarray;
		
		


			} //end while there are outstanding transaction to print

echo json_encode($returnarray);

//echo $FromCust;

 exit;



?>
