<?php
include('../config/config.php');
include('../classes/classDiagnostic.php');


/*echo '<pre>';
print_r($_POST);
echo '</pre>';
exit;*/

if(isset($_POST['from'])&&isset($_POST['to']))
{
	$from = $_POST['from'];
	$to = $_POST['to'];
}
else
{
	$to = date('Y-m-d',time());
	$from = date('Y-m-d',time());
}


try
{
	$retrieveTestOb = new classDiagnostic;
	if(isset($_POST['test_name'])&&$_POST['test_name']!='')
	{
		$retrieveTestOb->setLabTestName($_POST['test_name']);
		$labtest_array = $retrieveTestOb->retrieveLabTestsByLabTestName();
	}
	else
	{
		$retrieveTestOb->setOrganizationID($_SESSION['security']['org_id']);
		$labtest_array = $retrieveTestOb->retrieveLabTests();
	}
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	
?>
<!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" -->SALES BY TESTS REPORT<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
              <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
              	<span class="message_red"><?php echo $error_message;?></span>
              	<?php
			}
			?>

<section class="wrapper">
	<form action="" method="post">
        <table width="100%" border="0" cellpadding="1" cellspacing="0">
        
       
            <tr>
            
                <td width="1%" align="right"></td>
                
                <td width="15%">Test Name: <input type="text" name="test_name" value="<?php echo @$_POST['test_name'];?>" class="form-control"  style="width:60%;"></td>
               
                <td width="15%">From: <input type="text" name="from" value="<?php echo $from;?>" id="datepicker" class="form-control" readonly style="display:inline; width:65%;"></td>
                
                <td width="15%">To: <input type="text" name="to" value="<?php echo $to;?>" id="datepicker1" class="form-control" readonly style="display:inline; width:65%;"> </td>
                
                <td width="50%"><input type="submit" class="btn btn-success btn-sm" name="search_by_date" value="Search"></td>
                
            </tr>
        
        </table>
        </form>
      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
            <div class="panel-body">
              <div class="adv-table">
                <p style="font-family:Tahoma, Geneva, sans-serif; font-size:16px;"></p>
                <table  class="bottomBorder" width="100%">
                  <thead>
                    <tr>
                    	<th width="5%" align="center">T-Code</th>
            			<th width="45%" align="left"> Test</th>
            			<th width="15%" align="right">Sale Qty</th>
            			<th width="15%" align="right">Rate</th>
           			  	<th width="15%" align="right">Total Sale</th>
           			 </tr>
                  </thead>
                  
                  <tbody>
                  
                  	<?php
					if(isset($labtest_array[0]['labtest_id'])&&$labtest_array[0]['labtest_id']!='')
					{
						$location_id = $_SESSION['security']['location_id'];
						
						for($p=0;$p<count($labtest_array);$p++)
						{
							$diagnosis_id = $labtest_array[$p]['labtest_id'];
							$diagnosis_name = $labtest_array[$p]['labtest_name'];
							$diagnosis_cost = $labtest_array[$p]['labtest_cost'];
							$diagnosis_type = 'labtest';
							
							
							$testQtyOb = new classDiagnostic;
							$test_detail_array = $testQtyOb->retrieveSumOfInvoiceItemsDetail($from,$to,$location_id,$diagnosis_type,$diagnosis_id);
							
							?>
							<tr>
                             	<td align="center"><?php echo $diagnosis_id;?></td>
                                <td align="left"><?php echo $diagnosis_name;?></td>
                              	<td align="right"><?php echo $test_detail_array[0]['count(diagitems_id)'];?></td>
                                <td align="right">Rs. <?php echo number_format($diagnosis_cost,2);?></td>
                                <td align="right">Rs. <?php echo number_format($test_detail_array[0]['sum(net_total)'],2);?></td>
                               
							</tr>
                            <?php
						}
					}
					?>
                            
                  </tbody>
                  
                  <tfoot>
                  </tfoot>
                </table>
               
              </div>
            </div>
          </section>
        </div>
      </div>
      <!-- page end-->
    </section>
  <!-- page end-->
  
<!-- 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>
<script>
	$(function() {
		
		$("#datepicker").datepicker({
		showOn: "button",
		buttonImage: "../images/calendar.gif",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd"
		});
		
		$("#datepicker1").datepicker({
		showOn: "button",
		buttonImage: "../images/calendar.gif",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true,
		dateFormat: "yy-mm-dd"
		
		});
	
	});

</script>