Browse Source

merge after refern n earn

master
shakun 1 year ago
parent
commit
55a7860290
  1. 0
      ExecuteScript/17732-menu-disable.sql
  2. 0
      ExecuteScript/CLEAR TXN BEFORE DATA MIGRATION.sql
  3. 0
      ExecuteScript/Identity_Insert_AgentMaster.sql
  4. 0
      ExecuteScript/MobileAPI.sql
  5. 0
      ExecuteScript/idTypes.sql
  6. 0
      ExecuteScript/insertAC.sql
  7. 114
      StoredProc/proc_InsertRewardPoints.sql
  8. 26
      StoredProc/proc_SendTransaction.sql
  9. 162
      StoredProc/proc_get_exrate_master.sql
  10. 13
      functions/FNA_GET_RUNNING_BALANCE_POINT.sql

0
StoredProc/17732-menu-disable.sql → ExecuteScript/17732-menu-disable.sql

0
CLEAR TXN BEFORE DATA MIGRATION.sql → ExecuteScript/CLEAR TXN BEFORE DATA MIGRATION.sql

0
Identity_Insert_AgentMaster.sql → ExecuteScript/Identity_Insert_AgentMaster.sql

0
MobileAPI.sql → ExecuteScript/MobileAPI.sql

0
idTypes.sql → ExecuteScript/idTypes.sql

0
insertAC.sql → ExecuteScript/insertAC.sql

114
StoredProc/proc_InsertRewardPoints.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

26
StoredProc/proc_SendTransaction.sql

@ -619,9 +619,9 @@ BEGIN TRY
,@schemeCount = @schemeCount OUT
,@customerId = @senderId
,@createdFrom = 'M'
,@pCountry = @pCountryId
print @isEligible
print '@isEligible.Send' + @isEligible;
print '@@trancount.Send' + CAST(@trancount AS VARCHAR);
IF @isEligible = 'Y'
BEGIN
SET @iServiceCharge = 0
@ -633,7 +633,7 @@ BEGIN TRY
SELECT @iServiceChargeTemp = ISNULL(amount, - 1)
FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @collAmt, @collCurr)
SELECT @iServiceCharge = ISNULL(@iServiceChargeTemp,0) - ISNULL(@discountedFee,0)
--SELECT @iServiceCharge = ISNULL(@iServiceChargeTemp,0) - ISNULL(@discountedFee,0)
IF @iServiceCharge < 0 -- @iServiceCharge = - 1
BEGIN
@ -667,7 +667,15 @@ BEGIN TRY
RETURN
END
SELECT @iTAmt = @collAmt - @iServiceCharge
IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
BEGIN
EXEC proc_errorHandler 1
,'You do not have sufficient points for redeem!'
,NULL
RETURN;
END
SELECT @iTAmt = @collAmt - @iServiceCharge + ISNULL(@discountedFee, 0)
SELECT TOP 1 @place = place
,@currDecimal = currDecimal
@ -1435,7 +1443,6 @@ BEGIN TRY
,@isManualSc = 'N'
,@referralCode = @introducer
,@serviceCharge = @iServiceCharge
,@pCountry = @pCountryId
--------------------------#########------------OFAC/COMPLIANCE INSERT (IF EXISTS)---------------########----------------------
@ -1566,7 +1573,12 @@ BEGIN TRY
SELECT @SenderId,'Tran ID : '+CAST(@tranId AS VARCHAR)+' . Your transaction has been processed successfully but your balance is insufficient. Please load your wallet.','Insufficent Balance.',getdate(),'',@tranId,0,0,0,0,'INFO', 'Y'
END
--New logic for referral
IF ISNULL(@discountedFee, 0) > 0
EXEC proc_InsertRewardPoints @Flag = 'DEBIT', @CustomerId = @senderId, @rewardValue = @discountedFee, @TranId = @tranId
EXEC proc_InsertRewardPoints @Flag = 'TRANSACTION', @CustomerId = @senderId, @TranId = @tranId
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;

162
StoredProc/proc_get_exrate_master.sql

@ -94,7 +94,6 @@ BEGIN
,@schemeCount = @schemeCount OUT
,@customerId = @senderId
,@createdFrom = 'M'
,@pCountry = @pCountryId
IF NOT EXISTS (
SELECT 1
@ -120,12 +119,12 @@ BEGIN
END
END
print '@isFirstTran' + '-> ' + @isFirstTran
SELECT @createdFrom = serviceUsedFor
FROM customerMaster(NOLOCK)
WHERE customerId = @senderId
SET @sCountryId = 113
SET @sCountryId = 233
IF ISNULL(@pCountryId, 0) = 0
SELECT @pCountryId = countryId
@ -157,6 +156,14 @@ BEGIN
-- SET @isFirstTran = 'Y'
--END
-- END
IF dbo.FNA_GET_AVAILABLE_BALANCE_POINTS(@senderId) < ISNULL(@discountedFee, 0)
BEGIN
SELECT '1' ErrorCode
,'You do not have sufficient points for redeem!' Msg
,NULL id
RETURN
END
IF @flag = 'False'
AND @ProcessFor IN ('dashboard')
@ -178,7 +185,8 @@ BEGIN
AND IsActive = 1
AND ISNULL(PaymentMethod, @deliveryMethodId) = @deliveryMethodId
END
PRINT '@payoutPartner'
PRINT @payoutPartner;
IF @payoutPartner IS NOT NULL
BEGIN
--GET PAYOUT AGENT DETAILS
@ -238,6 +246,9 @@ BEGIN
RETURN
END
pRINT '@pAgent';
--pRINT @pAgent;
IF @flag = 'false'
BEGIN
IF @pCountryId = 151
@ -247,12 +258,13 @@ BEGIN
INTO #AgentList
FROM agentMaster(NOLOCK)
WHERE extCode = 'NP ANYWHERE'
PRINT '@sAgent'
PRINT @sAgent
PRINT '@sBranch'
PRINT @sBranch
PRINT @sCountryId;
PRINT @sAgent;
PRINT @sBranch;
PRINT @collCurr;
PRINT @pCountryId;
PRINT @pCurr;
PRINT @deliveryMethodId;
SELECT @exRate = customerRate
,@pCurrHoMargin = pCurrHoMargin
FROM (
@ -282,13 +294,14 @@ BEGIN
RETURN
END
PRINT @isFirstTran
PRINT @isEligible
PRINT '@isFirstTran:' + CAST( @isFirstTran AS VARCHAR);
PRINT '@isEligible:' + CAST( @isEligible AS VARCHAR);
PRINT '@tranCount:' + CAST( @tranCount AS VARCHAR);
PRINT '@@schemeCount:' + CAST( @schemeCount AS VARCHAR);
IF @calBy = 'C'
BEGIN
IF (
@tranCount = @schemeCount
IF ( @tranCount >= @schemeCount
AND ISNULL(@user, 'onlinedefault') <> 'onlinedefault'
--AND ISNULL(@ProcessFor, '') = 'send'
AND @isEligible = 'Y'
@ -311,19 +324,19 @@ BEGIN
SELECT @serviceChargetmp = isnull(amount, 0)
FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
IF (@discountedFee > '0.00')
AND (@serviceChargetmp < @discountedFee)
BEGIN
SELECT '8' ErrorCode
,'Redeem point can not be more than service charge' Msg
,NULL id
RETURN;
END
ELSE
BEGIN
SELECT @serviceCharge = @serviceChargetmp - ISNULL(@discountedFee, 0)
END
--IF (@discountedFee > '0.00')
-- AND (@serviceChargetmp < @discountedFee)
--BEGIN
-- SELECT '8' ErrorCode
-- ,'Redeem point can not be more than service charge' Msg
-- ,NULL id
-- RETURN;
--END
--ELSE
--BEGIN
-- SELECT @serviceCharge = @serviceChargetmp - ISNULL(@discountedFee, 0)
--END
END
ELSE
BEGIN
@ -356,7 +369,7 @@ BEGIN
SET @scDiscount = @serviceCharge - @scValue
END
SET @tAmt = @cAmt - @serviceCharge + @scDiscount
SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@discountedFee, 0)
SET @pAmt = @tAmt * (@exRate + @exRateOffer)
SET @pAmt = FLOOR(@pAmt)
END
@ -366,7 +379,7 @@ BEGIN
SET @tAmt = CEILING(@pAmt / (@exRate + @exRateOffer))
IF (
@tranCount = @schemeCount
@tranCount >= @schemeCount
AND ISNULL(@user, 'onlinedefault') <> 'onlinedefault'
--AND ISNULL(@ProcessFor, '') = 'send'
AND @isEligible = 'Y'
@ -389,19 +402,19 @@ BEGIN
SELECT @serviceChargetmp = isnull(amount, 0)
FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
IF (@discountedFee > '0.00')
AND (@serviceChargetmp < @discountedFee)
BEGIN
SELECT '8' ErrorCode
,'Redeem point can not be more than service charge' Msg
,NULL id
RETURN;
END
ELSE
BEGIN
SELECT @serviceCharge = @serviceChargetmp - ISNULL(@discountedFee, 0)
END
--IF (@discountedFee > '0.00')
-- AND (@serviceChargetmp < @discountedFee)
--BEGIN
-- SELECT '8' ErrorCode
-- ,'Redeem point can not be more than service charge' Msg
-- ,NULL id
-- RETURN;
--END
--ELSE
--BEGIN
-- SELECT @serviceCharge = @serviceChargetmp - ISNULL(@discountedFee, 0)
--END
END
ELSE
BEGIN
@ -433,7 +446,7 @@ BEGIN
SET @scDiscount = @serviceCharge - @scValue
END
SET @cAmt = (@tAmt + @serviceCharge - @scDiscount)
SET @cAmt = (@tAmt + @serviceCharge - @scDiscount) - ISNULL(@discountedFee, 0)
SET @cAmt = CEILING(@cAmt)
END
@ -658,19 +671,19 @@ BEGIN
SELECT @serviceChargetmp = ISNULL(amount, 0)
FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr)
IF (@discountedFee > '0.00')
AND (@serviceChargetmp < @discountedFee)
BEGIN
SELECT '8' ErrorCode
,'Redeem points can not be more than service charge' Msg
,NULL id
RETURN;
END
ELSE
BEGIN
SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
END
--IF (@discountedFee > '0.00')
-- AND (@serviceChargetmp < @discountedFee)
--BEGIN
-- SELECT '8' ErrorCode
-- ,'Redeem points can not be more than service charge' Msg
-- ,NULL id
-- RETURN;
--END
--ELSE
--BEGIN
-- SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
--END
END
ELSE
BEGIN
@ -703,7 +716,7 @@ BEGIN
SET @scDiscount = @serviceCharge - @scValue
END
SET @tAmt = @cAmt - @serviceCharge + @scDiscount
SET @tAmt = @cAmt - @serviceCharge + @scDiscount + ISNULL(@discountedFee, 0)
SET @pAmt = @tAmt * (@exRate + @exRateOffer)
SET @pAmt = FLOOR(@pAmt)
END
@ -716,19 +729,19 @@ BEGIN
SELECT @serviceChargetmp = isnull(amount, 0)
FROM [dbo].FNAGetServiceCharge(@sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @tAmt, @collCurr)
IF (@discountedFee > '0.00')
AND (@serviceCharge < @discountedFee)
BEGIN
SELECT '8' ErrorCode
,'Redeem points can not be more than service charge' Msg
,NULL id
RETURN;
END
ELSE
BEGIN
SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
END
--IF (@discountedFee > '0.00')
-- AND (@serviceCharge < @discountedFee)
--BEGIN
-- SELECT '8' ErrorCode
-- ,'Redeem points can not be more than service charge' Msg
-- ,NULL id
-- RETURN;
--END
--ELSE
--BEGIN
-- SELECT @serviceCharge = ISNULL(@serviceChargetmp, 0) - ISNULL(@discountedFee, 0)
--END
END
ELSE
BEGIN
@ -759,8 +772,13 @@ BEGIN
SET @scDiscount = @serviceCharge - @scValue
END
SET @cAmt = (@tAmt + @serviceCharge - @scDiscount)
SET @cAmt = (@tAmt + @serviceCharge - @scDiscount)-- - ISNULL(@discountedFee, 0)
SET @cAmt = ROUND(@cAmt, @currDecimal)
--New logic for calculating new tAmt and pAmt after adding discount fee
SET @tAmt = @tAmt + ISNULL(@discountedFee, 0)
SET @pAmt = @tAmt * (@exRate + @exRateOffer)
SET @pAmt = FLOOR(@pAmt)
END
--4. Validate Country Sending Limit

13
functions/FNA_GET_RUNNING_BALANCE_POINT.sql

@ -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
Loading…
Cancel
Save