USE [FastMoneyPro_Remit]
GO
/****** Object:  StoredProcedure [dbo].[PROC_THIRDPARTY_SEND_UTILITY]    Script Date: 7/4/2019 11:35:48 AM ******/
DROP PROCEDURE [dbo].[PROC_THIRDPARTY_SEND_UTILITY]
GO
/****** Object:  StoredProcedure [dbo].[PROC_THIRDPARTY_SEND_UTILITY]    Script Date: 7/4/2019 11:35:48 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PROC_THIRDPARTY_SEND_UTILITY](
    @Flag			VARCHAR(100)
   ,@AgentId		VARCHAR(20) = NULL
   ,@PayoutPartner	VARCHAR(20) = NULL
   ,@ReceivingMode	VARCHAR(20) = NULL
   ,@CountryId		VARCHAR(20) = NULL
)AS
BEGIN
	IF @Flag='get-agent-code'
	BEGIN
		IF EXISTS(SELECT 'x' FROM TblPartnerwiseCountry(NOLOCK) c 
		INNER JOIN  countryReceivingMode m ON c.CountryId=m.countryId 
		WHERE c.IsActive=1 AND c.CountryId = @CountryId AND m.receivingMode = @ReceivingMode AND m.agentSelection='M')
		BEGIN
			SELECT agentCode AS AgentCode FROM dbo.agentMaster(NOLOCK) WHERE agentId = @AgentId
			RETURN
		END
		SELECT NULL AS AgentCode
		RETURN
	END
	IF @Flag='get-agent-loc-code'
	BEGIN
		--IF EXISTS(SELECT 'x' FROM TblPartnerwiseCountry(NOLOCK) c 
		--INNER JOIN  countryReceivingMode m ON c.CountryId=m.countryId 
		--WHERE c.IsActive=1 AND c.CountryId = @CountryId AND m.receivingMode = @ReceivingMode AND m.agentSelection='M')
		--BEGIN
		--	SELECT routingCode AS LocationCode FROM dbo.agentMaster(NOLOCK) WHERE agentId = @AgentId
		--	RETURN
		--END
		--SELECT NULL AS LocationCode
		--RETURN

		SELECT routingCode AS LocationCode FROM dbo.agentMaster(NOLOCK) WHERE agentId = @AgentId
	END


	IF @Flag='get-bank-code'
	BEGIN		
		SELECT BANKCODE AS AgentCode,swiftCode AS SwiftBIC, extCode AS [ProviderId] FROM dbo.agentMaster(NOLOCK) WHERE agentId = @AgentId
		RETURN
	END

	IF @Flag='country-code'
	BEGIN
		SELECT countryCode FROM dbo.countryMaster(NOLOCK) WHERE countryId = @CountryId
		RETURN
	END
END

GO
