<body background="../forms/i.jpg">
<script language="javascript">
function check()
{
	if(myform2.myCompany.value=="")
	{
		alert("Please select Company");
		myform2.myCompany.focus();
		return false;
	}	
	if(myform2.Invno.value=="0")
	{
		alert("Please select Company");
		myform2.Invno.focus();
		return false;
	}	
	if(myform2.myDate.value=="")
	{
		alert("Please select Company");
		myform2.myDate.focus();
		return false;
	}	

}
</script>

<?php include("../../include/dbconnect.php");
foreach($_POST as $q=>$r)
{
	$_POST[$q] = trim($r);
}

$myDate = $_POST['Date'];

foreach($_POST as $p=>$t)
{
	$_POST[$p] = trim($t);
}
$myCompany = $_POST['Company'];

foreach($_POST as $a=>$b)
{
	$_POST[$a] = trim($b);
}
$myInvno = $_POST['Invno'];


$aresult = mysqli_query($conn,"select distinct account_year,name from company") or die(mysqli_error());
$arow = mysqli_fetch_row($aresult);
$account_year = $arow[0];

?>
<title>Trading Invoice Cancellation</title>
<center> 
<table border=0 cellpadding=3 cellspacing=4 width="724" bgcolor="#E6E6FF">
  <tr> 
    <td style="padding:3px;" colspan=2 bgcolor="#93BEE2"><font face="Verdana, Arial, Helvetica, sans-serif"><b><b>Trading Invoice Cancellation  </b></font></td>
  </tr>
<?
$result= mysqli_query($conn," select distinct compcode,name from company  order by name")or die( mysqli_error() );

?>
<form name='myform' method='POST' action='<?=$_SERVER['PHP_SELF']?>'>
<tr > 
    <td width="112" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Company 
      Type &nbsp;</b></font></td>
    <td width="174">

  <SELECT name='Company' onChange="javascript:submit();">
<?php 
	 echo "<option selected value=\" 0\"> Select Company";	  
      while ( $row1= mysqli_fetch_row($result))
      {
	  	if(isset($myCompany) && preg_match("/" . preg_quote($myCompany", '/') . "/", $row1[0]))
		{
			echo "<option selected value=\"$row1[0]\">$row1[1]";
	  	}
	  	else
	  	{
			echo "<option value=\"$row1[0]\">$row1[1]";
	  	}
	}
?>
</select>  
</td>
</tr>

<?
$result= mysqli_query($conn," select distinct invdate from trading where account_year = '$account_year' and compcode = '$myCompany'  order by invdate desc")or die( mysqli_error() );
?>
<tr > 
  <td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Date
    &nbsp;</b></font></td><td>
  <SELECT name='Date' onChange="javascript:submit();">
<?php 
	 echo "<option selected value=\" 0\"> Select Date";	  
      while ( $row1= mysqli_fetch_row($result))
      {
	  	$tmp = british($row1[0]);
	  	if(isset($myDate) && preg_match("/" . preg_quote($myDate", '/') . "/", $row1[0]))
		{
			echo "<option selected value=\"$row1[0]\">$tmp";
	  	}
	  	else
	  	{
			echo "<option value=\"$row1[0]\">$tmp";
	  	}
	}
?>
</select>  
</td></tr>

<tr >
<td width="139" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Trading Invoice No &nbsp;</b></font></td><td>
<?
$result = mysqli_query($conn,"SELECT distinct invno FROM trading WHERE (invdate ='$myDate') and compcode = '$myCompany'  order by compcode,invno ");
?>



<SELECT name='Invno' onChange="javascript:submit();"  >
<?
	 echo "<option selected value=\" 0\"> Select Invno";	  
      while ( $row1= mysqli_fetch_row($result))
      {
	  	$tmp = $row1[0];
	  	if(isset($Invno) && preg_match("/" . preg_quote($Invno", '/') . "/", $row1[0]))
		{
			echo "<option selected value=\"$row1[0]\">$tmp";
	  	}
	  	else
	  	{
			echo "<option value=\"$row1[0]\">$tmp";
	  	}
	}
?>
</SELECT></td></tr>

</form>

<form name='myform2' method='POST' action='inv_cancel_upd.php' onSubmit="return check()" >
<?

$res = mysqli_query($conn,"select trading.bcode, buy.name from trading, buy where trading.invno = '$Invno' and trading.account_year = '$account_year'  and trading.compcode = '$myCompany' and buy.bcode=trading.bcode")or die(mysqli_error());
$row2=mysqli_fetch_row($res);

?>
<tr>
		<td width="200" height="31" align="center" ><div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#003366">Customer Name
		  &nbsp;</font></b></font></div></td>
		<td width="125" > <input type="text"  size="50" onKeyPress="return event.keyCode!=13" name="bname" value= "<? echo($row2[1]); ?>" >		</td>
</tr>

<table width="729">
  <tr valign="top"> 
    <td colspan=2> <font >&nbsp;</font> </td>
  </tr>
<tr  bgcolor="#A4A4FF">

<td width="48" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Sl.No&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>


<?
$i=1;
$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, trading.trans_id from trading, product where trading.invno = '$Invno' and trading.account_year = '$account_year'  and trading.compcode = '$myCompany' and trading.prodcode=product.prodcode") 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];
	$disamt = $row1[7];
	$value = $row1[8];
	$remarks = $row1[9];
	$gtotal = $gtotal + $value;
	$transid = $row1[10];
?>
<tr  bgcolor="#D7D7FF">
<td width="48" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?echo($i);?></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>



<?
$i = $i + 1;
}


$result=mysqli_query($conn,"select trading.record, trading.compcode, trading.bcode, buy.name, 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, account_year from trading, buy where trading.trans_id='$transid' and trading.prodcode='TOTAL'and buy.bcode=trading.bcode ") or die(mysqli_error());
$row=mysqli_fetch_row($result);
//echo "$row[17]";
$subtotal = $gtotal + $row[5] + $row[7]  + $row[9] ;

?>
<input type="hidden" name="trans_id" value=<?echo($row[16]);?>>
<input type="hidden" name="account_year" value=<?echo($row[17]);?>>

<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($gtotal,2,'.','')?></b></font></td><td>&nbsp;</td>
</tr>

<?
if($row[5] > 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($row[5],2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}

if($row[7]  > 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($row[7],2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
if($row[9]  > 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($row[9],2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
if($row[5]  > 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($row[11] > 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($row[11],2,'.','')?></b></font></td><td>&nbsp;</td>
	</tr>

<?
}
if($row[13]  > 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($row[13],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($row[15],2,'.','')?></b></font></td><td>&nbsp;</td>
</tr>

  <tr valign="top"> 
    <td colspan=2> <font >&nbsp;</font> </td>
  </tr>

</table>
<table width="682">
  <tr> 
    <td align="right" colspan="3" ><font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Confirm</b></font></td>
    <td> <input type="radio"    onKeyPress="return event.keyCode!=13"   name="cnf" value = "No" checked> <font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>No 
    </b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio"    onKeyPress="return event.keyCode!=13"   name="cnf" value = "Yes"> <font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Yes
      </b></font>&nbsp;</td>
  </tr> 
  <table cellpading=0 cellspacing=10 width= 50>
    <tr> 
      <td> <blockquote> <input type =submit name="cancel" value = "Cancel"></blockquote></td>
  </table>
</table>

 
</form>