<?php
    
    include'connection.php';
    
    $userid = $_GET['userid'];
	$token = $_GET['token'];
	
	$quGetEwalletId="select * from RetBal where Userid='$userid'";
    $reGetEwalletId=mysqli_query($con,$quGetEwalletId);
    $dataGetEwalletId=mysqli_fetch_array($reGetEwalletId);
    $EwalletId=$dataGetEwalletId['Walletid'];
    
	$QuGetUser = "select * from retailer where Userid='$userid' and ApiToken='$token'";
	$ReGetUser = mysqli_query($con,$QuGetUser);
	$GetUser = mysqli_num_rows($ReGetUser);
	
	if($GetUser!==1)
	{    
		$myresponse = array("bal"=>"Invalid Userid Or API Token !");
		echo $myresult = json_encode($myresponse);
	}
	else
	{
	    $queryNewBal="select * from wallet where Userid='$userid' and Id>=$EwalletId";
	    $resultNewBal=mysqli_query($con,$queryNewBal);
	    $newbal=0;
	    while($dataNewBal=mysqli_fetch_array($resultNewBal))
	    {
	        $Retbal= $dataNewBal['Txn'];
	        $newbal=$newbal+$Retbal;
	    }
		
		$myresponse = array("bal"=>"$newbal");
		echo $myresult = json_encode($myresponse);
	}

?>