<?php 
if($_REQUEST['Save']!='')
{
   echo "manvi"; exit;
   for($k=1; $k<$_POST['rows']; $k++)
{
	if($_POST['pres_abs'][$k]!='0')
	{
  		$data['site']=$_POST['SITE'];
		$data['e_code']=$_POST['e_code'][$k];
		$data['card_no']=$_POST['card_no'][$k];
		$data['employee']=$_POST['employee'][$k];
		$data['shift_category']=$_POST['emp_shift'][$k];
		$data['shift_start']=$_POST['shift_start'][$k];
		$data['shiftstart_AMPM']=$_POST['shiftstart_AMPM'][$k];
		$data['shift_end']=$_POST['shift_end'][$k];
		$data['shiftend_AMPM']=$_POST['shiftend_AMPM'][$k];
		$data['time_in']=$_POST['time_in'][$k];
		$data['timein_AMPM']=$_POST['timein_AMPM'][$k];
		$data['time_out']=$_POST['time_out'][$k];
		$data['timeout_AMPM']=$_POST['timeout_AMPM'][$k];
		$data['work_hrs']=$_POST['work_hrs'][$k];
		if($_REQUEST['pres_abs'][$k]=='WL')
		{$data['ot_hrs']=='';}else
		{$data['ot_hrs']=$_POST['ot_hrs'][$k];}
		$data['late_arrival']=$_POST['late_arrival'][$k];
		$data['office_hours']=$_REQUEST['officework_hrs'][$k];
		$data['leave_code']=$_POST['leave_code'][$k];
		$data['attendance_date']=FormatDateForSQL($date);
		
		/*if($_POST['shiftstart_AMPM'][$k]=='PM')
		$data['out_date']=date('Y-m-d', strtotime("+1 day", strtotime(FormatDateForSQL($date))));
		else  
		$data['out_date']=FormatDateForSQL($date);*/
		$data['out_date']=FormatDateForSQL($_POST['out_date'][$k]);
		
		$data['created_date']=FormatDateForSQL($date);
		$data['attendance_day']=$day;
		$data['attendance_month']=$month;
		$data['attendance_year']=$year;
		
	  	$data['pres_abs']=$_REQUEST['pres_abs'][$k];
//		$data['others']=$_POST['other_official_tour'][$k];
		$data['created_by']=$_SESSION['UserID'];
		 
		 
echo "select * from daily_attendance where attendance_date='".FormatDateForSQL($date)."' and e_code='".$_POST['e_code'][$k]."'"; exit;		 
$chkatt=DB_query("select * from daily_attendance where attendance_date='".FormatDateForSQL($date)."' and e_code='".$_POST['e_code'][$k]."'",$db);
  $n=DB_num_rows($chkatt);
	if($n==0)
	{	 
//************************************************************		 
	/////Check Employee leave history	 
	 $leave_sql="Select * from leavemaster";
   $leave_res=DB_query($leave_sql,$db);  
  
   while($leave_row=DB_fetch_array($leave_res))
   {
     if($_REQUEST['pres_abs'][$k]=='L' && $leave_row['leavecode']==$_REQUEST['leave_code'][$k])	
      {
	   $totemp_leaves=$s->GetFieldValue('emp_leave',"emp_id='".$_REQUEST['employee'][$k]."' and  leave_type='".$leave_row['leavecode']."'",'leave_days');
	    if($totemp_leaves>0)
	    {
		      $chkleavestatus=$s->GetFieldValue('emp_leave_apply',"empid  ='".$_REQUEST['employee'][$k]."' and  leave_type='".$leave_row['leavecode']."' and approve_status='Y' and period_from='".ConvertSQLDate($_REQUEST['created_date'][$k])."'",'id');
			if($chkleavestatus==0)
			{
					$data_leaveapply['empid']=$_REQUEST['employee'][$k];
					$data_leaveapply['period_from']=FormatDateForSQL($_REQUEST['attendane_date']);
					$data_leaveapply['period_to']=FormatDateForSQL($_REQUEST['attendane_date']);
					$data_leaveapply['leave_reason']="Daily Auto Generated";
					$data_leaveapply['total_days']=1;
					$data_leaveapply['leave_type']=$leave_row['leavecode'];
					$data_leaveapply['approve_status']="Y";
					$s->RecordInsert('emp_leave_apply', $data_leaveapply);
					
					$data_update['leave_days']=$totemp_leaves-1;
					$data_update['emp_id']=$_REQUEST['employee'][$k]; 
					$cond_leave=" emp_id='".$_REQUEST['employee'][$k]."' and leave_type ='".$leave_row['leavecode']."'";		
					$s->RecordEdit('emp_leave', $data_update,$cond_leave);
			 } 
         }
	  }

   }  
 		 
		 
//*****************************************************		 
		 
		 $s->RecordInsert('daily_attendance', $data);
		$empshift=$s->GetFieldValue('shift_master',"id='".$_POST['emp_shift'][$k]."'" ,'shift_for');
		if(strtolower($empshift)=='staff'){	
			
			if($_POST['emp_basic_sal'][$k]>10000 && $OBJ_EMPSHIFT->ConvertTimeINTO_Mins($data['ot_hrs'])>=390)
			{
 				$CS=1;
				$data_leave['leave_type']='CS';
				$data_leave['emp_id']=$_POST['employee'][$k];
				$cond="emp_id='".$_POST['employee'][$k]."'";
				$chkempleave=$s->GetRecordById('emp_leave',  $cond);
				if(DB_num_rows($chkempleave)>0)
				{
					$rx=DB_fetch_array($chkempleave);
					
					$data_leave['leave_days']=$rx['leave_days']+$CS;
					$cond="id='".$rx['id']."'";				
					$s->RecordEdit('emp_leave', $data_leave, $cond);
				}else
				{
					$data_leave['leave_days']=$CS;
					$s->RecordInsert('emp_leave', $data_leave);
				}	
				
 				    $datacs['empid']=$_POST['employee'][$k];
					 $datacs['csdate']=FormatDateForSQL($date);
					 $datacs['csdays']=$CS;
  					 $insert=$s->RecordInsert('emp_csleave_updation', $datacs);
				
				
				
				
				
				
				
			}	
			 
	}		

		}
	}
}
 
 prnMsg( _('Attendance Saved Successfully'),'success');
//header('location:index.php?route=daily_attendance');
 echo "<script>location.href=".$target."&attendane_date=".$_REQUEST['attendane_date']."&AttSite=".$_REQUEST['AttSite']."</script>";
  
}
?>


 <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>