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.

196 lines
5.3 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_LockUnlockTransaction] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_LockUnlockTransaction]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_LockUnlockTransaction] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. /*
  12. EXEC proc_loclUnlockTransaction @flag = 'st', @controlNo = '91598256530'
  13. SELECT * FROM remitTran where controlNo = '91181462426'
  14. select * from staticDataValue where typeid in (5400, 5500)
  15. */
  16. CREATE PROC [dbo].[proc_LockUnlockTransaction]
  17. @flag VARCHAR(50)
  18. ,@controlNo VARCHAR(20) = NULL
  19. ,@user VARCHAR(30) = NULL
  20. ,@tranId INT = NULL
  21. ,@comments VARCHAR(MAX) = NULL
  22. ,@sortBy VARCHAR(50) = NULL
  23. ,@sortOrder VARCHAR(5) = NULL
  24. ,@pageSize INT = NULL
  25. ,@pageNumber INT = NULL
  26. AS
  27. DECLARE
  28. @select_field_list VARCHAR(MAX)
  29. ,@extra_field_list VARCHAR(MAX)
  30. ,@table VARCHAR(MAX)
  31. ,@sql_filter VARCHAR(MAX)
  32. SET NOCOUNT ON
  33. SET XACT_ABORT ON
  34. DECLARE @controlNoEncrypted VARCHAR(100)
  35. SET @controlNo = UPPER(LTRIM(RTRIM(@controlNo)))
  36. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  37. --EXEC proc_LockUnlockTransaction @flag = 'b' ,@pageNumber='1', @pageSize='10', @sortBy='controlNo', @sortOrder='ASC', @user = 'admin'
  38. IF @flag = 'b'
  39. BEGIN
  40. SET @table = '(
  41. SELECT
  42. trn.id
  43. , controlNo = dbo.FNADecryptString(controlNo)
  44. , controlNo1 = ''<a href="#" onclick="OpenInNewWindow('''''+dbo.FNAGetURL()+'Remit/Transaction/Reports/SearchTransaction.aspx?commentFlag=N&showBankDetail=N&tranId=''+CAST(trn.id AS VARCHAR)+'''''')">''+dbo.FNADecryptString(controlNo)+''</a>''
  45. ,sCustomerId = sen.customerId
  46. ,senderName = sen.firstName + ISNULL( '' '' + sen.middleName, '''') + ISNULL( '' '' + sen.lastName1, '''') + ISNULL( '' '' + sen.lastName2, '''')
  47. ,sCountryName = sen.country
  48. ,sStateName = sen.state
  49. ,sCity = sen.city
  50. ,sAddress = sen.address
  51. ,rCustomerId = rec.customerId
  52. ,receiverName = rec.firstName + ISNULL( '' '' + rec.middleName, '''') + ISNULL( '' '' + rec.lastName1, '''') + ISNULL( '' '' + rec.lastName2, '''')
  53. ,rCountryName = rec.country
  54. ,rStateName = rec.state
  55. ,rCity = rec.city
  56. ,rAddress = rec.address
  57. ,sAgentName = trn.sAgentName
  58. FROM remitTran trn WITH(NOLOCK)
  59. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  60. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  61. WHERE trn.tranStatus = ''Block''
  62. '
  63. SET @sql_filter = ''
  64. IF @controlNo IS NOT NULL
  65. SET @table = @table + ' AND trn.controlNo = ''' + LTRIM(RTRIM(@controlNoEncrypted)) + ''''
  66. SET @select_field_list ='
  67. id
  68. ,controlNo
  69. ,sCustomerId
  70. ,senderName
  71. ,sCountryName
  72. ,sStateName
  73. ,sCity
  74. ,sAddress
  75. ,rCustomerId
  76. ,receiverName
  77. ,rCountryName
  78. ,rStateName
  79. ,rCity
  80. ,rAddress
  81. ,sAgentName
  82. ,controlNo1
  83. '
  84. SET @table = @table + ') x'
  85. EXEC dbo.proc_paging
  86. @table
  87. ,@sql_filter
  88. ,@select_field_list
  89. ,@extra_field_list
  90. ,@sortBy
  91. ,@sortOrder
  92. ,@pageSize
  93. ,@pageNumber
  94. END
  95. ELSE IF @flag = 'lt'
  96. BEGIN
  97. IF NOT EXISTS (SELECT 'X' FROM remitTran WITH (NOLOCK)
  98. WHERE controlNo = @controlNoEncrypted)
  99. BEGIN
  100. EXEC proc_errorHandler 1, 'Transaction not found', @controlNo
  101. IF @@TRANCOUNT > 0
  102. ROLLBACK TRANSACTION
  103. RETURN;
  104. END
  105. IF @comments IS NULL
  106. BEGIN
  107. EXEC proc_errorHandler 1, 'Comment can not be blank.', @tranId
  108. IF @@TRANCOUNT > 0
  109. ROLLBACK TRANSACTION
  110. RETURN;
  111. END
  112. BEGIN TRANSACTION
  113. UPDATE remitTran SET
  114. blockedBy = @user
  115. ,tranStatus = 'Block'
  116. ,blockedDate = GETDATE()
  117. WHERE controlNo = @controlNoEncrypted
  118. --comments
  119. SELECT @tranId = id FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  120. EXEC proc_transactionLogs @flag='i', @user=@user, @tranId=@tranId, @message=@comments,@controlNo=@controlNoEncrypted
  121. COMMIT TRANSACTION
  122. EXEC proc_errorHandler 0, 'Transaction blocked successfully.', @tranId
  123. EXEC proc_addCommentAPI @flag = 'i', @controlNo = @controlNo, @user = @user, @message = @comments, @agentRefId = NULL
  124. END
  125. ELSE IF @flag = 'ut'
  126. BEGIN
  127. IF NOT EXISTS (SELECT 'X' FROM remitTran WITH (NOLOCK)
  128. WHERE controlNo = @controlNoEncrypted and tranStatus='Block' and payStatus='Unpaid')
  129. BEGIN
  130. EXEC proc_errorHandler 1, 'Blocked Transaction not found', @controlNo
  131. IF @@TRANCOUNT > 0
  132. ROLLBACK TRANSACTION
  133. RETURN;
  134. END
  135. IF @comments IS NULL
  136. BEGIN
  137. EXEC proc_errorHandler 1, 'Comment can not be blank.', @tranId
  138. IF @@TRANCOUNT > 0
  139. ROLLBACK TRANSACTION
  140. RETURN;
  141. END
  142. BEGIN TRANSACTION
  143. UPDATE remitTran SET
  144. modifiedBy = @user
  145. ,tranStatus = 'Payment'
  146. ,modifiedDate = GETDATE()
  147. ,modifiedDateLocal = DBO.FNADateFormatTZ(GETDATE(), @user)
  148. WHERE controlNo = @controlNoEncrypted
  149. AND tranStatus='Block' AND payStatus='Unpaid'
  150. --comments
  151. SELECT @tranId = id FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  152. EXEC proc_transactionLogs @flag='i', @user=@user, @tranId=@tranId, @message=@comments, @controlNo=@controlNoEncrypted
  153. COMMIT TRANSACTION
  154. EXEC proc_errorHandler 0, 'Transaction unlocked successfully.', @tranId
  155. END
  156. GO