<?
session_start();
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
if(isset($_POST['save']))
{
	$gname=$_REQUEST['gname'];
	$grp_tax=$_REQUEST['grp_tax'];
	$grp_comsion=$_REQUEST['grp_comsion'];
	$stat_rbt=$_REQUEST['stat_rbt'];
	$grp_kvic=$_REQUEST['grp_kvic'];
	$reduct=$_REQUEST['reduct'];
	$grp_kvicspl=$_REQUEST['grp_kvicspl'];
	$tax_aply=$_REQUEST['tax_aply'];
	$rebt_aply=$_REQUEST['rebt_aply'];
	$kvic_aply=$_REQUEST['kvic_aply'];
	$redct_aply=$_REQUEST['redct_aply'];
	$kvspl_aply=$_REQUEST['kvspl_aply'];

	$code=substr($gname,0,3).substr(time(),7,3).date("s"); 
	$code=str_replace(' ','-',$code);
	$sql="insert into groupmaster(code,gname,grp_tax,grp_comsion,stat_rbt,grp_kvic,reduct,grp_kvicspl,tax_aply,rebt_aply,kvic_aply,redct_aply,kvspl_aply,brcode) values('$code','$gname','$gr_tax','$gr_commi','$gr_strbt','$gr_kvic','$gr_reduct','$gr_kvspcl','$tax_chk','$strbt_chk','$kvic_chk','$reduct_chk','$kvspl_chk','$brcode')";
	mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));
	print "<script> document.location='grmaster.php'</script>";
	return;
}
?>
<link href="css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<html>
<body >

<title>Demo</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
</script>
<script>
function valid()
{
}
</script>
<style>
th{background-color:steelblue;color:white}
table.form{
font-weight: normal;border:1px;
} 
</style>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>
<body>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()" method='post'> 
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Master >> Group Master</font>
<br>

<center>
<table cellspacing=1 cellpadding=1 class=form>
<tr><td align=center bgcolor='white'>
<form name='f1' action='<?print $PHP_SELF?>' method='post' onSubmit="return valid()">
<table cellspacing=1 cellpadding=3 width='450'>
<th colspan=6><font size=3>GROUP MASTER</th>
<?
$sql="select * from taxmaster";
$rs=mysqli_query($db,$sql);
?>
<tr><td>Group Name<input type=text name='gname'></td><td></td><td></td><td>Tax %</td><td><select name='gr_tax'>
<?
while($row=mysqli_fetch_array($rs))
{
?>
<option><? echo $row[2] ?></option>
<?
}
?>
</select></td><td>Apply<input type='checkbox' name='tax_chk' value='1'></td>
</tr>

<tr><td>MDA<input type=text name='gr_strbt'></td><td>Apply</td><td><input type='checkbox' name='strbt_chk' value='1'></td>
<td>State Rebate</td><td><input type=text name='gr_kvic' ></td><td>Apply<input type='checkbox' name='kvic_chk' value='1'></td>
</tr>
<tr><td>Reduction<input type=text name='gr_reduct' ></td><td>Apply</td><td><input type='checkbox' name='reduct_chk' value='1'></td>
<td>State Rebate Special</td><td><input type=text name='gr_kvspcl'></td><td>Apply<input type='checkbox' name='kvspl_chk' value='1'></td>
</tr>
<th colspan=6><input type=submit value='Save' name='save'></td></tr>
</table>
</form>
</td></tr>
</table>
<br>
<table cellspacing=1 cellpadding=5 class=report>
<th>No <th>Group Name<th>Tax<th>MDA<th>State Rebate<th>Reduction<th>State Rebate Special<th>Edit<th>Del
<?
$i=1;
$res=mysqli_query($db,"select * from groupmaster order by gname");
while($row=mysqli_fetch_array($res))
{
?>
<form name='form2' id='form2' method='POST'>
<?
 print "<tr bgcolor='white' onMouseOver=bgColor='b8d7b4'; onMouseOut=bgColor='white'>";
 print "<td>".$i++."</td><td>".$row[gname]."</td><td>".$row[grp_tax]."</td><td>".$row[stat_rbt]."</td><td>".$row[grp_kvic]."</td><td>".$row[reduct]."</td><td>".$row[grp_kvicspl]."</td>";
  print "<td><input type=button value='Edit' name='ed' onClick=edtfun('$row[code]')></td>";
  print "<td><input type=button value='Del' name='del' onClick=delfun('$row[code]')></td></tr>";
}
?>
</form>
</table>
<script>
 function edtfun(x)
 {
   document.location='editgrmaster.php?code='+x;
 }
 function delfun(x)
 {
  if (confirm('do you want to delete '+x+' ?'))
   document.location='delgrmaster.php?code='+x;
 }
  
</script>
