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

include("../opendb.php");
if($sprint)
{ 
//	$re=mysqli_query($db,"select max(invno) from veh_invoice where brcode='$brcode' and type='-'")or die(mysqli_error());
 //	$inv_row=mysqli_fetch_row($re);
 //	if($inv_row[0]<=0)
  //		$invno=1;
 	//else 
  	//	$invno=$inv_row[0]+1;
	//$invno = 0;
 	$invdate=$y.'-'.$m.'-'.$d;
 	//$rr=mysqli_query($db,"select code from rep_master where repname='$rep'");
 	//$rep_row=mysqli_fetch_row($rr);
 	//$rep=$rep_row[0];
	//$rs=mysqli_query($db,"select max(invno) from profinv where brcode='$brcode' ")or die(mysqli_error());
 	//$p_row=mysqli_fetch_row($rs);
 	//if(mysqli_num_rows($rs)<=0)
  		//$profno=1;
 	//else
      		//$profno=$p_row[0]+1;
 	$sql="insert into veh_trans(invno,cust,custaddr,consignee,consaddr,invdate,config,unit,engno,chasis,brcode,addr,qty,remark ) values('$invno','$consignor','$conaddr','$consignee','$cnsaddr','$invdate','$config','$unitpr','$engno','$da','$brcode','$addr','$qty','$remark')";

	mysqli_query($db,$sql) or die(mysqli_error());
	print "<script>window.open('prntrans.php?invno=$invno');</script>";
	$cure=mysqli_query($db,"select code,custname from cust_master where code='$cust'");
	$cust_row=mysqli_fetch_row($cure);
	$cust_name=strtoupper($cust_row[1]);
} // end save

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

<script>
var adr=[];
var adr2=[];
var ar1=[];
var config=[];
var model=[];
var rep=[];
var area=[];
var color=[];
var engno=[];
var chasis=[];
var mcode=[];
var cust=[];
function fun1()
{
 	var x=document.f1.config.selectedIndex; 
 	if(x<=0)
   	{
     		document.f1.mcode.value='';
     		document.f1.config.value='';
   	}
 	else
  	{ 
    		document.f1.mcode.value=mcode[document.f1.config.selectedIndex];
  	}
}

function valid()
{
 submitOK="true";
 if(document.f1.qty.value<=0 || isNaN(document.f1.qty.value))
 {
   submitOK="false";
   alert('Invalid Quantity');
   document.f1.qty.focus();
 }
 if(document.f1.invno.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Invoice No.');
 }
if(document.f1.cust.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Customer');
 }
 /* if(document.f1.fin.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Financer');
 }

 if(document.f1.formno.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Formno');
 }
*/
 if(document.f1.unit.value.length<=0)
 {
   submitOK="false";
   alert('Invalid unit price');
 }
/*
 if(document.f1.segment.value.length<=0)
 {
   submitOK="false";
   alert('Invalid Segment');
 }
*/
  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='';
  }
}

function setadr()
{
  var x= document.f1.cust.selectedIndex ; 
  if(x>0)
    document.f1.addr.value=adr[document.f1.cust.selectedIndex];
  else
    document.f1.addr.value='';
}
function setModel()
{
  var x= document.f1.formno.selectedIndex ; 
  if(x>0)
    {
     document.f1.model.value=model[document.f1.formno.selectedIndex];
     document.f1.rep.value=rep[document.f1.formno.selectedIndex];
     document.f1.area.value=area[document.f1.formno.selectedIndex];
     document.f1.cust.value=cust[document.f1.formno.selectedIndex];
     document.f1.addr.value=adr[document.f1.formno.selectedIndex];

   }
  else
    {
      document.f1.model.value='';
     document.f1.rep.value='';
     document.f1.area.value='';
   }

}
function getamt()
{
var str1;

str1=document.f1.da.value;

 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txt1").innerHTML=xmlhttp.responseText;
	
 document.f1.config.value=document.getElementById("drivbatta").value;
document.f1.engno.value=document.getElementById("incrent").value;
 document.f1.unitpr.value=document.getElementById("incrent1").value;

    }
  }
xmlhttp.open("GET","calcdata.php?chsno="+str1,true);
xmlhttp.send();
}
function getaddr(str)
{




 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txt1").innerHTML=xmlhttp.responseText;
	
 
 document.f1.conaddr.value=document.getElementById("consnm1").value;

    }
  }
xmlhttp.open("GET","getaddress.php?custnm="+str,true);
xmlhttp.send();
}
function getaddr1(str2)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txt1").innerHTML=xmlhttp.responseText;
	
 
 document.f1.cnsaddr.value=document.getElementById("consnm2").value;

    }
  }
xmlhttp.open("GET","getaddress1.php?custnm="+str2,true);
xmlhttp.send();
}
</script>


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

<input type=button value='Show All' onClick=document.location='listproforma.php'><br>&nbsp;
<form name='f1' action='<?print $PHP_SELF?>' onSubmit="return valid()">
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='GRAY'><FONT COLOR='IVORY'><B>CUSTOMER DETAILS</TD></TR>
<TR><td align=center bgcolor='ivory'>
<table>
<tr><td><font color=red>Consignor</td><td>
<? $result=mysqli_query($db,"select * from consign_mast order by name asc")or die(mysqli_error());
?>
<select name='consignor' onChange='getaddr(this.value)'>
<option>Select One</option>
<?
while($row=mysqli_fetch_array($result))
{

print "\n<option>$row[name]</option>";

}
?>
</select>
<td>Address </td><td><textarea name='conaddr' cols=40></textarea></td></tr>
<tr>
<tr><td><font color=red>Consignee</td><td>
<? $result=mysqli_query($db,"select * from consign_mast order by name asc")or die(mysqli_error());
?>
<select name='consignee' onChange='getaddr1(this.value)'>
<option>Select One</option>
<?
while($row=mysqli_fetch_array($result))
{

print "\n<option>$row[name]</option>";

}
?>
<td>Address </td><td><textarea name='cnsaddr' cols=40></textarea></td></tr>
<tr>
</table>
</td></tr>
</table>
<br>
<CENTER>

<table cellspacing=1 cellpadding=1 bgcolor=green style="border-collapse:collapse;" width='100%'>
<tr  bgColor='c1d7bb'><td align=center>
<table border=1 cellspacing=1 cellpadding=2 style="border-collapse:collapse;" width='100%'>
<tr bgColor='c1d7bb'><td colspan=7 align=center bgcolor='green'>
<font color='ivory'><STRONG>VEH TRANSFER NO. (Trans No:
<?
$rs=mysqli_query($db,"select max(invno) from veh_trans")or die(mysqli_error());
$p_row=mysqli_fetch_row($rs);
if(mysqli_num_rows($rs)<=0)
  	$pno=1;
else
   	$pno=$p_row[0]+1;
print $pno.')';
?>
<input type=hidden name='pno' value='<?print $pno?>'>
</TD></TR>
<tr>
</tr>
<tr>
<td>Transfer No </td><td><input type=text readonly name='invno' value='<?print $pno?>' size=8 style={background-color:silver}></td>


</tr>
<tr>
<?
if($brcode=='AUT009'||$brcode=='AUT103')
{
	?>
	<td><center><font color='red'>Qty</td><td><input type=text name='qty' size=2 onChange=calcKA()></td>
	<?
}
else
{
	?>
	<td><center><font color='red'>Qty</td><td><input type=text name='qty' size=2 onChange=calc()></td>
	<?
}
?>
</tr>
<tr><td>Chasis No </td><td>
<select name='da' onChange='getamt()'>
<option></option>
<?
$i=1;
$result=mysqli_query($db,"select * from veh_purchase where sale_invoice='-'  and brcode='$brcode' order by da")or die(mysqli_error());
while($row=mysqli_fetch_array($result))
{
	print "\n<option>$row[chasis]</option>";
	print "\n<script> engno[$i]='$row[11]' </script>";
 	print "\n<script> rep[$i]='$row[2]' </script>";
 	print "\n<script> area[$i]='$row[3]' </script>";
 	$i++;
}
$result=mysqli_query($db,"select * from vehopstock where brcode='$brcode' and sold='-' order by dano")or die(mysqli_error());
while($row=mysqli_fetch_array($result))
{
 	print "\n<option>$row[chno]</option>";
 	$i++;
}
?>
</select>
</td>
<div id='txt1'></div>
</tr>
<tr><td>Transfer Date</td><td>dd <input type=text name='d' size=2 value='<?print date("d",time())?>'>
mm <input type=text name='m' size=2 value='<?print date("m",time())?>'>
yy <input type=text name='y' size=4 value='<?print date("Y",time())?>'>
</td></td></tr>
<tr><td>config </td><td>
<input type=text name='config' size=20>
</td></tr>
<tr>
	<td><font color=red>Unit Price </td><td><input type=text name='unitpr' size=8 > </td>
    	

	
    	



</tr>




<tr>
<td>Engine No</td><td><input type=text readonly name='engno'></td></tr>
</tr>

<tr><td>Remarks </td><td colspan=5><textarea name='remark' cols=55></textarea></td></tr>
<tr><th colspan=6  bgcolor='green'> 

<input type=submit  value=' SAVE AND PRINT BILL ' name='sprint'>

<input type=button value='  CANCEL  ' onClick=history.back(1)></th></tr>
</table>
</form>
</td></tr>
</table>
</center>
<br>
<script>
function calc()
{
/*
qty=parseInt(document.f1.qty.value);
document.f1.amt2.value=(document.f1.unit.value-document.f1.disc.value)*qty;
 //net=parseFloat(document.f1.netamt.value);
 amt=(document.f1.amt2.value* 14.5)/100; 
 document.f1.tax.value=parseFloat(amt).toFixed(2);
var netamt2=parseFloat(document.f1.amt2.value)+parseFloat(document.f1.tax.value);
document.f1.netamt.value=netamt2.toFixed(0);

 //var tax=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
// document.f1.tax.value=(net-amt).toFixed(2);
 //document.f1.tax.value=(tax).toFixed(2);
 //var cessper=parseFloat(document.f1.cessp.value).toFixed(0);
// var ces_amt=parseFloat((document.f1.tax.value*cessper)/100);
 //document.f1.cessamt.value=ces_amt.toFixed(2);
*/

/*
document.f1.netamt.value=(document.f1.unit.value-document.f1.disc.value);
 net=parseFloat(document.f1.netamt.value);
 amt=(net*100)/112.5; 
 document.f1.amt2.value=parseFloat(amt.toFixed(2));

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



//old

qty=parseInt(document.f1.qty.value);
document.f1.netamt.value=(document.f1.unit.value-document.f1.disc.value)*qty;
 net=parseFloat(document.f1.netamt.value);
 amt=(net* 100)/114.5; 
 document.f1.amt2.value=parseFloat(amt).toFixed(2);

 tax=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
// document.f1.tax.value=(net-amt).toFixed(2);
 document.f1.tax.value=(tax).toFixed(2);
 var cessper=parseFloat(document.f1.cessp.value).toFixed(0);
 var ces_amt=parseFloat((document.f1.tax.value*cessper)/100);
 document.f1.cessamt.value=ces_amt.toFixed(2);

/*
document.f1.netamt.value=(document.f1.unit.value-document.f1.disc.value);
 net=parseFloat(document.f1.netamt.value);
 amt=(net*100)/112.5; 
 document.f1.amt2.value=parseFloat(amt.toFixed(2));

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

function calcKA()
{
var tx_red=1+parseFloat(document.f1.taxp.value)/100;
qty=parseInt(document.f1.qty.value);
document.f1.netamt.value=(document.f1.unit.value-document.f1.disc.value)*qty;
 net=parseFloat(document.f1.netamt.value);
// amt=(net/1.135); 
   amt=(net/tx_red); 
 document.f1.amt2.value=parseFloat(amt).toFixed(2);

 tax=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
// document.f1.tax.value=(net-amt).toFixed(2);
 document.f1.tax.value=(tax).toFixed(2);
 var cessper=parseFloat(document.f1.cessp.value).toFixed(0);
 var ces_amt=parseFloat((document.f1.tax.value*cessper)/100);
 document.f1.cessamt.value=ces_amt.toFixed(2);
  document.f1.tax.value=parseFloat(tax).toFixed(2);

/*
document.f1.netamt.value=(document.f1.unit.value-document.f1.disc.value);
 net=parseFloat(document.f1.netamt.value);
 amt=(net*100)/114; 
 document.f1.amt2.value=parseFloat(amt.toFixed(2));

 tax=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
 document.f1.tax.value=(net-amt).toFixed(2);
*/
}
</script>



