ALTER PROC proc_sendRequest

		@flag							VARCHAR(20)		
		,@user							VARCHAR(20)		=	NULL
		,@membershipId					VARCHAR(20)		=	NULL
		,@idNumber						VARCHAR(20)		=	NULL
		,@receiverFullName				varchar(200)	=	NULL
		,@receiveraddress 				varchar(100)	=	NULL
		,@receiverMobileNumber			varchar(20)		=	NULL
		,@pCountryId 					BIGINT			=	NULL
		,@pModeId 						BIGINT			=	NULL
		,@pagentId 						BIGINT			=	NULL
		,@branchId 						BIGINT			=	NULL
		,@accountNumber 				varchar(50)		=	NULL
		,@cAmt 							MONEY			=	NULL
		,@tamt 							MONEY			=	NULL
		,@serviceCharge 				MONEY			=	NULL
		,@purposeOfRemittanceId			BIGINT			=	NULL
		,@otherPurposeOfRemittance		VARCHAR(100)	=	NULL
		,@relationShipId				BIGINT			=	NULL
		,@otherRelation					VARCHAR(100)	=	NULL
		,@referralName					VARCHAR(50)		=	NULL
AS
SET NOCOUNT ON ;
SET XACT_ABORT ON;
BEGIN
	IF @flag = 'sendRequest'
	BEGIN
		DECLARE @CUSTOMERID BIGINT, @rowId BIGINT
		IF NOT EXISTS (select 1 from customermaster where idnumber = @idNumber AND ISNULL(isActive, 'Y') = 'Y')
		BEGIN
			SELECT '1' ERROR_CODE, 'Customer with idNumber '''+@idNumber+''' does not exixts' Msg,@idNumber id
			RETURN
		END
		select @CUSTOMERID = CUSTOMERID,@membershipId = membershipId FROM CUSTOMERMASTER WHERE idNumber = @idNumber AND ISNULL(ISACTIVE, 'Y') = 'Y'
		--IF NOT EXISTS (SELECT 1 from receiverinformation where fullname = LTRIM(RTRIM(@receiverFullName))  and customerid = @CUSTOMERID)
		--BEGIN
		--	SELECT '1' ERROR_CODE, 'Receiver with name '''+@receiverFullName+''' does not exist of customer with membershipId '''+@membershipId+'''' Msg,@membershipId id
		--	RETURN
		--END

		INSERT INTO send_money_request(IdNumber,MembershipId,ReceiverFullName,Receiveraddress
		,ReceiverMobileNumber,purposeOfRemittance,otherPurpose,relationShip,otherRelation,referralName
		,PCountryId,PmodeId,PagentId,BranchId,AccountNumber,CAmt,Tamt,ServiceCharge,createdby,createddate
		)
		values
		(
		@idNumber,@membershipId,@receiverFullName	,@receiveraddress
		,@receiverMobileNumber,@purposeOfRemittanceId,@otherPurposeOfRemittance,@relationShipId,@otherRelation,@referralName			
		,@pCountryId ,@pModeId,@pagentId ,@branchId ,@accountNumber ,@cAmt ,@tamt ,@serviceCharge,@user,Getdate()
		)

		SET @rowId = @@IDENTITY

		SELECT '0' ERROR_CODE,'Request Send Successfully' Msg,@rowId id, cast(@CUSTOMERID as varchar) + '|' + cast(@membershipId as varchar) EXTRA
	END
	IF @flag = 'validateData'
	BEGIN
		IF NOT EXISTS (select 1 from customermaster where idNumber = @idNumber)

		BEGIN
			SELECT '1' ERROR_CODE, 'Customer with idNumber '''+@idNumber+''' does not exixts' Msg,@idNumber id
			RETURN
		END
		select @CUSTOMERID = CUSTOMERID FROM CUSTOMERMASTER WHERE idNumber = @idNumber AND ISNULL(ISACTIVE, 'Y') = 'Y'
		IF NOT EXISTS (SELECT 1 from receiverinformation where fullname = LTRIM(RTRIM(@receiverFullName))  and customerid = @CUSTOMERID)
		BEGIN
			SELECT '1' ERROR_CODE, 'Receiver with name '''+@receiverFullName+''' does not exist of customer with idNumber '''+@idNumber+'''' Msg,@idNumber id
			RETURN
		END
		SELECT '0' ERROR_CODE, 'Customer and receiver exixts' Msg,@idNumber id
	END
END