shakun
1 year ago
10 changed files with 236 additions and 79 deletions
-
0ExecuteScript/17732-menu-disable.sql
-
0ExecuteScript/CLEAR TXN BEFORE DATA MIGRATION.sql
-
0ExecuteScript/Identity_Insert_AgentMaster.sql
-
0ExecuteScript/MobileAPI.sql
-
0ExecuteScript/idTypes.sql
-
0ExecuteScript/insertAC.sql
-
114StoredProc/proc_InsertRewardPoints.sql
-
26StoredProc/proc_SendTransaction.sql
-
162StoredProc/proc_get_exrate_master.sql
-
13functions/FNA_GET_RUNNING_BALANCE_POINT.sql
@ -0,0 +1,114 @@ |
|||
|
|||
|
|||
ALTER PROC [dbo].[proc_InsertRewardPoints] ( |
|||
@Flag VARCHAR(20) |
|||
,@TranId BIGINT = NULL |
|||
,@CustomerId BIGINT = NULL |
|||
,@ReferralId BIGINT = NULL |
|||
,@rewardPoints INT = NULL |
|||
,@rewardValue MONEY = NULL |
|||
) |
|||
AS; |
|||
SET NOCOUNT ON; |
|||
SET XACT_ABORT ON; |
|||
-- #1526 - Post production fixes for Redeem & Earn |
|||
BEGIN |
|||
DECLARE @sourceCustomerId INT, @destinationCustomerId INT, @code NVARCHAR(50), @runningBalance MONEY, @totalDrAmount MONEY |
|||
, @totalCrAmount MONEY , @transactionPoints INT, @registrationPoints INT, @EquivalentPointsForOne INT, @AvailableBalance MONEY |
|||
|
|||
SELECT @transactionPoints = Points |
|||
FROM TBL_PROMOTION_SETUP (NOLOCK) |
|||
WHERE PromotionType = 'REGISTRATION' |
|||
AND IsActive = 1 |
|||
|
|||
SELECT @registrationPoints = Points |
|||
FROM TBL_PROMOTION_SETUP (NOLOCK) |
|||
WHERE PromotionType = 'TRANSACTION' |
|||
AND IsActive = 1 |
|||
|
|||
SELECT @EquivalentPointsForOne = Points |
|||
FROM TBL_PROMOTION_MASTER_SETUP (NOLOCK) |
|||
WHERE IsActive = 1 |
|||
|
|||
IF @Flag = 'REGISTER' |
|||
BEGIN |
|||
--@CustomerId = Customer who is newly registering in the system |
|||
--@ReferralId = Customer who is already in the system/ who have referred @CustomerId |
|||
--EXEC proc_InsertRewardPoints @Flag = 'REGISTER', @CustomerId = 1, @ReferralId = 2 |
|||
INSERT INTO Customer_Promotion(sourceCustomerId, destinationCustomerId, code, codeType, referenceId, rewardType, amount, createdDate, status, approvedDate, tranType, runningBalance, EquivalentPoints) |
|||
SELECT @CustomerId, @ReferralId, membershipId, 'REGISTRATION', @ReferralId, 'REFER_EARN', @registrationPoints/@EquivalentPointsForOne, GETDATE(), 1, GETDATE(), 'CR' |
|||
, DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@CustomerId) + (@registrationPoints/@EquivalentPointsForOne), @registrationPoints |
|||
FROM customerMaster (NOLOCK) |
|||
WHERE customerId = @CustomerId |
|||
|
|||
UNION |
|||
|
|||
SELECT @ReferralId, @ReferralId, membershipId, 'REGISTRATION', @ReferralId, 'REFER_EARN', @registrationPoints/@EquivalentPointsForOne, GETDATE(), 1, GETDATE(), 'CR' |
|||
, DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@ReferralId) + (@registrationPoints/@EquivalentPointsForOne), @registrationPoints |
|||
FROM customerMaster (NOLOCK) |
|||
WHERE customerId = @ReferralId |
|||
|
|||
UPDATE customerMaster SET bonusPoint = ISNULL(bonusPoint, 0) + @registrationPoints WHERE customerId = @CustomerId |
|||
UPDATE customerMaster SET bonusPoint = ISNULL(bonusPoint, 0) + @registrationPoints WHERE customerId = @ReferralId |
|||
END |
|||
ELSE IF @Flag = 'TRANSACTION' |
|||
BEGIN |
|||
--@CustomerId = Customer who is doing transaction |
|||
--EXEC proc_InsertRewardPoints @Flag = 'TRANSACTION', @CustomerId = 1, @TranId = 1234567890 |
|||
IF EXISTS(SELECT 'X' FROM REMITTRAN(NOLOCK) WHERE ID = @TranId AND CAMT <= 100) |
|||
BEGIN |
|||
SELECT @sourceCustomerId = sourceCustomerId, @destinationCustomerId = destinationCustomerId |
|||
FROM Customer_Promotion (NOLOCK) |
|||
WHERE sourceCustomerId = @CustomerId |
|||
and code = 'REGISTRATION' |
|||
|
|||
IF ISNULL(@destinationCustomerId, 0) <> 0 |
|||
BEGIN |
|||
IF NOT EXISTS(SELECT 'X' FROM Customer_Promotion(NOLOCK) WHERE code = 'FIRST_TXN' AND sourceCustomerId = @CustomerId) |
|||
BEGIN |
|||
INSERT INTO Customer_Promotion(sourceCustomerId, destinationCustomerId, code, codeType, referenceId, rewardType, amount, createdDate, status, approvedDate, tranType, runningBalance, EquivalentPoints) |
|||
SELECT @sourceCustomerId, @destinationCustomerId, membershipId, 'FIRST_TXN', @TranId, 'REFER_EARN', @transactionPoints/@EquivalentPointsForOne, GETDATE(), 1, GETDATE(), 'CR' |
|||
, DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@sourceCustomerId) + (@transactionPoints/@EquivalentPointsForOne), @transactionPoints |
|||
FROM customerMaster (NOLOCK) |
|||
WHERE customerId = @sourceCustomerId |
|||
|
|||
UNION |
|||
|
|||
SELECT @destinationCustomerId, @sourceCustomerId, membershipId, 'FIRST_TXN', @TranId, 'REFER_EARN', @transactionPoints/@EquivalentPointsForOne, GETDATE(), 1, GETDATE(), 'CR' |
|||
, DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@destinationCustomerId) + (@transactionPoints/@EquivalentPointsForOne), @transactionPoints |
|||
FROM customerMaster (NOLOCK) |
|||
WHERE customerId = @destinationCustomerId |
|||
|
|||
UPDATE customerMaster SET bonusPoint = ISNULL(bonusPoint, 0) + @transactionPoints WHERE customerId = @sourceCustomerId |
|||
UPDATE customerMaster SET bonusPoint = ISNULL(bonusPoint, 0) + @transactionPoints WHERE customerId = @destinationCustomerId |
|||
END |
|||
END |
|||
END |
|||
END |
|||
ELSE IF @Flag = 'DEBIT' |
|||
BEGIN |
|||
IF ISNULL(@rewardPoints, 0) > 0 |
|||
BEGIN |
|||
--@CustomerId = Customer who is doing transaction |
|||
--EXEC proc_InsertRewardPoints @Flag = 'DEBIT', @CustomerId = 1, @rewardPoints = 100, @TranId = 1234567890 |
|||
|
|||
SELECT @AvailableBalance = DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@CustomerId) |
|||
|
|||
IF ISNULL(@rewardPoints, 0) > ISNULL(@AvailableBalance, 0) |
|||
BEGIN |
|||
SELECT 1 Code, 'Insufficient Balance For Rededem!' msg, NULL id |
|||
RETURN; |
|||
END |
|||
|
|||
INSERT INTO Customer_Promotion(sourceCustomerId, destinationCustomerId, code, codeType, referenceId, rewardType, amount, createdDate, status, approvedDate, tranType, runningBalance, EquivalentPoints) |
|||
SELECT @CustomerId, 0, membershipId, 'REDEEM', @TranId, 'REFER_EARN', @rewardValue, GETDATE(), 1, GETDATE(), 'DR' |
|||
, DBO.FNA_GET_AVAILABLE_BALANCE_POINTS(@CustomerId) - @rewardValue, @rewardValue * @EquivalentPointsForOne |
|||
FROM customerMaster (NOLOCK) |
|||
WHERE customerId = @CustomerId |
|||
|
|||
UPDATE customerMaster SET bonusPoint = ISNULL(bonusPoint, 0) - @rewardPoints WHERE customerId = @CustomerId |
|||
END |
|||
END |
|||
END |
|||
|
|||
|
@ -0,0 +1,13 @@ |
|||
|
|||
ALTER FUNCTION [dbo].[FNA_GET_AVAILABLE_BALANCE_POINTS](@CustomerId BIGINT) |
|||
RETURNS MONEY |
|||
AS |
|||
BEGIN |
|||
DECLARE @BALANCE MONEY |
|||
|
|||
SELECT @BALANCE = ISNULL(SUM(CASE WHEN tranType = 'CR' THEN amount ELSE -1 * amount END), 0) |
|||
FROM Customer_Promotion CP(NOLOCK) |
|||
WHERE sourceCustomerId = @CustomerId |
|||
|
|||
RETURN ISNULL(@BALANCE, 0) |
|||
END |
Write
Preview
Loading…
Cancel
Save
Reference in new issue