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.

813 lines
50 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_payTxnV2] 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 procEDURE [dbo].[proc_payTxnV2](
  9. @flag VARCHAR(1)
  10. ,@user VARCHAR(50)
  11. ,@rowId BIGINT = NULL
  12. ,@securityNo VARCHAR(50) = NULL
  13. ,@transactionDate DATETIME = NULL
  14. ,@sendingCountry VARCHAR(50) = NULL
  15. ,@senderName VARCHAR(50) = NULL
  16. ,@senderAddress VARCHAR(50) = NULL
  17. ,@senderContactNo VARCHAR(50) = NULL
  18. ,@senderCountry VARCHAR(50) = NULL
  19. ,@senderIdNo VARCHAR(50) = NULl
  20. ,@senderIdType VARCHAR(50) = NULl
  21. ,@recName VARCHAR(50) = NULl
  22. ,@recAddress VARCHAR(50) = NULl
  23. ,@recContactNo VARCHAR(50) = NULl
  24. ,@recIdType VARCHAR(50) = NULl
  25. ,@recIdNo VARCHAR(50) = NULl
  26. ,@pAmount VARCHAR(50) = NULl
  27. ,@relationType VARCHAR(50) = NULl
  28. ,@relativeName VARCHAR(50) = NULl
  29. ,@rIdPlaceOfIssue VARCHAR(50) = NULl
  30. ,@partnerId VARCHAR(30) = NULL
  31. ,@pBranchId VARCHAR(50) = NULL
  32. ,@branchName VARCHAR(200) = NULL
  33. )
  34. AS
  35. IF @Flag='s'
  36. BEGIN
  37. DECLARE @agentGrp INT,@cotrolNo VARCHAR(50)
  38. IF @pBranchId IS NOT NULL
  39. SELECT @branchName = agentName, @agentGrp = agentGrp FROM agentMaster am WITH(NOLOCK) WHERE agentId = @pBranchId
  40. IF(@partnerId='4734') /***** Global Remit *****/
  41. BEGIN
  42. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  43. SELECT TOP 1
  44. rowId = gbl.rowId
  45. ,securityNo = dbo.FNADecryptString(gbl.radNo)
  46. ,transactionDate = gbl.createdDate
  47. ,senderName = gbl.senderName
  48. ,senderAddress = gbl.senderAddress
  49. ,senderMobile = gbl.senderMobile
  50. ,senderTel = gbl.senderTel
  51. ,senderIdNo = gbl.senderIdNo
  52. ,senderIdType = gbl.senderIdType
  53. ,senderCity = ''
  54. ,recName = gbl.benefName
  55. ,recAddress = gbl.benefAddress
  56. ,recMobile = gbl.benefMobile
  57. ,recTelePhone = gbl.benefTel
  58. ,recIdType = gbl.benefIdType
  59. ,recIdNo = gbl.benefAccIdNo
  60. ,recCity = ''
  61. ,recCountry = ''
  62. ,pAmount = isnull(gbl.amount,0)
  63. ,rCurrency = gbl.rCurrency
  64. ,pCurrency = gbl.pCurrency
  65. ,remarks = gbl.remarks
  66. ,paymentMethod = 'Cash Payment'
  67. ,tokenId = gbl.tokenId
  68. ,amt = isnull(gbl.amount,0)
  69. ,pBranch = gbl.pBranch
  70. ,sendingCountry = ''
  71. ,sendingAgent = ''
  72. ,branchName = @branchName
  73. ,providerName = 'Global Remit'
  74. ,orderNo = ''
  75. ,agentGrp = ''
  76. FROM globalBankPayHistory gbl WITH(NOLOCK)
  77. WHERE rowId = @rowId ORDER BY rowId DESC
  78. -- ## Log Details
  79. SELECT
  80. [message]
  81. ,trn.createdBy
  82. ,trn.createdDate
  83. FROM tranModifyLog trn WITH(NOLOCK)
  84. WHERE 1=2
  85. RETURN
  86. END
  87. IF (@partnerId='4670') /***** CASH EXPRESS *****/
  88. BEGIN
  89. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  90. SELECT TOP 1
  91. rowId
  92. ,securityNo = dbo.FNADecryptString(ce.gitNo)
  93. ,transactionDate = ce.createdDate
  94. ,senderName = ce.custName
  95. ,senderAddress = ISNULL(ce.custAddress,'')
  96. ,senderMobile = ISNULL(ce.custPhone,'')
  97. ,senderTel = ''
  98. ,senderIdNo = ce.custIdNo
  99. ,senderIdType = ce.custIdType
  100. ,senderCity = ''
  101. ,recName = ce.beneName
  102. ,recAddress = ce.beneAddress
  103. ,recMobile = isnull(ce.rContactNo,ce.benePhone)
  104. ,recTelePhone = ISNULL(ce.benePhone,'')
  105. ,recIdType = ce.rIdType
  106. ,recIdNo = ce.rIdNumber
  107. ,recCity = ''
  108. ,recCountry = ''
  109. ,pAmount = ce.destinationAmount
  110. ,rCurrency = 'NPR'
  111. ,pCurrency = ce.destinationCurrency
  112. ,remarks = ce.remarks
  113. ,paymentMethod = 'Cash Payment'
  114. ,tokenId = ''
  115. ,amt = ce.destinationAmount
  116. ,pBranch = ce.pBranch
  117. ,sendingCountry = ''
  118. ,sendingAgent = ''
  119. ,branchName = @branchName
  120. ,providerName = 'Cash Express'
  121. ,orderNo = ''
  122. ,agentGrp = @agentGrp
  123. FROM cePayHistory ce WITH(NOLOCK)
  124. WHERE rowId = @rowId ORDER BY rowId DESC
  125. -- ## Log Details
  126. SELECT
  127. [message]
  128. ,trn.createdBy
  129. ,trn.createdDate
  130. FROM tranModifyLog trn WITH(NOLOCK)
  131. WHERE 1=2
  132. RETURN
  133. END
  134. IF (@partnerId='4726') /***** EZ Remit *****/
  135. BEGIN
  136. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  137. SELECT TOP 1
  138. rowId = ez.id
  139. ,securityNo = dbo.FNADecryptString(ez.SecurityNumber)
  140. ,transactionDate = ez.createdDate
  141. ,senderName = ez.scCustomerName
  142. ,senderAddress = ISNULL(ez.scCustomerAddress,'')
  143. ,senderMobile = ISNULL(ez.scCustMobileNumber,'')
  144. ,senderTel = ISNULL(ez.scCustTelephoneNumber,'')
  145. ,senderIdNo = ez.scCustId
  146. ,senderIdType = ez.scCustIdType
  147. ,senderCity = ''
  148. ,recName = ez.tbName
  149. ,recAddress = ez.tbAddress
  150. ,recMobile = isnull(rContactNo,ez.tbContactTelephoneNo)
  151. ,recTelePhone = ISNULL(ez.tbTelephoneNumber,ez.tbContactTelephoneNo)
  152. ,recIdType = ez.rIdType
  153. ,recIdNo = ez.rIdNumber
  154. ,recCity = ''
  155. ,recCountry = ez.tbBenCountry
  156. ,pAmount = ez.tdFxAmount
  157. ,rCurrency = 'NPR'
  158. ,pCurrency = ez.tdFxCurrencyCode
  159. ,remarks = ez.remarks
  160. ,paymentMethod = 'Cash Payment'
  161. ,tokenId = ''
  162. ,amt = ez.tdFxAmount
  163. ,pBranch = ez.pBranch
  164. ,sendingCountry = ez.scCustCountry
  165. ,sendingAgent = ez.scCustBankName
  166. ,branchName = @branchName
  167. ,providerName = 'EZ Remit'
  168. ,orderNo = ''
  169. ,agentGrp = @agentGrp
  170. FROM ezPayHistory ez WITH(NOLOCK)
  171. WHERE ez.id = @rowId
  172. ORDER BY id DESC
  173. -- ## Log Details
  174. SELECT
  175. [message]
  176. ,trn.createdBy
  177. ,trn.createdDate
  178. FROM tranModifyLog trn WITH(NOLOCK)
  179. WHERE 1=2
  180. RETURN
  181. END
  182. IF (@partnerId='4869') /***** RIA *****/
  183. BEGIN
  184. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  185. SELECT TOP 1
  186. rowId
  187. ,securityNo = dbo.FNADecryptString(ria.pin)
  188. ,transactionDate = ria.createdDate
  189. ,senderName = ria.CustNameFirst + ISNULL( ' ' + ria.custNameLast1, '') + ISNULL( ' ' + ria.custNameLast2, '')
  190. ,senderAddress = ISNULL(ria.CustAddress,'')
  191. ,senderMobile = ISNULL(ria.custTelNo,'')
  192. ,senderTel = ISNULL(ria.custTelNo,'')
  193. ,senderIdNo = ''
  194. ,senderIdType = ''
  195. ,senderCity = ''
  196. ,recName = ria.beneNameFirst + ISNULL( ' ' + ria.beneNameLast1, '') + ISNULL( ' ' + ria.beneNameLast2, '')
  197. ,recAddress = ria.rAddress
  198. ,recMobile = ISNULL(ria.rContactNo,'')
  199. ,recTelePhone = ISNULL(ria.rContactNo,'')
  200. ,recIdType = ria.rIdType
  201. ,recIdNo = ria.rIdNumber
  202. ,recCity = ''
  203. ,recCountry = ''
  204. ,pAmount = ria.BeneAmount
  205. ,rCurrency = 'NPR'
  206. ,pCurrency = 'NPR'
  207. ,remarks = ria.remarks
  208. ,paymentMethod = 'Cash Payment'
  209. ,tokenId = ria.transRefID
  210. ,amt = ria.beneAmount
  211. ,pBranch = ria.pBranch
  212. ,sendingCountry = ''
  213. ,sendingAgent = ''
  214. ,branchName = @branchName
  215. ,providerName = 'RIA Financial'
  216. ,orderNo = ria.orderNo
  217. ,agentGrp = @agentGrp
  218. FROM riaRemitPayHistory ria WITH(NOLOCK)
  219. WHERE rowId = @rowId ORDER BY rowId DESC
  220. -- ## Log Details
  221. SELECT
  222. [message]
  223. ,trn.createdBy
  224. ,trn.createdDate
  225. FROM tranModifyLog trn WITH(NOLOCK)
  226. WHERE 1=2
  227. RETURN
  228. END
  229. IF (@partnerId='4909') /***** X-PRESS Money *****/
  230. BEGIN
  231. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  232. SELECT TOP 1
  233. rowId
  234. ,securityNo = dbo.FNADecryptString(xp.xpin)
  235. ,transactionDate = xp.payinDate
  236. ,senderName = xp.customerFirstName + ISNULL( ' ' + xp.customerMiddleName, '') + ISNULL( ' ' + xp.customerLastName, '')
  237. ,senderAddress = ISNULL(xp.customerAddress1,'')
  238. ,senderMobile = ISNULL(xp.customerMobile,'')
  239. ,senderTel = ISNULL(xp.customerPhone,'')
  240. ,senderIdNo = ''
  241. ,senderIdType = ''
  242. ,senderCity = customerAddressCity
  243. ,recName = xp.beneficiaryFirstName + ISNULL( ' ' + xp.beneficiaryMiddleName, '') + ISNULL( ' ' + xp.beneficiaryLastName, '')
  244. ,recAddress = xp.beneficiaryAddress1
  245. ,recMobile = ISNULL(xp.beneficiaryMobile,'')
  246. ,recTelePhone = ISNULL(xp.beneficiaryPhone,'')
  247. ,recIdType = xp.beneficiaryIDOtherType
  248. ,recIdNo = xp.beneficiaryID
  249. ,recCity = xp.beneficiaryAddressCity
  250. ,recCountry = xp.beneficiaryAddressCountry
  251. ,pAmount = xp.payoutAmount
  252. ,rCurrency = xp.payoutCcyCode
  253. ,pCurrency = xp.payoutCcyCode
  254. ,remarks = xp.messageToBeneficiary
  255. ,paymentMethod = 'Cash Payment'
  256. ,tokenId = xp.xmwsSessionID
  257. ,amt = xp.payoutAmount
  258. ,pBranch = xp.branchId
  259. ,sendingCountry = xp.sendingCountry
  260. ,sendingAgent = xp.sendingAgentName
  261. ,branchName = @branchName
  262. ,providerName = 'XPRESS Money'
  263. ,orderNo = ''
  264. ,agentGrp = @agentGrp
  265. FROM xPressTranHistory xp WITH(NOLOCK)
  266. WHERE rowId = @rowId ORDER BY rowId DESC
  267. -- ## Log Details
  268. SELECT
  269. [message]
  270. ,trn.createdBy
  271. ,trn.createdDate
  272. FROM tranModifyLog trn WITH(NOLOCK)
  273. WHERE 1=2
  274. RETURN
  275. END
  276. IF @partnerId = '4854' /***** MONEY GRAM *****/
  277. BEGIN
  278. --SELECT top 10 * FROM mgPayHistory WITH(NOLOCK) order by id desc WHERE id = @id
  279. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  280. SELECT TOP 1
  281. rowId = xp.id
  282. ,securityNo = dbo.FNADecryptString(xp.referenceNumber)
  283. ,transactionDate = xp.dateTimeSent
  284. ,senderName = xp.senderFirstName + ISNULL( ' ' + xp.senderMiddleName, '') + ISNULL( ' ' + xp.senderLastName, '')+ISNULL( ' ' + xp.senderLastName2, '')
  285. ,senderAddress = ISNULL(xp.senderAddress,'')
  286. ,senderMobile = ISNULL(xp.senderHomePhone,'')
  287. ,senderTel = ISNULL(xp.senderHomePhone,'')
  288. ,senderIdType = ''
  289. ,senderIdNo = ''
  290. ,senderCity = xp.senderCity
  291. ,senderCountry = xp.senderCountry
  292. ,recName = xp.receiverFirstName + ISNULL( ' ' + xp.receiverMiddleName, '') + ISNULL( ' ' + xp.receiverLastName, '') + ISNULL( ' ' + xp.receiverLastName2, '')
  293. ,recAddress = xp.receiverAddress
  294. ,recMobile = ''
  295. ,recTelePhone = ISNULL(xp.receiverContactNo,'')
  296. ,recIdType = xp.receiverIdType
  297. ,recIdNo = xp.receiverIdnumber
  298. ,recCity = xp.receiverCity
  299. ,recCountry = xp.receiverNativeCountry
  300. ,pAmount = floor(xp.receiveAmount)
  301. ,rCurrency = ''
  302. ,pCurrency = xp.receiveCurrency
  303. ,remarks = xp.remarks
  304. ,paymentMethod = 'Cash Payment'
  305. ,tokenId = xp.mgiTransactionSessionID
  306. ,amt = xp.receiveAmount
  307. ,pBranch = xp.branch
  308. ,sendingCountry = xp.originatingCountry
  309. ,sendingAgent = xp.agentName
  310. ,branchName = @branchName
  311. ,providerName = 'Money Gram'
  312. ,orderNo = ''
  313. ,agentGrp = @agentGrp
  314. FROM mgPayHistory xp WITH(NOLOCK)
  315. WHERE id = @rowId ORDER BY id DESC
  316. -- ## Log Details
  317. SELECT
  318. [message]
  319. ,trn.createdBy
  320. ,trn.createdDate
  321. FROM tranModifyLog trn WITH(NOLOCK)
  322. WHERE 1=2
  323. RETURN
  324. END
  325. IF (@partnerId='4816') /***** Instant Cash *****/
  326. BEGIN
  327. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @rowId
  328. SELECT TOP 1
  329. rowId
  330. ,securityNo = dbo.FNADecryptString(ic.ICTC_Number)
  331. ,transactionDate = CASE WHEN ISNULL(ic.Transaction_SentDate,'')<>'' AND LEN(ic.Transaction_SentDate)=8
  332. THEN SUBSTRING(ic.Transaction_SentDate,5,2)+'/'+SUBSTRING(ic.Transaction_SentDate,7,2)+'/'+SUBSTRING(ic.Transaction_SentDate,1,4)
  333. ELSE ic.Transaction_SentDate
  334. END -- 11/13/2014
  335. ,senderName = ic.Remitter_Name
  336. ,senderAddress = ISNULL(ic.Remitter_Address,'')
  337. ,senderMobile = ''
  338. ,senderTel = ''
  339. ,senderIdNo = ic.Remitter_IDDtl
  340. ,senderIdType = ic.Remitter_IDType
  341. ,senderCity = ''
  342. ,recName = ic.Beneficiary_Name
  343. ,recAddress = ic.Beneficiary_Address
  344. ,recMobile = ISNULL(ic.Beneficiary_MobileNo,'')
  345. ,recTelePhone = ISNULL(ic.Beneficiary_TelNo,'')
  346. ,recIdType = ic.rIdType
  347. ,recIdNo = ic.rIdNumber
  348. ,recCity = ic.Beneficiary_City
  349. ,recCountry = ic.Destination_Country
  350. ,pAmount = ic.Paying_Amount
  351. ,rCurrency = ic.Paying_Currency
  352. ,pCurrency = 'NPR'
  353. ,remarks = ic.remarks
  354. ,paymentMethod = 'Cash Payment'
  355. ,tokenId = ''
  356. ,amt = ic.Paying_Amount
  357. ,pBranch = ic.pBranch
  358. ,sendingCountry = ic.Originating_Country
  359. ,sendingAgent = ''
  360. ,branchName = @branchName
  361. ,providerName = 'Instant Cash'
  362. ,orderNo = ic.Agent_OrderNumber
  363. ,agentGrp = @agentGrp
  364. FROM icPayHistory ic WITH(NOLOCK)
  365. WHERE rowId = @rowId ORDER BY rowId DESC
  366. -- ## Log Details
  367. SELECT
  368. [message]
  369. ,trn.createdBy
  370. ,trn.createdDate
  371. FROM tranModifyLog trn WITH(NOLOCK)
  372. WHERE 1=2
  373. RETURN
  374. END
  375. DECLARE
  376. @mapCodeDom VARCHAR(50)
  377. ,@tranStatus VARCHAR(50)
  378. ,@tranId INT
  379. ,@payStatus VARCHAR(50)
  380. ,@controlNoEncrypted VARCHAR(50)
  381. ,@agentType VARCHAR(50)
  382. ,@pTxnLocation VARCHAR(50)
  383. ,@pAgentLocation VARCHAR(50)
  384. ,@pAgent VARCHAR(50)
  385. ,@controlNo VARCHAR(50)
  386. ,@paymentMethod VARCHAR(50)
  387. ,@sBranchId VARCHAR(50)
  388. ,@mapCodeInt VARCHAR(50)
  389. ,@lockStatus VARCHAR(50)
  390. ,@payTokenId VARCHAR(50)
  391. IF (@partnerId='IME-D') /***** IME DOMESTIC*****/
  392. BEGIN
  393. IF @pBranchId IS NULL
  394. BEGIN
  395. EXEC proc_errorHandler 1, 'Please Choose Paying Agent', NULL
  396. RETURN
  397. END
  398. SELECT
  399. @mapCodeDom = mapCodeDom,
  400. @agentType = agentType,
  401. @pAgentLocation = agentLocation,
  402. @branchName = agentName
  403. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranchId
  404. IF (@mapCodeDom IS NULL OR @mapCodeDom = '' OR @mapCodeDom = 0)
  405. BEGIN
  406. EXEC proc_errorHandler 1, 'Invalid Map Code', NULL
  407. RETURN
  408. END
  409. SELECT
  410. @tranStatus = tranStatus,
  411. @tranId = id,
  412. @payStatus = payStatus ,
  413. @controlNoEncrypted = controlNo,
  414. @paymentMethod = paymentMethod,
  415. @sBranchId = sBranch,
  416. @pTxnLocation = pLocation
  417. FROM remitTran WITH(NOLOCK)
  418. WHERE id = @rowId
  419. IF @tranStatus IS NULL
  420. BEGIN
  421. EXEC proc_errorHandler 1000, 'Transaction not found', NULL
  422. RETURN
  423. END
  424. IF @agentType = 2903
  425. BEGIN
  426. SET @pAgent = @pBranchId
  427. END
  428. INSERT INTO tranViewHistory(
  429. controlNumber
  430. ,tranViewType
  431. ,agentId
  432. ,createdBy
  433. ,createdDate
  434. ,tranId
  435. )
  436. SELECT
  437. @controlNoEncrypted
  438. ,'PAY'
  439. ,@pBranchId
  440. ,@user
  441. ,GETDATE()
  442. ,@tranId
  443. IF @paymentMethod = 'Bank Deposit'
  444. BEGIN
  445. EXEC proc_errorHandler 1, 'Cannot process payment for Payment Type Bank Deposit', NULL
  446. RETURN
  447. END
  448. IF @sBranchId = @pBranchId
  449. BEGIN
  450. EXEC proc_errorHandler 1, 'Cannot process payment for same POS', @tranId
  451. RETURN
  452. END
  453. IF (@tranStatus = 'CancelRequest')
  454. BEGIN
  455. EXEC proc_errorHandler 1, 'Transaction has been requested for cancel', @controlNoEncrypted
  456. RETURN
  457. END
  458. IF (@tranStatus = 'Lock' )
  459. BEGIN
  460. EXEC proc_errorHandler 1, 'Transaction is locked', @controlNoEncrypted
  461. RETURN
  462. END
  463. IF (@tranStatus = 'Block')
  464. BEGIN
  465. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact HO', @controlNoEncrypted
  466. RETURN
  467. END
  468. IF (@tranStatus = 'Paid')
  469. BEGIN
  470. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  471. RETURN
  472. END
  473. IF (@payStatus = 'Paid')
  474. BEGIN
  475. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  476. RETURN
  477. END
  478. IF (@tranStatus = 'Hold')
  479. BEGIN
  480. EXEC proc_errorHandler 1, 'Transaction is hold', @controlNoEncrypted
  481. RETURN
  482. END
  483. IF (@tranStatus = 'Cancel')
  484. BEGIN
  485. EXEC proc_errorHandler 1, 'Transaction is cancelled', @controlNoEncrypted
  486. RETURN
  487. END
  488. DECLARE @tranDistrictId INT, @payAgentDistrictId INT
  489. SELECT @payAgentDistrictId = districtId FROM apiLocationMapping WHERE apiDistrictCode = @pAgentLocation
  490. SELECT @tranDistrictId = districtId FROM apiLocationMapping WHERE apiDistrictCode = @pTxnLocation
  491. IF @payAgentDistrictId IS NULL
  492. BEGIN
  493. EXEC proc_errorHandler 1, 'Location not found. Please Contact HO', @controlNo
  494. RETURN
  495. END
  496. IF @tranDistrictId IS NULL
  497. BEGIN
  498. EXEC proc_errorHandler 1, 'Location not found. Please Contact HO', @controlNo
  499. RETURN
  500. END
  501. IF(@tranDistrictId <> @payAgentDistrictId)
  502. BEGIN
  503. EXEC proc_errorHandler 1, 'You are not allowed to pay this TXN. It is not within your district.', @controlNoEncrypted
  504. RETURN
  505. END
  506. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @tranId
  507. SET @payTokenId = SCOPE_IDENTITY()
  508. SELECT TOP 1
  509. rowId =trn.id
  510. ,securityNo =dbo.FNADecryptString(trn.controlNo)
  511. ,transactionDate =trn.createdDateLocal
  512. ,senderName =sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, '')
  513. ,senderAddress =sen.address
  514. ,senderCity =sen.city
  515. ,senderMobile =sen.mobile
  516. ,senderTel =sen.homephone
  517. ,senderIdType =sen.idType
  518. ,senderIdNo =sen.idNumber
  519. ,recName =rec.firstName + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, '')
  520. ,recAddress =rec.address
  521. ,recMobile =rec.mobile
  522. ,recTelePhone =rec.homephone
  523. ,recIdType =rec.idType
  524. ,recIdNo =rec.idNumber
  525. ,recCity =rec.city
  526. ,recCountry =rec.country
  527. ,pAmount =trn.pAmt
  528. ,rCurrency =trn.collCurr
  529. ,pCurrency =trn.payoutCurr
  530. ,remarks =pMessage
  531. ,paymentMethod =trn.paymentMethod
  532. ,tokenId =trn.payTokenId
  533. ,amt =tAmt
  534. ,pBranch =trn.pBranch
  535. ,sendingCountry =trn.sCountry
  536. ,sendingAgent =trn.sAgentName
  537. ,branchName =@branchName
  538. ,providerName ='IME Domestic'
  539. ,orderNo = ''
  540. ,agentGrp = @agentGrp
  541. FROM remitTran trn WITH(NOLOCK)
  542. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  543. INNER JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  544. WHERE trn.id = @rowId
  545. -- ## Lock Transaction
  546. UPDATE remitTran SET
  547. payTokenId = @payTokenId
  548. ,tranStatus = 'Lock'
  549. ,lockedBy = @user
  550. ,lockedDate = GETDATE()
  551. ,lockedDateLocal = GETDATE()
  552. WHERE id = @rowId
  553. -- ## Log Details
  554. SELECT
  555. [message]
  556. ,trn.createdBy
  557. ,trn.createdDate
  558. FROM tranModifyLog trn WITH(NOLOCK)
  559. WHERE trn.tranId = @tranId OR ISNULL(trn.controlNo,'') = ISNULL(@controlNoEncrypted, '')
  560. ORDER BY trn.createdDate DESC
  561. -- ## Compliance pay details Details
  562. SELECT tranId
  563. ,controlNo
  564. ,pBranch
  565. ,receiverName
  566. ,rMemId
  567. ,dob = CONVERT(VARCHAR(10),dob,101)
  568. ,rIdType
  569. ,rIdNumber
  570. ,rPlaceOfIssue
  571. ,rContactNo
  572. ,rRelationType
  573. ,rRelativeName
  574. ,relWithSender
  575. ,purposeOfRemit = ISNULL(sd.detailTitle,purposeOfRemit)
  576. ,purposeOfRemitId = purposeOfRemit
  577. ,reason
  578. ,bankName
  579. ,branchName
  580. ,chequeNo
  581. ,accountNo
  582. ,alternateMobileNo FROM tranPayCompliance tc WITH(NOLOCK)
  583. LEFT JOIN staticDataValue sd WITH(NOLOCK) ON tc.purposeOfRemit=sd.valueId
  584. WHERE tc.tranId = @tranId OR ISNULL(tc.controlNo,'') = ISNULL(@controlNoEncrypted, '')
  585. END
  586. IF (@partnerId='IME-I') /***** IME INTERNATIONAL *****/
  587. BEGIN
  588. IF @pBranchId IS NULL
  589. BEGIN
  590. EXEC proc_errorHandler 1, 'Please Choose Agent', NULL
  591. RETURN
  592. END
  593. SELECT
  594. @mapCodeInt = mapCodeInt
  595. ,@agentType = agentType
  596. ,@pAgentLocation = agentLocation
  597. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranchId
  598. IF (@mapCodeInt IS NULL OR @mapCodeInt = '' OR @mapCodeInt = 0)
  599. BEGIN
  600. EXEC proc_errorHandler 1, 'Invalid Map Code', NULL
  601. RETURN
  602. END
  603. SELECT
  604. @tranStatus = tranStatus
  605. , @tranId = id
  606. , @lockStatus = lockStatus
  607. , @payStatus = payStatus
  608. , @sBranchId = sBranch
  609. , @paymentMethod = paymentMethod
  610. , @controlNoEncrypted = controlNo
  611. FROM remitTran WITH(NOLOCK) WHERE id = @rowId
  612. IF @tranStatus IS NULL
  613. BEGIN
  614. EXEC proc_errorHandler 1000, 'Transaction not found', NULL
  615. RETURN
  616. END
  617. IF @agentType = 2903
  618. BEGIN
  619. SET @pAgent = @pBranchId
  620. END
  621. INSERT INTO tranViewHistory(
  622. controlNumber
  623. ,tranViewType
  624. ,agentId
  625. ,createdBy
  626. ,createdDate
  627. ,tranId
  628. )
  629. SELECT
  630. @controlNoEncrypted
  631. ,'PAY'
  632. ,@pBranchId
  633. ,@user
  634. ,GETDATE()
  635. ,@tranId
  636. IF @paymentMethod = 'Bank Deposit'
  637. BEGIN
  638. EXEC proc_errorHandler 1, 'Cannot process payment for Payment Type Bank Deposit', NULL
  639. RETURN
  640. END
  641. IF @sBranchId = @pBranchId
  642. BEGIN
  643. EXEC proc_errorHandler 1, 'Cannot process payment for same POS', @tranId
  644. RETURN
  645. END
  646. IF (@tranStatus = 'CancelRequest')
  647. BEGIN
  648. EXEC proc_errorHandler 1, 'Transaction has been requested for cancel', @controlNoEncrypted
  649. RETURN
  650. END
  651. IF (@lockStatus = 'Lock' )
  652. BEGIN
  653. EXEC proc_errorHandler 1, 'Transaction is locked', @controlNoEncrypted
  654. RETURN
  655. END
  656. IF (@tranStatus = 'Lock' )
  657. BEGIN
  658. EXEC proc_errorHandler 1, 'Transaction is locked', @controlNoEncrypted
  659. RETURN
  660. END
  661. IF (@tranStatus = 'Block')
  662. BEGIN
  663. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact HO', @controlNoEncrypted
  664. RETURN
  665. END
  666. IF (@tranStatus = 'Paid')
  667. BEGIN
  668. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  669. RETURN
  670. END
  671. IF (@payStatus = 'Paid')
  672. BEGIN
  673. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  674. RETURN
  675. END
  676. IF (@tranStatus = 'Hold')
  677. BEGIN
  678. EXEC proc_errorHandler 1, 'Transaction is hold', @controlNoEncrypted
  679. RETURN
  680. END
  681. IF (@tranStatus = 'Cancel')
  682. BEGIN
  683. EXEC proc_errorHandler 1, 'Transaction is cancelled', @controlNoEncrypted
  684. RETURN
  685. END
  686. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @tranId
  687. SET @payTokenId = SCOPE_IDENTITY()
  688. SELECT TOP 1
  689. rowId =trn.id
  690. ,securityNo =dbo.FNADecryptString(trn.controlNo)
  691. ,transactionDate =trn.createdDateLocal
  692. ,senderName =sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, '')
  693. ,senderAddress =sen.address
  694. ,senderCity =sen.city
  695. ,senderMobile =sen.mobile
  696. ,senderTel =sen.homephone
  697. ,senderIdType =sen.idType
  698. ,senderIdNo =sen.idNumber
  699. ,recName =rec.firstName + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, '')
  700. ,recAddress =rec.address
  701. ,recMobile =rec.mobile
  702. ,recTelePhone =rec.homephone
  703. ,recIdType =rec.idType
  704. ,recIdNo =rec.idNumber
  705. ,recCity =rec.city
  706. ,recCountry =rec.country
  707. ,pAmount =trn.pAmt
  708. ,rCurrency =trn.collCurr
  709. ,pCurrency =trn.payoutCurr
  710. ,remarks =pMessage
  711. ,paymentMethod =trn.paymentMethod
  712. ,tokenId =trn.payTokenId
  713. ,amt =trn.pAmt
  714. ,pBranch =trn.pBranch
  715. ,sendingCountry =trn.sCountry
  716. ,sendingAgent =trn.sAgentName
  717. ,branchName =dbo.GetAgentNameFromId(@pBranchId)
  718. ,providerName ='IME International'
  719. ,orderNo = ''
  720. ,agentGrp = @agentGrp
  721. FROM remitTran trn WITH(NOLOCK)
  722. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  723. INNER JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  724. WHERE trn.id = @rowId
  725. -- ## Lock Transaction
  726. UPDATE remitTran SET
  727. payTokenId = @payTokenId
  728. ,lockStatus = 'locked'
  729. ,lockedBy = @user
  730. ,lockedDate = GETDATE()
  731. ,lockedDateLocal = GETDATE()
  732. WHERE id = @rowId
  733. -- ## Log Details
  734. SELECT
  735. [message]
  736. ,trn.createdBy
  737. ,trn.createdDate
  738. FROM tranModifyLog trn WITH(NOLOCK)
  739. WHERE trn.tranId = @tranId OR ISNULL(trn.controlNo,'') = ISNULL(@controlNoEncrypted, '')
  740. ORDER BY trn.createdDate DESC
  741. -- ## Compliance pay details Details
  742. SELECT tranId
  743. ,controlNo
  744. ,pBranch
  745. ,receiverName
  746. ,rMemId
  747. ,dob = CONVERT(VARCHAR(10),dob,101)
  748. ,rIdType
  749. ,rIdNumber
  750. ,rPlaceOfIssue
  751. ,rContactNo
  752. ,rRelationType
  753. ,rRelativeName
  754. ,relWithSender
  755. ,purposeOfRemit = ISNULL(sd.detailTitle,purposeOfRemit)
  756. ,purposeOfRemitId = purposeOfRemit
  757. ,reason
  758. ,bankName
  759. ,branchName
  760. ,chequeNo
  761. ,accountNo
  762. ,alternateMobileNo FROM tranPayCompliance tc WITH(NOLOCK)
  763. LEFT JOIN staticDataValue sd WITH(NOLOCK) ON tc.purposeOfRemit=sd.valueId
  764. WHERE tc.tranId = @tranId OR ISNULL(tc.controlNo,'') = ISNULL(@controlNoEncrypted, '')
  765. END
  766. END
  767. GO