<?
session_start();
include("../opendb.php");
$res=mysqli_query($db,"select * from veh_purchase where da='$da'")or die(mysqli_error());
$purrow=mysqli_fetch_array($res);
print "rows=".mysqli_num_rows($res);
 if(mysqli_num_rows($res)>1)
  {
    print "<script> alert('Exiting, Found more than one DA');</script>";
    return;
  }

$jvres=mysqli_query($db,"select jvno from veh_purchreturn where da='$da'");
$jvres_row=mysqli_fetch_row($jvres);
if(mysqli_num_rows($jvres)>0)
 mysqli_query($db,"delete from journal2 where jvno='$jvres_row[0]' and brcode='$brcode'")  or die(mysqli_error());
else
 {
   print "<script> alert('Invalid Journal Number');</script>";
   return;
 }

 mysqli_query($db,"delete from veh_purchreturn where da='$da' and brcode='$brcode'") or die(mysqli_error());
 mysqli_query($db,"delete from veh_movement where da='$da' and type='pur_ret' and brcode='$brcode'") or die(mysqli_error());
 mysqli_query($db,"update veh_purchase set sale_invoice='-',type='eich' where da='$da' and brcode='$brcode'") or die(mysqli_error());
 mysqli_query($db,"update vehopstock set sold='-',transtype='-' where dano='$da' and brcode='$brcode'") or die(mysqli_error());
?>
<script>
 document.location='purch_ret.php';
</script>

 
