<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include("top.php");
include("opendb.php");
include("test.php");
//include("util/exqty.php");
//include ("spares/calcsparestock.php");
$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
$kar=mysqli_fetch_array($ker);
$pono=$_REQUEST['pono']; 
$vatorcst=$_REQUEST['vatorcst'];
$taxtype=$_REQUEST['taxtype'];
$mnfr=$_REQUEST['mnfr'];

?>
<html>
<title>Other Sales (Vehicle)</title>

<link href="css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<link type="text/css" href="jquery/jquery-ui.min.css" rel="stylesheet" />	
<script type="text/javascript" src="jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery/jquery.jqEasyCharCounter.min.js"></script>
    <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 type="text/javascript">
$(function(){

$(".partcode").live("keydown.autocomplete",function(){
var mnr=document.f1.mnfr.value;
var vator=document.f1.vatorcst.value;
$partcode = $(this);
$row = $partcode.parent().parent();
$(this).autocomplete({
		source: function( request, response ) {

		$.ajax({
		     
			url: "searchsord.php",
			dataType: "json",
			data: "key="+$partcode.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {calc
					return {
						//label: item.partcode+' | '+  item.partname+' | '+  item.stock +' | '+  item.price +' | '+  item.tax  ,
						label: item.partcode+' | '+  item.partname+' | '+  item.rate+' | '+  item.supqty,
						value: item.partcode,
						name:item.partname,
						exqty:item.supqty,
						price:item.rate,
						cgtxrt:item.cgstrt,
						sgtxrt:item.sgstrt,
						igtxrt:item.igstrt,

					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {
    $row.find('.partname').val(ui.item.name);
	$row.find('.price').val(ui.item.price);
	 <?
        if($vatorcst=='INTRASTATE')
        {
            
        ?>
        $row.find('.taxcgst').val(ui.item.cgtxrt);
        $row.find('.taxsgst').val(ui.item.sgtxrt);
        <?
        }
        ?>
         <?
        if($vatorcst=='INTERSTATE')
        {
            
        ?>
        $row.find('.taxigst').val(ui.item.igtxrt);
       
        <?
        }
        ?>
	$row.find('.availqty').val(ui.item.exqty);
	$row.find('.qty').val(0);
	$row.find('.qty').focus();
	//document.getElementById("unitprice").value=ui.item.stock;
	//$row.find('.rate').val(ui.item.price);
	
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});

$(".partname").live("keydown.autocomplete",function(){

$partcode = $(this);

$row = $partcode.parent().parent();
$(this).autocomplete({
		source: function( request, response ) {

		$.ajax({
			url: "search1.php?type=name",
			dataType: "json",
			data: "key="+$partcode.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label: item.partcode+' | '+  item.partname    ,
						value: item.partcode,
						code:item.brcode,
						

					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {

	$row.find('.partcode').val(ui.item.acname);
	$row.find('.supqty').val(ui.item.brcode);
	$row.find('.rate').val(ui.item.price);
	
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});






$(".orderto").live("keydown.autocomplete",function(){

$orderto = $(this);
$row = $orderto.parent().parent();
$(this).autocomplete({
		source: function( request, response ) {

		$.ajax({
			url: "searchcust.php",
			dataType: "json",
			data: "key="+$orderto.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label: item.orderto+' | '+  item.partname +' | '+  item.price  +' | '+  item.supqty  ,
						value: item.orderto,
						code:item.partname,
							adr:item.price,
							gst:item.supqty,
						

					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {
	$row.find('.orderto').val(ui.item.orderto);
	//$row.find('.msno').val(ui.item.partname);
	//document.f1.msno.value=ui.item.code;
	document.f1.addr.value=ui.item.adr;
	document.f1.tin.value=ui.item.gst;
	//document.f1.msno.focus();
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});

});
</script>



<script>
var inv=[];
var mcode=[];
var config=[];
var netamt=[];
var cust=[];
var unit=[];
var disc=[];
var tax=[];
var taxp=[];
var amt2=[];
var ccode=[];
var cstat=[];

var ttype=[];
function fun1()
{
 var x=document.f1.da.selectedIndex; 

 if(x<=0)
   {
     document.f1.inv.value='';
    document.f1.mcode.value='';
    document.f1.config.value='';
    document.f1.disamt.value='';
    document.f1.cust.value='';
    document.f1.custcode.value='';
 document.f1.cstate.value='';
document.f1.ttype1.value='';

   }
 else
  { 
    document.f1.inv.value=inv[document.f1.da.selectedIndex];
    document.f1.mcode.value=mcode[document.f1.da.selectedIndex];
    document.f1.config.value=config[document.f1.da.selectedIndex];
    document.f1.cust.value=cust[document.f1.da.selectedIndex];
    document.f1.custcode.value=ccode[document.f1.da.selectedIndex];
 document.f1.cstate.value=cstat[document.f1.da.selectedIndex];
document.f1.ttype1.value=ttype[document.f1.da.selectedIndex];

  }
}
</script>
<script type="text/javascript">
 var count1=0;
 var empname=[];

 var cur=1;
 //var partcode=[];
 var partname=[];
 var unitprice=[];
 var qty=[];
 var tot=[];
 var typ=[];
 var cnt=1;

function insRow(event,i1,id2)
{

var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

var cur_val=i1.value;


switch(keyCode)
{
case 38:
   var row=i1.parentNode.parentNode.rowIndex;
   var col  =i1.parentNode.cellIndex ;
			 
   document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
  break;
case 40:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
   document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
  break;
case 37:
  var row=field.parentNode.parentNode.rowIndex;
  var col  =field.parentNode.cellIndex ;
			 
  document.getElementById('myTable').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();
	
}



if(id2!="insrowbttn")
  {
   var i2=i1.parentNode.parentNode.rowIndex;
   var i3=parseFloat(i2)+parseFloat(1);
   var rowCounts = document.getElementById('myTable').rows.length;
   var rowCounts1= rowCounts-1;
   
  
  }
else
  {
   var i2=0;
   var rowCounts1=0;
  }




if(((keyCode == 13) && (i2==rowCounts1))||(cnt==1))
 {
var rowCount = document.getElementById('myTable').rows.length;
var rowcount1=parseFloat(rowCount)+parseFloat(1);
//alert(rowCount);
var x=document.getElementById('myTable').insertRow(rowCount);


if(rowCount>=1)
 {
  document.getElementById('insrowbttn').type='hidden';
 }

var a=x.insertCell(0);
var b1=x.insertCell(1);
var c1=x.insertCell(2);
var d1=x.insertCell(3);	
var e1=x.insertCell(4);
var f1=x.insertCell(5);
var g1=x.insertCell(6);
var h1=x.insertCell(7);
//var i1=x.insertCell(8);
<?
if($vatorcst=='INTRASTATE')
{
?>
var j1=x.insertCell(8);
var k1=x.insertCell(9);
var l1=x.insertCell(10);
var m1=x.insertCell(11);

var s1=x.insertCell(12);
var s2=x.insertCell(13);
var n1=x.insertCell(14);



var o1=x.insertCell(15);
var p1=x.insertCell(16);
var q1=x.insertCell(17);



<?
}
else
{
?>
var j1=x.insertCell(8);
var k1=x.insertCell(9);
var l1=x.insertCell(10);
var m1=x.insertCell(11);
var n1=x.insertCell(12);
var o1=x.insertCell(13);

<?
}
?>
var k;//=this.rowIndex;
var k1;
a.innerHTML=cur;

if(cur>1&&cnt>1)
{
    var ts=document.getElementById('dis'+(cur-1)).value;
}
else
{
    var ts=0;
}

b1.innerHTML="<input type=text name=partcode[] id=partcode"+cur+"  class='partcode' size=10 autocomplete='off' list='partcodelist' >";
c1.innerHTML="<input type=text name=partname[] id=partname"+cur+"  class='partname' size=20  autocomplete='off' list='partlist' onKeydown='return handleEnter(this, event)' >"; 
d1.innerHTML="<input type=text name='supqty[]' class='supqty' id=supqty"+cur+" size=4 onKeyup=calc(this.id) value='0' onKeydown='insRow(event,this,this.id)'>";
e1.innerHTML="<input type=text name=price[] id=price"+cur+" size=4 class='price' onfocus='sel(this.id)' onKeydown='return handleEnter(this, event)' onChange='calc(this.id)'>";

f1.innerHTML="<input type=text id='dis"+cur+"' name=disc[] value='"+ts+"' size=5 class='disc' onKeydown='insRow(event,this,this.id)' onfocus='sel(this.id)'  onKeyup='calc(this.id)'>";
g1.innerHTML="<input type=text id='discamt"+cur+"' name=discamt[] readonly value='0' size=5 class='disc' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
h1.innerHTML="<input type=text id='ap"+cur+"' name=aprice[] readonly value='0' size=5 class='aprice' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
i1.innerHTML="<input type=text id='hnd"+cur+"' name=hand[]  value='0' size=5 class='hand' onKeyup=calc(this.id) onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
<?
if($vatorcst=='INTRASTATE')
{
?>
j1.innerHTML="<input type=text id='taxcgst"+cur+"' name=taxcgst[]  value='0' size=5 class='taxcgst' onKeyup=calc(this.id) onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
k1.innerHTML="<input type=text id='taxamtcgst"+cur+"' name=taxamtcgst[] readonly value='0' size=5  onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
l1.innerHTML="<input type=text id='taxsgst"+cur+"' name=taxsgst[]  value='0' size=5 class='taxsgst' onKeyup=calc(this.id) onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
m1.innerHTML="<input type=text id='taxamtsgst"+cur+"' name=taxamtsgst[] readonly value='0' size=5 onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
n1.innerHTML="<input type=text id='taxamt"+cur+"' name=taxamt[] readonly value='0' size=5 onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
o1.innerHTML="<input type=text id='tot"+cur+"' name=tot[] readonly value='0' size=6 onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)' onKeyup='insRow(event,this,this.id)'  >";

s1.innerHTML="<input type=text id='fcessp"+cur+"' name=fcessp[]  value='0' size=6 onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)' onChange='calc(this.id)'  >";

s2.innerHTML="<input type=text id='fcessa"+cur+"' name=fcessa[] readonly value='0' size=6 onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)' onKeyup='insRow(event,this,this.id)'  >";

p1.innerHTML="<input type='button' onClick='delrow(this)' value='Del' style='width:30px;' class='del' id=del"+cur+">";
document.getElementById("partcode"+cur).focus();
q1.innerHTML="<input type=text id='availqty"+cur+"' name=availqty[] readonly value='0' size=5 class='availqty' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
<?
}
else
{
?>
j1.innerHTML="<input type=text id='taxigst"+cur+"' name=taxigst[] readonly value='0' size=5 class='taxigst' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
k1.innerHTML="<input type=text id='taxamtigst"+cur+"' name=taxamtigst[] readonly value='0' size=5  onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
l1.innerHTML="<input type=text id='taxamt"+cur+"' name=taxamt[] readonly value='0' size=5  onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
m1.innerHTML="<input type=text id='tot"+cur+"' name=tot[] readonly value='0' size=6 class='tot' onfocus='sel(this.id)' onKeydown='insRow(event,this,this.id)'>";
n1.innerHTML="<input type='button' onClick='delrow(this)' value='Del' style='width: 30px;' class='del' id=del"+cur+">";
document.getElementById("partcode"+cur).focus();
o1.innerHTML="<input type=text id='availqty"+cur+"' name=availqty[] readonly  size=5 class='availqty' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
<?
}
?>

cur++; 
cnt++;


var table = document.getElementById("myTable");
var row = table.rows[index];
console.log(secondRow.id);
}
if(keyCode == 40)
{
return handleEnter(this, event);
}
if(keyCode == 13)
{

var tbl = document.getElementById('myTable');
   var id3=tbl.rows[i3].cells[0].innerHTML;
document.getElementById("partcode"+id3).focus();
} 

}// end function insrow

function delrow(r)
{

var i=r.parentNode.parentNode.rowIndex;

 document.getElementById('myTable').deleteRow(i);

  var rowCount = document.getElementById('myTable').rows.length;

   var tbl = document.getElementById('myTable');
   
  var q;
  var id1;
  var part; 
  var sum2=0;
   var sum3=0;
  var stot;
  var ltot;
    
   var k=0;
			var ups = document.getElementsByName('discamt[]'), sum = 0, k;
			for(k = ups.length; k--;)
			{
				if(ups[k].value)
				{
					sum += parseFloat(ups[k].value, 10);
				}
                  document.getElementById('totdiscvl').value=sum.toFixed(2);
			}
			var l=0;
			var ups1 = document.getElementsByName('taxamt[]'), sum1 = 0, l;
			for(l = ups1.length; l--;)
			{
				if(ups1[l].value)
				{
					sum1 += parseFloat(ups1[l].value, 10);
				}
				 
                  document.getElementById('tottx').value=sum1.toFixed(2);
			}

			var m=0;
			var ups2 = document.getElementsByName('tot[]'), sum2 = 0, m;
			for(m = ups2.length; m--;)
			{
				if(ups2[m].value)
				{
					sum2 += parseFloat(ups2[m].value, 10);
				}
				  
                  document.getElementById('ggtot').value=sum2.toFixed(2);
			}
			var n=0;
			var ups3 = document.getElementsByName('supqty[]'), sum3 = 0, n;
			for(n = ups3.length; n--;)
			{
				if(ups3[n].value)
				{
					sum3 += parseFloat(ups3[n].value, 10);
				}
                  document.getElementById('totsupqty').value=sum3.toFixed(2);
			}
             handling();
	
 if(rowCount<=1)
 {
  document.getElementById('insrowbttn').type='button';
  ///alert(rowCount);
 }

cnt--;
cur--;     
 }

 $(document).ready(function(){
  
  $("#svbttn").click(function(){
$("#msgbox").html('<small>Loading...</small>');

if(document.f1.cust.value=='')
 {
  alert('Please select customer');
  document.f1.cust.focus();
  return false;
 }

 if(document.f1.paytype.selectedIndex<=0)
 {
  alert('Invalid Payment Type');
  document.f1.paytype.focus();
  return false;
 }
 if(confirm('Do you want to save?'))
	  {
 

      // var name= $(this).attr('name');

       //$('#type_name').val(name);

     var values1 = $("#jforms").serialize();
alert(values1);
   // $(".typeselecter").attr("disabled", true);
    // $("#td1").html('');

      $.ajax({
        url: "svinvoice_newveh.php",
        type: "POST",
       data:   values1,
         success: function(msg){
              if(parseInt(msg)!=0)

              {

                $('#msgbox').html(msg);
               // $("#load").html('');
                //$(".typeselecter").attr("disabled", false);
    }


        },
      error:function(){
          alert("failure1");
          $("#msgbox").html('there is error while submit');
      }
      });
	 }
	 else
	  {
   return false;
	  }
   });




$("#svbttn2").click(function(){
$("#msgbox").html('<small>Loading...</small>');



 if(document.f1.cust.value=='')
 {
  alert('Please select customer');
  document.f1.cust.focus();
  return false;
 }
 if(confirm('Do you want to save?'))
	  {
 

      // var name= $(this).attr('name');

       //$('#type_name').val(name);

     var values1 = $("#jforms").serialize();
//alert(values1);
   // $(".typeselecter").attr("disabled", true);
    // $("#td1").html('');

      $.ajax({
        url: "svinvoice_newtoken.php",
        type: "POST",
       data:   values1,
         success: function(msg){
              if(parseInt(msg)!=0)

              {

                $('#msgbox').html(msg);
               // $("#load").html('');
                //$(".typeselecter").attr("disabled", false);
    }


        },
      error:function(){
          alert("failure2");
          $("#msgbox").html('there is error while submit');
      }
      });
	 }
	 else
	  {
   return false;
	  }
   });



   });

</script>
<style>


#mask {
	display: none;
	background:url(images/bgimg1.gif) repeat;
	//background: #000; 
	position: fixed; left: 0; top: 0; 
	z-index: 10;
	width: 100%; height: 100%;
	opacity: 0.8;
	z-index: 999;
}

.login-popup{
		display:none;
	background:white;
	padding: 10px; 	
	border: 2px solid #ddd;
	float: left;
	font-size: 1.2em;
	position: fixed;
	top: 4%; left: 45%;
	z-index: 99999;
	box-shadow: 0px 0px 20px #999;
	-moz-box-shadow: 0px 0px 20px #999; /* Firefox */
    -webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
	border-radius:3px 3px 3px 3px;
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari, Chrome */
}
}

img.btn_close {
	float: right; 
	margin: -28px -28px 0 0;
}

fieldset { 
	border:none; 
}

form.signin .textbox label { 
	display:block; 
	padding-bottom:7px; 
}

form.signin .textbox span { 
	display:block;
}

form.signin p, form.signin span { 
	color:white; 
	font-size:11px; 
	line-height:18px;
} 

form.signin .textbox input { 
	background:#666666; 
	border-bottom:1px solid #333;
	border-left:1px solid #000;
	border-right:1px solid #333;
	border-top:1px solid #000;
	color:white; 
	border-radius: 3px 3px 3px 3px;
	-moz-border-radius: 3px;
    -webkit-border-radius: 3px;
	font:13px Arial, Helvetica, sans-serif;
	padding:6px 6px 4px;
	width:200px;
}

form.signin input:-moz-placeholder { color:white; text-shadow:0 0 2px #000; }
form.signin input::-webkit-input-placeholder { color:hwite; text-shadow:0 0 2px #000;  }

.submit button { 
	background: -moz-linear-gradient(center top, #f3f3f3, #dddddd);
	background: -webkit-gradient(linear, left top, left bottom, from(#f3f3f3), to(#dddddd));
	background:  -o-linear-gradient(top, #f3f3f3, #dddddd);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f3f3f3', EndColorStr='#dddddd');
	border-color:#000; 
	border-width:1px;
	border-radius:4px 4px 4px 4px;
	-moz-border-radius: 4px;
    -webkit-border-radius: 4px;
	color:#333;
	cursor:pointer;
	display:inline-block;
	padding:6px 6px 4px;
	margin-top:10px;
	font:12px; 
	width:100px;
}

.button:hover { background:#ddd; }


.del{
      border: none;
     background: url("images/delete.png") no-repeat scroll 0 0 transparent;
}




.pop-up2 {position:absolute; top:2px; left:50px;padding-left:180px;}
.pop-up2:target {position:static; left:0;}

.popBox2 {
  background:#ffffff;

 
  width:75%;
  min-height:100%;



   z-index:1;

  border:1px solid #3a3a3a;


  -moz-border-radius:12px;
  border-radius:12px;
  -webkit-box-shadow:2px 2px 4px #3a3a3a;
  -moz-box-shadow:2px 2px 4px #3a3a3a;
  box-shadow:2px 2px 4px #3a3a3a;
  opacity:0;
 -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  -ms-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;  
}
:target .popBox2 {position:fixed; opacity:1;}

.popBox2:hover {box-shadow:3px 3px 6px #5a5a5a;}



.lightbox {display:none; text-indent:0em; background:#000; opacity:0.0; width:100%; height:60%; position:fixed; top:0; left:0; bottom:0; right:0;}
:target .lightbox {display:block}



  


/* .popScroll {max-height:99%; overflow-y:scroll;} removed 17/07/2012 */
.popScroll2 {position:absolute; top:2%; left:3%; right:3%; bottom:9%; overflow-y:auto; *overflow-y:scroll; padding-right:0.5em}


</style>

<body background="../back_ground.jpg" onload="tblopen()">
<br>
<center>
<table class="container"><tr><td>

<form name="f1" id="jforms">

<div id="view" class="login-popup">

</div>
		<div id="login-box" class="login-popup">
        <a href="#" class="close"><img src="../images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>
          <div id='msgbox'></div>
		</div>
<input type=hidden name='invtype'  value='<?print $taxtype?>'>
<input type=hidden name='vatorcst' id='vatorcst' value='<?print $vatorcst?>'>

<?
$sqi="select max(invno) from spareinvoice_oth_veh where brcode='$brcode'";
$re=mysqli_query($db,$sqi);
	$row11=mysqli_fetch_array($re);
if($row11[0]>0)
{
	
	
	
	//print $row11[0];
       $invno=$row11[0]+1;
}
else
{
    
$invno='25'.$brcode.'220001'; 
	//print $invno;
       
/*	$invno=substr('000000'.$invno,-6);
	if($invno==0)
	{
		$invno='000001'; 
	}
	$invno=$mprefix.$invno; */
}	
 
$tbl="sparetmp".$brcode.$user;
print "<center><table border=0  cellspacing=1 cellpadding=3 class='form' ><th colspan=6 style='background-color: steelblue;color: white;'><H3> OTHER INVOICE VEHICLE($invno) $taxtype-$vatorcst</TH>";
print "<tr><td></td><td></td>";
print "<td></td><td></td>";
//print "<td>Refered By</td><td><input type=text name='msno' value='$row[msno]'></td>
print"</tr><tr>";
//print "<td>Customer</td><td><input type='text' name='customer' id='orderto' placeholder='Type Customer Name Here' class='orderto' size=50></td>";

?>
<tr><td>D.A</td><td><select name='da' onChange=fun1()>
<option></option>
<?
 $res=mysqli_query($db,"select a.acname,a.code,b.invno,b.da,b.chasis,b.config,b.netamt,b.unit, b.disc, b.taxp, b.tax, b.amt2,a.stat,b.taxtype from psn_amplvehicle2021.cust_master a,psn_amplvehicle2122.veh_invoice b where b.brcode='Aut141' and a.branch='Aut141' and b.type='-' and a.code=b.cust order by b.da")or die(mysqli_error($db));
 $i=1;
 while($row=mysqli_fetch_array($res))
 {
   print "\n<option>$row[da]</option>";
   print " \n<script> cust[$i]='$row[acname]'</script>";
   print " \n<script> ccode[$i]='$row[1]'</script>";
   print " \n<script> inv[$i]='$row[invno]'</script>";
   print " \n<script> mcode[$i]='$row[chasis]'</script>";
   print " \n<script> config[$i]='$row[config]'</script>";
   print " \n<script> netamt[$i]='$row[netamt]'</script>";
   print " \n<script> unit[$i]='$row[unit]'</script>";
   print " \n<script> disc[$i]='$row[disc]'</script>";
   print " \n<script> taxp[$i]='$row[taxp]'</script>";
   print " \n<script> tax[$i]='$row[tax]'</script>";
   print " \n<script> amt2[$i]='$row[amt2]'</script>";
 print " \n<script> cstat[$i]='$row[stat]'</script>";
 print " \n<script> ttype[$i]='$row[taxtype]'</script>";

  $i++;
 }
 
 $res=mysqli_query($db,"select a.acname,a.code,b.invno,b.da,b.chasis,b.config,b.netamt,b.unit, b.disc, b.taxp, b.tax, b.amt2,a.stat,b.taxtype from psn_amplvehicle.cust_master a,psn_amplvehicle.veh_invoice b where b.brcode='Aut141' and a.branch='Aut141' and b.type='-' and a.code=b.cust order by b.da")or die(mysqli_error($db));
 //$i=1;
 while($row=mysqli_fetch_array($res))
 {
   print "\n<option>$row[da]</option>";
   print " \n<script> cust[$i]='$row[acname]'</script>";
   print " \n<script> ccode[$i]='$row[1]'</script>";
   print " \n<script> inv[$i]='$row[invno]'</script>";
   print " \n<script> mcode[$i]='$row[chasis]'</script>";
   print " \n<script> config[$i]='$row[config]'</script>";
   print " \n<script> netamt[$i]='$row[netamt]'</script>";
   print " \n<script> unit[$i]='$row[unit]'</script>";
   print " \n<script> disc[$i]='$row[disc]'</script>";
   print " \n<script> taxp[$i]='$row[taxp]'</script>";
   print " \n<script> tax[$i]='$row[tax]'</script>";
   print " \n<script> amt2[$i]='$row[amt2]'</script>";
 print " \n<script> cstat[$i]='$row[stat]'</script>";
 print " \n<script> ttype[$i]='$row[taxtype]'</script>";

  $i++;
 }
 
 $res=mysqli_query($db,"select a.brname,a.code,b.invno,b.da,b.chasis,b.config,b.netamt,b.unit, b.disc, b.taxp, b.tax, b.amt2,a.stat,b.taxtype from psn_amplvehicle.br_master a,psn_amplvehicle.veh_invoice b where b.brcode='Aut141' and a.brcode='Aut141' and b.type='trans-out' and a.code=b.cust order by b.da")or die(mysqli_error($db));
 //$i=1;
 while($row=mysqli_fetch_array($res))
 {
   print "\n<option>$row[da]</option>";
   print " \n<script> cust[$i]='$row[brname]'</script>";
   print " \n<script> ccode[$i]='$row[1]'</script>";
   print " \n<script> inv[$i]='$row[invno]'</script>";
   print " \n<script> mcode[$i]='$row[chasis]'</script>";
   print " \n<script> config[$i]='$row[config]'</script>";
   print " \n<script> netamt[$i]='$row[netamt]'</script>";
   print " \n<script> unit[$i]='$row[unit]'</script>";
   print " \n<script> disc[$i]='$row[disc]'</script>";
   print " \n<script> taxp[$i]='$row[taxp]'</script>";
   print " \n<script> tax[$i]='$row[tax]'</script>";
   print " \n<script> amt2[$i]='$row[amt2]'</script>";
 print " \n<script> cstat[$i]='$row[stat]'</script>";
 print " \n<script> ttype[$i]='$row[taxtype]'</script>";

  $i++;
 }
?>
</select>
</td><td>Invoice </td><td>
<input type=text name='inv'></td></tr>
<tr><td>Customer </td><td colspan=4><input type=text size=80  readonly name='cust'></td></tr>
<tr> <td>Config </td><td colspan=4><input type=text  size=80 readonly name='config'></td><tr><tr><td>Chasis </td><td><input type=text readonly name='mcode'></td><td>Vehicle/MS No.</td><td><input type=text value='0' name='msno' id='msno' class='msno' size=30></td>
   </tr>

</tr>
<?
print "<td><font color=red>Payment Type</font></td><td><select name='paytype'><option></option>";
//if($cusrow[cramt]<=0)
//{
//print "<option>Cash</option></select></td></tr>";
//}
//else
//{
print "<option>Credit</option></select></td>";
//}
//print "<tr><td>Site Address</td><td><textarea name='addr'>$cusrow[addr1]$cusrow[dist1]</textarea></td>";
print "<td>GST No.</td><td><input type=text name='tin' value='0' readonly value='$cusrow[gst]' size=30></td></tr>";


print "<td>Sale Bill No.</td><td><input type=text readonly name='invno' value='$invno'></td><td>Ref: </td><td><input type=text name='ref' value='0' size=30></td> </tr>";
print "<tr><td>Sale Date</td><td>dd<input type=text  name='d' size=2 maxlength=2 value='".date("d")."'>
mm<input type=text  name='m' size=2 maxlength=2 value='".date("m")."'>
yy<input type=text  name='y' size=4 maxlength=4 value='".date("Y")."'>
</td>";
print "<td>Entry Date</td><td>dd<input type=text  name='d1' size=2 maxlength=2 value='".date("d")."'>
mm<input type=text  name='m1' size=2 maxlength=2 value='".date("m")."'>
yy<input type=text  name='y1' size=4 maxlength=4 value='".date("Y")."'>
</td>";




print "</tr>";
print "<tr>";
print "<input type=hidden name=mnfr value='$mnfr'>";
print "";
print "</tr>";
print "<tr><th colspan=10></tr>";
print"</table>";

?>

<center>
<table class=report>

<tr>    
<input type="button" id='insrowbttn' onclick="insRow(event,this,this.id)" style="color:#6B6B6B;font-weight:bold;font-size:15px;" value="+">
<td colspan='6' align=center>  
<table border=0 cellspacing=1 cellpadding=3 id="myTable" class='tble1'>
<tr class='trcls'><th>No<th>P Code <th> Name <th> Sale Qty
<th>Price <th>Disc% <th>Disc Amt<th>A Price
<?
if($vatorcst=='INTRASTATE')
   print "<th>CGST%<th>CGST Amt<th>SGST%<th>SGST Amt<th>Flood Cess %<th>Flood Cess Amt";
else
 print "<th>IGST%<th>IGST Amt";
?>
<th> Tax Amt<th> Total<th> Del<th>Qty Avail</tr>
</table></td></tr>
</table>
<?

print "\n<table class=report><tr><td colspan=4> <center><b>Total </td><td colspan=4 align=center></td><td></td><td align=center>Qty Total<input type=text class=right name='totsupqty[]' id='totsupqty' size=8></td>";
print "\n<td align=center>Disc Total<input type=text class=right name='totdiscvl' id='totdiscvl' readonly size=8></td><td align=center>";
print "Tax Total<input type=text class=right id='tottx' size=8></td><td>Handling<input type=text name=hnd id='hnd' value='0' onkeyup='handling()' size=5></td>";
print "<td>Hand Tax%<input type=text name=hndtax readonly id='hndtax' value='0' size=5></td>";
print "<td>Grand Total<input type=text name=ggtot id='ggtot' size=10></td></tr>";

?>
<tr>
<th colspan=17><input value="Save"  type="button" id='svbttn'>
<input type=button value='Cancel' onClick=window.close()></th>
</table>
</form>
</body>
<script type="text/javascript">

$(document).bind('keydown', 'Alt+n',function (e){

if(e.which==83 && e.ctrlKey) {
e.preventDefault()
 $( "#svbttn" ).click();
        return false;
}   
    if(e.which==78 && e.altKey){
	 //alert (e.which);
        shortkey_tblopen();
        return false;
    } 
 
   if(e.which==82 && e.altKey){
	 
         window.location.reload(true);
        return false;
    } 
      
    
});
function myFunction()
	{
		window.location.reload(true);
        	return false;
	}
</script>

<script>
 function calc(x)
 {
 	        
	var thenum = x.match(/\d+$/)[0];
    var x=thenum;
 var qty='supqty'+x; 
 var ele='price'+x; 
 var disele='dis'+x;
 var actele='ap'+x;
 //var hndele='hnd'+x;
 var taxele='taxcgst'+x;
 var taxsgstele='taxsgst'+x;
 var taxigstele='taxigst'+x;
 var totele='tot'+x;
 var txamtele='taxamt'+x;
 var totsupq='totsupqty';
 var tx='tottx';
 var avail='availqty'+x;
 var taxamtcgstele='taxamtcgst'+x;
 var taxamtsgstele='taxamtsgst'+x;
 var taxamtigstele='taxamtigst'+x;
 var taxamvl='discamt'+x;
 //var hndele='hnd'+x;
var taxfcessp='fcessp'+x;
var taxfcessa='fcessa'+x;
 if(parseFloat(document.getElementById(qty).value)>parseFloat(document.getElementById(avail).value) || document.getElementById(avail).value=='')
 {
   alert('Stock only 0'+document.getElementById(avail).value);
  document.getElementById(qty).value=0;
  document.getElementById(qty).focus();
   return false;
 }

 var amt=parseFloat(document.getElementById(ele).value)*(parseFloat(document.getElementById(qty).value)); //+parseFloat(document.getElementById(warele).value));
 var disc=amt*parseFloat(document.getElementById(disele).value)/100;
 var actamt=amt-disc;

 document.getElementById(taxamvl).value=parseFloat(disc).toFixed(2);
//document.getElementById(disele).value=parseFloat(disc);

document.getElementById(actele).value=parseFloat(actamt).toFixed(2);


    //var hnd=document.getElementById(hndele).value;
	//if(document.getElementById(hndele).value=='NaN')
	 //{
	//	document.getElementById(hndele).value==0;
	 //}
 
    var vator=document.getElementById('vatorcst').value;

	if(vator=='INTRASTATE')
	 {  
		var tx=parseFloat(document.getElementById(taxele).value);
		var txsgst=parseFloat(document.getElementById(taxsgstele).value);
		var txfcess=parseFloat(document.getElementById(taxfcessp).value);

		var taxc=(actamt*tx)/100;
		var taxs=(actamt*txsgst)/100;
		var tot_tax=taxc+taxs;
		var taxf=(actamt*txfcess)/100;
		document.getElementById(txamtele).value=tot_tax.toFixed(2);
		document.getElementById(taxamtcgstele).value=taxc.toFixed(2);
		document.getElementById(taxamtsgstele).value=taxs.toFixed(2);
		document.getElementById(taxfcessa).value=taxf.toFixed(2);
	    var total=parseFloat(actamt)+parseFloat(tot_tax)+parseFloat(taxf);
		document.getElementById(totele).value=parseFloat(total).toFixed(2);

	 }
	 else
	 {
		var txigst=parseFloat(document.getElementById(taxigstele).value);
		var tot_tax=(actamt*txigst)/100;
		document.getElementById(txamtele).value=tot_tax.toFixed(2);
		document.getElementById(taxamtigstele).value=tot_tax.toFixed(2);
		var total=parseFloat(actamt)+parseFloat(tot_tax);
		document.getElementById(totele).value=parseFloat(total).toFixed(2);
	 }


            var k=0;
			var ups = document.getElementsByName('discamt[]'), sum = 0, k;
			for(k = ups.length; k--;)
			{
				if(ups[k].value)
				{
					sum += parseFloat(ups[k].value, 10);
				}
                  document.getElementById('totdiscvl').value=sum.toFixed(2);
			}
			var l=0;
			var ups1 = document.getElementsByName('taxamt[]'), sum1 = 0, l;
			for(l = ups1.length; l--;)
			{
				if(ups1[l].value)
				{
					sum1 += parseFloat(ups1[l].value, 10);
				}
				 
                  document.getElementById('tottx').value=sum1.toFixed(2);
			}

			var m=0;
			var ups2 = document.getElementsByName('tot[]'), sum2 = 0, m;
			for(m = ups2.length; m--;)
			{
				if(ups2[m].value)
				{
					sum2 += parseFloat(ups2[m].value, 10);
				}
				  
                  document.getElementById('ggtot').value=sum2.toFixed(2);
			}
			var n=0;
			var ups3 = document.getElementsByName('supqty[]'), sum3 = 0, n;
			for(n = ups3.length; n--;)
			{
				if(ups3[n].value)
				{
					sum3 += parseFloat(ups3[n].value, 10);
				}
                  document.getElementById('totsupqty').value=sum3.toFixed(2);
			}
             handling();
				 

 }
 function handling()
 {

        			var p=0;
			var ups4 = document.getElementsByName('tot[]'), sum4 = 0, p;
			for(p = ups4.length; p--;)
			{
				if(ups4[p].value)
				{
					sum4 += parseFloat(ups4[p].value, 10);
				}
				  
                  document.getElementById('ggtot').value=sum4.toFixed(2);
			}
				 
         var hnd=document.getElementById('hnd').value;
		 var hnd_txamt=(parseFloat(hnd)*parseFloat(document.getElementById('hndtax').value))/100;
		 var grandtot=parseFloat(sum4)+parseFloat(hnd_txamt)+parseFloat(hnd);
		 document.getElementById('ggtot').value=parseFloat(grandtot).toFixed(2);
 }
</script>

<script type="text/javascript">
function tblopen()
{
                
               var rowCounts = document.getElementById('myTable').rows.length;
              //alert(rowCounts);
		if(rowCounts<=1){
			               document.getElementById('insrowbttn').click(); 
                        }		   					
 		 
 }
</script>