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.

797 lines
46 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_icPayHistory] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE proc [dbo].[proc_icPayHistory] (
  9. @flag VARCHAR(50)
  10. ,@user VARCHAR(50)
  11. ,@rowId BIGINT = NULL
  12. ------------ IC Pay parameters -----------
  13. ,@ICTC_Number VARCHAR(100) = NULL
  14. ,@Agent_OrderNumber VARCHAR(100) = NULL
  15. ,@Remitter_Name VARCHAR(100) = NULL
  16. ,@Remitter_Address VARCHAR(100) = NULL
  17. ,@Remitter_IDType VARCHAR(100) = NULL
  18. ,@Remitter_IDDtl VARCHAR(100) = NULL
  19. ,@Originating_Country VARCHAR(100) = NULL
  20. ,@Delivery_Mode VARCHAR(100) = NULL
  21. ,@Paying_Amount VARCHAR(100) = NULL
  22. ,@PayingAgent_CommShare VARCHAR(100) = NULL
  23. ,@Paying_Currency VARCHAR(100) = NULL
  24. ,@Paying_Agent VARCHAR(100) = NULL
  25. ,@Paying_AgentName VARCHAR(100) = NULL
  26. ,@Beneficiary_Name VARCHAR(100) = NULL
  27. ,@Beneficiary_Address VARCHAR(100) = NULL
  28. ,@Beneficiary_City VARCHAR(100) = NULL
  29. ,@Destination_Country VARCHAR(100) = NULL
  30. ,@Beneficiary_TelNo VARCHAR(100) = NULL
  31. ,@Beneficiary_MobileNo VARCHAR(100) = NULL
  32. ,@Expected_BenefID VARCHAR(100) = NULL
  33. ,@Bank_Address VARCHAR(100) = NULL
  34. ,@Bank_Account_Number VARCHAR(100) = NULL
  35. ,@Bank_Name VARCHAR(100) = NULL
  36. ,@Purpose_Remit VARCHAR(100) = NULL
  37. ,@Message_PayeeBranch VARCHAR(100) = NULL
  38. ,@Bank_BranchCode VARCHAR(100) = NULL
  39. ,@Settlement_Rate VARCHAR(100) = NULL
  40. ,@PrinSettlement_Amount VARCHAR(100) = NULL
  41. ,@Transaction_SentDate VARCHAR(100) = NULL
  42. ---------------------END--------------------------
  43. ,@payConfirmationNo VARCHAR(100) = NULL
  44. ,@apiStatus VARCHAR(100) = NULL
  45. ,@payResponseCode VARCHAR(20) = NULL
  46. ,@payResponseMsg VARCHAR(100) = NULL
  47. ,@recordStatus VARCHAR(50) = NULL
  48. ,@tranPayProcess VARCHAR(20) = NULL
  49. ,@createdDate DATETIME = NULL
  50. ,@createdBy VARCHAR(30) = NULL
  51. ,@paidDate DATETIME = NULL
  52. ,@paidBy VARCHAR(30) = NULL
  53. ,@pBranch INT = NULL
  54. ,@pBranchName VARCHAR(100) = NULL
  55. ,@pAgent INT = NULL
  56. ,@pAgentName VARCHAR(100) = NULL
  57. ,@rIdType VARCHAR(30) = NULL
  58. ,@rIdNumber VARCHAR(30) = NULL
  59. ,@rIdPlaceOfIssue VARCHAR(50) = NULL
  60. ,@rIssuedDate DATETIME = NULL
  61. ,@rValidDate DATETIME = NULL
  62. ,@rDob DATETIME = NULL
  63. ,@rAddress VARCHAR(100) = NULL
  64. ,@rOccupation VARCHAR(100) = NULL
  65. ,@rContactNo VARCHAR(50) = NULL
  66. ,@rCity VARCHAR(100) = NULL
  67. ,@rNativeCountry VARCHAR(100) = NULL
  68. ,@relationType VARCHAR(50) = NULL
  69. ,@relativeName VARCHAR(100) = NULL
  70. ,@remarks VARCHAR(500) = NULL
  71. ,@approveBy VARCHAR(30) = NULL
  72. ,@approvePwd VARCHAR(100) = NULL
  73. ,@sCountry VARCHAR(100) = NULL
  74. ,@agentName VARCHAR(100) = NULL
  75. ,@provider VARCHAR(100) = NULL
  76. ,@sortBy VARCHAR(50) = NULL
  77. ,@sortOrder VARCHAR(5) = NULL
  78. ,@pageSize INT = NULL
  79. ,@pageNumber INT = NULL
  80. ,@customerId INT = NULL
  81. ,@membershipId INT = NULL
  82. ,@rbankName VARCHAR(50) = NULL
  83. ,@rbankBranch VARCHAR(100) = NULL
  84. ,@rcheque VARCHAR(50) = NULL
  85. ,@rAccountNo VARCHAR(50) = NULL
  86. ,@topupMobileNo varchar(50) = null
  87. ,@relationship VARCHAR(100) = NULL
  88. ,@purpose VARCHAR(100) = NULL
  89. )
  90. AS
  91. SET XACT_ABORT ON
  92. BEGIN TRY
  93. DECLARE
  94. @sql VARCHAR(MAX)
  95. ,@table VARCHAR(MAX)
  96. ,@select_field_list VARCHAR(MAX)
  97. ,@extra_field_list VARCHAR(MAX)
  98. ,@sql_filter VARCHAR(MAX)
  99. ,@modType VARCHAR(6)
  100. ,@oldAgent INT
  101. ,@ApprovedFunctionId VARCHAR(8)
  102. IF @flag = 'a'
  103. BEGIN
  104. SELECT TOP 1
  105. rowId
  106. ,[controlNo] = dbo.FNADecryptString(ic.ICTC_Number)
  107. ,[sCountry] = ic.Originating_Country
  108. ,[sName] = ic.Remitter_Name
  109. ,[sAddress] = ISNULL(ic.Remitter_Address,'')
  110. ,[sIdType] = ic.Remitter_IDType
  111. ,[sIdNumber] = ic.Remitter_IDDtl
  112. ,[rCountry] = ic.Destination_Country
  113. ,[rName] = ic.Beneficiary_Name
  114. ,[rAddress] = ic.rAddress
  115. ,[rCity] = ic.rCity
  116. ,[rPhone] = ISNULL(ic.Beneficiary_TelNo,'')
  117. ,[rIdType] = ic.rIdType
  118. ,[rIdNumber] = ic.rIdNumber
  119. ,[pAmt] = ic.Paying_Amount
  120. ,[pCurr] = ic.Paying_Currency
  121. ,[pBranch] = am.agentName
  122. ,[pUser] = ic.createdBy
  123. FROM icPayHistory ic WITH(NOLOCK)
  124. INNER JOIN agentMaster am WITH(NOLOCK) ON ic.pBranch = am.agentId
  125. WHERE recordStatus <> ('DRAFT') AND ICTC_Number = dbo.FNAEncryptString(@ICTC_Number)
  126. ORDER BY rowId DESC
  127. RETURN
  128. END
  129. IF @flag = 'i'
  130. BEGIN
  131. IF EXISTS (SELECT 'x' FROM icPayHistory WITH(NOLOCK) WHERE ICTC_Number = dbo.FNAEncryptString(@ICTC_Number))
  132. BEGIN
  133. UPDATE icPayHistory SET
  134. recordStatus = 'EXPIRED'
  135. WHERE ICTC_Number = dbo.FNAEncryptString(@ICTC_Number) AND recordStatus <> 'READYTOPAY'
  136. END
  137. IF @pBranch IS NULL
  138. SELECT @pBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  139. IF @pBranch = '1001'
  140. BEGIN
  141. EXEC [proc_errorHandler] 1, 'Payout branch is missing.', @rowId
  142. RETURN;
  143. END
  144. INSERT INTO icPayHistory (
  145. ICTC_Number
  146. ,Agent_OrderNumber
  147. ,Remitter_Name
  148. ,Remitter_Address
  149. ,Remitter_IDType
  150. ,Remitter_IDDtl
  151. ,Originating_Country
  152. ,Delivery_Mode
  153. ,Paying_Amount
  154. ,PayingAgent_CommShare
  155. ,Paying_Currency
  156. ,Paying_Agent
  157. ,Paying_AgentName
  158. ,Beneficiary_Name
  159. ,Beneficiary_Address
  160. ,Beneficiary_City
  161. ,Destination_Country
  162. ,Beneficiary_TelNo
  163. ,Beneficiary_MobileNo
  164. ,Expected_BenefID
  165. ,Bank_Address
  166. ,Bank_Account_Number
  167. ,Bank_Name
  168. ,Purpose_Remit
  169. ,Message_PayeeBranch
  170. ,Bank_BranchCode
  171. ,Settlement_Rate
  172. ,PrinSettlement_Amount
  173. ,Transaction_SentDate
  174. ,apiStatus
  175. ,recordStatus
  176. ,pBranch
  177. ,createdDate
  178. ,createdBy )
  179. SELECT
  180. dbo.FNAencryptString(@ICTC_Number)
  181. ,@Agent_OrderNumber
  182. ,@Remitter_Name
  183. ,@Remitter_Address
  184. ,CASE
  185. WHEN @Remitter_IDType = '11' THEN 'Passport'
  186. WHEN @Remitter_IDType IN('6', '06') THEN 'Driving License'
  187. WHEN @Remitter_IDType IN('9','09') THEN 'Labour Card'
  188. WHEN @Remitter_IDType = '15' THEN 'State Id'
  189. WHEN @Remitter_IDType = '18' THEN 'Alien Registration'
  190. WHEN @Remitter_IDType = '99' THEN 'Other'
  191. ELSE @Remitter_IDType
  192. END --@Remitter_IDType
  193. ,@Remitter_IDDtl
  194. ,@Originating_Country
  195. ,@Delivery_Mode
  196. ,@Paying_Amount
  197. ,@PayingAgent_CommShare
  198. ,@Paying_Currency
  199. ,@Paying_Agent
  200. ,@Paying_AgentName
  201. ,@Beneficiary_Name
  202. ,@Beneficiary_Address
  203. ,@Beneficiary_City
  204. ,@Destination_Country
  205. ,@Beneficiary_TelNo
  206. ,@Beneficiary_MobileNo
  207. ,@Expected_BenefID
  208. ,@Bank_Address
  209. ,@Bank_Account_Number
  210. ,@Bank_Name
  211. , CASE
  212. WHEN @Purpose_Remit IN ('1', '01') THEN 'Family Maintenance'
  213. WHEN @Purpose_Remit IN ('2', '02') THEN 'Tourism'
  214. WHEN @Purpose_Remit IN ('3', '03') THEN 'Education'
  215. WHEN @Purpose_Remit IN ('4', '04') THEN 'Medical'
  216. ELSE @Purpose_Remit
  217. END --@Purpose_Remit
  218. ,@Message_PayeeBranch
  219. ,@Bank_BranchCode
  220. ,@Settlement_Rate
  221. ,@PrinSettlement_Amount
  222. ,@Transaction_SentDate
  223. ,@apiStatus
  224. ,'DRAFT'
  225. ,@pBranch
  226. ,GETDATE()
  227. ,@user
  228. SET @rowId = SCOPE_IDENTITY()
  229. EXEC [proc_errorHandler] 0, 'Transaction Has Been Saved Successfully', @rowId
  230. RETURN
  231. END
  232. IF @flag = 'readyToPay'
  233. BEGIN
  234. --IF NOT EXISTS(SELECT 'X' FROM applicationUsers WITH(NOLOCK) WHERE pwd = DBO.FNAEncryptString(@approvePwd) AND userName = @user)
  235. --BEGIN
  236. -- EXEC proc_errorHandler 1, 'TXN password is invalid !', @user
  237. -- RETURN
  238. --END
  239. --alter table icPayHistory add topupMobileNo varchar(20)
  240. --alter table icPayHistory add customerId bigint,membershipId varchar(50)
  241. UPDATE icPayHistory SET
  242. recordStatus = 'READYTOPAY'
  243. ,pBranch = ISNULL(@pBranch ,pBranch)
  244. ,rIdType = @rIdType
  245. ,rIdNumber = @rIdNumber
  246. ,rIdPlaceOfIssue = @rIdPlaceOfIssue
  247. ,rValidDate = @rValidDate
  248. ,rDob = @rDob
  249. ,rAddress = @rAddress
  250. ,rCity = @rCity
  251. ,rOccupation = @rOccupation
  252. ,rContactNo = @rContactNo
  253. ,nativeCountry = @rNativeCountry
  254. ,remarks = @remarks
  255. ,rBank = @rbankName
  256. ,rBankBranch = @rbankBranch
  257. ,rAccountNo = @rAccountNo
  258. ,rChequeNo = @rcheque
  259. ,topupMobileNo = @topupMobileNo
  260. ,customerId = @customerId
  261. ,membershipId = @membershipId
  262. ,relWithSender = @relationship
  263. ,purposeOfRemit = @purpose
  264. ,rIssueDate = @rIssuedDate
  265. WHERE rowId = @rowId
  266. EXEC [proc_errorHandler] 0, 'Ready to pay has been recorded successfully.', @rowId
  267. RETURN
  268. END
  269. IF @flag = 'payError'
  270. BEGIN
  271. UPDATE icPayHistory SET
  272. recordStatus = 'PAYERROR'
  273. ,payResponseCode = @payResponseCode
  274. ,payResponseMsg = @payResponseMsg
  275. WHERE rowId = @rowId
  276. EXEC [proc_errorHandler] 0, 'Pay error has been recorded successfully.', @rowId
  277. RETURN
  278. END
  279. IF @flag IN ('pay', 'restore')
  280. BEGIN
  281. IF NOT EXISTS(
  282. SELECT 'x' FROM icPayHistory WITH(NOLOCK)
  283. WHERE recordStatus IN('READYTOPAY', 'PAYERROR', 'PAID')
  284. AND rowid = @rowid )
  285. BEGIN
  286. EXEC proc_errorHandler 1, 'Transaction Not Found!', @rowid
  287. RETURN
  288. END
  289. DECLARE
  290. @tranId BIGINT
  291. ,@tranIdTemp BIGINT
  292. ,@pSuperAgent INT
  293. ,@pSuperAgentName VARCHAR(100)
  294. ,@pCountry VARCHAR(100)
  295. ,@pState VARCHAR(100)
  296. ,@pDistrict VARCHAR(100)
  297. ,@pLocation INT
  298. ,@pAgentComm MONEY
  299. ,@pAgentCommCurrency VARCHAR(3)
  300. ,@pSuperAgentComm MONEY
  301. ,@pSuperAgentCommCurrency VARCHAR(3)
  302. ,@sAgent INT
  303. ,@sAgentName VARCHAR(100)
  304. ,@sBranch INT
  305. ,@sBranchName VARCHAR(100)
  306. ,@sSuperAgent INT
  307. ,@sSuperAgentName VARCHAR(100)
  308. ,@sAgentMapCode INT = 33200000
  309. ,@sBranchMapCode INT = 33200100
  310. ,@bankName VARCHAR(100) = NULL
  311. ,@purposeOfRemit VARCHAR(100) = NULL
  312. ,@pBankBranch VARCHAR(100) = NULL
  313. ,@sAgentSettRate VARCHAR(100) = NULL
  314. ,@agentType INT
  315. ,@payoutMethod VARCHAR(50)
  316. ,@cAmt MONEY
  317. ,@beneIdNo INT
  318. ,@customerRate MONEY
  319. ,@payoutCurr VARCHAR(50)
  320. ,@collCurr VARCHAR(50)
  321. ,@MapCodeIntBranch VARCHAR(50)
  322. ,@MapCodeIntAgent VARCHAR(50)
  323. ,@MapAgentName VARCHAR(50)
  324. ,@companyId INT = 16
  325. ,@controlNo VARCHAR(50)
  326. SELECT
  327. @ICTC_Number = ic.ICTC_Number
  328. ,@Agent_OrderNumber = ic.Agent_OrderNumber
  329. ,@Remitter_Name = ic.Remitter_Name
  330. ,@Remitter_Address = ic.Remitter_Address
  331. ,@Remitter_IDType = ic.Remitter_IDType
  332. ,@Remitter_IDDtl = ic.Remitter_IDDtl
  333. ,@Originating_Country = ic.Originating_Country
  334. ,@Delivery_Mode = ic.Delivery_Mode
  335. ,@Paying_Amount = ic.Paying_Amount
  336. ,@PayingAgent_CommShare = ic.PayingAgent_CommShare
  337. ,@Paying_Currency = ic.Paying_Currency
  338. ,@Paying_Agent = ic.Paying_Agent
  339. ,@Paying_AgentName = ic.Paying_AgentName
  340. ,@Beneficiary_Name = ic.Beneficiary_Name
  341. ,@Beneficiary_Address = ic.rAddress
  342. ,@Beneficiary_City = ic.rCity
  343. ,@Destination_Country = ic.Destination_Country
  344. ,@Beneficiary_TelNo = ic.rContactNo
  345. ,@Beneficiary_MobileNo = ic.Beneficiary_MobileNo
  346. ,@Expected_BenefID = ic.Expected_BenefID
  347. ,@Bank_Address = ic.Bank_Address
  348. ,@Bank_Account_Number = ic.Bank_Account_Number
  349. ,@Bank_Name = ic.Bank_Name
  350. ,@Purpose_Remit = ic.Purpose_Remit
  351. ,@Message_PayeeBranch = ic.Message_PayeeBranch
  352. ,@Bank_BranchCode = ic.Bank_BranchCode
  353. ,@Settlement_Rate = ic.Settlement_Rate
  354. ,@PrinSettlement_Amount = ic.PrinSettlement_Amount
  355. ,@Transaction_SentDate = ic.Transaction_SentDate
  356. ,@rIdType = ic.rIdType
  357. ,@rIdNumber = ic.rIdNumber
  358. ,@rValidDate = ic.rValidDate
  359. ,@rDob = ic.rDob
  360. ,@rOccupation = ic.rOccupation
  361. ,@rNativeCountry = ic.nativeCountry
  362. ,@pBranch = pBranch
  363. ,@pBranchName = pb.agentName
  364. ,@rbankName = rBank
  365. ,@rbankBranch = rBankBranch
  366. ,@rcheque = rAccountNo
  367. ,@rAccountNo = rChequeNo
  368. ,@topupMobileNo = topupMobileNo
  369. ,@customerId = customerId
  370. ,@membershipId = membershipId
  371. ,@purpose = purposeOfRemit
  372. ,@relationship = relWithSender
  373. ,@rIssuedDate = rIssueDate
  374. FROM icPayHistory ic WITH(NOLOCK)
  375. LEFT JOIN agentMaster pb WITH(NOLOCK) ON ic.pBranch = pb.agentId
  376. WHERE rowId = @rowId
  377. --## Check if controlno exist in remittran.
  378. IF EXISTS( SELECT 'x' FROM remitTran WITH(NOLOCK) WHERE controlNo = @ICTC_Number)
  379. BEGIN
  380. DECLARE @status VARCHAR(100),@msg VARCHAR(100)
  381. SELECT
  382. @agentName = sAgentName
  383. ,@status = payStatus
  384. FROM remitTran WITH(NOLOCK) WHERE controlNo = @ICTC_Number
  385. SET @msg = 'This transaction belongs to ' + @agentName + ' and is in status: ' + @status
  386. EXEC proc_errorHandler 1,@msg,NULL
  387. RETURN
  388. END
  389. --## Set paying agent details.
  390. SELECT
  391. @pAgent = parentId,
  392. @pBranchName = agentName,
  393. @agentType = agentType,
  394. @pCountry = agentCountry,
  395. @pState = agentState,
  396. @pDistrict = agentDistrict,
  397. @pLocation = agentLocation,
  398. @MapCodeIntBranch=mapCodeInt
  399. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  400. IF @agentType = 2903
  401. SET @pAgent = @pBranch
  402. SELECT @sBranch = bm.agentId,
  403. @sAgent = am.agentId,
  404. @sBranchName = bm.agentName,
  405. @sAgentName = am.agentName
  406. FROM agentMaster bm WITH(NOLOCK) inner join agentMaster am with(nolock) on bm.parentId = am.agentId
  407. WHERE bm.agentId = 4817
  408. SELECT @sSuperAgent = '4641',
  409. @sSuperAgentName = 'INTERNATIONAL AGENTS'
  410. --## 2. Find Payout Agent Details
  411. SELECT @pSuperAgent = parentId
  412. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  413. SELECT @pSuperAgentname = agentNAME
  414. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pSuperAgent
  415. --## 3. Find Commission
  416. DECLARE @sCountryId INT, @deliveryMethodId INT, @pCommCheck MONEY
  417. SELECT @sCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @sCountry
  418. if @sCountryId is null
  419. select @sCountryId = agentCountryId from agentMaster with(nolock) where agentId = @sBranch
  420. SET @payoutMethod = 'Cash Payment'
  421. DECLARE @pCountryId INT = NULL
  422. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @pCountry
  423. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK)
  424. WHERE typeTitle = @payoutMethod AND ISNULL(isDeleted, 'N') = 'N'
  425. SELECT @pSuperAgentComm = 0, @pSuperAgentCommCurrency = 'NPR'
  426. SELECT @pAgentComm = ISNULL(amount, 0),
  427. @pCommCheck = amount,
  428. @pAgentCommCurrency = commissionCurrency,
  429. @pCommCheck = amount
  430. FROM dbo.FNAGetPayComm(@sBranch, @sCountryId, NULL, @pSuperAgent, 151,
  431. @pLocation, @pBranch, 'NPR', @deliveryMethodId, NULL, @Paying_Amount, NULL, NULL, NULL)
  432. IF @pCommCheck IS NULL
  433. BEGIN
  434. EXEC proc_errorHandler 1, 'Payout Commission not defined', NULL
  435. RETURN
  436. END
  437. -------Compliance Check Begin----------
  438. -- Thirdparty txn doesn't have tranid. Hence, temp tranid is created for compliance checking process. Later on this will replace by actual tranId.
  439. SELECT @tranIdTemp = ABS(CAST(CRYPT_GEN_RANDOM(8) AS BIGINT))
  440. IF NOT EXISTS(SELECT 'X' FROM remitTranCompliancePay WITH(NOLOCK) WHERE tranId = @tranIdTemp AND approvedDate IS NOT NULL)
  441. BEGIN
  442. DECLARE @csMasterId INT, @complianceRes VARCHAR(20), @totalRows INT, @count INT, @compFinalRes VARCHAR(20), @result VARCHAR(MAX),@complianceAction CHAR(1),
  443. @compApproveRemark VARCHAR(200)
  444. DECLARE @csMasterRec TABLE (rowId INT IDENTITY(1,1), masterId INT)
  445. INSERT @csMasterRec(masterId)
  446. SELECT masterId FROM dbo.FNAGetComplianceRuleMaster_Pay(@pBranch, @pCountryId, NULL, @pBranch, NULL, NULL, @customerId)
  447. SELECT @totalRows = COUNT(*) FROM @csMasterRec
  448. DECLARE @denyTxn CHAR(1) = 'N'
  449. IF EXISTS(SELECT 'X' FROM @csMasterRec)
  450. BEGIN
  451. DELETE FROM remitTranCompliancePayTemp WHERE tranId = @tranIdTemp
  452. SET @count = 1
  453. WHILE(@count <= @totalRows)
  454. BEGIN
  455. SELECT @csMasterId = masterId FROM @csMasterRec WHERE rowId = @count
  456. EXEC proc_complianceRuleDetail_Pay
  457. @user = @user
  458. ,@tranId = @tranIdTemp
  459. ,@tAmt = @Paying_Amount
  460. ,@customerId = @customerId
  461. ,@receiverId = @rIdNumber
  462. ,@receiverMemId = @membershipId
  463. ,@receiverName = @Beneficiary_Name
  464. ,@receiverMobile = @rContactNo
  465. ,@receiverAcNo = @rAccountNo
  466. ,@masterId = @csMasterId
  467. ,@paymentMethod = @deliveryMethodId
  468. ,@checkingFor = 'v'
  469. ,@result = @complianceRes OUTPUT
  470. SET @compFinalRes = ISNULL(@compFinalRes, '') + ISNULL(@complianceRes, '')
  471. IF @complianceRes = 'M' AND ISNULL(@complianceAction, '') <> 'C'
  472. SET @complianceAction = 'M'
  473. IF @complianceRes = 'C'
  474. SET @complianceAction = 'C'
  475. SET @count = @count + 1
  476. END
  477. END
  478. IF(ISNULL(@compFinalRes, '') <> '')
  479. BEGIN
  480. IF(@compFinalRes <> '')
  481. BEGIN
  482. IF EXISTS(SELECT 'X' FROM remitTranCompliancePayTemp WITH(NOLOCK) WHERE tranId = @tranIdTemp)
  483. BEGIN
  484. INSERT INTO remitTranCompliancePay(tranId, csDetailTranId, matchTranId)
  485. SELECT @tranIdTemp, csDetailTranId, matchTranId FROM remitTranCompliancePayTemp WITH(NOLOCK) WHERE tranId = @tranIdTemp
  486. --INSERT tranPayCompliance(tranId,provider,controlNo,pBranch,receiverName,rMemId,dob,
  487. --rIdType,rIdNumber,rPlaceOfIssue,rContactNo,rRelationType,rRelativeName,relWithSender,purposeOfRemit,createdBy,createdDate)
  488. --SELECT @tranIdTemp, '4816' , @ICTC_Number,@pBranch,@Beneficiary_Name,@membershipId,@rDob,
  489. --@rIdType,@rIdNumber,@rIdPlaceOfIssue,@rContactNo,@relationType,@relativeName,@relationship,@purpose,@user,GETDATE()
  490. DELETE FROM dbo.remitTranCompliancePayTemp WHERE tranId = @tranIdTemp
  491. END
  492. IF ISNULL(@complianceAction, '') <> ''
  493. BEGIN
  494. --UPDATE remitTran SET
  495. -- tranStatus = 'Hold'
  496. --WHERE id = @tranId
  497. UPDATE remitTranCompliancePay SET
  498. approvedRemarks = 'Marked for Compliance'
  499. ,approvedBy = 'system'
  500. ,approvedDate = GETDATE()
  501. WHERE tranId = @tranIdTemp
  502. --UPDATE tranPayCompliance SET
  503. -- approvedRemarks = 'Marked for Compliance'
  504. -- ,approvedBy = 'system'
  505. -- ,approvedDate = GETDATE()
  506. --WHERE tranId = @tranIdTemp
  507. END
  508. END
  509. END
  510. END
  511. -------Compliance Check End----------
  512. BEGIN TRANSACTION
  513. BEGIN
  514. INSERT INTO remitTran (
  515. [controlNo]
  516. ,[senderName]
  517. ,[sCountry]
  518. ,[sSuperAgent]
  519. ,[sSuperAgentName]
  520. ,[paymentMethod]
  521. ,[cAmt]
  522. ,[pAmt]
  523. ,[tAmt]
  524. ,[pAgentComm]
  525. ,[payoutCurr]
  526. ,[pAgent]
  527. ,[pAgentName]
  528. ,[pSuperAgent]
  529. ,[pSuperAgentName]
  530. ,[receiverName]
  531. ,[pCountry]
  532. ,[pBranch]
  533. ,[pBranchName]
  534. ,[pState]
  535. ,[pDistrict]
  536. ,[pLocation]
  537. ,[purposeofRemit]
  538. ,[pMessage]
  539. ,[createdDate]
  540. ,[createdDateLocal]
  541. ,[createdBy]
  542. ,[approvedDate]
  543. ,[approvedDateLocal]
  544. ,[approvedBy]
  545. ,[paidBy]
  546. ,[paidDate]
  547. ,[paidDateLocal]
  548. --## hardcoded parameters
  549. ,[tranStatus]
  550. ,[payStatus]
  551. ,[collCurr]
  552. ,[controlNo2]
  553. ,[tranType]
  554. ,[sAgent]
  555. ,[sAgentName]
  556. ,[sBranch]
  557. ,[sBranchName]
  558. ,sCurrCostRate
  559. )
  560. SELECT
  561. @ICTC_Number
  562. ,@Remitter_Name
  563. ,@Originating_Country
  564. ,@sSuperAgent
  565. ,@sSuperAgentName
  566. ,'Cash Payment'
  567. ,ROUND(@Paying_Amount,0)
  568. ,ROUND(@Paying_Amount,0)
  569. ,ROUND(@Paying_Amount,0)
  570. ,@pAgentComm
  571. ,'NPR'
  572. ,@pAgent
  573. ,@pAgentName
  574. ,@pSuperAgent
  575. ,@pSuperAgentName
  576. ,@Beneficiary_Name
  577. ,@pCountry
  578. ,@pBranch
  579. ,@pBranchName
  580. ,@pState
  581. ,@pDistrict
  582. ,@pLocation
  583. ,@purposeOfRemit
  584. ,@remarks
  585. ,GETDATE()
  586. ,GETDATE()
  587. ,'SWIFT:API'
  588. ,GETDATE()
  589. ,GETDATE()
  590. ,'SWIFT:API'
  591. ,@user
  592. ,dbo.FNAGetDateInNepalTZ()
  593. ,dbo.FNAGetDateInNepalTZ()
  594. --## HardCoded Parameters
  595. ,'Paid'
  596. ,'Paid'
  597. ,'NPR'
  598. ,@Agent_OrderNumber
  599. ,'I'
  600. ,@sAgent
  601. ,@sAgentName
  602. ,@sBranch
  603. ,@sBranchName
  604. ,'1'
  605. SET @tranId = SCOPE_IDENTITY()
  606. -- ## insert to TranSenders
  607. INSERT INTO tranSenders (
  608. tranId
  609. ,firstName
  610. ,country
  611. ,[address]
  612. ,homePhone
  613. )
  614. SELECT
  615. @tranId
  616. ,@Remitter_Name
  617. ,@Originating_Country
  618. ,@Remitter_Address
  619. ,''
  620. -- ## insert to TranReceivers
  621. INSERT INTO tranReceivers (
  622. tranId
  623. ,firstName
  624. ,country
  625. ,city
  626. ,[address]
  627. ,homePhone
  628. ,mobile
  629. ,idType
  630. ,idNumber
  631. ,dob
  632. ,occupation
  633. ,validDate
  634. ,bankName
  635. ,branchName
  636. ,chequeNo
  637. ,accountNo
  638. ,workPhone
  639. ,customerId
  640. ,membershipId
  641. ,relWithSender
  642. ,purposeOfRemit
  643. ,issuedDate2
  644. ,validDate2
  645. )
  646. SELECT
  647. @tranId
  648. ,@Beneficiary_Name
  649. ,@Destination_Country
  650. ,@Beneficiary_City
  651. ,@Beneficiary_Address
  652. ,@Beneficiary_MobileNo
  653. ,@Beneficiary_TelNo
  654. ,@rIdType
  655. ,@rIdNumber
  656. ,@rDob
  657. ,@rOccupation
  658. ,@rValidDate
  659. ,@rbankName
  660. ,@rbankBranch
  661. ,@rcheque
  662. ,@raccountNo
  663. ,@topupMobileNo
  664. ,@customerId
  665. ,@membershipId
  666. ,@relationship
  667. ,@purpose
  668. ,@rIssuedDate
  669. ,@rValidDate
  670. UPDATE remitTranCompliancePay SET
  671. tranId = @tranId
  672. WHERE tranId = @tranIdTemp
  673. --UPDATE tranPayCompliance SET
  674. --tranId = @tranId
  675. --WHERE tranId = @tranIdTemp
  676. IF @membershipId IS NOT NULL
  677. BEGIN
  678. UPDATE dbo.customerMaster SET
  679. paidTxn = ISNULL(paidTxn,0)+1,
  680. firstTxnDate = ISNULL(firstTxnDate,GETDATE())
  681. WHERE membershipId = @membershipId
  682. END
  683. -- ## Updating Data in icPayHistory table by paid status
  684. UPDATE icPayHistory SET
  685. recordStatus = 'PAID'
  686. ,tranPayProcess = CASE WHEN @flag = 'Pay' THEN 'REGULAR' ELSE 'RESTORED' END
  687. ,payResponseCode = @payResponseCode
  688. ,payResponseMsg = @payResponseMsg
  689. WHERE rowId = @rowId
  690. /*Topup Information Send SMS*/
  691. IF @membershipId IS NOT NULL
  692. BEGIN
  693. EXEC proc_topupQueue
  694. @flag = 'a'
  695. ,@user = @user
  696. ,@tranId = @tranId
  697. ,@tranType = 'I'
  698. END
  699. -- ## Limit Update
  700. EXEC Proc_AgentBalanceUpdate @flag = 'p',@tAmt = @Paying_Amount ,@settlingAgent = @pBranch
  701. END
  702. IF @@TRANCOUNT > 0
  703. COMMIT TRANSACTION
  704. SET @msg =
  705. CASE
  706. WHEN @flag = 'restore' THEN 'Transaction has been restored successfully'
  707. ELSE 'Transaction paid successfully'
  708. END
  709. EXEC proc_pushToAc @flag= 'i', @controlNoEncrypted = @ICTC_Number
  710. SET @controlNo = dbo.fnadecryptstring(@ICTC_Number)
  711. EXEC [proc_errorHandler] 0, @msg, @controlNo
  712. RETURN
  713. END
  714. END TRY
  715. BEGIN CATCH
  716. IF @@TRANCOUNT > 0
  717. ROLLBACK TRANSACTION
  718. SELECT 1 errorCode, ERROR_MESSAGE() msg, NULL id
  719. END CATCH
  720. GO