<?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($_GET['shiftid'])&&isset($_GET['doctorid']))
{
	$_SESSION['temp']['shiftid'] = base64_decode($_GET['shiftid']);
	$_SESSION['temp']['doctorid'] = base64_decode($_GET['doctorid']);
	//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'];
}




/////////////////////////////Add New Visit ////////////////////////

if(isset($_POST['patient_type'])&&$_POST['patient_type']!='')
{	
	if($_POST['patient_type']=='out_patient')
	{
		$patient_id = "0";
	}
	else
	{
		$patient_id = $_POST['patient_type'];
	}
	
	try
	{
		$visitCreateOb = new classVisits;
		$visitCreateOb->setDoctorID($doctor_id);
		$visitCreateOb->setShiftID($shift_id);
		$visitCreateOb->setPatientID($patient_id);
		$visitCreateOb->setLocationID($_SESSION['security']['location_id']);
		$visitCreateOb->execute();
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}	
}

/////////////////////////////Delete shift////////////////////////

if(isset($_GET['del_visit']))
{
	$del_visit = base64_decode($_GET['del_visit']);
		
	try
	{	
		$delVisitOb = new classVisits;
		$delVisitOb->setVisitID($del_visit);
		$delVisitOb->deleteVisit();
		
		header("Location:mgmtvisits.php");
	}
	catch (MyException $e)
	{
		$error_message = $e->getUserMsg();
	}	
}


///////////// retrieve Visits ////////////////////////////////////////

try
{
	$retrieveVisitOb = new classVisits;
	$retrieveVisitOb->setShiftID($shift_id);
	$retrieveVisitOb->setDoctorID($doctor_id);
	$visits_array = $retrieveVisitOb->retrieveVisits();
	
	$total_patients = 0;
	$total_payables = 0;
	$total_payments = 0;
	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 patients ////////////////////////////////////////

/*try
{
	$retrievePatientOb = new classPatient;
	$retrievePatientOb->setLocationID($_SESSION['security']['location_id']);
	$patients_array = $retrievePatientOb->retrievePatientByLocationID();
}
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 medical issues ////////////////////////////////////////
try
{
	$medIssueOb = new classVisits;
	$medIssueOb->setOrganizationID($_SESSION['security']['org_id']);
	$med_issue_array = $medIssueOb->retrieveMedicalIssues();
}
catch (MyException $e)
{
	$error_message = $e->getUserMsg();
}
?>
<!DOCTYPE html>
<html><!-- InstanceBegin template="/Templates/main.dwt.php" codeOutsideHTMLIsLocked="false" -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head> 
    <link rel="shortcut icon" href="../images/favicon.png">
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Med2TEC Hospital Management Information System</title>
    <!-- InstanceEndEditable -->
    <!--Core CSS -->
    <link href="../bs3/css/bootstrap.min.css" rel="stylesheet"> 
    <link href="../css/style.css" rel="stylesheet">
    <link href="../css/style-responsive.css" rel="stylesheet"/> 
    <link href="../popUp/popUp.css" rel="stylesheet">
    <link href="../css/bootstrap-fullcalendar.css" rel="stylesheet"/> 
    
    <link href="../css/clndr.css" rel="stylesheet">
    
    <link href="../css/css/font-awesome.css" rel="stylesheet">
    
    <link href="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.css" rel="stylesheet">
    <link href="../assets/jvector-map/jquery-jvectormap-1.2.2.css" rel="stylesheet">    
    <link href="../assets/jquery-multi-select/css/multi-select.css" rel="stylesheet" type="text/css">
    <!--clock css-->
    <link href="../assets/css3clock/css/style.css" rel="stylesheet"> 
    <!--Morris Chart CSS -->
    <link rel="stylesheet" href="../assets/morris-chart/morris.css">
    <!-- Custom styles for this template -->
   
    <link href="../datepicker/jquery-ui.css" rel="stylesheet" >   
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
<body>

<section id="container">
    <!--header start-->
    <header class="header fixed-top clearfix">
        <!--logo start-->
        <div class="brand">

            <a href="home.php" class="logo">
                <img src="../images/logo.png" alt="">
            </a>
            <div class="sidebar-toggle-box">
                <div class="fa fa-bars"></div>  
            </div>
        </div> 
        <!--logo end-->

        <div class="nav notify-row" id="top_menu" style="float: right; margin-top: 16px; margin-left: 0px; margin-right: 10px;">
            <!--  notification start -->
             <img alt="" src="../images/org_logos/<?php echo $_SESSION['security']['org_id']?>.png">
            <!--  notification end -->
        </div>
        <div class="top-nav clearfix">
            <!--search & user info start-->
            <ul class="nav pull-right top-menu">
                <li>
                    <div class="toggle-right-box"><!-- InstanceBeginEditable name="print" -->
                    <a href="javascript:Popup('printmgmtvisits.php')"><i class="fa fa-print" style="margin-left: 11px; margin-top: 11px;"></i></a>
					<!-- InstanceEndEditable --></div>
                </li>
                <!-- user login dropdown start-->
                <li class="dropdown">
                    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                        <img alt="" src="../images/avatar1_small.jpg"> 
                        <span class="username"><?php echo $username;?></span>
                        <b class="caret"></b>
                    </a>
                    <ul class="dropdown-menu extended logout">
                        <li><a href="profile.php"><i class=" fa fa-suitcase"></i>Profile</a></li>
                        <li><a href="#update_password-box" class="update_password-window"><i class="fa fa-cog"></i> Change Password</a></li>
                        <li><a href="../logout.php"><i class="fa fa-key"></i> Log Out</a></li>
                    </ul>
                </li>
                <!-- user login dropdown end -->
                <li>
                    <div class="toggle-right-box">
                        <div class="fa fa-bars"></div>
                    </div>
                </li>
            </ul>
            <!--search & user info end-->
        </div>
    </header>
    <!--header end-->
    <!--sidebar start-->
   <aside>
        <div id="sidebar" class="nav-collapse">
            <!-- sidebar menu start-->
            <ul class="sidebar-menu" id="nav-accordion">
					  	<li>
                    	<a class="active" href="db.php" style="background:#0072BC;">
                        <i class="fa fa-dashboard"></i>
                        <span>Dashboard</span>
                    	</a>
                		</li>
					  <?php
					  
				
					  
$orgOb = new classUser;
$orgOb->retrieveOrgDataByOrgID($_SESSION['security']['org_id']);
           
		  
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==5||$_SESSION['security']['userrole_id']==9||$_SESSION['security']['userrole_id']==10)
				{
					?>
					    <li class="sub-menu">
                    	<a href="dbpatient.php" style="background:#BC1C4A;">
                        <i class="fa fa-user"></i>
                        <span>Patient Registration</span>
                    	</a>
                    	</li>
					  <?php
				}
		  
		  if($orgOb->getOPD())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==4||$_SESSION['security']['userrole_id']==5||$_SESSION['security']['userrole_id']==9)
				{
					?>
						<li class="sub-menu">
						<a href="dbopd.php" style="background:#003366;">
						<i class="fa fa-th"></i>
						<span>Out-Patient (OPD)</span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getIPD())
		  {
			  	?>
						<li class="sub-menu">
						<a href="dbipd.php" style="background:#3AC7F9;">
						<i class="fa fa-th"></i>
						<span>In-Patient (IPD)</span>
						</a>
						</li>
						<?php
					
		  }
		  if($orgOb->getOT())
		  {
			   		?>
						<li class="sub-menu">
						<a href="dbot.php" style="background:#D6502A;">
						<i class="fa fa-th"></i>
						<span>Operation Theater</span>
						</a>
						</li>
                        <?php
		  }			
		  if($orgOb->getPharmacy())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==6||$_SESSION['security']['userrole_id']==7||$_SESSION['security']['userrole_id']==8||$_SESSION['security']['userrole_id']==9)
				{
			  		?>
						<li class="sub-menu">
						<a href="dbpharmacy.php" style="background:#00869C;">
						<i class="fa fa-th"></i>
						<span>Pharmacy</span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getDiagnostic())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==14||$_SESSION['security']['userrole_id']==9)
				{
			  	?>
						<li>
						<a href="dbdiagnostics.php" style="background:#380E4D;">
						<i class="fa fa-th"></i>
						<span>Diagnostics </span>
						</a>
						</li>
						<?php
				}
		  }
		  if($orgOb->getEmergency())
		  {
					  ?>
						<li class="sub-menu">
						<a href="dbemergency.php" style="background:#8EC63F;">
						<i class="fa fa-tasks"></i>
						<span>Emergency </span>
						</a>
						</li>
						<?php
		  }
          if($orgOb->getAdmin())
		  {
				if($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==9)
				{
					?>
						<li class="sub-menu">
						<a href="dbadmin.php" style="background:#28282E;">
						<i class="fa fa-laptop"></i>
						<span>Admin Panel</span>
						</a>
						</li>
						<?php
				}
		  }
		  ?>
               
            </ul> 
            <div style="position: absolute; bottom: 2%; padding-left:10%;"><a href="http://www.softusion.com/" target="_blank"><img width="30" height="40" src="../images/SoftusionLOGO.png" alt=""><span style="font-size: 11px; float: right; margin-top: 15%;">Designed by Softusion Inc.</span></a></div><br>
            <!-- sidebar menu end-->
        </div>
    </aside>
    <!--sidebar end-->
    <!--main content start-->
	<!-- InstanceBeginEditable name="center" -->
  <section id="main-content">
    <section class="wrapper">
    <table cellspacing="0" cellpadding="0" width="100%" border="0" style="font-size:11px;">
  <tbody>
    <tr>
      <td width="12%" align="center"><a href="dbopd.php"><img src="../images/icondb.png"></a></td>
      <td width="12%" align="center"><a href="mgmtshifts.php"><img src="../images/iconshifts.png"></a></td>
      <td width="12%" align="center">
      <a href="#select_patient-box" class="select_patient-window"  id="select_patient_popup"><img src="../images/icontoken.png" /></a>
      </td>
      <td width="12%" align="center"><?php $status="close"; echo "<a href='mgmtshifts.php?status=$status'>"; ?><img src="../images/iconshiftclose.png" /></td>
      <td width="12%" align="center"><a href="#select_appointments-box" class="select_appointments-window select_appointments"><img src="../images/iconappoint.png"></a></td>
      <td width="12%" align="center"><a href="opdtransact.php"><img src="../images/iconpayment.png"></a></td>
      <td width="12%" align="center"><a href="mgmtmedissues.php"><img src="../images/icon-practices.png"></a></td>
     
      <td width="12%" align="center"><!--<a href="javascript:Popup('printmgmtlaservisits.php')"><img src="../images/iconlaser.png"></a>--></td>
      <td width="2%" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td align="center"><a href="dbopd.php">Out Patient</a></td>
      <td align="center"><a href="mgmtshifts.php">Manage Shifts</a></td>
      <td align="center">
      <a href="#select_patient-box" class="select_patient-window"  id="select_patient_popup">Create Token</a>
      </td>
      <td align="center"><?php $status="close"; echo "<a href='mgmtshifts.php?status=$status'>Close Shift</a>" ?></td>
      <td align="center"><a href="#select_appointments-box" class="select_appointments-window select_appointments">Appointments</a></td>
      <td align="center"><a href="opdtransact.php">Payments & Refunds</a></td>
      <td align="center"><a href="mgmtmedissues.php">Medical Issues</a></td>
      
      <td align="center"><!--<a href="javascript:Popup('printmgmtlaservisits.php')">Laser Visits</a>--></td>
      <td height="24" align="center">&nbsp; </td>
    </tr>
  </tbody>
</table>
	<br>
 
      <!-- page start-->
      <div class="row">
        <div class="col-sm-12">
          <section class="panel">
          
           <header class="panel-heading">
              <h2>DAILY PATIENTS' VISITS</h2>
            </header>
            
           <?php
			if(isset($error_message)&&$error_message!='')
			{
				?><span class="message_red"><?php echo $error_message;?></span><?php
			}
			?>
            
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
              
                <td width="20%" valign="bottom"></td>
                <td width="80%" align="right">
                <div class="col-md-5" style="float: right;">
            <div class="profile-nav alt">
              <section class="panel">
                <div class="user-heading alt clock-row terques-bg">
                  <h1><?php echo $doctor_name;?></h1>
                  <p class="text-left"><?php echo $shift_created_date?></p>
                  <p class="text-left">Started at: <?php echo $shift_created_time;?></p></br>
                  <p class="text-left"></p>
                  <span>Total Patients: <div style="float:right;"><?php echo $total_patients;?></div></span></br>
                  <span>Total Payables: <div style="float:right;">Rs. <?php echo number_format($total_payables,2);?></div></span></br>
                  <span>Total Payments: <div style="float:right;">Rs. <?php echo number_format($total_payments,2);?></div></span>
                </div>
              </section>
            </div>
          </div>
          		</td>
                
              </tr>
            </table>
            
            <div class="panel-body">
              <div class="adv-table">
                <table  class="display table table-bordered table-striped" id="dynamic-table">
                  <thead>
                    <tr>
                      	<th width="10%" align="left"></th>
            			<th width="5%" align="center">Token</th>
            			<th width="10%" align="center">Time</th>
            			<th width="5%" align="center">ID</th>
            			<th width="15%" align="left">Patient's Name</th>
            			<th width="10%" align="left">Phone</th>
                        <th width="10%" align="left">Issue <span style="float:right; color:#D6502A; font-size:8px; font-weight:normal;"><a href="mgmtmedissues.php">Show List</a></span></th>
            			<th width="10%" align="center">Amount Payable</th>
            			<th width="10%" align="center">Payment</th>
            			<th width="10%" align="center">Balance</th>
            			<th width="5%" align="center">&nbsp;</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();
							
							$retrieveVisitPrecOb = new classVisits;
							$retrieveVisitPrecOb->setVisitID($visit_id);
							$prec_array = $retrieveVisitPrecOb->retrievePrescription();
							
							if ($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==4||$_SESSION['security']['userrole_id']==9)
							{
								$patienthistory_link = "<a href='opdhistory.php?patientid=$patient_id_encoded&visitid=$visit_id_encoded'>Clinical History</a>";
							}
							else
							{
								$href = 'javascript:Popup("printopdhistory.php?patientid='.$patient_id_encoded.'&visitid='.$visit_id_encoded.'")';	 
								$patienthistory_link = "<a href='$href'>Patient History</a>";
								
							} 
							
							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 = "<a href='#transaction-box' class='transaction-window transaction_data' id='$v'> <span class='label label-danger label-mini'>Receive Payment</span></a>";
                                
							  //$payment =  "<a href='transactopd.php?patientid=$patient_id_encoded&visitid=$visit_id_encoded'>Receive Payment</a>";
							} 
							else 
							{ 
								$payment = "Rs. ".$visits_array[$v]["payment"]; 
							}
							
							$balance = 'Rs. '.$visits_array[$v]['balance'];
							
							
							if($visits_array[$v]['pay_status']=="" && $visits_array[$v]['temp']=="" && $visits_array[$v]['bp']=="" && $visits_array[$v]['bsr']=="" && $visits_array[$v]['complaint']=="" && $visits_array[$v]['diagnosis']=="") 
							{
								 $delete = "<a href='?del_visit=$visit_id_encoded'><img src='../images/delete.png'></a>";
							}
							else
							{
								$href = 'javascript:Popup("printopdtoken.php?patientid='.$patient_id_encoded.'&visitid='.$visit_id_encoded.'")';
								$delete = "<a href='$href'>Print</a>";
							}
							
							?>
							
							<?php 
							if(($_SESSION['security']['userrole_id']==1||$_SESSION['security']['userrole_id']==2||$_SESSION['security']['userrole_id']==3||$_SESSION['security']['userrole_id']==9||$_SESSION['security']['userrole_id']==4)&&($visits_array[$v]['temp']=="" && $visits_array[$v]['bp']=="" && $visits_array[$v]['bsr']=="" && $visits_array[$v]['complaint']=="" && $visits_array[$v]['diagnosis']=="" && $visits_array[$v]['notes']=="")) 
							{
								?><tr style="color:#D6502A;"><?php
							}
							elseif($_SESSION['security']['userrole_id']==5&&$visits_array[$v]['pay_status']=="")
							{
								?><tr style="color:#D6502A;"><?php
							}
							else
							{
								?><tr class="<?php echo $class;?>"><?php
							}
							?>
							
                                <td align="center"><?php echo $patienthistory_link;?></td>
                                <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="left">
								
                                    <select name="med_issue_id" class="change_med_issue" id="med_issue_id_<?php echo $v;?>" style="width:120px;>
                                    <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']==$visits_array[$v]['med_issue_id']){echo 'selected';}?>><?php echo ucwords($med_issue_array[$m]['med_issue']);?></option>
										<?php
									}
                                    
                                    ?>
                                
                                    </select>
                                   
                                </td>
                                <td align="right"><?php echo $payable;?></td>
                                <td align="right"><?php echo $payment;?></td>
                                <td align="right" ><?php echo $balance;?>
                                <?php
								if($visits_array[$v]['balance']>0&&$visits_array[$v]['pay_status']!='') 
								{
									?>
									<a href="#transaction_income-box" class="transaction_income-window transaction_income_data" id="<?php echo $v;?>"> <span class="label label-danger label-mini">Balance Payment</span></a>
								  <?php
								}
								?>
                                </td>
                                <td align="center"><?php echo $delete;?></td>
                                
							</tr>
                            
                            <input type="hidden" name="visit_id" class="set_to_pop" id="visit_id_<?php echo $v;?>" value="<?php echo $visit_id;?>">
                        	<input type="hidden" name="patient_id" class="set_to_pop" id="patient_id_<?php echo $v;?>" value="<?php echo $patient_id;?>">
                            
                            <input type="hidden" name="patient_name" class="set_to_pop" id="patient_name_<?php echo $v;?>" value="<?php echo $patient_info[0]['patient_fname'].' '.$patient_info[0]['patient_lname'];?>">
                        	<input type="hidden" name="amount_payable" class="set_to_pop" id="amount_payable_<?php echo $v;?>" value="<?php echo $visits_array[$v]['payable'];?>">
                            
                            <input type="hidden" name="amount_payable_balance" class="set_to_pop" id="amount_payable_balance_<?php echo $v;?>" value="<?php echo $visits_array[$v]['balance'];?>">
							<?php
						}
                    }
					else
					{
						?>
							<tr>
								<table>
									<tr>
										<td>No entries found.</td>
									</tr>
								</table>
							</tr>
						<?php
					}
                    ?>
                  </tbody>
                  <tfoot>
                  </tfoot>
                </table>
              </div>
            </div>
            
          </section>
        </div>
      </div>
      <!-- page end-->
    </section>
  </section>
  
  <!-- InstanceEndEditable --><!--main content end-->
<!--right sidebar start-->
 
<!--right sidebar end-->
</section>
<!-- Placed js at the end of the document so the pages load faster -->
<!--Core js-->
<!--<script src="../js/jquery-1.10.2.min.js"></script>-->
  
 
<script src="../assets/jquery-ui/jquery-ui-1.10.1.custom.min.js"></script>
<script src="../bs3/js/bootstrap.min.js"></script>



<script src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../popUp/popUp.js"></script>
<script src="../js/ajax.js"></script>

<script src="../js/lib/jquery.js"></script>
<script src="../assets/fullcalendar/fullcalendar/fullcalendar.min.js"></script>
<script src="../js/calendar/external-dragging-calendar.js"></script>
<script src="../js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>
<script src="../js/scrollTo/jquery.scrollTo.min.js"></script>
<script src="../js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot-chart/excanvas.min.js"></script><![endif]-->
<script src="../assets/jQuery-slimScroll-1.3.0/jquery.slimscroll.js"></script>
<script src="../assets/skycons/skycons.js"></script>
<script src="../assets/jquery.scrollTo/jquery.scrollTo.js"></script>
<script src="../js/jquery.easing.min.js"></script>
<script src="../assets/calendar/clndr.js"></script>
<script src="../js/underscore-min.js"></script>
<script src="../assets/calendar/moment-2.2.1.js"></script>
<script src="../js/calendar/evnt.calendar.init.js"></script>
<script src="../assets/jvector-map/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../assets/jvector-map/jquery-jvectormap-us-lcc-en.js"></script>
<script src="../assets/gauge/gauge.js"></script>



<!--clock init-->
<script src="../assets/css3clock/js/script.js"></script>
<!--Easy Pie Chart-->
<script src="../assets/easypiechart/jquery.easypiechart.js"></script>
<!--Sparkline Chart-->
<!--Morris Chart-->
<script src="../assets/morris-chart/morris.js"></script>
<script src="../assets/morris-chart/raphael-min.js"></script>
<!--jQuery Flot Chart-->
<script src="../assets/flot-chart/jquery.flot.animator.min.js"></script>
<script src="../assets/flot-chart/jquery.flot.growraf.js"></script>
<script src="../js/dashboard.js"></script>
<script src="../js/custom-select/jquery.customSelect.min.js" ></script>
<!--common script init for all pages-->
<script src="../js/scripts.js"></script>
<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>



<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>
<!--<start===================>-->
<script src="../js/lib/jquery.js"></script>


<script src="../bs3/js/bootstrap.min.js"></script>



<script class="include" type="text/javascript" src="../js/accordion-menu/jquery.dcjqaccordion.2.7.js"></script>

<script src="../js/scrollTo/jquery.scrollTo.min.js"></script>
<script src="../js/nicescroll/jquery.nicescroll.js" type="text/javascript"></script>
<!--Easy Pie Chart-->
<script src="../assets/easypiechart/jquery.easypiechart.js"></script>
<!--Sparkline Chart-->
<script src="../assets/sparkline/jquery.sparkline.js"></script>
<!--jQuery Flot Chart-->
<script src="../assets/flot-chart/jquery.flot.js"></script>
<script src="../assets/flot-chart/jquery.flot.tooltip.min.js"></script>
<script src="../assets/flot-chart/jquery.flot.resize.js"></script>
<script src="../assets/flot-chart/jquery.flot.pie.resize.js"></script>
<script type="text/javascript" src="../assets/bootstrap-daterangepicker/daterangepicker.js"></script>
<script type="text/javascript" src="../assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

<!--dynamic table-->
<!--common script init for all pages-->
<script src="../js/scripts.js"></script>

<!--dynamic table initialization -->
<script src="../js/dynamic_table/dynamic_table_init.js"></script>

<script type="text/javascript" src="../datepicker/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../datepicker/jquery-ui.js"></script>

<!--<script type="text/javascript" src="../popUp/jquery-1.9.0.js"></script>-->
<script type="text/javascript">

 function Popup(apri) { 
	window.open(apri,"","top=10,left=200,width=800,height=700,status=no,menubar=no,toolbar=no,scrollbars=yes"); 
 }
</script> 

<div id="update_password-box" class="update_password-popup">
    
    <div class="pop_header">
        <span>Change Password</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_update_password_form"></div>
          
          <form action="" method="post" id="update_password_form" class="cmxform form-horizontal" onSubmit="return false;">
          	
            <br>
            
         	<div class="form-group">
            <label class="control-label col-lg-3" for="lastname">New Password:</label>
                <div class="col-lg-6">
                    <input type="password" name="password" class="form-control" value="" id="exampleInputPassword1">
                </div>
            </div>
           
            <p align="right">
            	<input type="hidden" name="user_id" value="<?php if(isset($user_id)&&$user_id!=''){echo $user_id;}else{ echo 
				$_SESSION['security']['user_id'];}?>">
                <input type="hidden" name="updateUserPwd" value="yes">
                <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Update"/>
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div> 
 
</body>  
<!-- InstanceEnd --></html>

<div id="select_patient-box" class="select_patient-popup">
    
    <div class="pop_header">
        <span>Select Patient</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <div class="scrollbar" style="height:300px;">
   		<form action="" method="post" id="patient_search_form">
    	<table width="100%" border="0" cellpadding="1" cellspacing="0">
         
          <tr>
          
            <td width="12%" align="right">Search Name: </td>
            <td width="15%">
                <input type="text" name="by_name" id="by_name" value="" class="form-control" aria-controls="dynamic-table">
            </td>
            
            <td width="5%" align="right">ID: </td>
            <td width="15%">
                <input type="text" name="by_id" id="by_id" value="" class="form-control" aria-controls="dynamic-table">
            </td>
            
            <td width="5%" align="right">Phone: </td>
            <td width="15%">
                <input type="text" name="by_phone" id="by_phone" value="" class="form-control" aria-controls="dynamic-table">
            </td>
            
            <td><input name="search" type="submit" id="patient_search" class="btn btn-success btn-sm" value="Search"/></td>
            
            <td width="15%" align="left"><a href="#" id="view_all_patients">View All</a></td>
            
          
          </tr>
        </table>
        <input type="hidden" name="search_patient" value="Search">
        </form>  
        <br>
         
    	<table class="display table table-bordered table-striped" id="dynamic-table">
        
          <thead>
            <tr>
              <th width="5%" align="center">&nbsp;</th>
              <th width="5%" align="center">&nbsp;</th>
              <th width="5%" align="center">ID</th>
              <th width="10%" align="center">DOB</th>
              <th width="20%">Patient Name</th>
              <th width="15%">Phone</th>
              <th width="15%">Registration Date</th>
            </tr>
          </thead>
          <tbody id="default_body">
          	<?php
            if(isset($patients_array[0]['patient_auto_id'])&&$patients_array[0]['patient_auto_id']!='')
            {
                for($p=0;$p<count($patients_array);$p++)
                {
                    if($p%2==0){ $class = 'gradeX';}else{$class = 'gradeC';}
                    
                    $pid = $patients_array[$p]['patient_auto_id'];
                    
                    $imageRetrieveOb = new classImages;
                    $imageRetrieveOb->setPatientAutoID($pid);
                    $image_id = $imageRetrieveOb->fetchImageOfPatient();
                    ?>
                    <form action="" method="post">
                    <tr class="<?php echo $class;?>">
                        <td align="center">
                        <input type="submit" name="select_patient" value="Select" class="btn btn-primary">
                        <input type="hidden" name="patient_type" value="<?php echo $pid;?>">
                        </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 $patients_array[$p]['patient_id'];?></td>
                        <td align="center"><?php echo  date('d M Y',strtotime($patients_array[$p]['dob']));?></td>
                        <td align="left"><?php echo $patients_array[$p]['patient_fname'].' '.$patients_array[$p]['patient_lname'];?></td>
                        <td align="center"><?php echo $patients_array[$p]['phone'];?></td>
                        <td align="center"><?php echo date('d M Y',$patients_array[$p]['reg_date']);?></td>
                    </tr>
                    </form>
                    <?php
                }
            }
            else
            {
                ?>
                <tr>
                    <table>
                        <tr>
                            <td></td>
                        </tr>
                    </table>
                </tr>
                <?php
            }
            ?>
          </tbody>
         
        </table>
        </div>
</div>

<div id="select_appointments-box" class="select_appointments-popup">
    
    <div class="pop_header">
        <span>Select Appointments</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <div class="scrollbar" style="height:300px;">
    
   		<form action="" method="post" id="appointments_search_form">
    	<table width="100%" border="0" cellpadding="1" cellspacing="0">
         
          <tr>
          
            <td width="5%" align="left">Date:</td>
            
            <td width="20%" align="left"><input type="text" name="app_date" value="<?php echo date('Y-m-d',time());?>" id="datepicker" class="form-control" aria-controls="dynamic-table" style="display:inline; width:90%;"></td>
            
            <td width="15%" align="right"><input name="search" type="submit" id="app_search" class="btn btn-success btn-sm" value="Search"/></td>
            
            <td width="50%" align="right"><!--<a href="#" id="view_all_appointments">View All</a>--></td>
            
          
          </tr>
        </table>
        <input type="hidden" name="search_appointments" value="Search">
        <input type="hidden" name="doctor_id" id="app_doctor_id" value="<?php echo $doctor_id;?>">
        
        </form>  
        
        <table class="display table table-bordered table-striped" id="dynamic-table">
        
          <thead>
            <tr>
              <th width="5%" align="center">&nbsp;</th>
              <th width="10%" align="center">App ID</th>
              <th width="10%" align="center">Time In</th>
              <th width="10%" align="center">Time Out</th>
              <th width="20%">Patient Name</th>
              <th width="15%">Phone</th>
              <th width="15%">Reg Date</th>
            </tr>
          </thead>
          <tbody id="default_app_body"></tbody>
         
        </table>
        </div>
</div>

<div id="transaction-box" class="transaction-popup">
    
    <div class="pop_header">
        <span>Transaction</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_opdtransaction_form" style="margin:10px;"></div>
          
          <form action="" method="post" id="insert_opdtransaction_form" class="cmxform form-horizontal" onSubmit="return false;">
          
           	<div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Head:</label>
              <div class="col-lg-6">
              <input type="hidden" name="acchead_id" value="<?php echo $account_data[0]['acchead_id'];?>">
               <?php echo $account_data[0]['acchead_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Name:</label>
              <div class= "col-lg-6">
                <input type="hidden" name="account_id" value="<?php echo $account_data[0]['account_id'];?>">
               <?php echo $account_data[0]['account_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Doctor Name:</label>
              <div class= "col-lg-6">
               <?php echo $doctor_name;?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Type:</label>
              <div class="col-lg-6">
                 <input type="hidden" name="type" value="<?php echo $account_data[0]['type'];?>">
               <?php echo $account_data[0]['type'];?>
              </div>
            </div>
           
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Patient Name:</label>
              <div class="col-lg-6" id="patient_name">
               
              </div>
            </div>
             
            <!--<div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Amount Payable:</label>
              <div class="col-lg-6" id="amount_payable">
               
              </div>
              <input type="hidden" name="amount_payable" id="amount_payable_value" value="">
            </div>-->
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Amount Payable:</label>
              <div class="col-lg-6">
              <input type="text" name="amount_payable" id="amount_payable_value" value="" class="form-control"> 
              </div>
              
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Payment Amount:</label>
              <div class="col-lg-6">
                <input type="text" name="payment_amount" id="lastname" class="form-control">
              </div>
            </div>
            
            
            <p align="right">
              <input type="hidden" name="doctor_id" id="doctor_id" value="<?php echo $doctor_id;?>">
              <input type="hidden" name="patient_id" id="patient_id" value="">
              <input type="hidden" name="visit_id" id="visit_id" value="">
              <input type="hidden" name="trx_opd_patient" value="yes">
              <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save" />
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div>

<div id="transaction_income-box" class="transaction_income-popup">
    
    <div class="pop_header">
        <span>Transaction Balance</span>
        <a href="#" class="pop_close" style="float:right;">Close (X)</a>
    </div>
    
    <table width="100%" border="0" cellspacing="2" cellpadding="2" class="panel">
      <tr>
        <td>
          <div id="result_insert_incometransaction_form" style="margin:10px;"></div>
          
          <form action="" method="post" id="insert_incometransaction_form" class="cmxform form-horizontal" onsubmit="return false;">
          
           	<div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Head:</label>
              <div class="col-lg-6">
              <input type="hidden" name="acchead_id" value="<?php echo $account_data[0]['acchead_id'];?>">
               <?php echo $account_data[0]['acchead_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Name:</label>
              <div class= "col-lg-6">
                <input type="hidden" name="account_id" value="<?php echo $account_data[0]['account_id'];?>">
               <?php echo $account_data[0]['account_name'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="firstname">Account Type:</label>
              <div class="col-lg-6">
                 <input type="hidden" name="type" value="<?php echo $account_data[0]['type'];?>">
               <?php echo $account_data[0]['type'];?>
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Patient Name:</label>
              <div class="col-lg-6" id="patient_name_balance">
               
              </div>
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Amount Payable:</label>
              <div class="col-lg-6" id="amount_payable_balance">
               
              </div>
              <input type="hidden" name="amount_payable" id="amount_payable_balance_value" value="">
            </div>
            
            <div class="form-group">
              <label class="control-label col-lg-3" for="lastname">Payment Amount:</label>
              <div class="col-lg-6">
                <input type="text" name="payment_amount" id="lastname" class="form-control">
              </div>
            </div>
            
           
            <p align="right">
              <input type="hidden" name="doctor_id" id="doctor_id_balance" value="<?php echo $doctor_id;?>">
              <input type="hidden" name="patient_id" id="patient_id_balance" value="">
              <input type="hidden" name="visit_id" id="visit_id_balance" value="">
              <input type="hidden" name="trx_opd_balance" value="yes">
              <input name="ajax_submit" type="submit" class="ajax_submit btn btn-info" value="Save" />
            </p>
            
          </form>
          </td>
          
      </tr>
    </table>
</div>



<script>

$(".transaction_data").click(function() {
	
	var id = this.id;
	
	visit_id = $("#visit_id_"+id).val();
	patient_id = $("#patient_id_"+id).val();
	patient_name = $("#patient_name_"+id).val();
	amount_payable = $("#amount_payable_"+id).val();
	
	$("#visit_id").val(visit_id);
	$("#patient_id").val(patient_id);
	$("#patient_name").html(patient_name);
	//$("#amount_payable").html(amount_payable);
	$("#amount_payable_value").val(amount_payable);
	
	});
	
$(".transaction_income_data").click(function() {

var id = this.id;

visit_id = $("#visit_id_"+id).val();
patient_id = $("#patient_id_"+id).val();
patient_name = $("#patient_name_"+id).val();
amount_payable_balance = $("#amount_payable_balance_"+id).val();

$("#visit_id_balance").val(visit_id);
$("#patient_id_balance").val(patient_id);
$("#patient_name_balance").html(patient_name);
$("#amount_payable_balance").html(amount_payable_balance);
$("#amount_payable_balance_value").val(amount_payable_balance);
	
	
});

	


$(function() {
		$("#datepicker").datepicker({
		showOn: "button",
		changeMonth: true,
		changeYear: true,
		buttonImage: "../images/calendar.gif",
		buttonImageOnly: true,
		dateFormat: "yy-mm-dd"
	});});
</script>