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

CREATE PROC [dbo].[PROC_KFTC_LOGS]
	 @FLAG			VARCHAR(50)
	,@METHODNAME	VARCHAR(200)	= NULL
	,@CONTROLNO		VARCHAR(50)		= NULL
	,@ROWID			BIGINT			= NULL
	,@REQUESTXML	NVARCHAR(MAX)	= NULL
	,@RESPONSEXML	NVARCHAR(MAX)	= NULL
	,@CUSTOMERID	VARCHAR(30)		= NULL
	,@ERRORCODE		VARCHAR(10)		= NULL
	,@ERRORMESSAGE	NVARCHAR(200)	= NULL
	,@PROCESSID		VARCHAR(40)		= NULL
AS
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF @flag = 'i'
BEGIN
	IF ISNULL(@PROCESSID, '') = ''
		SET @PROCESSID = NEWID()

	INSERT TBL_KFTC_LOG(METHODNAME, REQUESTXML, REQUESTDT, REQUESTEDBY, PROCESSID)
	SELECT	@METHODNAME, @REQUESTXML, GETDATE(), @CUSTOMERID, @PROCESSID
	
	SET @ROWID = SCOPE_IDENTITY()
	SELECT '0' ErrorCode, 'Request Logged Successfully' Msg, @ROWID Id,@PROCESSID Extra
	RETURN
END
ELSE IF @flag = 'u'
BEGIN
	UPDATE TBL_KFTC_LOG SET
		 RESPONSEXML = @RESPONSEXML
		,RESPONSEDT = GETDATE()
		,RESPONSECODE	= @ERRORCODE
		,RESPONSEMSG = @ERRORMESSAGE
	WHERE ROWID = @ROWID

	SELECT '0' ErrorCode, 'Response Logged Successfully' Msg, @ROWID Id
	RETURN 
END
GO
