<?php ob_start();
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');

?>
<style>
body{font-family:Arial, Helvetica, sans-serif; font-size:10px!important;}
	.caps
	{
		text-transform: uppercase;
	}
</style>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
	
       var e = document.getElementById(id);
	       e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
</script>
<body>
<table align="center" border="0" width="100%" cellpadding="0" cellspacing="0" style="">
	<tr>
    	<td width="15%"><img src="css/professional/images/webtech_logo.jpg" width="200" height="75" /></td>
    	<td width="70%"><table border="0" align="center" width="90%">
	<tr>
		<td><div align="center" style="font-size:28px; font-weight:bold;">Stock Summary</div></td>
	</tr>
	
</table></td>
<td width="15%">&nbsp;</td>
	</tr>
</table>
<form action="" method="post">
<div style="border:2px solid #000;  -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px;">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
	<table width="100%" border="0" style="border-bottom:1px solid #000;" align="center" cellpadding="0" cellspacing="0">
    <tr>
	<td valign="top" width="50%" style="border-right:1px solid #000;">
		<table width="100%" border="0" cellspacing="0" cellpadding="5"><tr>
    	          <td width="16%" height="40"><strong>Company Name</strong></td>
    	          <td width="45%">Webtech Packing India Pvt Ltd</td>
    	          <td width="15%" style="text-align:right;"><strong>Date From</strong></td>
    	          <td width="24%"><?php echo $_SESSION['frmdate']; ?>  <strong>To</strong> <?php echo $_SESSION['todate']; ?></td>
                </tr>
  	        </table></td>
   	      </tr>
    	    <tr>
    	      <td><table width="100%" border="0" cellspacing="1" cellpadding="2" class="lvt" bgcolor="#CCCCCC" style="border:1px solid #FFF;">
    	        <tr>
    	        <td width="8%" height="30" align="center" style="border-right:1px solid #FFF; text-align:center;"><strong>SL. No.</strong></td>
    	        <td width="14%" height="30" align="center" style="border-right:1px solid #FFF; text-align:center;"><strong>Item Code</strong></td>
    	          <td width="25%" height="30" align="center" style="border-right:1px solid #FFF; text-align:center;"><strong>Item Description</strong></td>
    	          <td width="15%" align="center" style="border-right:1px solid #FFF; text-align:center;"><strong>Rate</strong></td>
    	          <td width="14%" align="center" style="border-right:1px solid #FFF; text-align:center;"><strong>Closing Stock Qty</strong></td>
    	          <td width="14%" align="center" style="text-align:center;"> <strong>Closing Stock Value</strong></td>
   	            </tr>
   	            <?php
   	            $i=0;
			    $totalamount=0;
				 $query1=$_SESSION['query1'];
				 $query=DB_query($query1,$db);
				while($item_row=DB_fetch_array($query))
				{					
				$sql=DB_query("select item_rate from purchase_bill_details where item_code='".$item_row['itemcode']."' ORDER BY id DESC ",$db);	
				$rowdata=DB_fetch_array($sql);
				if($rowdata['item_rate']!='')
				{
				$rate=$rowdata['item_rate'];	
				}
				else 
				{
				$rate=$item_row['itemprice'];	
				}
				$total=$item_row['stockbalance']*$rate;	 
					$i++;  
					 $totalamount=$totalamount+$total;
					?>
				 <tr bgcolor="#FFFFFF">
    	          <td><?php echo $i; ?></td>
    	          <td><?php echo $item_row['itemcode']; ?></td>
    	          <td><?php echo $item_row['description']; ?></td>
    	          <td><?php echo $rate; ?></td>
    	          <td><?php echo $item_row['stockbalance']; ?></td>
    	          <td><?php echo $total; ?></td>
   	            </tr>
              <?php } ?>
              <tr bgcolor="#FFFFFF">
    	          <td ></td>
    	          <td ></td>
    	          <td ></td>
    	          <td ></td>
    	          <th>Total</th>
    	          <td><?php echo $totalamount; ?></td>
   	            </tr>
   	            <?php ?>
        </table>
	</td>
     </tr>
	</table>
    </td>
  </tr></table>
<div id="foo"><p align="center">
  <a href="#" onClick="javascript:toggle_visibility('foo');" >Print</a></p>
</div> 
</form>
</div>