<?php

    function getName($usrId)
    {   
	    include'connection.php';
	    $usrDigit=substr($usrId,0,2);
	    $intCheck= is_int($usrId);
	    if($intCheck=1 || empty($usrId))
	    {
	        $retName="SELF";
	        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'";
	        }
	        else
	        {
	            $retName="";
                return($retName);
                exit();
	        }
	        
	        if($reGetName=mysqli_query($con,$quGetName))
	        {
                $dataGetName=mysqli_fetch_array($reGetName);
                $retName=$dataGetName['Name'];
                return($retName);
	        }
	        else
	        {
	            $retName="";
                return($retName);
	        }
	    }
    }
    
    function getUser($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);
            return($dataGetName);
	    }
    }

    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);
    }
    
    function getOp($opName)
    {
        include'connection.php';
        $quGetOp="SELECT * FROM operator WHERE Operator='$opName'";
        $reGetOp=mysqli_query($con,$quGetOp);
        $dataOp=mysqli_fetch_array($reGetOp);
        
        return($dataOp);
    }
    
    function getDupRech($mobileNo,$amount,$opName,$date)
    {
        include'connection.php';
        $quDupRech="SELECT * FROM recharge WHERE Mobile='$mobileNo' AND Amount='$amount' AND Companyname='$opName' AND Rechargedate='$date' AND Status='SUCCESS' OR Mobile='$mobileNo' AND Amount='$amount' AND Companyname='$opName' AND Rechargedate='$date' AND Status='PENDING'";
	    $reDupRech=mysqli_query($con,$quDupRech);
	    $countDupRech=mysqli_num_rows($reDupRech);
	    return($countDupRech);
    }
    
    function getComm($usrId,$opName)
    {
        include'connection.php';
        $quComm="SELECT * FROM CommSlab WHERE Userid='$usrId' AND OpName='$opName'";
	    $reComm=mysqli_query($con,$quComm);
	    $dataComm=mysqli_fetch_array($reComm);
	    $usrComm=$dataComm['Comm'];
	    return($usrComm);
    }
    
    
    function chk_msg($msg_string, $chk_string)
    {
        include'connection.php';
        $msg_upper_string=strtoupper($msg_string);
        $chk_upper_string=strtoupper($chk_string);
        $result=similar_text($msg_upper_string, $chk_upper_string);
        
        return($result);
    }
    
    function getAFS()
    {
        include'connection.php';
        $quGetAutoFailedStatus="SELECT * FROM Auto_Failed WHERE Id='1'";
		$reGetAutoFailedStatus=mysqli_query($con,$quGetAutoFailedStatus);
		$dataGetAutoFailedStatus=mysqli_fetch_array($reGetAutoFailedStatus);
		$AutoFailedStatus=$dataGetAutoFailedStatus['Status'];
		return($AutoFailedStatus);
    }
    
    function getApiNo($newrechid)
    {
        include'connection.php';
        $quGetApiNo="SELECT API_NO FROM recharge WHERE Id='$newrechid'";
        $reGetApiNo=mysqli_query($con,$quGetApiNo);
        $dataApiNo=mysqli_fetch_array($reGetApiNo);
        $apiNo=$dataApiNo['API_NO'];
        
        return($apiNo);
    }
    
?>