USE [FastMoneyPro_Remit]
GO

/****** Object:  StoredProcedure [dbo].[PROC_DYNAMIC_TABLE]    Script Date: 11/8/2023 8:00:01 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


ALTER   PROC  [dbo].[PROC_DYNAMIC_TABLE] (
	@Flag VARCHAR(20)
	,@UserEmail VARCHAR(150) = NULL
	,@User VARCHAR(150) = NULL
	,@ShowAll VARCHAR(5) = NULL
	,@selectedValue1 VARCHAR(20) = NULL
	,@CountryId INT = NULL
	,@PaymentMethod INT = NULL
	,@Password VARCHAR(40) = NULL
	,@ConfirmPassword VARCHAR(40) = NULL
	,@ipAddress VARCHAR(20) = NULL
	,@id BIGINT = NULL
	,@SchemeId VARCHAR(30) = NULL
    
	)
AS
	;

SET NOCOUNT ON;
SET XACT_ABORT ON;

---------------------------------------------------------------------------------------------------
-- #19577 added new flags @flag = 'cust-detail' & 'tran-detail' for txn and receiver detail modal
-- #20203 added new flag = 'update-customer' to update receiver
---------------------------------------------------------------------------------------------------
BEGIN TRY
	DECLARE @ErrorMsg VARCHAR(MAX)
	DECLARE @agentid INT = 394395

	IF @Flag = 'CustomerTxn'
	BEGIN
	select  * from (
	
		SELECT top 3 Id = rt.id 
		    ,tAmount = tAmt
			,Amount = pAmt
			,STATUS = CASE WHEN rt.tranStatus='Reject' then 'DECLINED' 
			                       WHEN rt.tranStatus='Cancel' then 'CANCELLED' 
				                   WHEN depositType ='ONLINE' AND rt.verifiedDate IS  NULL THEN 'PENDING'						
								   WHEN depositType ='DEBIT_CARD' AND rt.verifiedDate IS NOT NULL THEN 'PROCESSING'	
								else UPPER(payStatus) end
			,TransactionDay = DATEPART(DAY, createdDate)
			,TransactionMonth = DATENAME(MONTH, createdDate)
			,PaymentMethod
			,PBankName
			,dbo.decryptDb( controlNo) controlNo
			,receiverName
			,collCurr 
			,PCurrency = payoutCurr
			,errorCode = 0
			,msg = 'Success'
			,createdDate
		FROM dbo.remitTran(NOLOCK) rt
		INNER JOIN dbo.tranSenders s(NOLOCK) ON s.tranid = rt.id
		WHERE s.customerId = @id 
		--ORDER BY createdDate ASC
		
		
		UNION ALL
		
		SELECT  top 3 Id = rtt.id
		    ,tAmount = tAmt
			,Amount = pAmt
			,STATUS = CASE WHEN rtt.tranStatus='Reject' then 'DECLINED' 
			                       WHEN rtt.tranStatus='Cancel' then 'CANCELLED' 
				                   WHEN depositType ='ONLINE' AND rtt.verifiedDate IS  NULL THEN 'PENDING'						
								   WHEN depositType ='DEBIT_CARD' AND rtt.verifiedDate IS NOT NULL THEN 'PROCESSING'	
								else UPPER('PENDING') end
			,TransactionDay = DATEPART(DAY, createdDate)
			,TransactionMonth = DATENAME(MONTH, createdDate)
			,PaymentMethod
			,PBankName
			,dbo.decryptDb( controlNo) controlNo
			,receiverName
			,collCurr 
			,PCurrency = payoutCurr
			,errorCode = 0
			,msg = 'Success'
			,createdDate
		FROM dbo.remitTranTemp(NOLOCK) rtt
		INNER JOIN dbo.tranSendersTemp ts(NOLOCK) ON ts.tranid = rtt.id
		WHERE ts.customerId = @id  
		--ORDER BY createdDate ASC
		)dum
		
		ORDER BY dum.createdDate  desc 
		
		 


	END
	ELSE IF @Flag = 'ForceChange'
	BEGIN
		DECLARE @OldPassword VARCHAR(40) = NULL

		SELECT @OldPassword = [REDACTED]
		FROM CUSTOMERMASTER(NOLOCK)
		WHERE EMAIL = @UserEmail
			AND isForcedPwdChange = 1

		IF ISNULL(@OldPassword, '') = ''
		BEGIN
			SELECT errorCode = 1
				,msg = 'Invalid customer!'
				,id = NULL

			RETURN;
		END

		IF @OldPassword = [REDACTED]
		BEGIN
			SELECT errorCode = 1
				,msg = 'Old password and new password can not be same!'
				,id = NULL

			RETURN;
		END

		UPDATE CUSTOMERMASTER
		SET isForcedPwdChange = 0
			,customerPassword = [REDACTED]
		WHERE EMAIL = @UserEmail

		SELECT errorCode = 0
			,msg = 'Password changed successfully!'
			,id = NULL

		RETURN;
	END
	ELSE IF @Flag = 'PayoutMethod'
	BEGIN
		DECLARE @PayoutCurrency VARCHAR(5)
			,@tpExRate MONEY

		SELECT @tpExRate = detailDesc
		FROM staticDataValue(NOLOCK)
		WHERE typeId = '8109'
			AND detailTitle = @SchemeId

		SELECT @PayoutCurrency = CM.currencyCode
		FROM countryCurrency CC(NOLOCK)
		INNER JOIN currencyMaster CM(NOLOCK) ON CM.currencyId = CC.currencyId
		WHERE CC.countryId = @CountryId
			AND ISNULL(CC.isActive, 'Y') = 'Y'
			AND CC.isDefault = 'Y'

		IF @PaymentMethod IS NULL
		BEGIN
			SELECT agentId
				,isRealTime
				,exRateCalByPartner
				,CM.COUNTRYCODE
				,CM.CountryName
				,AgentId
				,PayoutCurrency = @PayoutCurrency
				,tpExRate = @tpExRate
			FROM TblPartnerwiseCountry P(NOLOCK)
			INNER JOIN COUNTRYMASTER CM(NOLOCK) ON CM.COUNTRYID = P.COUNTRYID
			WHERE P.countryId = @CountryId
				AND (
					PaymentMethod IS NULL
					OR PaymentMethod IS NOT NULL
					)
				AND P.IsActive = 1
		END
		ELSE
		BEGIN
			SELECT agentId
				,isRealTime
				,exRateCalByPartner
				,CM.COUNTRYCODE
				,CM.CountryName
				,AgentId
				,PayoutCurrency = @PayoutCurrency
				,tpExRate = @tpExRate
			FROM TblPartnerwiseCountry P(NOLOCK)
			INNER JOIN COUNTRYMASTER CM(NOLOCK) ON CM.COUNTRYID = P.COUNTRYID
			WHERE P.countryId = @CountryId
				AND ISNULL(PaymentMethod, @PaymentMethod) = @PaymentMethod
				AND P.IsActive = 1
		END
	END
	ELSE IF @Flag = 'CustomerReceiver'
	BEGIN
		SELECT TOP 3 Id = receiverId
			,Name = FULLNAME
			,Country = CM.countryName
			,Mobile
			,TransactionType = SM.typeTitle
			,errorCode = 0
			,msg = 'Success'
		FROM receiverInformation RI(NOLOCK)
			INNER JOIN countryMaster CM(NOLOCK) ON CM.countryName = RI.country
		INNER JOIN serviceTypeMaster SM(NOLOCK) ON SM.serviceTypeId = RI.paymentMode
		WHERE Ri.customerId = @id order by RI.createdDate desc
	END
	ELSE IF @Flag = 'receiverList'
	BEGIN
		SELECT Id = receiverId
			,TEXT = FULLNAME
			,errorCode = 0
			,msg = 'Success'
		FROM receiverInformation RI(NOLOCK)
		INNER JOIN countryMaster CM(NOLOCK) ON CM.countryName = RI.country
		WHERE CM.countryId = @selectedValue1
	END
	ELSE IF @Flag = 'purpose'
	BEGIN
		SELECT Id = valueId
			,TEXT = detailTitle
			,errorCode = 0
			,msg = 'Success'
		FROM staticdatavalue(NOLOCK)
		WHERE typeid = 3800
			AND ISNULL(ISActive, 'Y') = 'Y'
			AND ISNULL(IS_DELETE, 'N') = 'N'
		ORDER BY detailTitle ASC
	END
	ELSE IF @Flag = 'howToPay'
	BEGIN
		SELECT Id = 'ONLINE'
			,TEXT = 'Online Banking(Best Rate)'
			,extra = 0
			,errorCode = 0
			,msg = 'Success'
		
		UNION ALL
		
		SELECT Id = 'EBANKING'
			,TEXT = 'E-Banking/ (Good rate)'
			,extra = 0
			,errorCode = 0
			,msg = 'Success'
		
		UNION ALL
		
		SELECT Id = 'DEBIT_CARD'
			,TEXT = 'DEBIT CARD'
			,extra = 0.15
			,errorCode = 0
			,msg = 'Success'
	END
	ELSE IF @Flag = 'pCountry'
	BEGIN
		SET @countryId = 233

		SELECT Id = countryId
			,TEXT = UPPER(countryName)
			,errorCode = 0
			,msg = 'Success'
		FROM countryMaster CM WITH (NOLOCK)
		INNER JOIN (
			SELECT receivingCountry
				,min(maxLimitAmt) maxLimitAmt
			FROM (
				SELECT receivingCountry
					,max(maxLimitAmt) maxLimitAmt
				FROM sendTranLimit SL WITH (NOLOCK)
				WHERE --countryId = @countryId  
					--AND  
					ISNULL(isActive, 'N') = 'Y'
					AND ISNULL(isDeleted, 'N') = 'N'
					AND ISNULL(agentId, ISNULL(@agentid, 0)) = ISNULL(@agentid, 0)
				GROUP BY receivingCountry
				
				UNION ALL
				
				SELECT receivingCountry
					,max(maxLimitAmt) maxLimitAmt
				FROM sendTranLimit SL WITH (NOLOCK)
				WHERE agentId = @agentid
					AND ISNULL(isActive, 'N') = 'Y'
					AND ISNULL(isDeleted, 'N') = 'N'
				GROUP BY receivingCountry
				) x
			GROUP BY receivingCountry
			) Y ON Y.receivingCountry = CM.countryId
		WHERE ISNULL(isOperativeCountry, '') = 'Y'
			AND Y.maxLimitAmt > 0
		ORDER BY countryName ASC
	END
	ELSE IF @Flag = 'pMode'
	BEGIN
		SET @countryId = 233

		SELECT Id = serviceTypeId
			,TEXT = UPPER(typeTitle)
			,errorCode = 0
			,msg = 'Success'
		FROM serviceTypeMaster stm WITH (NOLOCK)
		INNER JOIN (
			SELECT receivingMode
				,maxLimitAmt
			FROM countryReceivingMode crm WITH (NOLOCK)
			INNER JOIN sendTranLimit SL WITH (NOLOCK) ON crm.countryId = SL.receivingCountry
			WHERE SL.countryId = @countryId
				AND SL.receivingCountry = @selectedValue1
				AND SL.agentId IS NULL
				AND SL.tranType IS NULL
				AND receivingAgent IS NULL
			
			UNION ALL
			
			SELECT receivingMode
				,maxLimitAmt
			FROM countryReceivingMode crm WITH (NOLOCK)
			INNER JOIN sendTranLimit SL WITH (NOLOCK) ON crm.countryId = SL.receivingCountry
				AND SL.receivingCountry = @selectedValue1
				AND SL.countryId = @countryId
			WHERE agentId = @agentId
				AND SL.tranType IS NULL
				AND receivingAgent IS NULL
				AND ISNULL(isActive, 'N') = 'Y'
				AND ISNULL(isDeleted, 'N') = 'N'
			
			UNION ALL
			
			SELECT tranType
				,MAX(maxLimitAmt) maxLimitAmt
			FROM sendTranLimit SL WITH (NOLOCK)
			WHERE countryId = @countryId
				AND SL.receivingCountry = @selectedValue1
				AND ISNULL(isActive, 'N') = 'Y'
				AND ISNULL(isDeleted, 'N') = 'N'
				AND SL.agentId IS NULL
				AND SL.tranType IS NOT NULL
				AND SL.receivingAgent IS NULL
			GROUP BY tranType
			
			UNION ALL
			
			SELECT tranType
				,MAX(maxLimitAmt) maxLimitAmt
			FROM sendTranLimit SL WITH (NOLOCK)
			WHERE countryId = @countryId
				AND SL.receivingCountry = @selectedValue1
				AND SL.agentId = @agentid
				AND ISNULL(isActive, 'N') = 'Y'
				AND ISNULL(isDeleted, 'N') = 'N'
				AND receivingAgent IS NULL
				AND SL.tranType IS NOT NULL
				AND SL.receivingAgent IS NULL
			GROUP BY tranType
			) X ON X.receivingMode = stm.serviceTypeId
		WHERE ISNULL(STM.isActive, 'N') = 'Y'
			AND ISNULL(STM.isDeleted, 'N') = 'N'
			AND (STM.serviceTypeId NOT IN (5))
		--AND (STM.serviceTypeId NOT IN (3,5))  
		GROUP BY serviceTypeId
			,typetitle
		HAVING MIN(X.maxLimitAmt) > 0
		ORDER BY serviceTypeId ASC
	END
	ELSE IF @Flag = 'Txn-Detail'
	BEGIN
		SELECT ControlNo = dbo.decryptdb(rt.controlNo)
			,rt.receivername
			,tr.firstName AS recFName
			,tr.middleName AS recMidName
			,tr.lastName1 AS recLName
			,rt.camt
			,rt.id
			,rt.collCurr
			,tr.address raddress
			,rt.createdDate
			,rt.paymentMethod
			,collMode = rt.depositType
			,rt.pbankname
			,rt.pbankBranchName
			,rt.accountNo
			,rt.purposeofremit
			,STATUS =  CASE WHEN rt.tranStatus='Reject' then 'DECLINED' 
			                       WHEN rt.tranStatus='Cancel' then 'CANCELLED' 
				                   WHEN depositType ='ONLINE' AND rt.verifiedDate IS  NULL THEN 'PENDING'						
								   WHEN depositType ='DEBIT_CARD' AND rt.verifiedDate IS NOT NULL THEN 'PROCESSING'	
								else UPPER(payStatus) end
			,rt.pamt
			,rt.payoutCurr
			,rt.customerRate
			,PromotionPremiumRate = 0
			,rt.tamt
			,rt.collCurr
			,rt.servicecharge
			,PromotionDiscount = ISNULL(rewardPoints,0)
			,rt.camt
			,rt.pCountry
			,ts.zipcode
			,ts.firstname + ' ' + ts.middlename firstname
			,ts.lastname1
			,ts.address
			,ts.city
			,ts.mobile
			,SenderName = ISNULL(ts.fullname, ts.firstname + ' ' + ts.lastname1)
			,rt.tranType
		FROM remitTranTemp rt(NOLOCK)
		INNER JOIN tranReceiversTemp tr(NOLOCK) ON tr.tranid = rt.id
		INNER JOIN transendersTemp ts(NOLOCK) ON ts.tranid = rt.id
		WHERE rt.id = @id
		UNION ALL
		SELECT ControlNo = dbo.decryptdb(rt.controlNo)
			,rt.receivername
			,tr.firstName AS recFName
			,tr.middleName AS recMidName
			,tr.lastName1 AS recLName
			,rt.camt
			,rt.id
			,rt.collCurr
			,tr.address raddress
			,rt.createdDate
			,rt.paymentMethod
			,collMode = rt.depositType
			,rt.pbankname
			,rt.pbankBranchName
			,rt.accountNo
			,rt.purposeofremit
			,STATUS = CASE WHEN rt.tranStatus='Reject' then 'DECLINED' 
				                       WHEN rt.tranStatus='Cancel' then 'CANCELLED'   
				                       WHEN rt.tranStatus='paid' then 'PAID' 
				                    WHEN depositType =  'ONLINE' AND rt.verifiedDate IS  NULL THEN 'PENDING'	
									WHEN depositType in('ONLINE','DEBIT_CARD') AND rt.verifiedDate IS NOT NULL THEN 'PROCESSING'
									 else UPPER(payStatus) end
			,rt.pamt
			,rt.payoutCurr
			,rt.customerRate
			,PromotionPremiumRate = 0
			,rt.tamt
			,rt.collCurr
			,rt.servicecharge
			,PromotionDiscount = 0
			,rt.camt
			,rt.pCountry
			,ts.zipcode
			,ts.firstname + ' ' + ts.middlename firstname
			,ts.lastname1
			,ts.address
			,ts.city
			,ts.mobile
			,SenderName = ISNULL(ts.fullname, ts.firstname + ' ' + ts.lastname1)
			,rt.tranType
		FROM remitTran rt(NOLOCK)
		INNER JOIN tranReceivers tr(NOLOCK) ON tr.tranid = rt.id
		INNER JOIN transenders ts(NOLOCK) ON ts.tranid = rt.id
		WHERE rt.id = @id
	END
	ELSE IF @Flag = 'allCountrylist'
	BEGIN
		SELECT Id = @CountryId
			,TEXT = UPPER(countryName)
		FROM dbo.countryMaster(NOLOCK)
		ORDER BY ISNULL(isOperativeCountry, 'N') DESC
			,countryName
	END
	ELSE IF @flag = 'tran-detail-all'
	BEGIN
		SELECT cAmt
			,serviceCharge
			,(cAmt - serviceCharge + ISNULL(rewardpoints, 0)) AS tAmt
			,Amount = pAmt
			,pBankName
			,pCountry
			,paymentMethod
			,Id = rt.id
			,SenderName = ISNULL(s.fullname, s.firstname + ' ' + s.lastname1)
			,ReceiverName = rt.receiverName
			,FORMAT(createdDate, 'dd MMMM, yyyy') AS tranDate
			,rt.customerRate
			,[Status] = CASE 
				WHEN rt.tranStatus = 'Cancel'
					THEN 'CANCELLED'
				WHEN rt.tranStatus = 'Payment'
					AND rt.payStatus = 'Unpaid'
					AND rt.paymentMethod = 'Bank Deposit'
					THEN 'AWAITING PAYMENT'
				WHEN rt.tranStatus = 'Payment'
					AND rt.payStatus = 'Post'
					AND rt.paymentMethod = 'Cash Payment'
					THEN 'READY TO COLLECT'
				WHEN rt.tranStatus = 'Payment'
					AND rt.payStatus = 'Post'
					AND rt.paymentMethod = 'Bank Deposit'
					THEN 'PROCESSING'
				ELSE UPPER(rt.tranStatus)
				END
			,errorCode = 0
			,msg = 'Success'
		FROM dbo.remitTran(NOLOCK) rt
		INNER JOIN dbo.tranSenders s(NOLOCK) ON s.tranid = rt.id
		WHERE rt.id = @id
		
		UNION ALL
		
		SELECT cAmt
			,serviceCharge
			,(cAmt - serviceCharge + ISNULL(rewardpoints, 0)) AS tAmt
			,Amount = pAmt
			,pBankName
			,pCountry
			,PaymentMethod
			,rtt.id
			,SenderName = ISNULL(ts.fullname, ts.firstname + ' ' + ts.lastname1)
			,ReceiverName = rtt.receiverName
			,FORMAT(createdDate, 'dd MMMM, yyyy') AS tranDate
			,rtt.customerRate
			,[Status] = CASE 
				WHEN payStatus = 'Paid'
					THEN 'Paid'
				WHEN tranStatus = 'Cancel'
					OR payStatus = 'Cancel'
					THEN 'Cancel'
				ELSE 'PROCESSING'
				END
			,errorCode = 0
			,msg = 'Success'
		FROM dbo.remitTranTemp(NOLOCK) rtt
		INNER JOIN dbo.tranSendersTemp ts(NOLOCK) ON ts.tranid = rtt.id
		WHERE rtt.id = @id
	END
	ELSE IF @flag = 'cust-detail'
	BEGIN
		SELECT rt.tranStatus AS tranStatus
			,rt.pAmt AS nprAmt
			,CONCAT (
				RI.firstName
				,' '
				,RI.middleName
				,' '
				,RI.lastName1
				) AS FullName
			,rt.id AS tranId
			,rt.createdDate AS tranDate
			,tr.address AS address
			,ISNULL(tr.mobile, RI.mobile) AS mobile
			,rt.cAmt AS collAmt
			,rt.serviceCharge AS serviceCharge
			,rt.rewardPoints AS customerPremium
			,rt.tAmt AS sentAmt
			,rt.customerRate AS exRate
			,rt.pAmt AS payoutAmt
			,rt.pAgentName AS pAgent
			,errorCode = 0
			,msg = 'Success'
		FROM receiverInformation RI(NOLOCK)
		LEFT JOIN tranReceivers tr(NOLOCK) ON tr.id = RI.receiverId
		LEFT JOIN remitTran rt(NOLOCK) ON rt.id = tr.tranId
		WHERE RI.receiverId = @id
	END
	ELSE IF @Flag = 'CustomerTxn-all'
	BEGIN
		SELECT Id = rt.id
			,recName = rt.receiverName
			,recAccNum = rt.accountNo
			,Amount = pAmt
			--,STATUS = CASE 
			--	WHEN rt.tranStatus = 'Cancel'
			--		THEN 'CANCELLED'
			--	WHEN rt.tranStatus = 'Payment'
			--		AND rt.payStatus = 'Unpaid'
			--		AND rt.paymentMethod = 'Bank Deposit'
			--		THEN 'AWAITING PAYMENT'
			--	WHEN rt.tranStatus = 'Payment'
			--		AND rt.payStatus = 'Post'
			--		AND rt.paymentMethod = 'Cash Payment'
			--		THEN 'READY TO COLLECT'
			--	WHEN rt.tranStatus = 'Payment'
			--		AND rt.payStatus = 'Post'
			--		AND rt.paymentMethod = 'Bank Deposit'
			--		THEN 'PROCESSING'
			--	ELSE UPPER(rt.tranStatus)
			--	END
			--,TransactionDay = DATEPART(DAY, createdDate)
			--,TransactionMonth = DATENAME(MONTH, createdDate)
			,PaymentMethod
			,rt.pCountry
			--,PBankName
			--,PCurrency = payoutCurr
			,errorCode = 0
			,msg = 'Success'
		FROM dbo.remitTran(NOLOCK) rt
		INNER JOIN dbo.tranSenders s(NOLOCK) ON s.tranid = rt.id
		WHERE s.customerId = @id
		
		UNION ALL
		
		SELECT Id = rtt.id
			,recName = rtt.receiverName
			,recAccNum = rtt.accountNo
			,Amount = pAmt
			--,STATUS = CASE 
			--	WHEN payStatus = 'Paid'
			--		THEN 'Paid'
			--	WHEN tranStatus = 'Cancel'
			--		OR payStatus = 'Cancel'
			--		THEN 'Cancel'
			--	ELSE 'PROCESSING'
			--	END
			--,TransactionDay = DATEPART(DAY, createdDate)
			--,TransactionMonth = DATENAME(MONTH, createdDate)
			,PaymentMethod
			,rtt.pCountry
			--,PBankName
			--,PCurrency = payoutCurr
			,errorCode = 0
			,msg = 'Success'
		FROM dbo.remitTranTemp(NOLOCK) rtt
		INNER JOIN dbo.tranSendersTemp ts(NOLOCK) ON ts.tranid = rtt.id
		WHERE ts.customerId = @id
	END
	ELSE IF @Flag = 'CustomerReceiver-all'
	BEGIN
		SELECT Id = receiverId
			,Name = FULLNAME
			,Country = country
			,Mobile
			,TransactionType = SM.typeTitle
			,errorCode = 0
			,msg = 'Success'
		FROM receiverInformation RI(NOLOCK)
		INNER JOIN serviceTypeMaster SM(NOLOCK) ON SM.serviceTypeId = RI.paymentMode
		WHERE Ri.customerId = @id
	END
	ELSE IF @Flag = 'edit-customer'
	BEGIN
	print 'rr'
		SELECT Id = receiverId
			,FirstName = firstName
			,middleName = middleName
			,LastName1 = lastName1
			,relationship = ISNULL(relationOther,'')
			,Country = CM.CountryId
			,address = ISNULL(address, '')
			,city =  ISNULL(city,'')
			,zipCode = ISNULL(zipCode,'')
			,mobile = ISNULL(mobile,'')
			,email = ISNULL(email,'')
			--,paymentMode = ISNULL(STM.typeTitle,'')
			--,idType = ISNULL(sdv.detailTitle,'') 
			,paymentMode = ISNULL(paymentMode,'')
			,idType = ISNULL(idType,'')
			,idNumber = ISNULL(idNumber,'')
			,bank = ISNULL(bank, '')
			,bankName = ISNULL(bankBranchName,'')
			,accountNum = ISNULL(receiverAccountNo,'')
			,errorCode = 0
			,msg = 'Success'
		FROM receiverInformation RI(NOLOCK)
		LEFT JOIN countryMaster CM(NOLOCK) ON CM.countryName = RI.country
		LEFT JOIN serviceTypeMaster STM ON RI.paymentMode = stm.serviceTypeId
		LEFT JOIN staticDataValue sdv ON RI.idType = sdv.valueId
		WHERE receiverId = @id

		SELECT  '0' errorCode ,'Receiver updated Successfully.' msg ,id = @id;
	END
END TRY

BEGIN CATCH
	SET @ErrorMsg = 'Internal Server Error: ' + ERROR_MESSAGE()

	SELECT errorCode = 1
		,msg = @ErrorMsg
		,id = NULL
END CATCH
GO

