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



if ( isset($submit) && $submit == "Update")
{
   $result=mysql_query("update expinv set invno='$invno',invdate='$invdate',compcode='$compcode',prodcode='$prodcode',drawing_no='$drawing_no',quantity='$quantity',rate='$rate',value='$value',invstatus='$invstatus',po_no='$po_no',po_date='$po_date',schedule_no='$schedule_no',schedule_date='$schedule_date',month='$month',year='$year',taxtype='$taxtype',duty_posted='$duty_posted',prepare_time='$prepare_time',remove_time='$remove_time',account_year='$account_year',packing_amt='0',bed_amt='0',cess_amt='0',vat_amount='0',freight='0',total='0',round_off='0',gtotal='0',packing_percent='$packing_percent',bed='$bed',cess='$cess',vat_percent='$vat_percent' where record ='$record' ") or die(mysql_error());

   $totvalue=0;
   $calresult = mysql_query("select quantity,rate,packing_percent,bed,cess,vat_percent,freight,record,drawing_no,cust_record from expinv where invno ='$invno' and account_year='$account_year' " ) or die(mysql_error());
   while($calrow = mysql_fetch_row($calresult))
   {
		$quantity = $calrow[0];
		$rate = $calrow[1];
		$uprecord = $calrow[7];
		$drawing_no = $calrow[8];
		$newvalue = $calrow[0]*$calrow[1];
  	    $totvalue=$totvalue+$newvalue;			
		 if($drawing_no=='TOTAL')
		 {
				$packing_percent = $calrow[2];
				$bed = $calrow[3];
				$cess = $calrow[4];
				$vat_percent= $calrow[5];
				$freight = $calrow[6];
				$amrecord = $calrow[7];
				$cust_record = $calrow[9];			
		 }
		 if($quantity >0)
		 {
			$query = "update expinv set value = '$newvalue' where record = '$uprecord' ";
			mysql_query($query) or die(mysql_error());
		 }	
	 }


	$packing_amt = $totvalue * $packing_percent/100;
	$assessable_value = $totvalue +$packing_amt;
	$bed_amt= round($assessable_value * $bed/100,0);
	$cess_amt = round($bed_amt * $cess/100,0);	
	$vat_app_value = $assessable_value+$bed_amt+$cess_amt;
	$vat_amount = $vat_app_value * $vat_percent /100;
	
	$total = $vat_app_value + $vat_amount+$freight;
	$gtotal = round($total,0);
	$round_off  = $gtotal - $total;

   $result=mysql_query("update expinv set value='$totvalue',packing_amt='$packing_amt',bed_amt='$bed_amt',cess_amt='$cess_amt',vat_amount='$vat_amount',freight='$freight',total='$total',round_off='$round_off',gtotal='$gtotal',packing_percent='$packing_percent',bed='$bed',cess='$cess',vat_percent='$vat_percent' where record ='$amrecord' ") or die(mysql_error());


  
   $result = mysql_query("update custledger set dbamt = '$gtotal' where record = '$cust_record' ") or die(mysql_error());

}
elseif (isset($submit) && $submit == "Delete")

{
$result=mysql_query("delete from expinv where record='$record'") or die(mysql_error());
}

?>
<table>
<tr><td colspan=4 align=middle>

<h4><a href="view_sele.php">View Sales Register Details  </a>


<br><br><font size=1><center><a href= "index.html">Return to index page</center></font></table>
