<?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_grn_master WHERE cmpmid=$cmpmid and suppliermid= ".$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)){
			
			$grnmid=$rt['grnmid'];
			$grnfordisplay=$rt['grnfordisplay'];
			$grndate=$rt['grndate'];
			$grnnetamount=$rt['grnnetamount'];
			$eve41 = "select sum(outamount) as outamount from res_paymentout_master where outrefrenceid=$grnmid";

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

										{		
											$outamount=$rt41['outamount'];
											
										}
										$pendingamount=$grnnetamount-$outamount;
										if($pendingamount>0){
										echo '<option value="'.$rt['grnmid'].'">'.$grnfordisplay.'  '.$grndate.'</option>'; }
										else {}

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