<?
session_start();
$brcode = $_SESSION['brcode'];
include("../opendb.php");
include("../test.php");
$jcno = $_REQUEST['jcno'];
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
//	tr{background-color:white}
	th{background-color:steelblue;color:white}
.right{text-align:right};
</style>
<script>
 function valid()
 {
   if(confirm('Do you want to save?'))
     return true;
   else
     return false;
 }
</script>

<?
$jcre=mysqli_query($db,"select * from jobcard where jcno='$jcno' and brcode='$brcode'");
$jcrow=mysqli_fetch_array($jcre);

$re=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
if(mysqli_num_rows($re)<=0)
{
  print "<script> alert('Parts does not exist in $jcno'); history.back(1); </script>";
  return;
}
$row=mysqli_fetch_array($re);
print "<form action='svsalereturnjc.php' method='post' onSubmit='return valid()'>";
print "<table border=1 cellspacing=1 cellpadding=3 ><th colspan=2>
<H3> SPARE SALES RETURN <br>JOB CARD</h3></TH>";
print "<tr><td>Invoice No. </td><td>$jcrow[invno]</td></tr>";

print "<tr><td>Payment Type </td><td>$jcrow[ptype]</td></tr>";
print "<tr><td>Customer </td><td>$jcrow[cname]</td></tr>";
print "<tr><td>MS No</td><td>$jcrow[msno]</td></tr>";
print "<tr bgcolor='yellow'><td>Entry Date</td><td>dd<input type=text name='d' size=2 maxlength=2 value='".date("d")."'> mm<input type=text name='m' size=2 maxlength=2 value='".date("m")."'> yy<input type=text name='y' size=4 maxlength=4 value='".date("Y")."'></td></tr>";

?>
</table>
<br>
<center>

<input type=hidden name='jcno' value='<?print $jcno?>'>
<input type=hidden name='invtype' value='JC'>
<input type=hidden name='customer' value='<?print $jcrow[cname]?>'>
<table border=1  id="myTable" >
<th> No <th>Part Code <th>Part Name  <th>Rate<th>Qty <th>Ret Qty<th>Amount <th>Disc <th>VAT
<th>CessP <th>Cessamt <th>Hand <th>Tax Amt <th>Gtot
<?
 $res=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
 $i=1;
 $j=100;
 while($jrow=mysqli_fetch_array($res))
  {
   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=calcamt2($j)> </td>";
   print "<td><input type=text size=4 readonly name='qty[]' id='qty$j' value='$jrow[qty]' ></td>";
   print "<td bgcolor='yellow'><center><input type=text size=4 name='retqty[]' id='retqty$j' value='0' onChange=calcamt2($j)></td>";

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

   print "<td><input type=text size=3 name='cessp[]' id='cessp$j' value='$jrow[cessp]' onChange=calcamt2($j)></td>";
   print "<td><input type=text size=5 name='cessamt[]' readonly id='cesamt$j' value='$jrow[cessamt]'></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 size=8 name='taxamt[]' readonly id='taxamt$j' value='$jrow[taxamt]'></td>";
   print "<td><input type=text size=8 name='gtot[]' id='gtot$j' value='$jrow[gtot]'></td>";
   print "</tr>";
   $i++;
   $j++;
  }
?>
<tr><td colspan=16 bgcolor='steelblue' align=center><input type=submit value='Save'></td></tr>
</table> 

</form>
<script>
function chkqty(x)
 {
   var qtyK='qty'+x.id; 

    if(parseFloat(document.getElementById(qtyK).value)<parseFloat(document.getElementById(x.id).value)){
     alert('Invalid Quantity');
document.getElementById(x.id).value='';
document.getElementById(x.id).focus();
     return;
}
 }


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

 var ele2='rate'+(y);
 var qele='retqty'+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;

handamt=0;
vatamt=0;

 var qty=document.getElementById(qele).value;
 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;
amt1+=cessamt;
document.getElementById(cessele).value=cessamt.toFixed(2);
document.getElementById(gtotele).value=amt1.toFixed(2);
}
</script>

