Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:ORV2-2857 BE Refund To Multiple Payment Methods #1660

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 230 additions & 0 deletions database/mssql/scripts/versions/revert/v_50_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
BEGIN TRANSACTION
GO


IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_RECEIPT] ADD [TRANSACTION_ID] [bigint] NULL


IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_RECEIPT] WITH CHECK ADD CONSTRAINT [ORBC_RECEIPT_TRANSACTION_ID_FK] FOREIGN KEY([TRANSACTION_ID])
REFERENCES [permit].[ORBC_TRANSACTION] ([TRANSACTION_ID])

-- Alter trigger permit.ORBC_RCPT_A_S_IUD_TR
PRINT N'Alter trigger permit.ORBC_RCPT_A_S_IUD_TR'
GO
ALTER TRIGGER [permit].[ORBC_RCPT_A_S_IUD_TR] ON permit.[ORBC_RECEIPT] FOR INSERT, UPDATE, DELETE AS
SET NOCOUNT ON
BEGIN TRY
DECLARE @curr_date datetime;
SET @curr_date = getutcdate();
IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted)
RETURN;

-- historical
IF EXISTS(SELECT * FROM deleted)
update [permit].[ORBC_RECEIPT_HIST] set END_DATE_HIST = @curr_date where RECEIPT_ID in (select RECEIPT_ID from deleted) and END_DATE_HIST is null;

IF EXISTS(SELECT * FROM inserted)
insert into [permit].[ORBC_RECEIPT_HIST] ([RECEIPT_ID], [RECEIPT_NUMBER], [TRANSACTION_ID], [RECEIPT_DOCUMENT_ID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], _RECEIPT_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
select [RECEIPT_ID], [RECEIPT_NUMBER], [TRANSACTION_ID], [RECEIPT_DOCUMENT_ID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], (next value for [permit].[ORBC_RECEIPT_H_ID_SEQ]) as [_RECEIPT_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;

END TRY
BEGIN CATCH
IF @@trancount > 0 ROLLBACK TRANSACTION
EXEC orbc_error_handling
END CATCH;
GO

IF @@ERROR <> 0 SET NOEXEC ON
GO

-- Alter trigger permit.ORBC_RCPT_I_S_U_TR
PRINT N'Alter trigger permit.ORBC_RCPT_I_S_U_TR'
GO
ALTER TRIGGER [permit].[ORBC_RCPT_I_S_U_TR] ON permit.[ORBC_RECEIPT] INSTEAD OF UPDATE AS
SET NOCOUNT ON
BEGIN TRY
IF NOT EXISTS(SELECT * FROM deleted)
RETURN;

-- validate concurrency control
if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.RECEIPT_ID = deleted.RECEIPT_ID)
raiserror('CONCURRENCY FAILURE.',16,1)


-- update statement
update [permit].[ORBC_RECEIPT]
set "RECEIPT_NUMBER" = inserted."RECEIPT_NUMBER",
"TRANSACTION_ID" = inserted."TRANSACTION_ID",
"RECEIPT_DOCUMENT_ID" = inserted."RECEIPT_DOCUMENT_ID",
"APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
"APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
"APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
"APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY",
"CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
, DB_LAST_UPDATE_TIMESTAMP = getutcdate()
, DB_LAST_UPDATE_USERID = user_name()
from [permit].[ORBC_RECEIPT]
inner join inserted
on (ORBC_RECEIPT.RECEIPT_ID = inserted.RECEIPT_ID);

END TRY
BEGIN CATCH
IF @@trancount > 0 ROLLBACK TRANSACTION
EXEC orbc_error_handling
END CATCH;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DISABLE TRIGGER [permit].[ORBC_RCPT_I_S_U_TR] ON permit.[ORBC_RECEIPT]
GO

IF @@ERROR <> 0 SET NOEXEC ON
GO
UPDATE r
SET TRANSACTION_ID = t.TRANSACTION_ID
FROM [permit].[ORBC_RECEIPT] r
INNER JOIN [permit].[ORBC_TRANSACTION] t ON t.RECEIPT_ID = r.RECEIPT_ID;

IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_RECEIPT] ALTER COLUMN [TRANSACTION_ID] [bigint] NOT NULL

IF @@ERROR <> 0 SET NOEXEC ON
GO
AlTER TABLE [permit].[ORBC_RECEIPT_HIST] ALTER COLUMN [TRANSACTION_ID] [bigint] NOT NULL


IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_TRANSACTION] DROP CONSTRAINT FK_ORBC_TRANSACTION_RECEIPT_ID

IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_TRANSACTION] DROP COLUMN [RECEIPT_ID]


IF @@ERROR <> 0 SET NOEXEC ON
GO
-- Alter trigger permit.ORBC_TXN_A_S_IUD_TR
PRINT N'Alter trigger permit.ORBC_TXN_A_S_IUD_TR'
GO
ALTER TRIGGER [permit].[ORBC_TXN_A_S_IUD_TR] ON permit.[ORBC_TRANSACTION] FOR INSERT, UPDATE, DELETE AS
SET NOCOUNT ON
BEGIN TRY
DECLARE @curr_date datetime;
SET @curr_date = getutcdate();
IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted)
RETURN;

-- historical
IF EXISTS(SELECT * FROM deleted)
update [permit].[ORBC_TRANSACTION_HIST] set END_DATE_HIST = @curr_date where TRANSACTION_ID in (select TRANSACTION_ID from deleted) and END_DATE_HIST is null;

IF EXISTS(SELECT * FROM inserted)
insert into [permit].[ORBC_TRANSACTION_HIST] ([TRANSACTION_ID], [TRANSACTION_TYPE], [PAYMENT_METHOD_TYPE], [PAYMENT_CARD_TYPE], [TOTAL_TRANSACTION_AMOUNT], [TRANSACTION_SUBMIT_DATE], [TRANSACTION_ORDER_NUMBER], [PG_TRANSACTION_ID], [PG_TRANSACTION_APPROVED], [PG_AUTH_CODE], [PG_TRANSACTION_CARD_TYPE], [PG_TRANSACTION_DATE], [PG_CVD_ID], [PG_PAYMENT_METHOD], [PG_MESSAGE_ID], [PG_MESSAGE_TEXT], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], _TRANSACTION_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST)
select [TRANSACTION_ID], [TRANSACTION_TYPE], [PAYMENT_METHOD_TYPE], [PAYMENT_CARD_TYPE], [TOTAL_TRANSACTION_AMOUNT], [TRANSACTION_SUBMIT_DATE], [TRANSACTION_ORDER_NUMBER], [PG_TRANSACTION_ID], [PG_TRANSACTION_APPROVED], [PG_AUTH_CODE], [PG_TRANSACTION_CARD_TYPE], [PG_TRANSACTION_DATE], [PG_CVD_ID], [PG_PAYMENT_METHOD], [PG_MESSAGE_ID], [PG_MESSAGE_TEXT], [APP_CREATE_TIMESTAMP], [APP_CREATE_USERID], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP], (next value for [permit].[ORBC_TRANSACTION_H_ID_SEQ]) as [_TRANSACTION_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted;

END TRY
BEGIN CATCH
IF @@trancount > 0 ROLLBACK TRANSACTION
EXEC orbc_error_handling
END CATCH;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO


-- Alter trigger permit.ORBC_TXN_I_S_U_TR
PRINT N'Alter trigger permit.ORBC_TXN_I_S_U_TR'
GO
ALTER TRIGGER [permit].[ORBC_TXN_I_S_U_TR] ON permit.[ORBC_TRANSACTION] INSTEAD OF UPDATE AS
SET NOCOUNT ON
BEGIN TRY
IF NOT EXISTS(SELECT * FROM deleted)
RETURN;

-- validate concurrency control
if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.TRANSACTION_ID = deleted.TRANSACTION_ID)
raiserror('CONCURRENCY FAILURE.',16,1)


-- update statement
update [permit].[ORBC_TRANSACTION]
set "TRANSACTION_TYPE" = inserted."TRANSACTION_TYPE",
"PAYMENT_METHOD_TYPE" = inserted."PAYMENT_METHOD_TYPE",
"PAYMENT_CARD_TYPE" = inserted."PAYMENT_CARD_TYPE",
"TOTAL_TRANSACTION_AMOUNT" = inserted."TOTAL_TRANSACTION_AMOUNT",
"TRANSACTION_SUBMIT_DATE" = inserted."TRANSACTION_SUBMIT_DATE",
"TRANSACTION_ORDER_NUMBER" = inserted."TRANSACTION_ORDER_NUMBER",
"PG_TRANSACTION_ID" = inserted."PG_TRANSACTION_ID",
"PG_TRANSACTION_APPROVED" = inserted."PG_TRANSACTION_APPROVED",
"PG_AUTH_CODE" = inserted."PG_AUTH_CODE",
"PG_TRANSACTION_CARD_TYPE" = inserted."PG_TRANSACTION_CARD_TYPE",
"PG_TRANSACTION_DATE" = inserted."PG_TRANSACTION_DATE",
"PG_CVD_ID" = inserted."PG_CVD_ID",
"PG_PAYMENT_METHOD" = inserted."PG_PAYMENT_METHOD",
"PG_MESSAGE_ID" = inserted."PG_MESSAGE_ID",
"PG_MESSAGE_TEXT" = inserted."PG_MESSAGE_TEXT",
"APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP",
"APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID",
"APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID",
"APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY",
"CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER"
, DB_LAST_UPDATE_TIMESTAMP = getutcdate()
, DB_LAST_UPDATE_USERID = user_name()
from [permit].[ORBC_TRANSACTION]
inner join inserted
on (ORBC_TRANSACTION.TRANSACTION_ID = inserted.TRANSACTION_ID);

END TRY
BEGIN CATCH
IF @@trancount > 0 ROLLBACK TRANSACTION
EXEC orbc_error_handling
END CATCH;
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
DISABLE TRIGGER [permit].[ORBC_TXN_I_S_U_TR] ON permit.[ORBC_TRANSACTION]
GO


IF @@ERROR <> 0 SET NOEXEC ON
GO
ALTER TABLE [permit].[ORBC_TRANSACTION_HIST] DROP COLUMN [RECEIPT_ID]

IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Reverting addition of RECEIPT_ID col to ORBC_TRANSACTION and dropping TRANSACTION_ID from ORBC_RECEIPT.'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (49, @VersionDescription, getutcdate())

IF @@ERROR <> 0 SET NOEXEC ON
GO
COMMIT TRANSACTION
IF @@ERROR <> 0 SET NOEXEC ON
GO
DECLARE @Success AS BIT
SET @Success = 1
SET NOEXEC OFF
IF (@Success = 1) PRINT 'The database update succeeded'
ELSE BEGIN
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
PRINT 'The database update failed'
END
GO
Loading
Loading