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.

253 lines
9.8 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_ApproveHoldedTXN_Sub] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_ApproveHoldedTXN_Sub]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_ApproveHoldedTXN_Sub] 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_ApproveHoldedTXN_Sub @user='SYSTEM',@idList='<root><row id="10010026" /><row id="10010027" /></root>'
  13. */
  14. CREATE proc [dbo].[proc_ApproveHoldedTXN_Sub]
  15. @user VARCHAR(30)
  16. ,@idList XML
  17. AS
  18. BEGIN
  19. SET NOCOUNT ON
  20. SET XACT_ABORT ON
  21. DECLARE
  22. @cAmt MONEY
  23. ,@userId INT
  24. ,@tranId BIGINT
  25. ,@createdBy VARCHAR(50)
  26. DECLARE @confirm_process_id VARCHAR(200), @controlNoEnc VARCHAR(50)
  27. SET @confirm_process_id = NEWID()
  28. DECLARE @PinList TABLE(id VARCHAR(50), pin VARCHAR(50),hasProcess CHAR(1),isOFAC CHAR(1),errorMsg VARCHAR(MAX),createdBy VARCHAR(50))
  29. DECLARE @TempcompTable TABLE(errorCode INT,msg VARCHAR(MAX),id VARCHAR(50))
  30. DECLARE @SendList TABLE(amt MONEY, userId INT)
  31. INSERT @PinList(id)
  32. SELECT
  33. p.value('@id','VARCHAR(50)') id
  34. FROM @idList.nodes('/root/row') as tmp(p)
  35. UPDATE @PinList SET
  36. pin = r.controlNo
  37. FROM @PinList pl
  38. INNER JOIN remitTranTemp r ON pl.id = r.id
  39. --send email to customers
  40. INSERT INTO tempTransactionMailQueue(controlNo, createdDate, [status])--tranType is used to know either mail is sent or not, we put 'N' for not sent
  41. SELECT rt.controlNo, GETDATE(), 'N' FROM @PinList pl
  42. INNER JOIN remitTranTemp rt ON rt.id = pl.id
  43. BEGIN TRANSACTION
  44. UPDATE r SET
  45. tranStatus = CASE WHEN tranStatus = 'Hold' THEN 'Payment'
  46. WHEN tranStatus = 'Compliance Hold' THEN 'Compliance'
  47. WHEN tranStatus = 'OFAC Hold' THEN 'OFAC'
  48. WHEN tranStatus = 'OFAC/Compliance Hold' THEN 'OFAC/Compliance'
  49. ELSE 'Payment' END
  50. ,approvedBy = @user
  51. ,approvedDate = DBO.FNADateFormatTZ(GETDATE(), @user)
  52. ,approvedDateLocal = GETDATE()
  53. ,controlNo2 = r.controlNo
  54. FROM remitTranTemp r WITH(NOLOCK)
  55. INNER JOIN @PinList p ON r.id = p.id
  56. INSERT INTO remitTran(
  57. [holdTranId]
  58. ,[controlNo]
  59. ,[sCurrCostRate],[sCurrHoMargin],[sCurrSuperAgentMargin],[sCurrAgentMargin]
  60. ,[pCurrCostRate],[pCurrHoMargin],[pCurrSuperAgentMargin],[pCurrAgentMargin]
  61. ,[agentCrossSettRate],[customerRate],[sAgentSettRate],[pDateCostRate],[agentFxGain]
  62. ,[treasuryTolerance],[customerPremium],[schemePremium],[sharingValue],[sharingType]
  63. ,[serviceCharge],[handlingFee]
  64. ,[sAgentComm],[sAgentCommCurrency],[sSuperAgentComm],[sSuperAgentCommCurrency]
  65. ,[pAgentComm],[pAgentCommCurrency],[pSuperAgentComm],[pSuperAgentCommCurrency]
  66. ,[promotionCode],[promotionType],[pMessage]
  67. ,[sCountry],[sSuperAgent],[sSuperAgentName],[sAgent],[sAgentName],[sBranch],[sBranchName]
  68. ,[pCountry],[pSuperAgent],[pSuperAgentName],[pAgent],[pAgentName],[pBranch],[pBranchName]
  69. ,[paymentMethod]
  70. ,[pBank],[pBankName],[pBankBranch],[pBankBranchName],[accountNo],[externalBankCode]
  71. ,[collMode]
  72. ,[collCurr],[tAmt],[cAmt],[pAmt],[payoutCurr]
  73. ,[relWithSender],[purposeOfRemit],[sourceOfFund]
  74. ,[tranStatus],[payStatus]
  75. ,[createdDate],[createdDateLocal],[createdBy]
  76. ,[modifiedDate],[modifiedDateLocal],[modifiedBy]
  77. ,[approvedDate],[approvedDateLocal],[approvedBy]
  78. ,[paidDate],[paidDateLocal],[paidBy]
  79. ,[cancelRequestDate],[cancelRequestDateLocal],[cancelRequestBy]
  80. ,[cancelReason],[refund],[cancelCharge]
  81. ,[cancelApprovedDate],[cancelApprovedDateLocal],[cancelApprovedBy]
  82. ,[blockedDate],[blockedBy]
  83. ,[lockedDate],[lockedDateLocal],[lockedBy]
  84. ,[payTokenId]
  85. ,[tranType],[ContNo],[uploadLogId],[voucherNo],[controlNo2]
  86. ,[pBankType],[expectedPayoutAgent]
  87. ,[routedBy],[routedDate]
  88. ,[senderName],[receiverName]
  89. ,[bonusPoint]
  90. ,pState
  91. ,pDistrict
  92. )
  93. SELECT
  94. r.[id]
  95. ,[controlNo]
  96. ,[sCurrCostRate],[sCurrHoMargin],[sCurrSuperAgentMargin],[sCurrAgentMargin]
  97. ,[pCurrCostRate],[pCurrHoMargin],[pCurrSuperAgentMargin],[pCurrAgentMargin]
  98. ,[agentCrossSettRate],[customerRate],[sAgentSettRate],[pDateCostRate],[agentFxGain]
  99. ,[treasuryTolerance],[customerPremium],[schemePremium],[sharingValue],[sharingType]
  100. ,[serviceCharge],[handlingFee]
  101. ,[sAgentComm],[sAgentCommCurrency],[sSuperAgentComm],[sSuperAgentCommCurrency]
  102. ,[pAgentComm],[pAgentCommCurrency],[pSuperAgentComm],[pSuperAgentCommCurrency]
  103. ,[promotionCode],[promotionType],[pMessage]
  104. ,[sCountry],[sSuperAgent],[sSuperAgentName],[sAgent],[sAgentName],[sBranch],[sBranchName]
  105. ,[pCountry],[pSuperAgent],[pSuperAgentName],[pAgent],[pAgentName],[pBranch],[pBranchName]
  106. ,[paymentMethod]
  107. ,[pBank],[pBankName],[pBankBranch],[pBankBranchName],[accountNo],[externalBankCode]
  108. ,[collMode]
  109. ,[collCurr],[tAmt],[cAmt],[pAmt],[payoutCurr]
  110. ,[relWithSender],[purposeOfRemit],[sourceOfFund]
  111. ,[tranStatus],[payStatus]
  112. ,[createdDate],[createdDateLocal],r.[createdBy]
  113. ,[modifiedDate],[modifiedDateLocal],[modifiedBy]
  114. ,[approvedDate],[approvedDateLocal],[approvedBy]
  115. ,[paidDate],[paidDateLocal],[paidBy]
  116. ,[cancelRequestDate],[cancelRequestDateLocal],[cancelRequestBy]
  117. ,[cancelReason],[refund],[cancelCharge]
  118. ,[cancelApprovedDate],[cancelApprovedDateLocal],[cancelApprovedBy]
  119. ,[blockedDate],[blockedBy]
  120. ,[lockedDate],[lockedDateLocal],[lockedBy]
  121. ,[payTokenId]
  122. ,[tranType],[ContNo],[uploadLogId],[voucherNo],[controlNo2]
  123. ,[pBankType],[expectedPayoutAgent]
  124. ,[routedBy],[routedDate]
  125. ,[senderName],[receiverName]
  126. ,[bonusPoint]
  127. ,pState
  128. ,pDistrict
  129. FROM remitTranTemp r WITH(NOLOCK)
  130. INNER JOIN @PinList p ON r.id = p.id
  131. INSERT INTO tranSenders(
  132. [tranId]
  133. ,[holdTranId]
  134. ,[customerId]
  135. ,[membershipId]
  136. ,[firstName],[middleName],[lastName1],[lastName2],[fullName]
  137. ,[country],[address],[state],[district],[zipCode],[city]
  138. ,[email],[homePhone],[workPhone],[mobile]
  139. ,[nativeCountry],[dob],[placeOfIssue]
  140. ,[customerType],[occupation]
  141. ,[idType],[idNumber],[idPlaceOfIssue],[issuedDate],[validDate]
  142. ,[extCustomerId],[cwPwd],[ttName]
  143. ,[isFirstTran],[customerRiskPoint],[countryRiskPoint]
  144. ,[gender],[salary],[companyName],[address2]
  145. ,[dcInfo],[ipAddress],[notifySms],[txnTestQuestion],[txnTestAnswer]
  146. )
  147. SELECT
  148. main.id
  149. ,[tranId]
  150. ,[customerId]
  151. ,[membershipId]
  152. ,[firstName],[middleName],[lastName1],[lastName2],[fullName]
  153. ,[country],[address],[state],[district],[zipCode],[city]
  154. ,[email],[homePhone],[workPhone],[mobile]
  155. ,[nativeCountry],[dob],[placeOfIssue]
  156. ,[customerType],[occupation]
  157. ,[idType],[idNumber],[idPlaceOfIssue],[issuedDate],[validDate]
  158. ,[extCustomerId],[cwPwd],[ttName]
  159. ,[isFirstTran],[customerRiskPoint],[countryRiskPoint]
  160. ,[gender],[salary],[companyName],[address2]
  161. ,[dcInfo],[ipAddress],[notifySms],[txnTestQuestion],[txnTestAnswer]
  162. FROM tranSendersTemp sen WITH(NOLOCK)
  163. INNER JOIN remitTran main WITH(NOLOCK) ON sen.tranId = main.holdTranId
  164. INNER JOIN @PinList p ON sen.tranId = p.id
  165. INSERT INTO tranReceivers(
  166. [tranId]
  167. ,[holdTranId]
  168. ,[customerId]
  169. ,[membershipId]
  170. ,[firstName],[middleName],[lastName1],[lastName2],[fullName]
  171. ,[country],[address],[state],[district],[zipCode],[city]
  172. ,[email],[homePhone],[workPhone],[mobile]
  173. ,[nativeCountry],[dob],[placeOfIssue]
  174. ,[customerType],[occupation]
  175. ,[idType],[idNumber],[idPlaceOfIssue]
  176. ,[issuedDate],[validDate]
  177. ,[idType2],[idNumber2],[idPlaceOfIssue2],[issuedDate2],[validDate2]
  178. ,[relationType],[relativeName]
  179. ,[gender],[address2]
  180. ,[dcInfo],[ipAddress]
  181. )
  182. SELECT
  183. main.id
  184. ,[tranId]
  185. ,[customerId]
  186. ,[membershipId]
  187. ,[firstName],[middleName],[lastName1],[lastName2],[fullName]
  188. ,[country],[address],[state],[district],[zipCode],[city]
  189. ,[email],[homePhone],[workPhone],[mobile]
  190. ,[nativeCountry],[dob],[placeOfIssue]
  191. ,[customerType],[occupation]
  192. ,[idType],[idNumber],[idPlaceOfIssue]
  193. ,[issuedDate],[validDate]
  194. ,[idType2],[idNumber2],[idPlaceOfIssue2],[issuedDate2],[validDate2]
  195. ,[relationType],[relativeName]
  196. ,[gender],[address2]
  197. ,[dcInfo],[ipAddress]
  198. FROM tranReceiversTemp rec WITH(NOLOCK)
  199. INNER JOIN remitTran main WITH(NOLOCK) ON rec.tranId = main.holdTranId
  200. INNER JOIN @PinList p ON rec.tranId = p.id
  201. DELETE FROM remitTranTemp
  202. FROM remitTranTemp r
  203. INNER JOIN @PinList p ON r.id = p.id
  204. DELETE FROM tranSendersTemp
  205. FROM tranSendersTemp sen
  206. INNER JOIN @PinList p ON sen.tranId = p.id
  207. DELETE FROM tranReceiversTemp
  208. FROM tranReceiversTemp rec
  209. INNER JOIN @PinList p ON rec.tranId = p.id
  210. INSERT INTO PinQueueList(ICN)
  211. SELECT pin FROM @PinList WHERE ISNULL(pin, '') <> ''
  212. UPDATE utl SET
  213. utl.sendTodays = ISNULL(sendTodays, 0) + ISNULL(s.amt, 0)
  214. FROM userWiseTxnLimit utl
  215. INNER JOIN @SendList s ON utl.userId = s.userId
  216. IF @@TRANCOUNT > 0
  217. COMMIT TRANSACTION
  218. DECLARE @msg VARCHAR(MAX)='One or more transaction(s) Approved Successfully',@code INT=0
  219. IF EXISTS(SELECT 'X' FROM @PinList WHERE hasProcess = 'Y' AND isOFAC IN ('C','Y'))
  220. BEGIN
  221. SELECT @code=10 FROM @PinList WHERE isOFAC IN ('C','Y')
  222. SELECT @msg = CASE WHEN COUNT(*)>0 THEN 'Transaction Approved Successfully count : '+CAST(COUNT(*) AS VARCHAR) ELSE ' ' END FROM @PinList WHERE ISNULL(isOFAC,'N') = 'N'
  223. SELECT @msg = @msg+ CASE WHEN COUNT(*)>0 THEN ' <br> Transaction under compliance count : '+CAST(COUNT(*) AS VARCHAR) ELSE ' ' END FROM @PinList WHERE ISNULL(isOFAC,'N') = 'Y'
  224. SELECT @msg = @msg+ CASE WHEN COUNT(*)>0 THEN ' <br> Unsuccess/Same users TXN count : '+CAST(COUNT(*) AS VARCHAR) ELSE ' ' END FROM @PinList WHERE ISNULL(isOFAC,'N') = 'C'
  225. END
  226. EXEC proc_errorHandler @code, @msg, @user
  227. --EXEC proc_pushBulkToAc @flag = 'i',@idList = @idList
  228. END
  229. GO