CREATE OR ALTER PROC PROC_MoneyGram_Catalog(
	 @flag VARCHAR(100) = NULL,
	 @cci XML =  NULL,
	 @di XML  =  NULL,
	 @pCounntry VARCHAR(30)  =  NULL,
	 @deliverymethod  VARCHAR(30)  =  NULL,
	 @receiveAgentID  VARCHAR(30)  =  NULL
)AS
BEGIN
	IF @flag='catalog'
	BEGIN
		IF @cci IS NOT NULL
		BEGIN
			 INSERT INTO MG_countryCurrencyInfo(countryCode,baseCurrency,localCurrency,receiveCurrency,indicativeRateAvailable,deliveryOption,receiveAgentID,receiveAgentAbbreviation,mgManaged,agentManaged,validationExprs,checkDigitAlg)
			 SELECT  
				 T.c.value('@countryCode', 'varchar(100)')				
				,T.c.value('@baseCurrency', 'varchar(100)') 				
				,T.c.value('@localCurrency', 'varchar(100)')				
				,T.c.value('@receiveCurrency', 'varchar(100)')			
				,T.c.value('@indicativeRateAvailable', 'varchar(100)') 	
				,T.c.value('@deliveryOption', 'varchar(100)')				
				,T.c.value('@receiveAgentID', 'varchar(100)')				
				,T.c.value('@receiveAgentAbbreviation', 'varchar(100)')	
				,T.c.value('@mgManaged', 'varchar(100)') 					
				,T.c.value('@agentManaged', 'varchar(100)')				
				,T.c.value('@validationExprs', 'varchar(100)')			
				,T.c.value('@checkDigitAlg', 'varchar(100)')
			FROM @cci.nodes('/root/row') T(c)   
		END

		IF @di IS NOT NULL
		BEGIN

			INSERT INTO MG_deliveryOptionInfo(dssOption,deliveryOptionID,deliveryOption,deliveryOptionName)
			SELECT 
				 T.c.value('@dssOption', 'varchar(100)') AS dssOption  
				,T.c.value('@deliveryOptionID', 'varchar(100)') AS deliveryOptionID  
				,T.c.value('@deliveryOption', 'varchar(100)') AS deliveryOption  
				,T.c.value('@deliveryOptionName', 'varchar(100)') AS deliveryOptionName  
			FROM @di.nodes('/root/row') T(c)   
		END

		SELECT '0' ErrorCode, 'Success' [Message]
	END
	IF @flag = 'mapping'
	BEGIN
		  SELECT * FROM dbo.TBL_GME_MG_MAPPING(NOLOCK) WHERE FieldType='D'
		  UNION ALL
		  SELECT * FROM dbo.TBL_GME_MG_MAPPING(NOLOCK) WHERE FieldType='S' AND PCountry = @pCounntry AND DeliveryMethod =  @deliverymethod AND ReceiveAgentID =  @receiveAgentID
	END
END



				