<? session_start();


$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];

date_default_timezone_set("Asia/Kolkata");
$logdt=date("Y-m-d");
$logtime=date("H:i:s");


if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}

include("../opendb.php");

?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
th{font-size:14}
</style>

<script>
function validate()
{
 var uniprice=document.f1.uni_amt.value;
 var qty=document.f1.qty.value;
 var gross=document.f1.gross.value;
 var net=document.f1.net.value;
 var gtot=document.f1.gtot.value;
 var sub="true";
 if(qty.length<=0||isNaN(qty))
 {
   alert('Invalid Quantity'); sub="false";
 }

 if(uniprice.length<=0||qty.length<=0||gross.length<=0||net.length<=0||gtot.length<=0)
 {
   alert('Invalid entry'); sub="false";
 }
 if(gross<=0||uniprice<=0||isNaN(uniprice))
 {
   alert('Invalid Amt'); sub="false";
 }

 if(sub=="false")
  return false;
 else
  return true;
}
function calcgross()
{
  var uniprice=document.f1.uni_amt.value;
 var qty=document.f1.qty.value;
 if(qty<=0||isNaN(qty))
   document.f1.qty.value='1';
 var gross=uniprice*qty;
 document.f1.gross.value=gross;
 document.f1.disc.value=0;

 var gross=document.f1.gross.value;
 var disc=document.f1.disc.value;
 document.f1.net.value=gross-disc;
 var taxamt=document.f1.net.value*document.f1.taxp.value/100;
 document.f1.taxamt.value=taxamt;
 document.f1.gtot.value=parseFloat(document.f1.net.value)+parseFloat(document.f1.taxamt.value);


}

function calcnet()
{

if(document.f1.taxp.value==12.5)
document.f1.cessp.value=1;
else
{
document.f1.cessp.value=0;
}

//var disc=document.f1.disc.value;
 //var unit=parseFloat(document.f1.uni_amt.value);
 //var net=document.f1.net.value;
 //var gross=unit*document.f1.qty.value;
 //document.f1.gross.value=gross
 //var ces_p=parseFloat(document.f1.cessp.value);
 //var xx=parseFloat(document.f1.taxp.value)*ces_p/100; 
 //var taxp=parseFloat(document.f1.taxp.value);
 //var Btaxamt=parseFloat(gross)*100/(100+parseFloat(document.f1.taxp.value)+xx);
 //alert(Btaxamt);
 //var vat=parseFloat(gross-Btaxamt).toFixed(2);

var tax1=(parseFloat(document.f1.net.value)*parseFloat(document.f1.qty.value))*parseFloat(document.f1.taxp.value)/100;
 document.f1.taxamt.value= tax1.toFixed(2);
var cess1=parseFloat(document.f1.taxamt.value)*parseFloat(document.f1.cessp.value)/100;
document.f1.cessamt.value=cess1.toFixed(2);
//var uniamt2=parseFloat(document.f1.net.value)+parseFloat(document.f1.taxamt.value)+parseFloat(document.f1.cessamt.value);
var uniamt2=parseFloat(document.f1.net.value)*parseFloat(document.f1.qty.value);
document.f1.uni_amt.value=uniamt2.toFixed(2);
var gtot2=parseFloat(document.f1.uni_amt.value)+parseFloat(document.f1.taxamt.value)+parseFloat(document.f1.oth.value);
document.f1.gtot.value=gtot2.toFixed(0);

document.f1.gross.value=gtot2.toFixed(0);


 //document.f1.net.value=Btaxamt.toFixed(2);
 //document.f1.gtot.value=gross;
 //var tx=parseFloat(Btaxamt)*taxp/100;


 //var cess_amt=parseFloat(tx*ces_p/100);
 //document.f1.net.value=parseFloat((Btaxamt*taxp)/100).toFixed(2);

//document.f1.taxamt.value=parseFloat(tx).toFixed(2);
 //document.f1.cessamt.value=cess_amt.toFixed(2)

/*
 var disc=document.f1.disc.value;
 var unit=parseFloat(document.f1.uni_amt.value);
 var net=document.f1.net.value;
 var gross=unit*document.f1.qty.value;
 document.f1.gross.value=gross
 var ces_p=parseFloat(document.f1.cessp.value);
 var xx=parseFloat(document.f1.taxp.value)*ces_p/100; 
 var taxp=parseFloat(document.f1.taxp.value);
 var Btaxamt=parseFloat(gross)*100/(100+parseFloat(document.f1.taxp.value)+xx);
 alert(Btaxamt);
 var vat=parseFloat(gross-Btaxamt).toFixed(2);

 document.f1.taxamt.value=vat


 document.f1.net.value=Btaxamt.toFixed(2);
 document.f1.gtot.value=gross;
 var tx=parseFloat(Btaxamt)*taxp/100;


 var cess_amt=parseFloat(tx*ces_p/100);
 //document.f1.net.value=parseFloat((Btaxamt*taxp)/100).toFixed(2);

document.f1.taxamt.value=parseFloat(tx).toFixed(2);
 document.f1.cessamt.value=cess_amt.toFixed(2)
*/
}

</script>

<body bgcolor='ivory' onSubmit="return validate()">
<base target='main1'>
<CENTER>
<BR>
<table cellspacing=1 cellpadding=1 bgcolor='darkbrown'>
<tr><td align=center>

<FORM name='f1' ACTION='purch_items.php' METHOD='POST'>
<table>
<th>Item  <th>Chasis <th>Configuration
<tr> <td>
<select name='item'>
<?
 $re=mysqli_query($db,"select * from partmaster where group1='VEHICLE' order by partcode");
 while($row=mysqli_fetch_row($re))
 {
  print "<option value='$row[0]'>$row[1]</option>";
 }
?>
</select>
</td>
<td><input type=text name='chasis'></td> 
<td><select name='config'>
<?
$rrr=mysqli_query($db,"select config from  psn_amplvehicle.veh_master order by config")or die(mysqli_error($db));
while($crow=mysqli_fetch_array($rrr))
{
 print "<option>$crow[0]</option>";
}
?>
</select></td> 
</tr>
</table>
<table>
<tr>
<th>Tax Rate <th><font color=red>Unit Before Tax <th><font color=red> Qty  <th>Gross Value <th>Cash Disc<th><font color=red>Before Tax   
<th>Tax Amt. <th>Cess% <th>Cess Amt<th>Other Charges<th><font color=red>Grant Total <th>Disc/Gift <br>Free<th>Tax Type
<tr>
<td>Tax Type<select name='ttype' onChange='setttype()'> <option>INTRA STATE</option><option>INTER STATE</option></select> <select name='taxp' onChange=calcnet()>
<option value='28.00'>28%</option><option value='18.00'>18%</option>

    <option value='5'>5%</option> <option value='0'>0%</option>

 
</select></td>
<td><input type=text name='net' size=10 value='' onChange=calcnet()></td>

<td>    <input type=text size=4 name='qty' value='1'  onChange=calcnet()></td>
<td><input type=text readonly name='gross' size=8></td>
<td><input type=text name='disc' size=6 value='0' onChange=calcnet()></td>

<td>   <input type=text name='uni_amt' size=8 readonly style={text-align:right}></td>

<td><input type=text name='taxamt' size=6></td>
<?
if($brcode=='Aut009')
print "<td><input type=text name='cessp' readonly size=2 value=0 onChange=calcnet()></td>";
else
print "<td><input type=text name='cessp' readonly size=2 value=0 onChange=calcnet()></td>";
?>
<td><input type=text name='cessamt' readonly size=4></td>
<td><input type=text name='oth' size=5 value='0' onChange=calcnet()></td>
<td><input type=text name='gtot' size=10></td>
<td><input type=text name='disfree' value='0' size=6></td>
</table>
</td></tr>
<tr><td align=center bgColor='lightsteelblue'><input name='submit' type=submit value='   ADD   '></td></tr>
</table>
</td></tr>
</table>
</form>
