<?php
$PageSecurity = 15;
$title = _('Allowance Master');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];echo "<br>";

function selectcode()
{
global $db;
$SQL ="select allowcode from allowmaster";
$result=DB_query($SQL,$db,$ErrMsg);
while($resrow=DB_fetch_array($result)){
echo '<option value='.$resrow['allowcode'].'>'.$resrow['allowcode'].'</option>';
}
}

if(isset($_GET['id']) and $_GET['act']=='del')
{
$SQL="delete from allowmaster where id='".$_GET['id']."'";
$ErrMsg = _('The Allowance Master  record could not be deleted because');
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' Allowance Code Has Deleted!'),'success');
echo "<script>location.href='index.php?route=HRModule/AllowanceMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
}
function CheckallowCode($allowcode){
global $db;
$SQL ="select * from allowmaster where id ='".$_GET['id']."'";	
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
if(isset($resrow['allowcode'])){return false;} else {return true;}
}
if($_POST['edit'] =='' && $_REQUEST['act']=='edit' and $_GET['id']!='')
{
$SQL="select * from allowmaster where id='".$_GET['id']."'";
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
$_POST['allowcode']=$resrow[allowcode];
$_POST['allowname']=$resrow[allowname];
}

if($_POST['edit']!='' && $_REQUEST['act'] == 'edit' and $_GET['id']!='')
{
$SQL="update allowmaster set allowcode='".$_POST['allowcode']."' , allowname ='".$_POST['allowname']."',incentive_check='".$_REQUEST['incentive_check']."' where id='".$_GET['id']."'";
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' allow  Code Has Updated!'),'success');
echo "<script>location.href='index.php?route=HRModule/AllowanceMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
unset($_POST);
}

if(isset($_POST['add']) and !empty($_POST['allowcode']) and !empty($_POST['allowname']) and $_GET['act']!='edit')
{
	if(CheckallowCode($_POST['allowcode'])){
$SQL = "insert into allowmaster(id, allowcode, allowname,incentive_check)values ('','".$_POST['allowcode']."','".$_POST['allowname']."','".$_REQUEST['incentive_check']."')";	
		$InsResult=DB_query($SQL,$db,$ErrMsg);
		prnMsg( _('A New Allowance Code Has Inserted!'),'success');
		echo "<script>location.href='index.php?route=HRModule/AllowanceMaster&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
		unset($_POST);
	}
	else{	
	prnMsg( _('This Allowance Code All Ready Exit please Enter New Group Code!'),'error');
		
	}	
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Allowance Master</h1>
<form method="post" action="">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr class="row1">
<td width="15%" align="right">Allowance Code</td>
<td width="18%"><input name="allowcode" type="text" id="allowcode" value="<?php echo $_POST['allowcode'];?>" size="30" style="width:98%;" /></td>
<td width="15%" align="right">Allowance Name</td>
<td width="18%"><input name="allowname" type="text" id="allowname"  value="<?php echo $_POST['allowname'];?>" size="30" style="width:98%;" /></td>
<td width="15%" align="right">Including Incentive</td>
<td width="18%"><select name="incentive_check">
     <option value="0">Select</option>
     <option value="Y" <?php if($resrow['incentive_check']=='Y') {?> selected="selected" <?php } ?>>Yes</option>
     <option value="N" <?php if($resrow['incentive_check']=='N') {?> selected="selected" <?php } ?>>No</option>
     </select></td>
</tr>
<tr class="row1">
  <td align="center" colspan="6">
	<?php if($_GET['act']=='edit'){?>
	<input type="submit" name="edit" class="search" value="Edit" <?php if($_SESSION['frmEdit']=='0'){?>disabled<?php } ?>/>
	<input type="hidden" name='uiqeid' value="<?php echo $_GET['id'];?>" />
	<?php }else{ ?>
	<input type="submit" name="add" class="search" value="Accept" <?php if($_SESSION['frmcreate']=='0'){?>disabled<?php } ?>/>
	 <input type="submit" name="cancel" class="search" value="Cancel" /><?php  }?></td>
</tr>
</table>
</form>
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="12%">Allowance Code</th>
	<th>Allowance Name</th>
	<th width="12%">Including Incentive</th>
	<th width="6%" class="text-center">Edit</th>
	<th width="6%" class="text-center">Delete</th>
</tr>
<?php
$SQL ="select * from allowmaster";	
$result=DB_query($SQL,$db,$ErrMsg); 
while($resrow=DB_fetch_array($result)){?>
<tr>
<td><?php echo $resrow['allowcode']?></a></td>
<td><?php echo $resrow['allowname']?></td>
<td><?php if($resrow['incentive_check']=='Y') { echo "Yes"; } else { echo "No"; } ?></td>
<td align="center"><?php if($_SESSION['frmEdit']=='1') {?><a href="index.php?route=HRModule/AllowanceMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=edit&id=<?php echo $resrow['id']?>" class="link"><img src="images/icon-edit.png" height="15" width="15" title="Edit Document" /></a><?php }else{?><img src="images/icon-edit.png" height="15" width="15" style="opacity:0.6;" title="No Permission to Edit Document" /><?php }?></td>
<td align="center"><?php if($_SESSION['frmDelete']=='1') {?><a href="index.php?route=HRModule/AllowanceMaster&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&act=del&id=<?php echo $resrow['id']?>" onclick="return confirm('Are you sure you want to delete this record?')" class="link"><img src="images/Icon_Delete.png" height="14" width="14" title="Delete Document" /></a><?php }else{ ?><img src="images/Icon_Delete.png" height="14" width="14" style="opacity:0.6;" title="No Permission to Delete Document" /><?php }?></td>
</tr>
<?php }?>
</table>
</div>
</div>
<?php
include('includes/footer.inc');
?>
<style type="text/css" >
/*.button{ background-color:#666666;
color: #FFFFFF;
height:25px;
margin:0px 5px 0px 5px;
border:1px solid #359CA2;
}
.link{ color:#9900CC; font-family:"Comic Sans MS";
}*/
</style>