<?
session_start();
$brcode = $_SESSION['brcode'];
$user = $_SESSION['user'];
$yy = $_REQUEST['yy'];
$mm = $_REQUEST['mm'];
$dd = $_REQUEST['dd'];
$y = $_REQUEST['y'];
$m = $_REQUEST['m'];
$d = $_REQUEST['d'];
$da = $_REQUEST['da'];
$pno= $_REQUEST['pno'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");

//newly added

$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error());
$r=mysqli_fetch_row($us);
$user_level=$r[0];

$dt=$yy.'-'.$mm.'-'.$dd;
//print $user_level;
//print $dt;

if($user_level<=4)
{
$sq="select to_days(curdate())-to_days('$dt')";
$dtre=mysqli_query($db,$sq)or die(mysqli_error());
$dtrow=mysqli_fetch_row($dtre);

if($dtrow[0]>3 || $dtrow[0]<0)
{
 print "<script> alert('Invalid Date, Entry possible for last 3 days only'); history.back(1); </script>";
 return;
}
}
//
$upd = $_REQUEST['upd'];
if($upd)
{
    $invno= $_REQUEST['invno'];
    $ledger= $_REQUEST['ledger'];
    $mcode= $_REQUEST['mcode'];
    $config= $_REQUEST['config'];
    $netamt= $_REQUEST['netamt'];
    $tax= $_REQUEST['tax'];
    $taxp= $_REQUEST['taxp'];
    $amt2= $_REQUEST['amt2'];
    $disc= $_REQUEST['disc'];
    $color= $_REQUEST['color'];
    $engno= $_REQUEST['engno'];
    $chasis= $_REQUEST['chasis'];
    $remark= $_REQUEST['remark'];
    $tp= $_REQUEST['tp'];
    $loc= $_REQUEST['loc'];
    $emcode= $_REQUEST['emcode'];
    $cessp= $_REQUEST['cessp'];
    $cessamt= $_REQUEST['cessamt'];
    $hsncode= $_REQUEST['hsncode'];
    $jvno= $_REQUEST['jvno'];
    $oldda= $_REQUEST['oldda'];
    $entrydate=$yy.'-'.$mm.'-'.$dd;
    $invdate=$y.'-'.$m.'-'.$d;
    
    $taxtype = $_REQUEST['taxtype'];
if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}

if(!checkdate($mm,$dd,$yy))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}

$dif=0;
$purqry=mysqli_query($db,"select jvno from veh_purchase where pur_no='$pno' and da='$da' and brcode='$brcode'");
$purchrw=mysqli_fetch_array($purqry);
$oldjvno=$purchrw[0];
mysqli_query($db,"delete from journal2 where brcode='$brcode' and jvno='$oldjvno'");
 
$jvr=mysqli_query($db,"select max(jvno) from journal2 where brcode='$brcode'");
 $j_row=mysqli_fetch_row($jvr);
  if($j_row[0]<=0)
   $jvno=1;
  else
  $jvno=($j_row[0]+1);
 if (str_contains('ve', $ledger)) {
//if(eregi('ve',$ledger))
 $tp= "eich";
 }
else
 $tp= "other";
 
$sql="update veh_purchase set ledger='$ledger',invno='$invno',invdate='$invdate',da='$da',
mcode='$mcode', config='$config', netamt='$netamt', tax='$tax',taxp='$taxp', amt2='$amt2',disc='$disc', 
color='$color', engno='$engno',chasis='$chasis', remark='$remark',entrydate='$entrydate',
type='$tp',loc='$loc',emcode='$emcode',cessp='$cessp',cessamt='$cessamt',hsncode='$hsncode',jvno='$jvno' where pur_no='$pno' and da='$da' and brcode='$brcode'";
print $sql;
 mysqli_query($db,$sql) or die("Err:".mysqli_error());

$sql="update veh_movement set date='$entrydate',da='$da',sup_type='$ledger' where inv_no='$pno' and type='pur' and brcode='$brcode'";
mysqli_query($db,$sql) or die(mysqli_error());

$r=mysqli_query($db,"select code from purorder where purno='$pno' and brcode='$brcode'");
 $puorder=mysqli_fetch_row($r);
$sq="update purorder set purno='-',purdate='0000-00-00' where dano='$oldda' and brcode='$brcode'";
mysqli_query($db,$sq) or die(mysqli_error());
$sq="update purorder set purdate='$entrydate',purno='$pno' where dano='$da' and brcode='$brcode'";
mysqli_query($db,$sq) or die(mysqli_error());



if($taxtype=='INTRASTATE')
{
	$taxper = $taxp/2;
	$tax_amt = $tax/2;
	$sql="insert into journal2 values('$entrydate','$jvno','Dr','Purchase $taxp(vehicle)','$amt2', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	mysqli_query($db,$sql) or die("J V Write error 1:".mysqli_error());

	$sql="insert into journal2 values('$entrydate','$jvno','Dr','CGST $taxper','$tax_amt', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());

	$sql="insert into journal2 values('$entrydate','$jvno','Dr','SGST $taxper','$tax_amt', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());

  	$sql="insert into journal2 values('$entrydate','$jvno','Dr','Input Cess','$cessamt', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());
	if($tcsamt<='')
	{
	    $tcsamt=0;
	}
	$sql="insert into journal2 values('$entrydate','$jvno','Dr','TCS Amount Receivable @ $tcsp%','$tcsamt', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());
}
else
{
	$sql="insert into journal2 values('$entrydate','$jvno','Dr','Purchase $taxp(vehicle) IGST','$amt2', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	//echo $sql;
	mysqli_query($db,$sql) or die("J V Write error 1:".mysqli_error());

  	$sql="insert into journal2 values('$entrydate','$jvno','Dr','Input IGST $taxp%','$tax', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
  	//echo $sql;
	mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());

  	$sql="insert into journal2 values('$entrydate','$jvno','Dr','Input Cess','$cessamt', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
  	//echo $sql;
	mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());
	if($tcsamt<='')
	{
	    $tcsamt=0;
	}
	$sql="insert into journal2 values('$entrydate','$jvno','Dr','TCS Amount Receivable @ $tcsp%','$tcsamt', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
	//echo $sql;
	mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());
}
$sql="insert into journal2 values('$entrydate','$jvno','Cr','$ledger','0','$netamt','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
mysqli_query($db,$sql) or die("J V Write error 3:".mysqli_error());

        $jvd=mysqli_query($db,"select sum(dramt)-sum(cramt) from journal2 where jvno='$jvno' and brcode='$brcode'");
	    $difrow=mysqli_fetch_array($jvd);
	    $dif=$difrow[0];
	    
	    
	    $x=abs($dif);
	    if($dif<0)
	    {
    		$sql="insert into journal2 values('$entrydate','$jvno','Dr','Round Off','$x', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$invno')";
		   mysqli_query($db,$sql) or die("J V Write error dif1:".mysqli_error());
	    }
	    else if($dif>0)
	    {
    		$sql="insert into journal2 values('$entrydate','$jvno','Cr','Round Off','0','$x','P.Bill No: $invno','$brcode','V pur','DA','$da','$invno')";
		   mysqli_query($db,$sql) or die("J V Write error dif:".mysqli_error());
	    }
//echo $sql;






/*

if($roundoff>0)
{
$sql="insert into journal2 values('$entrydate','$jvno','Dr','Round Off','$roundoff', '0','P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());
}
else
{
$roff=abs($roundoff);

$sql="insert into journal2 values('$entrydate','$jvno','Cr','Round Off','0','$roff', 'P.Bill No: $invno','$brcode','V pur','DA','$da','$da')";
mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());

}
*/
 







//************** journal update
/*
if($taxtype=='VAT')
{
    $sql="update journal2 set date='$entrydate',dramt='$amt2', narr='P.Bill No: $invno',no='$da',partic='Purchase $taxp(vehicle)' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic like 'Purchase%(vehicle)'";
mysqli_query($db,$sql) or die("J V Write error 1:".mysqli_error());

  $sql="update journal2 set date='$entrydate',dramt='$tax',narr='P.Bill No: $invno',no='$da',partic='Input tax $taxp' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic like 'Input tax%'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());
  
$sql="update journal2 set date='$entrydate',dramt='$cessamt',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Input Cess'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());

}
else
{
$sql="update journal2 set date='$entrydate',dramt='$amt2', narr='P.Bill No: $invno',no='$da',partic='Purchase $taxp(vehicle) CST' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic like 'Purchase%(vehicle) CST'";
mysqli_query($db,$sql) or die("J V Write error 1:".mysqli_error());

  $sql="update journal2 set date='$entrydate',dramt='$tax',narr='P.Bill No: $invno',no='$da',partic='Input tax $taxp CST' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic like 'Input tax% CST'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());
  
$sql="update journal2 set date='$entrydate',dramt='$cessamt',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Input Cess'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());

}

if($roundoff>0)
{
$sql="update journal2 set date='$entrydate',dramt='$roundoff',type='Dr',cramt='0.00',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno'  and partic='Round Off'";
mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());
}
else
{
$roff=abs($roundoff);
$sql="update journal2 set date='$entrydate',cramt='$roff',type='Cr',dramt='0.00',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and partic='Round Off'";
//$sql="insert into journal2 values('$entrydate','$jvno','Cr','Round Off','0','$roff', 'P.Bill No: $invno','$brcode','V pur','DA','$da','$invno')";
mysqli_query($db,$sql) or die("J V Write error 2cess:".mysqli_error());

}

 $sql="update journal2 set date='$entrydate',cramt='$netamt',narr='P.Bill No: $invno',no='$da',partic='$ledger' where brcode='$brcode' and jvno='$jvno' and type='Cr' and partic!='Round Off'";

mysqli_query($db,$sql) or die("J V Write error 3:".mysqli_error());

/*
if($taxp=='12.5')
{ 
  $sql="update journal2 set date='$entrydate',dramt='$amt2', narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Purchase 12.5(vehicle)'";
mysqli_query($db,$sql) or die("J V Write error 1:".mysqli_error());

  $sql="update journal2 set date='$entrydate',dramt='$tax',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Input tax 12.5'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());
  
$sql="update journal2 set date='$entrydate',dramt='$cessamt',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Input Cess'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());


 $sql="update journal2 set date='$entrydate',cramt='$netamt',narr='P.Bill No: $invno',no='$da',partic='$ledger' where brcode='$brcode' and jvno='$jvno' and type='Cr'";
mysqli_query($db,$sql) or die("J V Write error 3:".mysqli_error());

}

if($taxp=='14')
{ 
  $sql="update journal2 set date='$entrydate',dramt='$amt2', narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Purchase 14(vehicle)'";
mysqli_query($db,$sql) or die("J V Write error 1:".mysqli_error());

  $sql="update journal2 set date='$entrydate',dramt='$tax',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Input tax 14'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());
  
$sql="update journal2 set date='$entrydate',dramt='$cessamt',narr='P.Bill No: $invno',no='$da' where brcode='$brcode' and jvno='$jvno' and type='Dr' and partic='Input Cess'";
mysqli_query($db,$sql) or die("J V Write error 2:".mysqli_error());


 $sql="update journal2 set date='$entrydate',cramt='$netamt',narr='P.Bill No: $invno',no='$da',partic='$ledger' where brcode='$brcode' and jvno='$jvno' and type='Cr'";
mysqli_query($db,$sql) or die("J V Write error 3:".mysqli_error());

}
*/
//************************** end joural
log_entry($brcode,$user,"$jvno|purchase|Edit","Edit purchase Journal $da,$invno, - $jvno",$db);
print "<script> document.location='veh_purch.php' </script>";
 return;
}

$result=mysqli_query($db,"select * from veh_purchase where da='$da' and pur_no='$pno' and brcode='$brcode'")or die(mysqli_error());
$pur_row=mysqli_fetch_array($result);
print 'Jv No:'.$pur_row['jvno'];
?>
<script>
var ar1=[];
var config=[];
function fun1()
{
 var x=document.f1.da.selectedIndex; 
 
    document.f1.mcode.value=ar1[document.f1.da.selectedIndex];
    document.f1.config.value=config[document.f1.da.selectedIndex];
}

function valid()
{
 submitOK="true";
 if(document.f1.invno.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Invoice No.');
 }
 if(document.f1.da.selectedIndex<0)
 {
   submitOK="false";
   alert('Invalid DA');
 }
 if(document.f1.loc.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Location');
 }

 if(document.f1.engno.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Engine No.');
 }
 if(document.f1.chasis.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Chasis');
 }

 if(document.f1.netamt.value.length<=0 || isNaN(document.f1.netamt.value))
 {
   submitOK="false";
   alert('Invalid Net Amount');
 }


var day1=document.f1.dd.value;
var mon1=document.f1.mm.value;
var year1=document.f1.yy.value;
var chdt=day1+"/"+mon1+"/"+year1;

var tempdt=year1+"-"+mon1+"-"+day1;
var tempact=document.f1.act.value;
var tempacf=document.f1.acf.value;


function ValidateDate() 
{
 
    var msg = '';
 
    this.isDate = function(date) 
     {
 
        var explodeData = date.explode("/");
        var day = explodeData[0];
        var month = explodeData[1];
        var year = explodeData[2];
 
        var thisMonth = new Date(year, month, 0);
        var daysInMonth = thisMonth.getDate();
        var pattern = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
 
        if (!pattern.test(date)) {
            msg = "invalid date format";
        }
        else if (day > daysInMonth) {
            msg = "invalid day";
        }
        else if (month > 12) {
            msg = "invalid month";
        }
 
        if (msg) {
            return false;
        } else {
            return true;
        }
    }
 
    this.getMsg = function() 
    {
 
        return msg;
    }
}

 
 vDate = new ValidateDate();
 
if (vDate.isDate(chdt))

 {

if(tempdt>=tempacf&&tempdt<=tempact)
{

//alert('hii');

}
else
{
submitOK="false";

document.f1.mm.focus();

alert('date should be in between current Financial Year');

}

 //alert("Date is valid");
 }
else 

{
 submitOK="false";

document.f1.dd.focus();
alert("Date is not valid: " + vDate.getMsg()); 
}



  if(submitOK=="true")
   return true;
  else
   return false;
}

function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf(' ')>-1) 
  {
    alert('Space is not allowed');
    abc.value='';
  }
}
</script>


<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<CENTER>
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()">
<input type=hidden name='jvno' value='<?Print $pur_row['jvno']?>'>
<table cellspacing=1 cellpadding=1 bgcolor=green>
<tr  bgColor='c1d7bb'><td align=center>
<table border=1 cellspacing=1 cellpadding=2>
<tr bgColor='c1d7bb'><td colspan=7 align=center bgcolor='green'>
<font color='ivory'><STRONG>VEHICLE PURCHASE EICHER(Pur No:
<?print $pur_row['pur_no']; ?> )
<input type=hidden name='pno' value='<?print $pno?>'>
</TD></TR>
<tr><td>From </td><td colspan=2><select name='ledger'>
<?
 if($pur_row['type']=='trans-in')
 {
   $rrr=mysqli_query($db,"select brcode,brname from branch where brcode='$pur_row[ledger]'") or die (mysqli_error());
   $br_row=mysqli_fetch_row($rrr);
   print "<option value='$br_row[0]'>$br_row[1]</option>";
 }
 else
   print "<option>$pur_row[ledger]</option>";
 
$res=mysqli_query($db,"select led from ledger where grp='Sundry Creditors'  and brcode='$brcode' order by led");
while($row=mysqli_fetch_row($res))
{
 print "<option>$row[0]</option>";
}
?>
</select></td>
<td colspan=1 align=right>Date  </td><td colspan=2>
<?
$end=explode('-',$pur_row['entrydate']);
?>
	dd <input type=text name='dd' size=2 value='<?print $end[2]?>'>
	mm <input type=text name='mm' size=2 value='<?print $end[1]?>'>
	yy <input type=text name='yy' size=4 value='<?print $end[0]?>'>
</td>
</tr>
<tr>
<td><font color=red>Invoice No </td><td><input type=text name='invno' value='<?print $pur_row['invno']?>' ></td>
<td>Invoice Date </td><td>
<?$ddt=explode('-',$pur_row['invdate']);
 $d1=$ddt[2];
 $m1=$ddt[1];
 $y1=$ddt[0];
?>
dd <input type=text name='d' size=2 value='<?print $d1 ?>'>
mm <input type=text name='m' size=2 value='<?print $m1 ?>'>
yy <input type=text name='y' size=4 value='<?print $y1 ?>'>
</td>
<td>Location </td><td><select name='loc'>
<option></option>
<?
$re=mysqli_query($db,"select code,lname from loc_master where brcode='$brcode' order by lname");
while($lorow=mysqli_fetch_row($re))
{
 print "<option value='$lorow[0]'>$lorow[1]</option>";
}
?>
</select></td>
</tr>
<tr><td><font color='red'>DA </td><td> <input type=hidden name='oldda' value='<?print $pur_row['da']?>'>
<select name='da' onChange=fun1()>
<option><?print $pur_row['da']?></option>
<?
 print "\n<script> ar1[0]='$pur_row[mcode]';\n config[0]='$pur_row[config]'</script>";
$result=mysqli_query($db,"select code,ordno,dano,mcode,config from purorder where purno ='-' and brcode='$brcode'")or die(mysqli_error());
$i=1;
while($row=mysqli_fetch_array($result))
{
 print "\n<option>$row[dano]</option>";
 print "\n<script> ar1[$i]='$row[mcode]';\n config[$i]='$row[config]'</script>";
 $i++;
}
?>
</select>
</td>
<td>Model Code </td><td><input type=text readonly name='mcode' value='<?print $pur_row['mcode']?>'></td>
<td>config </td>
<td>
<select name='config' onChange=fun1()>
<option><?print $pur_row['config']?></option>
<?
$result=mysqli_query($db,"select config,mcode from veh_master where brcode='$brcode' order by config")or die(mysqli_error());

$i=1;
while($row=mysqli_fetch_array($result))
{

 print "\n<option>$row[config]</option>";
 print "\n<script> ar1[$i]='$row[mcode]'</script>";
 $i++;
}
?>
</select>
</td>


</tr>

<tr><td><font color='red'>Net Amount</td><td><input type=text name='netamt' readonly value='<?print $pur_row['netamt']?>'></td>
    <td>Tax Type<input type=text name='taxtype' size=10 readonly value='<?print $pur_row['taxtype']?>'>Tax %</td><td><select name='taxp' onChange=calc()> <option><?print $pur_row['taxp']?></option>
 <option value='14.50'>14.50</option><option value='14.50'>14.50</option><option value='2'>2</option><option value='1'>1</option><option value='0'>0</option><option value='28.00'>28.00</option> </select>
 <input type=text name='tax' readonly size=10  value='<?print $pur_row['tax']?>'></td>
<td>Round Off</td><td><input type=text name='roundoff' readonly value='<?print round($pur_row['netamt']-($pur_row['amt2']+$pur_row['tax']),2)?>'></td>

</tr>

<tr>
<td>Cess %</td><td>
<?
if($brcode!='aut009')
{
print "<input type=text name='cessp' size=2 value=".$pur_row['cessp']." onChange=calc()>";
}
else
{
print "<input type=text name='cessp' size=2 value='0' onChange=calc()>";
}
?>

</td>
<td>Cess Amt</td><td><input type=text name='cessamt' size=6 value='<?print $pur_row['cessamt']?>'></td>
    <td>Amount <br>Before Tax </td><td><input type=text   name='amt2' onChange=calc() value='<?print $pur_row['amt2']?>' ></td>
</tr>
<tr><td>Discount </td><td><input type=text name='disc'  value='<?print $pur_row['disc']?>'></td><td>Color</td>
<td><input type=text name='color' value='<?print $pur_row['color']?>'></td>
<td><font color='red'>Engine No</td><td><input type=text name='engno'  value='<?print $pur_row['engno']?>' onKeyDown=chkey(this)></td>
</tr>
<tr>

<td><font color='red'>Chasis No</td><td>
 <input type=text name='chasis'  value='<?print $pur_row['chasis']?>'onKeyDown=chkey(this)></td>



<td>Eicher <br>Model Code </td><td><input type=text name='emcode' value='<?print $pur_row['emcode']?>'></td>
<td>HSN Code </td><td><input type=text name='hsncode' value='<?print $pur_row['hsncode']?>'></td></tr>
<tr><td colspan=6 align=right bgcolor='green'> <input type=submit name='upd' value=' UPDATE '>
<input type=button value='  Cancel  ' onClick=document.location='veh_purch.php'></td></tr>

<?
//
$acpd=mysqli_query($db,"select * from acperiod") or die ('err'.mysqli_error());
$acrow=mysqli_fetch_row($acpd);


?>
<tr><td><input type=hidden name='acf' value='<?print $acrow[0]?>'></td>
<td><input type=hidden name='act' value='<?print $acrow[1]?>'></td>
</tr>



</table>
</form>
</td></tr>
</table>
</center>
<br>
<script>

function fun1()
{
 var x=document.f1.config.selectedIndex; 
 
 if(x<=0)
   {
     document.f1.mcode.value='';
     document.f1.config.value='';
   }
 else
  {
    document.f1.mcode.value=ar1[document.f1.config.selectedIndex];
     }
}


function calc()
{
/*
var pe=document.f1.taxp.value; 
var cessper=parseFloat(document.f1.cessp.value).toFixed(0);

 if(pe==0)
  taxper=12.5;
 else
   taxper=0;
 net=parseFloat(document.f1.netamt.value);
 x=(100+parseFloat(cessper)); 
 zz=(100+parseFloat(pe)); 
  if(cessper>0)
  {
    yy=pe*cessper/100;
    zz=zz+yy;
  }

 amt=(net*100)/zz;
tax=(amt*parseFloat(document.f1.taxp.value))/100;
 
 document.f1.amt2.value=parseFloat(amt.toFixed(2));

// tax=(parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value))/100;

 document.f1.tax.value=tax.toFixed(2);

 var ces_amt=parseFloat((document.f1.tax.value*cessper)/100);
 document.f1.cessamt.value=ces_amt.toFixed(2);
*/

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

var tax_amt=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
document.f1.tax.value=tax_amt.toFixed(2);

var ces_amt=parseFloat(document.f1.tax.value)*parseFloat(document.f1.cessp.value)/100;
document.f1.cessamt.value=ces_amt.toFixed(2);


var net_amt=parseFloat(document.f1.amt2.value)+parseFloat(document.f1.tax.value)+parseFloat(document.f1.cessamt.value);
document.f1.netamt.value=net_amt.toFixed(0);

var gt=parseFloat(document.f1.amt2.value)+parseFloat(document.f1.tax.value)+parseFloat(document.f1.cessamt.value);
 var round=parseFloat(document.f1.netamt.value)-gt;
//alert(round.toFixed(2));

document.f1.roundoff.value=round.toFixed(2);

}
</script>
