You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 lines
13 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[PROC_PointMasterDetails] Script Date: 7/4/2019 11:35:48 AM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. --SELECT * FROM dbo.PointSetup
  9. --SELECT * FROM PointHistory
  10. --SELECT TOP 10 createdBy,pCountry,pAgent, * FROM dbo.remitTran(NOLOCK) ORDER BY id desc
  11. --EXEC PROC_PointMasterDetails @flag='send',@user='mahmet@gmail.com',@tranId='100485514'
  12. --EXEC PROC_PointMasterDetails @flag='cancel',@user='mahmet@gmail.com',@tranId='100485514'
  13. --SELECT bonusPoint FROM dbo.customerMaster WHERE customerId=85149
  14. CREATE OR ALTER PROC [dbo].[PROC_PointMasterDetails]
  15. (
  16. @flag VARCHAR(100)
  17. ,@customerId VARCHAR(100) = NULL
  18. ,@tranId BIGINT = NULL
  19. ,@holdtranId BIGINT = NULL
  20. )
  21. AS
  22. SET XACT_ABORT ON
  23. SET NOCOUNT ON
  24. BEGIN TRY
  25. DECLARE @condition1 VARCHAR(200)=NULL
  26. ,@condition2 INT=NULL
  27. ,@typeOneValue MONEY=NULL
  28. ,@typeTwoValue MONEY=NULL
  29. ,@result MONEY=NULL
  30. ,@email VARCHAR(200)=NULL
  31. ,@availablePoint MONEY=NULL
  32. ,@schemeStartDate DATETIME=NULL
  33. ,@schemeEndDate DATETIME=NULL
  34. ,@ReferalCode VARCHAR(30) =NULL
  35. ,@ReferalCustomerId BIGINT
  36. ,@ReferalValue INT
  37. ,@ReferalAvailablePoint INT
  38. -- IF CUSTOMER IS REFERAL AND FIRST TRANSACTION GIVE 5000 POINT EACH
  39. /*point type
  40. 1 : \ (txncount saving)
  41. 2 : a<\ (amount saving )
  42. 9 : (point use)
  43. 11: \  ͌(Cancel of txncount saving)
  44. 21: a<\  ͌(Cancel of txnAmount saving)
  45. 91: ͌(Cancel of point use)
  46. */
  47. SELECT TOP 1 @email=email, @availablePoint=ISNULL(bonusPoint,0), @ReferalCode=referelCode FROM dbo.customerMaster(NOLOCK) WHERE customerId=@customerId
  48. IF NOT EXISTS(SELECT 'X' FROM customerMaster (NOLOCK) WHERE customerId = @customerId AND ISNULL(isActive,'N')='Y')
  49. BEGIN
  50. EXEC proc_errorHandler '1', 'Invalid Customer.', @customerId
  51. RETURN
  52. END
  53. IF NOT EXISTS(SELECT 'x' FROM PointSetup (NOLOCK) WHERE GETDATE() BETWEEN schemeStartDate AND schemeEndDate)
  54. BEGIN
  55. EXEC proc_errorHandler '1', 'Invalid Point.', @customerId
  56. RETURN
  57. END
  58. SELECT @schemeStartDate=schemeStartDate, @schemeEndDate=schemeEndDate FROM PointSetup (NOLOCK) WHERE conditionType=1
  59. SELECT @condition1 = COUNT(1) FROM dbo.remitTran(NOLOCK) WHERE createdBy=@email AND approvedDate BETWEEN @schemeStartDate AND @schemeEndDate
  60. SELECT @condition2 = cAmt FROM dbo.remitTran(NOLOCK) WHERE holdTranId = @holdtranId AND createdBy=@email
  61. SELECT @typeOneValue = ISNULL(value,0)
  62. FROM PointSetup (NOLOCK)
  63. WHERE conditionType=1
  64. AND isActive = 1 AND isDeleted = 0
  65. AND (CONVERT(INT, @condition1) % CONVERT(INT,condition1))= 0
  66. SELECT @typeTwoValue = ISNULL(value,0)
  67. FROM PointSetup (NOLOCK)
  68. WHERE @condition2 BETWEEN condition1 AND condition2
  69. AND isActive = 1 AND isDeleted = 0 AND conditionType = '2'
  70. SET @result = @typeOneValue + @typeTwoValue
  71. IF @flag='send'
  72. BEGIN
  73. IF EXISTS (SELECT 'A' FROM PointHistory(NOLOCK) WHERE customerId=@customerId AND tranId = @holdtranId and pointType in('1','2') )
  74. BEGIN
  75. EXEC proc_errorHandler '1', 'Already Exist History.', @customerId
  76. RETURN
  77. END
  78. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  79. ---- IF CUSTOMER IS REFERAL AND FIRST TRANSACTION GIVE 5000 POINT EACH
  80. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  81. IF @condition1 = 1
  82. BEGIN
  83. SELECT @ReferalCustomerId = customerId, @ReferalAvailablePoint = bonusPoint
  84. FROM dbo.customerMaster(NOLOCK)
  85. WHERE membershipId = @ReferalCode AND approvedDate IS NOT NULL
  86. IF @ReferalCustomerId IS NOT NULL
  87. BEGIN
  88. SELECT @ReferalValue = 5000
  89. UPDATE customerMaster
  90. SET bonusPoint = ISNULL(bonusPoint,0) + ISNULL(@ReferalValue,0)
  91. WHERE customerId = @ReferalCustomerId
  92. SET @ReferalAvailablePoint = ISNULL(@ReferalAvailablePoint,0) + @ReferalValue
  93. INSERT INTO dbo.PointHistory (customerId, availablePoint, tranId, pointType, point,createdBy, createdDate)
  94. SELECT @ReferalCustomerId,@ReferalAvailablePoint,@holdtranId, 1,@ReferalValue,@email,GETDATE()
  95. END
  96. END
  97. IF @result <> 0
  98. BEGIN
  99. UPDATE customerMaster SET
  100. bonusPoint = ISNULL(bonusPoint,0) + ISNULL(@result,0)
  101. WHERE customerId = @customerId
  102. IF @typeOneValue <> 0
  103. BEGIN
  104. SET @availablePoint = ISNULL(@availablePoint,0) + ISNULL(@typeOneValue,0)
  105. INSERT INTO dbo.PointHistory (customerId, availablePoint, tranId, pointType, point,createdBy, createdDate)
  106. SELECT @customerId, @availablePoint,@holdtranId, 1,@typeOneValue,@email,GETDATE()
  107. END
  108. IF @typeTwoValue <> 0
  109. BEGIN
  110. SET @availablePoint = ISNULL(@availablePoint,0) + ISNULL(@typeTwoValue,0)
  111. INSERT INTO dbo.PointHistory (customerId, availablePoint, tranId, pointType, point,createdBy, createdDate)
  112. SELECT @customerId, @availablePoint,@holdtranId, 2,@typeTwoValue,@email,GETDATE()
  113. END
  114. EXEC proc_errorHandler '0', 'Success.', @customerId
  115. RETURN
  116. END
  117. EXEC proc_errorHandler '0', 'No Reward.', @customerId
  118. RETURN
  119. END
  120. IF @flag='cancel'
  121. BEGIN
  122. IF EXISTS (SELECT 'A' FROM PointHistory(NOLOCK) WHERE customerId=@customerId AND tranId = @holdtranId and pointType in('11','21'))
  123. BEGIN
  124. EXEC proc_errorHandler '1', 'Already Exist History.', @customerId
  125. RETURN
  126. END
  127. IF @result <>0
  128. BEGIN
  129. UPDATE customerMaster SET
  130. bonusPoint = ISNULL(bonusPoint,0) + ISNULL(@result,0)
  131. WHERE customerId = @customerId
  132. IF @typeOneValue <> 0
  133. BEGIN
  134. SET @availablePoint = ISNULL(@availablePoint,0) - ISNULL(@typeOneValue,0)
  135. INSERT INTO dbo.PointHistory (customerId, availablePoint, tranId, pointType, point,createdBy, createdDate)
  136. SELECT @customerId, @availablePoint,@holdtranId, '11',@typeOneValue,@email,GETDATE()
  137. END
  138. IF @typeTwoValue <> 0
  139. BEGIN
  140. SET @availablePoint = ISNULL(@availablePoint,0) - ISNULL(@typeTwoValue,0)
  141. INSERT INTO dbo.PointHistory (customerId, availablePoint, tranId, pointType, point,createdBy, createdDate)
  142. SELECT @customerId, @availablePoint,@holdtranId, '21',@typeTwoValue,@email,GETDATE()
  143. END
  144. EXEC proc_errorHandler '0', 'Success.', @customerId
  145. RETURN
  146. END
  147. EXEC proc_errorHandler '0', 'No Reward.', @customerId
  148. RETURN
  149. END
  150. IF @flag='expectedreward'
  151. BEGIN
  152. SELECT @result AS expectedReward
  153. EXEC proc_errorHandler '0', 'Success.', @customerId
  154. RETURN
  155. END
  156. END TRY
  157. BEGIN CATCH
  158. IF @@TRANCOUNT > 0 ROLLBACK TRAN
  159. PRINT ERROR_MESSAGE()
  160. END CATCH