<?php 
include("../../include/dbconnect.php");
?>
<SCRIPT LANGUAGE="JavaScript" src="../../include/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>

<title> Transaction  details edit</title>
<body bgcolor="#ffffff"  topmargin=0>
<center>
<table border=0 cellpadding=3 cellspacing=4 width="590">

<form name="myform2" method="POST"  action="update.php?record=<?echo($record);?>">

<?  

//echo("select trading.record,   trading.compcode, buy.name, trading.invno, trading.invdate,  trading.taxtype, salestax.description, trading.cenvat_type, excise.commodity, trading.bed, trading.bed_amt, trading.edcess, trading.edcess_amt, trading.hs_cess, trading.hscess_amt, trading.vat_percent, trading.vat_amount, trading.vat_cess, trading.vatcess_amt, trading.freight, trading.total, trading.trans_id, trading.address, trading.vehicle_no, trading.bcode, trading.compcode, trading.remarks from trading, buy, salestax, excise where trading.record ='$record' and trading.taxtype=salestax.taxtype and trading.cenvat_type=excise.tariff and trading.bcode=buy.bcode <br>");

$result=mysqli_query($conn,"select trading.record,   trading.compcode, buy.name, trading.invno, trading.invdate,  trading.taxtype, salestax.description, trading.cenvat_type, excise.commodity, trading.bed, trading.bed_amt, trading.edcess, trading.edcess_amt, trading.hs_cess, trading.hscess_amt, trading.vat_percent, trading.vat_amount, trading.vat_cess, trading.vatcess_amt, trading.freight, trading.total, trading.trans_id, trading.address, trading.vehicle_no, trading.bcode, trading.compcode, trading.remarks,trading.prepare_date,trading.removal_date,trading.po_no,trading.prepare_time,trading.remove_time,account_year from trading, buy, salestax, excise where trading.record ='$record'  and trading.bcode=buy.bcode ") or die(mysqli_error());
$row=mysqli_fetch_row($result);
$trans_id=$row[21];
$bcode=$row[24];
$taxtype = $row[5];
$prepare_date = $row[27];
$removal_date = $row[28];
$saletype = $row[29];
$prepare_time = $row[30];
$removal_time = $row[31];
$account_year = $row[32];
$myresult = mysqli_query($conn,"select reserved_word from salestax where taxtype = '$row[5]'") or die(mysqli_error());
$myrow = mysqli_fetch_row($myresult);
$tax_description = $myrow[0];


$myresult = mysqli_query($conn,"select commodity  from excise where tariff = '$row[7]'") or die(mysqli_error());
$myrow = mysqli_fetch_row($myresult);
$duty_description = $myrow[0];


?>

<table border=0 cellpadding=3 cellspacing=4 width="631" bgcolor="#E6E6FF">
  <tr> 
    <td  colspan="100%"  bgcolor="#93BEE2"><font face="Arial, Helvetica, sans-serif"><b>Edit 
      Trading Invoice</b></font><font face="Verdana, Arial, Helvetica, sans-serif"><b>  </b></font></td>
  </tr>


<tr > 
<td width="42" height="31" align="right" ><div align="left"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Company &nbsp;</b></font></div></td>
<td width="144"><input type="text" onKeyPress="return event.keyCode!=13" name="name" value="<? echo($row[1]); ?>" readonly></td>

<td width="42" height="31" align="right" ><div align="left"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Customer &nbsp;</b></font></div></td>
<td width="144"><input type="text" onKeyPress="return event.keyCode!=13" name="name" value="<? echo($row[2]); ?>" readonly></td>
</tr>

<tr>
<td  width="59" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Tax Type      &nbsp;</b></font></td>
<td width="144"><input type="text" onKeyPress="return event.keyCode!=13" name="tax_description" value="<? echo($tax_description); ?>" readonly></td>


<td width="42" align="right"><div align="left"><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Cenvat </b></font></div></td>
<td width="144"><input type="text"  readonly onKeyPress="return event.keyCode!=13" name="cenv" value="<? echo($duty_description); ?>"></td>
</tr>
<input type="hidden" name="taxtype" value="<?=$taxtype?>">
</table>

<table width="729">
  <tr  bgcolor="#A4A4FF">

<td width="48" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Modify&nbsp;</b></font></td>
<td width="259" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Product &nbsp;</b></font></td>

<td width="71" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Qty &nbsp;</b></font></td>
<td width="73" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Capacity</b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Rate </b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Discount </b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Discount Amt</b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Value </b></font></td>
<td width="104" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Description </b></font></td>
</tr>

<?
//$result1="select trading.record,   trading.prodcode, product.prodname, trading.quantity, trading.capacity,  trading.rate, trading.discount, trading.discount_amt, trading.value, trading.remarks from trading, product where trading.trans_id ='$trans_id' and trading.prodcode != 'TOTAL' and trading.prodcode=product.prodcode ";
//echo "$result1";

$result1=mysqli_query($conn,"select trading.record,   trading.prodcode, product.prodname, trading.quantity, trading.capacity,  trading.rate, trading.discount, trading.discount_amt, trading.value, trading.remarks from trading, product where trading.trans_id ='$trans_id' and trading.prodcode != 'TOTAL' and trading.prodcode=product.prodcode and account_year = '$account_year' ") or die(mysqli_error());



while($row1 = mysqli_fetch_row($result1))
{

	$record = $row1[0];
	$prodcode = $row1[1];
	$prodname = $row1[2];
	$qty = $row1[3];
	$capacity = $row1[4];
	$rate = $row1[5];
	$discount = $row1[6];
	$remarks = $row1[9];
	if($capacity >0)
	{
		$actualvalue = round($capacity * $rate * $qty,2);
		$disamt = round($actualvalue * $discount /100,2);
		$value = $actualvalue - $disamt;
	}
	else
	{
		$actualvalue = round($rate * $qty,2);
		$disamt = round($actualvalue * $discount /100,2);
		$value = $actualvalue - $disamt;
		
	}
	$gtotal = $gtotal + $actualvalue;
	$gdisc = $gdisc +$disamt;

	//$gtotal = $gtotal + $value;

?>
<tr  bgcolor="#D7D7FF">
<td width="48" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><a href = "peditview1.php?record=<?echo($record);?>&srecord=<?echo($row[0]);?>"><?echo($record);?></a></b></font></td>
<td width="259" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$prodname?></b></font></td>
<td width="71" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$qty?></b></font></td>
<td width="73" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$capacity;?></b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$rate?></b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$discount?></b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$disamt?></b></font></td>
<td width="94" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$value?></b></font></td>
<td width="104" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$remarks?></b></font></td>
</tr>

<?
}
?>

<tr  bgcolor="#D7D7FF">
<td  colspan="5" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Total</b></font></td>
<td width="79" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$gtotal?></b></font></td>
<td width="50" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$gdisc?></b></font></td>
<td width="81" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$gtotal-$gdisc?></b></font></td>
<td width="115" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$remarks?></b></font></td>

<?
$totalvalue=$gtotal - $gdisc;

$tresult = mysqli_query($conn,"select tax,cess from salestax where taxtype = '$row[5]' ") or die(mysqli_error());
$trow = mysqli_fetch_row($tresult);
$stax = $trow[0];
$stcess = $trow[1];

$cresult = mysqli_query($conn,"select bed,cess,hcess from excise where tariff = '$row[7]' ") or die(mysqli_error());
$crow = mysqli_fetch_row($cresult);
$bed = $crow[0];
$edcess = $crow[1];
$hscess = $crow[2];

		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)
		{	
			$assesstotal = $totalvalue *100/$divider;
		}
		else
		{
			$assesstotal = $totalvalue;
		}

	 



$dutyamt = $assesstotal * $bed /100;
$edcess = $dutyamt * $edcess /100;
$hcess = $dutyamt *$hscess /100;
$subtotal = round($assesstotal + $dutyamt + $edcess + $hcess,2);

$stamt = round($subtotal * $stax /100,2);
$stcessamt = round($stamt * $stcess/100,2);
$netamt = $subtotal + $stamt + $stcessamt;


?>

<tr bgcolor="#D7D7FF">
<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Assesable Value</b></font></td>
<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($assesstotal,2,'.','')?></b></font></td><td>&nbsp;</td>
</tr>

<?
if($dutyamt > 0)
{

	?>
	<tr bgcolor="#D7D7FF">
	<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Duty Amount</b></font></td>
	<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($dutyamt,2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}

if($edcess > 0)
{
	?>
	<tr bgcolor="#D7D7FF">
	<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Educational Cess</b></font></td>
	<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($edcess,2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
if($hcess > 0)
{
	?>
	<tr bgcolor="#D7D7FF">
	<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>H.Secondary Cess</b></font></td>
	<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($hcess,2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
if($dutyamt > 0)
{
?>
	<tr bgcolor="#D7D7FF">
	<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Sub Total</b></font></td>
	<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($subtotal,2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>
<?
}
if($stamt > 0)
{
	?>
	<tr bgcolor="#D7D7FF">
	<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Vat Amount</b></font></td>
	<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($stamt,2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
if($stcessamt > 0)
{
	?>
	<tr bgcolor="#D7D7FF">
	<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Vat Cess </b></font></td>
	<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($stcessamt,2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
?>
<tr bgcolor="#D7D7FF">
<td  colspan="7"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Net Amount</b></font></td>
<td width="94"  align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($netamt,2,'.','')?></b></font></td><td>&nbsp;</td>
</tr>


</table>
<table width="682">

<tr > 
<?
	if($myBuyer == '0')
	{
	?>
	<tr>
	 <td width="50" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Local Customer Name and address
        </b></font></td>
		<td><textarea rows="5" cols="30" name="address" ></textarea></td><tr>
  
	<?
	}

?>		
		<td width="99" height="31" align="right" ><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Trading Invoice No
		  &nbsp;</font></b></font></div></td>
		<td width="125" > <input type="text"  size="10" onKeyPress="return event.keyCode!=13" name="bill_no" value= "<? echo($row[3]); ?>" >		</td>


    <? $tddt=$row[4];
	$tddt = substr($tddt,8,2).'/'.substr($tddt,5,2).'/'.substr($tddt,0,4);?>
    <td width="61"  align="left"><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Bill   Date &nbsp;</font></b></font> </div></td>
    <td width="159" class="small_site_font_black" ><input name="tddt" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="<?=$tddt?>" size="10"   >
      <a href="#" onClick="cal.select(document.myform2.tddt,'anchor1','dd/MM/yyyy'); return false;"name="anchor1" id="anchor1"><img  src="../../images/cal.gif" border="0"></a> </td>

		
<?
		$query_3 = mysqli_query($conn,"SELECT acctcode, trans_id, account_year, record from ledger where trans_id='$row[21]' and acctcode='$cashcode'")or die(mysqli_error());
$row7=mysqli_fetch_row($query_3);
?>
		
    <td width="99" height="31" align="right" colspan="1" ><div align="left"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Mode</font></b></font> </div></td>
    <td width="125" ><?
if ($saletype == 'Cash')
{
?>
        <input name="salemode" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="Cash" size="10"  readonly >
        <?
}
else
{
?>
        <input name="salemode" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="Credit" size="10" readonly  >
        <?
}
//echo "$prodname";
//echo "$row[24]";
?>
</td>
</tr>
<input type="hidden" name="gtotal" value="<? echo($gtotal); ?>">
<input type="hidden" name="gdisc" value="<? echo($gdisc); ?>">
<input type="hidden" name="bcode" value="<? echo($row[24]); ?>">
<input type="hidden" name="compcode" value="<? echo($row[25]); ?>">
<input type="hidden" name="trans_id" value="<? echo($row[21]); ?>">
<input type="hidden" name="prodname" value="<? echo($prodname); ?>">
<input type="hidden" name="dutyamt" value="<? echo($dutyamt); ?>">
<input type="hidden" name="edcess" value="<? echo($edcess); ?>">
<input type="hidden" name="hcess" value="<? echo($hcess); ?>">
<input type="hidden" name="subtotal" value="<? echo($subtotal); ?>">
<input type="hidden" name="stamt" value="<? echo($stamt); ?>">
<input type="hidden" name="stcessamt" value="<? echo($stcessamt); ?>">
<input type="hidden" name="netamt" value="<? echo($netamt); ?>">

		<tr > 
	<td width="85"  align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Date and Time of Preparation
      </font></b></font></td>
		<td width="125" class="small_site_font_black" > 
		<?
		
		$prepdate=british($prepare_date); ?>
		<input name="prepdate" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="<?=$prepdate?>" size="10"   > 
		<a href="#" onClick="cal.select(document.myform2.prepdate,'anchor1','dd/MM/yyyy'); return false;"name="anchor1" id="anchor1"><img  src="../../images/cal.gif" border="0"></a>		<input name="preptime" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="<?=$prepare_time?>" size="10"   > 		</td>
	  

	<td width="85"  align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Date and Time of Removal
      </font></b></font></td>
		<td width="125" class="small_site_font_black" > 
		<?
		
		$remdate=british($removal_date); ?>
		<input name="remdate" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="<?=$remdate?>" size="10"   > 
		<a href="#" onClick="cal.select(document.myform2.remdate,'anchor1','dd/MM/yyyy'); return false;"name="anchor1" id="anchor1"><img  src="../../images/cal.gif" border="0"></a>		<input name="remtime" type="text" onKeyPress="return event.keyCode!=13" class="text_box_button" value="<?=$removal_time?>" size="10"   > 		</td>


		<td width="99" height="31" align="right" ><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Vehicle  No
		  &nbsp;</font></b></font></div></td>
		<td width="125" > <input type="text"  size="10" onKeyPress="return event.keyCode!=13" name="vehicle_no" value= '<?echo($row[23]);?>' >		</td>


		</tr>		


</table>

<tr><blockquote>

<td align=right>
   <input  type =submit name=submit value = "Update"></td> <td><input type =submit name=submit value = "Delete"></blockquote>



                                                                             
</body>
</form>
