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.

138 lines
8.1 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_txnDocuments] 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 proc [dbo].[proc_txnDocuments]
  9. @flag VARCHAR(50)
  10. ,@user VARCHAR(50) = NULL
  11. ,@rowId BIGINT = NULL
  12. ,@tranId VARCHAR(50) = NULL
  13. ,@agentId VARCHAR(50) = NULL
  14. ,@fromDate VARCHAR(50) = NULL
  15. ,@toDate VARCHAR(30) = NULL
  16. ,@agent VARCHAR(200) = NULL
  17. ,@status VARCHAR(50) = NULL
  18. ,@receivedId VARCHAR(50) = NULL
  19. ,@controlNo VARCHAR(20) = NULL
  20. ,@tranAmt VARCHAR(50) = Null
  21. ,@senderName VARCHAR(50) = NULL
  22. ,@receiverName VARCHAR(50) = NULL
  23. ,@createdBy VARCHAR(50) = NULL
  24. ,@createdDate DATE = NULL
  25. ,@fileDescription VARCHAR(100) = NULL
  26. ,@fileType VARCHAR(100) = NULL
  27. ,@txnYear VARCHAR(100) = NULL
  28. ,@fileName VARCHAR(100) = NULL
  29. ,@sortBy VARCHAR(50) = NULL
  30. ,@sortOrder VARCHAR(50) = NULL
  31. ,@pageSize VARCHAR(50) = NULL
  32. ,@pageNumber VARCHAR(50) = NULL
  33. ,@txnType VARCHAR(10) = NULL
  34. ,@icn VARCHAR(50) = NULL
  35. ,@voucherType VARCHAR(50) = NULL
  36. AS
  37. /*
  38. EXEC proc_txnDocuments @flag='deleteDoc',@user='admin',@rowId='28'
  39. */
  40. SET NOCOUNT ON;
  41. IF @flag = 'i'
  42. BEGIN
  43. SELECT
  44. @controlNo=dbo.FNADecryptString(controlNo)
  45. FROM vwRemitTranArchive WITH(NOLOCK)
  46. WHERE id=@rowId
  47. -- EXEC proc_txnDocuments @flag='i',
  48. --@user = null, @rowId = '5674003', @tranId = '5674003', @fileDescription = null,
  49. --@fileType = 'jpg', @txnYear = '2016', @agentId = '4616', @txnType = 'sd'
  50. DECLARE @sn INT
  51. SELECT
  52. @sn = COUNT(*)
  53. FROM txnDocuments (NOLOCK) WHERE controlNo = @controlNo
  54. SELECT @sn = ISNULL(@sn, 0) + 1
  55. SET @fileName = @ControlNo + +'_'+ CAST(@sn AS VARCHAR) + '.' + @fileType
  56. --SET @fileDescription = @fileName
  57. --IF EXISTS (SELECT 'x' FROM txnDocuments (NOLOCK) WHERE controlNo = @controlNo AND tdId=@rowId AND [fileName]=@fileName)
  58. --BEGIN
  59. -- DELETE FROM txnDocuments WHERE controlNo = @controlNo AND tdId=@rowId AND [fileName]=@fileName
  60. --END
  61. INSERT INTO txnDocuments (tdId, controlNo, [fileName], fileDescription, fileType, [year], agentId, createdBy, createdDate,txnType)
  62. SELECT @rowId, @controlNo, @fileName, @fileDescription, @fileType, @txnYear, @agentId, @user, GETDATE(),@txnType
  63. SET @rowId = SCOPE_IDENTITY()
  64. EXEC proc_errorHandler 0, 'File Uploaded Successfully', @fileName
  65. RETURN
  66. END
  67. ELSE IF @flag = 'test'
  68. BEGIN
  69. SELECT fileName, fileDescription, [year], agentId FROM txnDocuments WITH(NOLOCK) WHERE controlNo = @controlNo
  70. RETURN
  71. --EXEC proc_txnDocuments @flag='test', @controlNo='7180061158D'
  72. END
  73. ELSE IF @flag='displayDoc'
  74. BEGIN
  75. SELECT
  76. rowId
  77. ,tdId
  78. ,fileName
  79. ,fileDescription
  80. ,createdBy
  81. ,createdDate
  82. ,[year]
  83. ,agentId
  84. FROM txnDocuments WITH(NOLOCK)
  85. WHERE tdId=@rowId
  86. AND (isDeleted = 'N' OR isDeleted IS NULL)
  87. AND txnType=@txnType
  88. --ORDER BY CASE WHEN fileDescription = 'Voucher' THEN 0 ELSE 1 END ASC
  89. RETURN
  90. END
  91. ELSE IF @flag = 'a'
  92. BEGIN
  93. SELECT * FROM txnDocuments WITH(NOLOCK) WHERE rowId = @rowId
  94. RETURN
  95. END
  96. ELSE IF @flag='image-display'
  97. BEGIN
  98. SELECT
  99. [fileName] = fileName
  100. ,fileDescription
  101. ,agentId
  102. FROM txnDocuments a WITH(NOLOCK)
  103. WHERE tdid=@rowId AND isDeleted IS NULL
  104. RETURN
  105. END
  106. ELSE IF @flag='deleteDoc'
  107. BEGIN
  108. DECLARE @path VARCHAR(255)
  109. SELECT
  110. @path = CAST([Year] AS VARCHAR(20)) + '\' + CAST(agentId AS VARCHAR(20)) + '\' + [fileName]
  111. FROM txnDocuments (NOLOCK) WHERE rowId = @rowId
  112. DELETE txnDocuments WHERE rowId = @rowId
  113. EXEC proc_errorHandler 0, 'File Deleted Successfully', @path
  114. END
  115. ELSE IF @flag='cd'
  116. BEGIN
  117. SELECT '0' as errorCode,'Continue' as msg ,SUM(v+i+b) as id from ( select
  118. case when fileDescription='Voucher' then 2 else 0 end as v
  119. ,case when fileDescription='Id' then 1 else 0 end as i
  120. ,case when fileDescription='Both' then 4 else 0 end as b
  121. from txnDocuments where agentId=@agentId AND txnType=@voucherType AND tdId=@tranId
  122. UNION ALL
  123. SELECT 0,0,0
  124. )x
  125. RETURN
  126. END
  127. GO