<? 
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");
include("calstock.php");

$ulevel_qry=mysqli_query($db,"select level from bruser where username='$user' and brcode='$brcode'");

$u_level=mysqli_fetch_row($ulevel_qry);

$level=$u_level[0];

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>PSN Telcon</title>


<script type="text/javascript">
 

</script>

<style>

  #tbl td{
     
    border-collapse:collapse;
    border:1px solid grey;
    }

  #msg {
    height:80px auto;
    background-color:grey;
    padding:2px;
    margin-top:0px;
    border-bottom:5px solid white;
    border:5px solid #F8F8FF;
    width:150px auto;
    text_align:center;
    display: none;
    position: fixed; left: 600px; top: 0; 
    z-index: 10;
    opacity: 0.8;
    z-index: 999;
    color:white;
     }
 
  .show_hide {
    display:none;
    }


</style>



<script>
var ptnm=[];
var ptcd=[];
var st_ock=[];
var uprice1=[];
var uprice2=[];
var ndp=[];

var count=1;


  var rawTags;
   var inputField;
   var  initInputFieldValue;
   var dataList;
    var initNbVirgules ;


<?


 
$select=mysqli_query($db,"select * from $tbl2 where type='spares' and stock  >=1 ") or die("ERR6:".mysqli_error($db));

   $xxx="[";
 while($row=mysqli_fetch_array($select))
 
   {
        $xxx.='"'.$row[1].'",';

   
    }


  
   $xxx.="]"; ?>
rawTags=<?echo $xxx;?>;

 //rawTags = ["alf", "alfred", "alphonse", "bart", "batman", "calimero", "dora", "einstein", "jimmy", "joe dalton", "timo", "trollface", "william dalton", "pikachu"];


  function xx(str,event,this1)
  {


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

          if (keyCode == 37){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row-1].cells[5].getElementsByTagName("input")[0].focus();

	 }

     
 	if (keyCode == 38){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     //document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();

	 }

       
 	if (keyCode == 40){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     //document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();

	 }
 
              if (keyCode == 46){
                
			  var i=this1.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable').deleteRow(i);
					delrow(this1);
                                  document.getElementById('myTable').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			   
                       }


 inputField = document.getElementById(str);

 initInputFieldValue = inputField.value;
 dataList = document.getElementById('htmlListTags');

		if(keyCode!='40')
              {
                if(keyCode!='38')
              {
         

yy(str,event,this1); 


}
 


     }
 
 }
  function yy(str,event,this1) {
   


     initNbVirgules = (initInputFieldValue.match(/,/g)||[]).length;
     fillDatalist("",str,event,this1);
   } 
  
function fillDatalist(prefix,str,event,this1) {



	var nbRawList = rawTags.length;
       
	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}
	
	for (i=0; i < nbRawList; i++ ) {
		var nOpt = document.createElement("option");
		nOpt.value = prefix+rawTags[i];
		dataList.appendChild(nOpt);
	}

      var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
      var itemval=document.getElementById(str).value;
  
      if((keyCode=='13') &&(itemval!='')){
              
          var i=this1.parentNode.parentNode.rowIndex;
          var tbl = document.getElementById('myTable');
          var id1 =tbl.rows[i].cells[0].innerHTML;
          var pid ='partcode'+id1;
          var ptval= document.getElementById('partname'+id1).value;
          var quty = document.getElementById("qty"+id1).value;

   
    
         var act_stock=0;
         var a;
         for(a=1; a<count; a++){
            
          if(ptval==ptnm[a]){
           document.getElementById(pid).value=ptcd[a];
           document.getElementById('pur_rate'+id1).value=ndp[a];
           act_stock=st_ock[a];
             if(quty<5){
               document.getElementById('rate'+id1).value=uprice2[a];
             }
             else
               document.getElementById('rate'+id1).value=uprice1[a];
          }
       }

   var n=document.getElementById('myTable').rows.length;
   var m;
   var str1=0;
 
       for(m=1;m<n;m++){	
           
           var tbl1 = document.getElementById('myTable');
           var id2=tbl1.rows[m].cells[0].innerHTML;
           var part_pre = document.getElementById("partname"+id2).value;
           var qty_pre = document.getElementById("qty"+id2).value;
             
           if((ptval==part_pre)&&(id2!=id1)){
               str1=parseFloat(str1)+parseFloat(qty_pre);   
           }
       }

   var stk_bal=parseFloat(act_stock)-parseFloat(str1);
   document.getElementById('stok'+id1).value=stk_bal;
   
   

   check_stock();
   handleEnter(this1, event);  
     
   	
     }  
}

//mainLoop();

<?


$select=mysqli_query($db,"select * from $tbl2 where type='spares' and stock >=1 ") or die("ERR6:".mysqli_error($db));

   $xxx2="[";
 while($row=mysqli_fetch_array($select))
 
   {
        $xxx2.='"'.$row[0].'",';

   
    }


  
   $xxx2.="]"; ?>
rawTags2=<?echo $xxx2;?>;

 //rawTags = ["alf", "alfred", "alphonse", "bart", "batman", "calimero", "dora", "einstein", "jimmy", "joe dalton", "timo", "trollface", "william dalton", "pikachu"];


  function xx2(str,event,this1)
  {


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

          if (keyCode == 37){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row-1].cells[5].getElementsByTagName("input")[0].focus();

	 }

     
 	if (keyCode == 38){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     //document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();

	 }

       
 	if (keyCode == 40){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     //document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();

	 }
 
              if (keyCode == 46){
			  var i=this1.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable').deleteRow(i);
					delrow(this1);
                                  document.getElementById('myTable').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			   
                       }


 inputField = document.getElementById(str);

 initInputFieldValue = inputField.value;
 dataList = document.getElementById('htmlListTags');

		if(keyCode!='40')
              {
                if(keyCode!='38')
              {
         

yy2(str,event,this1); 


}
 


     }
 
 }
  function yy2(str,event,this1)
    {


     initNbVirgules = (initInputFieldValue.match(/,/g)||[]).length;
fillDatalist2("",str,event,this1);
    } 
  
function fillDatalist2(prefix,str,event,this1) {



	var nbRawList = rawTags2.length;
       
	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}
	
	for (i=0; i < nbRawList; i++ ) {
		var nOpt = document.createElement("option");
		nOpt.value = prefix+rawTags2[i];
		dataList.appendChild(nOpt);
	}

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

  
   var itemval=document.getElementById(str).value;


    if((keyCode=='13') &&(itemval!=''))
              {

   	 var i=this1.parentNode.parentNode.rowIndex;


   var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;
   var pid='partname'+id1;
   var ptval= document.getElementById('partcode'+id1).value;
   var quty = document.getElementById("qty"+id1).value;

       
       var act_stock=0;
       var a;
       for(a=1; a<count; a++){
            
          if(ptval==ptcd[a]){
           document.getElementById(pid).value=ptnm[a];
           document.getElementById('pur_rate'+id1).value=ndp[a];
           act_stock=st_ock[a];
           if(quty<5){
               document.getElementById('rate'+id1).value=uprice2[a];
             }
             else
               document.getElementById('rate'+id1).value=uprice1[a];
          }
       }

   var n=document.getElementById('myTable').rows.length;
   var m;
   var str1=0;
 
     for(m=1;m<n;m++){	
           
           var tbl1 = document.getElementById('myTable');
           var id2=tbl1.rows[m].cells[0].innerHTML;
           var part_pre = document.getElementById("partcode"+id2).value;
           var qty_pre = document.getElementById("qty"+id2).value;
             
           if((ptval==part_pre)&&(id2!=id1)){
               str1=parseFloat(str1)+parseFloat(qty_pre);   
           }
       }

   var stk_bal=parseFloat(act_stock)-parseFloat(str1);
   document.getElementById('stok'+id1).value=stk_bal;

   check_stock();

  handleEnter(this1, event); 
     
   }  
}

//mainLoop();


<?



$select1=mysqli_query($db,"select * from $tbl2 where type='labour' ") or die("ERR6:".mysqli_error($db));

   $xxx1="[";
 while($row1=mysqli_fetch_array($select1))
 
   {
        $xxx1.='"'.$row1[0].'",';

   
    }


  
   $xxx1.="]"; ?>
rawTags1=<?echo $xxx1;?>;

 //rawTags = ["alf", "alfred", "alphonse", "bart", "batman", "calimero", "dora", "einstein", "jimmy", "joe dalton", "timo", "trollface", "william dalton", "pikachu"];


  function xx1(str,event,this1)
  {


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


        if (keyCode == 37){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     document.getElementById('myTable2').rows[row-1].cells[5].getElementsByTagName("input")[0].focus();

	 }

     
 	if (keyCode == 38){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                     //document.getElementById('myTable2').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();

	 }

       
 	if (keyCode == 40){
                    var row=this1.parentNode.parentNode.rowIndex;
			 var col  =this1.parentNode.cellIndex ;
			 
                    // document.getElementById('myTable2').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();

	 }
           if (keyCode == 46){
			  var i=this1.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable2').deleteRow(i);
					delrow2(this1);
                                  document.getElementById('myTable2').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable2').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			   
                       }


 inputField = document.getElementById(str);

 initInputFieldValue = inputField.value;
 dataList = document.getElementById('htmlListTags');

		if(keyCode!='40')
              {
                if(keyCode!='38')
              {
         

yy1(str,event,this1); 


}
 


     }
 
 }
  function yy1(str,event,this1)
    {


     initNbVirgules = (initInputFieldValue.match(/,/g)||[]).length;
fillDatalist1("",str,event,this1);
    } 
  
function fillDatalist1(prefix,str,event,this1) {



	var nbRawList = rawTags1.length;
       
	while(dataList.childNodes.length > 0) {
		dataList.removeChild(dataList.childNodes[0]);
	}
	
	for (i=0; i < nbRawList; i++ ) {
		var nOpt = document.createElement("option");
		nOpt.value = prefix+rawTags1[i];
		dataList.appendChild(nOpt);
	}

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

  
   var itemval=document.getElementById(str).value;


    if((keyCode=='13') &&(itemval!=''))
              {


         //closingbal(itemval, this1, 'crcbal', 'myTable2');
         handleEnter2(this1, event);
         
   	
              }  
}

//mainLoop();



/** code below for down payment options  */
 function downpayment(){

    var e = document.getElementById('conf_panel');
    if(e.style.display == 'block') {
        e.style.display = 'none';
    } else {
        e.style.display = 'block';
    }
 }


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

 }



</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;
}
</style>

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="functions_est.js"></script>



<script>

var cur=1;
var partcode=[];
var partname=[];
var worktype=[];
var rate=[];
var qty=[];
var disc=[];
var hnd=[];
var gtot=[];
var exqty=[];
var typ=[];
var stok=[];
var assignto=[];
var cnt=1;
var day=[];
var month=[];
var year=[];
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 y=x.insertCell(1)	
var z=x.insertCell(2)	
var eng=x.insertCell(3);
var work=x.insertCell(4);
var ag=x.insertCell(5)
var z1=x.insertCell(6)	
var dis=x.insertCell(7)
var hnd=x.insertCell(8);
var tot=x.insertCell(9);
var qqty=x.insertCell(10);
var st=x.insertCell(11);
var asto=x.insertCell(12);
var dd1=x.insertCell(13);
var mm1=x.insertCell(14);
var yy1=x.insertCell(15);
var ndp=x.insertCell(16);
var dd=x.insertCell(17);

a.innerHTML=cur;
y.innerHTML="<input type=text name=partcode[] id=partcode"+cur+" size=20 class='partcode' onkeyup='xx2(this.id,event,this)'  autocomplete='off' list='htmlListTags'>"
z.innerHTML="<input type=text name=partname[] id=partname"+cur+" size=20 class='partname' onkeyup='xx(this.id,event,this)'  autocomplete='off' list='htmlListTags'>"
ag.innerHTML="<input type=text name='qty[]' id=qty"+cur+" size=2 value='0' onKeyup='qutychecking(this.value,this)' onKeydown='return handleEnter(this, event)'>";
z1.innerHTML="<input type=text  id='rate"+cur+"' name=rate[] size=3 class='rate' onKeyup='calctotal(this)' onKeydown='return handleEnter(this, event)'>"
dis.innerHTML="<input type=text name='disc[]' id=disc"+cur+" size=2 value='0' onKeyup='calctotal(this)' onKeydown='return handleEnter(this, event)'>";
hnd.innerHTML="<input type=text value='0.0' name='hnd[]' value='0' id=hnd"+cur+" size=2 onKeyup='calctotal(this)' onKeydown='return handleEnter(this, event)'>";
tot.innerHTML="<input type=text readonly value='total' name='gtot[]' id=gtot"+cur+" size=4 onKeydown='return handleEnter(this, event)'>";
qqty.innerHTML="<input type=text readonly name='exqty[]' id=exqty"+cur+" size=2 class='supqty' onKeydown='return handleEnter(this, event)'>";
st.innerHTML="<input type=text readonly name='stok[]' id=stok"+cur+" size=2 onKeydown='return handleEnter(this, event)'>";
ndp.innerHTML="<input type=text  id='pur_rate"+cur+"' name=pur_rate[] size=3 class='pur_rate' >"
var xv="";
xv="<select name='spareengineer[]' id=spareengineer"+cur+" onKeydown='return handleEnter(this, event)' style='width:80px;'><option>Orignial</option><option>Commercial</option><option>Used</option>\n";


eng.innerHTML=xv+"</select> ";
var xw="";
xw="<select name='worktype[]' id=worktype"+cur+" onKeydown='return handleEnter(this, event)' style='width:100px;'>\n";

<?
 
$qry2=mysqli_query($db,"select worktype from worktype_master");
 while($qry21=mysqli_fetch_row($qry2))
{
print "xw=xw+'<option>$qry21[0]</option>' \n";
}
?>
work.innerHTML=xw+"</select> ";
var va="";
va="<select name='assignto[]' id=assignto"+cur+" onKeydown='return handleEnter2(this, event)' style='width:100px;'><option></option>\n";

<?
 $empre1=mysqli_query($db,"select ename from empprofile where status!='releived' order by ename");
 while($emprow1=mysqli_fetch_row($empre1))
{
print "va=va+'<option>$emprow1[0]</option>' \n";
}
?>
asto.innerHTML=va+"</select> ";
dd1.innerHTML="<input type=text value='<?print date('d')?>' name='day[]' id=day"+cur+" size=1 onKeydown='return handleEnter(this, event)'>";
mm1.innerHTML="<input type=text value='<?print date('m')?>' name='month[]' id=month"+cur+" size=1 onKeydown='return handleEnter(this, event)'>";
yy1.innerHTML="<input type=text value='<?print date('Y')?>' name='year[]' id=year"+cur+" size=2 onKeyup='insRow(event,this,this.id)' ><input type=hidden  id='typ"+cur+"' name=typ[] value='x' readonly size=3 class='typ'   >";

dd.innerHTML="<input type='button'  onClick='delrow(this)' class='del' >";

document.getElementById("partcode"+cur).focus();
  cur++; 

cnt++;



var table = document.getElementById("myTable");
var row = table.rows[index];
console.log(secondRow.id);
}

if(keyCode == 13)
{

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



}// end function insrow





var cur2=1;
var cnt2=1;
var service=[];
var servamt=[];
var engineer1=[];
var serworktype=[];
var jobs=[];
var conv=[];
var sn=[];
var sa=[];
var rm=[];
var day1=[];
var month1=[];
var year1=[];
var lab_dis=[];
function insRow2(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('myTable2').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('myTable2').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('myTable2').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();
	
}


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



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

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


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

var a=x.insertCell(0)
var y=x.insertCell(1)
var job=x.insertCell(2)
var workt=x.insertCell(3);
var z=x.insertCell(4)	
var ds=x.insertCell(5)
var engs=x.insertCell(6)
var sn=x.insertCell(7);
var sa=x.insertCell(8);
var sb=x.insertCell(9);
var sc=x.insertCell(10);	
var rm=x.insertCell(11);
var dd3=x.insertCell(12);
var mm3=x.insertCell(13)	
var yy3=x.insertCell(14);
var dd2=x.insertCell(15);
a.innerHTML=cur2;
y.innerHTML="<input type=text name=service[] id=service"+cur2+" size=20 class='service' onkeyup='xx1(this.id,event,this)'  autocomplete='off' list='htmlListTags'>";
z.innerHTML="<input type=text name=servamt[] id=servamt"+cur2+" size=6 value='0' onkeyup='labtotal()' class='servamt' onKeydown='return handleEnter2(this, event)'>";
ds.innerHTML="<input type=text name=lab_dis[] id=lab_dis"+cur2+" size=6 value='0' onkeyup='labtotal()' class='servamt' onKeydown='return handleEnter2(this, event)'>";
dd2.innerHTML="<input type='button'  onClick='delrow2(this)' class='del' >";

var v="";
v="<select name='engineer1[]' id=engineer1"+cur+" onKeydown='return handleEnter2(this, event)' style='width:150px;'><option></option>\n";

<?
 $empre1=mysqli_query($db,"select ename from empprofile where status!='releived' order by ename");
 while($emprow1=mysqli_fetch_row($empre1))
{
print "v=v+'<option>$emprow1[0]</option>' \n";
}
?>
engs.innerHTML=v+"</select> ";

var vx="";
vx="<select name='jobs[]' id=jobs"+cur+" onKeydown='return handleEnter2(this, event)' style='width:80px;'><option>Change</option><option>Repair</option>\n";

job.innerHTML=vx+"</select> ";
var w="";
w="<select name='serworktype[]' id=serworktype"+cur+" onKeydown='return handleEnter2(this, event)' style='width:100px;'>\n";

<?
 
$qry1=mysqli_query($db,"select worktype from worktype_master ");
 while($qry11=mysqli_fetch_row($qry1))
{
print "w=w+'<option>$qry11[0]</option>' \n";
}
?>
workt.innerHTML=w+"</select> ";
dd3.innerHTML="<input type=text value='<?print date('d')?>' name='day1[]' id=day1"+cur+" size=2 onKeydown='return handleEnter2(this, event)'>";
mm3.innerHTML="<input type=text value='<?print date('m')?>' name='month1[]' id=month1"+cur+" size=2 onKeydown='return handleEnter2(this, event)'>";
yy3.innerHTML="<input type=text value='<?print date('Y')?>' name='year1[]' id=year1"+cur+" size=4 onKeyup='insRow2(event,this,this.id)'>";
sn.innerHTML="<input type=text name=subnm[] id=subnm"+cur2+" size=8 onKeydown='return handleEnter2(this, event)'>"
sa.innerHTML="<input type=text name=subamt[] id=subamt"+cur2+" size=6  onKeyup='chkval(this.value,this)' onKeydown='return handleEnter2(this, event)'>"
sb.innerHTML="<input type=text name=estmttm[] id=estmttm"+cur2+" size=12 value='<?print date('H:i:s') ?>'  onKeydown='return handleEnter2(this, event)'>"
sc.innerHTML="<input type=text name=cmpltm[] id=cmpltm"+cur2+" size=12  value='<?print date('H:i:s') ?>' onKeydown='return handleEnter2(this, event)'>"
rm.innerHTML="<input type=text name=rmk[] id=rmk"+cur2+" size=12 onKeydown='return handleEnter2(this, event)'>"

document.getElementById("service"+cur2).focus();
  cur2++; 

cnt2++;



var table = document.getElementById("myTable2");
var row = table.rows[index];
console.log(secondRow.id);
}

if(keyCode == 13)
{

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

} // end function insrow2


</script>



<link type="text/css" href="includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="css/form1.css" rel="stylesheet" />
<SCRIPT LANGUAGE="JavaScript" SRC="util/PopupWindow.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/AnchorPosition.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/date.js"></SCRIPT>

<script type="text/javascript">
			/*$(function() {
		
                                    $.datepicker.setDefaults( $.datepicker.regional[ "" ] );
                				$('#invoice_date').datepicker({ dateFormat: 'yy/mm/dd' } );
				$( "#customization_date_format" ).change(function() {
					$( "#invoice_date" ).datepicker( "option", "dateFormat", $( this ).val() );
				});
				$('#payment_due_date').datepicker({ dateFormat: 'yy/mm/dd' } );
				$( "#customization_date_format" ).change(function() {
					$( "#payment_due_date" ).datepicker( "option", "dateFormat", $( this ).val() );
				});
			});*/
var cal2 = new CalendarPopup();
cal2.showYearNavigation();

var cal3 = new CalendarPopup();
cal3.showYearNavigation();

var cal4 = new CalendarPopup();
cal4.showYearNavigation();

		</script>


<style>
.tble1 input {
background-color:transparent;
border: 0px solid;
height:20px;
//width:160px;
color:black;
}
.tble1
{
border-collapse:collapse;
border:1px solid silver;
margin-top:20px;
}	
.tble1 td, th
{
border-collapse:collapse;
border:1px solid silver;
}


#tbl1{
 margin-top:40px;
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{
 //margin:50px 20px 10px 20px;
 width:100%;
}
#tbl3{
 width:100%;
border-collapse:collapse;

}
#myTable{
width:100%;
border-collapse:collapse;

}
#myTable2{
width:100%;
border-collapse:collapse;
}
#myTable td,th{
border:1px solid grey;
}
#myTable2 td,th{
border:1px solid grey;
}
#tbl3 td,th{
border:1px solid grey;
}



  #conf_panel{  

        width:350px;
        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:25px;
    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:25px;
    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;

}


.acc  td
 {
background: #6bba70; /* Old browsers */
background: -moz-linear-gradient(top, #6bba70 0%, #6bba70 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6bba70), color-stop(100%,#6bba70)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #6bba70 0%,#6bba70 100%); /* IE10+ */
background: linear-gradient(to bottom, #6bba70 0%,#6bba70 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6bba70', endColorstr='#6bba70',GradientType=0 ); /* IE6-9 */
color:white;
 }

</style>


<?php
  $re=mysqli_query($db,"select max(invno) from invoice where brcode='$brcode' ");
//print "select max(invno) from invoice where brcode='$brcode' ";
     if(mysqli_num_rows($re)<1)
       {
           $inv=1; 
       }
       else
       {
        $row=mysqli_fetch_array($re);
         $inv=$row[0]+1;
        }
?>

<?php include('includes/top.php'); ?>
<body style="text-align: center;"  >

<div id="msg">
 <p align='right' ><a href="#" class="hide_show" ><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a></p>

  <div id='msgbox'></div>
</div>  

<div id="conf_panel" class="alist" style="display:none;">
 
<?
   
   $tot=0;

   $sql=mysqli_query($db,"select *  from down_payment where jcno='$jcno' and brcode='$brcode'");
 ?>
  <table  border='1' class='conf_tbl' style="border-collpase:collapse;background-color:white;  " width='100%'>
    <tr><th colspan=4> Down Payment  List Of RO:<? echo $jcno;?>&nbsp;&nbsp;&nbsp;<input type="button" value='X'  id='close'          
     onclick='close_div();'/></th></tr>

     <tr> <th> Dpr Id</th>  <th>Amt </th><th>Date </th><th>Journal No.</tr>
 <?
   $i=1;
   while($res=mysqli_fetch_array($sql))
   {
     if($res[6]>0)
         print "<tr class='acc' >";
     
    else
        print "<tr >";

     print " <td> $res[0]</td> <td align='right'> $res[4]</td><td> $res[5]</td><td> $res[6]</td></tr>";
     
     $tot+=$res[4];
  
     $i++;
   }
    
   if($i==1)
         print "<tr><td align='center' colspan=4>No data found...</td></tr>";
   else
         print "<tr><th align='right'  colspan=2>".putcoma($tot)."</th></th><th colspan=2></tr>";
?>  
  </table>


</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:#FFFFFD;margin:0px; padding:0px;">
		Jobcard</h1></td></tr>
		
		<tr>

             <td  style="text-align:right;"><input style="height:32px;width:110px;" value="Edit"  type="submit" onClick="window.open('editestimate1.php')">   
           <input style="height:32px;width:110px;" value="Print"  type="submit" onClick="window.open('printest1.php')">
          <a href="#" class='svbttn' id='svbttn1' style="text-decoration:none;"><input type='button' style="height:32px;width:110px;"  value='  Update form  ' name='upd' style="font-size:15; font-weight:bold" ></a>

<?
     if($show)
     {
       $res1=mysqli_query($db,"select work_status from gateentry where jcno='$jcno' and brcode='$brcode'");
         $jrow1=mysqli_fetch_array($res1);

        if($jrow1[0]=='TECHO')  
         {  
  ?>
<a href="#" class='svbttn' id='svbttn2' style="text-decoration:none;"><input type='button' style="height:32px;width:200px;"  value='Update form and Print Bill' name='updprn' style="font-size:15; font-weight:bold">
</a>
 <?

         }

      }
?>
  </td></tr>
	
<tr><td id='tbltd1' colspan='6'>

<div>
 <fieldset style="border:2px solid grey; border-style:dotted;">
            <legend style="text-align:center;">Jobcard</legend>

<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>
Select Jobcard No. <select name=jcno><option>--Select--</option>
<?
$re=mysqli_query($db,"select jcno,regno from gateentry where brcode='$brcode' and invno<=0 and work_status<>'NJD' order by jcno desc");
while($row=mysqli_fetch_row($re))
{
 print "<option value='$row[0]'>".(int)$row[0]."-$row[1]</option>";
}
?>
</select>
<input type=submit value='Show ->' name='show'>
</form>
<?
     if($show)
{
 $res=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode'");
 $jrow=mysqli_fetch_array($res);
?>  
 <form id="jforms" name="invoice_form" >
<input type='hidden' name='updprint' id='upd_flag' value='2'>

<table class='tbl2' id='tbl2'><tr><td style="width:100%;">
   <table border=1 id='tbl3'>
<h4>JCNo: <input type=text style='border:0px solid white;' readonly name='jcno' size=5 value='<?print $jcno;?>'></h4>
<tr><td>Date </td><td><input type=text readonly name='date' value= '<?print datetohtml($jrow[entrydate]);?>' size=8></td>
    <td>RegNo </td><td><input type=text readonly name='msno' value='<?print $jrow[regno];?>'  size=8></td>

	<td>Delivery Date</td><td><input type=text readonly name='dcomm' value='<?print datetohtml($jrow[estdate]);?>' size=8></td>
	<td>Model </td><td><input type=text readonly name='model' value='<?print $jrow[model];?>' size=8></td>
	<td>Owner </td><td><input type=text readonly name='cname' value='<?print $jrow[customer];?>'  size=8></td>
</tr>
<tr>	<td>Make </td><td><input type=text readonly name='stdate' value='<?print $jrow[vehiclename];?>'  size=8></td>
	<td>Ins type </td><td><input type=text readonly name='instype' value='<?print $jrow[instype];?>'  size=8></td>
	<td>Job Type </td><td><input type=text readonly name='wtstdate' value='<?print $jrow[jobtype];?>' size=8></td>
	<td>ReceivedBy </td><td><input type=text readonly name='wtyenddate' value='<?print $jrow[receivedby];?>' size=8></td>
	<td>KMS </td><td><input type=text readonly name='hmr' size=8 value='<?print $jrow[kms];?>'></td>

</tr>
<tr>
			<td>User </td><td><input type=text readonly name='user' value='<?print $user;?>' size=8></td>
<td>Entry Date </td><td colspan=3>
dd <input type=text readonly name='entrdate1' size=1 value='<?print date('d')?>'>
mm <input type=text readonly name='entrdate2' size=1 value='<?print date('m')?>'>
yy <input type=text readonly name='entrdate3' size=2 value='<?print date('Y')?>'>
</td>
<td>ChasisNO </td><td><input type=text name='chasisno' value='<?print $jrow[chasisno];?>'  size=8></td>

<td colspan=2> <input type='button' name='view_downpayment' value='View Down Payment' onclick='downpayment()' /> </td>


</tr>
</table>
</td></tr>

  <tr><td>
<h4>Parts Request </h4>

<input type="button" id='insrowbttn' onclick="insRow(event,this,this.id)" value=" Add Item ">
<table border=1  id="myTable" >


<th> No <th> Part Code<th> Part Name<th>Part type<th>Work type <th>Qty<th>Rate<th>Discount<th> Other<br>Charges<th>Total<th>Ref<th>Stock<th>Assigned to<th colspan=3>OrderDate<th>Purchase Rate<th>Delete


<?
$tbl="stockrepdet10".$brcode.$user;
mysqli_query($db,"delete from $tbl where supqty<=0 ");

 $res=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");

 $i=1;
 $j=1;
 $partot=0;
 while($jrow=mysqli_fetch_array($res))
  {
   $m=$j-1;
   $ptcode[$m]=$jrow[2];
   $quty[$m]=$jrow[qty];
   $totqty=0;
   $rr=mysqli_query($db,"select sum(qty) from jcardparts where partcode='$jrow[2]' and jcno='$jcno' and brcode='$brcode'");
   $rr1=mysqli_fetch_row($rr);
   
   $rr2=mysqli_query($db,"select stock from $tbl2 where partcode='$jrow[2]'");
   $rr3=mysqli_fetch_row($rr2);
   $stock=$rr3[0]+$rr1[0];
 
   $ptcd= $jrow[2];
   for($k=0;$k<$j;$k++){
       
       if(($ptcd==$ptcode[$k])&&($k!=$m)){
	   $totqty+=$quty[$k];
       }  
   } 
       
   $stock=$stock-$totqty; 
   $edate1=explode('-',$jrow[date]);

   print "<tr><td>".$i."</td>";
   print "<td><input type=text size=20 name='partcode[]' id='partcode$j' value='$jrow[2]' onkeyup='xx2(this.id,event,this)'  autocomplete='off' list='htmlListTags'></td>";
   print "<td><input type=text size=20 name='partname[]' id='partname$j' value='$jrow[3]' onkeyup='xx(this.id,event,this)'  autocomplete='off' list='htmlListTags'></td>";
   print "<td><select  id='spareengineer$j' name=spareengineer[]  style='width:80px;'  onKeydown='return handleEnter(this, event)' > <option>$jrow[engineer]</option>";
   print "<option>Orignial</option><option>Commercial</option><option>Used</option>";
   print "</select>  </td>";
   print "<td><select  id='worktype$j' name=worktype[]  style='width:100px;'  onKeydown='return handleEnter(this, event)' > <option>$jrow[worktype]</option>";
   
   $qry2=mysqli_query($db,"select worktype from worktype_master ");
   while($qry21=mysqli_fetch_row($qry2))
     {
       print "<option>$qry21[0]</option> \n";
     }
print "</select>  </td>";
  
 print "<td><input type=text size=2 name='qty[]' id='qty$j' value='$jrow[qty]' onKeyup='qutychecking(this.value,this)' onKeydown='return handleEnter(this, event)'></td>";

  print "<td><input type=text size=3  name='rate[]' id='rate$j' value='$jrow[rate]'  onKeyup='calctotal(this)' onKeydown='return handleEnter(this, event)'> </td>";
   print "<td><input type=text size=2 name='disc[]' id='disc$j' value='$jrow[disc]' onKeyup='calctotal(this)' onKeydown='return handleEnter(this, event)'></td>";


   print "<td><input type=text size=2 name='hnd[]' id='hnd$j' value='$jrow[hnd]' onKeyup='calctotal(this)' onKeydown='return handleEnter(this, event)'></td>";

   print "<td><input type=text readonly size=4 name='gtot[]' id='gtot$j' value='$jrow[gtot]' onKeydown='return handleEnter(this, event)'></td>";


 $qtres=mysqli_query($db,"select supqty from $tbl where partcode='$jrow[2]'");
 $qtrow=mysqli_fetch_row($qtres);
   $qqty=($qtrow[0]+$jrow[qty]);


   print "<td><input type=text  readonly name='exqty[]' id='exqty$j' value='$qqty' size=2 onKeydown='return handleEnter(this, event)'></td>";
   print "<td>   <input type=text readonly name='stok[]' value='".$stock."' id='stok$j' size=2 onKeydown='return handleEnter(this, event)'></td>";
   print "<td><select  id='assignto$i' name=assignto[]  style='width:100px;'  onKeydown='return handleEnter2(this, event)' > <option>$jrow[assignto]</option>";
   
 $empre1=mysqli_query($db,"select ename from empprofile where status!='releived' order by ename");
 while($emprow1=mysqli_fetch_row($empre1))
{
print "<option>$emprow1[0]</option> \n";
}
print "</select>  </td>";
    print "<td><input type=text   name='day[]' id='day$j' value='$edate1[2]' size=1 onKeydown='return handleEnter(this, event)'></td>";
    print "<td><input type=text   name='month[]' id='month$j' value='$edate1[1]' size=1 onKeydown='return handleEnter(this, event)'></td>";
    print "<td><input type=text   name='year[]' id='year$j' value='$edate1[0]' size=2 onKeyup='insRow(event,this,this.id)'></td>";
    print "<td><input type=text readonly size=4 name='pur_rate[]' id='pur_rate$j' value='$jrow[pur_rate]'></td>";
  
if($user=='vahid')
{
   if($level !='3')
	{
   	print "<td><input type=button class='del' onClick='delrow(this)'></td></tr>";
	}
}
else
{
   print "<td> No </td></tr>";
}
$partot+=$jrow[gtot];
   $i++;
   $j++;
print"<script>cur++;</script>";
print"<script>cnt++;</script>";

  }
?>
</table> 
</td></tr>
<tr><td>
<h4>Service Details </h4>
 <input type="button" id='insrowbttn2' onclick="insRow2(event,this,this.id)" value=" Add Service ">
<table border=1 id="myTable2" >
<th>No.<th>Service  <th>Repair/Replace<th>Work type<th>Amt<th>Disc <th>Assigned to<th>Sublet name <th>Sublet amt<th>Estimate Time<th>Completed Time<th>Remark<th colspan=3>EnteredOn<th>Delete

<?
 $res=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
 $servtot=0;
 $i=1;
 while($jrow=mysqli_fetch_array($res))


  {
$edate2=explode('-',$jrow[edate]);

   print "\n<tr><td>".$i."</td>";
   print "<td><input type=text size=20 name='service[]' id='service$i' value='$jrow[2]' onkeyup='xx1(this.id,event,this)'  autocomplete='off' list='htmlListTags'></td>";
   print "<td><select  id='jobs$i' name=jobs[]  style='width:80px;'  onKeydown='return handleEnter2(this, event)' > <option>$jrow[4]</option>";
print "<option>Change</option><option>Repair</option>";
print "</select>  </td>";
  print "<td><select  id='serworktype$i' name=serworktype[]  style='width:100px;'  onKeydown='return handleEnter2(this, event)' > <option>$jrow[worktype]</option>";
   
 $qry1=mysqli_query($db,"select worktype from worktype_master ");
 while($qry11=mysqli_fetch_row($qry1))
{
print "<option>$qry11[0]</option> \n";
}
print "</select>  </td>";
  print "\n<td><input type=text size=6 name='servamt[]' value='$jrow[3]' onkeyup='labtotal()' id='servamt$i' onKeydown='return handleEnter2(this, event)'  ></td>";
   
  print "\n<td><input type=text size=6 name='lab_dis[]' value='$jrow[18]' onkeyup='labtotal()' id='lab_dis$i' onKeydown='return handleEnter2(this, event)'  ></td>";

   print "<td><select  id='engineer1$i' name=engineer1[]  style='width:150px;'  onKeydown='return handleEnter2(this, event)' > <option>$jrow[engineer]</option>";
   
 $empre1=mysqli_query($db,"select ename from empprofile where status!='releived' order by ename");
 while($emprow1=mysqli_fetch_row($empre1))
{
print "<option>$emprow1[0]</option> \n";
}
print "</select>  </td>";

   print "<td><input type=text   name='subnm[]' id='subnm$i' value='$jrow[subnm]' size=8 onKeydown='return handleEnter2(this, event)' ></td>";
    print "<td><input type=text   name='subamt[]' id='subamt$i' value='$jrow[subamt]'  size=6 onKeyup='chkval(this.value,this)' onKeydown='return handleEnter2(this, event)' ></td>";
    print "<td><input type=text   name='estmttm[]' id='estmttm$i' value='$jrow[estmtm]' size=12 onKeydown='return handleEnter2(this, event)' ></td>";
      print "<td><input type=text   name='cmpltm[]' id='cmpltm$i' value='$jrow[comtm]' size=12 onKeydown='return handleEnter2(this, event)' ></td>";
    print "<td><input type=text   name='rmk[]' id='rmk$i' value='$jrow[rmk]' size=12 onKeydown='return handleEnter2(this, event)' ></td>";

    print "<td><input type=text   name='day1[]' id='day1$i' value='$edate2[2]' size=2 onKeydown='return handleEnter2(this, event)'></td>";
    print "<td><input type=text   name='month1[]' id='month1$i' value='$edate2[1]' size=2 onKeydown='return handleEnter2(this, event)'></td>";
    print "<td><input type=text   name='year1[]' id='year1$i' value='$edate2[0]' size=4 onKeyup='insRow2(event,this,this.id)'></td>";



if($level != '3')
{
   print "<td><input type=button class='del' onClick='delrow2(this)'></td>";
}
else
{
   print "<td>No</td>";
}
 
 print "</tr>";
 $tot=$jrow[3]-$jrow[18];

 $servtot+=$tot;
   $i++;
print"<script>cur2++;</script>";
print"<script>cnt2++;</script>";
  }
$ntot=$partot+$servtot;
?>
</table><br>

<datalist id="htmlListTags"></datalist>

<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='svflg' id='svflg' value='2'>
<div id='txtHint'></div>
<div id='partvalid'></div>
<div id='pstock'></div>

</td></tr>
<tr>   
<td  colspan='5' style="text-align:right;">
                      
                    Parts Total
                <input  style="border:0px solid white;text-align:right; width:100px; padding-right:5px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly" name="spare_total" id="spare_total" value=<? echo $partot; ?> type="text">
</td></tr>
<tr><td colspan='5' style="text-align:right;">
              Service Total
                <input  style="border:0px solid white;text-align:right; width:100px; padding-right:5px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly" name="labour_total" id="labour_total" value=<? echo $servtot; ?> type="text">
</td></tr>
<tr><td  colspan='5' style="text-align:right;">                  
              Total
                <input onclick="alert('The total is calculated automatically as soon as you have entered something into both the unit price and the quantity field in the lines above.\n\nExample: If you wish to invoice a service for $100.00, you should enter 100.00 in the unit price field and 1.00 in the quantity field.')" style="border:0px solid white;text-align:right; width:100px; padding-right:5px; font-weight:normal; font-family:verdana;font-size:13px;color:#3c3c3c;" readonly="readonly" name="sum_total" id="sum_total" value=<? echo $ntot; ?> type="text">

</td></tr>

<tr><td colspan='6'><hr></hr></td></tr>
<?
$res=mysqli_query($db,"select * from payment_mode  where  status='yes' order by mode");


?>

<tr><td colspan='5' style="text-align:right;"><b>Payment Mode:</b><select name='pmode' onchange="showtype(this.value)"><option>select</option>
<?
while($row=mysqli_fetch_array($res))
{
PRINT "<option >$row[1]</option>";
}
?>
</select>

 </form>

   </td></tr>
<tr><td colspan='5' style="text-align:right;"><b>Prepared By:</b><select name='pre_by' id='pre_by'><option>select</option>
<option>Rajesh</option>
<option>Abdul Vahid</option>
</td></tr>
</table>
   
</div>
</fieldset> 

</td></tr></table>
<?
}
$qry=mysqli_query($db,"select * from $tbl2");
$n=1;
while($qry1=mysqli_fetch_array($qry))
{
   $rr=mysqli_query($db,"select sum(qty) from jcardparts where partcode='$qry1[0]' and jcno='$jcno' and brcode='$brcode'");
   $rr1=mysqli_fetch_row($rr);
   $st_ock=$rr1[0]+$qry1[2];
   $rr2=mysqli_query($db,"select ndpcost from spareprmast where partcode='$qry1[0]' and brcode='$brcode'");
   $rr3=mysqli_fetch_row($rr2);
   $ndp=$rr3[0];
print "<script> ptnm[$n]='$qry1[1]';  </script>";
print "<script> ptcd[$n]='$qry1[0]'; </script>";
print "<script> st_ock[$n]='$st_ock'; </script>";
print "<script> uprice1[$n]='$qry1[3]'; </script>";
print "<script> uprice2[$n]='$qry1[4]'; </script>";
print "<script> ndp[$n]='$ndp'; </script>";
$n++;
print "<script> count++;</script>";
}
?>		


<?
$re=mysqli_query($db,"select * from jcardparts where brcode='$brcode'")or die('prt err:'.mysqli_error($db));
$i=1;

while($row=mysqli_fetch_array($re))
{
 

 print "\n<script> partname[$i]='$row[3]';</script> ";
 
 $i++;
}
?>
</body></html>