<?php include 'inc_classes.php'; 
include "admin_authentication.php";
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Attendance Summary</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">
  <!-- Bootstrap 3.3.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <!-- Morris chart -->
  <link rel="stylesheet" href="bower_components/morris.js/morris.css">
  <!-- jvectormap -->
  <link rel="stylesheet" href="bower_components/jvectormap/jquery-jvectormap.css">
  <!-- Date Picker -->
  <link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
  <!-- Daterange picker -->
  <link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
  <!-- bootstrap wysihtml5 - text editor -->
  <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <?php include "include/header-main.php"; ?>
  <!-- Left side column. contains the logo and sidebar -->
  <?php include "include/menu_left.php"; ?>
  <!-- Content Wrapper. Contains page content -->
    <!-- Left side column. contains the logo and sidebar -->
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Attendance Summary
        <!--<small>Version 2.0</small>-->
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      
      <div class="row">
        <div class="col-md-12" style="display:none">
          <div class="box">
            <!--<div class="box-header with-border">
              <h3 class="box-title">Monthly Recap Report</h3>

              <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <div class="btn-group">
                  <button type="button" class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown">
                    <i class="fa fa-wrench"></i></button>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="#">Action</a></li>
                    <li><a href="#">Another action</a></li>
                    <li><a href="#">Something else here</a></li>
                    <li class="divider"></li>
                    <li><a href="#">Separated link</a></li>
                  </ul>
                </div>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>
            </div>-->
            <!-- /.box-header -->
            <div class="box-body">
              <div class="row" >
                <div class="col-md-8">
                  <p class="text-center">
                    <strong>Sales: 1 Jan, 2014 - 30 Jul, 2014</strong>
                  </p>

                  <div class="chart">
                    <!-- Sales Chart Canvas -->
                    <canvas id="salesChart" style="height: 180px;"></canvas>
                  </div>
                  <!-- /.chart-responsive -->
                </div>
                <!-- /.col -->
                
                <!-- /.col -->
              </div>
              <!-- /.row -->
            </div>
      
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- Main row -->
      <div class="row">
     	<div class="col-md-3">
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">Todays</h3>

              <!--<div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>-->
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <ul class="products-list product-list-in-box">
                <li class="item">
                	<button type="button" class="btn btn-block btn-success btn-lg" disabled>Check In</button>
                  <!--<div class="product-img">
                    <img src="dist/img/default-50x50.gif" alt="Product Image">
                  </div>
                  <div class="product-info">
                    <a href="javascript:void(0)" class="product-title">Samsung TV
                      <span class="label label-warning pull-right">$1800</span></a>
                    <span class="product-description">
                          Samsung 32" 1080p 60Hz LED Smart HDTV.
                        </span>
                  </div>-->
                </li>
                <?php
				$sel_staf="select attendence_id,cm_id,admin_id from site_setting where 1 and admin_id='".$_SESSION['admin_id']."' ";
				$ptr_staff=mysql_query($sel_staf);
				$data_staff=mysql_fetch_array($ptr_staff);
				
				$c_year = date('Y');
				$c_month = date('m');
				$c_date=date('Y-m-d');
				$cm_id=$data_staff['cm_id'];
				$staff_att_id=$data_staff['attendence_id'];
				$employee_id=$data_staff['admin_id'];
				
				$currentMonth =$c_year.'-'.$c_month.'-01';
				$pr_month=Date('Y-m-d',strtotime($currentMonth));
				$first_day_this_month='01-'.$c_month.'-'.$c_year;
				$last_day_this_month=$days.'-'.$c_month.'-'.$c_year;
				$curr_date='';
				$total_day =0;
				
				$sel_staff="select name,attendence_id from site_setting where attendence_id='".$staff_att_id."' and cm_id='".$cm_id."'";
				$ptr_staff1 = mysql_query($sel_staff);
				if(mysql_num_rows($ptr_staff1))
				{
					$select_user="select * from pr_pune_biometric_attendance where cm_id='".$cm_id."' and year='".$c_year."' and month='".$c_month."' and UserID='".$staff_att_id."' and DATE(PunchTime)='".$c_date."' order by PunchTime asc";
					$ptr_chk_ext=mysql_query($select_user);
					if($tot=mysql_num_rows($ptr_chk_ext))
					{
						$c_in=0;
						$c_out=0;
						$tot_ckout=0;
						$tot_hrs=0;
						$curr_date='';
						$t=0;
						$check_in=array();
						$check_out=array();
						$hrs_min='';
						$ints=0;
						$in_ts='';
						$out_ts='';
						$punch_out='';
						$punch_in='';
						while($data_user_att=mysql_fetch_array($ptr_chk_ext))
						{
							$curr_date=$data_user_att['PunchTime'];
							if($data_user_att['AttendanceType']=='CheckIn')
							{
								$check_in[$c_in] = strtotime($data_user_att['PunchTime']);
								if($ints<=0) //check 1st of record PUNCH IN only
								{
									$in_ts= date('H:i',strtotime($data_user_att['PunchTime'])); // for inserting in DB
									$ints=1;
								}
								$c_in++;
							}
							else if($data_user_att['AttendanceType']=='CheckOut')
							{
								$check_out[$c_out] =strtotime($data_user_att['PunchTime']);
								$out_ts=date('H:i',strtotime($data_user_att['PunchTime']));// for inserting in DB
								$c_out++;
								$tot_ckout++;
							}							
							$t++;
						}
						if($out_ts)
						{
							$punch_out=$out_ts;//date('H:i',$check_out[$chk]);
						}
						if($in_ts)
						{
							$punch_in=$in_ts;//date('H:i',$check_in[$chk]);
						}
						//echo "<br/> totals-  ".$tot_ckout;
						$late_m =0;
						$day_tot=0;
						for($chk=0;$chk<$tot_ckout;$chk++)
						{
							$out=$check_out[$chk];
							$in=$check_in[$chk];
							if($out >0 && $in >0)
							{
								$tot_hrs +=($out - $in);
								$hrs_min=gmdate("H:i", $tot_hrs);
							}
						}
						//$punch_in /  $punch_out /  $hrs_min
					}
				}
				$start_date=date('Y').'-'.date('m').'-01';
				
				$sel_tot_att="select * from pr_daily_attendance where 1 and employee_id='".$_SESSION['admin_id']."' and staff_id='".$staff_att_id."' and date >='".$start_date."' and date <='".date('Y-m-d')."' and cm_id='".$cm_id."'";
				$ptr_to_att=mysql_query($sel_tot_att);
				$tot_rec=mysql_num_rows($ptr_to_att);
				$cnt_time=0;
				while($data_att=mysql_fetch_array($ptr_to_att))
				{
					
					$arr = explode(':', $data_att['total_hrs']);
					if (count($arr) == 2) {
						$ts_sec =  $arr[0] * 60 + $arr[1];
						$tot_whrs +=$ts_sec;
					}
					
					if($ts_sec > '524')
					{
						$cnt_time +=1;
					}
					
					$arr_time = explode(':', $data_att['extra_hrs']);
					if (count($arr) == 2) {
						$avg_tm +=  $arr_time[0] * 60 + $arr_time[1];
					}
				}
				$to_w_hours = round($tot_whrs / 60,2);
				$avg_tot_hr=$to_w_hours/$tot_rec;
				$avg_time_per= ($cnt_time / $tot_rec) *100;
				$extr_hr=round($avg_tm/60,2);
				?>
                <li class="item">
                	<a href="javascript:void(0)" class="uppercase">Check-In </a>
                    <span class="pull-right text-green"><!--<i class="fa fa-angle-left"></i>--> <?php echo $punch_in; ?> AM</span></a></li>
                    <!--<div class="box-footer text-left">
                      
                    </div>-->
                  <!--<div class="product-img">
                    <img src="dist/img/default-50x50.gif" alt="Product Image">
                  </div>
                  <div class="product-info">
                    <a href="javascript:void(0)" class="product-title">Xbox One <span
                        class="label label-danger pull-right">$350</span></a>
                    <span class="product-description">
                          Xbox One Console Bundle with Halo Master Chief Collection.
                        </span>
                  </div>-->
                </li>
                <!-- /.item -->
                <li class="item">
                	<a href="javascript:void(0)" class="uppercase">Check-Out</a>
                    <span class="pull-right text-green"><!--<i class="fa fa-angle-left"></i>--> <?php echo $punch_out; ?> PM</span></a></li>
                  	<!--<div class="box-footer text-left">
                    </div>-->
                </li>
                <!-- /.item -->
                
                <!-- /.item -->
                <li class="item">
                	<a href="javascript:void(0)" class="uppercase">Total Hours</a>
                    <span class="pull-right text-green"><!--<i class="fa fa-angle-left"></i>--> <?php echo $hrs_min; ?> Hrs.</span></a></li>
                  	<!--<div class="box-footer text-left">
                    </div>-->
                </li>
                <!-- /.item -->
              </ul>
            </div>
            <!-- /.box-body -->
            <!--<div class="box-footer text-center">
              <a href="javascript:void(0)" class="uppercase">Past Leaves</a>
            </div>-->
                <!-- /.box-footer -->
          </div>
        </div>
        <!--===Start col for info box 2======-->
        <div class="col-md-3">
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">This Month</h3>

              <!--<div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>-->
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <ul class="products-list product-list-in-box">
                <li class="item">
                	<button type="button" class="btn btn-block btn-default btn-lg">Check For Month</button>
                  <!--<div class="product-img">
                    <img src="dist/img/default-50x50.gif" alt="Product Image">
                  </div>
                  <div class="product-info">
                    <a href="javascript:void(0)" class="product-title">Samsung TV
                      <span class="label label-warning pull-right">$1800</span></a>
                    <span class="product-description">
                          Samsung 32" 1080p 60Hz LED Smart HDTV.
                        </span>
                  </div>-->
                </li>
                <li class="item">
                	<a href="javascript:void(0)" class="uppercase">Average Hours / Day</a>
                    <span class="pull-right text-green"> <?php echo round($avg_tot_hr,2); ?> Hrs.</span></a></li>
                    <!--<div class="box-footer text-left">
                    </div>-->
                  <!--<div class="product-img">
                    <img src="dist/img/default-50x50.gif" alt="Product Image">
                  </div>
                  <div class="product-info">
                    <a href="javascript:void(0)" class="product-title">Xbox One <span
                        class="label label-danger pull-right">$350</span></a>
                    <span class="product-description">
                          Xbox One Console Bundle with Halo Master Chief Collection.
                        </span>
                  </div>-->
                </li>
                <!-- /.item -->
                <li class="item">
                	<a href="javascript:void(0)" class="uppercase">On Time Average</a>
                    <span class="pull-right text-green"> <?php echo round($avg_time_per,2); ?>%</span></a></li>
                  	<!--<div class="box-footer text-left">
                    </div>-->
                </li>
                <!-- /.item -->
                
                <!-- /.item -->
                <li class="item">
                	<a href="javascript:void(0)" class="uppercase">Extra Hours</a>
                    <span class="pull-right text-green"> <?php echo $extr_hr; ?> Hrs.</span></a></li>
                  	<!--<div class="box-footer text-left">
                    </div>-->
                </li>
                <!-- /.item -->
              </ul>
            </div>
            <!-- /.box-body -->
            <!--<div class="box-footer text-center">
              <a href="javascript:void(0)" class="uppercase">Past Leaves</a>
            </div>-->
                <!-- /.box-footer -->
            </div>
        </div>
        <!--==========End col info box=======-->
        <div class="col-md-6">
          <div class="box box-default">
            <div class="box-header with-border">
              <h3 class="box-title">Summary</h3>
              <!--<div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>-->
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <div class="row">
                <div class="col-md-8">
                  <div class="chart-responsive">
                    <canvas id="pieChart" height="150"></canvas>
                  </div>
                  <!-- ./chart-responsive -->
                </div>
                <!-- /.col -->
                <div class="col-md-4">
                  <ul class="nav nav-pills nav-stacked">
                  	<li><a href="#">Totla Working Day
                      <span class="pull-right text-green">30</span></a></li>
                    <li>
                    <li><a href="#">Totla leaves
                      <span class="pull-right text-red"><i class="fa fa-angle-down"></i> 2</span></a></li>
                    <li>
                      <a href="#">Present Day<span class="pull-right text-green"><i class="fa fa-angle-up"></i> 22</span></a>
                    </li>
                    <li><a href="#">Holidays
                      <span class="pull-right text-yellow"><i class="fa fa-angle-left"></i> 6</span></a>
                    </li>
                  </ul>
                </div>
                <!-- /.col -->
              </div>
              <!-- /.row -->
            </div>
            <!-- /.box-body -->
            <!--<div class="box-footer no-padding">
              
            </div>-->
            <!-- /.footer -->
          </div>
        </div>
        <!--==========End col info box=======-->
        
      </div>
      <div class="row">
        <!-- Left col -->
        <div class="col-md-12">
          <!-- TABLE: LATEST ORDERS -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Attendace Summary For last 10 Days</h3>

              <!--<div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>-->
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <div class="table-responsive">
                <table class="table no-margin">
                  <thead>
                  <tr>
                    <th>Sr. No.</th>
                    <th>Date</th>
                    <th>Punch-In</th>
                    <th>Punch-Out</th>
                    <th>Total Hours</th>
                    <th>Extra Hrs.</th>
                    <th>Time Utilized</th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php
				  $sel_attts="select * from pr_daily_attendance where employee_id='".$_SESSION['admin_id']."' and staff_id='".$staff_att_id."' order by attendance_id desc limit 0,10";
				  $ptr_atts=mysql_query($sel_attts);
				  $t=1;
				  while($data_atts=mysql_fetch_array($ptr_atts))
				  {
					  $arr = explode(':', $data_atts['total_hrs']);
					  if (count($arr) == 2) {
						 $ts_sec =  $arr[0] * 60 + $arr[1];
					  }
					  if($ts_sec >= '524')
					  {
						  $ontime='<span class="label label-success">Yes</span>';
					  }
					  else
					  {
						  $ontime='<span class="label label-warning">No</span>';
					  }
					  ?>
                      <tr>
                        <td><?php echo $t; ?></td>
                        <td><?php echo date('d M y',strtotime($data_atts['date']))?></td>
                        <td><?php echo $data_atts['punch_in']; ?> AM</td>
                        <td><?php echo $data_atts['punch_out']; ?> PM</td>
                        <td><?php echo $data_atts['total_hrs']; ?> Hrs</td>
                        <td><?php echo $data_atts['extra_hrs']; ?> Hrs</td>
                        <td><?php echo $ontime; ?></td>
                        <!--<td>
                          <div class="sparkbar" data-color="#00a65a" data-height="20">90,80,90,-70,61,-83,63</div>
                        </td>-->
                      </tr>
                      <?php
					  $t++;
				  }
				  ?>
                  </tbody>
                </table>
              </div>
              <!-- /.table-responsive -->
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
              <!--<a href="javascript:void(0)" class="btn btn-sm btn-info btn-flat pull-left">Place New Order</a>
              <a href="javascript:void(0)" class="btn btn-sm btn-default btn-flat pull-right">View All Orders</a>-->
            </div>
            <!-- /.box-footer -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
	  </div>
      
      <!--<div class="row">
        <div class="col-md-4">
          <div class="info-box bg-yellow">
            <span class="info-box-icon"><i class="ion ion-ios-pricetag-outline"></i></span>

            <div class="info-box-content">
              <span class="info-box-text">Inventory</span>
              <span class="info-box-number">5,200</span>

              <div class="progress">
                <div class="progress-bar" style="width: 50%"></div>
              </div>
              <span class="progress-description">
                    50% Increase in 30 Days
                  </span>
            </div>
          </div>
          <div class="info-box bg-green">
            <span class="info-box-icon"><i class="ion ion-ios-heart-outline"></i></span>

            <div class="info-box-content">
              <span class="info-box-text">Mentions</span>
              <span class="info-box-number">92,050</span>

              <div class="progress">
                <div class="progress-bar" style="width: 20%"></div>
              </div>
              <span class="progress-description">
                    20% Increase in 30 Days
                  </span>
            </div>
          </div>
          <div class="info-box bg-red">
            <span class="info-box-icon"><i class="ion ion-ios-cloud-download-outline"></i></span>

            <div class="info-box-content">
              <span class="info-box-text">Downloads</span>
              <span class="info-box-number">114,381</span>

              <div class="progress">
                <div class="progress-bar" style="width: 70%"></div>
              </div>
              <span class="progress-description">
                    70% Increase in 30 Days
                  </span>
            </div>
          </div>
          <div class="info-box bg-aqua">
            <span class="info-box-icon"><i class="ion-ios-chatbubble-outline"></i></span>

            <div class="info-box-content">
              <span class="info-box-text">Direct Messages</span>
              <span class="info-box-number">163,921</span>

              <div class="progress">
                <div class="progress-bar" style="width: 40%"></div>
              </div>
              <span class="progress-description">
                    40% Increase in 30 Days
                  </span>
            </div>
          </div>
          
        </div>
      </div>-->
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php include "include/footer-main.php"; ?>
</div>
<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- Sparkline -->
<script src="bower_components/jquery-sparkline/dist/jquery.sparkline.min.js"></script>
<!-- jvectormap  -->
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<!-- SlimScroll -->
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- ChartJS -->
<script src="bower_components/chart.js/Chart.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="dist/js/pages/dashboard2.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
</body>
</html>