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.

243 lines
15 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_payAcDeposit] 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_payAcDeposit]
  9. @flag VARCHAR(50)
  10. ,@controlNo VARCHAR(20) = NULL
  11. ,@accountNo VARCHAR(30) = NULL
  12. ,@senderName VARCHAR(50) = NULL
  13. ,@receiverName VARCHAR(50) = NULL
  14. ,@user VARCHAR(30) = NULL
  15. ,@tranIds VARCHAR(MAX) = NULL
  16. ,@pBranch INT = NULL
  17. ,@settlingAgent INT = NULL
  18. ,@bankId INT = NULL
  19. ,@sortBy VARCHAR(50) = NULL
  20. ,@sortOrder VARCHAR(5) = NULL
  21. ,@pageSize INT = NULL
  22. ,@pageNumber INT = NULL
  23. ,@tranNos VARCHAR(MAX) = NULL
  24. AS
  25. /*
  26. EXEC proc_payAcDeposit @flag = 's' ,@pageNumber='1', @pageSize='10', @sortBy='controlNo', @sortOrder='ASC', @user = 'admin'
  27. */
  28. DECLARE
  29. @select_field_list VARCHAR(MAX)
  30. ,@extra_field_list VARCHAR(MAX)
  31. ,@table VARCHAR(MAX)
  32. ,@sql_filter VARCHAR(MAX)
  33. SET NOCOUNT ON
  34. SET XACT_ABORT ON
  35. DECLARE
  36. @controlNoEncrypted VARCHAR(100)
  37. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  38. SELECT @pageSize = 1000, @pageNumber = 1
  39. IF @flag = 's' --Select Transaction with payment type AC Deposit
  40. BEGIN
  41. SET @table = '(
  42. SELECT
  43. trn.id
  44. ,controlNo = ''<a href="#" onclick="OpenInNewWindow('''''+dbo.FNAGetURL()+'Remit/Transaction/Reports/SearchTransaction.aspx?controlNo='' + dbo.FNADecryptString(trn.controlNo) + '''''')">'' + dbo.FNADecryptString(trn.controlNo) + ''</a>''
  45. --,controlNo = dbo.FNADecryptString(trn.controlNo)
  46. ,trn.accountNo
  47. ,bankName = ISNULL(trn.pBankName,trn.pAgentName)
  48. ,pBranchName = ISNULL(trn.pBankBranchName,trn.pBranchName)
  49. ,trn.pAmt
  50. ,trn.payoutCurr
  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. ,tranDate = trn.approvedDate
  58. FROM remitTran trn WITH(NOLOCK)
  59. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  60. WHERE trn.tranStatus = ''Payment''
  61. AND trn.payStatus = ''Unpaid''
  62. AND trn.paymentMethod = ''Bank Deposit''
  63. '
  64. --AND pBranch = ' + CAST(@pBranch AS VARCHAR) + '
  65. SET @sql_filter = ''
  66. IF @bankId IS NOT NULL
  67. SET @table = @table + ' AND pAgent = ' + CAST(@bankId AS VARCHAR) + ''
  68. IF @pBranch IS NOT NULL
  69. SET @table = @table + ' AND pBranch = ' + CAST(@pBranch AS VARCHAR) + ''
  70. IF @controlNo IS NOT NULL
  71. SET @table = @table + ' AND trn.controlNo = ''' + @controlNoEncrypted + ''''
  72. IF @accountNo IS NOT NULL
  73. SET @table = @table + ' AND trn.accountNo = ''' + @accountNo + ''''
  74. IF @receiverName IS NOT NULL
  75. SET @sql_filter = @sql_filter + ' AND receiverName LIKE ''%' + @receiverName + '%'''
  76. SET @select_field_list ='
  77. id
  78. ,controlNo
  79. ,accountNo
  80. ,bankName
  81. ,pBranchName
  82. ,pAmt
  83. ,payoutCurr
  84. ,rCustomerId
  85. ,receiverName
  86. ,rCountryName
  87. ,rStateName
  88. ,rCity
  89. ,rAddress
  90. ,tranDate
  91. '
  92. SET @table = @table + ') x'
  93. EXEC dbo.proc_paging
  94. @table
  95. ,@sql_filter
  96. ,@select_field_list
  97. ,@extra_field_list
  98. ,@sortBy
  99. ,@sortOrder
  100. ,@pageSize
  101. ,@pageNumber
  102. END
  103. ELSE IF @flag = 'payIntl'
  104. BEGIN
  105. DECLARE @txn TABLE(id INT IDENTITY(1,1),tranNo VARCHAR(50))
  106. DECLARE @script VARCHAR(MAX)
  107. IF NOT EXISTS(SELECT 'X' FROM @txn)
  108. BEGIN
  109. EXEC proc_errorHandler 0, 'No Transaction to post', NULL
  110. RETURN
  111. END
  112. EXEC proc_errorHandler 0, 'Transaction(s) paid successfully', NULL
  113. END
  114. ELSE IF @flag = 'u'
  115. BEGIN
  116. DECLARE @sql VARCHAR(MAX)
  117. DECLARE
  118. @tranId INT
  119. ,@rowId INT
  120. ,@totalRow INT
  121. ,@sBranch INT
  122. ,@pSuperAgent INT
  123. ,@sCountry VARCHAR(100)
  124. ,@sLocation INT
  125. ,@pHubComm MONEY, @pHubCommCurrency VARCHAR(3), @pSuperAgentComm MONEY, @pSuperAgentCommCurrency VARCHAR(3), @pAgentComm MONEY, @pAgentCommCurrency VARCHAR(3)
  126. ,@pCountry VARCHAR(100), @pCountryId INT, @pLocation INT
  127. ,@deliveryMethod VARCHAR(50), @deliveryMethodId INT
  128. ,@collCurr VARCHAR(3), @tAmt MONEY, @cAmt MONEY, @pAmt MONEY, @payoutCurr VARCHAR(3), @serviceCharge MONEY
  129. IF(@tranIds IS NULL)
  130. BEGIN
  131. EXEC proc_errorHandler 1, 'Transaction(s) not found', NULL
  132. RETURN
  133. END
  134. CREATE TABLE #tempTran(rowId INT IDENTITY(1,1), tranId INT)
  135. SET @sql = '
  136. INSERT INTO #tempTran(tranId)
  137. SELECT id FROM remitTran WHERE id IN (' + @tranIds + ')
  138. '
  139. EXEC(@sql)
  140. SET @rowId = 1
  141. SELECT @totalRow = COUNT(rowId) FROM #tempTran
  142. WHILE (@rowId <= @totalRow)
  143. BEGIN
  144. SELECT @tranId = tranId FROM #tempTran WHERE rowId = @rowId
  145. SELECT
  146. @sBranch = trn.sBranch
  147. ,@sCountry = trn.sCountry
  148. ,@sLocation = sb.agentLocation
  149. ,@pSuperAgent = trn.pSuperAgent
  150. ,@pCountryId = cm.countryId
  151. ,@pLocation = trn.pLocation
  152. ,@pBranch = trn.pBranch
  153. ,@deliveryMethodId = dm.serviceTypeId
  154. ,@tAmt = trn.tAmt
  155. ,@cAmt = trn.cAmt
  156. ,@pAmt = trn.pAmt
  157. ,@serviceCharge = trn.serviceCharge
  158. ,@payoutCurr = trn.payoutCurr
  159. FROM remitTran trn WITH(NOLOCK)
  160. LEFT JOIN agentMaster sb WITH(NOLOCK) ON trn.sBranch = sb.agentId
  161. LEFT JOIN countryMaster cm WITH(NOLOCK) ON trn.pCountry = cm.countryName
  162. LEFT JOIN serviceTypeMaster dm WITH(NOLOCK) ON trn.paymentMethod = dm.typeTitle
  163. WHERE id = @tranId
  164. --Commission Calculation Starts---------------------------------
  165. IF @sCountry = 'Nepal'
  166. BEGIN
  167. SELECT
  168. @pAgentComm = ISNULL(pAgentComm, 0)
  169. ,@pSuperAgentComm = ISNULL(psAgentComm, 0)
  170. FROM dbo.FNAGetDomesticPayComm(@sBranch, @pBranch, @deliveryMethodId, @tAmt)
  171. SELECT @pAgentCommCurrency = 'NPR', @pSuperAgentCommCurrency = 'NPR'
  172. END
  173. ELSE
  174. BEGIN
  175. SELECT @pSuperAgentComm = amount, @pSuperAgentCommCurrency = commissionCurrency FROM dbo.FNAGetPayCommSA(@sBranch, NULL, @sLocation, @pSuperAgent, @pCountryId, @pLocation, @pBranch, @payoutCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, @pHubComm, 0)
  176. SELECT @pAgentComm = amount, @pAgentCommCurrency = commissionCurrency FROM dbo.FNAGetPayComm(@sBranch, NULL, @sLocation, @pSuperAgent, @pCountryId, @pLocation, @pBranch, @payoutCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, @pHubComm, @pSuperAgentComm)
  177. END
  178. --Commission Calculation Ends-----------------------------------
  179. UPDATE remitTran SET
  180. pHubComm = @pHubComm
  181. ,pHubCommCurrency = @pHubCommCurrency
  182. ,pSuperAgentComm = @pSuperAgentComm
  183. ,pSuperAgentCommCurrency = @pSuperAgentCommCurrency
  184. ,pAgentComm = @pAgentComm
  185. ,pAgentCommCurrency = @pAgentCommCurrency
  186. ,tranStatus = 'Paid'
  187. ,payStatus = 'Paid'
  188. ,paidBy = @user
  189. ,paidDate = GETDATE()
  190. ,paidDateLocal = dbo.FNADateFormatTZ(GETDATE(), @user)
  191. WHERE id = @tranId
  192. SELECT @settlingAgent = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  193. --EXEC proc_updateTopUpLimit @settlingAgent, @pAmt
  194. SET @rowId = @rowId + 1
  195. END
  196. /*
  197. -- ### inserting txn view history
  198. INSERT INTO tranViewHistory (
  199. tranViewType
  200. ,createdBy
  201. ,createdDate
  202. ,tranId
  203. ,remarks
  204. )
  205. SELECT
  206. 'PAY'
  207. ,@user
  208. ,GETDATE()
  209. ,value
  210. ,'ADM: PAY A/C DEPOSIT TXN' from dbo.Split(',',@tranIds)
  211. */
  212. EXEC proc_errorHandler 0, 'Transaction(s) paid successfully', NULL
  213. END
  214. GO