<?php include("../../include/dbconnect.php"); 


		$myresult = mysqli_query($conn,"select prodcode,account_year,trans_id,bed,edcess,hs_cess from trading where record = '$record' ") or die(mysqli_error());
		$myrow = mysqli_fetch_row($myresult);
		$prodcode = $myrow[0];
		$account_year = $myrow[1];
		$trans_id = $myrow[2];
		$bed = $myrow[3];
		$edcess =$myrow[4];
		$hs_cess = $myrow[5];



if ( isset($submit) && $submit == "Update")
{

		if($capacity >0)
		{
			$actualvalue = $capacity * $rate * $qty;
			$discount_amt = round($actualvalue * $discount /100,2);
			$value = $actualvalue - $discount_amt;
		}
		else
		{
			$actualvalue = $rate * $qty;
			$discount_amt = round($actualvalue * $discount /100,2);
			$value = $actualvalue - $discount_amt;
		
		}


		if($bed >0)
		{
			$val1=$bed;
		}
		if($edcess>0)
		{
			$val2 = $bed*$edcess/100;
		}
		if($hscess>0)
		{
			$val3 = $bed*$hscess/100;
		}
		$divider = 100+$val1+$val2+$val3;	
			
		if($divider >0)
		{	
			$assess_value = $value *100/$divider;
		}
		else
		{
			$assess_value = $value;
		}

		
		$dutyamt = $assess_value * $bed /100;
		$edcessamt = $dutyamt * $edcess /100;
		$hcessamt = $dutyamt *$hscess /100;

		
		$val = $value +$discount_amt;
	    $result=mysqli_query($conn,"update trading set quantity = '$qty',capacity = '$capacity',rate = '$rate',remarks = '$remarks',discount = '$discount', discount_amt='$discount_amt', value='$val',assess_value = '$assess_value',bed_amt = '$bed_amt',edcess_amt = '$edcess_amt',hscess_amt = '$hscess_amt' where record ='$record'") or die(mysqli_error());
		$query="update stktrans set outqty='$qty',  remarks='$nar' where trans_id='$trans_id' and account_year = '$account_year' and acctcode = '$prodcode' ";
		mysqli_query($conn,$query) or die (mysqli_error());			




}

?>
<meta http-equiv="refresh" content="0 url=editview.php?record=<?=$srec?>">
