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.

140 lines
4.1 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_online_customerWallet] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_online_customerWallet]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_online_customerWallet] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. CREATE PROC [dbo].[proc_online_customerWallet]
  12. @flag VARCHAR(50) = NULL
  13. ,@customerId VARCHAR(30) = NULL
  14. ,@amount VARCHAR(15) = NULL
  15. ,@remarks VARCHAR(150) = NULL
  16. ,@fromDate VARCHAR(20) = NULL
  17. ,@toDate VARCHAR(20) = NULL
  18. AS
  19. SET NOCOUNT ON;
  20. SET XACT_ABORT ON;
  21. BEGIN TRY
  22. IF @flag = 'i'
  23. BEGIN
  24. DECLARE
  25. @walletTxnId BIGINT
  26. ,@bankId INT
  27. ,@remBalance VARCHAR(20)
  28. ,@withDrawalCharge VARCHAR(20)
  29. ,@availableBal VARCHAR(20)
  30. SELECT @withDrawalCharge = 1000
  31. SELECT @bankId = bankName, @availableBal = availableBalance FROM customerMaster(NOLOCK) WHERE customerId = @customerId
  32. SELECT '1' ErrorCode, 'Sorry, you can not perform withfrawal. Please contact GME HO for any assistance' Msg, '' Id
  33. RETURN
  34. IF ISNULL(@amount,0) <=0
  35. BEGIN
  36. SELECT '1' ErrorCode, 'Invalid Operation withdraw amount not sufficient.' Msg, '' Id
  37. RETURN
  38. END
  39. IF CAST(@availableBal AS MONEY) <= 0
  40. BEGIN
  41. SELECT '1' ErrorCode,'Invalid Operation available balance not sufficient.' Msg, '' Id
  42. RETURN
  43. END
  44. IF CAST(@availableBal AS MONEY) < @amount
  45. BEGIN
  46. SELECT '1' ErrorCode,'Invalid Operation available balance not sufficient.' Msg, '' Id
  47. RETURN
  48. END
  49. INSERT INTO WalletTransactions(
  50. createdDate
  51. ,customerId
  52. ,bankId
  53. ,controlNo
  54. ,tranId
  55. ,remarks
  56. ,amount
  57. ,approvedDate
  58. ,approvedBy
  59. ,status
  60. )
  61. SELECT GETDATE(), @customerId, @bankId, NULL, NULL, 'Customer Withdrawal', @amount, NULL, NULL, 1
  62. SELECT @walletTxnId = SCOPE_IDENTITY()
  63. INSERT INTO WithdrawalLogs(
  64. WalletTransactionId
  65. ,createdDate
  66. ,customerId
  67. ,bankId
  68. ,remarks
  69. ,amount
  70. ,approvedDate
  71. ,approvedBy
  72. ,status
  73. )
  74. SELECT @walletTxnId, GETDATE(), @customerId, @bankId, @remarks, @amount, NULL, NULL, 1
  75. SELECT @remBalance = ISNULL(CAST(@availableBal AS MONEY), 0.00) - CAST(@withDrawalCharge AS MONEY) - CAST(@amount AS MONEY)
  76. UPDATE customerMaster SET availableBalance = @remBalance WHERE customerId = @customerId
  77. SELECT '0' ErrorCode, 'Your request for withdrawal of amount ' + @amount + ' has been successful.' Msg, '' Id, @remBalance Extra
  78. END
  79. IF @flag = 's'
  80. BEGIN
  81. --SELECT Debit = '' , Credit = '', [Date] = '', Particular = 'Opening Balance', Balance = ISNULL(SUM(amount),'0.00')
  82. --FROM WalletTransactions(NOLOCK)
  83. --WHERE customerId = @customerId AND createdDate < @fromDate
  84. --UNION ALL
  85. --SELECT Debit = CASE WHEN amount > 0 THEN amount ELSE '0.00' END,
  86. -- Credit = CASE WHEN amount < 0 THEN amount ELSE '0.00' END,
  87. -- [Date] = CONVERT(VARCHAR(10), wt.createdDate, 103),
  88. -- Particular = remarks,
  89. -- Balance = ''
  90. --FROM WalletTransactions(NOLOCK) wt INNER JOIN customerMaster cm ON wt.customerId = cm.customerId
  91. --WHERE wt.customerId = @customerId AND wt.createdDate BETWEEN CAST(@fromDate AS DATETIME) AND CAST(@toDate AS DATETIME) + '23:59:59'
  92. DECLARE @SQL VARCHAR(MAX),@email VARCHAR(500), @requestFrom varchar(20)
  93. SELECT @email=email FROM customerMaster(NOLOCK) WHERE customerId = @customerId
  94. EXEC mobile_proc_WalletStatement @UserID = @email,@startDate = @fromDate ,@endDate = @toDate
  95. --DECLARE @RESULT TABLE(ID INT IDENTITY(1,1),TRNDate VARCHAR(10),tran_rmks VARCHAR(MAX),DRTotal DECIMAL(18,2),cRTotal DECIMAL(18,2),end_clr_balance DECIMAL(18,2),ref_num VARCHAR(20))
  96. --SET @SQL = 'mobile_proc_WalletStatement @UserID = ''' + @email +''',@startDate = ''' + @fromDate + ''',@endDate = ''' + @toDate + ''''
  97. --INSERT INTO @RESULT
  98. --EXEC(@SQL)
  99. --SELECT
  100. --Debit= DRTotal,
  101. --Credit= cRTotal,
  102. --[Date] = TrnDate,
  103. --Particular= tran_Rmks,
  104. --Balance = ISNULL(end_Clr_Balance,'0.00')
  105. --FROM @RESULT
  106. END
  107. END TRY
  108. BEGIN CATCH
  109. IF @@TRANCOUNT > 0
  110. ROLLBACK TRANSACTION
  111. DECLARE @errorMessage VARCHAR(MAX)
  112. SET @errorMessage = ERROR_MESSAGE()
  113. EXEC proc_errorHandler 1, @errorMessage, @customerId
  114. END CATCH
  115. GO