<?php
include('../config/config.php');
include('../classes/classPatient.php');
include("../classes/classImages.php");
include("../classes/classWardMgmt.php");

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

################################################################################
#########################Pagination Starts here. {########################
################################################################################

$countBedAllotOb = new classWardMgmt;	
$countBedAllotOb->setLocationID($_SESSION['security']['location_id']);
$count = $countBedAllotOb->countAllBedAllotmentDetails();		

$array['item_count'] = $count;
if(isset($_GET['page']) && isset($_GET['items']))
{
	if($array['item_count'] > $_GET['items'])
	{
		$array['pages'] = ceil($array['item_count']/$_GET['items']);
		if($_GET['page'] >$array['pages'])
		{
			$_GET['page'] = 1;
		}
		$array['current_page'] = $_GET['page'];
		if($_GET['page'] > 1)
		{
			$starting_record = $_GET['items']*($_GET['page']-1);
			$ending_record = $_GET['items'];
			$array['limit'] = $starting_record . "," . $ending_record;
			$limit = $array['limit'];
		}
		else
		{
			$limit = $_GET['items'];
		}
	}
	else
	{
		$array['current_page'] = $_GET['current_page'] = 1;
		$array['pages'] = 1;
		$array['limit'] = $_GET['items'];
		$limit = $array['limit'];
	}
}
else
{
	if($array['item_count'] > 20)
	{
		$array['pages'] = ceil($array['item_count']/20);
	}
	else
	{
		$array['pages'] = 1;
	}
	$array['current_page'] = 1;
	$array['limit'] = 20;
	$limit = $array['limit'];
}

$_SESSION['pagination']['item_count']=$array['item_count'];
$_SESSION['pagination']['pages']=$array['pages'];
$_SESSION['pagination']['current_page']=$array['current_page'];
$_SESSION['pagination']['limit']=$limit;

################################################################################
######################### Pagination Ends here. }##########################
################################################################################

try
{
	if(@$_POST['by_id']!=''||@$_POST['by_name']!=''||@$_POST['by_phone']!='')
	{
		$bedWardOb = new classWardMgmt;
		$bed_ward_array = $bedWardOb->retrieveAllBedAllotmentDetailsByPatient($_POST['by_id'],$_POST['by_name'],$_POST['by_phone'],$_SESSION['security']['location_id']);
	}
	else
	{
		$bedWardOb = new classWardMgmt;
		$bedWardOb->setLocationID($_SESSION['security']['location_id']);
		$bed_ward_array = $bedWardOb->retrieveAllBedAllotmentDetails($limit);
	}
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}




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


?>
<!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"><head></head><!-- 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" --><!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
    <title>Med2TEC Hospital Management Information System</title>
    
  <section id="main-content">
    <section class="wrapper">
      <!-- page start-->
      	<div class="row">
        <div class="col-sm-12">
          <section class="panel">
           <header class="panel-heading">
              <h2>IPD ADMISSIONS HISTORY</h2>
            </header>

            <div class="panel-body">
              <div class="adv-table">
                <table class="bottomBorder"  width="100%" cellpadding="0" cellspacing="0">
                  <thead>
                    <tr>
                      </tr><tr>
                      <th width="10%" align="center">Date of Admission</th>
                      <th width="10%" align="center">Bed No.</th>
                      <th width="5%" align="center">Adm. No</th>
                      <th width="5%" align="center">&nbsp;</th>
                      <th width="5%" align="center">ID</th>
                      <th width="15%">Patient Name</th>
                      <th width="10%" align="center">Status</th>
                      <th width="10%">Discharged at</th>
                      <th width="5%">Result</th>
                      <th width="10%" align="center">Payment</th>
                    </tr>
                    </td></tr>
                  </thead>
                  <tbody>
                  <?php
					if(isset($bed_ward_array[0]['ipd_bed_allotment_id'])&&$bed_ward_array[0]['ipd_bed_allotment_id']!='')
					{
						for($ba=0;$ba<count($bed_ward_array);$ba++)
						{
							if($ba%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
							
							$pid = $bed_ward_array[$ba]['patient_id'];
							
							$status = $bed_ward_array[$ba]['allot_status'];
							
							$ipd_bed_allotment_id = $bed_ward_array[0]['ipd_bed_allotment_id'];
							
							$imageRetrieveOb = new classImages;
							$imageRetrieveOb->setPatientAutoID($pid);
							$image_id = $imageRetrieveOb->fetchImageOfPatient();
							
							$patientOb = new classPatient;
							$patientOb->setPatientAutoID($pid);
							$patient_info = $patientOb->retrievePatientByPatientID();
							
							$patient_name = ucwords($patient_info[0]['patient_fname'].' '.$patient_info[0]['patient_lname']);
							?>
							<tr class="<?php echo $class;?>">
                               
                                <td align="center"><?php echo @date('d M Y',$bed_ward_array[$ba]['allot_time']);?></td>
                                <td align="center"><?php echo $bed_ward_array[$ba]['ipd_bed_no'];?></td>
                                <td align="center"><?php echo $bed_ward_array[$ba]['ipd_bed_allotment_id'];?></td>
                                <td align="center">
                                <?php
                                if(isset($image_id)&&$image_id!='')
                                {
									?>
                                	<img src="../images/patient_images/<?php echo $image_id;?>.jpg" width="30" height="30" />
                                    <?php
                                }
                                else
                                {
									?>
                                	<img src="../images/photo.png" width="30" height="30" />
                                    <?php
                                }
								?>
                                </td>
                                <td align="center"><?php echo $pid;?></td>
                                <td align="left"><?php echo $patient_name;?></td>
                                <td align="left"><?php echo $status;?></td>
                                <td align="center"><?php echo @date('d M Y',$bed_ward_array[$ba]['discharge_time']);?></td>
                                <td align="center"></td>
                                <td align="center"><?php echo @number_format($bed_ward_array[$ba]['payment'],2);?></td>
                                
							</tr>
                            <?php
						}
					}
					else
					{
						?>
                        
                        
						<tr>
                        	<td colspan="11">No entries found!</td>
                        </tr>
                        <?php
					}
				  ?>
                  </tbody>
                  <tfoot>
                  </tfoot>
                  
                </table>
                <?php
				if(!$_POST)
				{
					?>
					
					<?php
				}
				?>
                
                <!--<div class="row-fluid">
                  <div class="span6">
                    <div class="dataTables_info" id="hidden-table-info_info">Showing 1 to 10 of 57 entries</div>
                  </div>
                  <div class="span6">
                    <div class="dataTables_paginate paging_bootstrap pagination">
                    
                      <ul>
                        <li class="prev disabled"><a href="#">? Previous</a></li>
                        <li class="active"><a href="#">1</a></li>
                        <li><a href="#">2</a></li>
                        <li><a href="#">3</a></li>
                        <li><a href="#">4</a></li>
                        <li><a href="#">5</a></li>
                        <li class="next"><a href="#">Next ? </a></li>
                      </ul>
                    </div>
                  </div>
                </div>-->
              </div>
            </div>
          </section>
        </div>
      </div>
      <!-- page end-->
      
    </section>
  </section>
  <!-- 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>


