<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
    print "<script> alert('Invalid Login') </script>";
    return;
}
include("../opendb.php");
include("../test.php");
$intr=$_REQUEST['intr'];
print 'Branch Code:'.$brcode;
?>
<link type="text/css" href="../css/form.css" rel="stylesheet" />
<script>
var cur=1;
var partcode=[];
var partname=[];
var lstprice=[];
var handp=[];
var conv=[];
var discar=[];
var cessar=[];
var exq=[];
var cgstper=[];
var sgstper=[];
var igstper=[];
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 z1=x.insertCell(3);
var ag=x.insertCell(4);
var agval=x.insertCell(5);
var dis=x.insertCell(6);

<?
if($intr=='INTRASTATE')
{
?>
var cgstpp=x.insertCell(7);
var cgstamtp=x.insertCell(8);
var sgstpp=x.insertCell(9);
var sgstamtp=x.insertCell(10);
var cessamt=x.insertCell(11);
var hnd=x.insertCell(12);
var taxamt1=x.insertCell(13);
var tot=x.insertCell(14);
var dd=x.insertCell(15);
var qqty=x.insertCell(16);
var eng=x.insertCell(17);   
var flg=x.insertCell(18);  
<?
}
else
{
?>
var igstpp=x.insertCell(7);
var igstamtp=x.insertCell(8);
var hnd=x.insertCell(9);
var taxamt1=x.insertCell(10);
var tot=x.insertCell(11);
var dd=x.insertCell(12);
var qqty=x.insertCell(13);
var eng=x.insertCell(14);
var flg=x.insertCell(15);  
<?
}
?>
a.innerHTML=cur;
var value="<select name=partcode[] id='partcode"+cur+"'onChange=setval(this.selectedIndex,this)>";
for(k=0;k<partcode.length;k++)
 value=value+"<option>"+partcode[k]+"</option>";
value=value+"</select>";
y.innerHTML=value
z.innerHTML="<input type=text name=partname[] id=partname"+cur+" size=20>"
z1.innerHTML="<input type=text  id='rate"+cur+"' name=rate[]  size=10>"
ag.innerHTML="<input type=text name='qty[]' id=qty"+cur+" size=3 onChange=calcamt(cur)>";
agval.innerHTML="<input type=text readonly name='amt[]' id=amt"+cur+" size=8>";
dis.innerHTML="<input type=text name='disc[]' value='0' id=disc"+cur+" size=6 onChange=calcamt(cur)>";
<?
if($intr=='INTRASTATE')
{
    ?>
cgstpp.innerHTML="<input type=text name='cgstpp[]' readonly value='0.00' id=cgstpp"+cur+" size=4 onChange=calcamt(cur)>";
cgstamtp.innerHTML="<input type=text name='cgstamtp[]' readonly value='0' id=cgstamtp"+cur+" size=4 onChange=calcamt(cur)>";
sgstpp.innerHTML="<input type=text readonly value='0.00' name='sgstpp[]' id=sgstpp"+cur+" size=4 onChange=calcamt(cur)>";
sgstamtp.innerHTML="<input type=text name='sgstamtp[]' readonly value='0' id=sgstamtp"+cur+" size=4 onChange=calcamt(cur)>";
cessamt.innerHTML="<input type=text name='cessamt[]' readonly value='0' id=cessamt"+cur+" size=4 onChange=calcamt(cur)>";
hnd.innerHTML="<input type=text value='0.00' name='hnd[]' id=hnd"+cur+" onChange=calcamt(cur) size=3>";
taxamt1.innerHTML="<input type=text value='0.0' readonly name='taxamt[]' id=taxamt"+cur+" size=6>";
tot.innerHTML="<input type=text readonly value='total' name='gtot[]' id=gtot"+cur+" size=8>";
dd.innerHTML="<input type=button value='Del' onClick='delrow(this)'>";
qqty.innerHTML="<input type=text readonly name='exqty[]' id=exqty"+cur+" size=3 >";
flg.innerHTML="<input type=hidden id=flg"+cur+" value='flg1'>";
var xv="";
xv="<select name='spareengineer[]' id=spareengineer"+cur+"><option></option>\n";

<?
 $empre=mysqli_query($db,"select empname from empmaster where design like '%eng%'");
 while($emprow=mysqli_fetch_row($empre))
 {
  print "xv=xv+'<option>$emprow[0]</option>' \n";
 }
?>

eng.innerHTML=xv+"</select> ";
<?
}
else
{
?>
igstpp.innerHTML="<input type=text readonly value='0.00' name='igstpp[]' id=igstpp"+cur+" size=6>";
igstamtp.innerHTML="<input type=text name='igstamtp[]' readonly value='0' id=igstamtp"+cur+" size=4 onChange=calcamt(cur)>";
hnd.innerHTML="<input type=text value='0.00' name='hnd[]' id=hnd"+cur+" size=3 onChange=calcamt(cur)>";
taxamt1.innerHTML="<input type=text value='0.0' readonly name='taxamt[]' id=taxamt"+cur+" size=6>";
tot.innerHTML="<input type=text readonly value='total' name='gtot[]' id=gtot"+cur+" size=8>";
dd.innerHTML="<input type=button value='Del' onClick='delrow(this)'>";
qqty.innerHTML="<input type=text readonly name='exqty[]' id=exqty"+cur+" size=3 >";
flg.innerHTML="<input type=hidden  id=flg"+cur+"  value='flg2'>";
var xv="";
xv="<select name='spareengineer[]' id=spareengineer"+cur+"><option></option>\n";

<?
 $empre=mysqli_query($db,"select empname from empmaster where design like '%eng%'");
 while($emprow=mysqli_fetch_row($empre))
 {
  print "xv=xv+'<option>$emprow[0]</option>' \n";
 }
?>

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

//alert(cur);
cur++; 
}// end function insrow

function setval(x)
{

 var ele1='partname'+(cur-1);
 var ele2='rate'+(cur-1);
 var hand='hnd'+(cur-1);
 var cpele='cgs'+(cur-1);
 var disele='disc'+(cur-1);
 var cessele='cgs'+(cur-1);
 var qqtyele='exqty'+(cur-1);
 var qele='qty'+(cur-1);
 var cgstp_val='cgstpp'+(cur-1);
  var sgstp_val='sgstpp'+(cur-1);
  var igstp_val='igstpp'+(cur-1);
 document.getElementById(qele).value=0;
 
 document.getElementById(ele1).value=partname[x];
 document.getElementById(ele2).value=lstprice[x];

if(document.getElementById('intr').value=='INTRASTATE')
{
 document.getElementById(cgstp_val).value=cgstper[x];
  document.getElementById(sgstp_val).value=sgstper[x];
}
else
{
   document.getElementById(igstp_val).value=igstper[x];
}
 //document.getElementById(cpele).value=conv[x];  
 document.getElementById(disele).value=discar[x];  //alert('hi');
 //document.getElementById(cessele).value=1; //cessar[x-1];

 document.getElementById(qqtyele).value=exq[x];
}
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='cgstpp'+y;
    var cessele='sgstpp'+y;
    var cesspele='cgstamtp'+y;
    var cesssgst='sgstamtp'+y;
    var cessamtele='cessamt'+y;
    var igstele='igstpp'+y;
    var igstamtele='igstamtp'+y;
    var taxele='taxamt'+y;
    var gtotele='gtot'+y;
    var qqtyele='exqty'+y;
    var flgele='flg'+y;
    var vatamt;
    var gstele = 'gst';
    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=amount*discp/100;
        amount-=disamt;
    }
    document.getElementById(amtele).value=amount.toFixed(2);
    var handamt=parseFloat(document.getElementById(handele).value);
    var cgstamt;
    var sgstamt;
    var flgp=document.getElementById(flgele).value;
    
    if(flgp=='flg1')
    {
        vatp=parseFloat(document.getElementById(vatele).value);
        vatpp=parseFloat(document.getElementById(cessele).value);
        cgstamt=amount*vatp/100;
        document.getElementById(cesspele).value=cgstamt.toFixed(2);
        sgstamt=amount*vatpp/100;
        document.getElementById(cesssgst).value=sgstamt.toFixed(2);
        vatamt=cgstamt+sgstamt;
        document.getElementById(taxele).value=vatamt.toFixed(2);
        //if(document.getElementById(gstele).value=='NOT REGISTERD')
            //cessamt = (amount*1/100);
        //else
            cessamt = 0;
        document.getElementById(cessamtele).value=cessamt.toFixed(2);
        
        amt1=amount+handamt+cgstamt+sgstamt+cessamt;
        document.getElementById(gtotele).value=amt1.toFixed(2);
        
        
    }
    else
    {
        var igvatp=parseFloat(document.getElementById(igstele).value);
        igvatpp=amount*igvatp/100;
        document.getElementById(igstamtele).value=igvatpp.toFixed(2);
        vatamt=igvatpp;
        document.getElementById(taxele).value=vatamt.toFixed(2);
        amt1=amount+handamt+igvatpp;
        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 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 qty=document.getElementById(qele).value;
 var exqty2=document.getElementById(qqtyele).value;

 if(parseFloat(qty)>parseFloat(exqty2))
 {
  alert('Invalid quantity');
  document.getElementById(qele).value=0;
  return false;
 }
 var rate=document.getElementById(ele2).value;
 var amount=parseFloat(qty)*parseFloat(rate);
 var discp=parseFloat(document.getElementById(disele).value);
 if(discp>0)
 {
   disamt=amount*discp/100;
   amount-=disamt;
 }
document.getElementById(amtele).value=amount.toFixed(2);
handp=parseFloat(document.getElementById(handele).value);
if(handp>0)
 handamt=(amount*handp)/100;
vatp=parseFloat(document.getElementById(vatele).value);
vatamt=((amount+handamt)*vatp)/100;
amt1=(amount+handamt)+vatamt;

document.getElementById(taxele).value=vatamt.toFixed(2);
//cessamt=(vatamt*document.getElementById(cesspele).value)/100;
cessamt=0;
amt1+=cessamt;
document.getElementById(cessele).value=cessamt.toFixed(2);
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 z=x.insertCell(2)	
var z1=x.insertCell(3)	
<?if($intr=='INTRASTATE'){?>
var dd3=x.insertCell(4)	
var dd4=x.insertCell(5)
var dd5=x.insertCell(6)
var dd6=x.insertCell(7)	
var cessamtl=x.insertCell(8)	
var dd7=x.insertCell(9)	
var dd8=x.insertCell(10)	
var engs=x.insertCell(11)
var flg=x.insertCell(12)
<?}else{?>

var dd3=x.insertCell(4)	
var dd4=x.insertCell(5)	
var dd5=x.insertCell(6)	
var dd2=x.insertCell(7)	
var engs=x.insertCell(8)
var flg=x.insertCell(9)
<?}?>

a.innerHTML=cur2
y.innerHTML="<input type=text name=service[] id=service"+cur2+" size=30>";
z.innerHTML="<input type=text name=servamt[] id=servamt"+cur2+" size=8 onChange='calctotal(cur2)'>";
z1.innerHTML="<input type=text name=descr[] id=desc"+cur2+" size=20>";
<?
$query=mysqli_query($db,"select * from taxmaster where tax='labour_tax'");
$result=mysqli_fetch_array($query);
if($intr=='INTRASTATE'){?>
dd3.innerHTML="<input type=text name=cgstp[] id=cgstp"+cur2+" size=8 readonly value='<?echo $result['tax_cgst']?>' onChange='calctotal(cur2)'>";
dd4.innerHTML="<input type=text readonly name=cgstamt[] id=cgstamt"+cur2+" size=8 readonly value='0' onChange='calctotal(cur2)'>";
dd5.innerHTML="<input type=text readonly name=sgstp[] id=sgstp"+cur2+" size=8 readonly value='<?echo $result['tax_sgst']?>' onChange='calctotal(cur2)'>";
dd6.innerHTML="<input type=text readonly name=sgstamt[] id=sgstamt"+cur2+" size=8 readonly value='0' onChange='calctotal(cur2)'>";
cessamtl.innerHTML="<input type=text readonly name=cessamtl[] id=cessamtl"+cur2+" size=8 readonly value='0' onChange='calctotal(cur2)'>";
dd7.innerHTML="<input type=text readonly name=tot[] id=tot"+cur2+" size=8 value='0'>";
dd8.innerHTML="<input type=button value='Del' onClick='delrow2(this)'>";

var v="";
v="<select name='spareengineer2[]' id=spareengineer2"+cur+"><option></option>\n";

<?
 $empre1=mysqli_query($db,"select empname from empmaster where design like '%eng%'");
 while($emprow1=mysqli_fetch_row($empre1))
 {
  print "v=v+'<option>$emprow1[0]</option>' \n";
 }
?>
engs.innerHTML=v+"</select> ";
flg.innerHTML="<input type=hidden value='flg' id=flgs"+cur2+">";
<?}else{?>

dd3.innerHTML="<input type=text readonly name=igstp[] id=igstp"+cur2+" size=8 readonly value='<?echo $result['tax_igst']?>' onChange='calctotal(cur2)'>";
dd4.innerHTML="<input type=text readonly name=igstamt[] id=igstamt"+cur2+" size=8 readonly value='0' onChange='calctotal(cur2)'>";
dd5.innerHTML="<input type=text readonly name=tot[] id=tot"+cur2+" size=8 value='0'>";
dd2.innerHTML="<input type=button value='Del' onClick='delrow2(this)'>";

var v="";
v="<select name='spareengineer2[]' id=spareengineer2"+cur+"><option></option>\n";

<?
 $empre1=mysqli_query($db,"select empname from empmaster where design like '%eng%'");
 while($emprow1=mysqli_fetch_row($empre1))
 {
  print "v=v+'<option>$emprow1[0]</option>' \n";
 }
?>
engs.innerHTML=v+"</select> ";
flg.innerHTML="<input type=hidden value='flg1' id=flgs"+cur2+">";
<?}?>

cur2++;
} // end function insrow2
function calctotal(vv)
{vv--;
    var sele='servamt'+vv
    var ed='cgstp'+vv;
    var hred='sgstp'+vv;
    var ighred='igstp'+vv;
    var edamt='cgstamt'+vv;
    var hredamt='sgstamt'+vv;
    var ighredamt='igstamt'+vv;
    var cessamtl1 = 'cessamtl'+vv; 
    var flgele='flgs'+vv;
    var ttele='tot'+vv;
    var gstele = 'gst';
    var flgv=document.getElementById(flgele).value;
    if(flgv=='flg')
    {
        amt=document.getElementById(sele).value;
        stx=(amt*parseFloat(document.getElementById(ed).value))/100;
        document.getElementById(edamt).value=parseFloat(stx).toFixed(2);
        edtx=(amt*parseFloat(document.getElementById(hred).value))/100;
        document.getElementById(hredamt).value=parseFloat(edtx).toFixed(2);
        //if(document.getElementById(gstele).value=='NOT REGISTERD')
            //cessamt = (amt*1/100);
        //else
            cessamt = 0;
        document.getElementById(cessamtl1).value=parseFloat(cessamt).toFixed(2);
        totamt=parseFloat(amt)+parseFloat(stx)+parseFloat(edtx)+parseFloat(cessamt);
        document.getElementById(ttele).value=parseFloat(totamt).toFixed(2);
    }
    else
    {
        amt=document.getElementById(sele).value;
        stx=(amt*parseFloat(document.getElementById(ighred).value))/100;
        document.getElementById(ighredamt).value=parseFloat(stx).toFixed(2);
        totamt=parseFloat(amt)+parseFloat(stx);
        document.getElementById(ttele).value=parseFloat(totamt).toFixed(2);
    }
}
function calctotal2(vv)
{
  var sele='servamt'+vv
  
  var ed='cgstp'+vv;
  var hred='sgstp'+vv;
  var ighred='igstp'+vv;
  var edamt='cgstamt'+vv;
  var hredamt='sgstamt'+vv;
  var ighredamt='igstamt'+vv;
  var flgele='flgs'+vv;
  var ttele='tot'+vv;
  var flgv=document.getElementById(flgele).value;
if(flgv=='flg')
{alert('hi');
  amt=document.getElementById(sele).value;
  stx=(amt*parseFloat(document.getElementById(ed).value))/100;
   document.getElementById(edamt).value=parseFloat(stx).toFixed(2);
   
  edtx=(amt*parseFloat(document.getElementById(hred).value))/100;
  document.getElementById(hredamt).value=parseFloat(edtx).toFixed(2);
  
  totamt=parseFloat(amt)+parseFloat(stx)+parseFloat(edtx);
  document.getElementById(ttele).value=parseFloat(totamt).toFixed(2);
}
else
{
  amt=document.getElementById(sele).value;
  stx=(amt*parseFloat(document.getElementById(ighred).value))/100;
   document.getElementById(ighredamt).value=parseFloat(stx).toFixed(2);
  
  totamt=parseFloat(amt)+parseFloat(stx);
  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(isset($_POST['show']))
{
    
    $jcno=$_REQUEST['jcno'];
   // include("../spares/calcsparestock.php");
    
    $res=mysqli_query($db,"select * from jobcard where jcno='$jcno' and brcode='$brcode'");
    $jrow=mysqli_fetch_array($res);
    //echo "select gst from customer where cname='$jrow[cname]'";
    $cusrow=mysqli_query($db,"select gst from customer where acname='$jrow[cname]'");
    $cusrow_res=mysqli_fetch_array($cusrow);
    if($cusrow_res['gst']=='Null')
    {
        print "<script>alert('Update Gst No Of Customer ".$jrow['cname']."');history.back();</script>";
        return;
    }
   
?>


   <form action='updjobcard_sb.php' method='post' onSubmit='return valid()'> 
   
<table border=1>
<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 $jrow['date']?>' size=8></td>
    <td>MSNO </td><td><input type=text readonly name='msno' value='<?print $jrow['msno']?>' size=12></td>

	<td>D Comm </td><td><input type=text readonly name='dcomm' value='<?print $jrow['dcomm']?>' size=8></td>
	<td>Model </td><td><input type=text readonly name='model' value='<?print $jrow['model']?>' size=8></td>
	<td>Customer </td><td><input type=text readonly name='cname' value='<?print $jrow['cname']?>'>
	GST No.</td><td><input type=text readonly name='gst' id = 'gst' value='<?print $cusrow_res['gst']?>'></td>
</tr>
<tr>	<td>St Date </td><td><input type=text readonly name='stdate' value='<?print $jrow['stdate']?>'></td>
	<td>Cl Date </td><td><input type=text readonly name='cldate' value='<?print $jrow['cldate']?>'></td>
	<td>WTY St Date </td><td><input type=text readonly name='wtystdate' value='<?print $jrow['wtystdate']?>' size=8></td>
	<td>WTY End Date </td><td><input type=text readonly name='wtyenddate' value='<?print $jrow['wtyenddate']?>' size=8></td>
	<td>Serv Type </td><td><input type=text readonly name='servtype' value='<?print $jrow['servtype']?>'></td>
</tr>
<tr>
	<td>HMR </td><td><input type=text readonly name='hmr' size=8 value='<?print $jrow['hmr']?>'></td>
	<td>Supervisor </td><td><input type=text readonly name='engineer3' value='<?print $jrow['engineer']?>'></td>
	<td>User </td><td><input type=text readonly name='user' value='<?print $jrow['user']?>' size=8></td>
<td>Entry Date </td><td colspan=3>
dd <input type=text readonly name='entrdate1' size=2 value='<?print date('d')?>'>
mm <input type=text readonly name='entrdate2' size=2 value='<?print date('m')?>'>
yy <input type=text readonly name='entrdate3' size=4 value='<?print date('Y')?>'>
<input type=text name='intr' value='<?print $intr?>' id='intr' readonly>
</td>
</tr>
<tr><td>Complaint</td><td><textarea id="complaints" name="complaints" rows="2" cols="20"></textarea></td><td>Observation</td><td><textarea id="observation" name="observation" rows="2" cols="20"></textarea></td>
<td>Action Taken</td><td><textarea id="actiontaken" name="actiontaken" rows="2" cols="20"></textarea></td><td></td><td></td></tr>
</table> 
<h3>Parts Issued </h3>
<input type="button" onclick="insRow()" value=" Add Item ">
<table border=1  id="myTable" >
<th> No <th>Part Code <th>Part Name  <th>Rate<th>Qty <th>Amount <th>Disc 

<?
//******************spare
if($intr=='INTRASTATE')
{
    print "<th>CGST %<th>CGST Amt<th>SGST %<th>SGST Amt<th>Cess Amt";
}
else
{
    print "<th>IGST %<th>IGST Amt";
}
?>
<th>Hand <th>Tax Amt <th>Gtot<th>Del<th>Exqty <th>Engineer
<?
$tbl="sparetmp".$brcode.$user;

$res=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
$i=1;
$j=100;
while($jrow=mysqli_fetch_array($res))
{
   if (is_numeric($jrow['hnd']))
     $mhnd = $jrow['hnd'];
   else
     $mhnd = 0;
   print "<tr><td>".$i."</td><td><input type=text 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 size=8  name='rate[]'  id='rate$j' value='$jrow[rate]' onChange=calcamt($i)> </td>";
   print "<td><input type=text size=4 name='qty[]' id='qty$j' value='$jrow[qty]' onChange=calcamt($i)></td>";
   print "<td><input type=text size=8 readonly name='amt[]' id='amt$j' value='$jrow[amt]' onChange=calcamt($i)></td>";
   print "<td><input type=text size=4 name='disc[]' id='disc$j' value='$jrow[disc]'></td>";
   
   
   if($intr=='INTRASTATE')
   {
      print "<td><input type=text size=3 name='cgstpp[]' readonly id='cgstpp$j' value='$jrow[cgstp]' ></td>";
      print "<td><input type=text size=3 name='cgstamtp[]' readonly id='cgstamtp$j' value='$jrow[cgstamt]'></td>";
      print "<td><input type=text size=3 name='sgstpp[]' readonly id='sgstpp$j' value='$jrow[sgstp]' ></td>";
      print "<td><input type=text size=3 name='sgstamtp[]' readonly id='sgstamtp$j' value='$jrow[sgstamt]'></td>";
      print "<td><input type=text size=3 name='cessamt[]' readonly id='cessamt$j' value='$jrow[cessamt]'></td>";
      //*******to passing 
      print "<input type=hidden name='igstpp[]' id='igstpp$j' value='0'>";
      print "<input type=hidden name='igstamtp[]' id='igstamtp$j' value='0'>";
   }
   else
   {
      print "<td><input type=text size=3 name='igstpp[]' readonly id='igstpp$j' value='0'></td>";
      print "<td><input type=text size=3 name='igstamtp[]' readonly id='igstamtp$j' value='0'></td>";
      //*******to passing 
      print "<input type=hidden name='cgstpp[]' id='cgstpp$j' value='0' ></td>";
      print "<input type=hidden name='cgstamtp[]' id='cgstamtp$j' value='0'></td>";
      print "<input type=hidden name='sgstpp[]' id='sgstpp$j' value='0'></td>";
      print "<input type=hidden name='sgstamtp[]' id='sgstamtp$j' value='0'></td>";
   }

   print "<td><input type=text size=3 name='hnd[]' id='hnd$j' value='$mhnd' onChange=calcamt2($j)></td>";
   print "<td><input type=text size=5 name='taxamt[]' readonly id='taxamt$j' value='$jrow[taxamt]'></td>";
   print "<td><input type=text readonly size=8 name='gtot[]' id='gtot$j' value='$jrow[gtot]'></td>";
   print "<td><input type=button value='Del' onClick='delrow(this)'></td>";
 $qtres=mysqli_query($db,"select supqty from $tbl where partcode='$jrow[2]'");
 $qtrow=mysqli_fetch_row($qtres);
 if($qtrow[0]>0)
   $qqty=($qtrow[0]+$jrow['qty']);
 else
   $qqty=$jrow['qty'];
   print "<td><input type=text  readonly name='exqty[]' id='exqty$j' value='$qqty' size=4></td>";
   print "<td><input type=text  readonly name='engineer[]' id='engineer$j' value='$jrow[engineer]' size=20></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>Amt <th>Description
<?
//******************service
   if($intr=='INTRASTATE')
   {
print "<th>CGST %<th>CGST Amt<th>SGST %<th>SGST Amt<th>Cess Amt";
    }
else
{
print "<th>IGST %<th>IGST Amt";
}
?>

<th>Total<th>Del<th>Engineer

<?

 $res=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
 $i=1;
while($jrow=mysqli_fetch_array($res))
 {
      $query=mysqli_query($db,"select * from taxmaster where tax = 'GST28' ");
        $result=mysqli_fetch_array($query);
   print "\n<tr><td>".$i."</td>";
   print "<td><input type=text size=20 name='service[]' value='$jrow[2]'></td>";
   print "\n<td><input type=text size=8 name='servamt[]' value='$jrow[3]' id='servamt$i' onChange='calctotal2($i)'></td>";
   print "\n<td><input type=text size=25 name='descr[]' id='descr$i' value='$jrow[4]'></td>";
   if($intr=='INTRASTATE')
   {
   print "<td><input type=text size=6 name='cgstp[]' readonly id='cgstp$i' value='$result[tax_cgst]' onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=6 name='cgstamt[]' readonly id='cgstamt$i' value='$jrow[cgstamt]' onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=6 name='sgstp[]' readonly id='sgstp$i' value='$result[tax_sgst]'  onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=6 name='sgstamt[]' readonly id='sgstamt$i' value='$jrow[sgstamt]' onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=6 name='cessamtl[]' readonly id='cessamtl$i' value='$jrow[hredutx]' onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=8 readonly name='tot[]' id='tot$i' value='$jrow[tot]'></td>";
   print "<td><input type=button value='Del' onClick='delrow2(this)'></td>";
   print "<td><input type=text  readonly name='engineer1[]' id='engineer1$j' value='$jrow[engineer]' size=20></td>";
   //******To Passing
   print "<input type=hidden name='igstp[]' id='igstp$i' value='0' >";
   print "<input type=hidden name='igstamt[]' id='igstamt$i' value='0'>";
   print "<input type=hidden  id='flgs$i' value='flg'>";
   }
      else
      {
          
   print "<td><input type=text size=6 name='igstp[]' readonly id='igstp$i' value='$result[tax_igst]' onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=6 name='igstamt[]' readonly id='igstamt$i' value='$jrow[igstamt]' onChange='calctotal2($i)'></td>";
   print "<td><input type=text size=8 readonly name='tot[]' id='tot$i' value='$jrow[tot]'></td>";
   print "<td><input type=button value='Del' onClick='delrow2(this)'></td>";
   print "<td><input type=text  readonly name='engineer1[]' id='engineer1$j' value='$jrow[engineer]' size=20></td>";
   //******To Passing
   print "<input type=hidden name='cgstp[]' id='cgstp$i' value='0' >";
   print "<input type=hidden name='cgstamt[]' id='cgstamt$i' value='0'>";
   print "<input type=hidden name='sgstp[]' id='sgstp$i' value='0'>";
   print "<input type=hidden name='sgstamt[]' id='sgstamt$i' value='0'>";
   print "<input type=hidden  id='flgs$i' value='flg1'>";
      }

 
 print "</tr>";
   $i++;
  }
 
?>
</table><br>
<table width=100%>
<tr bgcolor='#AED69A'><td>Invoice Type <select name='invtype'>
<option>8b</option>
</select>&nbsp;&nbsp;&nbsp;
 Payment Type  <select name='ptype' id='ptype'> 
<option></option>
<option>Credit</option>
</select>
</tr>
<tr><td bgcolor='#AED69A' align=right colspan=4>
<input type=submit value='  U p d a t e f o r m  ' name='upd' style="font-size:15; font-weight:bold">
<input type=submit value='  U p d a t e &nbsp; f o r m  &nbsp; a n d  &nbsp; P r i n t  &nbsp;  B i l l  ' name='updprn' style="font-size:15; font-weight:bold">

</td></tr>
</table>
</span>
</form>
<?

$re11=mysqli_query($db,"select partcode,partname,hand_charge,cessonvat,cessonvat from partmaster order by partcode")or die('prt err:'.mysqli_error($db));
$i=1;
while($row=mysqli_fetch_array($re11))
{
 $prres=mysqli_query($db,"select lstprice,discount from spareprmast where partcode='$row[partcode]' order by effectfrom desc limit 1");
 $prrow=mysqli_fetch_array($prres);

$stkres=mysqli_query($db,"select * from $tbl where partcode='$row[0]'");
$stkrow=mysqli_fetch_array($stkres);
if(mysqli_num_rows($stkres)>0)
 print "\n <script> exq[$i]='$stkrow[supqty]'</script>";
else
 print "\n <script> exq[$i]='0'</script>";

 print "\n <script>partcode[$i]='$row[0]'; partname[$i]='$row[1]'; lstprice[$i]='$prrow[0]';";
 print "\n handp[$i]='0'; conv[$i]='$row[cessonvat]'; discar[$i]='0'; ";
 print "\n cessar[$i]='$row[cessonvat]'; </script>";
 $sql12=mysqli_query($db,"select * from taxmaster where tax='$row[gst]'");
$row12=mysqli_fetch_array($sql12);
 
  print "\n <script>cgstper[$i]='$row12[tax_cgst]'; sgstper[$i]='$row12[tax_sgst]'; igstper[$i]='$row12[tax_igst]'; </script>";

 $i++;
}
return;
}

echo "test";
?>
<CENTER>
<H3><font color='darkbrown'>JOB CARD REPORT / EDIT</font></h3>
</center>
<form name=f1 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>
Select Jobcard No. <select name=jcno>
<?
$re=mysqli_query($db,"select jcno,msno,closed from jobcard where brcode='$brcode' and jvno<=0 ");
while($row=mysqli_fetch_row($re))
{
    if($row[2]=='Y')
        $a=0;
    else
        print "<option value='$row[0]'>$row[0]-$row[1]</option>";
}
?>
</select><td>
<select name=intr><option>INTRASTATE</option><option>INTERSTATE</option></select></td>
<input type=submit value='Show ->' name='show'>
</form>
<script>
 function valid1()
 {
  if(document.f1.jcno.value.length<=0)
   {
    alert('Invalid jcno');
    return false
   }
 }
</script>
