<?php $PageSecurity = 15;
include('includes/fun-php.php');
include('Class-EmpShift.php');

if($_REQUEST['SaveAttendance']=='Save')
{
   echo "test";
    echo "<pre>";
    print_r($_REQUEST);
    exit;
}

if($_REQUEST['proceed']!='')
{
	$_REQUEST['attendane_date']=$_REQUEST['attendane_date'];
	$_REQUEST['AttSite']=$_REQUEST['site'];
	$_SESSION['site']=$_REQUEST['site'];
	
	//echo $_SESSION['site'];
   
 		$datefilter=explode("/",$_REQUEST['attendane_date']);
		$holiday_status=GET_Holidays($datefilter[0],$datefilter[1],$datefilter[2]);
	 $condition="day(start_date)='".$datefilter[0]."' and  month(start_date)='".$datefilter[0]."' and published='Y' and  year(start_date)='".$datefilter[0]."'";
	   $holidaytitle=$s->GetFieldValue('holidays',$condition ,'holiday_title');
	if($holiday_status!=1){?>
	<form action="" method="post">
<div style="overflow:auto;  width:auto; height:auto"> 
<p align="left"><strong>P:Present &nbsp; A:Absent &nbsp; L:Leave &nbsp; O:Official tour</strong></p>
  <table width="100%" border="0" cellspacing="4" cellpadding="0">
    <tr>
      <td width="3%" bgcolor="#CCCCCC"><strong>Sr.</strong></td>
      <td width="6%" bgcolor="#CCCCCC">&nbsp;</td>
	  <td width="11%" bgcolor="#CCCCCC">&nbsp;</td>
      <td width="8%" bgcolor="#CCCCCC">&nbsp;</td>
      <td width="9%" bgcolor="#CCCCCC">&nbsp;</td>
      <td width="5%" bgcolor="#CCCCCC">&nbsp;</td>
      <th colspan="2" bgcolor="#CCCCCC"><strong>Time</strong></th>
	  <td width="7%" bgcolor="#CCCCCC">&nbsp;</td>
	  <td width="3%" bgcolor="#CCCCCC"><strong>Office<br />Working</strong></td>
	  <td width="6%" bgcolor="#CCCCCC"><strong>Working</strong></td>
	  <td width="4%" bgcolor="#CCCCCC"><strong>OT</strong></td>
      <td width="6%" bgcolor="#CCCCCC"><strong>Leave</strong></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC"><strong>No.</strong></td>
	  <td bgcolor="#CCCCCC"><div align="center"><strong>P/A</strong></div></td>
      <td bgcolor="#CCCCCC" width="5%"><div align="center"><strong>E Code</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Employee <br />Name </strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Employee<br /> Designation </strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Shift </strong></div></td>
	  <td width="14%" bgcolor="#CCCCCC"><div align="center"><strong>In</strong></div></td>
      <td width="15%"  bgcolor="#CCCCCC"><div align="center"><strong>Out</strong></div></td>
	  <td bgcolor="#CCCCCC"><div align="center"><strong>Out Date</strong></div></td>
	   <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td>
	   <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>HRS</strong></div></td>
      <td bgcolor="#CCCCCC"><div align="center"><strong>Code</strong></div></td>
    </tr>
    <?php
	$emp_daily_attendance_id='';
	$chkemp_dailydate=DB_query("Select employee from daily_attendance where attendance_date='".ConvertSQLDate($_REQUEST['attendane_date'])."'",$db);
	if(DB_num_rows($chkemp_dailydate)>0)
	{
		while($emp_daily_attendance=DB_fetch_array($chkemp_dailydate))
 		 {
 		 	 $emp_daily_attendance_id[]=$emp_daily_attendance['employee'];
		 }
		  $emp_daily_attendance_id=implode(',',array_unique($emp_daily_attendance_id));
	}
	
	if($_SESSION['site']!='' && $_REQUEST['attendane_date']!=''){
	 	 
if($emp_daily_attendance_id!='')
   $emp_sql="Select * from empmaster where emp_site='".$_SESSION['site']."' and id not in($emp_daily_attendance_id)";
else {
	$emp_sql="Select * from empmaster where emp_site='".$_SESSION['site']."'";
}

   $chkDay=DayOfDate(ConvertSQLDate($date));
   $emp_result=DB_query($emp_sql,$db);
   $i=1;
  if(DB_num_rows($emp_result)>0){
  while($emp_row=DB_fetch_array($emp_result))
  {   $_POST['e_code']=$emp_row['emp_code'];
      $emp_site=$emp_row['emp_site'];
	   $emp_shift=$emp_row['employee_type'];
	  $GETEMPTYPE=   $s->getField('shift_master','id', $emp_shift,'shift_for');
	  
     $GetEmpShift= GetDay($emp_row['emp_weekly_off']);
  // if($GetEmpShift!=$chkDay)
   { 
  // echo "<br> select * from shift_master where id='".$emp_row['employee_type']."' and site='".$_REQUEST['AttSite']."' and shift_for='".$GETEMPTYPE."'";
    $get_shift=DB_query("select * from shift_master where id='".$emp_row['employee_type']."' and site='".$_SESSION['site']."' and shift_for='".$GETEMPTYPE."'",$db);
	  $get_res=DB_fetch_array($get_shift);
   	  $_REQUEST['shift_start']=$get_res['shift_start'];
	  $_REQUEST['shiftstart_AMPM']=$get_res['start_AMPM'];
	  $_REQUEST['shift_end']=$get_res['shift_end'];
	   $_REQUEST['shiftend_AMPM']=$get_res['end_AMPM'];
	  $_REQUEST['time_in'][$i]=$get_res['shift_start'];
	  $_REQUEST['timein_AMPM'][$i]=$get_res['start_AMPM'];
	  $_REQUEST['time_out'][$i]=$get_res['shift_end'];
	  if($get_res['end_AMPM']!='')
	  $_REQUEST['timeout_AMPM'][$i]=$get_res['end_AMPM'];
	  else
	  	$_REQUEST['timeout_AMPM'][$i]='PM';
		
		
		$_REQUEST['work_hrs'][$i]=0;
$_REQUEST['ot_hrs'][$i]=0;
  ?>
    <tr bgcolor="#999999">
		  
      <td><?php echo $i;;?>
	  <input name="emp_basic_sal[<?php echo $i;?>]" type="hidden" value="<?php echo $emp_row['gross_sal']; ?>" /></td>
	  <td>
	  <?php
	if($GetEmpShift==$chkDay)
	 {echo "<br><b>WeeklyOff</b>";}
	else if($holiday_status==1) {echo "<br><b>Holiday</b>";}
	 ?> 
	 <input name="present_status_<?php echo $i;?>"  id="present_status_<?php echo $i;?>"  type="hidden" value="<?php echo ($GetEmpShift==$chkDay?'WL':'');?>" />
<select name="pres_abs[<?php echo $i;?>]" id="pres_abs_<?php echo $i;?>" style="width:auto" onChange="hideDetails(this.value,<?php echo $i;?>)">
<option value="0">--</option>
<option value="P">P</option>
<option value="A">A</option>
<option value="L">L</option>
<option value="official_tour">O</option>
<option value="WL">WL</option>
<option value="HO">HO</option>
<option value='WL' <?php echo ($GetEmpShift==$chkDay?'selected':'')?>>WL</option>
</select>
  </td>
      <td width="5%"><?php echo $_POST['e_code'];?>
          <input name="e_code[<?php echo $i;?>]" type="hidden" id="e_code_<?php echo $i;?>" value="<?php echo $_POST['e_code'];?>" size="15" /> <input name="card_no[<?php echo $i;?>]" type="hidden" id="card_no_<?php echo $i;?>" value="<?php echo $_REQUEST['card_no'];?>" size="3" /></td>
      <td><?php echo $emp_row['emp_name'];?>
          <input type="hidden" value="<?php echo $emp_row['id'];?>" name="employee[<?php echo $i;?>]" id="employee_<?php echo $i;?>" /></td>
      <td><?php 
      echo $s->getField('desigmaster','desigcode',$emp_row['designation'],'designame');
     //echo $emp_row['designation'];?>
          <input type="hidden" value="<?php echo $emp_row['id'];?>" name="employee[<?php echo $i;?>]" id="employee_<?php echo $i;?>" /></td>
	<td>
	<?php 
	  if($emp_site!='')
 	  $emp_shift_sql=DB_query("Select id ,shift_for,shift_category  from shift_master where site='".$emp_site."' and shift_for='".$GETEMPTYPE."'",$db);	?>	  
	  <select name="emp_shift[<?php echo $i;?>]" id="emp_shift_<?php echo $i;?>" onChange="ShowDiv(this.value,'hid-shift_<?php echo $i;?>','emp_shifttime.php?AttSite=<?php echo $_SESSION['site'].'&shift_for='.$GETEMPTYPE.'&i='.$i?>')" style="width:auto;">	 
 	<?php while($emp_shift_row=DB_fetch_array($emp_shift_sql)){	?>
	<option value="<?php echo $emp_shift_row['id'];?>"<?php echo ($emp_shift==$emp_shift_row['id']?'selected':'')?>><?php echo $emp_shift_row['shift_for'].'('.$emp_shift_row['shift_category'].')'?></option>
	<?php } ?></select></td>
  <td colspan="2">  
  <div id="hid-shift_<?php echo $i; ?>">  
  <table width="100%" border="0">
  <tr>
    <td width="50%">
	<?php 
	$disabled='';
	if($GetEmpShift==$chkDay){$disabled="disabled";}?>
	
	
		   <input name="shift_start[<?php echo $i;?>]" type="hidden" id="shift_start_<?php echo $i;?>" value="<?php echo $_REQUEST['shift_start'];?>" size="3" />
	  
	  
	  <select name="shiftstart_AMPM[<?php echo $i;?>]" id="shiftstart_AMPM_<?php echo $i;?>" style="width:40px;display:none" >
	  <option value="AM"<?php echo ($_REQUEST['shiftstart_AMPM']=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['shiftstart_AMPM']=='PM'?'selected':'')?>>PM</option>
	  </select>
	  
  <input name="shift_end[<?php echo $i;?>]" type="hidden" id="shift_end_<?php echo $i;?>" value="<?php echo $_REQUEST['shift_end'];?>" size="3" />
<?php  //echo $setAMPM= $_REQUEST['shiftend_AMPM'];?>
   <select name="shiftend_AMPM[<?php echo $i;?>]" id="shiftend_AMPM_<?php echo $i;?>" style="width:40px;display:none"  >
	  <option value="AM"<?php echo ($_REQUEST['shiftend_AMPM']=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['shiftend_AMPM']=='PM'?'selected':'')?>>PM</option>
	  </select>
	
	
	
	  <input name="time_in[<?php echo $i;?>]" type="text" id="time_in_<?php echo $i;?>" value="<?php echo $_REQUEST['time_in'][$i];?>"  style="width:40%" <?php echo $disabled;?>/>
	  <select name="timein_AMPM[<?php echo $i;?>]" id="timein_AMPM_<?php echo $i;?>" style="width:40px">
	  <option value="AM"<?php echo ($_REQUEST['timein_AMPM'][$i]=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['timein_AMPM'][$i]=='PM'?'selected':'')?>>PM</option>
	  </select>	
	
	
	</td>
     <td width="50%">
	 
	 <input name="time_out[<?php echo $i;?>]" type="text" id="time_out_<?php echo $i;?>" value="<?php echo $_REQUEST['time_out'][$i];?>" style="width:40%" <?php echo $disabled;?>/>
	  <select name="timeout_AMPM[<?php echo $i;?>]" id="timeout_AMPM_<?php echo $i;?>" style="width:40px" >
	  	  <option value="AM"<?php echo ($_REQUEST['timeout_AMPM'][$i]=='AM'?'selected':'')?>>AM</option>
	  <option value="PM"<?php echo ($_REQUEST['timeout_AMPM'][$i]=='PM'?'selected':'')?>>PM</option>

	  
	  
	  </select>
	 </td>
  </tr>
</table>
  </div></td>
  
 <td><input type="text" name="out_date[<?php echo $i;?>]" id="out_date_<?php echo $i;?>" value="<?php echo $_REQUEST['attendane_date'];?>" style="width:95%" class="datepicker" /><input type="hidden" name="current_date[<?php echo $i;?>]" id="current_date_<?php echo $i?>" value="<?php echo $_REQUEST['attendane_date'];?>" /></td>
  
  
  
	     <td><input name="officework_hrs[<?php echo $i;?>]" id="officework_hrs_<?php echo $i;?>" type="text"  onfocus="calculate_officeworkhours(<?php echo $i;?>)" value="" size="3" <?php echo $disabled;?>/></td>
		   <td><input name="work_hrs[<?php echo $i;?>]" type="text" id="work_hrs_<?php echo $i;?>"  size="3" onFocus="calculate_workhours(<?php echo $i;?>,document.getElementById('present_status_<?php echo $i?>').value)" <?php echo $disabled;?>/>		   </td>
	   <td><input name="ot_hrs[<?php echo $i;?>]" type="text" id="ot_hrs_<?php echo $i;?>"  size="3"  onfocus="calculate_OverTime(<?php echo $i;?>,document.getElementById('present_status_<?php echo $i?>').value)" <?php echo $disabled;?>/></td>
	   
      <td><select name="leave_code[<?php echo $i;?>]" id="leave_code_<?php echo $i;?>" style="width:50px" <?php echo $disabled;?>>
        <option value="000">---</option>
        <?php
	$leave_sql=DB_query("select * from leavemaster",$db); 
	while($leave_row=DB_fetch_array($leave_sql)){
	?>
        <option value="<?php echo $leave_row['leavecode'];?>"><?php echo $leave_row['leavename'];?></option>
        <?php } ?>
      </select></td>
    </tr>
    <?php   $i++;
	}  
	
   } 
  
  }else
  {?>
  <tr><td colspan="13"><h3 align="center">No employee at this branch</h3></td></tr>
  <?php 
  }?>
    <input type="hidden" name="rows" id="rows" value="<?php echo $i;?>" /><?php } ?>
  </table>
</div>
<p align="center">
<input type="hidden" name="SITE_CODE" value="<?php echo $_SESSION['site'];?>" /></p>
<input type="submit" name="SaveAttendance" value="Save" />
</form>
	<?php 
	}else{
	  echo "<div align='center'> <h3>Today is HoliDay</h3></div>";
	}
?>
<?php  
}
?>