<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php");
if($del && $pswd=='del')
{
 $sql="select jvno,saleordno from spareinvoice where invno='$invno' and invtype='$invtype' and vatorcst='$vatorcst' and brcode='$brcode'";
  $jvres=mysqli_query($db,$sql) or die(mysqli_error());
  $jvrow=mysqli_fetch_row($jvres);
//print $sql;
 $sql="delete from spareinvoice where invno='$invno' and invtype='$invtype' and vatorcst='$vatorcst' and brcode='$brcode'";
//print $sql;
mysqli_query($db,$sql) or die(mysqli_error());
$sq="delete from journal2 where jvno='$jvrow[0]' and narr like'%$invno%' and brcode='$brcode'";
//print $sq;
mysqli_query($db,$sq) or die('jv err'.mysqli_error());

$sq="update saleorder_spare set sqty='0',trans_type='',msno='' where orderno='$jvrow[1]' and brcode='$brcode'";
mysqli_query($db,$sq) or die('sord:'.mysqli_error()); 

log_entry($brcode,$user,$REMOTE_ADDR,"Del spareinvoice:$invno,invtype:$invtype,vatorcst:$vatorcst , Journal: $jvrow[0]");
print "<script> alert('Record has been deleted'); document.location='invrepo.php';</script>";
}
else 
 print "Invalid Password";

?>
<form action='<?print $PHP_SELF?>'>
<input type=hidden name='invno' value='<?print $invno?>'>
<input type=hidden name=invtype value='<?print $invtype?>'>
<input type=hidden name=vatorcst value='<?print $vatorcst?>'>

Enter Password <input type=password name='pswd'>
<input type=submit value='Del' name='del'>
</form>
 
