<?php $PageSecurity = 11;

include('includes/SQL_CommonFunctions.inc');
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$rurl="&modid=".$modid."&frmid=".$frmid;
$targetpage="index.php?route=HRModule/LateEmp".$rurl;
$msgErr=array();

$min_minute1=explode(":",$_REQUEST['min_hrs']);
$min_minute2=$min_minute1[0]*60;
$min_minute=$min_minute2+$min_minute1[1];

$max_minute1=explode(":",$_REQUEST['max_hrs']);
$max_minute2=$max_minute1[0]*60;
$max_minute=$max_minute2+$max_minute1[1];

if($_REQUEST['Save']){
	$Insert = DB_query("INSERT INTO late_emp SET 
						emp_site = '".$_REQUEST['emp_site']."',
						employment_type = '".$_REQUEST['employment_type']."',
						min_hrs = '".$_REQUEST['min_hrs']."',
						max_hrs = '".$_REQUEST['max_hrs']."',
						min_minute = '".$min_minute."',
						max_minute = '".$max_minute."',
						deduction = '".$_REQUEST['deduction']."'",$db);
			$s->pageLocation("index.php?route=HRModule/LateEmp".$rurl);
}

if($_REQUEST['action']=='Edit'){
	$con ="id='".$_REQUEST['id']."'";
	$Get_id = $s->GetRecordById('late_emp',$con);
	$var = DB_fetch_array($Get_id);

	if($_REQUEST['Update']){
	$UPDATE = DB_query("UPDATE late_emp SET 
						emp_site = '".$_REQUEST['emp_site']."',
						employment_type = '".$_REQUEST['employment_type']."',
						min_hrs = '".$_REQUEST['min_hrs']."',
						max_hrs = '".$_REQUEST['max_hrs']."',
						min_minute = '".$min_minute."',
						max_minute = '".$max_minute."',
						deduction = '".$_REQUEST['deduction']."'
						where id = '".$_REQUEST['id']."'",$db);
						$s->pageLocation("index.php?route=HRModule/LateEmp".$rurl);
	
	}
}

if($_REQUEST['action']=='Delete'){
	$delete = DB_query("DELETE FROM late_emp
						WHERE id = '".$_REQUEST['id']."'",$db);
}

?>
<link rel="stylesheet" href="css/new_mxerp1.css">
<div class="body_contain">
<div class="tab_div">
<h1>Late Deduction Master</h1>
<form name="weeklyoff" method="post">
<table width="50%" border="0" cellpadding="3" cellspacing="0" align="center">
<tr class="row1">
	<td class="tabledata1"><strong>Site</strong></td>
    <td><select name="emp_site" id="emp_site" style="width:150px;">
        <option value="000">---Select---</option>
        <?php 
	$site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
        <option value="<?php echo $site_row['loccode'];?>"<?php echo ($var['emp_site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
        <?php } ?>
      </select>    </td>
</tr>
<tr class="row1">
	<td class="tabledata1"><strong>Employment Type </strong></td>
    <td><select name="employment_type" id="employment_type" style="width:150px;">
		<option value="Permanent" <?php echo($var['employment_type']=='Permanent'?'selected':'')?>>Permanent</option>
		<option value="Temporary" <?php echo($var['employment_type']=='Temporary'?'selected':'')?>>Temporary</option>
      </select>
    </td>
  </tr>
<tr class="row1">
	<td class="tabledata1"><strong>Minimum Hours </strong></td>
    <td><input type="text" name="min_hrs" id="min_hrs" style="width:150px;" value="<?php echo $var['min_hrs']; ?>" />
    </td>
  </tr>
<tr class="row1">
	<td class="tabledata1"><strong>Maximum Hours </strong></td>
    <td><input type="text" name="max_hrs" id="max_hrs" style="width:150px;" value="<?php echo $var['max_hrs']; ?>" />
    </td>
  </tr>
<tr class="row1">
	<td class="tabledata1"><strong>Deduction </strong></td>
    <td>
		<!--<input type="text" name="deduction" id="deduction" value="<?php echo $var['deduction']; ?>" />-->
		<select name="deduction" id="deduction" style="width:150px;">
			<option value="0">Select Deduction</option>
			<option value="ABS" <?php if($var['deduction']=='ABS') {echo "selected";} ?>>Mark Absent</option>
			<option value="HD" <?php if($var['deduction']=='HD') {echo "selected";} ?>>Mark Half Day</option>
			<option value="SL" <?php if($var['deduction']=='SL') {echo "selected";} ?>>Mark Short Leave</option>
		</select>
    </td>
  </tr>
<tr class="row1">
	<td class="tabledata1" colspan="2" style="text-align:center;">
		<input name="<?php if($_REQUEST['action']=='Edit') { echo 'Update';}else { echo 'Save'; }?>" class="search" type="submit"  onclick="return validate_deduction()" value="<?php if($_REQUEST['action']=='Edit') { echo 'Update';}else { echo 'Save'; }?>" />

	</td>
  </tr>
  </table>
  </form>
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
  <tr>
    <td class="tabledata"><strong>S. No.</strong></td>
    <td class="tabledata"><strong>Site Name</strong></td>
    <td class="tabledata"><strong>Employment Type</strong></td>
	<td class="tabledata"><strong>Minimum Hours</strong></td>
	<td class="tabledata"><strong>Maximum Hours</strong></td>
	<td class="tabledata"><strong>Deduction</strong></td>
    <td class="tabledata"><strong>Edit</strong></td>
    <td class="tabledata"><strong>Delete</strong></td>
  </tr>
  <?php $j=0; 
    $ResultData=DB_query("select *  from late_emp",$db);
    while($RowData = DB_fetch_array($ResultData))
   {  if($j++%2==0)
     $bgcolor="#CCCCCC";
	 else{
	 $bgcolor="#FFFFFF";
	 }
	 ?>
<tr bgcolor="#c1c1c1">
    <td><?php echo $j."." ?></td>
    <td><?php echo $s->getField('locations','loccode',$RowData['emp_site'],'locationname');;?> </td>
    <td><?php echo $RowData['employment_type'];?></td>
	<td><?php echo $RowData['min_hrs'];?></td>
	<td><?php echo $RowData['max_hrs'];?></td>
	<td><?php echo $RowData['deduction'];?></td>
    <td><a href="<?php  echo $targetpage;?>&action=Edit&id=<?php echo $RowData['id']?>"><img src="images/icon_edit.gif" /></a></td>
    <td><a href="<?php echo $targetpage;?>&action=Delete&id=<?php echo $RowData['id']?>" ><img src="images/Icon_Delete3.gif" /></a></td>
  </tr>
  <?php } ?>
</table>
  
<script type="text/javascript">
function validate_deduction() {
	if(document.getElementById("emp_site").value=='000')
	{
		alert("Please Select Branch First");
		return false;
	}
	else if(document.getElementById("min_hrs").value=='')
	{
		alert("Please Enter Minimum Hours");
		document.getElementById("min_hrs").focus();
		return false;
	}
	else if(document.getElementById("max_hrs").value=='')
	{
		alert("Please Enter Maximum Hours");
		document.getElementById("max_hrs").focus();
		return false;
	}
	else if(document.getElementById("max_hrs").value<document.getElementById("min_hrs").value)
	{
		alert("Maximum Hours not less than Minimum Hours.");
		document.getElementById("max_hrs").focus();
		return false;
	}
	else if(document.getElementById("deduction").value==0)
	{
		alert("Please Select Deduction");
		return false;
	}
}
</script>