<?php 
include('../config/config.php');
include("../classes/classShift.php");
include("../classes/classDoctor.php");
include("../classes/classVisits.php");
include('../classes/classPatient.php');
include("../classes/classImages.php");
include('../classes/classTransaction.php');


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

if(isset($_SESSION['temp']['shiftid'])&&$_SESSION['temp']['shiftid']!='')
{
	$shift_id = $_SESSION['temp']['shiftid'];
}
if(isset($_SESSION['temp']['doctorid'])&&$_SESSION['temp']['doctorid']!='')
{
	$doctor_id = $_SESSION['temp']['doctorid'];
}

///////////// retrieve Visits ////////////////////////////////////////
$total_patients = 0;
$total_payables = 0;
$total_payments = 0;
$to = date('Y-m-d',time());
$from = date('Y-m-d',time());

if(isset($_POST['med_issue_id'])&&$_POST['med_issue_id']!='')
{
try
{
	$med_issue_id = $_POST['med_issue_id'];
	$from = $_POST['from'];
	$to = $_POST['to'];
	
	$retrieveVisitOb = new classVisits;
	$visits_array = $retrieveVisitOb->retrieveMedIssueVisits($from,$to,$doctor_id,$shift_id,$med_issue_id);
	
	if(isset($visits_array[0]['visit_id'])&&$visits_array[0]['visit_id']!='')
	{
	  	for($int=0;$int<count($visits_array);$int++)
		{
			$total_patients ++;
			$total_payables += $visits_array[$int]['payable'];
			$total_payments += $visits_array[$int]['payment'];
		}
	}

	
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	
}
///////////// retrieve shift Detail ////////////////////////////////////////

try
{
	$retrieveShiftOb = new classShift;
	$retrieveShiftOb->setShiftID($shift_id);
	$shift_array = $retrieveShiftOb->retrieveShiftByShiftID();
	
	
	$shift_created_date = date('d M Y , l',$shift_array[0]['date']);
	$shift_created_time = date('h:i A',$shift_array[0]['start_time']);
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	


///////////// retrieve doctor Detail ////////////////////////////////////////

try
{
	$doctorOb = new classDoctor;
	$doctorOb->setDoctorID($doctor_id);
	$doctor_detail = $doctorOb->retrieveDoctorByDoctorID();
	
	$doctor_name = $doctor_detail[0]['title'].'. '.$doctor_detail[0]['doc_fname'].' '.$doctor_detail[0]['doc_lname'];
	
	$doctor_acc_id = $doctor_detail[0]['account_id'];
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

///////////// retrieve medical issues ////////////////////////////////////////
try
{
	$medIssueOb = new classVisits;
	$medIssueOb->setOrganizationID($_SESSION['security']['org_id']);
	$med_issue_array = $medIssueOb->retrieveMedicalIssues();
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}

try
{
	$tranOb = new classTransaction;
	$account_data = $tranOb->retrieveAccountHeadAndAccountByID(1,$doctor_acc_id);	
}
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" -->LIST OF LASER PATIENT VISITS<!-- InstanceEndEditable --></h2>
            </header>

  <br />
  
<!-- InstanceBeginEditable name="main" -->
  <!-- page start-->
<form action="" method="post">             
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    	<td width="40%">
            <span>For: <?php echo $doctor_name;?><br></span>
            <span>Date: <?php echo $shift_created_date?></span><br>
            <span> From: <?php echo $shift_created_time;?></span></p>
            <span>Total Patients: <?php echo $total_patients;?></span></br>
            <span>Total Payables: Rs. <?php echo $total_payables;?></span></br>
            <span>Total Payments: Rs. <?php echo $total_payments;?></span>
        </td>
    
        <td  width="60%" valign="top"><table width="100%" border="0" cellpadding="1" cellspacing="0">
        
        <tr>
        
        <td width="25%">Search Type: 
        <?php
        if(isset($med_issue_array[0]))
        {
        
			?>
			<select name="med_issue_id">
			<option value="">Select Issue</option>
			<?php
			for($m=0;$m<count($med_issue_array);$m++)
			{
				?>
				<option value="<?php echo $med_issue_array[$m]['med_issue_id']?>" <?php if($med_issue_array[$m]['med_issue_id']==@$_POST['med_issue_id']){echo 'selected';}?>><?php echo ucwords($med_issue_array[$m]['med_issue']);?></option>
				<?php
			}
			?>
			</select>
			<?php
        }
        ?>
        </td>
        
        <td width="25%">From: <input type="text" name="from" value="<?php echo $from;?>" id="datepicker" class="form-control" readonly style="display:inline; width:100%;"></td>
        
        <td width="25%">To: <input type="text" name="to" value="<?php echo $to;?>" id="datepicker1" class="form-control" readonly style="display:inline; width:100%;"> 
        </td>
        
        <td width="25%"><input type="submit" class="btn btn-success btn-sm" name="search_by_date" value="Search"></td>
        
        </tr>

        </table></td>
    </tr>
</table>
</form>

<br>
 <?php
			if(isset($error_message)&&$error_message!='')
			{
				?>
              <span class="message_red"><?php echo $error_message;?></span>
              <?php
			}
			?>
<table  class="bottomBorder" width="100%">
                  <thead>
                    <tr>
            			<th width="5%" align="center">Token</th>
            			<th width="10%" align="center">Time</th>
            			<th width="5%" align="center">ID</th>
            			<th width="20%" align="left">Patient's Name</th>
            			<th width="10%" align="left">Phone</th>
            			<th width="15%" align="center">Amount Payable</th>
            			<th width="10%" align="center">Payment</th>
            			<th width="10%" align="center">Balance</th>
                    </tr>
                  </thead>
                  <tbody>
					<?php
                    if(isset($visits_array[0]['shift_id'])&&$visits_array[0]['shift_id']!='')
                    {
                    	for($v=0;$v<count($visits_array);$v++)
						{
							if($v%2==0){$class = 'gradeX';}{$class = 'gradeC';}
							
							$visit_id = $visits_array[$v]['visit_id'];
							$visit_id_encoded = base64_encode($visit_id);
							
							$patient_id = $visits_array[$v]['patient_id'];
							$patient_id_encoded = base64_encode($patient_id);
							
							$patientOb = new classPatient;
							$patientOb->setPatientAutoID($patient_id);
							$patient_info = $patientOb->retrievePatientByPatientID();
							
							if(isset($visits_array[$v]['zakat'])&&$visits_array[$v]['zakat']=='zakat')
							{
								$payable = $visits_array[$v]['zakat'];
							}
							else
							{
								$payable = 'Rs. '.$visits_array[$v]['payable'];
							}
							
							if($visits_array[$v]['pay_status']!= "paid" && $visits_array[$v]['zakat']!='zakat')
							{
								
                               $payment = "Rs. ".$visits_array[$v]["payment"];
							} 
							else 
							{ 
								$payment = "Rs. ".$visits_array[$v]["payment"]; 
							}
							
							$balance = 'Rs. '.$visits_array[$v]['balance'];
							
							
							
							
							?>
							<tr class="<?php echo $class;?>">
                                <td align="center"><?php echo $visits_array[$v]['token_no'];?></td>
                                <td align="center"><?php echo date('h:i A',$visits_array[$v]['visit_date']);?></td>
                                <td align="center"><?php echo $patient_info[0]['patient_id'];?></td>
                                <td align="left"><?php echo $patient_info[0]['patient_fname'].' '.$patient_info[0]['patient_lname'];?></td>
                                <td align="center"><?php echo $patient_info[0]['phone'];?></td>
                                <td align="right"><?php echo $payable;?></td>
                                <td align="right"><?php echo $payment;?></td>
                                <td align="right" ><?php echo $balance;?></td>
							</tr>
                            
                            
							<?php
						}
                    }
					else
					{
						?>
							
						<?php
					}
                    ?>
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>
  <!-- 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>