<?php

    function getName($usrId)
    {   
	    include'connection.php';
	    $usrDigit=substr($usrId,0,2);
	    
	    if(empty($usrDigit))
	    {
	        $retName=" ";
	        return($retName);
	    }
	    elseif($usrDigit==11 || $usrDigit==22)
	    {
	        $retName="ADMIN";
	        return($retName);
	    }
	    else
	    {
	        if($usrDigit==50)
	        {
	            $quGetName="SELECT * FROM retailer WHERE Userid='$usrId'";  
	        }
	        elseif($usrDigit==20)
	        {
	            $quGetName="SELECT * FROM distributer WHERE Userid='$usrId'";
	        }
	        elseif($usrDigit==30)
	        {
	            $quGetName="SELECT * FROM masterdis WHERE Userid='$usrId'";
	        }
	        
	        $reGetName=mysqli_query($con,$quGetName);
            $dataGetName=mysqli_fetch_array($reGetName);
            $retName=$dataGetName['Name'];
            return($retName);
	    }
    }

    function getBal($usrId)
    {
        include'connection.php';
        $quGetEwalletId="select * from RetBal where Userid='$usrId'";
        $reGetEwalletId=mysqli_query($con,$quGetEwalletId);
        $dataGetEwalletId=mysqli_fetch_array($reGetEwalletId);
        $EwalletId=$dataGetEwalletId['Walletid'];
    
        $quDisOpBal="select * from wallet where Userid='$usrId' and Id>=$EwalletId";
	    $reDisOpBal=mysqli_query($con,$quDisOpBal);
	    $Bal=0;
	    while($dataDisOpBal=mysqli_fetch_array($reDisOpBal))
	    {
	       $OldDisTxn= $dataDisOpBal['Txn'];
	       $Bal=$Bal+$OldDisTxn;
	    }
	    return($Bal);
    }
?>