<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
date_default_timezone_set("Asia/Kolkata");
$jvno=$_REQUEST['jvno'];
$dt=$_REQUEST['dt'];
if(($user=='mathew')||($user=='sreejith')||($user=='shameem')||($user=='vibin')||($user=='minosh'))
{
?>
<form action='<?print $PHP_SELF?>' method='POST'>
<input type=hidden name=jvno value='<?print $jvno?>'>
<input type=hidden name=dt value='<?print $dt?>'>
<table>
<tr><td>Enter password </td><td><input type=password name='pswd'></td>
    <td><input type=submit value='Del' name='del'></td>
</tr>
</table>
</form>
<?
include("../opendb.php");
include("../test.php");

//if($del && $pswd=='del')
if(isset($_POST['del']))
{
 $pswd=$_REQUEST['pswd'];
if($pswd=='del')
{
$re=mysqli_query($db,"select j_type,no,tr_no from journal2 where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error());
$j_row=mysqli_fetch_array($re);
$upddatetime=date('Y-m-d H:i:s');
$jvqry=mysqli_query($db,"select * from journal2 where jvno='$jvno' and brcode='$brcode'")or die('Led Post Err1'.mysqli_error($db));
    while($jvqryrw=mysqli_fetch_array($jvqry))
    {
        $jvsql="insert into journal2_log(date,jvno,type,partic,dramt,cramt,narr,brcode,j_type,against,no,tr_no,user,entrytime,action) values('$jvqryrw[date]','$jvqryrw[jvno]','$jvqryrw[type]','$jvqryrw[partic]','$jvqryrw[dramt]','$jvqryrw[cramt]','$jvqryrw[narr]','$brcode','$jvqryrw[j_type]','$jvqryrw[against]','$jvqryrw[no]','$jvqryrw[tr_no]','$user','$upddatetime','Del $j_row[j_type] Journal - $jvno -$j_row[narr]')";
        mysqli_query($db,$jvsql);
    }

$sq="delete from journal2 where jvno='$jvno' and brcode='$brcode'";
mysqli_query($db,$sq)or die(mysqli_error());

  if($j_row['j_type']=='CR Note')
  {
    mysqli_query($db,"delete from crnote where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error());
  }
  if($j_row['j_type']=='CR')
  {
    mysqli_query($db,"delete from cshrec where j_type='$jvno' and brcode='$brcode'")or die(mysqli_error());
  }
  if($j_row['j_type']=='CP')
  {
    mysqli_query($db,"delete from cshpay where j_type='$jvno' and brcode='$brcode'")or die(mysqli_error());
  }
  if($j_row['j_type']=='BR')
  {
     $drr=mysqli_query($db,"select brec_date from bnkrec where j_type='$jvno' and brcode='$brcode'");
      $rec_row=mysqli_fetch_row($drr) or die(mysqli_error());
    $sql="delete from bnkrec where j_type='$jvno' and brcode='$brcode'"; 
    mysqli_query($db,$sql)or die(mysqli_error());
  }
  if($j_row['j_type']=='BP')
  {
     	$drr=mysqli_query($db,"select brec_date from bnkpay where j_type='$jvno' and brcode='$brcode'");
      	$rec_row=mysqli_fetch_row($drr) or die(mysqli_error());
    	$sql="delete from bnkpay where j_type='$jvno' and brcode='$brcode'"; 
    	mysqli_query($db,$sql)or die(mysqli_error());
	$sql="delete from chq_det where jvno='$jvno' and brcode='$brcode'"; 
    	mysqli_query($db,$sql)or die(mysqli_error());
  }
  $ip_details="$jvno|".$j_row['j_type']."|Add";
log_entry($brcode,$user,$ip_details,"Del $j_row[j_type] Journal - $jvno",$db);
print "<font color=green>Data has been deleted</font><br>";
}// end if pswd

else
{
 print "Invalid Password";
}
?>

<?
}
}
?>
