<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
include('testword.php');
$query="select brname,braddr,brcity,tin,cstno from branch where brcode ='$brcode'";
$rs=mysqli_query($db,$query);
$brw=mysqli_fetch_array($rs);
$inno=$_REQUEST['inno'];
$rs=mysqli_query($db,"select * from brtransferout 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;
}
</style>
<body onload="window.print()" >

<div width=100%>           
 <form id="jforms" name="invoice_form" >
<table width=100% align='center' class='trcls'>
<tr><td align='center'>KERALA KHADI & VILLAGE INDUSTRIES BOARD</td>
</tr>
<tr><td align='center'><? echo $brw[1] ?></td></tr>
<tr><td align='center'><? echo $brw[2] ?></td></tr>
<tr><td align='center'></td></tr>
<tr><td align='center'></td></tr>
<tr><td align='right'>KGST No.: </td></tr>
<tr><td align='right'>CST No.:<? echo $brw[4] ?> </td></tr>
<tr><td align='right'>TIN :<? echo $brw[3] ?> </td></tr>
<?
$invdate=date('d-m-Y', strtotime($rw[1]));
?>
<tr><td align='left'>Date : <? echo $invdate ?> </td></tr>
<tr><td align='left'>Invoice No. : <? echo $rw[0] ?></td></tr>
<tr><td align='left'>From : </td><td align='left'>To : </td></tr>
<?
$qr=mysqli_query($db,"select * from branch where brname='$rw[2]'");
$qw=mysqli_fetch_array($qr);
?>

<table width=100% align='center' class='trcls'>

<tr> <td> <? echo $brw[0] ?> </td> <td align="right"> <? echo $rw[2] ?> </td> </tr>
<tr><td></td><td align="right"><? echo $qw[3] ?>&nbsp;<? echo $qw[4] ?></td></tr>

</table>

<table width=100%   align='center' class='tbl1' border='1'>
<tr ><td>SL No.</td><td>STOCK No</td><td>Particulars</td><td>Qty</td><td>Rate</td><td>Amount</td></tr>
<?
$slno=1;
$query=mysqli_query($db,"select * from brtransferout 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);
$grandamt=$ntvl+$taxamount+$margin+$row[24]+$row[25];
?>
<tr><td><? echo $slno++ ?></td><td><? echo $row[5] ?></td><td><? echo $row[4] ?></td><td><? echo $row[7] ?></td><td><? echo $row[8] ?></td><td><? echo $row[10] ?></td></tr>
<?
$netdisc+=$row[19];
$netval+=$ntvl;
$tottax+=$taxamount;
$totcomision+=$commission;
$totamt+=$grandamt;
$total+=$row[10];
}
$totamt=round($totamt,2);
?>
<tr><td colspan='4'>Gross Amount</td><td colspan='2'><? echo $total ?></td></tr>
<tr><td colspan='4'>Commission</td><td colspan='2'><? echo $totcomision ?></td></tr>
<tr><td colspan='4'>Net Amount</td><td colspan='2'><? echo $totamt ?></td></tr>

</table>
<br><br>
<table width=100% align='center' class='trcls'>


<tr><td>The above invoice will be prepared in triplicate by the officer of the centre. Two copies will be sent by</td></tr>
<tr><td>him to the recipient. The recipient will acknowledge receipt and return one copy to the sender</td></tr>
<tr><td>retaining the other for his record. The sender will keep up the acknowledgement.</td></tr>
<tr><td></td></tr>

<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='left'>Amount in words: <? echo word($totamt); ?> </td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'>Dispatch Bhavan Manager</td></tr>
<tr><td align='left'>Prepared By</td></tr>
<tr><td align='left'>Checked By</td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td>Received goods in good condition as per this bill ............................................................... Despatched by</td></tr>
<tr><td>Train/Lorry Service To ..........................................................Under R.R./Lorry Way Bill No ...................</td></tr>
<tr><td> Dated ......................... Against Order No  ..................................................Dated ......................................</td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'></td></tr>
<tr><td align='right'>Received</td></tr>
<tr><td align='right'>Signature With Date</td></tr>
</table>
</table>
</div>
 </form>
</body></html>
<?
}
?>