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.

235 lines
9.1 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_payReceipt] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_payReceipt]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_payReceipt] 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. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  13. /*
  14. EXEC proc_payReceipt @flag = 'receiptLocal', @user = 'admin',
  15. @controlNo = '91722496166', @msgType = 'P'
  16. */
  17. CREATE PROC [dbo].[proc_payReceipt] (
  18. @flag VARCHAR(50)
  19. ,@user VARCHAR(30) = NULL
  20. ,@controlNo VARCHAR(30) = NULL
  21. ,@msgType CHAR(1) = NULL
  22. ,@sortBy VARCHAR(50) = NULL
  23. ,@sortOrder VARCHAR(5) = NULL
  24. ,@pageSize INT = NULL
  25. ,@pageNumber INT = NULL
  26. )
  27. AS
  28. SET NOCOUNT ON;
  29. DECLARE @controlNoEncrypted VARCHAR(20)
  30. SELECT @controlNoEncrypted = dbo.FNAEncryptString(UPPER(@controlNo))
  31. IF @flag = 'receipt' --All transaction information (sender, receiver, payout)
  32. BEGIN
  33. SELECT * FROM payTranDetail with (nolock) WHERE controlNo = @controlNoEncrypted
  34. --Message
  35. DECLARE @headMsg NVARCHAR(MAX)
  36. ,@commonMsg NVARCHAR(MAX)
  37. ,@countrySpecificMsg NVARCHAR(MAX)
  38. ,@pAgent INT
  39. ,@pCountry INT
  40. ,@pUser VARCHAR(50)
  41. ,@pUserFullName VARCHAR(75)
  42. SELECT
  43. @pAgent = sBranch
  44. ,@pUser = paidBy
  45. FROM remitTran with (nolock) WHERE controlNo = @controlNoEncrypted
  46. SELECT
  47. @pUserFullName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName, '')
  48. FROM applicationUsers with (nolock) WHERE userName = @pUser
  49. SELECT @pCountry = agentCountry FROM agentMaster with (nolock) WHERE agentId = @pAgent
  50. --Head Message
  51. SELECT @headMsg = headMsg FROM message with (nolock) WHERE countryId = @pCountry AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  52. IF(@headMsg IS NULL)
  53. SELECT @headMsg = headMsg FROM message with (nolock) WHERE countryId IS NULL AND headMsg IS NOT NULL AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  54. --Common Message
  55. SELECT @commonMsg = commonMsg FROM message with (nolock) WHERE countryId = @pCountry AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  56. IF(@commonMsg IS NULL)
  57. SELECT @commonMsg = commonMsg FROM message with (nolock) WHERE countryId IS NULL AND commonMsg IS NOT NULL AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  58. --Country Specific Message
  59. SELECT @countrySpecificMsg = countrySpecificMsg FROM message with (nolock) WHERE countryId = @pCountry AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  60. IF(@countrySpecificMsg IS NULL)
  61. SELECT @countrySpecificMsg = countrySpecificMsg FROM message with (nolock) WHERE countryId IS NULL AND countrySpecificMsg IS NOT NULL AND msgType = @msgType AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  62. SELECT @headMsg AS headMsg,@commonMsg AS commonMsg, @countrySpecificMsg AS countrySpecificMsg, @pUserFullName AS pUserFullName
  63. END
  64. ELSE IF @flag = 'receiptLocal'
  65. BEGIN
  66. SELECT
  67. tranId = trn.id
  68. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  69. --Sender Information
  70. ,sMemId = sen.membershipId
  71. ,sCustomerId = sen.customerId
  72. ,senderName = UPPER(ISNULL(sen.firstName, '') + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, ''))
  73. ,sCountryName = sen.country
  74. ,sStateName = sen.state
  75. ,sDistrict = sen.district
  76. ,sCity = sen.city
  77. ,sAddress = left(sen.address,50)
  78. ,sContactNo = COALESCE(sen.mobile, sen.homephone, sen.workphone)
  79. ,sIdType = sen.idType
  80. ,sIdNo = sen.idNumber
  81. ,sValidDate = sen.validDate
  82. ,sEmail = sen.email
  83. --Receiver Information
  84. ,rMemId = rec.membershipId
  85. ,rCustomerId = rec.customerId
  86. ,receiverName = UPPER(ISNULL(rec.firstName, '') + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, ''))
  87. ,rCountryName = rec.country
  88. ,rStateName = rec.state
  89. ,rDistrict = rec.district
  90. ,rCity = rec.city
  91. ,rAddress = rec.address
  92. ,rContactNo = COALESCE(rec.mobile, rec.homephone, rec.workphone)
  93. ,rIdType = rec.idType2
  94. ,rIdNo = rec.idNumber2
  95. --Sending Agent Information
  96. ,sAgentName = CASE WHEN trn.sAgentName = trn.sBranchName THEN trn.sSuperAgentName ELSE trn.sAgentName END
  97. ,sBranchName = trn.sBranchName
  98. ,sAgentCountry = sa.agentCountry
  99. ,sAgentState = sa.agentState
  100. ,sAgentDistrict = sa.agentDistrict
  101. ,sAgentLocation = sLoc.districtName
  102. ,sAgentCity = sa.agentCity
  103. ,sAgentAddress = sa.agentAddress
  104. --Payout Agent Information
  105. ,pAgentName = CASE WHEN trn.pAgentName = trn.pBranchName THEN trn.pSuperAgentName ELSE trn.pAgentName END
  106. ,pBranchName = trn.pBranchName
  107. ,pAgentCountry = trn.pCountry
  108. --,pAgentState = trn.pState
  109. ,pAgentDistrict = trn.pDistrict
  110. ,pAgentLocation = pLoc.districtName
  111. ,pAgentPhone = pa.companyPhone1
  112. ,pAgentAddress = pa.agentAddress
  113. ,trn.tAmt
  114. ,trn.serviceCharge
  115. ,handlingFee = ISNULL(trn.handlingFee, 0)
  116. ,trn.cAmt
  117. ,trn.pAmt
  118. ,relationship = ISNULL(trn.relWithSender, '-')
  119. ,purpose = ISNULL(trn.purposeOfRemit, '-')
  120. ,sourceOfFund = ISNULL(trn.sourceOfFund, '-')
  121. ,collMode = trn.collMode
  122. ,trn.collCurr
  123. ,paymentMethod = trn.paymentMethod
  124. ,trn.payoutCurr
  125. ,trn.tranStatus
  126. ,trn.payStatus
  127. ,payoutMsg = ISNULL(trn.pMessage, '-')
  128. ,trn.createdBy
  129. ,trn.createdDate
  130. ,trn.approvedBy
  131. ,trn.approvedDate
  132. ,trn.paidBy
  133. ,trn.paidDate
  134. ,trn.payTokenId
  135. ,rec.chequeNo
  136. FROM remitTran trn WITH(NOLOCK)
  137. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  138. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  139. LEFT JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  140. LEFT JOIN agentMaster pa WITH(NOLOCK) ON trn.pBranch = pa.agentId
  141. LEFT JOIN api_districtList pLoc WITH(NOLOCK) ON trn.pLocation = pLoc.districtCode
  142. LEFT JOIN api_districtList sLoc WITH(NOLOCK) ON sa.agentLocation = sLoc.districtCode
  143. WHERE trn.controlNo = @controlNoEncrypted
  144. ----------------------------- MESSAGE ----------------------------------------------------------
  145. SELECT @pUser = paidBy FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  146. SELECT
  147. @pUserFullName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName, '')
  148. FROM applicationUsers WITH(NOLOCK) WHERE userName = @pUser
  149. SELECT @pCountry = countryId FROM countryMaster WITH(NOLOCK)
  150. WHERE countryName = (SELECT agentCountry FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent)
  151. --Head Message
  152. SELECT @headMsg = headMsg FROM [message] WITH(NOLOCK) WHERE countryId = @pCountry AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  153. IF(@headMsg IS NULL)
  154. SELECT @headMsg = headMsg FROM [message] WITH(NOLOCK) WHERE countryId IS NULL AND headMsg IS NOT NULL AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  155. --Common Message
  156. SELECT @commonMsg = commonMsg FROM [message] WITH(NOLOCK) WHERE countryId = @pCountry AND ISNULL(isDeleted, 'N') <> 'Y'
  157. IF(@commonMsg IS NULL)
  158. SELECT @commonMsg = commonMsg FROM [message] WITH(NOLOCK) WHERE countryId IS NULL AND commonMsg IS NOT NULL AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  159. --Country Specific Message
  160. SELECT @countrySpecificMsg = countrySpecificMsg FROM [message] WITH(NOLOCK) WHERE countryId = @pCountry AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  161. IF(@countrySpecificMsg IS NULL)
  162. SELECT @countrySpecificMsg = countrySpecificMsg FROM [message] WITH(NOLOCK) WHERE countryId IS NULL AND countrySpecificMsg IS NOT NULL AND msgType = @msgType AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  163. SELECT @headMsg AS headMsg,@commonMsg AS commonMsg, @countrySpecificMsg AS countrySpecificMsg, @pUserFullName AS pUserFullName
  164. END
  165. ELSE IF @flag = 'c' --Check Transaction Control No
  166. BEGIN
  167. IF NOT EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK)
  168. WHERE controlNo = @controlNoEncrypted
  169. AND payStatus = 'Paid'
  170. AND ISNULL(tranType, 'D') = 'D')
  171. BEGIN
  172. EXEC proc_errorHandler 1, 'Paid Transaction Not Found', @controlNoEncrypted
  173. RETURN
  174. END
  175. DECLARE @agentId INT
  176. SELECT @agentId = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  177. IF @agentId = dbo.FNAGetHOAgentId()
  178. BEGIN
  179. EXEC proc_errorHandler 0, 'Transaction Found', @controlNoEncrypted
  180. RETURN
  181. END
  182. SELECT @pAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @agentId
  183. IF NOT EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND (pAgent = @pAgent OR pBranch = @agentId))
  184. BEGIN
  185. EXEC proc_errorHandler 1, 'You are not authorized to view this transaction', @controlNoEncrypted
  186. RETURN
  187. END
  188. EXEC proc_errorHandler 0, 'Transaction Found', @controlNo
  189. END
  190. GO