<?php
session_start();
include('connect.php');
error_reporting(0);
$cmpmid = $_SESSION['linkarisecmpmid'];
if(isset($_POST["partymid"]) && !empty($_POST["partymid"])){
    //Get all city data
   
$partymid = $_POST['partymid'];


$eve="SELECT * FROM res_booking_master WHERE cmpmid=$cmpmid and partymid= ".$partymid;

    $re = mysqli_query($conn, $eve);
//echo '<option value="'.$eve.'">'.$eve.'</option>';
    //Count total number of rows
    if(mysqli_num_rows($re) > 0)
{
echo '<option value="0">Select Reference ID</option>';
        while($rt = mysqli_fetch_assoc($re)){
			
			$bookingmid=$rt['bookingmid'];
			$spotmid=$rt['spotmid'];
		
			$bookingdate=$rt['bookingdate'];
			$bookingtotalamount=$rt['bookingtotalamount'];
			$eve41 = "select sum(bookingreceivedamount) as receiptamont from res_bookingpayment_detail where bookingmid=$bookingmid";

										$re41 = mysqli_query($conn, $eve41);
										$receiptamont=0;
										while($rt41 = mysqli_fetch_assoc($re41))

										{		
											$receiptamont=$rt41['receiptamont'];
											
										}
										
										
				$eve21 = "select * from res_spot_master where spotmid ='$spotmid'";

				$re21 = mysqli_query($conn, $eve21);
																			
				if(mysqli_num_rows($re21) > 0)

				{											
																				
				while($rt21 = mysqli_fetch_assoc($re21))
				{
					$spotname=$rt21['spotname'];
					
						
				}
																				 
				}
				
										$pendingamount=$bookingtotalamount-$receiptamont;
										if($pendingamount>0){
										echo '<option value="'.$rt['bookingmid'].'">'.$bookingmid.'-'.$spotname.'('.$bookingdate.')'.'</option>'; }
										else {}

        }
    }else{
        echo '<option value="0">No Data Found</option>';
    }
}
?>