<?php
	session_start();

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}

	include("connect.php");
	
	$pddid=(int)mysqli_real_escape_string($conn,$_GET['id']);
	
	$imid=$_GET['p3'];
	
	$evepay = "select isdid,paidamount from res_payments_detail where pddid=$pddid";
	$repay = mysqli_query($conn, $evepay);
	while($rtpay = mysqli_fetch_assoc($repay))
	{
		$isdid=$rtpay['isdid'];
		$paidamount=$rtpay['paidamount'];
	}
	
	$evepay1 = "select isreceviedamt from res_inquiryservice_detail where isdid=$isdid";
	$repay1 = mysqli_query($conn, $evepay1);
	while($rtpay1 = mysqli_fetch_assoc($repay1))
	{
		$isreceviedamt=$rtpay1['isreceviedamt'];
	}
	
	 $eve2 = "update res_inquiryservice_detail set isreceviedamt= isreceviedamt-$paidamount,ispendingamount=ispendingamount+$paidamount where isdid=$isdid";

	$re2 = mysqli_query($conn, $eve2);
	
    $query="delete from res_payments_detail where pddid=$pddid";
	$result= mysqli_query($conn, $query) or die("Error");
		
	$_SESSION['msg'] = "Record deleted successfully";
	header("Location:  inquirydetail.php?id=$imid#student_detail");
?>