<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
$rolemid = $_SESSION['userrolemid'];
$branchid = $_SESSION['branchid'];
	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	$eve = "select * from res_transfercash_detail group by branchmid";
	
	$re = mysqli_query($conn, $eve);	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		 while($rt = mysqli_fetch_assoc($re))
		 {
			 
				$tcdid=$rt['tcdid'];
				$tctransferto=$rt['tctransferto'];
				$tctransferamount=$rt['tctransferamount'];
				$tcremark=$rt['tcremark'];
				$branchname='';
				if($tctransferto== 'Branch')
				{
					$branchmid=$rt['branchmid'];
					$eveag1 = "select * from res_branch_master where branchmid=$branchmid";
				$reag1 = mysqli_query($conn, $eveag1);
				if(mysqli_num_rows($reag1) > 0)
				{
					while($rtag1 = mysqli_fetch_assoc($reag1))
					{
						$branchname=$rtag1['branchname'];
					}
				
				}
				
				}
				
				$totalin=0;
				$eve12 = "select sum(tctransferamount) as totalin from res_transfercash_detail where branchmid=$branchmid";
				$re12 = mysqli_query($conn, $eve12);
				if(mysqli_num_rows($re12) > 0)
				{
					while($rt12 = mysqli_fetch_assoc($re12))
					{
						$totalin=$rt12['totalin'];
					}
				
				}
				
				$totalout=0;
				$eve12 = "select sum(payamount) as totalout from res_pettycash_detail where branchmid=$branchmid";
				$re12 = mysqli_query($conn, $eve12);
				if(mysqli_num_rows($re12) > 0)
				{
					while($rt12 = mysqli_fetch_assoc($re12))
					{
						$totalout=$rt12['totalout'];
					}
				
				}
				
				
				$currentbal = $totalin - $totalout;
				$pidedit='';
				$currentfile1 = basename($_SERVER['PHP_SELF']);
				 $currentfile = ltrim($currentfile1, 'json');
							
				$aa = "<a href='#' data-bs-toggle='modal' data-id='".$branchmid."' data-bs-target='#kt_modal_close_meeting1' class='far fa-eye fa-lg' id='closemeeting1'></a>";
				$piddelete='';
				$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and madelete=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				
				$piddelete="<a href='cashdepositedelete.php?id=".$rt['tcdid']."'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>";
					}				
                $op=$piddelete;
								
								
			
								
				$posts[] = array('srno'=> $i++,'view'=> $aa, 'currentbal'=> $currentbal, 'branchname'=> $branchname);
		 }
		 
		$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);	
	
?>