<?
session_start();
$brcode = $_SESSION['brcode'];
if(strlen($brcode)<=0)
{
    print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
    return;
}
include("../opendb.php");
include("../test.php");
$purno = $_REQUEST['purno'];
print 'Pur no:'. $purno;
$upd = $_REQUEST['upd'];
$pd = $_REQUEST['pd'];
$py = $_REQUEST['py'];
$pm = $_REQUEST['pm'];
$sup = $_REQUEST['sup'];
$pbillnonew = $_REQUEST['pbillnonew'];
$pbillno = $_REQUEST['pbillnonew'];
$ttype = $_REQUEST['ttype'];
$purdate=$py.'-'.$pm.'-'.$pd;
$jvno = $_REQUEST['jvno'];
$oldsup = $_REQUEST['oldsup'];
if($upd)
{
  
    $sql="update sparepurchase set suplier='$sup',pbillno='$pbillnonew',purdate='$purdate' where purno='$purno' and brcode='$brcode' and pbillno='$pbillno' and taxtype='$ttype'";
    //print $sql;
    mysqli_query($db,$sql) or die(mysqli_error($db));
    $sql="update journal2 set partic='$sup' where jvno='$jvno' and partic='$oldsup' and brcode='$brcode' and type='Cr'";
    //print $sql;
    mysqli_query($db,$sql) or die(mysqli_error($db));
    print "Record has been saved";
    return;
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:lightsteelblue;color:black}
//tr{background-color:white}
</style>
<center>
<?
$sq="select pbillno,jvno,suplier,purdate from sparepurchase where purno='$purno' and brcode='$brcode' and taxtype='$ttype'";

$res=mysqli_query($db,$sq)or die(mysqli_error($db));
$prow=mysqli_fetch_array($res);
?>
<form action='<?print $PHP_SELF?>' name='f1'>
<input type=hidden name='purno' value='<?print $purno?>'>
<input type=hidden name='jvno' value='<?print $prow[1]?>'>
<input type=hidden name='ttype' value='<?print $ttype?>'>
<table border=0 bgcolor='steelblue' cellspacing=1 cellpadding=3>
<tr><td colspan=3><font color=white><b><center>EDIT PURCHASE <?PRINT $purno?></td></tr>
<tr bgcolor=white><td>Purchase Date</td>
<?
$p1=explode('-',$prow[purdate]);
?>
<td>dd <input type=text name='pd' size=2 value='<?print $p1[2]?>'>
mm <input type=text name='pm' size=2 value='<?print $p1[1]?>'>
yy <input type=text name='py' size=4 value='<?print $p1[0]?>'>
</td></tr>

<tr bgcolor=white><td>P Bill No Old</td>
<td><input type=text readonly name='pbillno' value='<?print $prow[0]?>'>
</td></tr>
<tr bgcolor=white><td>P Bill No New</td>
<td><input type=text  name='pbillnonew' value='<?print $prow[0]?>'>
</td></tr>

<tr bgcolor=white><td>Old Supplier </td>
<td><input type=text readonly name='oldsup' value='<?print $prow[2]?>' size=40>
</td></tr>

<tr bgcolor=white><td> Select Supplier </td><td>
<select name='sup'>
<?
$re=mysqli_query($db,"select supname from sup_master where branch='$brcode' order by supname");
while($row=mysqli_fetch_row($re))
{
 print "\n<option>$row[0]</option>";
}
?>
</select></td>
<td><input type=submit value='Update' name='upd'></td></tr>
</table>
