<?
session_start();
$brcode = $_SESSION['brcode'];
$level  = $_SESSION['level'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<html>
<head>
<title>Psn Eicher</title>
<link type="text/css" href="../includes/style1.css" rel="stylesheet" />
<link rel="stylesheet" href="../style.css" type="text/css" />
<link rel="stylesheet" href="../css/form.css" type="text/css" />
<link href="../css/pagination.css" rel="stylesheet" type="text/css" />
<link href="../css/grey.css" rel="stylesheet" type="text/css" />

<style>
th{background-color:lightsteelblue;color:black}
//tr{background-color:white}
</style>
<script type="text/javascript">
$(function() {
  $('.nyroModal').nyroModal();
});
</script>
<style>
    input
    {
    width: 100px;
    }
</style>
<center>
<h1>Purchase Update</h1>

<?

$sql1="select distinct purno,suplier,entrydate,porderno,taxtype,jvno,grno from sparepurchase where pbillno IS NULL and brcode='$brcode' order by grno";

//$sql1="select distinct pbillno, purno,suplier,entrydate,porderno,taxtype from sparepurchase where entrydate>='$dfrom' and entrydate<='$dto' and brcode='$brcode' and taxtype='vat' order by purno";
 $re1=mysqli_query($db,$sql1)or die(mysqli_error($db));

print "<form method=post action=upd_vendorinv.php><table border=0 bgcolor='steelblue' cellspacing=1 cellpadding=3 class=report>";
print "<th>PNo<th>Supplier<th>Entry Date<th>Before Tax<th>Tax<th>Hnd Chgs<th>Total<th>Gr No<th>PBill No<th>Invoice Type<th>";
if($level==4)
 print "<th colspan=2>Action";
$i=1;
 while($row1=mysqli_fetch_array($re1))
 {
 $sql="select sum(supqty),sum(aprice) aprice, sum(hand) hand,sum(taxamt) tax, sum(cessamt) cessamt,sum(tot) tot from sparepurchase where pbillno IS NULL and purno='$row1[purno]' and brcode='$brcode'";

 $re=mysqli_query($db,$sql) or die(mysqli_error($db));

while($row=mysqli_fetch_array($re))
{
 print "\n<tr bgcolor='white' onMouseOver=bgColor='silver'; onMouseOut=bgColor='white'>";
 print "<input type=hidden name=purno[$i] value=$row1[purno]>";
 print  "<td>$row1[purno]</td><td>$row1[suplier]</td>";
 print "<td>".datetohtml($row1[entrydate])."</td> ";
 print "<td align=right>$row[aprice]</td><td align=right>$row[tax]</td>";
 print "<td align=right>$row[hand]</td><td align=right>$row[tot]</td><td>$row1[grno]</td><td><input type=text name=pbillno[$i] value=$row1[pbillno]></td><td>";
 print "<select name='taxtype[$i]' size=1>";
?>
<option>VAT</option>
<option value="CST">CST</option>
<option value="UNREG">UNREG</option>
<option value="8B">FORM 8B</option>
</select></td>
 
 <?
 print "<td><input type=submit value='Upd' name='upd' onClick=position_fix(".$i.")></td>";


 print "\n</tr>";
 $gtot+=$row[tot];
 $i++;
}

}
print "<tr><input type='hidden' name='pos' value='' id='pos'/><td colspan=6 align=right><b>Total</td><td align=right>".putComa($gtot)."</td><td colspan=6></td>";
print "</form></table><br> <hr>";

?>
<script>
function edfun(x,y)
{
 if(confirm('Do you want to edit P.O. No.'+x+' ?'))
  document.location='edpur.php?purno='+x+'&ttype='+y;
}
function edfun1(x,y,jvno)
{
 if(confirm('Do you want to edit P.O. No.'+x+' ?'))
  window.open('edpurvat.php?purno='+x+'&ttype='+y+'&jvno='+jvno);
}
function delfun(x,y)
{
 if(confirm('Do you want to Delete P.O. No.'+x+' ?'))
  document.location='delpur.php?purno='+x+'&ttype='+y;
}
</script>
<script>
function position_fix(str){
document.getElementById('pos').value=str;
alert('do you want to update...!!!');
}
</script>
