<?php $table='ot_salary_master';

$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];

$rurl="index.php?route=HRModule/OTMaster&modid=".$modid."&frmid=".$frmid."";

if($_REQUEST['Save'])
{
 	//$data['advance_date'] = FormatDateForSQL($_REQUEST['advance_date']);
	$data['emp_site'] = $_REQUEST['emp_site'];
	$data['emp_shift'] = $_REQUEST['emp_shift'];
	$data['salary_range'] = $_REQUEST['salary_range'];
	$data['salary_based'] = $_REQUEST['salary_based'];
	$data['OThours'] = $_REQUEST['OThours'];
	$data['OTleaveday'] = $_REQUEST['OTleaveday'];
 	  
 	if($_REQUEST['action']!='Edit')
	$insert=$s->RecordInsert($table, $data);
	else {
		$cond="id='".$_REQUEST['id']."'";
		$insert=$s->RecordEdit($table, $data, $cond);
	}
	if($insert)
	{
		  
		   $s->pageLocation( $rurl.'&action=view&daction=Updated');
	}	
}

if($_REQUEST['action']=='Edit')
{
   $query=DB_query("select * from $table where id='".$_REQUEST['id']."'",$db);
   while($row=DB_fetch_array($query))
	{
		$emp_site=$row['emp_site'];
		$emp_shift=$row['emp_shift'];
		$salary_range=$row['salary_range'];
		$salary_based=$row['salary_based'];
		$OThours=$row['OThours'];
		$OTleaveday=$row['OTleaveday'];
		 							
	
	}
}
if($_REQUEST['action']=='Delete')
{
	$cond="id='".$_REQUEST['id']."'";
	$s->DeleteRecord($table,  $cond);
   $s->pageLocation( $rurl.'&action=view&daction=Deleted');
}
 ?>
 
<script type="text/javascript" src="js/function-ajax.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<script type="text/javascript" language="javascript">
function check()
{

	 var site=document.getElementById("emp_site").value;	  
	 if(site=='000')
	{alert('Please select site'); 
	document.getElementById("emp_site").focus();
	return false;}
	 
	
}
</script>

<h1>OT Master</h1>
  <?php 
  if($_REQUEST['daction']!='')
  {
  echo "<div class='success'><center>Record ".$_REQUEST['daction']." Successfully</center></div>";
  }
  ?>
<?php 
  if(($_REQUEST['action']=='Addnew'|| $_REQUEST['action']=='Edit' )  )
  {?>

  
<form action="" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
 	<tr class="row1">
	  <td width="13%" align="right">Site</td>
      <td width="20%">
	    <select name="emp_site" id="emp_site" tabindex="2" onchange="ShowDiv(this.value,'hid-staffdiv','Empshift.php');" >
        <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 ($emp_site==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
        <?php } ?>
      </select></td>
    <td width="13%" align="right">Employee Type</td>
    <td width="20%"> 
 <div id='hid-staffdiv'>
	  <select name="emp_shift" id="emp_shift" >	 
 	<?php 	
	if($emp_site!='')
 	$emp_shift_sql=DB_query("Select id ,shift_for,shift_category  from shift_master where site='".$emp_site."'",$db);
 	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> </div>
	</td>
    <td width="13%" align="right">Employee Sal range</td>
    <td>
	<select name="salary_range" >
	<option value="1" <?php echo ($salary_range=='1'?'selected':'')?>>5,000 Below</option>
	<option value="2" <?php echo ($salary_range=='2'?'selected':'')?>>5,000 Above</option>
	<option value="3" <?php echo ($salary_range=='3'?'selected':'')?>>10,000 Below </option>
	<option value="4" <?php echo ($salary_range=='4'?'selected':'')?>>10,000  Above</option>
	</select>
	  </td>
  </tr>
  <tr class="row1">
    <td align="right">Based Hours/ Leave</td>
    <td> 
	<select name="salary_based" >
	<option value="Hours"<?php echo ($salary_based=='Hours'?'selected':'')?>>Hours</option>
	<option value="Leave" <?php echo ($salary_based=='Leave'?'selected':'')?>>Leave</option><option value="ActualAmount">Actual Sal</option>
 	</select></td>
    <td align="right">Hours</td>
    <td><input type="text" name="OThours" value="<?php echo $OThours;?>"  /></td>
    <td align="right">Leave Days</td>
    <td><input type="text" name="OTleaveday" value="<?php echo $OTleaveday;?>"  /></td>
  </tr>
  <tr class="row1">
    <td align="center" colspan="6"><input type="submit" name="Save" value="Save" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>  onclick="return check();" class="search" /></td>
  </tr>
</table>
</form>
<br>
 <?php } else if($_REQUEST['action']!='Addnew'&& $_REQUEST['action']!=='Edit' ) 
      {?>
<p align="left"><a href="<?php echo $rurl;?>&action=Addnew"><input type="button" class="search" value="Add New" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?>/></a></p>

<table cellpadding="3" cellspacing="0" border="0" width="100%" class="thborder">
	<tr>
	    <th width="15%">Emp Site</th>
		<th>Emp Shift</th>
		<th width="12%">Salary Range</th>		 
		<th width="12%">Salary Based</th>
		<th width="8%">OT Hours</th>
		<th width="4%" class="text-center">View</th>
		<th width="4%" class="text-center">Delete</th>		
	</tr>
	<?php
  	$GetProcess = "Select * from $table  ";		 	   
       $ResultProcess_SalData = DB_query($GetProcess,$db);
	  // echo DB_num_rows($ResultData);
   	   while($RowData = DB_fetch_array($ResultProcess_SalData))
	   {
	  ?> 
		<tr>
		<td><?php  echo $RowData['emp_site']?></td>
		<td><?php  //echo $RowData['emp_id'];
		echo $s->getField('shift_master','id',$RowData['emp_shift'],'shift_for');
		
		echo "( ".$s->getField('shift_master','id',$RowData['emp_shift'],'shift_category')." )";
			?></td>
		 <td><?php  switch($RowData['salary_range']){
		 case 1: echo "5,000 below"; break;
 		 case 2: echo "5,000 above"; break;
		 case 3: echo "10,000 below "; break;
		 case 4: echo "10,000 above"; break;	 
		 }?></td>		 
		<td><?php  echo $RowData['salary_based']?></td>
		<td><?php  echo $RowData['OThours']?></td>
		<td align="center"><?php if($_SESSION['frmEdit']=='1'){?><a href="<?php echo $rurl.'&id='.$RowData['id'].'&action=Edit' ; ?>"><img src="images/search.gif" height="15" width="15" title="View Document" /></a><?php }else{ ?><img src="images/search.gif" height="15" width="15" style="opacity:0.6;" title="No Permission to View Document" /><?php } ?></td>
		<td align="center"><?php if($_SESSION['frmDelete']=='1'){?><a href="<?php echo $rurl.'&id='.$RowData['id'].'&action=Delete' ; ?>"><img src="images/Icon_Delete.png" width="13" height="13" title="Delete Document" /></a><?php }else{ ?><img src="images/Icon_Delete.png" width="15" style="opacity:0.6;" title="No Permission to View Document" /><?php } ?></td>		
	 </tr>
	<?php }?>
</table>
<?php } ?>