<?php  
session_start(); 
	include("connect.php");	
	include("connectp.php");
	header("Access-Control-Allow-Origin: *");


	$brmid = $_SESSION['linkarisebranchid'];
	$cmpmid = $_SESSION['linkarisecmpmid'];
	$umid = $_SESSION['linkariseumid'];	
	
		$q = $db7->prepare("select * from res_paymentout_master where cmpmid=$cmpmid ");
	//$q->bindValue(':p1', "$par1");
	//$q->bindValue(':p2',  "$par2");
	$q->execute();

	$response = array();
	$posts = array();
	
	$result="0";
	
	if ($q->rowCount() > 0)
	{
		$i=1;
		while($i<=$q->rowCount())
		{
			$rt = $q->fetch(PDO::FETCH_ASSOC);
			
			 	$payoutno=$rt['payoutno'];
			 	$paymentoutmid=$rt['paymentoutmid'];
				
				
				/* $uedit="<form action='paymentoutedit.php' method='post' style='flex: 1; margin-right: 2px;'><button  class='fa fa-edit fa-lg' name='paymentoutmid' type='submit' value='$paymentoutmid'></button></form>";
			
				$udelete="<form action='paymentoutdelete.php' method='post' style='flex: 1; margin-right: 2px;'><button  class='fa fa-trash-o fa-lg' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' name='payoutno' type='submit' value='$payoutno'></button></form></div>";
				
				$view="<div style='display: flex; flex-direction: row;'><form action='paymentoutdetail.php' method='post' style='flex: 1; margin-right: 2px;'><button  class='fa fa-eye fa-lg' name='paymentoutmid' type='submit' value='$paymentoutmid'></button></form>"; */
				
				$uedit="<a href='paymentoutedit.php?id=".$rt['paymentoutmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
			
				$udelete="<a href='paymentoutdelete.php?id=".$rt['payoutno']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";
				
				$view="<a href='paymentoutdetail.php?id=".$rt['paymentoutmid']."' data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg'>  </a>";
				
				$op=$view."&nbsp;&nbsp;".$uedit."&nbsp;&nbsp;".$udelete;
				
				$partymid=$rt['partymid'];

				$partyname='';
				
				$eve1 = "select * from res_party_master where partymid ='$partymid'";

				$re1 = mysqli_query($conn, $eve1);
																			
				if(mysqli_num_rows($re1) > 0)

				{											
																				
				while($rt1 = mysqli_fetch_assoc($re1))
				{
					$partyname=$rt1['partyname'];
						
				}
																				 
				}
					
				$outrefrenceid=$rt['outrefrenceid'];

				$grnfordisplay='';
				$grndate='';
				
				$eve2 = "select * from res_grn_master where grnmid ='$outrefrenceid'";

				$re2 = mysqli_query($conn, $eve2);
																			
				if(mysqli_num_rows($re2) > 0)

				{											
																				
				while($rt2 = mysqli_fetch_assoc($re2))
				{
					$grnfordisplay=$rt2['grnfordisplay'];
					$grndate=$rt2['grndate'];
						
				}
																				 
				}
				
				$payoutfordisplay=$rt['payoutfordisplay'];
				$outdate=implode('-', array_reverse(explode('-', $rt['outdate'])));
				$outamount=$rt['outamount'];
				$outmode=$rt['outmode'];
				$outdetail=$rt['outdetail'];
				$outrefrenceid=$grnfordisplay." ".'('.$grndate.')';
				
				$posts[] = array('srno'=> $i++, 'partymid'=> $partyname,'outrefrenceid'=> $outrefrenceid,'outdate'=> $outdate,'outamount'=> $outamount, 'outmode'=> $outmode, 'cmpmid'=> $cmpmid, 'outdetail'=> $outdetail,'payoutfordisplay'=>$payoutfordisplay, 'op'=> $op);
		}
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		//mysqli_close($conn);
		//return;
	}
	
   else
	{
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
	}
   
	mysqli_close($conn);	
?>