<?
 session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
include("../test.php");
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
th{background-color:green;color:white}
.mnu{margin-left:5}
</style>
<body bgcolor='ivory'>

<center>
<form action='<?print $PHP_SELF?>'>
<table>
<th colspan=2>Change Supplier</th>
<tr><td>Enter Da </td><td><input type=text name='da' value='<?print $da?>'></td></tr>
<tr><td colspan=2><center><input type=submit value='Next ->' name='go'></td></tr>
</table>
</form>
<?
if($go)
{
 $re=mysqli_query($db,"select * from veh_purchase where da='$da' and brcode='$brcode'");
 if(mysqli_num_rows($re)<=0)
 {
   print "<font color=red> DA Not found </font>";
    return;
 }
 $row=mysqli_fetch_array($re);
 print "<form action='$PHP_SELF'>\n<input type=hidden name='da' value='$da'>";
 print "<input type=hidden name='jvno' value='$row[jvno]'>";
 print "<table border=1>\n<tr><td>Current Supplier</td><td><select name='suppold'>";
  print "<option>$row[ledger]</option>";
 print "<tr><td>New Supplier </td><td>\n<select name='suppnew'>";
 $re1=mysqli_query($db,"select * from sup_master where branch='$brcode' order by supname");
  while($suprow=mysqli_fetch_array($re1))
  {
     print "\n<option>$suprow[supname]</option>";
  }
 print "</select></td></tr>";
 print "<tr><td colspan=2 align=center><input type=submit value='Change' name='ch'></td> </tr></table></form>";
}

if($ch)
{
 print 'changing ..'.$da;
 $sql="update veh_purchase set ledger='$suppnew' where da='$da' and brcode='$brcode'";
 mysqli_query($db,$sql) or die(mysqli_error());
 $sql="update journal2 set partic='$suppnew' where jvno='$jvno' and type='Cr' and brcode='$brcode'";
 mysqli_query($db,$sql) or die(mysqli_error());
 print "<br><font color=green> Done.</font>";
}
?>
