<?php

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

		$_SESSION['FromCust'] = $_POST['FromCust'];
	
	$FromCust= $_SESSION['FromCust'];




	/*now get all the outstanding transaction ie Settled=0 */
		
		$sql = "SELECT systypes.typename,
					debtortrans.transno,
					debtortrans.trandate,
					debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst as total,
					debtortrans.alloc,
					debtortrans.ovamount+debtortrans.ovdiscount+debtortrans.ovfreight+debtortrans.ovgst-debtortrans.alloc as ostdg
				FROM debtortrans INNER JOIN systypes
					ON debtortrans.type=systypes.typeid
				WHERE debtortrans.account_number='" . $FromCust. "'
				
				ORDER BY debtortrans.id";

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

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

				$DisplayAlloc = $myrow['alloc'];
				$DisplayOutstanding = $myrow['ostdg'];

				$typename= $myrow['typename'];
				$invoicenumber=$myrow['transno'];
				$date= $myrow['trandate'];

			
					$DisplayTotal = $myrow['total'];
					

			
	 $rowarray = array(
 		"Type"=> $typename,
 		"No"=> $invoicenumber,
 		"Date"=>$date,
		 "TotalInvoice"=> $DisplayTotal,
		 "Allocated"=> $DisplayAlloc,
 		"Outstanding"=> $DisplayOutstanding
 	);	
 	$returnarray[] = $rowarray;
		
		


			} //end while there are outstanding transaction to print

echo json_encode($returnarray);

//echo $FromCust;

 exit;



?>
