<?php require('../db/db.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/print.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <link rel="shortcut icon" href="../images/favicon.png">
    <title>Med2TEC Hospital Management Information System</title> 
    <link href="../css/print.css" rel="stylesheet">
    <link href="../datepicker/jquery-ui.css" rel="stylesheet" >  
    <script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="../datepicker/jquery-ui.js"></script> 
</head>

<body> 
<div align="right"> 
 <SCRIPT LANGUAGE="JavaScript">  
if (window.print) {
document.write('<form class="no-print"><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script></div>

<section class="wrapper">
<div style="background:#FFF; padding:0px 0px 0; height:auto;">
  <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
    <tbody>
      <tr>
        <td align="left" style="background:#fff;"><img alt="" src="../images/org_print_logos/<?php echo $_SESSION['security']['org_id']?>.png" style="width:100%;"></td>
      </tr>
    </tbody>
  </table>
  
</br>

</div>

<div class="row">
          <section class="panel">
            <header class="panel-heading">
              <h2><!-- InstanceBeginEditable name="title" -->SALE INVOICES<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <div class="content">

   <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
          <p align="right">
  <SCRIPT LANGUAGE="JavaScript"> 
if (window.print) {
document.write('<form class="no-print"><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script></p>
  
  <tr>
    <td align="right"><table width="100%" border="0" cellspacing="1" cellpadding="1" class="bottomBorder">
      <tr>
        <td valign="bottom"><h1>PRODUCTS INVENTORY</h1></td>
        <td align="right" valign="top"> </td>
      </tr>
	  <tr> </tr>
      </table></td>
  </tr>
 
  <tr>
    <td width="511"><table width="100%">
      
      
      <tr>
        <td>
        <table width="100%" class="bottomBorder">
          <tr>
            <th width="3%" align="center">ID</th>
            <th width="15%" align="left">Product Name</th>
            <th width="7%" align="center">Product Type</th>
            <th width="10%" align="center">Products Received</th>
            <th width="10%" align="center">Products Sold</th>
            <th width="10%" align="center">Unit Qty in Stock</th>
            <th width="10%" align="right">Unit Price</th>
            <th width="10%" align="right">Leaf Price</th>
            <th width="10%" align="right">Box Price</th>
            <th width="15%" align="right">Stock Price</th>
          </tr><?php
			
			$min_length = 1;
			if(isset($_POST['search'])&&$_POST['search']!="")
			{
				 $search = $_POST['search']; 
$raw_results = mysql_query("SELECT * FROM products WHERE (product_name LIKE '%".$search."%') OR (category LIKE '%".$search."%') OR (medicine_type LIKE '%".$search."%') order by product_name asc") or die(mysql_error()); 
			}
			
			else
			{
				$raw_results = mysql_query("SELECT * FROM products order by product_name asc") or die(mysql_error()); 
			}
			
			if(mysql_num_rows($raw_results) > 0)
			{
				while($row = mysql_fetch_array($raw_results))
				{ 
					$product_id=$row['product_id'];
					$unit_qtyinstock=$row['unit_qtyinstock'];
					
					$queryForProductRecItems = mysql_query("SELECT SUM(unitqty_recieved) FROM product_recitems WHERE product_id = '$product_id'  GROUP BY product_id") or die(mysql_error()); 
					$rowOfRecItems = mysql_fetch_assoc($queryForProductRecItems);
					
					$queryForProductSaleItems = mysql_query("SELECT SUM(unitsaleqty) FROM product_saleitems WHERE product_id = '$product_id' GROUP BY product_id") or die(mysql_error()); 
					$rowOfSaleItems = mysql_fetch_assoc($queryForProductSaleItems);
					
					//$raw_result5 = mysql_query("SELECT * FROM product_closingitems where product_id='$product_id' GROUP BY product_id") or die(mysql_error()); 
//					$row5 = mysql_fetch_array($raw_result5);
//					
//					$phy_count=$row5['closingcount'];	
					
					?>
					
					<tr> 
					
                        <td align="center"><?php echo $row['product_id'];?><p></td>
                        <td align="left"><?php echo $row['product_name'];?><p></td>
                        <td align="left"><?php echo $row['medicine_type'];?><p></td>
                        
                        <td align="center"><?php echo $rowOfRecItems['SUM(unitqty_recieved)']; ?> <p></td>
                        
                        <td align="center"><?php  echo $rowOfSaleItems['SUM(unitsaleqty)']; ?><p></td>
                        
                        <td align="center"><?php echo $row['unit_qtyinstock'];?><p></td>
                        
                        <td align="right">Rs. <?php echo number_format($unit_price=$row['unit_retailprice'],2); ?><p></td>
                        <td align="right">Rs. <?php echo number_format($row['leaf_retailprice'],2); ?><p></td>
                        <td align="right">Rs. <?php echo number_format($row['box_retailprice'],2); ?><p></td>
                        <td align="right">Rs. <?php  echo number_format($unit_price*$row['unit_qtyinstock'],2);?><p></td>
					
					</tr>
					<?php 
				} 
			}  
			else
			{ 
				?>
				<tr> <h2> <span style="float:left; color:red;">  No Products Found  </span> </h2> </tr>
				<?php 
            } 
			?> 
          </table></td>
      </tr>
      <tr>
        <td></td>
      </tr>  
      </table></td>
  </tr>
  </table
></form>
  </div>
  <!-- InstanceEndEditable -->
</section>
</div>

<!--<p align="center" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; margin-top:260px;"><strong><!--317 A-1, Nursery Stop, Township, Lahore. 
Ph: 042-35151666</strong><br />
For Appointment call at 042-35151666 (bring your Patient ID Card) </p>-->

   <div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color: rgb(0, 0, 0); text-align: right; font-size: 10px; margin-top: 4px; position: absolute; right: 180px;">© Software by Softusion Inc. 0322 6155 219</div>   
    </div>
</div>

<!--<div class="sidepop" style="float:right;">
    <div class="sidepopbutton stemp"><div style="color:#000; text-align:right; font-size:9px;">© Software designed by Softusion Inc. Contact us at 0322 6155 219</div>   
    </div>
</div>-->


          
</body>
<!-- InstanceEnd --></html>
