<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
   print "<script> alert('Invalid User'); document.location='inde.php' </script>";
   return;
}
?>
<head>
<script>
function chkey(abc)
{
  yy=abc.value
  if(yy.indexOf('  ')>-1)
  {
     alert('Multiple space is not allowed');
     abc.value='';
  }
  if(yy.indexOf("'")>-1)
  {
     alert("\' is not allowed");
     abc.value='';
 }
 if(yy.indexOf('"')>-1)
 {
    alert("\" is not allowed");
    abc.value='';
  }
 if(yy.indexOf('&')>-1)
  {
    alert("\& is not allowed");
    abc.value='';
  }
var igstrt=document.getElementById('igstrate').value;
if(igstrt>0)
   {
   document.getElementById('igstrate').value=abc.value;
   }
else{
document.getElementById('igstrate').value=0;
}

}
function chkey1(abc)
{
   var taxrt=document.getElementById('tax_rte').value;
   if(abc.value>0)
   {
         alert("CGST % and SGST % must be Zero and IGST % equal to Tax Rate %");
         document.getElementById('cgstrate').value=0;
         document.getElementById('sgstrate').value=0;
         document.getElementById('igstrate').value=taxrt;
   }       
   
}
</script>

</head>
<?
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include_once("test.php");
if(isset($_POST['add']))
{

   $tax_rte=$_REQUEST['tax_rte'];
   $tax_descr=$_REQUEST['tax_descr'];
   $tax_cod=$_REQUEST['tax_cod'];
   $cgstrate=$_REQUEST['cgstrate'];
   $sgstrate=$_REQUEST['sgstrate'];
   $igstrate=$_REQUEST['igstrate'];


   if(($cgstrate+$sgstrate)!=$tax_rte)
   {
      print "<script>alert('Sum of CGST % and SGST % equal to Tax Rate %')</script>";      
   }
   if(strlen($tax_rte)<=0)
   {
      print "<script>alert('In sufficient entry')</script>";
      
   }

   /*$re=mysqli_query($db,"select * from taxmaster where taxrate='$tax_rte' and brcode='$brcode'");
   if(mysqli_num_rows($re)>0)
   {
      print "Duplicate entry $tax_rte";
      return;
   }
   else
   { */


   
   if($cgstrate>0)
       $txtyp='CGST';
   if($igstrate>0)
       $txtyp='IGST';

mysqli_query($db,"insert into taxmaster (brcode,taxrate,csgtrate,sgstrate,igstrate,id,taxdescr,taxtpe,taxcod)
     values('$brcode','$tax_rte','$cgstrate','$sgstrate','$igstrate','$tax_cod','$tax_descr','$txtyp','$tax_cod')");

  // }
}
if(isset($_POST['del'])) 
{
   $txid=$_REQUEST['txid'];
   mysqli_query($db,"delete from taxmaster where id='$txid'");
}
?>
<title>Amplc</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>

<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function handleEnter (field, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13) {
      var i;
      for (i = 0; i < field.form.elements.length; i++)
        if (field == field.form.elements[i])
          break;
      i = (i + 1) % field.form.elements.length;
      field.form.elements[i].focus();
      return false;
    }
    else
    return true;
  }

</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>
<style>
th{background-color:steelblue;color:white}
</style>
<body background="back_ground.jpg">
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()" method='post'>

<br>
<table class="container"><tr><td>
<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Master >> Tax Master</font>
<br>

<center>
<table class="form" ><tr><th colspan='2'>
<h3><font color='black'>Tax Master</font></h3></td></tr>
<form action='<?print $PHP_SELF?>'>

<tr><td>Tax Rate %</td><td><input type=text name='tax_rte' id='tax_rte' size=5 onKeyUp=chkey(this) onKeyPress="return handleEnter(this, event)"></td></tr>
<tr><td>Tax Desc</td><td><input type=text name='tax_descr' size=40 onKeyPress="return handleEnter(this, event)"></td></tr>
<tr><td>Tax Code</td><td><input type=text name='tax_cod' size=5 onKeyPress="return handleEnter(this, event)"></td></tr>
<tr><td>CGST %</td><td><input type=text name='cgstrate' id='cgstrate' size=5 onKeyPress="return handleEnter(this, event)"></td></tr>
<tr><td>SGST %</td><td><input type=text name='sgstrate' id='sgstrate' size=5 onKeyPress="return handleEnter(this, event)"></td></tr>
<tr><td>IGST %</td><td><input type=text name='igstrate' id='igstrate' size=5 onKeyUp=chkey1(this) onKeyPress="return handleEnter(this, event)"></td></tr>
<tr> <th colspan='2' align='center'><input type=submit value='Add' name='add'></th></tr>
</table>
</form>
<br>
<table border=1 class='report' width='50%'>
<th>Slno<th>TaxRate<th>Descr<th>TaxCode<th>Tax Type<th>Action
<?
$i=1;
$res=mysqli_query($db,"select * from taxmaster order by taxrate");
 while($row=mysqli_fetch_array($res))
 {
 print "<tr><form action='$PHP_SELF'><input type=hidden name='txid' value='$row[3]'><td>".$i++."</td><td>$row[2]</td><td>$row[4]</td><td>$row[0]</td><td>$row[5]</td><td><input type=submit value='Del' name='del'></td></form></tr>";
  }
?>