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



$userid=$_SESSION["userid"];
$invid=$_POST["invid"];
$size = count($_POST['saleqty']);

$i = 0;
while ($i < $size) {
	$saleqty= $_POST['saleqty'][$i];
	
	$invitemid = $_POST['invitemid'][$i];
	$inv_no= $_POST['inv_no'][$i];
	
	$item_name= $_POST['item_name'][$i];
	$srate= $_POST['retail_price'][$i];
	echo $item_name;
	
	 $sql5 = "SELECT * FROM invoice_details where id = '$id' and  user_id='$userid'";
$result5=$conn->query($sql5);
$row5 = $result5->fetch_assoc();

   $prate=$row5['prate'] ;
	 $netamount=$saleqty * $srate;
	 $totalpamount=$sale_qty * $prate;
$totaldiff=$netamount - $totalpamount;


	
	
 	
	$sql1 = "UPDATE invoice_details SET srate='$srate',qty='$saleqty',amount='$netamount' ,pamount='$totalpamount',diff='$totaldiff' WHERE id='$id'";
$conn->query($sql1);

$tnetamount = $tnetamount + $netamount;
	
	++$i;
$sql2 = "UPDATE invoice SET netamount='$tnetamount' WHERE id='$invid'";
$conn->query($sql2);
// do the update and print out some info just to provide some visual feedback



} 

?>
