<?php
session_start();
ob_start();
 include "../config/config.php"; 
 include "../config/function.php"; 
 
//  print_r($_REQUEST);
 $private_key=get_privatekey($_SESSION['admin_name']);
 $request_from_server=$_SERVER['HTTP_REFERER'];
$this_server=$_SERVER['HTTP_HOST'];
if($request_from_server!=''){
	check_access_url($request_from_server,$this_server);
}

// echo $_SESSION['login_status'];echo "<br>";
// echo $_SESSION['private_key'];echo "<br>";
// echo $_SESSION['admin_name'];echo "<br>";

if($_SESSION['login_status']!='YES' || $_SESSION['private_key']!=$private_key || $_SESSION['private_key']=='' || $_SESSION['admin_name']=='')
{
    echo "Blank";
	header("Location:../AppLogin");
	exit();
}
else
{
 
echo "<br>". $emi_reference_no=trim($_REQUEST['emi_reference_no']);

   
    $resChk=mysqli_query($connection,"Select * from tbl_plot_emi_payment where emi_reference_no='$emi_reference_no' and closingstatus=0");
    if(mysqli_num_rows($resChk)==1)
    {
        $row=mysqli_fetch_array($resChk);
        $booking_random_no=$row['booking_random_no'];
        $member_user_id=$row['member_user_id'];
        $business_amt=$row['payment_amt'];
         mysqli_query($connection,"Delete From tbl_plot_emi_payment where emi_reference_no='$emi_reference_no'") or die(mysqli_error($connection));
    
    	$strb="Update tbl_plot_registry_booking set paid_amount=paid_amount-$business_amt,balance_amt=balance_amt+$business_amt where booking_random_no='$booking_random_no' and member_user_id='$member_user_id'";
        mysqli_query($connection,$strb) or die(mysqli_error($connection));
        
      	//Set Total Plot Collectio Percentage
        $strp="Update tbl_plot_registry_booking set payment_per=(paid_amount*100)/net_amount where booking_random_no='$booking_random_no' and member_user_id='$member_user_id'";
        mysqli_query($connection,$strp) or die(mysqli_error($connection));
    }
 }
header("location:../PendingEMIPayment");



?>