USE [FastMoneyPro_Remit]
GO
/****** Object:  StoredProcedure [dbo].[PROC_WSB_REG_ACCOUNT]    Script Date: 2019-11-22 오후 5:50:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[PROC_WSB_REG_ACCOUNT]  
(  
@rowId      BIGINT     = NULL  
,@Flag      VARCHAR(20)    = NULL  
,@customerId    BIGINT     = NULL  
,@customerGuid    VARCHAR(50)    = NULL  
,@requestData    NVARCHAR(MAX)   = NULL  
,@requestDate    DateTime    = NULL  
,@responseData    NVARCHAR(MAX)   = NULL  
,@responseDate    DateTime    = NULL  
,@dataLen     NUMERIC(4)    = NULL  
,@orgtId     VARCHAR(10)    = NULL  
,@srvcDs     VARCHAR(6)    = NULL  
,@trxTypeCd     VARCHAR(4)    = NULL  
,@rspsCd     VARCHAR(4)    = NULL  
,@tlgSeqNo     NUMERIC(10)    = NULL  
,@tlgSendHur    VARCHAR(14)    = NULL  
,@filler     NVARCHAR(MAX)   = NULL  
,@virtualAccountNo   VARCHAR(20)    = NULL  
,@customerName    NVARCHAR(MAX)   = NULL  
,@depoCtrlYn    VARCHAR(1)    = NULL  
,@depoCtlDepoprNm   NVARCHAR(MAX)   = NULL  
,@depoCtlDepoAmt   NUMERIC(15)    = NULL  
,@depoCtlDepoBankAccNo  VARCHAR(20)    = NULL  
,@depoCanDt     VARCHAR(8)    = NULL  
,@depoStopYn    VARCHAR(1)    = NULL  
,@depoCtlDepoBankCd   VARCHAR(3)    = NULL  
,@depoCanTime    VARCHAR(4)    = NULL  
,@filler1     NVARCHAR(MAX)   = NULL  
,@accountNumber    VARCHAR(30)    = NULL  
,@MethodName    VARCHAR(100)   = NULL  
)  
AS   
SET NOCOUNT ON;    
SET XACT_ABORT ON;    
BEGIN TRY  
IF @flag='ilog'  
BEGIN  
BEGIN TRANSACTION  
   
	SET @customerGuid =NEWID()  

	INSERT INTO dbo.WSB_REG_ACCOUNT  
	(  
	customerId,  	customerGuid,   requestData,    requestDate, 	dataLen, 	orgtId,    			srvcDs,  
	trxTypeCd,  	rspsCd,    		tlgSeqNo,   	tlgSendHur, 	filler,    	virtualAccountNo,   customerName      
	  
	)  
	VALUES  
	(    
	@customerId, 	@customerGuid, 	@RequestData,  	GETDATE(),  	@dataLen, 	@orgtId,   			@srvcDs,  
	@trxTypeCd, 	@rspsCd,  		@tlgSeqNo,   	@tlgSendHur, 	@filler, 	@accountNumber,  	@customerName   
	)  
   
	SET @rowId = @@IDENTITY  
	IF @@TRANCOUNT > 0              
		COMMIT TRANSACTION    
 
	SELECT 0 as code , 'Record saved successfully' message  ,@rowId id   
  
END  

IF @flag='iulog'  
BEGIN  
BEGIN TRANSACTION  
   
	SELECT 	TOP 1 @customerGuid=ISNULL(customerGuid,@customerGuid)     
	FROM 	WSB_REG_ACCOUNT (NOLOCK) 
	WHERE tlgSeqNo =@tlgSeqNo   
   
	INSERT INTO dbo.WSB_REG_ACCOUNT  
	(  
		customerId,  	customerGuid,   requestData,    requestDate, 	dataLen, 	orgtId,    			srvcDs,  
		trxTypeCd,  	rspsCd,    		tlgSeqNo,   	tlgSendHur, 	filler,    	virtualAccountNo,   customerName    
		,depoCtrlYN     
		,depoCtlDepoprNm    
		,depoCtlDepoAmt    
		,depoCtlDepoBankAccNo  
		,depoCanDt     
		,depoStopYN     
		,depoCtlDepoBankCd   
		,depoCanTime     
		,filler1   
		,responseData  
		,responseDate     
	)  
	VALUES  
	(    
		@customerId, 	@customerGuid, 	@RequestData,  	GETDATE(),  	@dataLen, 	@orgtId,   			@srvcDs,  
		@trxTypeCd, 	@rspsCd,  		@tlgSeqNo,   	@tlgSendHur, 	@filler, 	@accountNumber,  	@customerName   
		,ISNULL(@depoCtrlYn,'N'),      
		@depoCtlDepoprNm,  
		@depoCtlDepoAmt,  
		@depoCtlDepoBankAccNo,  
		@depoCanDt,  
		ISNULL(@depoStopYn,'N'),  
		@depoCtlDepoBankCd,  
		ISNULL(@depoCanTime,'0000'),  
		@filler1  
		,@responseData  
		,GETDATE()  
	)  
   
	SET @rowId = @@IDENTITY  
	IF @@TRANCOUNT > 0              
		COMMIT TRANSACTION    
 
	SELECT 0 as code , 'Record saved successfully' message  ,@rowId id 
END  

IF @flag='ulog'  
BEGIN  
	BEGIN TRANSACTION  
	UPDATE  WSB_REG_ACCOUNT 
	SET responseData   = @ResponseData,  
		responseDate   = GETDATE(),  
		depoCtrlYN    = ISNULL(@depoCtrlYn,'N'),      
		depoCtlDepoprNm   = ISNULL(@depoCtlDepoprNm,depoCtlDepoprNm),  
		depoCtlDepoAmt   = ISNULL(@depoCtlDepoAmt,depoCtlDepoAmt),  
		depoCtlDepoBankAccNo = ISNULL(@depoCtlDepoBankAccNo,depoCtlDepoBankAccNo),  
		depoCanDt    = ISNULL(@depoCanDt,depoCanDt),  
		depoStopYN    = ISNULL(@depoStopYn,'N'),  
		depoCtlDepoBankCd  = ISNULL(@depoCtlDepoBankCd,depoCtlDepoBankCd),  
		depoCanTime    = ISNULL(@depoCanTime,'0000'),  
		filler1     = ISNULL(@filler1,filler1)  
	WHERE rowId=@rowId     
    
	SELECT 	TOP 1 @customerGuid=customerGuid 
	FROM 	WSB_REG_ACCOUNT(NOLOCK) 
	WHERE rowId=@rowId  
	
	COMMIT TRANSACTION     
	
	SELECT 0 as code , 'Record saved successfully' message  ,@customerGuid id   
END  
END TRY  
BEGIN CATCH  
  IF @@TRANCOUNT > 0    
     ROLLBACK TRANSACTION    
     DECLARE @errorMessage VARCHAR(MAX)    
     SET @errorMessage = ERROR_MESSAGE()    
     EXEC proc_errorHandler 1, @errorMessage, NULL    
END CATCH 