<?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>Check For Month</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>
        Check For Month
        <!--<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>
    <script>
	$(document).ready(function()
	{
		$("#year").chosen({allow_single_deselect:true});
		$("#month").chosen({allow_single_deselect:true});
		$("#staff_id").chosen({allow_single_deselect:true});
		
		<?php
		if($_SESSION['type']=="S" || $_SESSION['type']=='Z' || $_SESSION['type']=='LD' )
		{
			?>
			$("#branch_name").chosen({allow_single_deselect:true});
			<?php
		}
		?>
	});
	</script>
   <style>
	.table-bordered > thead > tr > th, .table-bordered > tbody > tr > th, .table-bordered > tfoot > tr > th, .table-bordered > thead > tr > td, .table-bordered > tbody > tr > td, .table-bordered > tfoot > tr > td {
  	border: 1px solid #782929 !important;
	}
   </style>
    <!-- Main content -->
            <!-- /.box-header -->
            <div class="box-body">
              <div class="table-responsive">
                <table class="tbl table no-margin table-bordered">
                  <thead>
                  <tr>
                  	<th class="th1">Date</th>
					<th class="th1">Punch In</th>
					<th class="th1">Punch Out</th>
					<th class="th1">Total Hrs</th>
					<th class="th1">Extra Hrs</th>
					<th class="th1">Full Day</th>
					<th class="th1">Half Day</th>
					<th class="th1">Day Total</th> 
					<th class="th1">Total Till Date</th>
					<th class="th1">Late Marks</th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php
                  $staff="select name,attendence_id from site_setting where attendence_id='".$val_query1['staff_id']."' and system_status='Enabled' ".$where_branch_name." ";
                  $staff1 = mysql_query($staff);
                  //if(mysql_num_rows($staff1))
                  // {
                  $staff_name = mysql_fetch_array($staff1);
                  ?>
                  <tr>
                  	<td class="td1 td2" colspan="17" style="background-color:#F2F2F2;"><b style="color:green;font-size:14px;float:left;"><?php echo $staff_name['name'];?></b></td></tr>
                  	<?php
              		$currrentDate =date('Y-m-d');
              		$newMonth = date("m", strtotime ( '-1 month' , strtotime ( $currrentDate ) )) ;
              		$newYear = date("Y", strtotime ( '-1 month' , strtotime ( $currrentDate ) )) ;
              
					//$prevmonth = date('M Y ', strtotime("last month"));
              
					$select_exc="select * from pr_import_attendance where month ='".$newMonth."' and year='".$newYear."' and employee_id='".$_SESSION['admin_id']."' ";
					$ptr_fs = mysql_query($select_exc);
					if(mysql_num_rows($ptr_fs)) 
					{
						$t=1;
						$val_query1 = mysql_fetch_array($ptr_fs);
						{ 
							//  $staff="select name,attendence_id from site_setting where attendence_id='".$val_query1['staff_id']."' and system_status='Enabled' ".$where_branch_name." ";
							//  $staff1 = mysql_query($staff);
							// if(mysql_num_rows($staff1))
							// {
								// $staff_name = mysql_fetch_array($staff1);
								?>
								<!-- <tr>
							<td class="td1 td2" colspan="17" style="background-color:#F2F2F2;"><b style="color:green;font-size:14px;float:left;"><?php echo $staff_name['name'];?></b></td></tr> -->
								<?php
								//$number=mysql_num_rows($ptr_fs);
								//$no=$number%$val_query['days'];
								//if ($number != 0 && $number%$val_query['days'] == 0)
								//{
								//	echo $val_query['staff_id'];
								//	}
								$year=$newYear;
								$month=$newMonth;
								$currentMonth =$year.'-'.$month.'-01';
								$pr_month=Date('M',strtotime($currentMonth));
								$first_day_this_month='01-'.$pr_month.'-'.$year;
								$last_day_this_month=$val_query1['days'].'-'.$pr_month.'-'.$year;

								$days = cal_days_in_month(CAL_GREGORIAN, $month, $year); // 31
								$tot_seconds = 0;
								$ex_seconds=0;
								$tot_full_day=0;
								$tot_half_day=0; 
								$tot_quarter_day=0; 
								$tot_onethird_day=0;
								$tot_present_day=0;
								for($i=1;$i<=$days;$i++)
								{
									if($i<10)
									{
										$d='0'.$i;
									}
									else
									{
										$d=$i;
									}
									$curr_date=$year.'-'.$month.'-'.$d;
									$pr_month=Date('M',strtotime($curr_date));
									$select_exc1 ="select * from pr_import_attendance where DATE(date)='".$curr_date."'  AND staff_id='".$val_query1['staff_id']."' and employee_id='".$_SESSION['admin_id']."' AND month='".$newMonth."' AND year='".$newYear."' ".$where_branch_name." order by staff_id,date asc";
									//$select_exc1 ="select * from pr_import_attendance where date>='".$first_day_this_month."' AND date<='".$last_day_this_month."' AND staff_id='".$val_query1['staff_id']."' AND month='".$_REQUEST['month']."' AND year='".$_REQUEST['year']."' AND branch_name='".$_REQUEST['branch_name']."' order by staff_id,date asc";
									$ptr_fs1 = mysql_query($select_exc1);
									$tot_present_day +=mysql_num_rows($ptr_fs1);
									$val_query = mysql_fetch_array($ptr_fs1);
									//while($val_query = mysql_fetch_array($ptr_fs1))
									//{
										//Date in YYYY-MM-DD format.
										$date =$curr_date;
										$att_date=$d.'-'.$pr_month.'-'.$year;
										//Set this to FALSE until proven otherwise.
										$weekendDay = false;
										//Get the day that this particular date falls on.
										$day = date("D", strtotime($date));
										//Check to see if it is equal to Sat or Sun.
										if($day == 'Sun'){
											//Set our $weekendDay variable to TRUE.
											//$weekendDay = true;
											$datestyle="style='background-color:#FF6262;'";
										}
										else if($day == 'Sat'){
											//Set our $weekendDay variable to TRUE.
											//$weekendDay = true;
											$datestyle="style='background-color:#FBF882;'";
										}
										else{
											$datestyle="";
										}
										?>
										<tr>
											<td class="td1 td2" <?php echo $datestyle; ?>><?php echo $att_date;  ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?>><?php echo $val_query['punch_in']; ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?>><?php echo $val_query['punch_out']; ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?>><?php echo $val_query['total_hrs']; ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?>><?php echo $val_query['extra_hrs']; ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?> id="chk_full_day_<?php echo $val_query['attendance_id']; ?>" ><div ondblclick="return editColumn(<?php echo $val_query['attendance_id'];?>,'full_day')" id="edit_full_day_<?php echo $val_query['attendance_id']; ?>"><?php echo $val_query['full_day']; ?> &nbsp;&nbsp;&nbsp;</div></td>
											<td class="td1 td2" <?php echo $datestyle; ?> id="chk_half_day_<?php echo $val_query['attendance_id']; ?>" ><div ondblclick="return editColumn(<?php echo $val_query['attendance_id'];?>,'half_day')" id="edit_half_day_<?php echo $val_query['attendance_id']; ?>"><?php echo $val_query['half_day']; ?>&nbsp;&nbsp;&nbsp;</div></td>

											<td class="td1 td2" <?php echo $datestyle; ?> ><?php echo $val_query['day_total']; ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?> ><?php echo $val_query['total_till_date']; ?></td>
											<td class="td1 td2" <?php echo $datestyle; ?> id="chk_late_mark_<?php echo $val_query['attendance_id']; ?>"><div ondblclick="return editColumn(<?php echo $val_query['attendance_id'];?>,'late_mark')" id="edit_late_mark_<?php echo $val_query['attendance_id']; ?>"><?php if($val_query['late_marks']==0) echo ''; else echo $val_query['late_marks']; ?>&nbsp;&nbsp;&nbsp;</div></td>
											<?php
											//$tot_hr +=$val_query['total_hrs'];
											$tot_hr=$val_query['total_hrs'].':00';
											$extra_hr =$val_query['extra_hrs'].':00';
											$day_totals +=$val_query['day_total']; 
											$total_till_date=$val_query['total_till_date'];
											$tot_late_mark +=$val_query['late_marks'];
											//======Total hours========			  	
											list($hour,$minute,$second) = explode(':', $tot_hr);
											$tot_seconds += $hour*3600;
											$tot_seconds += $minute*60;
											$tot_seconds += $second;
											//======Extra Hours====
											list($exhour,$exminute,$exsecond) = explode(':', $extra_hr);
											$ex_seconds += $exhour*3600;
											$ex_seconds += $exminute*60;
											$ex_seconds += $exsecond;
											//========TOTAL Full DAY====
											if($val_query['full_day'] ==='P')
											{
												$tot_full_day +=1;
											}
											//========TOTAL Half DAY====
											if($val_query['half_day'] ==='P')
											{
												$tot_half_day +=1;
											}

											?>
											<input type="hidden" name="floor_id<?php echo $t; ?>" id="floor_id<?php echo $t; ?>" value="<?php echo $val_query['attendance_id'] ?>" />
											<input type="hidden" name="days" id="days" value="<?php echo $val_query['days'] ?>" />
										</tr>
										<?php $t++;
									//}
								}
								//=====Calc Total Hours=======
								$tohours = floor($tot_seconds/3600);
								$tot_seconds -= $tohours*3600;
								$tominutes  = floor($tot_seconds/60);
								$tot_seconds -= $tominutes*60;
								$tot_hours="{$tohours}:{$tominutes}:{$tot_seconds}";
								//=====Calc Extra hours=======
								$ext_hours = floor($ex_seconds/3600);
								$ex_seconds -= $ext_hours*3600;
								$ext_minutes  = floor($ex_seconds/60);
								$ex_seconds -= $ext_minutes*60;
								$extra_hours="{$ext_hours}:{$ext_minutes}:{$ex_seconds}";
								?>
								<tr style='background-color:#5CA7DF;'>
									<td class="td1 td2" colspan="3" >Total</td>
									<td class="td1 td2"><?php echo $tot_hours;  ?></td>
									<td class="td1 td2"><?php echo $extra_hours;  ?></td>
									<td class="td1 td2"><?php echo $tot_full_day; ?></td>
									<td class="td1 td2"><?php echo $tot_half_day; ?></td>

									<td class="td1 td2"><?php echo $day_totals;  ?></td>
									<td class="td1 td2"><?php echo $total_till_date;  ?></td>
									<td class="td1 td2"><?php echo $tot_late_mark;  ?></td>

									<input type="hidden" name="floor_id<?php echo $t; ?>" id="floor_id<?php echo $t; ?>" value="<?php echo $val_query['attendance_id'] ?>" />
									<input type="hidden" name="days" id="days" value="<?php echo $val_query['days'] ?>" />
								</tr>
								<?php
							}
						//}
						?>
						</tbody>  
						</table><?php
					}
					else 
					{ 
						?>
						 <p Style="font-size:20px;color:red;">No Record Found for this month.</p> 
						<?php 
					}
					?>
<script type="text/javascript">
function PrintDiv(elem) {
	$(".table1").css( "border", "1px solid" );
	$(".td1").css( "border", "1px solid" );
	$(".th1").css( "border", "1px solid" );
	$(".table1").css( "border-collapse", "collapse" );
	$(".td1").css( "border-collapse", "collapse" );
	$(".th1").css( "border-collapse", "collapse" );
	$(".table1").css( "padding", "4px" );
	$(".td1").css( "padding", "4px" );
	$(".th1").css( "padding", "4px" );
	$(".table1").css( "font-size", "12px" );
	$(".td1").css( "font-size", "12px" );
	$(".td2").css( "text-align", "center" );

	$("#title").remove(); 
	var originalContents = $("body").html();
	var printContents = $("#example").html();
	$("body").html(printContents);
	window.print();
	$("body").html(originalContents);
	return false;
}
</script>