
<?
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>PSN Telcon</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>-->

  

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


<?php include('includes/top.php'); ?>
<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>
var cur=1
var partcode=[];
var partname=[];
var lstprice=[];
var handp=[];
var conv=[];
var discar=[];
var cessar=[];
var exq=[];
function delrow(r)
{
 var i=r.parentNode.parentNode.rowIndex
 document.getElementById('myTable').deleteRow(i)
 cur--;
}

function insRow()
{
var x=document.getElementById('myTable').insertRow(1)
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 dis=x.insertCell(6)
var hnd=x.insertCell(7);
var tot=x.insertCell(8);
var qqty=x.insertCell(9);
var dd1=x.insertCell(10);
var mm1=x.insertCell(11);
var yy1=x.insertCell(12);

var dd=x.insertCell(13);

a.innerHTML=cur;
y.innerHTML="<input type=hidden text readonly name=partcode[] id=partcode"+cur+"  class='partcode' size=20>";
z.innerHTML="<input type=text name=partname[] id=partname"+cur+" size=20 class='partname'>"
ag.innerHTML="<input type=text name='qty[]' id=qty"+cur+" size=3 onChange=calcamt(cur)>";
z1.innerHTML="<input type=text  id='rate"+cur+"' name=rate[] size=10 class='rate' onChange=calcamt(cur)>"
dis.innerHTML="<input type=text name='disc[]' id=disc"+cur+" size=6 onChange=calcamt(cur)>";
hnd.innerHTML="<input type=text value='0.0' name='hnd[]' id=hnd"+cur+" size=3 onChange=calcamt(cur)>";
tot.innerHTML="<input type=text readonly value='total' name='gtot[]' id=gtot"+cur+" size=8>";
qqty.innerHTML="<input type=text readonly name='exqty[]' id=exqty"+cur+" size=3 class='supqty' >";
var xv="";
xv="<select name='spareengineer[]' id=spareengineer"+cur+"><option>Orignial</option><option>Commercial</option><option>Used</option>\n";


eng.innerHTML=xv+"</select> ";
dd1.innerHTML="<input type=text value='<?print date('d')?>' name='day[]' id=day"+cur+" size=2>";
mm1.innerHTML="<input type=text value='<?print date('m')?>' name='month[]' id=month"+cur+" size=2>";
yy1.innerHTML="<input type=text value='<?print date('Y')?>' name='year[]' id=year"+cur+" size=4>";

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

//alert(cur);
cur++; 
f1.partname.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(gtotele).value=amt1.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;
function delrow2(r)
{
 var i=r.parentNode.parentNode.rowIndex
 document.getElementById('myTable2').deleteRow(i)
 //cur2--;
}


function insRow2()
{
var x=document.getElementById('myTable2').insertRow(cur2)
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'>"
z.innerHTML="<input type=text name=servamt[] id=servamt"+cur2+" size=8 onChange='calctotal(cur2)' class='servamt'>";


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

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

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



cur2++;
} // 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>
<?


 $res=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode'");
 $jrow=mysqli_fetch_array($res);
?>

<form name=f1  method='post' id='jforms' >


<table border=1 class='form'>
<h4>JCNo:<input type=text 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=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></td>
<td></td>
<td></td>

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

<!--<input type="button" onclick="insRow()" 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>Discount<th> OtherCharges<th>Total<th>Ref<th colspan=3>OrderDate


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

 $res=mysqli_query($db,"select * from pjcardparts where jcno='$jcno' and brcode='$brcode'");
 $i=1;
 $j=100;
 while($jrow=mysqli_fetch_array($res))
  {
$edate1=explode('-',$jrow[edate]);

   print "<tr><td>".$i."</td><td><input type= text readonly name='partcode[]' value='$jrow[2]' size=12></td>";
 print "<td><input type=text size=20 name='partname[]' value='$jrow[3]'></td>";
 print "<td><input type=text  readonly name='spareengineer[]' id='spareengineer$j' value='$jrow[engineer]' size=20></td>";
  
 print "<td><input type=text size=4 name='qty[]' id='qty$j' value='$jrow[qty]' onChange=calcamt2($j)></td>";

  print "<td><input type=text size=8  name='rate[]' id='rate$j' value='$jrow[rate]' onChange=calcamt2($j)> </td>";
   print "<td><input type=text size=4 name='disc[]' id='disc$j' value='$jrow[disc]' onChange=calcamt2($j)></td>";


   print "<td><input type=text size=3 name='hnd[]' id='hnd$j' value='$jrow[hnd]' onChange=calcamt2($j)></td>";

   print "<td><input type=text readonly size=8 name='gtot[]' id='gtot$j' value='$jrow[gtot]'></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=4></td>";

    print "<td><input type=text   name='day[]' id='day$j' value='$edate1[2]' size=2></td>";
    print "<td><input type=text   name='month[]' id='month$j' value='$edate1[1]' size=2></td>";
    print "<td><input type=text   name='year[]' id='year$j' value='$edate1[0]' size=4></td>";

  

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


	print "<script>cur++</script>";
	
   $i++;
   $j++;
  }
?>
</table>
<br>
 <hr></hr>
<br> 
<h4>Service Details </h4>
<!-- <input type="button" onclick="insRow2()" value="   Add Service   ">-->
<table border=1 id="myTable2">
<th>No.<th>Service  <th>Repair/Replace<th>Amt <th>Assigned to<th colspan=3>EnteredOn

<?
 $res=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
 $i=1;
 $totservamt=0;
 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[]' value='$jrow[2]'></td>";
   print "<td><input type=text size=20 name='jobs[]' value='$jrow[4]'></td>";
  
  print "\n<td><input type=text size=8 name='servamt[]' value='$jrow[3]' id='servamt$i' onChange='calctotal2($i)'></td>";
   




 print "<td> <select name='engineer1[]' id='engineer1$i'><option>$jrow[engineer]</option>\n";


 $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='day1[]' id='day1$j' value='$edate2[2]' size=2></td>";
    print "<td><input type=text   name='month1[]' id='month1$j' value='$edate2[1]' size=2></td>";
    print "<td><input type=text   name='year1[]' id='year1$j' value='$edate2[0]' size=4></td>";



//print "<td><input type=button value='Del' ></td>";

 
 print "</tr>";
   $i++;
print "<script>cur2++</script>";
 $totservamt+=$jrow[3];
  }

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

<?

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


<input type="button" id='insrowbttn3' onclick="insRow3(event,this,this.id)"   value="  Add  Workshop Labour   ">
<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>
 
</td></tr></table>

<CENTER>
<H3><font color='darkbrown'>JOB CARD REPORT / EDIT</font></h3>
</center>

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