<?php include 'header1f.php';?>
<?php
	require_once("perpage.php");	
	require_once("dbcontroller.php");
	$db_handle = new DBController();
	
	$datepicker = "";
	$datepicker1 = "";
	$location = "";
	$billing_GST_no = "";
	$state = "";
	$city = "";
	$company_name="";
	
	$queryCondition = "";
	if(!empty($_POST["search"])) {
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

$queryCases = array("datepicker","datepicker1","location","billing_GST_no","company_name");
				if(in_array($k,$queryCases)) {
					if(!empty($queryCondition)) {
						$queryCondition .= " AND ";
						
					} else {
						$queryCondition .= " WHERE ";
					}
				}
				switch($k) {
						case "datepicker":
						$datepicker = $v;
						$queryCondition .= "dpinv_date BETWEEN";
						case "datepicker1":
						$datepicker1 = $v;
						$queryCondition .= "'" . $v . "'";
						break;
						
						case "location":
						$location = $v;
						$queryCondition .= "location LIKE '%" . $v . "%'";
						break;
						case "company_name":
						$company_name = $v;
						$queryCondition .= "company_name LIKE '%" . $v . "%'";
						break;
						
						case "billing_GST_no":
						$billing_GST_no = $v;
						$queryCondition .= "billing_GST_no LIKE '%" . $v . "%'";
						break;
						
						
						
						
				}
			}
		}
	}
	if(!empty($queryCondition)) {
	
	$orderby = " ORDER BY ingid"; 
	$sql = "SELECT * FROM  prescription" . $queryCondition ." " ;
	}else{
	 $sql= "SELECT * FROM  prescription";
	}
	//echo $sql ;
	$href = 'view_all_products.php';					
	
	$perPage = 5000; 
	$page = 1;
	if(isset($_POST['page'])){
		$page = $_POST['page'];
	}
	$start = ($page-1)*$perPage;
	if($start < 0) $start = 0;
		
	$query =  $sql . $orderby .  " limit " . $start . "," . $perPage; 
	$result = $db_handle->runQuery($query);
	
	if(empty($result)) {
		
	$result["perpage"] = showperpage($sql, $perPage, $href);
	}
	else{ 
	$result["perpage"] = showperpage($sql, $perPage, $href); }
	
?>

<div class="content-page">
<div class="content">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="page-header-title">
<button type="button" class="btn btn-dark  waves-effect waves-light" onclick="location.href='index.php'">BACK </button>

<div class="clearfix"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">INGREDIENTS</h3>
</div>
<div class="panel-body">
<table  id="datatable-buttons" class="table table-striped table-bordered">
<thead>
<tr>
<th>Sr No.</th>
<th>Patient Name</th>
<th>Date</th>
<th>Height</th>
<th>Weight</th>
<th>Age</th>
<th>Pulse</th>
<th>HO</th>
<th>CO</th>
<th>Next Follow up Date</th>
<th>Next Follow up Time</th>
<th>Print</th>
</tr>
</thead>
<tbody>
<?php 
foreach($result as $k=>$v) {
if(is_numeric($k)) {
						
$registration_id = $result[$k]["registration_id"];
$prescription_id = $result[$k]["prescription_id"];
					
$qry9 = "select * from patient_register where registration_id = '$registration_id'";
$re9 = mysqli_query($conn,$qry9);
while($row=mysqli_fetch_array($re9))
{  
$patient_name  = $row['patient_name'];
}				
						
												 					
													?>
<tr>
<td><?php echo $k+1?></a></td>
<td><?php echo $patient_name?></td>
<td><?php echo $result[$k]["prescription_date"]?></td>
<td><?php echo $result[$k]["height"]?></td>
<td><?php echo $result[$k]["weight"]; ?></td>
<td><?php echo $result[$k]["age"]; ?></td>
<td><?php echo $result[$k]["pulse"]?></td>
<td><?php echo $result[$k]["HO"]?></td>
<td><?php echo $result[$k]["CO"]?></td>
<td><?php echo $result[$k]["next_followup_on"]?></td>
<td><?php echo $result[$k]["next_followup_at"]?></td>
<td><a href="print_prescription.php?prescription_id=<?php echo $prescription_id?>" class="btn btn-danger btn-xs waves-effect waves-light" target="_blank">PRINT<br />PRESCRIPTION</a></td>
</tr>
<?php }}?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include 'footer1a.php';?>
