<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
   print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
  return;
}
include("../opendb.php");
$inno=$_REQUEST['inno'];
//if($user=='antony'||$user=='thomas')
//{
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>PSN Auto, Administration Software</title>
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />	
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript" src="functions_purchase.js"></script>


<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() {

    
 $("#supinvoice_date").datepicker({
	dateFormat: "yy-mm-dd"
   });



 });
  </script>
  <script type="text/javascript">

$(function(){
  $(".supnm").live("keydown.autocomplete",function(){
  $supnm = $(this);
  $row = $supnm.parent().parent();
  $(this).autocomplete({
    source: function( request, response ) {
    $.ajax({
      url: "search1.php",
      dataType: "json",
      data: "key="+$supnm.val(),
      success: function( data ) {
        response( $.map( data, function( item ) {
          return {
            label: '<span class="la-name">'+item.supnm+' </span><span class="la-name">'+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
            value: item.supnm,
            name:item.partname,
            tax:item.tax,
            stock:item.stock,
            rate:item.rate,
            reduct:item.reduct,
            }
        }));
      }
    });
  }
  ,
  minLength: 2,
  select: function( event, ui ) {
  $row.find('.partname').val(ui.item.name);
  $row.find('.stok').val(ui.item.stock);
  $row.find('.unitprice').val(ui.item.rate);

  $row.find('.tax').val(ui.item.tax);
  $row.find('.itmvl').val(ui.item.reduct);
  $row.find('.qty').focus();
  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

  }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };
  });
});


           





</script>
<script type="text/javascript">
var count1=1;
var count2=1;
var count3=1;
var pname=[];
var pcode=[];
var pname1=[];
var pcode1=[];
var empname=[];
var ndpcost=[];
$(function(){
$(".partcode").live("keydown.autocomplete",function(){
$partcode = $(this);

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

		$.ajax({
			url: "search.php",
			dataType: "json",
			data: "key="+$partcode.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					
					
					return { 
						label: '<span class="la-code">'+item.partcode+' </span><span class="la-name">'+  item.partname + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
						value: item.partcode,
						name:item.partname,
						tax:item.tax,
						
						stock:item.stock,
						rate:item.rate,
						
							
						
					}
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {
	$row.find('.partname').val(ui.item.name);
	
	
	$row.find('.unitprice').val(ui.item.rate);
	
	
	
	
	$row.find('.qty').show().focus();
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	}).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };

					
});




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

$partname = $(this);

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

		$.ajax({
			url: "search5.php?type=name",
			dataType: "json",
			data: "key="+$partname.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return { 
						label: '<span class="la-code">'+item.partcode+' </span><span class="la-name">'+  item.partname + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
						code: item.partcode,
						value:item.partname,
						tax:item.tax,
						
						stock:item.stock,
						rate:item.rate,
						rate2:item.rate2,
						reduct:item.reduct,	
						
						
					}
	
				}));
			}
		});
	}
	
,
	minLength: 2,
	select: function( event, ui ) {

	$row.find('.partcode').val(ui.item.code);
	$row.find('.stok').val(ui.item.stock);
	$row.find('.unitprice').val(ui.item.rate);
	$row.find('.pur_rate').val(ui.item.rate2);
	$row.find('.tax').val(ui.item.tax);
	$row.find('.itmvl').val(ui.item.reduct);
	$row.find('.qty').focus();
		
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	}).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };

					
});
});





function sel(id1)
{

   document.getElementById(id1).select();
  
}




function showHint()
{
document.getElementById("popScroll2").innerHTML="<img src='images/loader.GIF' />";

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("popScroll2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","purchviewinv1.php", true);
xmlhttp.send();
}



function viewinv(str)
{
document.getElementById("popScroll2").innerHTML="<img src='images/loader.GIF' />";


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("popScroll2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","purchviewinv.php?inno="+str,true);
xmlhttp.send();
}


/** code below for close popup div **/
function close_div(){
   var list = document.getElementsByClassName("pop-up2");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('pop2');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }



 function check_empname(str,id1){

   var flg=0;
   for(var j=0;j<count1;j++){
alert(empname[j]);
       if(str==empname[j]){

         flg++;

       }//close of if cond.
  

   }//close of for loop.

   var len=str.length;

   if((!isNaN(str))&&len<=1){

   flg++;
   }
 
   if(flg<1){
    alert('Invalid employee');
    document.getElementById(id1).value='';
    document.getElementById(id1).focus();
    
   }
   
 }//function closed.


 function showHint1()
{
document.getElementById("popScroll2").innerHTML="<img src='images/loader.GIF' />";

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("popScroll2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","delete_itmpurch1.php", true);
xmlhttp.send();
}
function viewinv1(str)
{
document.getElementById("popScroll2").innerHTML="<img src='images/loader.GIF' />";


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("popScroll2").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","delete_itmpurch.php?inno="+str,true);
xmlhttp.send();
}
</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
</style>
<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("../img/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>

<script type="text/javascript">

$(document).bind('keydown', 'Alt+n',function (e){
      
    if(e.which==78 && e.altKey){
	 //alert (e.which);
        shortkey_tblopen();
        return false;
    } 
     if(e.which==83 && e.altKey){
	 
         $( "#svbttn" ).click();
        return false;
    } 
   if(e.which==82 && e.altKey){
	 
         window.location.reload(true);
        return false;
    } 
      
    
});
</script>

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

</script>
<script>
$(document).ready(function() {
	$('a.login-window').click(function() {
		
		// Getting the variable's value from a link 
		var loginBox = $(this).attr('href');

		//Fade in the Popup and add close button
		$(loginBox).fadeIn(300);
		
		//Set the center alignment padding + border
		var popMargTop = ($(loginBox).height() + 24) / 2; 
		var popMargLeft = ($(loginBox).width() + 24) / 2; 
		
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		// Add the mask to body
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		
		return false;
	});
	
	// When clicking on the button close or the mask layer the popup closed
	$('a.close, #mask').live('click', function() { 
	  $('#mask , .login-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
});
$(document).ready(function(){
  $("#svbttn").click(function(){

$("#msgbox").html('<small>Loading...</small>');


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

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

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

  	  $.ajax({
   	   url: "upd_purchase.php",
    	  type: "POST",
   	  data:   values1,
     	  success: function(msg){



           	 if(parseInt(msg)!=0)

          	  {
              
                $('#msgbox').html(msg);

                //$(".typeselecter").attr("disabled", false);
		}


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

	 });
	 });



</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;
  }
//alert(cur);



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 j1=x.insertCell(8);
var s1=x.insertCell(9);
var p1=x.insertCell(10);
var k;//=this.rowIndex;
var k1;
a.innerHTML=cur;


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='qty[]' readonly class='qty' id=qty"+cur+" size=4 onKeydown='return handleEnter(this, event)' onKeyup='calc(this.value,this,this.id)'>";//onKeyup=validnum(this.id)
e1.innerHTML="<input type=text name=unitprice[] id=unitprice"+cur+" size=4 class='unitprice' onfocus='sel(this.id)' onKeydown='return handleEnter(this, event)' onKeyup='calc(this.value,this,this.id)'>";

f1.innerHTML="<input type=text id='befrtxamt"+cur+"' name=befrtxamt[] readonly value='0' size=5 class='befrtxamt' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'  >";
var v="";
v="<select name='vat[]' id=vat"+cur+" class='vat' onKeydown='return handleEnter(this, event)'>";
if(document.getElementById("taxtype").value=='VAT')
{
<?
$sql="select * from taxmaster where type='VAT'";
$rs=mysqli_query($db,$sql);
while($row=mysqli_fetch_array($rs))
{
?>
v=v+'<option><? echo $row[0] ?></option>';
<?
}
?>
}
else if(document.getElementById("taxtype").value=='CST')
{
<?
$sql="select * from taxmaster where type='CST'";
$rs=mysqli_query($db,$sql);
while($row=mysqli_fetch_array($rs))
{
?>
v=v+'<option><? echo $row[0] ?></option>';
<?
}
?>
}
else
{
v=v+'<option>0</option>';
}
g1.innerHTML=v+"</select> ";
h1.innerHTML="<input type=text id='taxamt"+cur+"' name=taxamt[] readonly value='0' size=5 class='taxamt' onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)' onKeyup='insRow(event,this,this.id)'  >";

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

var ss="";

ss="<select name='itmtyp[]' id=itmtyp"+cur+" class='itmtyp' onKeydown='return handleEnter(this, event)'>";
ss=ss+'<option>Spares</option>';
ss=ss+'<option>Lubricant</option>';
s1.innerHTML=ss+"</select> ";

p1.innerHTML="<input type='button' onClick='delrow(this)' class='del' id=del"+cur+">";
document.getElementById("partcode"+cur).focus();
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 newcustomer()
{
document.getElementById("to_new_customerTD").innerHTML=" <input id='to_new_customer' name='cus' style='outline:none;border:1px solid grey; border-style:dotted;width:150px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;'   placeholder='Customer name' type='text'>";

 document.getElementById("to_new_registerTD").innerHTML=" <input id='to_new_register' name='reg' style='outline:none;border:1px solid grey;width:150px; padding-left:7px; font-weight:normal;border-style:dotted; font-family:verdana;font-size:13px;'  placeholder='Customer id' type='text'>"
 document.getElementById("show").innerHTML="<a href='#' style='text-decoration:none; color:black;' onclick='showcustomer()'>Click Here to Show Existing Customer</a>";
document.getElementById("pmode").value='CASH';
}
function showcustomer()
{

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("to_new_customerTD").innerHTML=xmlhttp.responseText;
    document.getElementById("show").innerHTML="<a href='#' style='text-decoration:none; color:black;' onclick='newcustomer()'>Click Here for Cash Invoice</a>";
    }
  }
document.getElementById("pmode").value='CREDIT';
xmlhttp.open("GET","showcus.php",true);
xmlhttp.send();
}

function showregister(str)
{
//var str="hello";
//alert (str);
if (str=="")
  {
  document.getElementById("to_new_registerTD").innerHTML="";
  return;
  }
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("to_new_registerTD").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","showreg.php?cname="+str,true);
xmlhttp.send();

}

function showinfo(str)
{
//var str="hello";


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("to_new_model").innerHTML=xmlhttp.responseText;
    var  mod= document.getElementById("mod").value;
    document.getElementById('to_new_model').value=mod;
    document.getElementById("chno").innerHTML=xmlhttp.responseText;
    var  chasis= document.getElementById("chasis").value;
    document.getElementById('chno').value=chasis;
    
    }
  }
xmlhttp.open("GET","showinfo.php?reg="+str,true);
xmlhttp.send();

}
</script>



<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form1.css" rel="stylesheet" />



<style>
.tble1 input {
background-color:transparent;
border: 0px solid;
height:20px;
//width:160px;
color:black;
}
.tble1
{

border:1px solid silver;
margin-top:20px;
}
.trcls
{

background-color:#BDBDBD;
border:1px solid silver;

}	
.tble1 td, th
{
border-collapse:collapse;
border:1px solid silver;
}

#tbl1{
 margin-top:0px;
min-width:65%;
 text-align:center;
}

#tbltd1{
vertical-align: top;
margin-top:20px;
 height:400px;
background-color:white;
-moz-box-shadow: 0 0 5px -1px #000;
-webkit-box-shadow: 0 0 5px -1px #000;
box-shadow: 0 0 5px -1px #000;

}
#tbl1 td{
 text-align:left;

}
#tbl2{
 
 min-width:95%;
}


.tble2
{

border:0px solid silver;

}
#conf_panel{  

        width:250px;
        margin-top:200px;
        position:fixed; 
        top: 1px;  
        left: 450px;  
        text_align:center;
        
        -moz-box-shadow: 0 0 2px 2px #888;
        -webkit-box-shadow: 0 0 2px 2px#888;
         box-shadow: 0 0 2px 2px #888;
     
        background-color: white;  
      
        color: black;  
        display: none; 
        border:1px solid #C2DFFF; 

    }
.conf_tbl th{
  
    font-weight: bold;  
    color: white; 
    border:1px solid #D7D7D1;
    height:45px;
    border-collapse:collapse;

   

background: rgb(181,189,200); /* Old browsers */
background: -moz-linear-gradient(top, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,189,200,1)), color-stop(36%,rgba(130,140,149,1)), color-stop(100%,rgba(40,52,59,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* W3C */
//filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */

 }




.conf_tbl td{

    height:32px;
    border: 1px solid #A9A9A9;
  
  text-align:left;
    // font-size:4 px;  
    color: black; 
background: -moz-linear-gradient(top, rgba(246,248,249,1) 0%, rgba(229,235,238,0.94) 50%, rgba(215,222,227,0.94) 51%, rgba(233,237,240,0.91) 81%, rgba(245,247,249,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(246,248,249,1)), color-stop(50%,rgba(229,235,238,0.94)), color-stop(51%,rgba(215,222,227,0.94)), color-stop(81%,rgba(233,237,240,0.91)), color-stop(100%,rgba(245,247,249,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(246,248,249,1) 0%,rgba(229,235,238,0.94) 50%,rgba(215,222,227,0.94) 51%,rgba(233,237,240,0.91) 81%,rgba(245,247,249,1) 100%); /* W3C */
//filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f6f8f9', endColorstr='#f5f7f9',GradientType=0 ); /* IE6-9 */



 }

.conf_tbl input[type="text"]  {
   // padding: 0px 5px 0px 5px;
    border-style:none;
    border-color: white;//transparent;
    background-color: transparent;
   // font-size:12px;

}


</style>
<script>

/** code below for drag the confirmation div */
window.onload = function(){
    draggable('conf_panel');
};

var dragObj = null;
function draggable(id)
{
    var obj = document.getElementById(id);
    obj.style.position = "absolute";
    obj.onmousedown = function(){
            dragObj = obj;
    }
}

document.onmouseup = function(e){
    dragObj = null;
};

document.onmousemove = function(e){
    var x = e.pageX;
    var y = e.pageY;

    if(dragObj == null)
        return;

    dragObj.style.left = x +"px";
    dragObj.style.top= y +"px";
};
</script>


<?
	
       $re=mysqli_query($db,"select * from sparepurchase where grno='$inno' and brcode='$brcode' order by partcode");
	
     $irow=mysqli_fetch_array($re);
      


        
?>


<?php //include('includes/top.php'); ?>
<?php include('help_window.php'); ?>
<div align='left'><font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Purchase >>  invoice</font></div>
<body style="background-image:url(images/bg.jpg);" onload="document.getElementById('to_new_customer').focus();" >
    
<div id="pop2" class="pop-up2" >
  <div class="popBox2">

    <div class="popScroll2" id='popScroll2' >

    </div>
 
  </div>


  <a href="#links" class="lightbox"></a>
</div>
  





         <table class='tbl1' id='tbl1'  align='center'>
            
             <tr><td align='left' colspan='6'>
		<h1 style="font-size:20px;font-weight:bold;font-family:verdana;color:blue;margin:0px; padding:0px;">
		Item Purchase</h1></td></tr>
		
		<tr>
 



                
           <td style="text-align:right; width:250px; height:45px;"><a href="#login-box" class="login-window" style="text-decoration:none;"> <input  style="height:32px;width:110px;" value="Save" type="button" id='svbttn'></a></td></tr>
	
<tr><td id='tbltd1' colspan='6'>
<div>
 <fieldset style="border:2px solid grey; border-style:dotted;">
            <legend style="text-align:center;">Invoice</legend>
 <form id="jforms" name="invoice_form" >

    <table class='tbl2' id='tbl2' >

<input type=hidden name='porderno' value='<?print $pono?>'>
<input type=hidden name='taxtypett' value='<?print $taxtype?>'>
<tr><td align='left'>   Tax Type            
     </td>
<td id="to_new_registerTD">       
      <select name='taxtype' id="taxtype" class="taxtype" style='width:160px;border:1px solid grey; border-style:dotted;' onkeypress='return handleEnter(this, event)' onchange='showitmtype(this.value)'><option>-select-</option>	
<option value="VAT"<?php if ($irow[18] == 'VAT') echo ' selected="selected"'; ?>>VAT</option>
<option value="CST"<?php if ($irow[18] == 'CST') echo ' selected="selected"'; ?>>CST</option>
<option value="UNREG"<?php if ($irow[18] == 'UNREG') echo ' selected="selected"'; ?>>UNREG</option>


</select>
             
</td>
<td></td><td></td>
<td >
   Pur No # </td>                    
<td style="text-align:right;">
   <input id="invoice_number" name='invno' style="outline:none;border:1px solid grey; border-style:dotted; width:141px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;"   value="<? echo $irow[0];?>" type="text" readonly onKeydown="return handleEnter(this, event)" onfocus='sel(this.id)'>

</td></tr>
<tr>
<td align='left'>
</td>
<td id="to_new_customerTD">
<?
$slqry="SELECT supname from sup_master";
$slrs=mysqli_query($db,$slqry);

?>



 
    
 </td>
<td></td><td></td>
<td >   

   Entry Date</td>
  <td style="text-align:right;" class="invoiceForm_fromNameTD" id="invoice_dateTD">                
<input id="invoice_date" name="invdt" readonly  placeholder='Entry Date' style="width:141px;outline:none;border:1px solid grey; border-style:dotted; cursor:pointer;background: url(img/cal.gif) 120px 2px no-repeat; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;"  type=text  value="<? echo $irow[entrydate]; ?>" onKeydown="return handleEnter(this, event)">
<A HREF="#"  TITLE="Click for Calander" NAME="anchor1" ID="anchor1"></A>

  </td></tr>
<tr><td align='left'>  Supplier name             
     </td>
<td id="to_new_registerTD">       
     
<input  name='sup' style='width: 240px;border:1px solid grey; border-style:dotted;' placeholder='Supplier Name' type='text' id='supnm' value="<? echo $irow[2]?>" class='supnm' size="45" onkeypress="return handleEnter(this, event)">             
</td>
<td id="to_new_registerTDs">       
     
<input  name='supcode' style='width: 240px;border:1px solid grey; border-style:dotted;' placeholder='Supplier Name' type='hidden' id='supnmcode' value="<? echo $irow[1]?>" class='supnm' size="45" onkeypress="return handleEnter(this, event)">             
</td>

<td></td>
<td>Pur Bill No. #</td>
<td style="text-align:right;">
<input id="pbillno" name='pbillno' style="outline:none;border:1px solid grey; border-style:dotted; width:141px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;"   value="<? echo $irow[3] ?>" type="text" onKeydown="return handleEnter(this, event)" onfocus='sel(this.id)'>

</tr>
<tr>

    <td>GRNNo</td><td>
    <input id="grnno" name='grnno' placeholder='GRN No' style="outline:none;border:1px solid grey; border-style:dotted; width:141px; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;"   value="<? echo $irow[grno]; ?>" type="text" onKeydown="return handleEnter(this, event)" onfocus='sel(this.id)'>

</td>

<td></td><td></td>
<td >   

   Pur.Bill Date</td>
  <td style="text-align:right;" class="invoiceForm_fromNameTD" id="invoice_dateTD">                
<input id="supinvoice_date" name="supinvdt" style="width:141px;outline:none;border:1px solid grey; border-style:dotted; cursor:pointer; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;"  readonly  type=text  value="<?  ?>" onKeydown="return handleEnter(this, event)">
<A HREF="#"  TITLE="Click for Calander" NAME="anchor1" ID="anchor1"></A>

  </td>
</tr>

<tr><td colspan='6'>      
<input type="button" id='insrowbttn' onclick="insRow(event,this,this.id)" style="color:#6B6B6B;font-weight:bold;font-size:15px;" value="+">

<table border=1 id="myTable" class='tble1' width=100%>
<tr class='trcls'><td>No.</td><td>P Code</td><td>Name</td><td>Qty</td><td>Price</td><td>Before Taxamt</td>

<td>TAX%</td>
<td>Tax Amt</td><td>Total</td> <td>Item Type</td>    <td>Del</td></tr>
<?
     $result=mysqli_query($db,"select * from sparepurchase where grno='$inno' and brcode='$brcode' order by partcode");
$i=1;

while($row=mysqli_fetch_array($result))
{
 $itmres=mysqli_query($db,"select * from partmaster where partcode='$row[6]'");
 $prtrow=mysqli_fetch_array($itmres);

 $prres=mysqli_query($db,"select * from spareprmast where partcode='$row[6]' order by effectfrom desc");
 $prrow=mysqli_fetch_array($prres);

print "<tr bgcolor='white'; onMouseOver=bgColor='c1d7bb'; onMouseOut=bgColor='white'>\n<td>".$i."</td><td><input type=text readonly name='partcode[]' id='partcode$i'  class='partcode' value='$row[6]' size=10 autocomplete='off'></td><td>";
print "<input type=text readonly name='partname[]' id='partname$i' class='partname' value='$row[7]' autocomplete='off'></td>";

 print "\n<td align=center><input type=text readonly name='qty[]' class='qty' id='qty$i' size=4 value='$row[supqty]' onChange=calc(this.value,this,this.id) onKeydown='return handleEnter(this, event)'></td>";


 print "<td align=center><input class='unitprice' type=text  name='unitprice[]' id='unitprice$i' size=8 value='$row[price]' onChange=calc(this.value,this,this.id) onKeydown='return handleEnter(this, event)'></td>";

$maprice = $row[price] * $row[supqty];
 print "<td align=center><input class=right type=text   name='befrtxamt[]' id='befrtxamt$i' readonly size=8 value='$maprice' onKeydown='return handleEnter(this, event)'></td>";
 

 print "<td align=center><select class='vat' name='vat[]' id='vat$i'   onChange=calc(this.value,this,this.id) onKeydown='return handleEnter(this, event)'>
<option value=$row[tax]>$row[tax]</option>
 <option value=0.00>0.00</option>
  <option value=1.00>1.00</option>
   <option value=2.00>2.00</option>
 <option value=5.00>5.00</option>
 <option value=5.50>5.50</option>

 <option value=14.50>14.50</option>
 </select></td>";


$mtaxamt = round($maprice * 14.5/100,2);
 print "<td align=center><input class=right type=text   name='taxamt[]' id='taxamt$i' readonly size=4 value='$row[taxamt]' onChange=calc(this.value,this,this.id) onKeydown='return handleEnter(this, event)' onKeyup='insRow(event,this,this.id)'></td>";
 $mcessamt = 0;

$mtot = $row[tot];
 print "<td align=center><input class=right type=text   name='tot[]' id='tot$i' readonly size=12 value = '$mtot' onKeydown='return handleEnter(this, event)'></td>";
 print "<td><select id='itmtyp$i' name=itmtyp[]  class='itmtyp' onchange='showitmtype(this.value,this,this.id)' > ";
?>
<option value="Spares"<?php if ($row[itemtype] == 'Spares') echo ' selected="selected"'; ?>>Spares</option>
<option value="Lubricant"<?php if ($row[itemtype] == 'Lubricant') echo ' selected="selected"'; ?>>Lubricant</option>

 <?
 
 print "<td><input type='button' onClick='delrow(this)' class='del' id='del$i'></td></tr>";

 print"<script>cur++;</script>";
print"<script>cnt++;</script>";
$ntamt+=$mtot;
$i++;

}


?>
</table>
<table border=1 class='tble2' width=100%>
<tr>


<td colspan='5' style="text-align:right;">Net Total:</td>
<td><input style="border:0px solid white;  padding-right:5px;text-align:right; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly" name="nt_amt" id="nt_amt" value="<? echo $ntamt ?>" type="text"></td>
</tr>
 <tr>

<td colspan='5' style="text-align:right;">Hand Chrge	:</td>
<td><input style="outline:none;border:1px solid grey; border-style:dotted; text-align:right; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:black;" name="handling" id="handling" value="<? echo $irow[13] ?>" type="text" onKeyup="calc(this.value,this,this.id)" onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'></td>
</tr> 

  <tr>

<td colspan='5' style="text-align:right;">Discount	:</td>
<td><input style="outline:none;border:1px solid grey; border-style:dotted; text-align:right; padding-left:7px; font-weight:normal; font-family:verdana;font-size:13px;color:black;" name="discamt" id="discamt" value=0 type="text" onKeyup="calc(this.value,this,this.id)" onKeydown='return handleEnter(this, event)' onfocus='sel(this.id)'></td>
</tr> 


 
 <?
 $stotamt=$ntamt+$irow[13];
 ?>



<tr>

<td colspan='5' style="text-align:right;">
Net Amount:</td> 
<td>                
              
                <input style="border:0px solid white; width:100px; padding-right:5px; font-weight:normal;text-align:right; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly" name="sum_total" id="sum_total" value="<? echo $stotamt ?>" type="text">

</td></tr>

<tr>

<td colspan='5' style="text-align:right;">
Total:</td> 
<td>                
              
                <input style="border:0px solid white; width:100px; padding-right:5px; font-weight:normal;text-align:right; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly" name="sum_total1" id="sum_total1" value="<? echo round($stotamt,0) ?>" type="text">

</td></tr>

</table>
<script>
var cnt=1;
</script>

<div id="livesearch" style="display: inline-block;"></div>


<input type='hidden' name='brcode' id='brcode' value='<? print $brcode;?>'>
<input type='hidden' name='curqty' id='curqty' value='0'>
<input type='hidden' name='prtname' id='prtname' value='0'>
<input type='hidden' name='savecount' id='savecount' value='0'>
<div id='txtHint'></div>
<div id='partvalid'></div>

<div id='strtxt' style="visibility: hidden"></div>
<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>
</td></tr>
 


 </form>
  
</table>
   
</fieldset> 
</div>
</td></tr></table>
		

</body></html>
<script type="text/javascript">
function showitmtype111(str,r,itid)
{

var i=r.parentNode.parentNode.rowIndex;

   var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;
	var stvl;
	stvl=document.getElementById("itmvl"+id1).value;
	
	if(str=='D')
	{

 	document.getElementById("itmvl"+id1).style.visibility = "visible";
  	document.getElementById("itmvl"+id1).focus();
	

	}
    else 
	{
	
	document.getElementById("itmvl"+id1).style.visibility ="hidden";
	document.getElementById("qty"+id1).focus();
	
	
       
	}
   
 
}
</script>

<script type="text/javascript">

function itemclose_div(){
   var list = document.getElementsByClassName("itemalist");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('addsup_panel');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }
 function itemclose_div(){
   var list = document.getElementsByClassName("itemalist");
             for (var i = 0; i < list.length; i++) {
               list[i].style.display = 'none';
             }
    		var e = document.getElementById('aditem_panel');
   		 if(e.style.display == 'block') {
       		 e.style.display = 'none';
   		 } else {
        	e.style.display = 'none';
              }

 }
</script>


<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='';
  }

}
</script>
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/

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>
<script>
 gtt=0;
 function calc(str,r,qid)
 {
 
 var i=r.parentNode.parentNode.rowIndex;
     var tbl = document.getElementById('myTable');
     var id1=tbl.rows[i].cells[0].innerHTML;


 var amt=parseFloat(document.getElementById('qty'+id1).value)*parseFloat(document.getElementById('unitprice'+id1).value);

  document.getElementById('befrtxamt'+id1).value=parseFloat(amt).toFixed(2);

 var tx=parseFloat(document.getElementById('vat'+id1).value);
 var tax=((amt)*tx)/100;
 document.getElementById('taxamt'+id1).value=tax.toFixed(2);
 document.getElementById('tot'+id1).value=(amt+tax).toFixed(2);

   var k=0;
                 var ups = document.getElementsByName('tot[]'), sum = 0, k;
                  for(k = ups.length; k--;)
                      if(ups[k].value)
                            sum += parseFloat(ups[k].value, 10);
                  document.getElementById('nt_amt').value=sum.toFixed(2);
                  document.getElementById('sum_total').value=(parseFloat(document.getElementById('nt_amt').value)+parseFloat(document.getElementById('handling').value)).toFixed(2);
                  document.getElementById('sum_total1').value=(parseFloat(document.getElementById('nt_amt').value)+parseFloat(document.getElementById('handling').value)-parseFloat(document.getElementById('discamt').value)).toFixed(0);
                  
                  
}
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;
   for(q=1;q<rowCount;q++)
    {
     id1=tbl.rows[q].cells[0].innerHTML;
    
      ltot = document.getElementById("tot"+id1).value;
       sum3+= parseFloat(ltot);
            
    }
   document.getElementById('nt_amt').value=sum3.toFixed(2);
  var nttot= parseFloat(document.getElementById('nt_amt').value)+parseFloat(document.getElementById('handling').value);
    document.getElementById('sum_total').value=nttot.toFixed(2);
document.getElementById('sum_total1').value=nttot.toFixed(0);

 if(rowCount<=1)
 {
  document.getElementById('insrowbttn').type='button';
 }


cnt--;
     
 }
</script>
<script type="text/javascript">
function showitmtype(str)
{
	cells = document.getElementsByClassName("vat");	
	var xhr = [];	
	for (var i = 0; i < cells.length; i++)
        	{
                	var n=cells[i].parentNode.parentNode.rowIndex;                	
                        var tbl = document.getElementById('myTable');
                        var id1=tbl.rows[n].cells[0].innerHTML;
                        
                         (function (i)
                         	{
                         		xhr[i] = new XMLHttpRequest();  
                         		url = "chktxtp.php?itcd="+str;
                                //alert(url);
                                	xhr[i].open("GET", url, true);
                                	xhr[i].onreadystatechange = function () 
                                	{
                                		if (xhr[i].readyState == 4 && xhr[i].status == 200) 
                                		{
                                		document.getElementById("strtxt").innerHTML=xhr[i].responseText; 
                                		
                                		var s=i+1;
                                		
                                		document.getElementById("vat"+s).innerHTML=xhr[i].responseText;
                                		
                                		}
                			};
                			xhr[i].send();
            			})(i);	
			
		}
   
 
}
</script>
<?
//}
//else{print "<script>alert('You Have No permition...!!!');document.location='purchase_edit1.php';</script>";}
?>