<?php
	//include '../db_connect.php';
	//check_admin_cookie();
	include ('common/connection.php');
	$user_sql="select * from user_master where User_Name='".$_SESSION['user']."'";
$user_query=mysqli_query($con,$user_sql);
$user=mysqli_fetch_array($user_query);
$cityname=mysqli_fetch_array(mysqli_query($con,"select * from location_master where SLN='".$user['Location']."'"));
$cityname['Location_Name'];
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Buurtzorg  | Daily Report | operation</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <?php include("headerlink.php"); ?>
  
  <link rel="stylesheet" href="css/data-table/bootstrap-table.css">
    	<link rel="stylesheet" href="css/data-table/bootstrap-editable.css">
		<style>
		.fixed-table-container thead th .th-inner, .fixed-table-container tbody td .th-inner {
		padding: 8px;
		line-height:inherit;
		vertical-align: top;
		overflow: hidden;
		text-overflow: inherit;
		white-space: inherit;
		width: 50px;
		font-size: 12px;}
		.lb_bg {
			margin-top: 10px;
			padding: 10px 10px 8px;
			background-color: #f1f1f1;
			font-weight: 600;
		}
		</style>
  <!-- Bootstrap 3.3.7 -->
  <?php 
  //$sql_all ="select * from allocation_master where doctor_name='".$_SESSION['id']."' or nurse_name='".$_SESSION['id']."'";
  //$res_all= mysqli_query($con,$sql_all);
  //$fetch=mysqli_fetch_array($res_all);
  ?>
</head>
<body>
 <?php include("left-menu.php"); ?>
    
 
    <div class="all-content-wrapper">
        
        
       <?php include("header-menu.php"); ?> 

  <!-- Content Wrapper. Contains page content -->
  <div class="static-table-area">
    <!-- Content Header (Page header) -->
    <div class="container-fluid">
       <div class="row">
                
       <div class="col-lg-12 col-md-6 col-sm-6 col-xs-12" style="padding:30px 15px 0px;">
          <div class="sparkline9-list mt-b-30 res-mg-t-30 analysis-progrebar-ctn">
    
      <h3 style="margin:0 0 15px 0;">
        Daily Operational Report
       </h3>
    

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
     
		

          <div class="box">
           
            <!-- /.box-header -->
            <div class="box-body" style="overflow-x:auto;">
			<form method="post">
			<select name="post_report" class="form-control" id="post_report" style="width:170px; float:left; margin-top: 10px;">
														<option value="">Select Location</option>
														<?php
														$location_sql=mysqli_query($con,"select * from location_master where Active='Yes'");
														while($location=mysqli_fetch_array($location_sql))
														{
															?>
														<option value="<?php echo $location['SLN']; ?>"<?php if($_REQUEST['post_report']==$location['SLN']){echo "selected";} ?>><?php echo $location['Location_Name']; ?></option>	
															<?php
														}
															?>
														 </select>
			<input type="submit" name="submit" id="submit" value="submit" style="width:100px;height:38px; float:left; margin-top: 10px;margin-left:10px;">											 
														 
            </form>
            <!--<div class="col-xs-12" style="padding:0px; margin-bottom:15px;">
            <button class="btn btn-info" style="float:right; border-radius:0px;"><a href="report_wise_treatment_report1.php">Export</a></button>
			</div>-->
			<?php 
			$condition_to=" Treatment_Service_Date='".date('Y-m-d')."'";
			if($_REQUEST['post_report']!="")
			{
			$condition_to.=" and Control_Location='".$_REQUEST['post_report']."'";	
			}
			$fetch_hours=mysqli_fetch_array(mysqli_query($con,"select sum(Planned_Hours_Count) as counthr from roster_master where {$condition_to}")); 
			$condition_mtd=" Treatment_Service_Date between '".date('Y-m-01')."' and '".date('Y-m-d')."'";
			if($_REQUEST['post_report']!="")
			{
			$condition_mtd.=" and Control_Location='".$_REQUEST['post_report']."'";	
			}
			//"select sum(Planned_Hours_Count) as countmtd from roster_master where {$condition_mtd}";
			$fetch_mtd=mysqli_fetch_array(mysqli_query($con,"select sum(Planned_Hours_Count) as countmtd from roster_master where {$condition_mtd}"));
			?>
			
            <div class="col-xs-3" style="padding-right: 7.5px;"><div class="lb_bg">Today Hour of service : <?php echo $fetch_hours['counthr']; ?></div></div>
			<div class="col-xs-3" style="padding-left: 7.5px;"><div class="lb_bg">Hour of MTD : <?php echo $fetch_mtd['countmtd']; ?></div></div>
			
			
			
              <table id="Table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="false" data-show-pagination-switch="false" data-show-refresh="false" data-key-events="false" data-show-toggle="false" data-resizable="false" data-cookie="false"
                                        data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar">
                <thead>
                 <tr>
                  <th>Date</th>
				  <th>Day</th>
				  <th>Pln Hrs</th>
				  <th>Actl Hrs</th>
				  <th>Crtcal Srvce</th>
				  <th>Smi Crtcl Srvce</th>
				  <th>Compnnshp Srvce</th>
				  <th>Bby Cr Srvce</th>
				  <th>In Srvce Emp</th>
				  <th>On Call Emp</th>
				  <th>Week Off</th>
				  <th>Leave</th>
				  <th>Absent</th>
				  <th>Total Emp</th>
				  <th>Active Emp</th>
				  <th>Mnthly Cpcty</th>
				  <th>Mnthly Actl</th>
				  <th>Mnthly Srpls</th>
				  <th>Avail Resrcs</th>
                  </tr>
                </thead>
                 <tbody>
                    
                    <?php
					$first_day_this_month = date('Y-m-01');
					$last_day_this_month  = date('Y-m-t');
					if($_REQUEST['post_report']!="")
					{
					$condition.=" Control_Location='".$_REQUEST['post_report']."' and Treatment_Service_Date between '".$first_day_this_month."' and '".$last_day_this_month."' and Active='0' group by Treatment_Service_Date";
					}
					else
					{
					$condition=" Treatment_Service_Date between '".$first_day_this_month."' and '".$last_day_this_month."' group by Treatment_Service_Date";	
					}
					$roster_master_sql="select * from roster_master where {$condition}";
					$roster_master=mysqli_query($con,$roster_master_sql);
					if(mysqli_num_rows($roster_master)>0)
					{
						while($fetch_report=mysqli_fetch_array($roster_master))
						{
							$timestamp = strtotime($fetch_report['Treatment_Service_Date']);

							$day = date('D',$timestamp);
							
							if($_REQUEST['post_report']!="")
							{
							$condition_pl=" Control_Location='".$_REQUEST['post_report']."' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";
							}
							else
							{
							$condition_pl=" `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";	
							}
							$sum_planned_hr_sql="SELECT sum(`Number_Of_Working_Hour`) as sumplaned FROM `roster_master`  WHERE {$condition_pl}";	
							$sum_planned_hr=mysqli_fetch_array(mysqli_query($con,$sum_planned_hr_sql));
							
							//echo "SELECT sum(`Planned_Hours_Count`) as sumactual FROM `roster_master`  WHERE `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							if($_REQUEST['post_report']!="")
							{
							$condition_act=" Control_Location='".$_REQUEST['post_report']."' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							}
							else
							{
							$condition_act=" `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";	
							}
							$sum_actual_hrs_sql="SELECT sum(`Planned_Hours_Count`) as sumactual FROM `roster_master`  WHERE {$condition_act}";
							$sum_actual_hrs=mysqli_fetch_array(mysqli_query($con,$sum_actual_hrs_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_critical=" Control_Location='".$_REQUEST['post_report']."' and Service_Type='critical' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";
							}
							else
							{
							$condition_critical=" Service_Type='critical' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";	
							}
							$critical_sql="select Sum(Number_Of_Working_Hour) as criticalcare from roster_master where {$condition_critical}";
							$critical=mysqli_fetch_array(mysqli_query($con,$critical_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_semicritical=" Control_Location='".$_REQUEST['post_report']."' and Service_Type='semicritical' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";
							}
							else
							{
							$condition_semicritical=" Service_Type='semicritical'  and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";	
							}
							$semicritical_sql="select sum(Number_Of_Working_Hour) as semicriticalcare from roster_master where {$condition_semicritical}";
							$semicritical=mysqli_fetch_array(mysqli_query($con,$semicritical_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_champion=" Control_Location='".$_REQUEST['post_report']."' and Service_Type='Companionship' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";
							}
							else
							{
							$condition_champion=" Service_Type='Companionship' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and  Active='0'";	
							}
							$champion_sql="select sum(Number_Of_Working_Hour) as champion from roster_master where {$condition_champion}";
							$champion=mysqli_fetch_array(mysqli_query($con,$champion_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_baby=" Control_Location='".$_REQUEST['post_report']."' and Service_Type='baby' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";
							}
							else
							{
							$condition_baby=" Service_Type='baby' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."' and Active='0'";	
							}
							$baby_sql="select sum(Number_Of_Working_Hour) as babycare from roster_master where {$condition_baby}";
							$baby=mysqli_fetch_array(mysqli_query($con,$baby_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_emp=" Control_Location='".$_REQUEST['post_report']."' and Offday='0' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							}
							else
							{
							$condition_emp=" Offday='0' and Visiting_Time_From!='00:00:00' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";	
							}
							$service_emp_sql="select count(TNA_Name) as servicetna from roster_master where {$condition_emp}";
							$service_emp=mysqli_fetch_array(mysqli_query($con,$service_emp_sql));
							
							
							if($_REQUEST['post_report']!="")
							{
							$condition_oncall=" Control_Location='".$_REQUEST['post_report']."' and Offday='4' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							}
							else
							{
							$condition_oncall=" Offday='4' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";	
							}
							$oncall_sql="select count(TNA_Name) as oncalltna from roster_master where {$condition_oncall}";
							$oncall=mysqli_fetch_array(mysqli_query($con,$oncall_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_weekoff=" Control_Location='".$_REQUEST['post_report']."' and (Offday='1' || Offday='3') and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							}
							else
							{
							$condition_weekoff=" (Offday='1' || Offday='3') and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";	
							}
							$weekoff_sql="select count(TNA_Name) as wo from roster_master where {$condition_weekoff}";
							$weekoff=mysqli_fetch_array(mysqli_query($con,$weekoff_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_leave=" Control_Location='".$_REQUEST['post_report']."' and Offday='2' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							}
							else
							{
							$condition_leave=" Offday='2' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";	
							}
							$leave_sql="select count(TNA_Name) as leavetna from roster_master where {$condition_leave}";
							$leave=mysqli_fetch_array(mysqli_query($con,$leave_sql));
							
							if($_REQUEST['post_report']!="")
							{
							$condition_absent=" Control_Location='".$_REQUEST['post_report']."' and (Offday='0' || Offday='4') and Visiting_Time_From='00:00:00' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";
							}
							else
							{
							$condition_absent=" (Offday='0' || Offday='4') and Visiting_Time_From='00:00:00' and `Treatment_Service_Date`='".$fetch_report['Treatment_Service_Date']."'";	
							}
							$absent_sql="select count(TNA_Name) as absenttna from roster_master where {$condition_absent}";
							$absent=mysqli_fetch_array(mysqli_query($con,$absent_sql));
							//$sum_actual_hr=$critical['criticalcare']+$semicritical['semicriticalcare']+$champion['champion']+$baby['babycare'];
							
					?>
					
					<tr>
                        <td><?php echo date('d,M Y',strtotime($fetch_report['Treatment_Service_Date'])); ?></td>
                        <td><?php echo  $day;?></td>
                        <td><?php echo $sum_planned_hr['sumplaned']; ?></td>
						<td><?php echo $sum_actual_hrs['sumactual']; ?></td>
						<?php
						if($critical['criticalcare']!="")
						{
						?>
                        <td><?php echo $critical['criticalcare']; ?></td>
						<?php
						}
						else
						{
							?>
							<td><?php echo "0";?></td>
							<?php
						}
						if($semicritical['semicriticalcare']!="")
						{
						?>
						<td><?php echo $semicritical['semicriticalcare']; ?></td>
						<?php
						}
						else
						{
							?>
							<td><?php echo "0";?></td>
							<?php
						}
						if($champion['champion']!="")
						{
						?>
                        <td><?php echo $champion['champion']; ?></td>
						<?php
						}
						else
						{
							?>
							<td><?php echo "0";?></td>
							<?php
						}
						if($baby['babycare']!="")
						{
						?>
						<td><?php echo $baby['babycare']; ?></td>
						<?php
						}
						else
						{
							?>
							<td><?php echo "0";?></td>
							<?php
						}
						?>
                        <td><?php echo $service_emp['servicetna']; ?></td>
						<td><?php echo $oncall['oncalltna']; ?></td>
                        <td><?php echo $weekoff['wo']; ?></td>
						<td><?php echo $leave['leavetna']; ?></td>
						<?php
							if($fetch_report['Treatment_Service_Date']<=date('Y-m-d'))
							{
						?>
                        <td><?php echo $absent['absenttna']; ?></td>
						<?php
							}
							$totaltna=$service_emp['servicetna']+$oncall['oncalltna']+$weekoff['wo']+$leave['leavetna'];
							$activetna=$service_emp['servicetna']+$oncall['oncalltna']+$weekoff['wo'];
							$monthly_capacity=$totaltna*240;
							$monthly_actual=$activetna*240;
							$monthly_surplus=$monthly_actual-($sum_actual_hrs['sumactual']*31);
							$avlresourc=$monthly_surplus/240;
						?>
						<td><?php echo $totaltna; ?></td>
                        <td><?php echo $activetna; ?></td>
						<td><?php echo $monthly_capacity; ?></td>
                        <td><?php echo $monthly_actual; ?></td>
						<td><?php echo $monthly_surplus; ?></td>
                        <td><?php echo $avlresourc; ?></td>
                    </tr>
                   
                    <?php 
						}
					}
					?>
                   
                  </tbody>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
         </div>
       </div>
       
     </div>
    </div>
    
    </div>
    
   </div> 
    
  <!-- /.content-wrapper -->
 <div class="footer-copyright-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="footer-copy-right">
                            <p>Copyright © 2019. All rights reserved.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
 
 
</div>
 
   <!-- jquery
		============================================ -->
    <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <!-- bootstrap JS
		============================================ -->
    <script src="js/bootstrap.min.js"></script>
    <!-- wow JS
		============================================ -->
    <script src="js/wow.min.js"></script>
    <!-- price-slider JS
		============================================ -->
    <script src="js/jquery-price-slider.js"></script>
    <!-- meanmenu JS
		============================================ -->
    <script src="js/jquery.meanmenu.js"></script>
    <!-- owl.carousel JS
		============================================ -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- sticky JS
		============================================ -->
    <script src="js/jquery.sticky.js"></script>
    <!-- scrollUp JS
		============================================ -->
    <script src="js/jquery.scrollUp.min.js"></script>
    
    
    
    <!-- datepicker JS
		============================================ -->
    <script src="js/datepicker/jquery-ui.min.js"></script>
    <script src="js/datepicker/datepicker-active.js"></script>
    
    
    
    <!-- data table JS
		============================================ -->
    <script src="js/data-table/bootstrap-table.js"></script>
    <script src="js/data-table/tableExport.js"></script>
    <script src="js/data-table/data-table-active.js"></script>
    <script src="js/data-table/bootstrap-table-editable.js"></script>
    <script src="js/data-table/bootstrap-editable.js"></script>
    <script src="js/data-table/bootstrap-table-resizable.js"></script>
    <script src="js/data-table/colResizable-1.5.source.js"></script>
    <script src="js/data-table/bootstrap-table-export.js"></script>
    
    
    
    <!-- mCustomScrollbar JS
		============================================ -->
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>
    <!-- metisMenu JS
		============================================ -->
    <script src="js/metisMenu/metisMenu.min.js"></script>
    <script src="js/metisMenu/metisMenu-active.js"></script>
    <!-- peity JS
		============================================ -->
    <script src="js/peity/jquery.peity.min.js"></script>
    <script src="js/peity/peity-active.js"></script>
    <!-- sparkline JS
		============================================ -->
    <script src="js/sparkline/jquery.sparkline.min.js"></script>
    <script src="js/sparkline/sparkline-active.js"></script>
    <!-- tab JS
		============================================ -->
    <script src="js/tab.js"></script>
    <!-- plugins JS
		============================================ -->
    <script src="js/plugins.js"></script>
    <!-- main JS
		============================================ -->
    <script src="js/main.js"></script>
    <!-- tawk chat JS
		============================================ -->
        
         <script>
$(document).ready(function() {
   $("body").tooltip({ 
   	selector: '[data-toggle=tooltip]' 
	 });
});
 
</script>
<!------------------------Fancybox---------------------------------->
 
 <script type="text/javascript" src="lib/jquery.mousewheel.pack.js"></script>

<script type="text/javascript" src="source/jquery.fancybox.pack.js?v=2.1.5"></script>
	<link rel="stylesheet" type="text/css" href="source/jquery.fancybox.css" media="screen" />

<style type="text/css">
	.fancybox-custom .fancybox-skin {
		box-shadow: 0 0 50px #222;
	}
</style> 
<script>
$(document).ready(function() {
	$(".various5").fancybox({
		maxWidth	: 800,
		maxHeight	: 410,
		fitToView	: true,
		width		: '100%',
		height		: '100%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		
		
		
		
	});
	
 
});

</script>
<script>
$(document).ready(function() {
	$(".various6").fancybox({
		maxWidth	: 380,
		maxHeight	: 410,
		fitToView	: true,
		width		: '100%',
		height		: '100%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none',
		
		
		
		
	});
	
 
});

</script>
</body>
</html>
