 <?php
	include 'inc/conx.php';
	
	$invoice = (trim($_POST['invoice']));
	
	$q = "SELECT SUM(total) AS SUMTOTAL FROM expiries WHERE invoiceNo = '".$invoice."'";
	$r = $db->query($q);
	$row = $r->fetchArray();

	$update = $db->query("UPDATE expiries SET subtotal = '".$row['SUMTOTAL']."', grand_total = '".$row['SUMTOTAL']."', remaining = '".$row['SUMTOTAL']."' WHERE invoiceNo = '".$invoice."'");

	$q = "SELECT subtotal, grand_total, remaining FROM expiries WHERE invoiceNo = '".$invoice."'";
	$r = $db->query($q);
	$row = $r->fetchArray();
	
	//$totals = array();
	//array_push($totals, $row['SUMTOTAL']);
	echo json_encode($row);
	die();


?>