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.

1223 lines
31 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_loadCashRemitCard] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_loadCashRemitCard]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_loadCashRemitCard] Script Date: 7/4/2019 11:35:48 AM ******/
  7. SET ANSI_NULLS ON
  8. GO
  9. SET QUOTED_IDENTIFIER ON
  10. GO
  11. CREATE PROC [dbo].[proc_loadCashRemitCard]
  12. (
  13. @flag VARCHAR(50) = NULL
  14. ,@user VARCHAR(50) = NULL
  15. ,@id INT = NULL
  16. ,@controlNo VARCHAR(50) = NULL
  17. ,@agentUniqueRefId VARCHAR(20) = NULL
  18. ,@sBranch INT = NULL
  19. ,@sBranchName VARCHAR(100) = NULL
  20. ,@sAgent INT = NULL
  21. ,@sAgentName VARCHAR(100) = NULL
  22. ,@sSuperAgent INT = NULL
  23. ,@sSuperAgentName VARCHAR(100) = NULL
  24. ,@settlingAgent INT = NULL
  25. ,@mapCode VARCHAR(8) = NULL
  26. ,@mapCodeDom VARCHAR(8) = NULL
  27. ,@remitCardNo VARCHAR(50) = NULL
  28. ,@benefName VARCHAR(200) = NULL
  29. ,@benefAddress VARCHAR(500) = NULL
  30. ,@benefMobile VARCHAR(50) = NULL
  31. ,@benefIdType VARCHAR(50) = NULL
  32. ,@benefIdNo VARCHAR(50) = NULL
  33. ,@senderName VARCHAR(200) = NULL
  34. ,@senderAddress VARCHAR(500) = NULL
  35. ,@senderMobile VARCHAR(50) = NULL
  36. ,@senderIdType VARCHAR(50) = NULL
  37. ,@senderIdNo VARCHAR(50) = NULL
  38. ,@senderRemitCardNo VARCHAR(50) = NULL
  39. ,@tAmt MONEY = NULL
  40. ,@serviceCharge MONEY = NULL
  41. ,@cAmt MONEY = NULL
  42. ,@pAmt MONEY = NULL
  43. ,@purposeOfRemit VARCHAR(200) = NULL
  44. ,@sourceOfFund VARCHAR(200) = NULL
  45. ,@remarks VARCHAR(MAX) = NULL
  46. ,@fromSendTrnTime VARCHAR(20) = NULL
  47. ,@toSendTrnTime VARCHAR(20) = NULL
  48. ,@txtPass VARCHAR(50) = NULL
  49. ,@sDcInfo VARCHAR(50) = NULL
  50. ,@sIpAddress VARCHAR(50) = NULL
  51. ,@payResponseCode VARCHAR(200) = NULL
  52. ,@payResponseMsg VARCHAR(200) = NULL
  53. ,@isKycApprove CHAR(1) = NULL
  54. ,@refNo VARCHAR(50) = NULL
  55. )
  56. AS
  57. SET NOCOUNT ON
  58. SET XACT_ABORT ON
  59. BEGIN TRY
  60. CREATE TABLE #msg(errorCode INT, msg VARCHAR(100), membershipId INT)
  61. DECLARE
  62. @sql VARCHAR(MAX)
  63. ,@oldValue VARCHAR(MAX)
  64. ,@newValue VARCHAR(MAX)
  65. ,@module VARCHAR(10)
  66. ,@tableAlias VARCHAR(100)
  67. ,@logIdentifier VARCHAR(50)
  68. ,@logParamMod VARCHAR(100)
  69. ,@logParamMain VARCHAR(100)
  70. ,@table VARCHAR(MAX)
  71. ,@select_field_list VARCHAR(MAX)
  72. ,@extra_field_list VARCHAR(MAX)
  73. ,@sql_filter VARCHAR(MAX)
  74. ,@modType VARCHAR(6)
  75. ,@errorMsg VARCHAR(MAX)
  76. ,@controlNoEncrypted VARCHAR(50)
  77. ,@benefAcNo VARCHAR(50)
  78. ,@sCountry VARCHAR(100)
  79. ,@sCountryId VARCHAR(30)
  80. ,@pCountry VARCHAR(100)
  81. ,@pCountryId VARCHAR(30)
  82. ,@deliveryMethod VARCHAR(50)
  83. ,@collMode VARCHAR(50)
  84. ,@sendingCustType VARCHAR(50)
  85. ,@sendingCurrency CHAR(3)
  86. ,@iCollectAmount MONEY
  87. ,@kycApproveFlag CHAR(1)
  88. ,@limitBal MONEY
  89. ,@agentType INT
  90. IF @flag='selectByRemitCardNo'
  91. BEGIN
  92. IF NOT EXISTS(SELECT 'x' FROM kycMaster WITH(NOLOCK)
  93. WHERE remitCardNo = @remitCardNo AND ISNULL(isDeleted,'N') = 'N' AND ISNULL(isActive,'Y') = 'Y')
  94. BEGIN
  95. EXEC proc_errorHandler 1, 'KYC Customer Not Found.', NULL
  96. RETURN
  97. END
  98. SELECT
  99. errorCode = 0 ,
  100. fullName = ISNULL(' '+km.firstName,'')+ ISNULL(' '+km.middleName,'')+ ISNULL(' '+km.lastName,''),
  101. pAddress = ISNULL(' '+vdcMP,'') + ISNULL(' '+wardNoT,'')+ISNULL(' '+districtP,'')+ISNULL(' '+sm.stateName,'')+ISNULL(' '+cm.countryName,''),
  102. mobileP,
  103. idCardType = 'Citizenship',
  104. idCardNo = citizenshipNo,
  105. remitCardNo
  106. FROM kycMaster km WITH(NOLOCK)
  107. LEFT JOIN countryMaster cm WITH(NOLOCK) ON km.countryP = cm.countryId
  108. LEFT JOIN countryStateMaster sm WITH(NOLOCK) ON km.zoneP = sm.stateId
  109. WHERE remitCardNo = @remitCardNo
  110. END
  111. --## load starter
  112. IF @flag = 'ls'
  113. BEGIN
  114. DECLARE
  115. @pBranchName VARCHAR(200),
  116. @receiverName VARCHAR(200),
  117. @availableLimit MONEY
  118. SELECT
  119. @pBranchName = pBranchName,
  120. @sBranch = pBranch,
  121. @receiverName = receiverName,
  122. @pAmt = pAmt,
  123. @remitCardNo = CASE WHEN LEN(ISNULL(rec.membershipId,'')) = 16 THEN rec.membershipId ELSE '' END
  124. FROM remitTran rt WITH(NOLOCK)
  125. INNER JOIN dbo.tranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  126. WHERE controlNo = dbo.FNAEncryptString(@controlNo)
  127. SELECT @sAgent = parentId, @agentType = agentType FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  128. IF @agentType = 2903
  129. SET @sAgent = @sBranch
  130. SELECT @sSuperAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  131. SELECT @settlingAgent = agentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  132. IF @settlingAgent IS NULL
  133. SELECT @settlingAgent = agentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  134. IF @settlingAgent IS NULL
  135. SELECT @settlingAgent = agentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @sSuperAgent AND isSettlingAgent = 'Y'
  136. SELECT
  137. @availableLimit = ISNULL(dbo.FNAGetLimitBal(@settlingAgent), 0)
  138. FROM creditLimit cl
  139. LEFT JOIN currencyMaster cm WITH(NOLOCK) ON cl.currency = cm.currencyId
  140. WHERE agentId = @settlingAgent
  141. IF EXISTS(SELECT 'x' FROM kycMaster WITH(NOLOCK)
  142. WHERE remitCardNo = @remitCardNo AND ISNULL(isDeleted,'N') = 'N' AND ISNULL(isActive,'Y') = 'Y')
  143. BEGIN
  144. SELECT
  145. @benefName = ISNULL(' '+km.firstName,'')+ ISNULL(' '+km.middleName,'')+ ISNULL(' '+km.lastName,''),
  146. @benefAddress = ISNULL(' '+vdcMP,'') + ISNULL(' '+wardNoT,'')+ISNULL(' '+districtP,'')+ISNULL(' '+sm.stateName,'')+ISNULL(' '+cm.countryName,''),
  147. @benefMobile = mobileP,
  148. @benefIdType = 'Citizenship',
  149. @benefIdNo = citizenshipNo
  150. FROM kycMaster km WITH(NOLOCK)
  151. LEFT JOIN countryMaster cm WITH(NOLOCK) ON km.countryP = cm.countryId
  152. LEFT JOIN countryStateMaster sm WITH(NOLOCK) ON km.zoneP = sm.stateId
  153. WHERE remitCardNo = @remitCardNo
  154. END
  155. SELECT
  156. remitCardNo = @remitCardNo,
  157. controlNo = @controlNo,
  158. pBranchName = @pBranchName,
  159. pBranch = @sBranch,
  160. receiverName = @receiverName,
  161. pAmt = @pAmt,
  162. availableBal = @availableLimit,
  163. benefName = @benefName,
  164. benefAddress = @benefAddress,
  165. benefMobile = @benefMobile,
  166. benefIdType = @benefIdType,
  167. benefIdNo = @benefIdNo
  168. END
  169. --## save history
  170. IF @flag='sh'
  171. BEGIN
  172. IF @user IS NULL
  173. BEGIN
  174. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  175. RETURN
  176. END
  177. SET @txtPass = dbo.FNAEncryptString(@txtPass)
  178. IF NOT EXISTS(SELECT 'X' FROM applicationUsers WITH(NOLOCK) WHERE PWD = @txtPass AND userName = @user)
  179. BEGIN
  180. EXEC proc_errorHandler 1, 'TXN password is invalid !', @user
  181. RETURN
  182. END
  183. IF(DATEDIFF(MI,CAST(dbo.FNAGetDateInNepalTZ() AS TIME), CAST(@fromSendTrnTime AS TIME))) > 0
  184. BEGIN
  185. EXEC proc_errorHandler 1, 'You are not authorized to send at this time', NULL
  186. RETURN
  187. END
  188. IF(DATEDIFF(MI,CAST(dbo.FNAGetDateInNepalTZ() AS TIME), CAST(@toSendTrnTime AS TIME))) < 0
  189. BEGIN
  190. EXEC proc_errorHandler 1, 'You are not authorized to send at this time', NULL
  191. RETURN
  192. END
  193. IF NOT EXISTS(SELECT 'x' FROM kycMaster WITH(NOLOCK)
  194. WHERE remitCardNo = @remitCardNo
  195. AND ISNULL(isDeleted,'N') = 'N'
  196. AND ISNULL(isActive,'Y') = 'Y')
  197. BEGIN
  198. EXEC proc_errorHandler 1, 'KYC Customer Not Found.', NULL
  199. RETURN
  200. END
  201. SELECT @agentType = agentType,
  202. @sAgent = parentId,
  203. @sBranchName = agentName
  204. FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  205. IF @agentType = 2903
  206. BEGIN
  207. SET @sAgent = @sBranch
  208. END
  209. SELECT DISTINCT @sSuperAgent = parentId, @sAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  210. SELECT DISTINCT @sSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sSuperAgent
  211. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  212. IF @settlingAgent IS NULL
  213. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  214. IF @settlingAgent IS NULL
  215. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sSuperAgent AND isSettlingAgent = 'Y'
  216. SELECT @pCountry = 'Nepal'
  217. SELECT @sCountry = 'Nepal'
  218. SELECT @pCountryId = '151'
  219. SELECT @sCountryId = '151'
  220. SET @deliveryMethod = 'IME Remit Card'
  221. SET @collMode = NULL
  222. SET @sendingCustType = NULL
  223. SET @sendingCurrency = 'NPR'
  224. DECLARE @currentDate DATETIME
  225. SET @limitBal = [dbo].FNAGetLimitBal(@settlingAgent)
  226. SET @currentDate = dbo.FNAGetDateInNepalTz()
  227. IF EXISTS(SELECT 'X' FROM remitTran trn WITH(NOLOCK)
  228. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  229. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  230. WHERE
  231. trn.createdDate BETWEEN CONVERT(VARCHAR,GETDATE(),101) AND CONVERT(VARCHAR,GETDATE(),101)+' 23:59:59'
  232. AND trn.senderName = @senderName
  233. AND trn.receiverName = @benefName
  234. AND trn.tAmt = @tAmt
  235. AND trn.serviceCharge = @serviceCharge
  236. AND trn.cAmt = @cAmt
  237. AND DATEDIFF(MI, trn.createdDate, @currentDate) <= 5)
  238. BEGIN
  239. EXEC proc_errorHandler 1, 'Similar Transaction Found', NULL
  240. RETURN
  241. END
  242. IF @tAmt > @limitBal
  243. BEGIN
  244. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', NULL
  245. RETURN
  246. END
  247. IF EXISTS (
  248. SELECT
  249. 'X'
  250. FROM sendTranLimit
  251. WHERE agentId = @settlingAgent
  252. AND (tranType = @collMode OR tranType IS NULL)
  253. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  254. AND (customerType = @sendingCustType OR customerType IS NULL)
  255. AND currency = @sendingCurrency
  256. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  257. AND ISNULL(minLimitAmt, 0) > @tAmt
  258. AND ISNULL(maxLimitAmt, 0) < @tAmt
  259. AND ISNULL(isActive, 'N') = 'Y'
  260. )
  261. BEGIN
  262. EXEC [proc_errorHandler] 1, 'Agent Sending limit is exceeded.', NULL
  263. RETURN
  264. END
  265. IF NOT EXISTS (
  266. SELECT
  267. 'X'
  268. FROM sendTranLimit
  269. WHERE countryId = @sCountryId
  270. AND (tranType = @collMode OR tranType IS NULL)
  271. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  272. AND (customerType = @sendingCustType OR customerType IS NULL)
  273. AND currency = @sendingCurrency
  274. AND (receivingCountry = @pCountryId OR receivingCountry IS NULL)
  275. AND ISNULL(minLimitAmt, 0) <= @tAmt
  276. AND ISNULL(maxLimitAmt, 0) >= @tAmt
  277. AND ISNULL(isActive, 'N') = 'Y'
  278. )
  279. BEGIN
  280. EXEC [proc_errorHandler] 1, 'Country Sending limit is not defined or exceeds.', NULL
  281. RETURN
  282. END
  283. DECLARE @sAgentComm MONEY,@sSuperAgentComm MONEY
  284. SELECT
  285. @serviceCharge = 0
  286. ,@sAgentComm = 0
  287. ,@sSuperAgentComm = 0
  288. IF (@cAmt IS NULL)
  289. BEGIN
  290. SET @cAmt = @tAmt + @serviceCharge
  291. END
  292. SET @iCollectAmount = @tAmt + @serviceCharge
  293. IF(@cAmt <> @iCollectAmount)
  294. BEGIN
  295. EXEC [proc_errorHandler] 1, 'Collection Amount not match.', NULL
  296. RETURN
  297. END
  298. SELECT @kycApproveFlag = CASE WHEN approvedDate IS NULL THEN 'N' ELSE 'Y' END,
  299. @benefAcNo = accountNo
  300. FROM kycMaster WITH(NOLOCK) WHERE remitCardNo = @remitCardNo
  301. BEGIN TRANSACTION
  302. INSERT INTO globalCardServiceHistory
  303. (
  304. remitCardNo
  305. ,controlNo
  306. ,sAgent
  307. ,sAgentName
  308. ,sSuperAgent
  309. ,sSuperAgentName
  310. ,sBranch
  311. ,sBranchName
  312. ,benefName
  313. ,benefAddress
  314. ,benefMobile
  315. ,benefIdType
  316. ,benefIdNo
  317. ,benefAcNo
  318. ,senderName
  319. ,senderAddress
  320. ,senderMobile
  321. ,senderIdType
  322. ,senderIdNo
  323. ,senderRemitCardNo
  324. ,collCurr
  325. ,payoutCurr
  326. ,tAmt
  327. ,cAmt
  328. ,serviceCharge
  329. ,sAgentComm
  330. ,dollarRate
  331. ,purposeOfRemit
  332. ,sourceOfFund
  333. ,remarks
  334. ,paymentMethod
  335. ,tranType
  336. ,tranStatus
  337. ,createdBy
  338. ,createdDate
  339. ,createdDateLocal
  340. ,approvedBy
  341. ,approvedDate
  342. ,approvedDateLocal
  343. ,dcInfo
  344. ,ipAddress
  345. ,refNo
  346. )
  347. VALUES
  348. (
  349. @remitCardNo
  350. ,@controlNoEncrypted
  351. ,@sAgent
  352. ,@sAgentName
  353. ,@sSuperAgent
  354. ,@sSuperAgentName
  355. ,@sBranch
  356. ,@sBranchName
  357. ,@benefName
  358. ,@benefAddress
  359. ,@benefMobile
  360. ,@benefIdType
  361. ,@benefIdNo
  362. ,@benefAcNo
  363. ,@senderName
  364. ,@senderAddress
  365. ,@senderMobile
  366. ,@senderIdType
  367. ,@senderIdNo
  368. ,@senderRemitCardNo
  369. ,'NPR'
  370. ,'NPR'
  371. ,@tAmt
  372. ,@cAmt
  373. ,@serviceCharge
  374. ,@sAgentComm
  375. ,'0'
  376. ,@purposeOfRemit
  377. ,@sourceOfFund
  378. ,@remarks
  379. ,'Card Deposit'
  380. ,'C'
  381. ,'Processing'
  382. ,@user
  383. ,GETDATE()
  384. ,DBO.FNAGetDateInNepalTZ()
  385. ,@user
  386. ,GETDATE()
  387. ,DBO.FNAGetDateInNepalTZ()
  388. ,@sDcInfo
  389. ,@sIpAddress
  390. ,@refNo
  391. )
  392. SET @id = @@IDENTITY
  393. IF @@TRANCOUNT > 0
  394. COMMIT TRANSACTION
  395. SELECT 0 errorCode, 'Transaction has been proceed successfully.' msg, @id id, @kycApproveFlag extra
  396. END
  397. --## txn detail
  398. IF @flag ='td'
  399. BEGIN
  400. SELECT
  401. controlNo = CAST(id AS VARCHAR)+'D'
  402. ,benefName = benefName
  403. ,benefAddress = benefAddress
  404. ,benefMobile = benefMobile
  405. ,benefIdType = benefIdType
  406. ,benefIdNo = benefIdNo
  407. ,benefAccNo = benefAcNo
  408. ,senderName = senderName
  409. ,senderAddress = senderAddress
  410. ,senderMobile = senderMobile
  411. ,senderIdType = senderIdType
  412. ,senderIdNo = senderIdNo
  413. ,purpose = purposeOfRemit
  414. ,remitType = 'BANK'
  415. ,payingBankBranchCd= '14'
  416. ,rCurrency = 'NPR'
  417. ,localAmount = tAmt
  418. ,amount = tAmt
  419. ,serviceCharge = serviceCharge
  420. ,pCommission = sAgentComm
  421. ,dollarRate = 1
  422. ,refNo = remitCardNo
  423. ,remarks = remarks
  424. ,[source] = sourceOfFund
  425. ,txnType = 'C'
  426. ,HitApi = '1'
  427. ,refTranNo = refNo
  428. FROM globalCardServiceHistory WITH(NOLOCK)
  429. WHERE id = @id AND tranStatus = 'Processing'
  430. END
  431. --## api error
  432. IF @flag='ae'
  433. BEGIN
  434. UPDATE globalCardServiceHistory SET tranStatus='sendError' WHERE id = @id
  435. EXEC proc_errorHandler 1, @payResponseMsg, @id
  436. RETURN
  437. END
  438. --## receipt
  439. IF @flag = 'r'
  440. BEGIN
  441. IF RIGHT(@controlNo,1) = 'D'
  442. BEGIN
  443. SELECT
  444. tranNo = trn.id
  445. ,benefRemitCardNo = rec.membershipId
  446. ,controlNo = DBO.FNADecryptString(controlNo)
  447. ,benefName = trn.receiverName
  448. ,benefAddress = rec.address
  449. ,benefMobile = rec.mobile
  450. ,benefIdType = rec.idType
  451. ,benefIdNo = rec.idNumber
  452. ,senderName = trn.senderName
  453. ,senderAddress = sen.address
  454. ,senderMobile = sen.mobile
  455. ,senderIdType = sen.idType
  456. ,senderIdNo = sen.idNumber
  457. ,senderRemitCardNo = sen.membershipId
  458. ,collCurr = 'NPR'
  459. ,tAmt
  460. ,cAmt
  461. ,serviceCharge
  462. ,sAgentComm
  463. ,dollarRate =''
  464. ,rec.purposeOfRemit
  465. ,sourceOfFund
  466. ,pMessage
  467. ,modeOfPayment = paymentMethod
  468. ,tranType
  469. ,tranStatus
  470. ,trn.createdDate
  471. ,sAgentName = CASE WHEN trn.sAgentName = trn.sBranchName THEN trn.sSuperAgentName ELSE trn.sAgentName END
  472. ,sBranchName = trn.sBranchName
  473. ,sAgentCountry = sa.agentCountry
  474. ,sAgentLocation = sLoc.districtName
  475. ,sAgentAddress = sa.agentAddress
  476. ,agentPhone1 = sa.agentPhone1
  477. FROM remitTran trn WITH(NOLOCK)
  478. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  479. INNER JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  480. INNER JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  481. LEFT JOIN api_districtList sLoc WITH(NOLOCK) ON sa.agentLocation = sLoc.districtCode
  482. WHERE trn.controlNo = dbo.FNAEncryptString(@controlNo)
  483. END
  484. ELSE
  485. BEGIN
  486. SELECT
  487. tranNo = trn.id
  488. ,benefRemitCardNo = trn.remitCardNo
  489. ,controlNo = trn.id
  490. ,benefName = trn.benefName
  491. ,benefAddress = trn.benefAddress
  492. ,benefMobile = trn.benefMobile
  493. ,benefIdType = trn.benefIdType
  494. ,benefIdNo = trn.benefIdNo
  495. ,senderName = trn.senderName
  496. ,senderAddress = trn.senderAddress
  497. ,senderMobile = trn.senderMobile
  498. ,senderIdType = trn.senderIdType
  499. ,senderIdNo = trn.senderIdNo
  500. ,senderRemitCardNo = trn.senderRemitCardNo
  501. ,collCurr = 'NPR'
  502. ,tAmt
  503. ,cAmt
  504. ,serviceCharge
  505. ,sAgentComm
  506. ,dollarRate =''
  507. ,purposeOfRemit
  508. ,sourceOfFund
  509. ,pMessage = 'Transaction has been sent but waiting for approval from HO.'
  510. ,modeOfPayment = paymentMethod
  511. ,tranType
  512. ,tranStatus
  513. ,trn.createdDate
  514. ,sAgentName = CASE WHEN trn.sAgentName = trn.sBranchName THEN trn.sSuperAgentName ELSE trn.sAgentName END
  515. ,sBranchName = trn.sBranchName
  516. ,sAgentCountry = sa.agentCountry
  517. ,sAgentLocation = sLoc.districtName
  518. ,sAgentAddress = sa.agentAddress
  519. ,agentPhone1 = sa.agentPhone1
  520. FROM globalCardServiceHistory trn WITH(NOLOCK)
  521. INNER JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  522. LEFT JOIN api_districtList sLoc WITH(NOLOCK) ON sa.agentLocation = sLoc.districtCode
  523. WHERE trn.id = @controlNo
  524. END
  525. DECLARE @sUserFullName VARCHAR(200),
  526. @sUser VARCHAR(50),
  527. @headMsg VARCHAR(MAX),
  528. @commonMsg VARCHAR(MAX),
  529. @countrySpecificMsg VARCHAR(MAX),
  530. @msgType CHAR(1) = 'S'
  531. -->> 6.Message
  532. SELECT
  533. @sUserFullName = ISNULL(''+firstName,'') + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName, '')
  534. FROM applicationUsers WITH(NOLOCK) WHERE userName = @User
  535. SELECT @sCountry = countryId FROM countryMaster WITH(NOLOCK)
  536. WHERE countryName = (SELECT agentCountry FROM agentMaster WHERE agentId = @sAgent)
  537. --Head Message
  538. SELECT @headMsg = headMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  539. IF(@headMsg IS NULL)
  540. SELECT @headMsg = headMsg FROM message WHERE countryId IS NULL AND headMsg IS NOT NULL AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  541. --Common Message
  542. SELECT @commonMsg = commonMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y'
  543. IF(@commonMsg IS NULL)
  544. SELECT @commonMsg = commonMsg FROM message WHERE countryId IS NULL AND commonMsg IS NOT NULL AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'Inactive') = 'Active'
  545. --Country Specific Message
  546. SELECT @countrySpecificMsg = countrySpecificMsg FROM message WHERE countryId = @sCountry AND ISNULL(isDeleted, 'N') <> 'Y' AND ISNULL(isActive, 'Inactive') = 'Active'
  547. IF(@countrySpecificMsg IS NULL)
  548. 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'
  549. SELECT @headMsg AS headMsg,@commonMsg AS commonMsg, @countrySpecificMsg AS countrySpecificMsg, @sUserFullName AS sUserFullName
  550. END
  551. --## Send & Pay
  552. IF @flag='sp'
  553. BEGIN
  554. IF @user IS NULL
  555. BEGIN
  556. UPDATE globalCardServiceHistory SET tranStatus='sendError' WHERE id = @id
  557. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  558. RETURN
  559. END
  560. SET @controlNo = CAST(@id AS VARCHAR(10))+ 'D'
  561. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  562. DECLARE
  563. @tranId INT,
  564. @customerId INT,
  565. @ReceiverRemitCardNo VARCHAR(16),
  566. @benefFirstName VARCHAR(200),
  567. @benefMiddleName VARCHAR(200),
  568. @benefLastName VARCHAR(200),
  569. @benefPhone VARCHAR(50),
  570. @benefEmail VARCHAR(50),
  571. @benefCountry VARCHAR(50),
  572. @senderFirstName VARCHAR(200),
  573. @senderMiddleName VARCHAR(200),
  574. @senderLastName VARCHAR(200),
  575. @senderPhone VARCHAR(50),
  576. @senderEmail VARCHAR(50),
  577. @senderCountry VARCHAR(50),
  578. @sFullName VARCHAR(500),
  579. @rFullName VARCHAR(500)
  580. SELECT
  581. @ReceiverRemitCardNo = remitCardNo,
  582. @senderRemitCardNo = senderRemitCardNo,
  583. @sBranch = sBranch,
  584. @tAmt = tAmt,
  585. @rFullName = benefName,
  586. @sFullName = senderName,
  587. @serviceCharge = serviceCharge,
  588. @pAmt = tAmt,
  589. @cAmt = cAmt,
  590. @sAgentComm = sAgentComm,
  591. @mapCodeDom = am.mapCodeDom
  592. FROM globalCardServiceHistory gh WITH(NOLOCK)
  593. INNER JOIN agentMaster am WITH(NOLOCK) ON gh.sBranch = am.agentId
  594. WHERE gh.id = @id
  595. SELECT
  596. @benefFirstName = firstName,
  597. @benefMiddleName = middleName,
  598. @benefLastName = lastName,
  599. @benefPhone = phoneNoP,
  600. @benefEmail = emailP,
  601. @benefCountry = cm.countryName
  602. FROM kycMaster km WITH(NOLOCK)
  603. LEFT JOIN countryMaster cm WITH(NOLOCK) ON cm.countryId = km.countryP
  604. WHERE remitCardNo = @ReceiverRemitCardNo
  605. SELECT
  606. @customerId = customerId
  607. FROM customerMaster WITH(NOLOCK) WHERE membershipId = @ReceiverRemitCardNo
  608. SELECT @pCountry = 'Nepal'
  609. SELECT @sCountry = 'Nepal'
  610. SELECT @pCountryId = '151'
  611. SELECT @sCountryId = '151'
  612. --## Start Bonus Point
  613. IF (ISNULL(@customerId, 0) <> 0)
  614. BEGIN
  615. DECLARE @maxPointsPerTxn INT, @bonusSchemeId INT, @bonusUnit INT, @bonusPoint INT
  616. SELECT @bonusSchemeId = bonusId
  617. ,@maxPointsPerTxn = maxPointsPerTxn
  618. FROM dbo.FNAGetBonusSetupDetail(@sCountryId, @sAgent, @sBranch, @pCountryId, '')
  619. SELECT @bonusUnit = unit, @bonusPoint = points FROM bonusOperationSetup WITH(NOLOCK) WHERE bonusSchemeId = @bonusSchemeId
  620. IF @bonusSchemeId IS NOT NULL
  621. BEGIN
  622. DECLARE @txnBonusPoint FLOAT
  623. SET @txnBonusPoint = @tAmt * (CAST(@bonusPoint AS FLOAT)/CAST(@bonusUnit AS FLOAT))
  624. SET @txnBonusPoint = CASE WHEN @txnBonusPoint > ISNULL(@maxPointsPerTxn, 0) THEN ISNULL(@maxPointsPerTxn, 0) ELSE ISNULL(@txnBonusPoint, 0) END
  625. UPDATE customerMaster SET
  626. bonusPointPending = ISNULL(bonusPointPending, 0) + @txnBonusPoint
  627. ,bonusTxnCount = ISNULL(bonusTxnCount, 0) + 1
  628. ,bonusTxnAmount = ISNULL(bonusTxnAmount, 0) + @tAmt
  629. WHERE customerId = @customerId
  630. END
  631. END
  632. BEGIN TRANSACTION
  633. INSERT INTO remitTran
  634. (
  635. controlNo,
  636. serviceCharge,
  637. sAgentComm,
  638. pMessage,
  639. sCountry,
  640. sSuperAgent,
  641. sSuperAgentName,
  642. sAgent,
  643. sAgentName,
  644. sBranch,
  645. sBranchName,
  646. pCountry,
  647. pSuperAgent,
  648. pSuperAgentName,
  649. pAgent,
  650. pAgentName,
  651. pBranch,
  652. pBranchName,
  653. pState,
  654. pDistrict,
  655. pLocation,
  656. collCurr,
  657. tAmt,
  658. cAmt,
  659. pAmt,
  660. payoutCurr,
  661. purposeOfRemit,
  662. sourceOfFund,
  663. tranStatus,
  664. payStatus,
  665. paymentMethod,
  666. createdDate,
  667. createdDateLocal,
  668. createdBy,
  669. approvedDate,
  670. approvedDateLocal,
  671. approvedBy,
  672. paidDate,
  673. paidDateLocal,
  674. paidBy,
  675. tranType,
  676. senderName,
  677. receiverName,
  678. bonusPoint,
  679. holdTranId,
  680. accountNo,
  681. controlNo2
  682. )
  683. SELECT
  684. @controlNoEncrypted,
  685. serviceCharge,
  686. sAgentComm,
  687. remarks,
  688. 'Nepal',
  689. sSuperAgent,
  690. sSuperAgentName,
  691. sAgent,
  692. sAgentName,
  693. sBranch,
  694. sBranchName,
  695. 'Nepal',
  696. '1002',
  697. 'INTERNATIONAL MONEY EXPRESS (IME) PVT. LTD',
  698. '20733',
  699. 'GIBL Remit Card',
  700. '20733',
  701. 'GIBL Remit Card',
  702. 'Bagmati',
  703. 'Kathmandu',
  704. '137',
  705. collCurr,
  706. tAmt,
  707. cAmt,
  708. tAmt,
  709. payoutCurr,
  710. purposeOfRemit,
  711. sourceOfFund,
  712. 'Paid',
  713. 'Paid',
  714. 'IME Remit Card',
  715. GETDATE(),
  716. DBO.FNAGetDateInNepalTZ(),
  717. @user,
  718. GETDATE(),
  719. DBO.FNAGetDateInNepalTZ(),
  720. @user,
  721. GETDATE(),
  722. DBO.FNAGetDateInNepalTZ(),
  723. @user,
  724. 'D',
  725. senderName,
  726. benefName,
  727. @bonusPoint,
  728. @id,
  729. benefAcNo,
  730. refNo
  731. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  732. SET @tranId = SCOPE_IDENTITY()
  733. INSERT INTO tranReceivers
  734. (
  735. tranId
  736. ,customerId
  737. ,membershipId
  738. ,firstName
  739. ,middleName
  740. ,lastName1
  741. ,country
  742. ,[address]
  743. ,email
  744. ,homePhone
  745. ,mobile
  746. ,nativeCountry
  747. ,idType
  748. ,idNumber
  749. )
  750. SELECT
  751. @tranId
  752. ,@customerId
  753. ,@ReceiverRemitCardNo
  754. ,@benefFirstName
  755. ,@benefMiddleName
  756. ,@benefLastName
  757. ,@benefCountry
  758. ,benefAddress
  759. ,@benefEmail
  760. ,@benefPhone
  761. ,benefMobile
  762. ,@benefCountry
  763. ,benefIdType
  764. ,benefIdNo
  765. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  766. IF @senderRemitCardNo IS NOT NULL
  767. BEGIN
  768. SELECT
  769. @senderFirstName = firstName,
  770. @senderMiddleName = middleName,
  771. @senderLastName = lastName,
  772. @senderPhone = phoneNoP,
  773. @senderCountry = cm.countryName,
  774. @senderEmail = emailP
  775. FROM kycMaster km WITH(NOLOCK)
  776. LEFT JOIN countryMaster cm WITH(NOLOCK) ON cm.countryId = km.countryP
  777. WHERE RemitCardNo = @senderRemitCardNo
  778. SELECT
  779. @customerId = customerId
  780. FROM customerMaster WITH(NOLOCK) WHERE membershipId = @senderRemitCardNo
  781. INSERT INTO tranSenders
  782. (
  783. tranId
  784. ,customerId
  785. ,membershipId
  786. ,firstName
  787. ,middleName
  788. ,lastName1
  789. ,country
  790. ,[address]
  791. ,email
  792. ,homePhone
  793. ,mobile
  794. ,nativeCountry
  795. ,idType
  796. ,idNumber
  797. )
  798. SELECT
  799. @tranId
  800. ,@customerId
  801. ,@senderRemitCardNo
  802. ,@senderFirstName
  803. ,@senderMiddleName
  804. ,@senderLastName
  805. ,@senderCountry
  806. ,benefAddress
  807. ,@senderEmail
  808. ,@senderPhone
  809. ,senderMobile
  810. ,@senderCountry
  811. ,senderIdType
  812. ,senderIdNo
  813. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  814. END
  815. ELSE
  816. BEGIN
  817. INSERT INTO tranSenders
  818. (
  819. tranId
  820. ,firstName
  821. ,[address]
  822. ,mobile
  823. ,idType
  824. ,idNumber
  825. ,ipAddress
  826. ,dcInfo
  827. )
  828. SELECT
  829. @tranId
  830. ,senderName
  831. ,senderAddress
  832. ,senderMobile
  833. ,senderIdType
  834. ,senderIdNo
  835. ,ipAddress
  836. ,dcInfo
  837. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  838. END
  839. EXEC FastMoneyPro_account.dbo.[PROC_REMIT_DATA_UPDATE]
  840. @flag = 's'
  841. ,@controlNo = @controlNo
  842. ,@mapCode = @mapCodeDom
  843. ,@sFirstName = @sFullName
  844. ,@rFirstName = @rFullName
  845. ,@cAmt = @cAmt
  846. ,@pAmt = @pAmt
  847. ,@serviceCharge = @serviceCharge
  848. ,@sAgentComm = @sAgentComm
  849. ,@pAgentComm = 0
  850. ,@deliveryMethod = 'Bank Deposit'
  851. ,@user = @user
  852. ,@tranId = @tranId
  853. EXEC FastMoneyPro_account.dbo.PROC_REMIT_DATA_UPDATE
  854. @flag = 'p'
  855. ,@mapCode = '20733'
  856. ,@user = @user
  857. ,@pAgentComm = 0
  858. ,@controlNo = @controlNo
  859. DELETE FROM globalCardServiceHistory WHERE id = @id
  860. IF @@TRANCOUNT > 0
  861. COMMIT TRANSACTION
  862. EXEC [proc_errorHandler] 0, 'Transaction has been sent successfully.', @controlNo
  863. END
  864. --## send unpaid (unapproved customer)
  865. IF @flag='su'
  866. BEGIN
  867. IF @user IS NULL
  868. BEGIN
  869. UPDATE globalCardServiceHistory SET tranStatus='sendError' WHERE id = @id
  870. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  871. RETURN
  872. END
  873. --SET @controlNo = '7' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9) + 'D'
  874. --SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  875. SET @controlNo = CAST(@id AS VARCHAR(10))+ 'D'
  876. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  877. SELECT
  878. @ReceiverRemitCardNo = remitCardNo,
  879. @senderRemitCardNo = senderRemitCardNo,
  880. @sBranch = sBranch,
  881. @tAmt = tAmt,
  882. @rFullName = benefName,
  883. @sFullName = senderName,
  884. @serviceCharge = serviceCharge,
  885. @pAmt = tAmt,
  886. @cAmt = cAmt,
  887. @sAgentComm = sAgentComm,
  888. @mapCodeDom = am.mapCodeDom
  889. FROM globalCardServiceHistory gh WITH(NOLOCK)
  890. INNER JOIN agentMaster am WITH(NOLOCK) ON gh.sBranch = am.agentId
  891. WHERE gh.id = @id
  892. SELECT
  893. @benefFirstName = firstName,
  894. @benefMiddleName = middleName,
  895. @benefLastName = lastName,
  896. @benefPhone = phoneNoP,
  897. @benefEmail = emailP,
  898. @benefCountry = cm.countryName
  899. FROM kycMaster km WITH(NOLOCK)
  900. LEFT JOIN countryMaster cm WITH(NOLOCK) ON cm.countryId = km.countryP
  901. WHERE remitCardNo = @ReceiverRemitCardNo
  902. SELECT
  903. @customerId = customerId
  904. FROM customerMaster WITH(NOLOCK) WHERE membershipId = @ReceiverRemitCardNo
  905. SELECT @pCountry = 'Nepal'
  906. SELECT @sCountry = 'Nepal'
  907. SELECT @pCountryId = '151'
  908. SELECT @sCountryId = '151'
  909. --## Start Bonus Point
  910. IF (ISNULL(@customerId, 0) <> 0)
  911. BEGIN
  912. SELECT @bonusSchemeId = bonusId
  913. ,@maxPointsPerTxn = maxPointsPerTxn
  914. FROM dbo.FNAGetBonusSetupDetail(@sCountryId, @sAgent, @sBranch, @pCountryId, '')
  915. SELECT @bonusUnit = unit, @bonusPoint = points FROM bonusOperationSetup WITH(NOLOCK) WHERE bonusSchemeId = @bonusSchemeId
  916. IF @bonusSchemeId IS NOT NULL
  917. BEGIN
  918. SET @txnBonusPoint = @tAmt * (CAST(@bonusPoint AS FLOAT)/CAST(@bonusUnit AS FLOAT))
  919. SET @txnBonusPoint = CASE WHEN @txnBonusPoint > ISNULL(@maxPointsPerTxn, 0) THEN ISNULL(@maxPointsPerTxn, 0) ELSE ISNULL(@txnBonusPoint, 0) END
  920. UPDATE customerMaster SET
  921. bonusPointPending = ISNULL(bonusPointPending, 0) + @txnBonusPoint
  922. ,bonusTxnCount = ISNULL(bonusTxnCount, 0) + 1
  923. ,bonusTxnAmount = ISNULL(bonusTxnAmount, 0) + @tAmt
  924. WHERE customerId = @customerId
  925. END
  926. END
  927. BEGIN TRANSACTION
  928. INSERT INTO remitTran
  929. (
  930. controlNo,
  931. serviceCharge,
  932. sAgentComm,
  933. pMessage,
  934. sCountry,
  935. sSuperAgent,
  936. sSuperAgentName,
  937. sAgent,
  938. sAgentName,
  939. sBranch,
  940. sBranchName,
  941. collCurr,
  942. tAmt,
  943. cAmt,
  944. pAmt,
  945. payoutCurr,
  946. purposeOfRemit,
  947. sourceOfFund,
  948. tranStatus,
  949. payStatus,
  950. paymentMethod,
  951. createdDate,
  952. createdDateLocal,
  953. createdBy,
  954. approvedDate,
  955. approvedDateLocal,
  956. approvedBy,
  957. tranType,
  958. senderName,
  959. receiverName,
  960. bonusPoint,
  961. holdTranId,
  962. accountNo
  963. )
  964. SELECT
  965. @controlNoEncrypted,
  966. serviceCharge,
  967. sAgentComm,
  968. remarks,
  969. 'Nepal',
  970. sSuperAgent,
  971. sSuperAgentName,
  972. sAgent,
  973. sAgentName,
  974. sBranch,
  975. sBranchName,
  976. collCurr,
  977. tAmt,
  978. cAmt,
  979. tAmt,
  980. payoutCurr,
  981. purposeOfRemit,
  982. sourceOfFund,
  983. 'Payment',
  984. 'Unpaid',
  985. 'IME Remit Card',
  986. GETDATE(),
  987. DBO.FNAGetDateInNepalTZ(),
  988. @user,
  989. GETDATE(),
  990. DBO.FNAGetDateInNepalTZ(),
  991. @user,
  992. 'D',
  993. senderName,
  994. benefName,
  995. @bonusPoint,
  996. @id,
  997. benefAcNo
  998. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  999. SET @tranId = SCOPE_IDENTITY()
  1000. INSERT INTO tranReceivers
  1001. (
  1002. tranId
  1003. ,customerId
  1004. ,membershipId
  1005. ,firstName
  1006. ,middleName
  1007. ,lastName1
  1008. ,country
  1009. ,[address]
  1010. ,email
  1011. ,homePhone
  1012. ,mobile
  1013. ,nativeCountry
  1014. ,idType
  1015. ,idNumber
  1016. )
  1017. SELECT
  1018. @tranId
  1019. ,@customerId
  1020. ,@ReceiverRemitCardNo
  1021. ,@benefFirstName
  1022. ,@benefMiddleName
  1023. ,@benefLastName
  1024. ,@benefCountry
  1025. ,benefAddress
  1026. ,@benefEmail
  1027. ,@benefPhone
  1028. ,benefMobile
  1029. ,@benefCountry
  1030. ,benefIdType
  1031. ,benefIdNo
  1032. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  1033. IF @senderRemitCardNo IS NOT NULL
  1034. BEGIN
  1035. SELECT
  1036. @senderFirstName = firstName,
  1037. @senderMiddleName = middleName,
  1038. @senderLastName = lastName,
  1039. @senderPhone = phoneNoP,
  1040. @senderCountry = cm.countryName,
  1041. @senderEmail = emailP
  1042. FROM kycMaster km WITH(NOLOCK)
  1043. LEFT JOIN countryMaster cm WITH(NOLOCK) ON cm.countryId = km.countryP
  1044. WHERE RemitCardNo = @senderRemitCardNo
  1045. SELECT
  1046. @customerId = customerId
  1047. FROM customerMaster WITH(NOLOCK) WHERE membershipId = @senderRemitCardNo
  1048. INSERT INTO tranSenders
  1049. (
  1050. tranId
  1051. ,customerId
  1052. ,membershipId
  1053. ,firstName
  1054. ,middleName
  1055. ,lastName1
  1056. ,country
  1057. ,[address]
  1058. ,email
  1059. ,homePhone
  1060. ,mobile
  1061. ,nativeCountry
  1062. ,idType
  1063. ,idNumber
  1064. )
  1065. SELECT
  1066. @tranId
  1067. ,@customerId
  1068. ,@senderRemitCardNo
  1069. ,@senderFirstName
  1070. ,@senderMiddleName
  1071. ,@senderLastName
  1072. ,@senderCountry
  1073. ,senderAddress
  1074. ,@senderEmail
  1075. ,@senderPhone
  1076. ,senderMobile
  1077. ,@senderCountry
  1078. ,senderIdType
  1079. ,senderIdNo
  1080. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  1081. END
  1082. ELSE
  1083. BEGIN
  1084. INSERT INTO tranSenders
  1085. (
  1086. tranId
  1087. ,firstName
  1088. ,[address]
  1089. ,mobile
  1090. ,idType
  1091. ,idNumber
  1092. ,ipAddress
  1093. ,dcInfo
  1094. )
  1095. SELECT
  1096. @tranId
  1097. ,senderName
  1098. ,senderAddress
  1099. ,senderMobile
  1100. ,senderIdType
  1101. ,senderIdNo
  1102. ,ipAddress
  1103. ,dcInfo
  1104. FROM globalCardServiceHistory WITH(NOLOCK) WHERE id = @id
  1105. END
  1106. EXEC FastMoneyPro_account.dbo.[PROC_REMIT_DATA_UPDATE]
  1107. @flag = 's'
  1108. ,@controlNo = @controlNo
  1109. ,@mapCode = @mapCodeDom
  1110. ,@sFirstName = @sFullName
  1111. ,@rFirstName = @rFullName
  1112. ,@cAmt = @cAmt
  1113. ,@pAmt = @pAmt
  1114. ,@serviceCharge = @serviceCharge
  1115. ,@sAgentComm = @sAgentComm
  1116. ,@pAgentComm = 0
  1117. ,@deliveryMethod = 'Bank Deposit'
  1118. ,@user = @user
  1119. ,@tranId = @tranId
  1120. UPDATE globalCardServiceHistory SET tranStatus='Unpaid' WHERE id = @id
  1121. IF @@TRANCOUNT > 0
  1122. COMMIT TRANSACTION
  1123. EXEC [proc_errorHandler] 0, 'Transaction has been sent successfully, Waiting for approval. Please contact Head Office.', @controlNo
  1124. END
  1125. END TRY
  1126. BEGIN CATCH
  1127. IF @@TRANCOUNT > 0
  1128. ROLLBACK TRANSACTION
  1129. DECLARE @errorMessage VARCHAR(MAX)
  1130. SET @errorMessage = ERROR_MESSAGE()
  1131. EXEC proc_errorHandler 1, @errorMessage, @sBranch
  1132. END CATCH
  1133. GO