<?
session_start();
//include_once("../includes/top.php");
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../inde.php'; </script>";
 return;
}
$jvno=$_REQUEST['jvno'];
$dt=$_REQUEST['dt'];
$d=$_REQUEST['dfd1'];
$m=$_REQUEST['dfm1'];
$y=$_REQUEST['dfy1'];
$d1=$_REQUEST['dtd1'];
$m1=$_REQUEST['dtm1'];
$y1=$_REQUEST['dty1'];
date_default_timezone_set("Asia/Kolkata");
?>
<? //include_once('../accounts/top.php'); ?>
<br>
<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");
include_once("includes/top.php");
//print $d;
//print $m;
$r=mysqli_query($db,"select 	acpass2 from branch ");
 $pu=mysqli_fetch_array($r);


$pwd=$_REQUEST['pswd'];

if(isset($_POST['del']))


{

if($pwd=='delpro')

{
    $ree=mysqli_query($db,"select against from journal2 where jvno='$jvno' and brcode='$brcode' and against='done'")or die(mysqli_error($db));
$j_rowe=mysqli_fetch_array($ree);

if(mysqli_num_rows($ree)>0)
{
//print " Branch clearing entry cannot be deleted";
//return;

}
    
    
    
    $sqins="insert into journal2deljour(select * from journal2 where jvno='$jvno' and brcode='$brcode' )";
mysqli_query($db,$sqins)or die(mysqli_error($db));

$re=mysqli_query($db,"select j_type,no,tr_no from journal2 where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
$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' and j_type='$j_row[j_type]'";
mysqli_query($db,$sq)or die(mysqli_error($db));

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

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


if($j_row['j_type']=='JC Spare Invoice')
  {
    mysqli_query($db,"delete from jobcard where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
    mysqli_query($db,"delete from jcardparts where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
mysqli_query($db,"delete from jcardserv where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));

  }
  
  
  if($j_row['j_type']=='Spare Invoice')
  {
    mysqli_query($db,"delete from spareinvoice where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  if($j_row['j_type']=='Spare sale ret')
  {
    mysqli_query($db,"delete from salesretnew where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  
  if($j_row['j_type']=='Wty coupon Invoice P')
  {
    mysqli_query($db,"delete from warcouponinvoicepassey where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  if($j_row['j_type']=='GST Expense')
  {
      print $j_row['j_type'];
    mysqli_query($db,"delete from gst_expense where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  
  if($j_row['j_type']=='GST Expense Rev')
  {
      print $j_row['j_type'];
    mysqli_query($db,"delete from gst_expenserev where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  
  
  if($j_row['j_type']=='GST Income')
  {
      print $j_row['j_type'];
    mysqli_query($db,"delete from gst_income where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  
  
  
  if($j_row['j_type']=='GST Income inv')
  {
      print $j_row['j_type'];
    mysqli_query($db,"delete from gst_incomecust where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  if($j_row['j_type']=='Spare Pur')
  {
    mysqli_query($db,"delete from sparepurchase where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  if($j_row['j_type']=='eich')
  {
    mysqli_query($db,"delete from eicherpurchase  where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  
  if($j_row['j_type']=='CR NOTE')
  {
    mysqli_query($db,"delete from crnote where j_type='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
  }
  if($j_row['j_type']=='CR')
  {
    mysqli_query($db,"delete from cshrec where j_type='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
  }
  if($j_row['j_type']=='CP')
  {
    mysqli_query($db,"delete from cshpay where j_type='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
  }
  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($db));
    $sql="delete from bnkrec where j_type='$jvno' and brcode='$brcode'"; 
    mysqli_query($db,$sql)or die(mysqli_error($db));
  }
  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($db));
    $sql="delete from bnkpay where j_type='$jvno' and brcode='$brcode'"; 
    mysqli_query($db,$sql)or die(mysqli_error($db));
  }
  
   if($j_row['j_type']=='Spare Invoice Other')
  {
    mysqli_query($db,"delete from spareinvoice_oth where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
   if($j_row['j_type']=='Service Invoice')
  {
    mysqli_query($db,"delete from spareinvoice_lab where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  if($j_row['j_type']=='Spare Pur Eich')
  {
    mysqli_query($db,"delete from sparepurchase where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
 
  if($j_row['j_type']=='Spare trans out')
  {
    mysqli_query($db,"delete from sparetransout  where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  if($j_row['j_type']=='Spare trans out agt')
  {
    mysqli_query($db,"delete from sparetransout  where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  } 
  if($j_row['j_type']=='Spare trans in agt')
  {
    mysqli_query($db,"delete from sparetransin  where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  if($j_row['j_type']=='Acs trans out')
  {
    mysqli_query($db,"delete from sparetransoutexcess  where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  if($j_row['j_type']=='I pur')
  {
    mysqli_query($db,"delete from item_purchase_veh where jvno='$jvno' and brcode='$brcode'")or die(mysqli_error($db));
   
  }
  
  
log_entry($brcode,$user,"$jvno|Del $j_row[j_type] Journal|Del","Del $j_row[j_type] Journal - $jvno",$db);
print "<font color=green>Data has been deleted</font><br>";
echo "<script>document.location='db2.php?d=$d&m=$m&y=$y&d1=$d1&m1=$m1&y1=$y1';</script>";
}// end if pswd
else
{
 print "Invalid Password";
}
}
?>


