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

date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;
		 $t=time();
$username=$_SESSION["username"];
$userid=$_SESSION["userid"];
$invid=$_POST["invid"];


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

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

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


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

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


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

?>
