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


if ($upd)
{
$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
$kar=mysqli_fetch_array($ker);
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
$sq="select jvno from ijobcard where jcno='$jcno' and brcode='$brcode'";
$r_r=mysqli_query($db,$sq) or die(mysqli_error($db));
$r_row=mysqli_fetch_array($r_r);
if($r_row[0]>0)

{
 print "<script> alert('Duplicate saving of ijobcard $jcno'); </script>";
 return;
}

$i=0;
foreach($partcode as $a)
{
 $partcode[$i]=$a; 
 $i++;
}
$i=0;
foreach($partname as $a)
{
 $partname1[$i]=$a; 
 $i++;
}

$i=0;
foreach($rate as $a)
{
 $rate[$i]=$a; 
 $i++;
}

$i=0;
foreach($qty as $a)
{
 $qty[$i]=$a; 
 $i++;
}
$i=0;
foreach($amt as $a)
{
 $amt[$i]=$a; 
 $i++;
}
$i=0;
foreach($disc as $a)
{
 $disc[$i]=$a; 
 $i++;
}
$i=0;
foreach($vat as $a)
{
 $vat[$i]=$a; 
 $i++;
}
$i=0;
foreach($cessp as $a)
{
 $cessp[$i]=$a; 
 $i++;
}
$i=0;
foreach($cesamt as $a)
{

 $cessamt[$i]=$a; 
 $i++;
}

$i=0;
foreach($hnd as $a)
{
 $hnd[$i]=$a; 
 $i++;
}
$i=0;
foreach($taxamt as $a)
{
 $taxamt[$i]=$a; 
 $i++;
}
$i=0;
foreach($spareengineer as $a)
{
 $spareengineer[$i]=$a; 
 $i++;
}
foreach($engineer as $a)
{
 $engineer[$i]=$a; 
 $i++;
}

$i=0;
foreach($day as $a)
{
 $day[$i]=$a; 
 $i++;
}
$i=0;
foreach($month as $a)
{
 $month[$i]=$a; 
 $i++;
}
$i=0;
foreach($year as $a)
{
 $year[$i]=$a; 
 $i++;
}



$i=0;
foreach($gtot as $a)
{
 $gtot[$i]=$a; 
 $i++;
}
$entrydate=$entrdate3.'-'.$entrdate2.'-'.$entrdate1;

//********** chk ledger

$chre=mysqli_query($db,"select * from ledger where led='$cname' and brcode='$brcode'");
if(mysqli_num_rows($chre)<=0)
{
$code=substr($customer,0,3).date(ymds);
$code=str_replace(' ','-',$code);

$sql="insert into ledger values('$cname','Sundry Debtors','0','Dr','$code','$brcode')";
mysqli_query($db,$sql);
}


$tbl="stockrepdet10".$brcode.$user;


$invres=mysqli_query($db,"select max(invno) from ijobcard where brcode='$brcode' and invtype='$invtype'");
$invrow=mysqli_fetch_row($invres);
if($invrow[0]>0)
 $invno=($invrow[0]+1);
else
 $invno=1;

$sql="delete from ijobcard where jcno='$jcno' and brcode='$brcode'";

mysqli_query($db,$sql) or die('err'.mysqli_error($db));
mysqli_query($db,"delete from ijcardparts where jcno='$jcno' and brcode='$brcode'");
mysqli_query($db,"delete from ijcardserv where jcno='$jcno' and brcode='$brcode'");

include ("spares/calcstock.php");
mysqli_query($db,"delete from $tbl where supqty<=0");

$jvres=mysqli_query($db,"select max(jvno) from journal2 where brcode='$brcode'");
$jvrow=mysqli_fetch_row($jvres);
if($jvrow[0]>0)
 $jvno=($jvrow[0]+1);
else
 $jvno=1;

/*
$date=$y.'-'.$m.'-'.$d;
$comd=explode('-',$dcomm);
$dcomm=$comd[2].'-'.$comd[1].'-'.$comd[0];

$stdate1=explode('-',$stdate);
$stdate=$stdate1[2].'-'.$stdate1[1].'-'.$stdate1[0].' '.$stdate1[3].$sttime;

$cldate1=explode('-',$cldate);
$cldate=$stdate1[2].'-'.$cldate1[1].'-'.$cldate1[0].' '.$cldate1[3].$cldatetm;

$wtystdate1=explode('-',$wtystdate);
$wtystdate=$wtystdate1[2].'-'.$wtystdate1[1].'-'.$wtystdate1[0];

$wtyenddate1=explode('-',$wtyenddate);
$wtyenddate=$wtyenddate1[2].'-'.$wtyenddate1[1].'-'.$wtyenddate1[0];
*/


if($updprn)
{
$sql="insert into ijobcard (jcno , date, msno, dcomm, model, cname, stdate, cldate, wtystdate, wtyenddate, servtype,hmr,engineer, brcode,user,jvno,invtype,ptype,invno,entrydate) values('$jcno' , '$date', '$msno','$dcomm', '$model', '$cname', '$stdate', '$cldate', '$wtystdate', '$wtyenddate', '$servtype','$hmr', '$engineer3','$brcode','$user','$jvno','$invtype','$ptype','$invno','$entrydate')";
}
else
{
$sql="insert into ijobcard (jcno , date, msno, dcomm, model, cname, stdate, cldate, wtystdate, wtyenddate, servtype,hmr,engineer, brcode,user) values('$jcno' , '$date', '$msno','$dcomm', '$model', '$cname', '$stdate', '$cldate', '$wtystdate', '$wtyenddate', '$servtype','$hmr', '$engineer3','$brcode','$user')";
}

 mysqli_query($db,$sql) or die("Err 0".mysqli_error($db));

/*
for($j1=0;$j1<$i;$j1++)
{
if($qty[$j1]>0)
{
  $chstkre=mysqli_query($db,"select * from $tbl where partcode='$partcode[$j1]'");
  $chstkrow=mysqli_fetch_array($chstkre);
   if($qty[$j1]>$chstkrow[supqty])
    {
      print "Insufficient Quantity ".$partcode[$j1];
	$sq="update ijobcard set jvno='0',invno='0' where jcno='$jcno' and brcode='$brcode'";
         mysqli_query($db,$sq) or die(mysqli_error($db));
      return;
    }
}
}
*/
$t=1;
$s=1;
print $i;
$dt=date('Y-m-d');
for($j=0;$j<$i;$j++)

{
if($qty[$j]>0)
{

$edate=$year[$j].'-'.$month[$j].'-'.$day[$j];

 $sql="insert into ijcardparts values('$jcno','$brcode','$partcode[$j]','$partname[$j]','$rate[$j]', '$qty[$j]', '$amt[$j]','$disc[$j]', '$vat[$j]', '1' , '$cessamt[$j]', '$hnd[$j]', '$taxamt[$j]', '$gtot[$j]','0','0','$dt','$spareengineer[$j]','".$s++."','$edate')";
 mysqli_query($db,$sql) or die("Err 1".mysqli_error($db));



}
}






$i=0;
foreach($servamt as $a)
{
 $servamt[$i]=$a; 
 $i++;
}

$i=0;
foreach($engineer1 as $a)
{
 $engineer1[$i]=$a; 
 $i++;
}


$i=0;
foreach($jobs as $a)
{
 $jobs[$i]=$a; 
 $i++;
}

$i=0;
foreach($day1 as $a)
{
 $day1[$i]=$a; 
 $i++;
}
$i=0;
foreach($month1 as $a)
{
 $month1[$i]=$a; 
 $i++;
}
$i=0;
foreach($year1 as $a)
{
 $year1[$i]=$a; 
 $i++;
}



$i=0;
foreach($service as $a)
{
 $service[$i]=$a; 
 $i++;
}



$s=1;

for($j=0;$j<$i;$j++)
{

if(strlen($service[$j])>0)
{

$edate=$year1[$j].'-'.$month1[$j].'-'.$day1[$j];

 $sql="insert into ijcardserv (jcno, brcode, service,servamt, descr, servtx,edutx,hredutx,tot,engineer,edate,sno)   values('$jcno','$brcode','$service[$j]','$servamt[$j]','$jobs[$j]','$servtx[$j]','$edutx[$j]','$hredutx[$j]','$tot[$j]','$engineer1[$j]','$edate','".$s++."')";
 mysqli_query($db,$sql) or die("Err 2".mysqli_error($db));
}
}

}



$us=mysqli_query($db,"select level from bruser where username='$user'")or die(mysqli_error($db));
$r=mysqli_fetch_row($us);
$user_level=$r[0];
 //print "User Level:".$user_level;
        
?>
<!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="includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="css/form1.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>

    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
	<script type="text/javascript">
    $(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>
.cont
	{


       background-color:#3b5998;

	//background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
  	width: 100%;position: absolute ;
	height:99%;
    	/* Optional - just for DIV)*/
    	//border: solid 1px #000000;
	-moz-box-shadow: 0px 5px 5px #888;
	-webkit-box-shadow: 0px 5px 5px #888;
	box-shadow: 0px 5px 10px #888;
    
	}
</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 bgcolor="#0033FF">
<div class='cont'>

<?php include('includes/top.php'); ?>
<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 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>
<?
if($show)
{
 $res=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode'");
 $jrow=mysqli_fetch_array($res);
?>
<form name=f1 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid2()'>

<table border=1 class='form'>
<th colspan=10 bgcolor=#AED69A>JCNo: <input type=text readonly name='jcno' size=5 value='<?print $jcno?>'></th>
<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>Ins type </td><td><input type=text readonly name='instype' value='<?print $jrow[instype]?>'></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 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> 
<h4>Parts Request </h4>
<input type="button" onclick="insRow()" value=" Add Item ">
<table border=1  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<th>Delete


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

 $res=mysqli_query($db,"select * from ijcardparts 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=hidden 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>";

  
if($user!='RAJESHTS'||$user!='RAJESHHYD'||$user!='RAJESHMW'|| $user!='nandakumar'|| $user!='anand')
{
   print "<td><input type=button value='Del' onClick='delrow(this)'></td></tr>";
}
else
{
   print "<td><input type=button value='No' ></td></tr>";
}

   $i++;
   $j++;
  }
?>
</table> 
<h3>Service Details </h3>
 <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<th>Del

<?
 $res=mysqli_query($db,"select * from ijcardserv where jcno='$jcno' and brcode='$brcode'");
 $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[]' 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><input type=text  readonly name='engineer1[]' id='engineer1$j' value='$jrow[engineer]' size=20></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>";



if($user!='RAJESHTS'||$user!='RAJESHHYD'||$user!='RAJESHMW')
{
   print "<td><input type=button value='Del' onClick='delrow2(this)'></td>";
}
else
{
   print "<td><input type=button value='No' ></td>";
}
 
 print "</tr>";
   $i++;
  }
?>
</table><br>
<table width=100% class='report'>

<tr><td align=center bgcolor='#AED69A' align=right colspan=4>
<input type=submit value='  S A V E  ' name='upd' style="font-size:16; font-weight:bold">


</td></tr>
</table>
</span>
</form>
<?
}
?>
<CENTER>
<H3><font color='darkbrown'>JOB CARD REPORT / EDIT</font></h3>
</center>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>
Select Jobcard No. <select name=jcno>
<?
$re=mysqli_query($db,"select jcno,regno from gateentry where brcode='$brcode' order by jcno desc");
while($row=mysqli_fetch_row($re))
{
 print "<option value='$row[0]'>$row[0]-$row[1]</option>";
}
?>
</select>
<input type=submit value='Show ->' name='show'>
</form>
<script>
 function valid1()
 {
  if(document.f2.jcno.value.length<=0)
   {
    alert('Invalid jcno');
    return false
   }


 }
</script>
