
<?
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");
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>World Wide Automotive Center</title>
   <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	
     <link type="text/css" href="css2/style1.css" rel="stylesheet" />
    
      <link type="text/css" href="css2/form1.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>

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

    <script type="text/javascript">








$(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 values1 = $("#jforms").serialize();
 

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

 

           	 if(parseInt(msg)!=0)    

          	  {

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

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

	 }); 
	 }); 


        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
	<script type="text/javascript">
    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            //$(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "110",
               width: "110",
              
            }, "fast");
        }, function() {
            // hover out
         //   $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "80",
                width: "80",
                
            }, "fast");
        });
        
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });




    </script>

<!-- js code below for active enter with textfield-->


<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>


<style>


body {
     background:blue;

  }


#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; }


#outPopUp{
     //position:absolute;
     width:800px;
     text-align:center;
    // height:300px;
    // z-index:15;
     //top:50%;
     //left:50%;
    // margin:-150px 0 0 -150px;
     //background:red;
}

</style>
<script src="css3-dropdown-menu-demo_files/bsa.js" async="" type="text/javascript"></script><script async="async" src="css3-dropdown-menu-demo_files/s_a5f348233fceef06ba365ab392938d10.js" id="_bsap_js_a5f348233fceef06ba365ab392938d10" type="text/javascript"></script><style id="bsa_css" type="text/css">.one{position:relative}.one .bsa_it_ad{display:block;padding:15px;border:1px solid #e1e1e1;background:#f9f9f9;font-family:helvetica,arial,sans-serif;line-height:100%;position:relative}.one .bsa_it_ad a{text-decoration:none}.one .bsa_it_ad a:hover{text-decoration:none}.one .bsa_it_ad .bsa_it_t{display:block;font-size:12px;font-weight:bold;color:#212121;line-height:125%;padding:0 0 5px 0}.one .bsa_it_ad .bsa_it_d{display:block;font-size:11px;color:#434343;font-size:12px;line-height:135%}.one .bsa_it_ad .bsa_it_i{float:left;margin:0 15px 10px 0}.one .bsa_it_p{display:block;text-align:right;position:absolute;bottom:10px;right:15px}.one .bsa_it_p a{font-size:10px;color:#666;text-decoration:none}.one .bsa_it_ad .bsa_it_p a:hover{font-style:italic}</style></head>
<body >



<table id='outPopUp' style="width:800px; margin:0 auto;"><tr><td>
<br>
<table class="container" ><tr><td>

	<link type="text/css" href="css/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
		<script type="text/javascript" src="css/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="css/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript">
$(function(){

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

$partcode = $(this);

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

		$.ajax({
			url: "search4.php",
			dataType: "json",
			data: "key="+$partcode.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {
					return {
						label: item.partcode+' | '+  item.partname + '| '+ item.supqty +'|'+item.price    ,
						value: item.partcode,
						name:item.partname,
						qty:item.supqty,
						price:item.price,

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

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

					
});




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

$partcode = $(this);

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

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

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

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

					
});



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

$service = $(this);

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

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


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

	$row.find('.service').val(ui.item.value);
	$row.find('.servamt').val(ui.item.code);
	
	/*log( ui.item ?
	"Selected: " + ui.item.label :
	"Nothing selected, input was " + this.value);
	*/
	 }
	
	});

					
});



});
</script>







<?php echo "<body onload='f1.entrydate.focus()'>\n"; ?>

<link href="css1/xp1.css" type="text/css" rel="stylesheet" media="print,screen"  />


<?

print 'Branch Code:'.$brcode;
$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
$kar=mysqli_fetch_array($ker);
?>
<script>



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




var cur=1;
var cnt=1;
var partcode=[];
var partname=[];
var lstprice=[];
var handp=[];
var conv=[];
var discar=[];
var cessar=[];
var depc=[];
var exq=[];
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 n=document.getElementById('myTable').rows.length-1;
  var m;
   var str1=0;
   var str2=0;
   var str3=0;
   var str4=0;
    for(m=1;m<=n;m++)	
     {
      var tbl1 = document.getElementById('myTable');
      var id2=tbl1.rows[m].cells[0].innerHTML;
 

      var prttot = document.getElementById("gtot"+id2).value;
      var prtdept = document.getElementById("depc"+id2).value;
      var prtntot = document.getElementById("nett"+id2).value;
      var typ = document.getElementById("spareengineer"+id2).value;
      var servtot = document.getElementById("servamt"+id2).value;
      
      
      str1=parseFloat(str1)+parseFloat(prttot); 
       str4=parseFloat(str4)+parseFloat(servtot);
 
if(typ=='Original')
    {
      str2=parseFloat(str2)+parseFloat(prtdept); 
     }
      str3=parseFloat(str3)+parseFloat(prtntot);  
        
     } 
     document.getElementById("gtot_p").innerHTML= parseFloat(str1).toFixed(2);
     document.getElementById("dpc").innerHTML= parseFloat(str2).toFixed(2);
     document.getElementById("ntot_p").innerHTML= parseFloat(str3).toFixed(2);
     document.getElementById("gtot_l").innerHTML= parseFloat(str4).toFixed(2);



   

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

function insRow(event,i1,id2)
{

var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
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 ag=x.insertCell(4)
var z1=x.insertCell(5)
var rpr=x.insertCell(6)

var bm=x.insertCell(7)
var dep=x.insertCell(8)
	
var dis=x.insertCell(9)
var hnd=x.insertCell(10);
var tot=x.insertCell(11);
var samt=x.insertCell(12)
var qqty=x.insertCell(13);
var nt=x.insertCell(14);

var dd=x.insertCell(15);

a.innerHTML=cur;
y.innerHTML="<input type=text readonly name=partcode[] id=partcode"+cur+"  class='partcode' size=20 onKeyPress='return handleEnter(this, event)'>";
z.innerHTML="<input type=text name=partname[] id=partname"+cur+" size=20 class='partname' onKeyPress='return handleEnter(this, event)'>"
ag.innerHTML="<input type=text name='qty[]' id=qty"+cur+" value='0' size=3 onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'>";
z1.innerHTML="<input type=text  id='rate"+cur+"' value='0'  name=rate[] size=10 class='rate' onkeyup=caltotal(this,this.value,this.id) onKeyPress='return handleEnter(this, event)'>";

var reprp="";
reprp="<select name='jobs[]' id=jobs"+cur+" onKeyPress='return handleEnter(this, event)' ><option>Change</option><option>Repair</option>\n";
rpr.innerHTML=reprp+"</select> ";

var bomc="";
bomc="<select name='bom[]' id='bom$i' value='$jrow[bom]' onchange='chkorginal(this,this.value)' onKeyPress='return handleEnter(this, event)'><option>B</option><option>M</option>\n";
bm.innerHTML=bomc+"</select> ";
var depcct="";
depcct="<select name='depr[]' id='depr$i' value='$jrow[depr]' onchange='chkorginal(this,this.value)' onKeyPress='return handleEnter(this, event)'><option>D</option><option>-</option>\n";
dep.innerHTML=depcct+"</select> ";
samt.innerHTML="<input type=text  id='servamt"+cur+"' value='0'  name=servamt[] size=10 onkeyup=caltotal(this,this.value,this.id) onKeyPress='return handleEnter(this, event)'>";

dis.innerHTML="<input type=text name='disc[]' value='0' id=disc"+cur+" size=6 onkeyup='chkorginal(this,this.value)' onKeyPress='return handleEnter(this, event)'>";
hnd.innerHTML="<input type=text value='0.0'  value='0' name='hnd[]' id=hnd"+cur+" size=3 onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'>";
tot.innerHTML="<input type=text readonly  name='gtot[]'  value='0' id=gtot"+cur+" size=8 onKeyPress='return handleEnter(this, event)'>";
qqty.innerHTML="<input type=text  name='depc[]'  value='0' id=depc"+cur+" size=3 class='supqty' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'>";
nt.innerHTML="<input type=text readonly value='0'  value='0' name='nett[]' id=nett"+cur+" size=8 onKeyPress='insRow(event,this,this.id)' >";
var xv="";
xv="<select name='spareengineer[]' id=spareengineer"+cur+" onKeyPress='return handleEnter(this, event)' onchange='chkorginal(this,this.value)'><option>Original</option><option>Commercial</option><option>Used</option>\n";


eng.innerHTML=xv+"</select> ";

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

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

cnt++;



}

else
{
var tbl = document.getElementById('myTable');
   var id3=tbl.rows[i3].cells[0].innerHTML;
if(keyCode==13)
{

document.getElementById("partcode"+id3).focus();
}
}


}// end function insrow

function setval(x)
{
 var ele1='partname'+(cur-1);
 var ele2='rate'+(cur-1);
 var hand='hnd'+(cur-1);
 var cpele='cessp'+(cur-1);
 var disele='disc'+(cur-1);
 var cessele='cessp'+(cur-1);
 var qqtyele='exqty'+(cur-1);
 var qele='qty'+(cur-1)

 document.getElementById(qele).value=0;
 document.getElementById(ele1).value=partname[x-1];
 document.getElementById(ele2).value=lstprice[x-1];
 document.getElementById(hand).value=handp[x-1];
 document.getElementById(cpele).value=conv[x-1];
 document.getElementById(disele).value=discar[x-1];
<?
if($kar[0]!='Kerala') 
{
?>
 document.getElementById(cessele).value=0; //cessar[x-1];
<?
}
else
{
?>
 document.getElementById(cessele).value=0; //cessar[x-1];
<?
}
?>
 document.getElementById(qqtyele).value=exq[x-1];

}
function calcamt(y)
{y--;
 var ele2='rate'+(y);
 var qele='qty'+y;  
 var amtele='amt'+y;
 var disele='disc'+y;
 var handele='hnd'+y;
 var vatele='vat'+y;
 var taxele='taxamt'+y;
 var cessele='cesamt'+y;
 var cesspele='cessp'+y;
 var gtotele='gtot'+y;
 var qqtyele='exqty'+y;
handamt=0;
vatamt=0;

 var exisqty=parseFloat(document.getElementById(qqtyele).value);
 
 var qty=parseFloat(document.getElementById(qele).value);
 if(qty>exisqty)
 {
  alert('Insufficient Quantity');
 document.getElementById(qele).value=0;
 document.getElementById(amtele).value=0;

 // return;
 }
 var rate=document.getElementById(ele2).value;
 var amount=parseFloat(qty)*parseFloat(rate);
 var discp=parseFloat(document.getElementById(disele).value);
 if(discp>0)
 {
   disamt=discp;
   amount-=disamt;
 }
//document.getElementById(amtele).value=amount.toFixed(2);
handp=parseFloat(document.getElementById(handele).value);
if(handp>0)
 handamt=handp;
amt1=(amount+handamt);
 
document.getElementById(gtot).innerHTML=amt1;
}
//***********************************


function chkdigit(val,id1)
{
if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id1).value='0.00';
   document.getElementById(id1).select();
  }
}



function chkorginal(r,val)

 {
  
var i=r.parentNode.parentNode.rowIndex;
var handamt=0;
var vatamt=0;
var amt1=0;
 var amount=0;
 var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;

    var rate=document.getElementById('rate'+id1).value;
    var qty=document.getElementById('qty'+id1).value;
    var otherch=document.getElementById('hnd'+id1).value;
     var disc=document.getElementById('disc'+id1).value;
     
     var depct=document.getElementById('dep').value;

     var srvamt=document.getElementById('servamt').value;

     var ptot=parseFloat(((qty*rate)-disc))+parseFloat(otherch);
    var typ1 = document.getElementById("spareengineer"+id1).value;

     var depc_amt=0;
 
    if(depct>0)
     {
     if(typ1=='Original')
      {
     depc_amt=ptot*depct/100;
     }
    }
   var nettot=ptot-depc_amt+srvamt;


  document.getElementById('gtot'+id1).value=ptot;
  document.getElementById('depc'+id1).value=depc_amt;
  document.getElementById('nett'+id1).value=nettot;


  var n=document.getElementById('myTable').rows.length-1;
  var m;
   var str1=0;
   var str2=0;
   var str3=0;
   var str4=0; 
    for(m=1;m<=n;m++)	
     {
      var tbl1 = document.getElementById('myTable');
      var id2=tbl1.rows[m].cells[0].innerHTML;
 

      var prttot = document.getElementById("gtot"+id2).value;
      var prtdept = document.getElementById("depc"+id2).value;
      var prtntot = document.getElementById("nett"+id2).value;
     var typ = document.getElementById("spareengineer"+id2).value;
     var servtot = document.getElementById("servamt"+id2).value;

      str1=parseFloat(str1)+parseFloat(prttot); 
       str4=parseFloat(str4)+parseFloat(servtot); 

   if(typ=='Original')
      {
      str2=parseFloat(str2)+parseFloat(prtdept); 
      }
      str3=parseFloat(str3)+parseFloat(prtntot);  
        
     } 
     document.getElementById("gtot_p").innerHTML= parseFloat(str1).toFixed(2);
    document.getElementById("dpc").innerHTML= parseFloat(str2).toFixed(2);
    document.getElementById("ntot_p").innerHTML= parseFloat(str3).toFixed(2);
    document.getElementById("gtot_l").innerHTML= parseFloat(str4).toFixed(2);


 }



function caltotal(r,val,id4)

 {
if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id4).value='0';
   document.getElementById(id4).focus();
  
  }
              
var i=r.parentNode.parentNode.rowIndex;
var handamt=0;
var vatamt=0;
var amt1=0;
 var amount=0;
 var tbl = document.getElementById('myTable');
   var id1=tbl.rows[i].cells[0].innerHTML;

    var rate=document.getElementById('rate'+id1).value;
    var qty=document.getElementById('qty'+id1).value;
    var otherch=document.getElementById('hnd'+id1).value;
     var disc=document.getElementById('disc'+id1).value;
    var srvamt=document.getElementById('servamt'+id1).value;
     
     var depct=document.getElementById('dep').value;

     var ptot=parseFloat(((qty*rate)-disc))+parseFloat(otherch);
    var typ1 = document.getElementById("spareengineer"+id1).value;

     var depc_amt=0;
 
    if(depct>0)
     {
     if(typ1=='Original')
      {
     depc_amt=ptot*depct/100;
     }
    }
   var nettot=ptot-depc_amt+parseFloat(srvamt);


  document.getElementById('gtot'+id1).value=ptot;
  document.getElementById('depc'+id1).value=depc_amt;
  document.getElementById('nett'+id1).value=nettot;


  var n=document.getElementById('myTable').rows.length-1;
  var m;
   var str1=0;
   var str2=0;
   var str3=0;
   var str4=0;

    for(m=1;m<=n;m++)	
     {
      var tbl1 = document.getElementById('myTable');
      var id2=tbl1.rows[m].cells[0].innerHTML;
 

      var prttot = document.getElementById("gtot"+id2).value;
      var prtdept = document.getElementById("depc"+id2).value;
      var prtntot = document.getElementById("nett"+id2).value;
     var typ = document.getElementById("spareengineer"+id2).value;
       var servtot = document.getElementById("servamt"+id2).value;

      str1=parseFloat(str1)+parseFloat(prttot); 
      str4=parseFloat(str4)+parseFloat(servtot); 

   if(typ=='Original')
      {
      str2=parseFloat(str2)+parseFloat(prtdept); 
      }
      str3=parseFloat(str3)+parseFloat(prtntot);  
        
     } 
     document.getElementById("gtot_p").innerHTML= parseFloat(str1).toFixed(2);
    document.getElementById("dpc").innerHTML= parseFloat(str2).toFixed(2);
    document.getElementById("ntot_p").innerHTML= parseFloat(str3).toFixed(2);
    document.getElementById("gtot_l").innerHTML= parseFloat(str4).toFixed(2);



     
     }




function caltotal2(val,id4)

 {
if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id4).value='0';
   document.getElementById(id4).focus();
  
  }
 if(val>100)
  {
  alert('Invalid Amount');
  document.getElementById(id4).value='0';
   document.getElementById(id4).focus();
  
  }  

    var n=document.getElementById('myTable').rows.length-1;
  var m;
   var str1=0;
   var str2=0;
   var str3=0;
     var str4=0;
    for(m=1;m<=n;m++)	
     {

      var tbl1 = document.getElementById('myTable');
      var id2=tbl1.rows[m].cells[0].innerHTML;


    var rate=document.getElementById('rate'+id2).value;
    var qty=document.getElementById('qty'+id2).value;
    var otherch=document.getElementById('hnd'+id2).value;
     var disc=document.getElementById('disc'+id2).value;
     
     var depct=document.getElementById('dep').value;

     var ptot=parseFloat(((qty*rate)-disc))+parseFloat(otherch);
     var typ = document.getElementById("spareengineer"+id2).value;
   //alert (typ);
     var depc_amt=0;
    if(depct>0)
     {
     //alert (typ);
       if(typ=='Original')
       {
     // alert (typ);
    //alert (id2);
     depc_amt=ptot*depct/100;
       }
      }
   var nettot=ptot-depc_amt;


  document.getElementById('gtot'+id2).value=ptot;
  document.getElementById('depc'+id2).value=depc_amt;
  document.getElementById('nett'+id2).value=nettot;

      var prttot = document.getElementById("gtot"+id2).value;
      var prtdept = document.getElementById("depc"+id2).value;
      var prtntot = document.getElementById("nett"+id2).value;
      var servtot = document.getElementById("servamt"+id2).value;

      str1=parseFloat(str1)+parseFloat(prttot); 
      str4=parseFloat(str4)+parseFloat(servtot); 
   if(typ=='Original')
      {
      str2=parseFloat(str2)+parseFloat(prtdept); 
      }
      str3=parseFloat(str3)+parseFloat(prtntot);  
        
     } 
     document.getElementById("gtot_p").innerHTML= parseFloat(str1).toFixed(2);
    document.getElementById("dpc").innerHTML= parseFloat(str2).toFixed(2);
    document.getElementById("ntot_p").innerHTML=parseFloat(str3).toFixed(2);
     document.getElementById("gtot_l").innerHTML=parseFloat(str4).toFixed(2);




     
     }


function calservamt(r,val,id4)
  
{
 if(isNaN(val))
  {
  alert('Enter Number');
  document.getElementById(id4).value='0';
   document.getElementById(id4).focus();
  
  }

 var n=document.getElementById('myTable2').rows.length-1;
  var m;
   var str1=0;
   var str2=0;
   var str3=0;
  
    for(m=1;m<=n;m++)	
     {
      var tbl1 = document.getElementById('myTable2');
      var id2=tbl1.rows[m].cells[0].innerHTML;
 

      var prttot = document.getElementById("servamt"+id2).value;
      
      str1=parseFloat(str1)+parseFloat(prttot); 
      
        
     } 
     document.getElementById("stot").innerHTML= parseFloat(str1).toFixed(2);




}







function calcamt2(y)
{//y--; 

 var ele2='rate'+(y);
 var qele='qty'+y;
 var amtele='amt'+y;
 var disele='disc'+y;
 var handele='hnd'+y;
 var gtotele='gtot'+y;
 var qqtyele='exqty'+y;
handamt=0;
vatamt=0;

 var qty=document.getElementById(qele).value;
 var exqty2=document.getElementById(qqtyele).value;

 var rate=document.getElementById(ele2).value;
 var amount=parseFloat(qty)*parseFloat(rate);
 var discp=parseFloat(document.getElementById(disele).value);
 if(discp>0)
 {
   disamt=discp;
   amount-=disamt;
 }
//document.getElementById(amtele).value=amount.toFixed(2);
handp=parseFloat(document.getElementById(handele).value);
if(handp>0)
 handamt=handp;
amt1=(amount+handamt);

document.getElementById(gtotele).value=amt1.toFixed(2);
}

//**********************************
var cur2=1;
var cnt2=1;
var service=[];
var servamt=[];
var engineer1=[];
var jobs=[];
var day1=[];
var month1=[];
var year1=[];
function delrow2(r)
{
 var i=r.parentNode.parentNode.rowIndex;




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

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

 var n=document.getElementById('myTable2').rows.length-1;
  var m;
   var str1=0;
   var str2=0;
   var str3=0;
  
    for(m=1;m<=n;m++)	
     {
      var tbl1 = document.getElementById('myTable2');
      var id2=tbl1.rows[m].cells[0].innerHTML;
 

      var prttot = document.getElementById("servamt"+id2).value;
      
      str1=parseFloat(str1)+parseFloat(prttot); 
      
        
     } 
     document.getElementById("stot").innerHTML= parseFloat(str1);


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


function insRow2(event,i1,id2)
{

var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
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;
  }
 

		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 z=x.insertCell(3)	


var engs=x.insertCell(4)
var dd3=x.insertCell(5);
var mm3=x.insertCell(6)	
var yy3=x.insertCell(7);
var dd2=x.insertCell(8);
a.innerHTML=cur2;
y.innerHTML="<input type=text name=service[] id=service"+cur2+" size=30 class='service' onKeyPress='return handleEnter(this, event)'>"
z.innerHTML="<input type=text name=servamt[] id=servamt"+cur2+" size=8 onkeyup='calservamt(this,this.value,this.id)' class='servamt' onKeyPress='return handleEnter(this, event)'>";


dd2.innerHTML="<input type=button value='Del' onClick='delrow2(this)'>";
var v="";
v="<select name='engineer1[]' id=engineer1"+cur2+" onKeyPress='return handleEnter(this, event)'><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+" onKeyPress='return handleEnter(this, event)'><option>Change</option><option>Repair</option>\n";

job.innerHTML=vx+"</select> ";

dd3.innerHTML="<input type=text value='<?print date('d')?>' name='day1[]' id=day"+cur2+" size=2 onKeyPress='return handleEnter(this, event)'>";
mm3.innerHTML="<input type=text value='<?print date('m')?>' name='month1[]' id=month"+cur2+" size=2 onKeyPress='return handleEnter(this, event)'>";
yy3.innerHTML="<input type=text value='<?print date('Y')?>' name='year1[]' id=year"+cur2+" size=4 onKeyPress='insRow2(event,this,this.id)' >";




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

cnt2++;



}

else
{
var tbl = document.getElementById('myTable2');
   var id3=tbl.rows[i3].cells[0].innerHTML;
if(keyCode==13)
{
//alert (id3) ;
document.getElementById("service"+id3).focus();
}
}
} // end function insrow2





function handleEnter (field, event,val) {
                         if(val!=''){
		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;
          } 
	}      





var cate=[];
var wrkavg=[];
var workamt=[];
var wrkavg=[];
var staff=[];
var day2=[];
var month2=[];
var year2=[];


var e_hr=[];
var e_mt=[];
var c_hr=[];
var c_mt=[];


var cnt3=1;
var cur3=1;
function insRow3(event,i1,id2)
{

if(id2!="insrowbttn3")
  {
   var i2=i1.parentNode.parentNode.rowIndex;
   var i3=parseFloat(i2)+parseFloat(1);
   var rowCounts = document.getElementById('myTable3').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))||(cnt3==1))
 {
var rowCount = document.getElementById('myTable3').rows.length;
var rowcount1=parseFloat(rowCount)+parseFloat(1);
//alert(rowCount);
var x=document.getElementById('myTable3').insertRow(rowCount);


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

var a=x.insertCell(0)
var y=x.insertCell(1)
var wrk=x.insertCell(2)
var z=x.insertCell(3)

var est_time=x.insertCell(4)	
var cmp_time=x.insertCell(5)

	
var emps=x.insertCell(6)
var dd3=x.insertCell(7);
var mm3=x.insertCell(8)	
var yy3=x.insertCell(9);
var dd2=x.insertCell(10);

a.innerHTML=cur3;



var u="";
u="<select name=cate[] id=cate"+cur3+" onKeyPress='return handleEnter(this, event,this.value)'><option></option>\n";

<?
$res=mysqli_query($db,"select * from workshop_category  where brcode='$brcode' and status='yes' order by category");
while($row=mysqli_fetch_array($res))
{

print "u=u+'<option>$row[1]</option>' \n";
}
?>
y.innerHTML=u+"</select> ";



wrk.innerHTML="<input type=text name=wrkavg[] id=wrkavg"+cur3+" size=8 onKeyPress='return handleEnter(this, event,this.value)' onkeyup='workshopamt(this.value,this)' >";


 z.innerHTML="<input type=text size=8 readonly name='workamt[]' onKeyPress='return handleEnter(this, event,this.value)' value='0' id=workamt"+cur3+" >";




var uu="";

 uu="<select name='e_hr[]' onKeyPress='return handleEnter(this, event,this.value)' id=e_hr"+cur3+" style='width:40px' onchange='test(this.value)'>\n";
              <?
   		$jj=0;
   		$kk=0;
  	 for($jj=0;$jj<50;$jj++)
     		 {
        		 $m=$jj*60;
         		print "uu=uu+'<option value=$m>$jj</option>' \n"; 
      		}
          
               ?> 
               uu=uu+"</select> ";
    



	 uu=uu+ "<b>:</b> <b>mm</b><select name='e_mt[]' onKeyPress='return handleEnter(this, event,this.value)' id=e_mt"+cur3+" style='width:40px'>\n";
          <?
 	   for($kk=0;$kk<60;$kk++)
     		 {
         		$m=$kk*60;
          		print "uu=uu+'<option>$kk</option>' \n"; 
     		 }
                  ?>
   		est_time.innerHTML=uu;

var w="";

  w="<b>Hr</b><select name='c_hr[]' onKeyPress='return handleEnter(this, event,this.value)' id=c_hr"+cur3+" style='width:40px'>\n";
              <?
   		$jj=0;
   		$kk=0;
  	 for($jj=0;$jj<50;$jj++)
     		 {
        		 $m=$j*60;
         		print "w=w+'<option value=$m>$jj</option>' \n"; 
      		}
          
               ?> 
               w=w+"</select> ";
    
  		
		 w=w+ "<b>:</b> <b>mm</b><select name='c_mt[]' onKeyPress='return handleEnter(this, event,this.value)' id=c_mt"+cur3+" style='width:40px'>\n";
          <?
 	   for($kk=0;$kk<60;$kk++)
     		 {
         		$m=$k*60;
          		print "w=w+'<option>$kk</option>' \n"; 
     		 }
                  ?>
   		cmp_time.innerHTML=w;










var v="";
v="<select name='staff[]' onKeyPress='return handleEnter(this, event,this.value)' id=emp"+cur3+" 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";
}
?>
emps.innerHTML=v+"</select> ";


dd3.innerHTML="<input type=text value='<?print date('d')?>' name='day2[]' onKeyPress='return handleEnter(this, event,this.value)' id=days"+cur3+" size=2>";
mm3.innerHTML="<input type=text value='<?print date('m')?>' name='month2[]' onKeyPress='return handleEnter(this, event,this.value)' id=months"+cur3+" size=2>";
yy3.innerHTML="<input type=text value='<?print date('Y')?>' name='year2[]' onKeyPress='insRow3(event,this,this.id)' id=years"+cur3+" size=4>";
dd2.innerHTML="<input type=button value='Del' onClick='delrow3(this)'>";

document.getElementById("cate"+cur3).focus();
  cur3++; 

cnt3++;



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

else
{
var tbl = document.getElementById('myTable3');
   var id3=tbl.rows[i3].cells[0].innerHTML;
document.getElementById("cate"+id3).focus();
}


} // end function insrow3

function delrow3(r)
{
 var i=r.parentNode.parentNode.rowIndex
 document.getElementById('myTable3').deleteRow(i)
   var rowCount = document.getElementById('myTable3').rows.length;
 if(rowCount<=1)
 {
  document.getElementById('insrowbttn3').type='button';
 }
 cnt3--;
}




function workshopamt(val,r)
{
 if(isNaN(val))
  {
   alert('enter digit');
  
  }
else
  {

var i=r.parentNode.parentNode.rowIndex;


 //  var tbl = document.getElementById('myTable3');
 //  var id1=tbl.rows[i].cells[0].innerHTML;


   var n=document.getElementById('myTable3').rows.length-1;
//alert(n);
if(n>=1)
   {
   var m;
   var str1=0;

  var totserv= document.getElementById("servtotal").value;
   for(m=1;m<=n;m++)	
    {
     var tbl1 = document.getElementById('myTable3');
     var id2=tbl1.rows[m].cells[0].innerHTML;

    var avg1 = document.getElementById("wrkavg"+id2).value;

   
      str1=(totserv)*(avg1/100);
   document.getElementById("workamt"+id2).value=str1;
    

   }

  } 

  }


}



function calctotal(vv)
{vv--;
  var sele='servamt'+vv
  var tx='servtx'+vv
  var ed='edutx'+vv;
  var hred='hredutx'+vv;
  var ttele='tot'+vv;

  amt=document.getElementById(sele).value;
  stx=(amt*parseFloat(document.getElementById(tx).value))/100;
  edtx=(stx*parseFloat(document.getElementById(ed).value))/100;
  hredtx=(stx*parseFloat(document.getElementById(hred).value))/100;
  totamt=parseFloat(amt)+parseFloat(stx)+parseFloat(edtx)+parseFloat(hredtx);
  document.getElementById(ttele).value=parseFloat(totamt).toFixed(2);
}
function calctotal2(vv)
{
  var sele='servamt'+vv
  var tx='servtx'+vv
  var ed='edutx'+vv;
  var hred='hredutx'+vv;
  var ttele='tot'+vv;

  amt=document.getElementById(sele).value;
  stx=(amt*parseFloat(document.getElementById(tx).value))/100;
  edtx=(stx*parseFloat(document.getElementById(ed).value))/100;
  hredtx=(stx*parseFloat(document.getElementById(hred).value))/100;
  totamt=parseFloat(amt)+parseFloat(stx)+parseFloat(edtx)+parseFloat(hredtx);
  document.getElementById(ttele).value=parseFloat(totamt).toFixed(2);
}

function valid()
{
   alert('Select Cash or Credit, Cash will be posted automatically');
 if(document.getElementById('ptype').selectedIndex<=0)
 {
   alert('Select Cash or Credit, Cash will be posted automatically');
   return false;
 }
 if(confirm('Do you want to save?')) 
  return true;
 else
  return false;
}
</script>
<style>
#save
{
background:url(images/button.png) no-repeat;
width:109px;
height:39px;
border:0px;
}
</style>
<?
$sql=mysqli_query($db,"select * from jcard_est where jcno='$jcno' and brcode='$brcode'");
$sql1=mysqli_fetch_array($sql);
if ($flg=='new'){
  if(mysqli_num_rows($sql)>0)
  {
    print "<script>alert('Estimation is already created for this Jobcard No with Est No:".$sql1[2]."');window.close();</script>";
  }
}
 $res=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode'");
 $jrow=mysqli_fetch_array($res);
$re=mysqli_query($db,"select max(estno) from jcard_est where brcode='$brcode' ");

//print "select max(estno) from jcard_est where brcode='$brcode' ";
     if(mysqli_num_rows($re)<1)
       {
           $estno=1; 
       }
       else
       {
        $row=mysqli_fetch_array($re);
        
         $estno=$row[0]+1;
        }
?>

<form name=f1  method='post' id='jforms' >
<input type=hidden  name='flg' value='<?print $flg;?>'>
<table><tr><td><h4 style="text-align:right;">JCNo:<input type=text readonly name='jcno' size=5 value='<?print $jcno?>'></h4></td><td>
<h4 style="text-align:right;">ESTNo:
<?
if ($flg=='new'){
?>
<input type=text readonly name='estno' size=5 value='<?print $estno;?>'>
<?
}
else{
$qry2=mysqli_query($db,"select estno from jcard_est where jcno='$jcno' and brcode='$brcode' ");
$qry3=mysqli_fetch_row($qry2);
?>
<input type=text readonly name='estno' size=5 value='<?print $qry3[0];?>'>
<?
}
?>
</h4></td></tr></table>

<table border=1 class='form'>

<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=12></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[owner]?>'></td>
</tr>
<tr>	<td>Make </td><td><input type=text readonly name='stdate' value='<?print $jrow[vehiclename]?>'></td>
	<td>Insurance </td><td><input type=text readonly name='instype' value='<?print $jrow[insurance]?>'></td>
	<td>Job Type </td><td><input type=text readonly name='wtstdate' value='<?print $jrow[instype]?>' 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 name='hmr' size=8 value='<?print $jrow[hmr]?>'></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]?>'></td>

<td>Depreciation</td>
<td><input type='text' name='dep' id='dep' value='<? echo $jrow[depreciation];?>' onkeyup='caltotal2(this.value,this.id)' /></td>


</tr>
</table> 
<br>
 <hr></hr>
<br>
<h4>Parts Request </h4>

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


<th> No <th>Part Code<th> Part Name<th>Part type <th>Qty<th>Rate<th>Repair/Replace<th>B / M<th>Depr<th>Discount<th> OtherCharges<th> Total<th>Labour Amt<th>Deprc<th>Net Total<th>Delete


<?

$depct=$jrow[depreciation];

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

 $res=mysqli_query($db,"select * from jcard_estparts where jcno='$jcno' and brcode='$brcode'");
 $i=1;
 $j=1;
 $ptot=0;
  $ltot=0;
  $totdep=0;

  $gnett=0;
 while($jrow=mysqli_fetch_array($res))
  {
$edate1=explode('-',$jrow[edate]);

   print "<tr><td>".$j."</td><td><input type= text readonly name='partcode[]' id='partcode$j' value='$jrow[pcode]' size=12 onKeyPress='return handleEnter(this, event)'></td>";
 print "<td><input type=text size=20 name='partname[]' value='$jrow[4]' onKeyPress='return handleEnter(this, event)'></td>";


  print"<td><select name='spareengineer[]' id='spareengineer$j' onKeyPress='return handleEnter(this, event)' onchange='chkorginal(this,this.value)'><option>$jrow[5]</option><option>Original</option><option>Commercial</option><option>Used</option></select></td>";

  
 print "<td><input type=text size=4 name='qty[]' id='qty$j' value='$jrow[qty]' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'></td>";

  print "<td><input type=text size=8  name='rate[]' id='rate$j' value='$jrow[rate]' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'> </td>";

print "<td><select name='jobs[]' id='jobs$i' onKeyPress='return handleEnter(this, event)' ><option value='$jrow[repr]'>$jrow[repr]</option><option>Change</option><option>Repair</option></select></td>";


print "<td><select name='bom[]' id='bom$i' onKeyPress='return handleEnter(this, event)' onchange='chkorginal(this,this.value)'><option>$jrow[14]</option><option>B</option><option>M</option></select></td>";
print "<td><select name='depr[]' id='depr$i' onKeyPress='return handleEnter(this, event)' onchange='chkorginal(this,this.value)'><option>$jrow[15]</option><option>D</option><option>-</option></select></td>";
  

   print "<td><input type=text size=4 name='disc[]' id='disc$j' value='$jrow[disc]' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'></td>";


   print "<td><input type=text size=3 name='hnd[]' id='hnd$j' value='$jrow[othcharge]' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)' ></td>";

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


 $qtres=mysqli_query($db,"select supqty from $tbl where partcode='$jrow[pcode]'");
 $qtrow=mysqli_fetch_row($qtres);
   $qqty=($qtrow[0]+$jrow[qty]);
   $ptot+=$jrow[total];
   $ltot+=$jrow[labramt];
   if(($depct>0)&&($jrow[5]=='Original'))
    {
   $damt=$jrow[total]*($depct/100);
   $nett=$jrow[total]-$damt+$jrow[labramt];
    }
   else
    {
     $damt=0;
     $nett=$jrow[total]+$jrow[labramt];
    }

print "\n<td><input type=text size=8 name='servamt[]' value='$jrow[labramt]' id='servamt$j' value='$jrow[labramt]' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'></td>";
  
   print "<td align='right' width='5%'><input type=text   name='depc[]' id='depc$j' value='$damt' size='5' onkeyup='caltotal(this,this.value,this.id)' onKeyPress='return handleEnter(this, event)'></td>";

    print "<td align='right' style='text-align:right;'><input type=text   name='nett[]' id='nett$j' value='$nett' size='5' onKeyPress='insRow(event,this,this.id)' ></td>";
  

  

 print "<td><input type=button value='Del' onClick='delrow(this)'></td></tr>";


     $totdep+=$damt;
     $gnett+=$nett;

	print "<script>cur++</script>";
	print "<script>cnt++ ;</script>";
   $i++;
   $j++;
  }
?>
<!--<tr><td align='right' height='30' colspan='8'><b>Total Amount:</b></td><td > <? echo putcoma($ptot); ?></td><td> <? echo putcoma($totdep); ?></td><td> <? echo putcoma($gnett); ?></td></tr>-->
</table> 
<table border='0' align='right' style='width:20%'><tr><td>Total Spares:</td><td id='gtot_p'><? echo putcoma($ptot); ?></td></tr>
<tr><td>Total Deprec:</td><td id='dpc'><? echo putcoma($totdep); ?></td></tr>
<tr><td>Total Labour:</td><td id='gtot_l'><? echo putcoma($ltot); ?></td></tr>
<tr><td>Net Total:</td><td id='ntot_p'><? echo putcoma($gnett); ?></td></tr></table>
<br>
<br>
<br>
<br>
<br>
<br> 
 <hr></hr>  
<br>
  
 


<h4>Other Expences</h4>
<?
$qry=mysqli_query($db,"select * from jcard_est where jcno='$jcno' and brcode='$brcode'");
$qry1=mysqli_fetch_array($qry);
?>
<table border=1 width=50% id="myTable3" >


<th>A/C Gas <th>Miscellaneous<th>Other Expences<th> Collection Excess 
<tr><td><input type='text' name='acgas' id='acgas' value='<? print $qry1[5]; ?>' onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" onKeyPress='return handleEnter(this, event)' onkeyup='chkdigit(this.value,this.id)'></td>
<td><input type='text' name='misc' id='misc' value='<? print $qry1[7]; ?>' onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" onKeyPress='return handleEnter(this, event)' onkeyup='chkdigit(this.value,this.id)'></td>
<td><input type='text' name='otherexp' id='otherexp' value='<? print $qry1[6]; ?>' onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" onKeyPress='return handleEnter(this, event)' onkeyup='chkdigit(this.value,this.id)'></td>
<td><input type='text' name='colex' id='colex' value='<? print $qry1[8]; ?>' onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" onkeyup='chkdigit(this.value,this.id)'></td></tr>
</table>

  <!--<table align='right' ><tr><td><input type='text' name='totserv' id='totserv' value='<? echo $totservamt;?>' readonly  /> </td></tr></table>-->
<br>
<br>
<hr></hr>
<br>

<?

 $res1=mysqli_query($db,"select * from  workshoplabour where jcno='$jcno' and brcode='$brcode'");
$jrow1=mysqli_fetch_array($res1)
?>



<!-- <h4>Workshop Labour (Total Amount-<INPUT TYPE='TEXT' NAME='servtotal' id='servtotal' value='<? echo $jrow1[7];?>' size='5' onkeyup='workshopamt(this.value,this)'/>)</h4>
<table border=1 id="myTable3"><th>No.<th>Workshop</br>category<th>Work in %<th>Amt<th>Esti.Time<th>Compt.Time<th>Assigned to<th colspan=3>EnteredOn<del>

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

 $k=1;
 while($jrow=mysqli_fetch_array($res))


  {


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

   print "\n<tr><td>".$k."</td>";
  
  
 
   
  print"<td> <select name='cate[]' onKeyPress='return handleEnter(this, event,this.value)' id='cate$k'  >";
print "<option>$jrow[1]</option>' \n";
 $res2=mysqli_query($db,"select * from workshop_category  where brcode='$brcode' and status='yes' order by category");
while($row2=mysqli_fetch_array($res2))
{

print "<option>$row2[1]</option>' \n";
} 

   print "</select></td>";

  print"<td><input type=text name='wrkavg[]' id='wrkavg$k' size=8 value='$jrow[2]' onKeyPress='return handleEnter(this, event,this.value)' onkeyup='workshopamt(this.value,this)'></td>";
    

     

  print "\n<td><input type=text size=8 readonly name='workamt[]' onKeyPress='return handleEnter(this, event,this.value)' value='$jrow[3]' id='workamt$k' ></td>";


 	 $hr_est = floor($jrow[8] / 60);

 	 $hr_est1 = $hr_est*60;

  	 $mn_est = $jrow[8]% 60;

  	 $hr_cmp = floor($jrow[9] / 60);

  	  $hr_cmp1=$hr_cmp*60;
  	 $mn_cmp = $jrow[9]% 60;


  	print "<td> <b>Hr</b><select name='e_hr[]' onKeyPress='return handleEnter(this, event,this.value)' id='e_hr$k' style='width:40px'>\n";
   		$j=0;
   		$kk=0;
               print "<option value='".$hr_est1."'>$hr_est</option>' \n"; 

  	 for($j=0;$j<50;$j++)
     		 {
        		 $m=$j*60;
         		print "<option value='".$m."'>$j</option>' \n"; 
      		}

  		 print "</select>";
		 print "<b>:</b> <b>mm</b><select name='e_mt[]' onKeyPress='return handleEnter(this, event,this.value)' id='e_mt$k' style='width:40px'>\n";
                 print "<option>$mn_est</option>' \n"; 
 	   for($kk=0;$kk<60;$kk++)
     		 {
         		$m=$kk*60;
          		print "<option>$kk</option>' \n"; 
     		 }
   		 print "</select></td>";



               	print "<td> <b>Hr</b><select name='c_hr[]' onKeyPress='return handleEnter(this, event,this.value)' id='c_hr$k' style='width:40px'>\n";
   		$j=0;
   		$kk=0;
         print "<option value='".$hr_cmp1."'>$hr_cmp</option>' \n"; 
  	 for($j=0;$j<50;$j++)
     		 {
        		 $m=$j*60;
         		print "<option value='".$m."'>$j</option>' \n"; 
      		 }

  		 print "</select>";
		 print "<b>:</b> <b>mm</b><select name='c_mt[]' onKeyPress='return handleEnter(this, event,this.value)' id='c_mt$k' style='width:40px'>\n";

                  print "<option>$mn_cmp</option> \n"; 
 	    for($kk=0;$kk<60;$kk++)
     		 {
         		$m=$kk*60;
          		print "<option>$kk</option>' \n"; 
     		 }
   		 print "</select></td>";




 print "<td> <select name='staff[]' onKeyPress='return handleEnter(this, event,this.value)' id='emp$k' style='width:150px'>\n";
print "<option>$jrow[4]</option>' \n";

  $res3=mysqli_query($db,"select ename from empprofile where status!='releived' order by ename");
 while($row3=mysqli_fetch_row($res3))
{
print "<option>$row3[0]</option>' \n";
}

   print "</select></td>";



    print "<td><input type=text   name='day2[]' id='days$k' value='$edate2[2]' onKeyPress='return handleEnter(this, event,this.value)' size=2></td>";
    print "<td><input type=text   name='month2[]' id='months$k' value='$edate2[1]' onKeyPress='return handleEnter(this, event,this.value)' size=2></td>";
    print "<td><input type=text   name='year2[]' id='years$k' value='$edate2[0]' onKeyPress='insRow3(event,this,this.id)' size=4></td>";



print "<td><input type=button value='Del' onClick='delrow3(this)' ></td>";

 
 print "</tr>";
   $k++;
print "<script>cur3++</script>";
print "<script>cnt3++</script>";
  }

?>
</table><br>-->





<a href="#login-box" class="login-window" style="text-decoration:none;"> <input  style="height:32px;width:110px;" value="Save" type="button" id='svbttn'></a>

</span>



<input type='hidden' name='savecount' value='0' id='savecount'/>
</form>
 <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></table>


</body>

<script>
 function valid1()
 {
  if(document.f2.jcno.value.length<=0)
   {
    alert('Invalid jcno');
    return false
   }
 }
function valid2()
 {
  if(document.f1.chasisno.value.length<=0)
   {
    alert('Please enter Chasis NO');
    return false
   }
 else
   {
    document.f1.submit();
   }

 
 }
</script>
