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

include("../opendb.php");
include("../test.php");
print 'Branch Code:'.$brcode;
$del=$_REQUEST['del'];
$pswd=$_REQUEST['pswd'];
if($del && $pswd=='del')
{
$jcno=$_REQUEST['jcno'];
 $r1=mysqli_query($db,"select jvno from jobcard where jcno='$jcno'  and brcode='$brcode'");
 if(mysqli_num_rows($r1)<=0)
 {
  print "JCNO does not exist";
  return;
 }
 $row1=mysqli_fetch_array($r1);
 $sql="delete from journal2 where jvno='$row1[jvno]' and no='$jcno' and brcode='$brcode'";
  mysqli_query($db,$sql) or die(mysqli_error($db));
 $sql="update jobcard set jvno='0',invno='0',entrydate='0000-00-00' where jcno='$jcno' and brcode='$brcode'";
  mysqli_query($db,$sql) or die(mysqli_error($db));
  $sql="update jcardparts set jvno='0',invno='0' where jcno='$jcno' and brcode='$brcode'";
  mysqli_query($db,$sql) or die(mysqli_error($db));
  $sql="update jcardserv set jvno='0',invno='0' where jcno='$jcno' and brcode='$brcode'";
  mysqli_query($db,$sql) or die(mysqli_error($db));
log_entry($brcode,$user,$REMOTE_ADDR,"Del Jobcard:$jcno, Journal: $jvno",$db);
print "<b>Record has been deleted</b>";
}
?>
<style>
 td,body{font-family:'arial narrow';font-size:14;letter-spacing:1}
</style>
<center>
<table cellspacing=1 cellpadding=1 bgcolor=red>
<tr><td align=center><font size=5>Cancel a Job Card</font></td></tr>
<tr><td align=center bgcolor=white>


<form action='<?print $PHP_SELF?>' method='post'>
<table>
<tr><td>Enter Password </td><td><input type=password name='pswd'></td></tr>
<tr><td>Enter JCNo </td><td><input type=text name='jcno'></td></tr>
<tr><td colspan=2 align=center bgcolor='orange'><input type=submit value='Delete' name='del'></td></tr>
</table>
</form>
</td></tr>
</table>
