USE [FastMoneyPro_Remit]
GO

ALTER PROCEDURE DLL_PROC_GET_PARTNER_CONFIG(
    @Flag				VARCHAR(100)
   ,@payOutPartnerId	BIGINT
   ,@pCountryId			BIGINT
   ,@pCountryName		VARCHAR(50) = NULL
   ,@deliveryMethodId	BIGINT
)
AS
SET  NOCOUNT ON
BEGIN
	IF @Flag='config'
	BEGIN
		IF @pCountryId IS NULL AND @pCountryName IS NOT NULL
			SELECT @pCountryId = countryId FROM countryMaster(NOLOCK) WHERE countryName = @pCountryName
		

		IF @PAYOUTPARTNERID = 601391 ---- CEBUEANA LHUILLIER
		BEGIN		
			SELECT TOP 1
				BaseUrl = 'http://cebuana.gmeremit.com.kr:7005/Cebuana'
				,[Authorization] = '29F9D158-9F59-4D3E-972F-2B4E29D996F2'
				,[PartnerRate]	 = 0
				,[PartnerPin]	 = 0
				,DefaultAgent	 = ''
			RETURN
		END

		IF EXISTS(SELECT 'x' FROM dbo.TblPartnerwiseCountry(NOLOCK) WHERE IsActive = 1 AND AgentId=@payOutPartnerId AND CountryId=@pCountryId AND PaymentMethod = @deliveryMethodId)
		BEGIN
			SELECT TOP 1
				 [BaseUrl]
				,[PartnerRate]	 = CASE WHEN GetRateFrom='LOG' THEN 1 ELSE [PartnerRate] END
				,[PartnerPin]	 = [PartnerPin]
				,[Authorization] = AuthKey		
				,DefaultAgent		
			FROM dbo.TblPartnerwiseCountry(NOLOCK)
			WHERE AgentId=@payOutPartnerId AND CountryId=@pCountryId AND PaymentMethod=@deliveryMethodId 
			AND IsActive=1
		END
		ELSE
		BEGIN
			   	SELECT TOP 1
				 [BaseUrl]
				,[PartnerRate]	 = CASE WHEN GetRateFrom='LOG' THEN 1 ELSE [PartnerRate] END
				,[PartnerPin]	 = [PartnerPin]
				,[Authorization] = AuthKey
				,DefaultAgent
			FROM dbo.TblPartnerwiseCountry(NOLOCK)
			WHERE IsActive=1 AND AgentId=@payOutPartnerId AND CountryId=@pCountryId --AND PaymentMethod=@deliveryMethodId
		END
	END 
END

