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.

175 lines
10 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_txnDocUpload] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE procEDURE [dbo].[proc_txnDocUpload]
  9. @flag VARCHAR(10)
  10. ,@user VARCHAR(50) = NULL
  11. ,@id VARCHAR(50) = NULL
  12. ,@controlNo VARCHAR(50) = NULL
  13. ,@rowId VARCHAR(50) = NULL
  14. ,@tranId VARCHAR(50) = NULL
  15. ,@agent VARCHAR(50) = NULL
  16. ,@branch VARCHAR(50) = NULL
  17. ,@fileName VARCHAR(200) = NULL
  18. ,@fileType VARCHAR(10) = NULL
  19. ,@docFolder VARCHAR(50) = NULL
  20. AS
  21. SET NOCOUNT ON;
  22. BEGIN
  23. DECLARE @controlNoEncrypted VARCHAR(50)
  24. IF @flag='s'
  25. BEGIN
  26. DECLARE @table VARCHAR(MAX),@sqlFilter VARCHAR(MAX)='where 1=1'
  27. IF @controlNo IS NOT NULL AND @tranId IS NULL
  28. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  29. IF @controlNo IS NULL
  30. BEGIN
  31. SELECT @controlNoEncrypted = controlNo, @controlNo = dbo.FNADecryptString(controlNo) FROM vwRemitTran WITH(NOLOCK) WHERE id = @tranId OR holdTranId = @tranId
  32. END
  33. IF @controlNo IS NULL
  34. BEGIN
  35. EXEC proc_errorHandler 1, 'Invalid ICN or Tran ID.', NULL
  36. RETURN
  37. END
  38. SELECT
  39. DISTINCT
  40. ControlNo = @controlNo
  41. ,sender = senderName
  42. ,receiver = receiverName
  43. ,sendingAmount = dbo.ShowDecimal(cAMt)
  44. ,receivingAmount = dbo.ShowDecimal(pAmt)
  45. ,transactionDate = CONVERT(VARCHAR,T.createdDate ,101)
  46. ,holdTranId = holdTranId
  47. ,tranId = ISNULL(holdTranId, id)
  48. ,[fileName] = d.[fileName]
  49. ,fileType = d.fileType
  50. ,docFolder = ISNULL(d.txnDocFolder,'')
  51. ,sendingCountry = t.sCountry
  52. ,receivingCountry = t.pCountry
  53. ,sendingAgent = t.sAgent
  54. ,sendingCurrency = t.collCurr
  55. ,createdBy = t.createdBy
  56. ,approvedBy = t.approvedBy
  57. ,docApprovedby = isnull(d.ApprovedBy,'')
  58. ,docApprovedDate = isnull(d.ApprovedDate,'')
  59. FROM vwRemitTran t WITH(NOLOCK)
  60. LEFT JOIN txnDocUpload d WITH(NOLOCK) ON t.holdTranId = d.tranId
  61. WHERE t.controlNo = @controlNoEncrypted
  62. UNION
  63. SELECT
  64. DISTINCT
  65. ControlNo = @controlNo
  66. ,sender = senderName
  67. ,receiver = receiverName
  68. ,sendingAmount = dbo.ShowDecimal(cAMt)
  69. ,receivingAmount = dbo.ShowDecimal(pAmt)
  70. ,transactionDate = CONVERT(VARCHAR,T.createdDate ,101)
  71. ,holdTranId = holdTranId
  72. ,tranId = ISNULL(holdTranId, id)
  73. ,[fileName] = d.[fileName]
  74. ,fileType = d.fileType
  75. ,docFolder = ISNULL(d.txnDocFolder,'')
  76. ,sendingCountry = t.sCountry
  77. ,receivingCountry = t.pCountry
  78. ,sendingAgent = t.sAgent
  79. ,sendingCurrency = t.collCurr
  80. ,createdBy = t.createdBy
  81. ,approvedBy = t.approvedBy
  82. ,docApprovedby = isnull(d.ApprovedBy,'')
  83. ,docApprovedDate = isnull(d.ApprovedDate,'')
  84. FROM FastMoneyPro_remit_Archive.dbo.remitTran t WITH(NOLOCK)
  85. LEFT JOIN txnDocUpload d WITH(NOLOCK) ON t.holdTranId = d.tranId
  86. WHERE t.controlNo = @controlNoEncrypted
  87. END
  88. IF @flag='i'
  89. BEGIN
  90. IF EXISTS(SELECT 'X' from txnDocUpload WHERE tranId = @tranId and fileType = @fileType)
  91. BEGIN
  92. UPDATE txnDocUpload SET
  93. modifiedBy = @user
  94. ,modifiedDate = GETDATE()
  95. ,[fileName] = @fileName
  96. WHERE tranId = @tranId and fileType = @fileType
  97. EXEC proc_errorHandler 0, 'Image updated successfully.', @fileName
  98. END
  99. ELSE
  100. BEGIN
  101. INSERT INTO txnDocUpload (
  102. tranId
  103. ,[fileName]
  104. ,fileType
  105. ,txnDocFolder
  106. ,createdBy
  107. ,createdDate
  108. )
  109. SELECT
  110. @tranId
  111. ,@fileName
  112. ,@fileType
  113. ,@docFolder
  114. ,@user
  115. ,GetDATE()
  116. SET @rowId = SCOPE_IDENTITY()
  117. EXEC proc_errorHandler 0, 'Image has been added successfully.', @fileName
  118. END
  119. END
  120. IF @flag='d'
  121. BEGIN
  122. SELECT @fileName = [fileName],@docFolder=txnDocFolder FROM txnDocUpload WHERE tranId = @tranId AND fileType = @fileType
  123. DELETE FROM txnDocUpload WHERE tranId = @tranId AND fileType = @fileType
  124. --EXEC proc_errorHandler 0, 'Image has been deleted successfully.',null, @fileName
  125. SELECT 0 errorCode,'Image has been deleted successfully.' msg, @fileName id, @docFolder docFolder
  126. END
  127. IF @flag='search'
  128. BEGIN
  129. DECLARE @holdTranId BIGINT
  130. IF @controlNo IS NOT NULL
  131. SELECT @controlNo = dbo.FNADecryptString(controlNo),@holdTranId=holdTranId FROM vwRemitTran WITH(NOLOCK) WHERE controlNo = dbo.FNAEncryptString(@controlNo)
  132. ELSE
  133. SELECT @controlNo = dbo.FNADecryptString(controlNo),@holdTranId=holdTranId FROM vwRemitTran WITH(NOLOCK) WHERE id = @tranId OR holdTranId = @tranId
  134. IF @controlNo IS NULL
  135. BEGIN
  136. EXEC proc_errorHandler 1, 'Invalid ICN or Tran ID.', NULL
  137. RETURN
  138. END
  139. SELECT rowId,[fileName],fileType,ISNULL(fileDescription,'') fileDescription,ISNULL(txnDocFolder,'') AS docFolder,createdBy, createddate = CONVERT(varchar,createddate,103)
  140. FROM txnDocUpload txn WITH(NOLOCK)
  141. WHERE tranId=@holdTranId
  142. ORDER BY createdDate DESC
  143. RETURN
  144. END
  145. END
  146. GO