
ALTER PROCEDURE [dbo].[proc_MobileApiLogs](    
  @flag    VARCHAR(10) =  NULL    
 ,@user    VARCHAR(30) =  NULL    
 ,@REQUESTEDBY  VARCHAR(100) = NULL    
 ,@rowId   INT   =  NULL    
 ,@pageSize   INT   = NULL    
 ,@pageNumber  INT   = NULL    
 ,@sortBy   VARCHAR(50)  = NULL    
 ,@sortOrder  VARCHAR(50)  = NULL   
 ,@agentId   varchar(20) = NULL    
 ,@logType   VARCHAR(20) = NULL  
 ,@date    VARCHAR(10) = NULL  
 ,@logby   VARCHAR(50) = NULL  
 ,@controlno  VARCHAR(30) = NULL  
 ,@processid  VARCHAR(100) = NULL  
)AS    
SET NOCOUNT ON    
SET XACT_ABORT ON    
BEGIN    
 DECLARE    
   @table    VARCHAR(MAX)    
  ,@select_field_list VARCHAR(MAX)    
  ,@extra_field_list VARCHAR(MAX)    
  ,@sql_filter  VARCHAR(MAX)   
  if @flag = 'method' 
  BEGIN
  	SELECT *
		FROM (
			SELECT '' [value]
				,'Select Log Type' [text]
			
			UNION ALL
			
			SELECT 'newUserRegister' [value]
				,'Basic Registration' [text]
			
			UNION ALL
			
			SELECT 'RegisterKyc' [value]
				,'KYC Doc Upload ' [text]
			
			UNION ALL
			
			SELECT 'requestOTP' [value]
				,'Request OTP' [text]

			UNION ALL
			
			SELECT 'submitOTP' [value]
				,'Submit OTP' [text]
			UNION ALL
			
			SELECT 'LoginToSystem' [value]
				,'Login' [text]

			UNION ALL
			
			SELECT 'AddReceiver' [value]
				,'Add Beneficiary' [text]
			UNION ALL
			SELECT 'dotransaction' [value]
				,'Send Money' [text]
			UNION ALL
			SELECT 'ChangePassword' [value]
				,'Change  Password' [text]
		    UNION ALL
			SELECT 'ResetPassword' [value]
				,'Forgot Password' [text]
			) x

  END

 else IF @flag='s'    
 BEGIN      
  SET @sortBy='rowId'    
  SET @sortOrder='DESC'    
  SET @table='    
  (     
   SELECT rowId  
   ,processId  
   ,createdDate 
   ,methodName
   ,message  
   ,exception  
   ,createdBy  
   ,controlNo
   FROM logDb.DBO.applicationlogger (NOLOCK)    
   WHERE 1=1    
  )x'    
          
  SET @sql_filter = ''    
  IF @agentId IS NOT NULL      
  SET @sql_filter=@sql_filter + ' AND methodName = ''' +@agentId+''''    
  
  IF @logby IS NOT NULL      
  SET @sql_filter=@sql_filter + ' AND createdBy = ''' +@logby+''''   
     
  IF @date IS NOT NULL      
   SET @sql_filter=@sql_filter + ' AND CONVERT(varchar(10),createdDate,121) = ''' +@date+''''    
  
  IF @logType IS NOT NULL      
   BEGIN 
   if(@logType='sendTxn')
      SET @sql_filter=@sql_filter + ' AND right(processId,7) = '''+@logType+''''    
  END
  IF @controlno IS NOT NULL      
   SET @sql_filter=@sql_filter + ' AND controlno = ''' +@controlno+''''    
   
  IF @processid IS NOT NULL      
   SET @sql_filter=@sql_filter + ' AND processId  = ''' +@processid+''''       
       
  SET @select_field_list = '    
         rowId  
   ,processId  
   ,createdDate  
   ,MethodName
   ,message  
   ,createdBy  
   ,controlno   
       '    
           
  EXEC dbo.proc_paging    
   @table    
  ,@sql_filter    
  ,@select_field_list    
  ,@extra_field_list    
  ,@sortBy    
  ,@sortOrder    
  ,@pageSize    
  ,@pageNumber    
     
      
      
 END    
 IF @flag='a'    
 BEGIN    
    SELECT rowId    
       ,processId providerName    
       ,MethodName methodName    
       ,controlNo    
       ,[message] requestXml    
       ,'' requestXml    
	  
       ,createdBy requestedBy    
       ,createdDate requestedDate    
       ,'' responseDate    
          
         
     FROM logDb.DBO.applicationlogger (NOLOCK)    
     WHERE rowId=@rowId    
 END    
END    