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.

669 lines
23 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_payTranHo] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_payTranHo]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_payTranHo] 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_payTranHo] (
  12. @flag VARCHAR(50)
  13. ,@controlNo VARCHAR(20) = NULL
  14. ,@user VARCHAR(30) = NULL
  15. ,@agentRefId VARCHAR(20) = NULL
  16. ,@payTokenId VARCHAR(20) = NULL
  17. ,@tranId INT = NULL
  18. ,@sAgentName VARCHAR(200) = NULL
  19. ,@txnDate DATETIME = NULL
  20. ,@sFirstName VARCHAR(30) = NULL
  21. ,@sMiddleName VARCHAR(30) = NULL
  22. ,@sLastName1 VARCHAR(30) = NULL
  23. ,@sLastName2 VARCHAR(30) = NULL
  24. ,@sMemId VARCHAR(30) = NULL
  25. ,@sId BIGINT = NULL
  26. ,@sCountry VARCHAR(50) = NULL
  27. ,@sAddress VARCHAR(100) = NULL
  28. ,@sCity VARCHAR(50) = NULL
  29. ,@sMobile VARCHAR(20) = NULL
  30. ,@sTranId VARCHAR(50) = NULL
  31. ,@rFirstName VARCHAR(30) = NULL
  32. ,@rMiddleName VARCHAR(30) = NULL
  33. ,@rLastName1 VARCHAR(30) = NULL
  34. ,@rLastName2 VARCHAR(30) = NULL
  35. ,@rMemId VARCHAR(30) = NULL
  36. ,@rId BIGINT = NULL
  37. ,@rCountry VARCHAR(50) = NULL
  38. ,@rAddress VARCHAR(100) = NULL
  39. ,@rCity VARCHAR(50) = NULL
  40. ,@rMobile VARCHAR(20) = NULL
  41. ,@rIdType VARCHAR(30) = NULL
  42. ,@rIdNumber VARCHAR(30) = NULL
  43. ,@rPlaceOfIssue VARCHAR(50) = NULL
  44. ,@rIssuedDate DATETIME = NULL
  45. ,@rValidDate DATETIME = NULL
  46. ,@rRelationType VARCHAR(50) = NULL
  47. ,@rRelativeName VARCHAR(100) = NULL
  48. ,@payoutAmt MONEY = NULL
  49. ,@payoutCurr VARCHAR(3) = NULL
  50. ,@paymentType VARCHAR(30) = NULL
  51. ,@sLocation INT = NULL
  52. ,@pLocation INT = NULL
  53. ,@msgType CHAR(1) = NULL
  54. ,@pBranch INT = NULL
  55. ,@customerId INT = NULL
  56. ,@sortBy VARCHAR(50) = NULL
  57. ,@sortOrder VARCHAR(5) = NULL
  58. ,@pageSize INT = NULL
  59. ,@pageNumber INT = NULL
  60. )
  61. AS
  62. DECLARE
  63. @select_field_list VARCHAR(MAX)
  64. ,@extra_field_list VARCHAR(MAX)
  65. ,@table VARCHAR(MAX)
  66. ,@sql_filter VARCHAR(MAX)
  67. SET NOCOUNT ON
  68. SET XACT_ABORT ON
  69. SELECT @pageSize = 1000, @pageNumber = 1
  70. DECLARE
  71. @sBranch INT
  72. ,@pSuperAgent INT
  73. ,@pSuperAgentName VARCHAR(100)
  74. ,@pAgent INT
  75. ,@pAgentName VARCHAR(100)
  76. ,@pBranchName VARCHAR(100)
  77. ,@pCountry VARCHAR(100)
  78. ,@pState VARCHAR(100)
  79. ,@pDistrict VARCHAR(100)
  80. ,@deliveryMethod VARCHAR(100)
  81. ,@tAmt MONEY
  82. ,@cAmt MONEY
  83. ,@pAmt MONEY
  84. ,@serviceCharge MONEY
  85. ,@pAgentComm MONEY
  86. ,@pAgentCommCurrency VARCHAR(3)
  87. ,@pSuperAgentComm MONEY
  88. ,@pSuperAgentCommCurrency VARCHAR(3)
  89. ,@pHubComm MONEY
  90. ,@pHubCommCurrency VARCHAR(3)
  91. ,@collMode INT
  92. ,@sendingCustType INT
  93. ,@receivingCurrency INT
  94. ,@senderId INT
  95. ,@payoutMethod INT
  96. ,@agentType INT
  97. ,@actAsBranchFlag CHAR(1)
  98. ,@tokenId BIGINT
  99. ,@controlNoEncrypted VARCHAR(20)
  100. ,@agentLocation INT
  101. DECLARE
  102. @settlingAgent INT
  103. ,@pCountryId INT
  104. SELECT @controlNoEncrypted = dbo.FNAEncryptString(UPPER(@controlNo))
  105. IF @flag = 'details'
  106. BEGIN
  107. SELECT
  108. trn.id
  109. ,dbo.FNADecryptString(trn.controlNo)
  110. ,sMemId = sen.membershipId
  111. ,sCustomerId = sen.customerId
  112. ,senderName = sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, '')
  113. ,sCountryName = sen.country
  114. ,sStateName = sen.state
  115. ,sCity = sen.city
  116. ,sAddress = sen.address
  117. ,rMemId = rec.membershipId
  118. ,rCustomerId = rec.customerId
  119. ,receiverName = rec.firstName + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, '')
  120. ,rCountryName = rec.country
  121. ,rStateName = rec.state
  122. ,rCity = rec.city
  123. ,rAddress = rec.address
  124. ,rIdType = rci.idType
  125. ,rIdNumber = rci.idNumber
  126. ,rPlaceOfIssue = rci.placeOfIssue
  127. ,rIssuedDate = rci.issuedDate
  128. ,rValidDate = rci.validDate
  129. ,sAgentCountry = trn.sCountry
  130. ,relationship = trn.relWithSender
  131. ,purpose = trn.purposeOfRemit
  132. ,trn.pAmt
  133. ,collMode = trn.collMode
  134. ,paymentMethod = trn.paymentMethod
  135. ,trn.payoutCurr
  136. ,sAgent = trn.sAgentName
  137. ,trn.tranStatus
  138. ,trn.payStatus
  139. ,pMessage = ISNULL(trn.pMessage, '-')
  140. FROM remitTran trn WITH(NOLOCK)
  141. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  142. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  143. LEFT JOIN customerIdentity rci WITH(NOLOCK) ON rec.customerId = rci.customerId
  144. WHERE trn.controlNo = @controlNoEncrypted
  145. END
  146. ELSE IF @flag = 'paySearch' --Pay Search Local
  147. BEGIN
  148. /*
  149. EXEC proc_payTran @flag = 'paySearch', @user = 'bharat', @controlNo = '91598256530', @agentRefId = 'buruysvr5v5k1pfxxjgfq00f'
  150. */
  151. DECLARE @tranStatus VARCHAR(20) = NULL
  152. SELECT @tranStatus = tranStatus, @tranId = id FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  153. SELECT @agentType = agentType, @pLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  154. IF @agentType = 2903 --Agent
  155. BEGIN
  156. SET @pAgent = @pBranch
  157. END
  158. --Validation Starts----------------------------------------------------------------------------------------------
  159. IF (@tranStatus IS NOT NULL)
  160. BEGIN
  161. INSERT INTO tranViewHistory(
  162. controlNumber
  163. ,tranViewType
  164. ,agentId
  165. ,createdBy
  166. ,createdDate
  167. ,tranId
  168. )
  169. SELECT
  170. @controlNoEncrypted
  171. ,'PAY'
  172. ,@pBranch
  173. ,@user
  174. ,GETDATE()
  175. ,@tranId
  176. SET @payTokenId = SCOPE_IDENTITY()
  177. END
  178. ELSE
  179. BEGIN
  180. EXEC proc_errorHandler 1000, 'No Transaction Found', @controlNoEncrypted
  181. RETURN
  182. END
  183. IF EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND paymentMethod = 'Bank Deposit')
  184. BEGIN
  185. EXEC proc_errorHandler 1, 'Cannot process payment for Payment Type "Bank Deposit"', NULL
  186. RETURN
  187. END
  188. IF (EXISTS(SELECT 'X' FROM remitTran WHERE controlNo = @controlNoEncrypted AND sBranch = @pBranch)
  189. OR EXISTS(SELECT 'X' FROM remitTran WHERE controlNo = @controlNoEncrypted AND sAgent = @pAgent))
  190. BEGIN
  191. EXEC proc_errorHandler 1, 'Cannot process payment for same POS', @tranId
  192. RETURN
  193. END
  194. IF (@tranStatus = 'Paid')
  195. BEGIN
  196. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  197. RETURN
  198. END
  199. IF (@tranStatus = 'Hold')
  200. BEGIN
  201. EXEC proc_errorHandler 1, 'Transaction is hold', @controlNoEncrypted
  202. RETURN
  203. END
  204. IF (@tranStatus = 'Cancel')
  205. BEGIN
  206. EXEC proc_errorHandler 1, 'Transaction is cancelled', @controlNoEncrypted
  207. RETURN
  208. END
  209. IF (@tranStatus = 'CancelRequest')
  210. BEGIN
  211. EXEC proc_errorHandler 1, 'Transaction has been requested for cancel', @controlNoEncrypted
  212. RETURN
  213. END
  214. IF (@tranStatus = 'Lock' )
  215. BEGIN
  216. EXEC proc_errorHandler 1, 'Transaction is locked. Please Contact HO', @controlNoEncrypted
  217. RETURN
  218. END
  219. IF (@tranStatus = 'Block')
  220. BEGIN
  221. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact HO', @controlNoEncrypted
  222. RETURN
  223. END
  224. DECLARE @tranDistrictId INT, @payAgentDistrictId INT
  225. SELECT @payAgentDistrictId = districtId FROM apiLocationMapping WITH(NOLOCK) WHERE apiDistrictCode = @pLocation
  226. SELECT @tranDistrictId = districtId FROM apiLocationMapping WITH(NOLOCK) WHERE apiDistrictCode = (SELECT pLocation FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted)
  227. IF @payAgentDistrictId IS NULL
  228. BEGIN
  229. EXEC proc_errorHandler 1, 'Location not found. Please Contact HO', @controlNo
  230. RETURN
  231. END
  232. IF @tranDistrictId IS NULL
  233. BEGIN
  234. EXEC proc_errorHandler 1, 'Location not found. Please Contact HO', @controlNo
  235. RETURN
  236. END
  237. IF(@tranDistrictId <> @payAgentDistrictId)
  238. BEGIN
  239. EXEC proc_errorHandler 1, 'You are not allowed to pay this TXN. It is not within your district.', @controlNoEncrypted
  240. RETURN
  241. END
  242. EXEC proc_errorHandler 0, 'Transaction Verification Successful', @tranId
  243. --End of Validation--------------------------------------------------------------------------------------------------
  244. --Select payout details----------------------------------------------------------------------------------------------
  245. SELECT
  246. trn.id
  247. ,controlNo = dbo.FNADecryptString(trn.controlNo)
  248. ,sMemId = sen.membershipId
  249. ,sCustomerId = sen.customerId
  250. ,senderName = sen.firstName + ISNULL( ' ' + sen.middleName, '') + ISNULL( ' ' + sen.lastName1, '') + ISNULL( ' ' + sen.lastName2, '')
  251. ,sCountryName = sen.country
  252. ,sStateName = sen.state
  253. ,sDistrict = sen.district
  254. ,sCity = sen.city
  255. ,sAddress = sen.address
  256. ,sContactNo = COALESCE(sen.mobile, sen.homephone, sen.workphone)
  257. ,sIdType = sen.idType
  258. ,sIdNo = sen.idNumber
  259. ,sValidDate = sen.validDate
  260. ,sEmail = sen.email
  261. ,rMemId = rec.membershipId
  262. ,rCustomerId = rec.customerId
  263. ,receiverName = rec.firstName + ISNULL( ' ' + rec.middleName, '') + ISNULL( ' ' + rec.lastName1, '') + ISNULL( ' ' + rec.lastName2, '')
  264. ,rCountryName = rec.country
  265. ,rStateName = rec.state
  266. ,rDistrict = rec.district
  267. ,rCity = rec.city
  268. ,rAddress = rec.address
  269. ,rContactNo = COALESCE(rec.mobile, rec.homephone, rec.workphone)
  270. ,rIdType = rec.idType
  271. ,rIdNo = rec.idNumber
  272. ,sAgent = trn.sBranchName
  273. ,sAgentCountry = sa.agentCountry
  274. ,pBranchName = ISNULL(trn.pBranchName, 'Any')
  275. ,pCountryName = trn.pCountry
  276. ,pStateName = trn.pState
  277. ,pDistrictName = trn.pDistrict
  278. ,pLocationName = pLoc.districtName
  279. ,pAddress = pa.agentAddress
  280. ,trn.tAmt
  281. ,trn.serviceCharge
  282. ,handlingFee = ISNULL(trn.handlingFee, 0)
  283. ,trn.cAmt
  284. ,trn.pAmt
  285. ,relationship = ISNULL(trn.relWithSender, '-')
  286. ,purpose = ISNULL(trn.purposeOfRemit, '-')
  287. ,sourceOfFund = ISNULL(trn.sourceOfFund, '-')
  288. ,trn.pAmt
  289. ,collMode = trn.collMode
  290. ,paymentMethod = trn.paymentMethod
  291. ,trn.payoutCurr
  292. ,trn.tranStatus
  293. ,trn.payStatus
  294. ,payoutMsg = ISNULL(trn.pMessage, '-')
  295. ,send_agent = COALESCE(trn.sBranchName, trn.sAgentName)
  296. ,txn_date = trn.createdDateLocal
  297. ,payTokenId = @payTokenId
  298. FROM remitTran trn WITH(NOLOCK)
  299. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  300. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  301. LEFT JOIN agentMaster sa WITH(NOLOCK) ON trn.sBranch = sa.agentId
  302. LEFT JOIN agentMaster pa WITH(NOLOCK) ON trn.pBranch = pa.agentId
  303. LEFT JOIN api_districtList pLoc WITH(NOLOCK) ON trn.pLocation = pLoc.districtCode
  304. WHERE trn.controlNo = @controlNoEncrypted
  305. --End of Select payout details--------------------------------------------------------------------------------------
  306. --Lock Transaction--------------------------------------------------------------------------------------------------
  307. UPDATE remitTran SET
  308. payTokenId = @payTokenId
  309. ,tranStatus = 'Lock'
  310. ,lockedBy = @user
  311. ,lockedDate = GETDATE()
  312. ,lockedDateLocal = dbo.FNADateFormatTZ(GETDATE(), @user)
  313. WHERE controlNo = @controlNoEncrypted
  314. --End of Lock Transaction--------------------------------------------------------------------------------------------
  315. --Log Details-------------------------------------------------------------------------------------------------------
  316. SELECT
  317. message
  318. --,createdBy = au.firstName + ISNULL( ' ' + au.middleName, '') + ISNULL( ' ' + au.lastName, '')
  319. ,trn.createdBy
  320. ,trn.createdDate
  321. FROM tranModifyLog trn WITH(NOLOCK)
  322. LEFT JOIN applicationUsers au WITH(NOLOCK) ON trn.createdBy = au.userName
  323. WHERE trn.tranId = @tranId OR trn.controlNo = @controlNoEncrypted
  324. ORDER BY trn.createdDate DESC
  325. --End of Log Details------------------------------------------------------------------------------------------------
  326. END
  327. ELSE IF @flag = 'payUpdate' --Pay Update Local
  328. BEGIN
  329. IF @user IS NULL
  330. BEGIN
  331. EXEC proc_errorHandler 1, 'Your session has expired. Cannot pay transaction', NULL
  332. RETURN
  333. END
  334. --1.Start of Validation--------------------------------------------------------------------------------------------------
  335. SELECT
  336. @tranStatus = tranStatus
  337. ,@deliveryMethod = paymentMethod
  338. ,@sCountry = sCountry
  339. ,@pLocation = pLocation
  340. ,@tAmt = tAmt
  341. ,@cAmt = cAmt
  342. ,@pAmt = pAmt
  343. ,@serviceCharge = serviceCharge
  344. ,@payoutCurr = payoutCurr
  345. FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  346. IF (@tranStatus = 'CancelRequest')
  347. BEGIN
  348. EXEC proc_errorHandler 1, 'Transaction has been requested for cancel', @controlNoEncrypted
  349. RETURN
  350. END
  351. IF NOT EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND lockedBy = @user AND (payTokenId = @payTokenId OR payTokenId IS NULL))
  352. BEGIN
  353. EXEC proc_errorHandler 1, 'Transaction is locked. Please Contact HO', @controlNoEncrypted
  354. RETURN
  355. END
  356. IF (@tranStatus = 'Block')
  357. BEGIN
  358. EXEC proc_errorHandler 1, 'Transaction is blocked. Please Contact HO', @controlNoEncrypted
  359. RETURN
  360. END
  361. IF (@tranStatus = 'Paid')
  362. BEGIN
  363. EXEC proc_errorHandler 1, 'Transaction has already been paid', @controlNoEncrypted
  364. RETURN
  365. END
  366. IF (@tranStatus = 'Hold')
  367. BEGIN
  368. EXEC proc_errorHandler 1, 'Transaction is hold', @controlNoEncrypted
  369. RETURN
  370. END
  371. IF (@tranStatus = 'Cancel')
  372. BEGIN
  373. EXEC proc_errorHandler 1, 'Transaction is cancelled', @controlNoEncrypted
  374. RETURN
  375. END
  376. DECLARE @userId INT, @payPerTxn MONEY, @payPerDay MONEY, @payTodays MONEY
  377. SELECT @userId = userId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user AND ISNULL(isDeleted, 'N') = 'N'
  378. SELECT @payPerDay = payPerDay, @payPerTxn = payPerTxn, @payTodays = ISNULL(payTodays, 0) FROM userWiseTxnLimit WITH(NOLOCK) WHERE userId = @userId AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  379. IF(@pAmt > @payPerTxn)
  380. BEGIN
  381. EXEC proc_errorHandler 1, 'Transfer Amount exceeds user per Pay Transaction Limit.', @controlNoEncrypted
  382. RETURN
  383. END
  384. IF(@payTodays > @payPerDay)
  385. BEGIN
  386. EXEC proc_errorHandler 1, 'User Per Day Pay Transaction Limit exceeded.', @controlNoEncrypted
  387. RETURN
  388. END
  389. SELECT @agentType = agentType, @agentLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  390. IF @agentType = 2903 --Agent
  391. BEGIN
  392. SET @pAgent = @pBranch
  393. END
  394. SELECT @payAgentDistrictId = districtId FROM apiLocationMapping WHERE apiDistrictCode = @agentLocation
  395. SELECT @tranDistrictId = districtId FROM apiLocationMapping WHERE apiDistrictCode = @pLocation
  396. IF @payAgentDistrictId IS NULL
  397. BEGIN
  398. EXEC proc_errorHandler 1, 'Location not found. Please Contact HO', @controlNo
  399. RETURN
  400. END
  401. IF @tranDistrictId IS NULL
  402. BEGIN
  403. EXEC proc_errorHandler 1, 'Location not found. Please Contact HO', @controlNo
  404. RETURN
  405. END
  406. IF(@tranDistrictId <> @payAgentDistrictId)
  407. BEGIN
  408. EXEC proc_errorHandler 1, 'You are not allowed to pay this TXN. It is not within your district.', @controlNoEncrypted
  409. RETURN
  410. END
  411. IF EXISTS(SELECT 'X' FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted AND sBranch = @pBranch)
  412. BEGIN
  413. EXEC proc_errorHandler 1, 'Cannot process for same POS', @controlNoEncrypted
  414. RETURN
  415. END
  416. --End Of Validation-----------------------------------------------------------------------------------------------
  417. --2.Find Sending Agent and Payout Agent Details-------------------------------------------------------------------
  418. SELECT
  419. @pCountry = agentCountry
  420. ,@pState = agentState
  421. ,@pDistrict = agentDistrict
  422. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  423. --Sending Agent
  424. SELECT @sBranch = sBranch FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  425. IF @sBranch IS NULL
  426. SELECT @sBranch = sAgent FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  427. SELECT @sLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  428. --Payout
  429. SELECT @agentType = agentType, @pBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  430. --Check for Branch or Agent Acting as Branch
  431. IF @agentType = 2903 --Agent
  432. BEGIN
  433. SET @pAgent = @pBranch
  434. END
  435. ELSE
  436. BEGIN
  437. SELECT @pAgent = parentId, @pBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  438. END
  439. SELECT @pSuperAgent = parentId, @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  440. SELECT @pSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pSuperAgent
  441. --End of Find Sending Agent and Payout Agent Details------------------------------------------------------------
  442. --Check Sending List From Table dbo.rsList----------------------------------------------------------------------
  443. --IF EXISTS(SELECT 'X' FROM rsList WITH(NOLOCK)
  444. -- WHERE agentId = @pBranch
  445. -- AND rsAgentId = @sBranch
  446. -- AND agentRole = 's'
  447. -- AND listType = 'ex'
  448. -- AND ISNULL(isDeleted, 'N') <> 'Y'
  449. -- AND ISNULL(isActive, 'Y') = 'Y')
  450. --BEGIN
  451. -- EXEC proc_errorHandler 1, 'You are not allowed to pay this transaction', NULL
  452. -- RETURN
  453. --END
  454. --IF NOT EXISTS(SELECT 'X' FROM rsList WITH(NOLOCK)
  455. -- WHERE agentId = @pBranch
  456. -- AND rsAgentId = @sBranch
  457. -- AND agentRole = 's'
  458. -- AND listType = 'in'
  459. -- AND ISNULL(isDeleted, 'N') <> 'Y'
  460. -- AND ISNULL(isActive, 'Y') = 'Y')
  461. --BEGIN
  462. -- EXEC proc_errorHandler 1, 'You are not allowed to pay this transaction', NULL
  463. -- RETURN
  464. --END
  465. --End of Checking Sending List------------------------------------------------------------------------------------
  466. --3.Find Settlement Agent-----------------------------------------------------------------------------------------
  467. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @pBranch AND isSettlingAgent = 'Y'
  468. IF @settlingAgent IS NULL
  469. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @pAgent AND isSettlingAgent = 'Y'
  470. IF @settlingAgent IS NULL
  471. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @pSuperAgent AND isSettlingAgent = 'Y'
  472. --End of Find Settlement Agent-------------------------------------------------------------------------------
  473. --4.Commission Calculation Start-------------------------------------------------------------------------------
  474. DECLARE @deliveryMethodId INT
  475. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N' AND typeTitle = @deliveryMethod
  476. IF @sCountry = 'Nepal'
  477. BEGIN
  478. DECLARE @commissionCheck MONEY
  479. SELECT
  480. @pAgentComm = ISNULL(pAgentComm, 0)
  481. ,@pSuperAgentComm = ISNULL(psAgentComm, 0)
  482. ,@commissionCheck = pAgentComm
  483. FROM dbo.FNAGetDomesticPayComm(@sBranch, @pBranch, @deliveryMethodId, @tAmt)
  484. SELECT @pAgentCommCurrency = 'NPR', @pSuperAgentCommCurrency = 'NPR'
  485. END
  486. ELSE
  487. BEGIN
  488. DECLARE @sCountryId INT
  489. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @pCountry
  490. SELECT @sCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @sCountry
  491. --SELECT @pHubComm = ISNULL(amount, 0), @pHubCommCurrency = commissionCurrency FROM dbo.FNAGetPayCommHub(@sBranch, @sCountryId, @sLocation, @pSuperAgent, @pCountryId, @pLocation, @pBranch, @payoutCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, 0, 0)
  492. SELECT @pSuperAgentComm = ISNULL(amount, 0), @pSuperAgentCommCurrency = commissionCurrency
  493. FROM dbo.FNAGetPayCommSA(@sBranch, @sCountryId, @sLocation, @pSuperAgent, @pCountryId, @pLocation, @pBranch, @payoutCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, @pHubComm, 0)
  494. SELECT @pAgentComm = ISNULL(amount, 0), @commissionCheck = amount, @pAgentCommCurrency = commissionCurrency
  495. FROM dbo.FNAGetPayComm(@sBranch, @sCountryId, @sLocation, @pSuperAgent, @pCountryId, @pLocation, @pBranch, @payoutCurr, @deliveryMethodId, @cAmt,
  496. @pAmt, @serviceCharge, @pHubComm, @pSuperAgentComm)
  497. END
  498. IF @commissionCheck IS NULL
  499. BEGIN
  500. EXEC proc_errorHandler 1, 'Pay Commission has not been defined', NULL
  501. RETURN
  502. END
  503. --Commission Calculation End---------------------------------------------------------------------------------
  504. BEGIN TRANSACTION
  505. --5.Update Transaction Record----------------------------------------------------------------------------
  506. UPDATE remitTran SET
  507. pAgentComm = @pAgentComm
  508. ,pAgentCommCurrency = @pAgentCommCurrency
  509. ,pSuperAgentComm = @pSuperAgentComm
  510. ,pSuperAgentCommCurrency = @pSuperAgentCommCurrency
  511. ,pHubComm = @pHubComm
  512. ,pHubCommCurrency = @pHubCommCurrency
  513. ,pBranch = @pBranch
  514. ,pBranchName = @pBranchName
  515. ,pAgent = @pAgent
  516. ,pAgentName = @pAgentName
  517. ,pSuperAgent = @pSuperAgent
  518. ,pSuperAgentName = @pSuperAgentName
  519. ,pCountry = @pCountry
  520. ,pState = @pState
  521. ,pDistrict = @pDistrict
  522. ,tranStatus = 'Paid'
  523. ,payStatus = 'Paid'
  524. ,paidDate = GETDATE()
  525. ,paidDateLocal = DBO.FNADateFormatTZ(GETDATE(), @user)
  526. ,paidBy = @user
  527. WHERE controlNo = @controlNoEncrypted
  528. ------End of Update Transaction Record------------------------------------------------------------------
  529. --6.Update receiver identification details--------------------------------------------------------------
  530. SELECT @tranId = id FROM remitTran WITH(NOLOCK) WHERE controlNo = @controlNoEncrypted
  531. UPDATE tranReceivers SET
  532. idType2 = @rIdType
  533. ,idNumber2 = @rIdNumber
  534. ,issuedDate2 = @rIssuedDate
  535. ,validDate2 = @rValidDate
  536. ,idPlaceOfIssue2 = @rPlaceOfIssue
  537. ,mobile = @rMobile
  538. ,relationType = @rRelationType
  539. ,relativeName = @rRelativeName
  540. WHERE tranId = @tranId
  541. --SELECT
  542. -- @customerId = customerId
  543. --FROM remitTran trn WITH(NOLOCK)
  544. --LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  545. --WHERE trn.controlNo = @controlNoEncrypted
  546. --UPDATE customerIdentity SET
  547. -- idType = ISNULL(@rIdType, idType)
  548. -- ,idNumber = ISNULL(@rIdNumber, idNumber)
  549. -- ,issuedDate = ISNULL(@rIssuedDate, issuedDate)
  550. -- ,validDate = ISNULL(@rValidDate, validDate)
  551. -- ,placeOfIssue = ISNULL(@rPlaceOfIssue, placeOfIssue)
  552. --WHERE customerId = @customerId AND ISNULL(isDeleted, 'N') <> 'Y' AND isPrimary = 'Y'
  553. ---End of Update receiver identification details-------------------------------------------------------
  554. --7.A/C Master----------------------------------------------------------------------------------------------
  555. EXEC proc_updatePayTopUpLimit @settlingAgent, @pAmt
  556. UPDATE userWiseTxnLimit SET
  557. payTodays = ISNULL(payTodays, 0) + @pAmt
  558. WHERE userId = @userId AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'Y'
  559. --UPDATE ac_master SET
  560. -- system_reserved_amt = ISNULL(system_reserved_amt, 0) - ISNULL(@payoutAmt, 0)
  561. --WHERE agent_id = @settlingAgent AND gl_code = 1
  562. --End Of A/C Master-----------------------------------------------------------------------------------------
  563. ---##### PROCEDURE FOR PAID TANSACTIO EOD
  564. --EXEC proc_paidEODRemit @USER, @tranId
  565. IF @@TRANCOUNT > 0
  566. COMMIT TRANSACTION
  567. --8.Accounting Server---------------------------------------------------------------------------------------
  568. --SELECT * FROM [192.168.1.234].IME_TEST.dbo.[REMIT_TRN_LOCAL]
  569. DECLARE @mapCodeDom VARCHAR(20)
  570. SELECT @mapCodeDom = mapCodeDom FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  571. EXEC FastMoneyPro_account.dbo.PROC_REMIT_DATA_UPDATE
  572. @flag = 'p'
  573. ,@mapCode = @mapCodeDom
  574. ,@user = @user
  575. ,@pAgentComm = @pAgentComm
  576. ,@controlNo = @controlNo
  577. /*
  578. UPDATE [192.168.1.234].IME_TEST.dbo.[REMIT_TRN_LOCAL] SET
  579. R_BRANCH = @mapCodeDom
  580. ,R_AGENT = @mapCodeDom
  581. ,paidBy = @user
  582. ,P_DATE = GETDATE()
  583. ,PAY_STATUS = 'Paid'
  584. ,TRN_STATUS = 'Paid'
  585. ,R_SC = @pAgentComm
  586. WHERE TRN_REF_NO = dbo.encryptDbLocal(@controlNo)
  587. */
  588. EXEC [proc_errorHandler] 0, 'Transaction has been paid successfully', @controlNoEncrypted
  589. END
  590. GO