<?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_expense_detail 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);
			
			 	$expensemmid=$rt['expensemmid'];
			 	$expno=$rt['expno'];
				
				
				$uedit="<a href='expensemanagementedit.php?id=".$rt['expensemmid']."'data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg' >  </a>";
			
				$udelete="<a href='expensemanagementdelete.php?id=".$rt['expensemmid']."' 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='expensemanagementdetail.php?id=".$rt['expensemmid']."'data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg' >  </a>";
				
				$op=$view."&nbsp;&nbsp;&nbsp; ".$uedit."&nbsp;&nbsp;&nbsp; ".$udelete;
				
				$expensetype=$rt['expensetype'];

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

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

				{											
																				
				while($rt1 = mysqli_fetch_assoc($re1))
				{
					$partyname=$rt1['partyname'];
						
				}
																				 
				}
					
				$expfordisplay=$rt['expfordisplay'];
				$expensedate=implode('-', array_reverse(explode('-', $rt['expensedate'])));
				$expenseremark=$rt['expenseremark'];
				$expenseamount=$rt['expenseamount'];
				$paymentmode=$rt['paymentmode'];
				$paymentdetail=$rt['paymentdetail'];
				
				$posts[] = array('srno'=> $i++, 'expensetype'=> $partyname,'expensedate'=> $expensedate,'expenseremark'=> $expenseremark, 'expenseamount'=> $expenseamount,  'paymentmode'=> $paymentmode,'paymentdetail'=>$paymentdetail,'expfordisplay'=>$expfordisplay, '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);	
?>