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.

371 lines
12 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendReceipt] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_sendReceipt]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_sendReceipt] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. ALTER PROC [dbo].[proc_sendReceipt] (
  12. @flag VARCHAR(50)
  13. ,@user VARCHAR(30) = NULL
  14. ,@controlNo VARCHAR(30) = NULL
  15. ,@tranId VARCHAR(30) = NULL
  16. ,@msgType CHAR(1) = NULL
  17. ,@sortBy VARCHAR(50) = NULL
  18. ,@sortOrder VARCHAR(5) = NULL
  19. ,@pageSize INT = NULL
  20. ,@pageNumber INT = NULL
  21. )
  22. AS
  23. DECLARE @controlNoEncrypted VARCHAR(20),@tranStatus VARCHAR(20),@agentId INT
  24. DECLARE @headMsg NVARCHAR(MAX)
  25. ,@commonMsg NVARCHAR(MAX)
  26. ,@countrySpecificMsg NVARCHAR(MAX)
  27. ,@sAgent INT
  28. ,@sCountry INT
  29. ,@sUser VARCHAR(50)
  30. ,@sUserFullName VARCHAR(75)
  31. ,@customerId INT
  32. ,@bonusPointPending MONEY
  33. ,@bonusPoint MONEY
  34. ,@bonusSchemeId INT
  35. IF @controlNo IS NOT NULL
  36. BEGIN
  37. SELECT @controlNoEncrypted = dbo.FNAEncryptString(UPPER(@controlNo))
  38. SELECT @tranId = holdTranId FROM vwRemitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  39. END
  40. IF @tranId IS NOT NULL
  41. BEGIN
  42. IF ISNUMERIC(@tranId) = 0
  43. BEGIN
  44. EXEC proc_errorHandler 1, 'Invalid Transaction ID', NULL
  45. RETURN
  46. END
  47. SELECT @controlNoEncrypted = controlNo FROM vwRemitTran WITH(NOLOCK) WHERE holdTranId = @tranId OR id = @tranId
  48. SET @controlNo = dbo.FNADecryptString(@controlNoEncrypted)
  49. END
  50. --## Check Transaction Control No
  51. IF @flag = 'c'
  52. BEGIN
  53. IF NOT EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted)
  54. BEGIN
  55. EXEC proc_errorHandler 1, 'Transaction Not Found', @controlNoEncrypted
  56. RETURN
  57. END
  58. SELECT @tranStatus = tranStatus FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  59. IF @tranStatus = 'Cancel'
  60. BEGIN
  61. EXEC proc_errorHandler 1, 'Transaction Not Found', @controlNoEncrypted
  62. RETURN
  63. END
  64. IF @tranStatus = 'Block'
  65. BEGIN
  66. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact Head Office.', @controlNoEncrypted
  67. RETURN
  68. END
  69. SELECT @agentId = agentId FROM applicationUsers WHERE userName = @user
  70. IF @agentId = dbo.FNAGetHOAgentId()
  71. BEGIN
  72. EXEC proc_errorHandler 0, 'Transaction Found', @controlNoEncrypted
  73. RETURN
  74. END
  75. --IF NOT EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND (sBranch = (SELECT agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user)))
  76. --BEGIN
  77. -- EXEC proc_errorHandler 1, 'You are not authorized to view this transaction', @controlNoEncrypted
  78. -- RETURN
  79. --END
  80. EXEC proc_errorHandler 0, 'Transaction Found', @controlNoEncrypted
  81. END
  82. --## transaction information for receipt
  83. IF @flag = 'receipt'
  84. BEGIN
  85. SELECT
  86. @sAgent = sBranch
  87. ,@sUser = createdBy
  88. ,@customerId = sen.customerId
  89. FROM remitTran rt with(nolock)
  90. inner join tranSenders sen with(nolock) on rt.id = sen.tranId
  91. WHERE controlNo = @controlNoEncrypted
  92. SELECT @bonusSchemeId = bonusSchemeId
  93. FROM bonusOperationSetup
  94. WHERE GETDATE() BETWEEN schemeStartDate AND schemeEndDate
  95. AND isnull(isActive,'N') = 'Y'
  96. IF @bonusSchemeId is not null and @customerId is not null
  97. SELECT
  98. @bonusPointPending= bonusPointPending,
  99. @bonusPoint=isnull(bonusPoint,0)
  100. FROM customerMaster WITH (NOLOCK)
  101. where isnull(isDeleted,'N') <> 'Y'
  102. and customerId = @customerId
  103. SELECT
  104. tranId = trn.id
  105. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  106. ,sMemId = sen.membershipId
  107. ,senderName = UPPER(sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, ''))
  108. ,sCountryName = sen.country
  109. ,sAddress = sen.address
  110. ,sContactNo = COALESCE(sen.mobile, sen.homephone, sen.workphone)
  111. ,sIdType = ISNULL(sdv.detailTitle,sen.idType)
  112. ,sIdNo = sen.idNumber
  113. ,sEmail = sen.email
  114. --Receiver Information
  115. ,rMemId = rec.membershipId
  116. ,rCustomerId = rec.customerId
  117. ,receiverName = UPPER(rec.firstName + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, ''))
  118. ,rCountryName = rec.country
  119. ,rAddress = rec.address
  120. ,rContactNo = COALESCE(rec.mobile, rec.homephone, rec.workphone)
  121. ,rIdType = rec.idType
  122. ,rIdNo = rec.idNumber
  123. ,relWithSender = trn.relWithSender
  124. ,sAgentName = CASE WHEN trn.sAgentName = trn.sBranchName THEN trn.sSuperAgentName ELSE trn.sAgentName END
  125. ,sBranchName = trn.sBranchName
  126. ,sAgentCountry = sa.agentCountry
  127. ,sAgentLocation = sLoc.districtName
  128. ,sAgentAddress = sa.agentAddress
  129. ,agentPhone1 = sa.agentPhone1
  130. ,pAgentCountry = trn.pCountry
  131. ,pAgentDistrict = trn.pDistrict
  132. ,pAgentLocation = pLoc.districtName
  133. ,trn.tAmt
  134. ,trn.serviceCharge
  135. ,handlingFee = ISNULL(trn.handlingFee, 0)
  136. ,trn.cAmt
  137. ,trn.pAmt
  138. ,trn.paymentMethod
  139. ,relationship = ISNULL(trn.relWithSender, '-')
  140. ,purpose = ISNULL(trn.purposeOfRemit, '-')
  141. ,sourceOfFund = ISNULL(trn.sourceOfFund, '-')
  142. ,collMode = trn.collMode
  143. ,trn.collCurr
  144. ,trn.accountNo
  145. ,branchName = trn.pBankBranchName
  146. ,bankName = trn.pBankName
  147. ,paymentMethod = trn.paymentMethod
  148. ,trn.payoutCurr
  149. ,trn.tranStatus
  150. ,trn.payStatus
  151. ,payoutMsg = isnull(trn.pMessage,'')
  152. ,trn.createdBy
  153. ,trn.createdDate
  154. ,trn.approvedBy
  155. ,trn.approvedDate
  156. ,trn.paidBy
  157. ,trn.paidDate
  158. ,trn.payTokenId
  159. ,pendingBonus = isnull(cast(@bonusPointPending as varchar),'')
  160. ,earnedBonus = isnull(cast(@bonusPoint as varchar),'')
  161. FROM remitTran trn WITH(NOLOCK)
  162. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  163. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  164. LEFT JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  165. LEFT JOIN agentMaster pa WITH(NOLOCK) ON trn.pBranch = pa.agentId
  166. LEFT JOIN api_districtList pLoc WITH(NOLOCK) ON trn.pLocation = pLoc.districtCode
  167. LEFT JOIN api_districtList sLoc WITH(NOLOCK) ON sa.agentLocation = sLoc.districtCode
  168. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON sen.idType=CAST(sdv.valueId AS VARCHAR)
  169. WHERE trn.controlNo = @controlNoEncrypted
  170. -->> 6.Message
  171. SELECT
  172. @sUserFullName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName, '')
  173. FROM applicationUsers WHERE userName = @sUser
  174. SELECT @sCountry = countryId FROM countryMaster WITH(NOLOCK)
  175. WHERE countryName = (SELECT agentCountry FROM agentMaster WHERE agentId = @sAgent)
  176. --Head Message
  177. SELECT @headMsg = headMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  178. IF(@headMsg IS NULL)
  179. SELECT @headMsg = headMsg FROM message WHERE countryId IS NULL AND headMsg IS NOT NULL AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  180. --Common Message
  181. SELECT @commonMsg = commonMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y'
  182. IF(@commonMsg IS NULL)
  183. SELECT @commonMsg = commonMsg FROM message WHERE countryId IS NULL AND commonMsg IS NOT NULL AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  184. --Country Specific Message
  185. SELECT @countrySpecificMsg = countrySpecificMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  186. IF(@countrySpecificMsg IS NULL)
  187. SELECT @countrySpecificMsg = countrySpecificMsg FROM message WHERE countryId IS NULL AND countrySpecificMsg IS NOT NULL AND msgType = @msgType AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  188. SELECT @headMsg AS headMsg,@commonMsg AS commonMsg, @countrySpecificMsg AS countrySpecificMsg, @sUserFullName AS sUserFullName
  189. END
  190. --## transaction information for fee receipt
  191. IF @flag = 'receiptFeeCollection'
  192. BEGIN
  193. SELECT
  194. @sAgent = sBranch
  195. ,@sUser = createdBy
  196. ,@customerId = sen.customerId
  197. FROM remitTran rt with(nolock)
  198. inner join tranSenders sen with(nolock) on rt.id = sen.tranId
  199. WHERE controlNo = @controlNoEncrypted
  200. SELECT @bonusSchemeId = bonusSchemeId
  201. FROM bonusOperationSetup
  202. WHERE GETDATE() BETWEEN schemeStartDate AND schemeEndDate
  203. AND isnull(isActive,'N') = 'Y'
  204. IF @bonusSchemeId is not null and @customerId is not null
  205. SELECT
  206. @bonusPointPending= bonusPointPending,
  207. @bonusPoint=isnull(bonusPoint,0)
  208. FROM customerMaster WITH (NOLOCK)
  209. where isnull(isDeleted,'N') <> 'Y'
  210. and customerId = @customerId
  211. SELECT
  212. tranId = trn.id
  213. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  214. --## Sender Information
  215. ,sMemId = sen.membershipId
  216. ,senderName = UPPER(sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, ''))
  217. ,sCountryName = sen.country
  218. ,sAddress = sen.address
  219. ,sContactNo = COALESCE(sen.mobile, sen.homephone, sen.workphone)
  220. ,sIdType = ISNULL(sdv.detailTitle,sen.idType)
  221. ,sIdNo = sen.idNumber
  222. ,sEmail = sen.email
  223. --## Receiver Information
  224. ,receiverName = sMas.name
  225. ,rCountryName = sMas.country
  226. ,rAddress = sMas.address
  227. ,rContactNo = sMas.contactNo
  228. --## student Information
  229. ,stdName = rec.stdName
  230. ,stdLevel = lvl.name
  231. ,stdRollRegNo = rec.stdRollRegNo
  232. ,stdSemYr = rec.stdSemYr
  233. ,stdFeeType = fee.feeType
  234. ,sAgentName = CASE WHEN trn.sAgentName = trn.sBranchName THEN trn.sSuperAgentName ELSE trn.sAgentName END
  235. ,sBranchName = trn.sBranchName
  236. ,sAgentCountry = sa.agentCountry
  237. ,sAgentLocation = sLoc.districtName
  238. ,sAgentAddress = sa.agentAddress
  239. ,agentPhone1 = sa.agentPhone1
  240. ,pAgentCountry = trn.pCountry
  241. ,pAgentDistrict = trn.pDistrict
  242. ,pAgentLocation = pLoc.districtName
  243. ,trn.tAmt
  244. ,trn.serviceCharge
  245. ,handlingFee = ISNULL(trn.handlingFee, 0)
  246. ,trn.cAmt
  247. ,trn.pAmt
  248. ,trn.paymentMethod
  249. ,relationship = ISNULL(trn.relWithSender, '-')
  250. ,purpose = ISNULL(trn.purposeOfRemit, '-')
  251. ,sourceOfFund = ISNULL(trn.sourceOfFund, '-')
  252. ,collMode = trn.collMode
  253. ,trn.collCurr
  254. ,accountNo=sMas.accountNo
  255. ,branchName = BRANCH.agentAddress
  256. ,bankName = BANK.agentName
  257. ,paymentMethod = trn.paymentMethod
  258. ,trn.payoutCurr
  259. ,trn.tranStatus
  260. ,trn.payStatus
  261. ,payoutMsg = isnull(trn.pMessage,'')
  262. ,trn.createdBy
  263. ,trn.createdDate
  264. ,trn.approvedBy
  265. ,trn.approvedDate
  266. ,trn.paidBy
  267. ,trn.paidDate
  268. ,trn.payTokenId
  269. ,pendingBonus = isnull(cast(@bonusPointPending as varchar),'')
  270. ,earnedBonus = isnull(cast(@bonusPoint as varchar),'')
  271. FROM remitTran trn WITH(NOLOCK)
  272. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  273. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  274. LEFT JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  275. LEFT JOIN agentMaster pa WITH(NOLOCK) ON trn.pBranch = pa.agentId
  276. LEFT JOIN api_districtList pLoc WITH(NOLOCK) ON trn.pLocation = pLoc.districtCode
  277. LEFT JOIN api_districtList sLoc WITH(NOLOCK) ON sa.agentLocation = sLoc.districtCode
  278. LEFT JOIN schoolMaster sMas WITH(NOLOCK) ON sMas.rowId = rec.stdCollegeId
  279. LEFT JOIN schoolLevel lvl with(nolock) on lvl.rowId=rec.stdLevel
  280. LEFT JOIN agentMaster BANK WITH(NOLOCK) ON BANK.agentId=sMas.bankId
  281. LEFT JOIN agentMaster BRANCH WITH(NOLOCK) ON BRANCH.agentId=sMas.bankBranchId
  282. LEFT JOIN schoolFee fee with(nolock) on fee.rowId=rec.feeTypeId
  283. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON sen.idType=CAST(sdv.valueId AS VARCHAR)
  284. WHERE trn.controlNo = @controlNoEncrypted
  285. END
  286. --## Check Internation send Transaction Control No
  287. IF @flag = 'checkInt'
  288. BEGIN
  289. declare @sBranch int,@userType varchar(20),@parentId int
  290. SELECT @tranStatus = tranStatus,@sAgent = sAgent,@sBranch = sBranch FROM vwRemitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  291. IF @tranStatus IS NULL
  292. BEGIN
  293. EXEC proc_errorHandler 1, 'Transaction Not Found', @controlNo
  294. RETURN
  295. END
  296. IF @tranStatus = 'Cancel'
  297. BEGIN
  298. EXEC proc_errorHandler 1, 'Transaction is cancelled', @controlNo
  299. RETURN
  300. END
  301. IF @tranStatus = 'Block'
  302. BEGIN
  303. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact Head Office.', @controlNo
  304. RETURN
  305. END
  306. SELECT @agentId = au.agentId,
  307. @userType = userType,
  308. @parentId = am.parentId
  309. FROM applicationUsers au WITH(NOLOCK) inner join agentMaster am with(nolock) ON au.agentId = am.agentId WHERE userName = @user
  310. IF @agentId = dbo.FNAGetHOAgentId()
  311. BEGIN
  312. EXEC proc_errorHandler 0, 'Transaction Found', @controlNo
  313. RETURN
  314. END
  315. if @sBranch = @agentId
  316. BEGIN
  317. EXEC proc_errorHandler 0, 'Transaction Found', @controlNo
  318. RETURN
  319. END
  320. if @sAgent = @parentId and @userType = 'AH'
  321. BEGIN
  322. EXEC proc_errorHandler 0, 'Transaction Found', @controlNo
  323. RETURN
  324. END
  325. EXEC proc_errorHandler 1, 'Transaction not found', @controlNo
  326. END