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.

267 lines
12 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_customerTxnHistory] 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_customerTxnHistory]
  9. @controlNo VARCHAR(30) = NULL
  10. ,@date DATETIME = NULL
  11. ,@fromDate VARCHAR(50) = NULL
  12. ,@toDate VARCHAR(50) = NULL
  13. AS
  14. BEGIN
  15. IF @controlNo IS NOT NULL
  16. BEGIN
  17. IF EXISTS(SELECT 'X' FROM customerTxnHistory WITH(NOLOCK) WHERE refno = @controlNo)
  18. RETURN
  19. INSERT INTO customerTxnHistory
  20. (
  21. Tranno
  22. ,refno
  23. ,senderFax
  24. ,senderPassport
  25. ,SenderName
  26. ,sender_mobile
  27. ,SenderAddress
  28. ,SenderCountry
  29. ,customerId
  30. ,receiverIDDescription
  31. ,receiverID
  32. ,receiverName
  33. ,ReceiverPhone
  34. ,receiver_mobile
  35. ,ReceiverAddress
  36. ,ReceiverCity
  37. ,ReceiverCountry
  38. ,rBankACNo
  39. ,rBankName
  40. ,rBankBranch
  41. ,rBankID
  42. ,ben_bank_id
  43. ,ben_bank_name
  44. ,rBankAcType
  45. ,receiveAgentID
  46. ,expected_payoutagentid
  47. ,paymentType
  48. ,paidAmt
  49. ,confirmDate
  50. ,paidCType
  51. ,receiveCType
  52. ,pAgent
  53. ,pAgentName
  54. ,pBranch
  55. ,pBranchName
  56. ,pBank
  57. ,pBankName
  58. ,pBankBranch
  59. ,pBankBranchName
  60. )
  61. SELECT
  62. Tranno = rt.id
  63. ,refno = controlNo
  64. ,senderFax = sen.idType
  65. ,senderPassport = sen.idNumber
  66. ,SenderName = rt.senderName
  67. ,sender_mobile = sen.mobile
  68. ,SenderAddress = sen.address
  69. ,SenderCountry = rt.sCountry
  70. ,customerId = sen.customerId
  71. ,receiverIDDescription = rec.idType
  72. ,receiverID = rec.idNumber
  73. ,receiverName = rt.receiverName
  74. ,ReceiverPhone = rec.homePhone
  75. ,receiver_mobile = rec.mobile
  76. ,ReceiverAddress = rec.address
  77. ,ReceiverCity = rec.city
  78. ,ReceiverCountry = rt.pCountry
  79. ,rBankACNo = rt.accountNo
  80. ,rBankName = rt.pAgentName
  81. ,rBankBranch = rt.pBranchName
  82. ,rBankID = rt.pBranch
  83. ,ben_bank_id = rt.externalBankCode
  84. ,ben_bank_name = rt.pBankName
  85. ,rBankAcType = rt.pBankBranchName
  86. ,receiveAgentID = rt.pAgent
  87. ,expected_payoutagentid = rt.pAgent
  88. ,paymentType = rt.paymentMethod
  89. ,paidAmt = cAmt
  90. ,confirmDate = approvedDate
  91. ,paidCType = collCurr
  92. ,receiveCType = payoutCurr
  93. ,pAgent
  94. ,pAgentName
  95. ,pBranch
  96. ,pBranchName
  97. ,pBank
  98. ,pBankName
  99. ,pBankBranch
  100. ,pBankBranchName
  101. FROM vwRemitTran rt WITH(NOLOCK)
  102. INNER JOIN vwTranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  103. INNER JOIN vwTranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  104. WHERE controlNo = @controlNo
  105. END
  106. ELSE
  107. BEGIN
  108. IF @fromDate IS NULL AND @toDate IS NULL AND @date IS NULL
  109. BEGIN
  110. SET @fromDate = CONVERT(varchar(20), GETDATE()-1, 101)
  111. SET @toDate = CONVERT(varchar(20), GETDATE()-1, 101) + ' 23:59:59:998'
  112. END
  113. ELSE IF @date IS NOT NULL
  114. BEGIN
  115. SET @fromDate = CONVERT(VARCHAR, @date, 101)
  116. SET @toDate = CONVERT(VARCHAR, @date, 101) + ' 23:59:59:998'
  117. END
  118. --SELECT @fromDate, @toDate
  119. IF OBJECT_ID('tempdb..#temp1') IS NOT NULL
  120. DROP TABLE #temp1
  121. SELECT
  122. Tranno = rt.id
  123. ,refno = controlNo
  124. ,senderFax = sen.idType
  125. ,senderPassport = sen.idNumber
  126. ,SenderName = rt.senderName
  127. ,sender_mobile = sen.mobile
  128. ,SenderAddress = sen.address
  129. ,SenderCountry = rt.sCountry
  130. ,customerId = sen.customerId
  131. ,receiverIDDescription = rec.idType
  132. ,receiverID = rec.idNumber
  133. ,receiverName = rt.receiverName
  134. ,ReceiverPhone = rec.homePhone
  135. ,receiver_mobile = rec.mobile
  136. ,ReceiverAddress = rec.address
  137. ,ReceiverCity = rec.city
  138. ,ReceiverCountry = rt.pCountry
  139. ,rBankACNo = rt.accountNo
  140. ,rBankName = rt.pAgentName
  141. ,rBankBranch = rt.pBranchName
  142. ,rBankID = rt.pBranch
  143. ,ben_bank_id = rt.externalBankCode
  144. ,ben_bank_name = rt.pBankName
  145. ,rBankAcType = rt.pBankBranchName
  146. ,receiveAgentID = rt.pAgent
  147. ,expected_payoutagentid = rt.pAgent
  148. ,paymentType = rt.paymentMethod
  149. ,paidAmt = cAmt
  150. ,confirmDate = approvedDate
  151. ,paidCType = collCurr
  152. ,receiveCType = payoutCurr
  153. ,pAgent
  154. ,pAgentName
  155. ,pBranch
  156. ,pBranchName
  157. ,pBank
  158. ,pBankName
  159. ,pBankBranch
  160. ,pBankBranchName
  161. INTO #TEMP1
  162. FROM remitTran rt WITH(NOLOCK)
  163. INNER JOIN tranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  164. INNER JOIN tranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  165. WHERE 1=1 AND tranType = 'I'
  166. --AND SenderCountry ='Malaysia'
  167. AND createdDate >= @fromDate
  168. DELETE T
  169. FROM #TEMP1 T, customerTxnHistory C
  170. WHERE T.refno = C.refno
  171. INSERT INTO customerTxnHistory
  172. (
  173. Tranno
  174. ,refno
  175. ,senderFax
  176. ,senderPassport
  177. ,SenderName
  178. ,sender_mobile
  179. ,SenderAddress
  180. ,SenderCountry
  181. ,customerId
  182. ,receiverIDDescription
  183. ,receiverID
  184. ,receiverName
  185. ,ReceiverPhone
  186. ,receiver_mobile
  187. ,ReceiverAddress
  188. ,ReceiverCity
  189. ,ReceiverCountry
  190. ,rBankACNo
  191. ,rBankName
  192. ,rBankBranch
  193. ,rBankID
  194. ,ben_bank_id
  195. ,ben_bank_name
  196. ,rBankAcType
  197. ,receiveAgentID
  198. ,expected_payoutagentid
  199. ,paymentType
  200. ,paidAmt
  201. ,confirmDate
  202. ,paidCType
  203. ,receiveCType
  204. ,pAgent
  205. ,pAgentName
  206. ,pBranch
  207. ,pBranchName
  208. ,pBank
  209. ,pBankName
  210. ,pBankBranch
  211. ,pBankBranchName
  212. )
  213. SELECT
  214. Tranno
  215. ,refno
  216. ,senderFax
  217. ,senderPassport
  218. ,SenderName
  219. ,sender_mobile
  220. ,SenderAddress
  221. ,SenderCountry
  222. ,customerId
  223. ,receiverIDDescription
  224. ,receiverID
  225. ,receiverName
  226. ,ReceiverPhone
  227. ,receiver_mobile
  228. ,ReceiverAddress
  229. ,ReceiverCity
  230. ,ReceiverCountry
  231. ,rBankACNo
  232. ,rBankName
  233. ,rBankBranch
  234. ,rBankID
  235. ,ben_bank_id
  236. ,ben_bank_name
  237. ,rBankAcType
  238. ,receiveAgentID
  239. ,expected_payoutagentid
  240. ,paymentType
  241. ,paidAmt
  242. ,confirmDate
  243. ,paidCType
  244. ,receiveCType
  245. ,pAgent
  246. ,pAgentName
  247. ,pBranch
  248. ,pBranchName
  249. ,pBank
  250. ,pBankName
  251. ,pBankBranch
  252. ,pBankBranchName
  253. FROM #TEMP1
  254. END
  255. END
  256. GO