<?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>';*/

#################### set temp session  ##############################################

if(isset($_GET['patientid'])&&isset($_GET['visitid']))
{
	$_SESSION['temp']['patient_id'] = base64_decode($_GET['patientid']);
	$_SESSION['temp']['visit_id'] = base64_decode($_GET['visitid']);
	//header("Location:mgmtvisits.php");
}
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'];
}
if(isset($_SESSION['temp']['patient_id'])&&$_SESSION['temp']['patient_id']!='')
{
	$patient_id = $_SESSION['temp']['patient_id'];
}
if(isset($_SESSION['temp']['visit_id'])&&$_SESSION['temp']['visit_id']!='')
{
	$visit_id = $_SESSION['temp']['visit_id'];
}



#################### retrieve data ##############################################

try
{
	$retrieveVisitPrecOb = new classVisits;
	$retrieveVisitPrecOb->setVisitID($visit_id);
	$visit_array = $retrieveVisitPrecOb->retrieveVisitByVisitID();
	
	///////////// retrieve patient single data ///////////////////////////////
	
	$retrievePatientOb = new classPatient;
	$retrievePatientOb->setPatientAutoID($patient_id);
	$patient_single_detail = $retrievePatientOb->retrievePatientByPatientID();
	$patient_age = $retrievePatientOb->age_from_dob($patient_single_detail[0]['dob']);
	
	$imageOb = new classImages;
	$imageOb->setPatientAutoID($patient_id);
	$image_id = $imageOb->fetchImageOfPatient();
	$images_array = $imageOb->fetchAllImageOfPatient();
	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

///////////// retrieve doctor ////////////////////////////////////////
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 Accounts ////////////////////////////////////////
try
{
	$tranOb = new classTransaction;
	$account_data = $tranOb->retrieveAccountHeadAndAccountByID(1,$doctor_acc_id);	
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}
	
///////////// retrieve location ////////////////////////////////////////		

try
{
	$retrieveLocOB = new classUser;
	$retrieveLocOB->setOrganizationID($_SESSION['security']['org_id']);
	$location_array = $retrieveLocOB->retrieveLocationsOfOrganization();
	
	$org_name = ucwords($retrieveLocOB->retrieveOrgNameByOrgID($_SESSION['security']['org_id']));
	$loc_address = $location_array[0]['address'];
	$loc_phone = $location_array[0]['phone'];
	$contact_person  = $location_array[0]['contact_person'];
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}	

/*echo '<pre>';
print_r($invoice_items_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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="../css/print.css" rel="stylesheet">
</head>
<style>
table.bottomBorder { border-collapse:collapse; }
table.bottomBorder td, table.bottomBorder th { border-bottom:1px dotted black;}

@media screen {
  body {
    width: 95%;
  }
}

@media print {
  body {
    width: 50%;
	margin: 5px;
	padding: 5px;
  }
}
<!--
@page { size: landscape; }
-->
</style>
<body style="font-size:9px;">

       <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>
        
       <div class="invoice_print" align="center" style="font-size:14px;"><p><img alt="" src="../images/org_print_logos/<?php echo $_SESSION['security']['org_id']?>.png" style="width:100%;"></br><?php echo $loc_address;?> <?php echo $loc_phone;?></p></div>



      <!-- page start-->
      
       <div class="row invoice_print" id="pageHeader">
            
                    <div class="panel-body invoice">
                    
                        <div class="invoice-header">
                            <div class="">
                              <h1>TOKEN NO: <?php echo $visit_array[0]['token_no'];?></h1>
                            </div>
                            
                        </div>
                      	<?php
						if(isset($error_message)&&$error_message!='')
						{
							?>
                            <table>
							<tr>
								<td><span class="message_red"><?php echo $error_message;?></span></td>
							</tr>
                           
                            </table>
							<?php
						}
						?>
                        
                        <?php
						if(isset($_SESSION['temp']['patient_id'])&&$_SESSION['temp']['patient_id']!='')
						{
							?>
							<div id="result"></div>
                            
                            <table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:12px;">
                            
                                <tr>
                                    <td width="24%">Patient ID:</td>
                                    <td width="33%"><?php  if(isset($patient_single_detail[0]['patient_id'])){echo $patient_single_detail[0]['patient_id'];}?></td>
                                    <td width="19%"></td>
                                    <td width="19%"></td>
                                </tr>
                                
                                <tr>
                                    <td>Patient Name:</td>
                                    <td><?php if(isset($patient_single_detail[0]['patient_fname'])){echo strtoupper($patient_single_detail[0]['patient_fname'].' '.$patient_single_detail[0]['patient_lname']);}else{echo 'OUTDOOR';}?></td>
                                    <td>Date:</td>
                                    <td><?php echo date('d M Y',$visit_array[0]['shift_date']);?></td>
                                    
                                    
                                </tr>
                                
                               
                                
                                <tr>
                                <td>s/d/w of:</td>
                                    <td>
                                <?php if(isset($patient_single_detail[0]['parent_name'])){echo strtoupper($patient_single_detail[0]['parent_name']);}?>
                               </td>
                                    
                                    <td>Phone:</td>
                                    <td>
                                <?php if(isset($patient_single_detail[0]['phone'])){echo $patient_single_detail[0]['phone'];}?>
                                </td>
                                </tr>
                                
                                <tr>
                                    <td>Age:</td>
                                    <td><?php if(isset($patient_single_detail[0]['age'])){echo $patient_single_detail[0]['age'].' years';}?></td>
                                    <td>Address:</td>
                                    <td><?php if(isset($patient_single_detail[0]['address'])){echo strtoupper($patient_single_detail[0]['address']);}?></td>
                                    
                                </tr>
                                
                               
                            </table>
								
							<br />

							<table class="bottomBorder" cellpadding="0" cellspacing="0" width="100%" style="font-size:12px;">
                            
								<thead>
									<tr style="background:#CCC;">
										<th width="2%" align="left">Visit ID</th>
										<th width="20%" align="left">Description</th>
										<th width="15%" align="right">Amount</th>
									</tr>
								</thead>
                                
								<tbody>
                               	<?php
								
								if(isset($visit_array[0]['visit_id'])&&$visit_array[0]['visit_id']!='')
								{
									?>
									<tr>
							
                                    	<td style="border-bottom:none;" align="center"><?php echo $visit_array[0]['visit_id'];?></td>
                                    
                                    	<td style="border-bottom:none;"><?php echo $account_data[0]['account_name'];?></td>
                                    
                                    	<td align="right" style="border-bottom:none;"> <?php echo 'Rs. '.number_format($visit_array[0]['payable'],2);?></td>
							   
								
									</tr>
									<?php
										
								}
								?>  
                                
                                </tbody>
                                
							</table>

                            <table width="50%" border="0" cellpadding="0" cellspacing="4" align="right" style="font-size:14px; border-top:1px dotted black;">
                            	<tr>
                            <td width="60%">Payment Received:</td>
                            <td width="40%" align="right">Rs. <?php echo number_format($visit_array[0]['payment'],2);?></td>
                            </tr>
                            
                            </table>
                            
                            <br />
                            <br />
                            <br /><br />
                            

							<!--<h4>Terms &amp; Conditions</h4>
                            <p>1. Check Cash before leaving.</p>
                            <p>2. No Legal responsibility and Financial Liability is accepted for any error or ommission.</p>
                            <p>3. Fee is non refundable, once the tests are done.</p>
                            <p>4. NOT VALID FOR ANY COURT CASES.</p>-->
                            
							<br />
                            <br />
                            
                            <div style="color:#737373; text-align:center;">All Rights Reserved © Software designed by Softusion Inc. 2013<br />For details visit us at www.softusion.com</div>
							
							<?php
						}
						else
						{
							?>
                            
                            <?php
						}
						?>
                        
                    </div>
               
        </div>
        
      <!-- page end-->


</body>
</html>