<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
$inno=$_REQUEST['inno'];
include('test.php');
//$rs=mysqli_query($db,"select * from prodinvoicewholesale where invno='$inno' and apprv_dt>'0000-00-00 00:00:00' and brcode='$brcode'");
$rs=mysqli_query($db,"select * from prodinvoicewholesale where invno='$inno' and brcode='$brcode'");
$rw=mysqli_fetch_array($rs);
$num=mysqli_num_rows($rs);
if($num>0)
{
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Kerala Khadi & Village Industries Board</title>	
<style>
.trcls
{
font-family:Calibri;
}	
.tbl1{
border: 0px solid black;
border-bottom:0px solid white;
font-family:Calibri;
border-collapse:collapse;
text-align:center;
margin-top:25px;

}
.tbl1 td{
border-bottom:1px solid black;
height:40px;
}
</style>
<body onload='window.print()'>		
<div width=100%>           
 <form id="jforms" name="invoice_form" >
<table width=100% align='center' class='trcls'>
<tr>
<td align='left'>TIN :
<?
$qry=mysqli_query($db,"select * from branch where brcode='$brcode'");
$reslt=mysqli_fetch_array($qry);
print $reslt[tin];
?>
</td>
</tr>
<tr>
<td align='left'>
</td>
</tr>
<tr><td align='center'>KERALA KHADI & VILLAGE INDUSTRIES BOARD</td>
</tr>
<tr><td align='center'><? echo $reslt[brname] ?></td></tr>
<tr><td align='center'><? echo $reslt[braddr] ?>&nbsp;<? echo $reslt[brcity] ?></td></tr>

<tr><td align='center'>KERALA VALUE ADDED TAX RULES, 2005</td></tr>
  <tr><td align='center'>FORM NO. 8 A</td></tr>
  <tr><td align='center'>TAX INVOICE</td></tr>
<table width=100% align='center' class='tbl1' border='1'>
<tr ><td>Invoice No</td><td>Delivery Note</td><td>Purchase Order</td><td>Despatch Doc No. & Date</td><td>Terms of Delivery</td></tr>
<tr><td><? echo $rw[0]."<br>".implode("-",array_reverse(explode("-",$rw[1]))) ?></td><td><? echo $rw[28] ?></td><td><? echo $rw[29] ?></td><td><? echo $rw[30] ?></td><td><? echo $rw[31] ?></td></tr>
</table>
<?
$qr=mysqli_query($db,"select * from customer where cname='$rw[2]'");
$qw=mysqli_fetch_array($qr);
?>
<br>
<br>
<table width=100% align='center' class='trcls'>
<tr><td>Name & Address of the Purchasing Dealer :</td></tr>
<tr>  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <? echo $rw[2] ?> </td> </tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<? echo $qw[6] ?>,&nbsp;<? echo $qw[7] ?></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TIN : &nbsp;<? echo $qw[tin] ?> </td><td></td><td></td><td>CST No. &nbsp;<? echo $rw[23] ?></td></tr>
</table>

<table width=100% align='center' class='tbl1' border='1'>
<tr ><td>Sl No.</td><td>Description</td><td>Item Code</td><td>Tax Rate</td><td>Unit Price</td></td><td>Qty</td></td><td>Gross Value</td></td><td>Cash Discount</td></td><td>Net Value</td></tr>
<?
$slno=1;
$pf_charge=0;
$oth_charge=0;
$net_tot = 0;
$net_comm = 0;
$net_mda = 0;
$query=mysqli_query($db,"select * from prodinvoicewholesale where invno='$inno' and brcode='$brcode'");

while($row=mysqli_fetch_array($query))
{
	$mda=($row[10])*($row[16]/100);
	$commission=($row[10])*($row[17]/100);
	$discount=($row[10])*($row[19]/100);
	$totdisc=$mda+$commission+$discount;
	$ntvl=$row[10]-$totdisc;
	$taxamount=$ntvl*($row[20]/100);
	$margin=$row[10]*($row[23]/100);
	$pf_charge = $row[24];
	$oth_charge = $row[25];
	$grandamt=$ntvl+$taxamount+$margin+$row[24]+$row[25];
	?>
	<tr><td><? echo $slno++ ?></td><td><? echo $row[4] ?></td><td><? echo $row[5] ?></td><td><? echo $row[20] ?></td><td><? echo $row[8] ?></td><td><? echo $row[7] ?></td><td><? echo $row[10] ?></td><td><? echo $row[19] ?></td><td><? echo $row[10] ?></td></tr>
	<?
	$netdisc+=$row[19];
	$netval+=$ntvl;
	$tottax+=$taxamount;
	$totamt+=$grandamt;
	$net_tot += $row[10];
	$net_comm += $commission;
	$net_mda += $mda;
}
$net_tot = round($net_tot,2);
?>
<tr><td colspan='7'>Total</td><td><? echo $netdisc ?></td><td><? echo $net_tot ?></td></tr>
</table>
<br><br>
<table width=100% align='center' class='trcls'>
<?
$net_comm = round($net_comm,2);
$net_mda = round($net_mda,2);
$tottax = round($tottax,2);
$pf_charge = round($pf_charge,2);
$oth_charge = round($oth_charge,2);
$bef_tax = $net_tot - $net_comm - $net_mda;
$nettot_amt = $bef_tax + $tottax + $pf_charge + $oth_charge;
$nettot_amt = round($nettot_amt,2);

print "<tr><td colspan='0'>Total : ".$net_tot."</td><td align='right'> Less Commission : ".$net_comm. " </td><td align='right'> Less MDA :".$net_mda."</td></tr>";
print "<tr><td>Before Tax : ".$bef_tax. "</td><td align='right'>  Tax : ".$tottax." </td><td align='right'>  P&F Charges : ".$pf_charge." </td><td align='right'>  Other Charges : ".$oth_charge."</td><td align='right'>"." </td><td align='right'> Net Amt : ".$nettot_amt."</td></tr>";
?>
</table>
<table width=100% align='center' class='trcls'>
<tr ><td>Rupees in words : <? echo word_new($nettot_amt) ?></td><tr>
<tr><td>E & OE</td></tr>
<tr><td align='center'>Goods once sold will not be taken back</td></tr>
<tr><td><u>DECLARATION</U></td></tr>
<tr><td>Certified that all the particulars shown in the above Tax Invoice are true and correct in all respects and the goods on which the tax charged and collected are in accordance with the provisions of the KVAT ACT 2003 and the rules made there under. It is also certified that my/our Registration under KVAT Act 2003 is not subject to any suspension/cancellation and it is valid as on the date of this Bill.</td></tr>

<tr><td align='right'>For : KERALA KHADI AND VILLAGE INDUSTRIES BOARD<br><br><br><br></td></tr>
<tr><td align='right'>Authorized Signatory</td></tr>
</table>
</div>
 </form>
</body></html>
<?
}
else
{
print "<script> alert('Approval required! Please contact your Project Manager!'); document.location='wholesale_printinv1.php' </script>";
  return;
}
?>


