<?php
$PageSecurity = 15;
$title = _('Deduction 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>";

if(isset($_GET['id']) and $_GET['act']=='del')
{
$SQL="delete from deduction_master where id='".$_GET['id']."'";
$ErrMsg = _('The Deduction Master  record could not be deleted because');
$result = DB_query($SQL,$db,$ErrMsg);
prnMsg( _(' Deduction Code Has Deleted!'),'success');
echo "<script>location.href='index.php?route=HRModule/deduction_master&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
}

if($_POST['edit'] =='' && $_REQUEST['act']=='edit' and $_GET['id']!='')
{
$SQL="select code,name from deduction_master where id='".$_GET['id']."'";
$result=DB_query($SQL,$db,$ErrMsg);
$resrow=DB_fetch_array($result);
$_POST['code']=$resrow['code'];
$_POST['name']=$resrow['name'];
}

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

if(isset($_POST['add']) and !empty($_POST['code']) and !empty($_POST['name']) and $_GET['act']!='edit')
{
	
		
		$SQL = "insert into deduction_master(id, code, name)values ('','".$_POST['code']."','".$_POST['name']."')";	
		$InsResult=DB_query($SQL,$db,$ErrMsg);
		prnMsg( _('A New Deduction Code Has Inserted!'),'success');
		echo "<script>location.href='index.php?route=HRModule/deduction_master&modid=".$_SESSION['modid']."&frmid=".$_SESSION['frmid']."'</script>";
		unset($_POST);
	//prnMsg( _('This Deduction 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>Deduction Master</h1>
<form method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="row1">
<td width="12%" align="right">Deduction Code</td>
<td width="35%"><input name="code" type="text" id="code" value="<?php echo $_POST['code'];?>" size="30"  /></td>
<td width="20%" align="right">Deduction Name</td>
<td><input name="name" type="text" id="name" value="<?php echo $_POST['name'];?>" size="30"  /></td>
</tr>
<tr class="row1">
	<td align="center" colspan="4">
	<?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" cellpadding="3" cellspacing="0" class="thborder">
<tr>
	<th width="12%">Deduction Code</th>
	<th>Deduction Name</th>
	<th width="6%" class="text-center">Edit</th>
	<th width="6%" class="text-center">Delete</th>
</tr>
<?php
$SQL ="select * from deduction_master";	
$result=DB_query($SQL,$db,$ErrMsg); 
while($resrow=DB_fetch_array($result)){?>
<tr>
	<td><?php echo $resrow['code']?></a></td>
	<td><?php echo $resrow['name']?></td>
	<td align="center"><?php if($_SESSION['frmEdit']=='1'){?><a href="index.php?route=HRModule/deduction_master&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/deduction_master&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>