<?php
session_start();
include 'dbc.php';



$userid=$_SESSION["userid"];

$size = count($_POST['saleqty']);

$i = 0;
while ($i < $size) {
	$saleqty= $_POST['saleqty'][$i];
	
	$id = $_POST['id'][$i];
	$inv_no= $_POST['inv_no'][$i];
	
	$item_name= $_POST['item_name'][$i];
	$srate= $_POST['srate'][$i];
	$inv_no= $_POST['inv_no'][$i];
	$st= $_POST['st'][$i];
	$barcode= $_POST['barcode'][$i];

											$amount=$saleqty * $srate;
											$disamount=$amount * $st / 100;
											$netamount=$amount - $disamount;
	
 	
	$sql1 = "UPDATE invoice_details1 SET srate='$srate',qty='$saleqty',amount='$amount',st='$st',stamount='$disamount',netamount='$netamount' WHERE id='$id'";
$conn->query($sql1);

$tamount = $tamount + $amount;
$tdisamount = $tdisamount + $disamount;
$tnetamount = $tnetamount + $netamount;
	
	++$i;
$sql2 = "UPDATE invoice1 SET netamount='$tamount',discount='$tdisamount',gamount='$tnetamount' WHERE id='$inv_no'";
$conn->query($sql2);
// do the update and print out some info just to provide some visual feedback



} 
header("location:Open_Invoice.php");

?>
