<?php 
require('../db/db.php'); 
$day=date('d',time());
$month=date('m',time());
$year=date('Y',time());
$query = mysql_query("SELECT * FROM  users WHERE username = '$username'") or die(mysql_error()); 

while($row = mysql_fetch_assoc($query))
{
	$userrole=$row['userrole'];
}
?>
<!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="1" cellspacing="10">
  
  
  <tr>
    <td align="right"><table width="100%" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <td valign="bottom"><h1>PRODUCTS INVENTORY</h1></td>
        <td align="right" valign="top"> </td>
      </tr>
	  <tr> </tr>
      </table></td>
  </tr>
  <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
           
            <tr>
            	<td width="70%" >
                </td>
                
                <td width="30%">
                	<span class="message_blue"><strong>As at <?php echo date('d M Y',time()); ?></strong></span>
                
                    <table width="100%" border="0" cellpadding="1" cellspacing="5" class="information-box">
						<?php
                       $totalStockValue='';
					    $totalStockValue_retail='';
						
                        
							
                            $queryForProducts = mysql_query("SELECT * FROM products WHERE active=1 order by product_name asc") or die(mysql_error()); 
                       
						while($calculateStockValue = mysql_fetch_assoc($queryForProducts))
						{ 
							$totalStockValue += $calculateStockValue['unit_qtyinstock']*$calculateStockValue['unit_tradeprice'];
							
							$totalStockValue_retail += $calculateStockValue['unit_qtyinstock']*$calculateStockValue['unit_retailprice'];
							
							$product_id=$calculateStockValue['product_id'];
							$queryForClosingCount = "SELECT closingcount,closing_date FROM product_closingitems WHERE product_id = '$product_id' ORDER BY closing_date DESC Limit 1";
							$closingCountResult = mysql_query($queryForClosingCount) or die(mysql_error());
							if(mysql_num_rows($closingCountResult) > 0)
							{
								$closingCountArray = mysql_fetch_assoc($closingCountResult) or die(mysql_error());
								$closingCountshowInHeading = $closingCountArray['closing_date']; 
							}
							else
							{
								$closingCountshowInHeading = '';
							}
						}
                        
                        $queryForTotalSales = mysql_query("SELECT sum(amount_payable) FROM product_saleinvoice WHERE MONTH(saleinvoice_date)=$month AND YEAR(saleinvoice_date)=$year");
                        $arrayForTotalSales = mysql_fetch_assoc($queryForTotalSales);
                        $totalSales = $arrayForTotalSales['sum(amount_payable)'];
						
						$queryForTotalReceived = mysql_query("SELECT sum(amount_payable) FROM product_recinvoice WHERE MONTH(recinvoice_date)=$month AND YEAR(recinvoice_date)=$year");
                        $arrayForTotalReceived = mysql_fetch_assoc($queryForTotalReceived);
                        $totalReceived = $arrayForTotalReceived['sum(amount_payable)'];
						
						?>
						<tr>
							<td width="50%" align="right">Total Products:</td>
							<td width="50%" align="right" ><h4><?php echo mysql_num_rows($queryForProducts)."\n"; ?></h4>
						</p></td>
						</tr>
						
						 
						<tr>
							<td align="right" >Total Trade Stock Value:</td>
							<td align="right" valign="top"><h4>Rs. <?php echo number_format($totalStockValue,2); ?></h4>
						</p></td>
						</tr>
                        <tr>
							<td align="right" >Total Sale Stock Value:</td>
							<td align="right" ><h4>Rs. <?php echo number_format($totalStockValue_retail,2); ?></h4>
						</p></td>
						</tr>
					
                    </table>
                </td>
            </tr>
            <tr>
            <td><table border="0" align="left" cellpadding="0" cellspacing="0">
          
          </table>
            </td>
            </tr>
        </table></td>
  </tr>
  <tr>
    <td width="511">
    <table width="100%">
      <tr>
        <td>
        <table width="100%" class="bottomBorder">
            <tr>
                <th width="5%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3><br />ID</h3></th>
                <th width="15%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3><br /> Product Name</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Product <br />Type</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Unit Qty<br />in Stock<br />&nbsp;</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Box<br />TradePrice<br />&nbsp;</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Box<br />RetailPrice<br />&nbsp;</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Unit<br />TradePrice<br />&nbsp;</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Unit<br />RetailPrice<br />&nbsp;</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Trade Stock Value<br />&nbsp;</h3></th>
                <th width="10%" rowspan="2" align="center" valign="middle" bgcolor="#F0F0F0"><h3>Sale Stock Value<br />&nbsp;</h3></th>
            </tr>
            <tr>
            </tr>
			<?php
			
				$queryForProducts = mysql_query("SELECT * FROM products WHERE active=1  order by product_name asc") or die(mysql_error()); 
			
			
			
				while($row = mysql_fetch_assoc($queryForProducts))
				{ 
					
					$product_id=$row['product_id'];
					$unit_qtyinstock=$row['unit_qtyinstock'];
					$box_tradeprice=$row['box_tradeprice'];
					$box_retailprice=$row['box_retailprice'];
					$unit_tradeprice=$row['unit_tradeprice'];
					$unit_retailprice=$row['unit_retailprice'];
					
					$month=date('m',time());
					$year=date('Y',time());

					
					
					
					?>
					
					<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 $unit_qtyinstock;?></td>
                        
                       	<td align="right"><?php echo number_format($box_tradeprice,2);?></td>
                        
                        <td align="right"><?php echo number_format($box_retailprice,2);?></td>
                        
                        <td align="right"><?php echo number_format($unit_tradeprice,2);?></td>
                        
                        <td align="right"><?php echo number_format($unit_retailprice,2);?></td>
                         
                        <td align="right"><?php echo number_format($unit_qtyinstock*$unit_tradeprice,2);?></td>
                        
                        <td align="right"><?php echo number_format($unit_qtyinstock*$unit_retailprice,2);?></td>
					
					</tr>
                    
					
				<?php 
            } 
			?> 
          </table>
        </td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
  </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>
