<?
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;
?>
<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 JCNo </td><td><input type=text name='jcno'></td></tr>
<tr><td colspan=2 align=center bgcolor='orange'><input type=submit value='View' name='view'></td></tr>
</table>
</form>
</td></tr>
</table>
<?
$view=$_REQUEST['view'];
if($view)
{
  $invno=$_REQUEST['jcno'];
  $res1=mysqli_query($db,"select * from jobcard where invno='$invno'  and brcode='$brcode'");
  if(mysqli_num_rows($res1)<=0)
  {
    print "<font color=red>JCNO does not exist</font>";
    return;
  }
  $row12=mysqli_fetch_array($res1);
  print "<form method='post'><center><table border=1>";
  print "<th>Jobcard No<th>Date<th>Customer<th>Jvno";
  print "<tr><td>$row12[invno] <input type=hidden name=invno value='$row12[invno]'> </td><td>$row12[date]</td>";
  print "<td>$row12[cname]</td><td>$row12[jvno]</td></tr>";
  print "<tr><td>Enter Password</td><td><input type=password name='pswd'></td><td></td><td></td></tr>";
  print "<tr><td colspan=4 align=center bgcolor='orange'><input type=submit value='Delete' name='del'></td></tr>";
  print "</table></form>";
} 
$del=$_REQUEST['del'];
$pswd=$_REQUEST['pswd'];
if($del && $pswd=='del')
{
$invno=$_REQUEST['invno'];    
 $r1=mysqli_query($db,"select invno,jvno from jobcard where invno='$invno'  and brcode='$brcode'");
 $row1=mysqli_fetch_array($r1);
 $sql1="delete from journal2 where jvno='$row1[jvno]' and no='$invno' and brcode='$brcode'";
 mysqli_query($db,$sql1) or die(mysqli_error($db));
  
  $sql2="delete from jobcard where invno='$invno' and brcode='$brcode'";
  mysqli_query($db,$sql2) or die(mysqli_error($db));
  
  $sql3="delete from jcardparts where invno='$invno' and brcode='$brcode'";
  mysqli_query($db,$sql3) or die(mysqli_error($db));
  
  $sql4="delete from jcardserv where invno='$invno' and brcode='$brcode'";
  mysqli_query($db,$sql4) or die(mysqli_error($db));
  
log_entry($brcode,$user,$REMOTE_ADDR,"Del Jobcard:$jcno, Journal: $jvno");
print "<b>Record has been deleted</b>";
}
?>

