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.

1097 lines
63 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_ezPayHistory] 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_ezPayHistory](
  9. @flag VARCHAR(50) = NULL
  10. ,@user VARCHAR(50) = NULL
  11. ,@rowId BIGINT = NULL
  12. ,@TransactionNumber VARCHAR(50) = NULL
  13. ,@SecurityNumber VARCHAR(50) = NULL
  14. ,@TransactionDate VARCHAR(50) = NULL
  15. ,@TypeOfTransaction VARCHAR(50) = NULL
  16. ,@TransactionStatus VARCHAR(50) = NULL
  17. ,@scCustomerName VARCHAR(50) = NULL
  18. ,@scCustomerArabicName VARCHAR(50) = NULL
  19. ,@scCustomerAddress VARCHAR(50) = NULL
  20. ,@scCustomerCardNumber VARCHAR(50) = NULL
  21. ,@scCustID VARCHAR(50) = NULL
  22. ,@scCustIDType VARCHAR(50) = NULL
  23. ,@scCustTelephoneNumber VARCHAR(50) = NULL
  24. ,@scCustMobileNumber VARCHAR(50) = NULL
  25. ,@scCustNationality VARCHAR(50) = NULL
  26. ,@scCustEmail VARCHAR(50) = NULL
  27. ,@sccustDOB VARCHAR(50) = NULL
  28. ,@scCustMessage VARCHAR(50) = NULL
  29. ,@scCustOccupation VARCHAR(50) = NULL
  30. ,@scRelationship VARCHAR(50) = NULL
  31. ,@scCustBankcode VARCHAR(50) = NULL
  32. ,@scCustBankShortname VARCHAR(50) = NULL
  33. ,@scCustBankName VARCHAR(50) = NULL
  34. ,@scCustBankBranchcode VARCHAR(50) = NULL
  35. ,@scCustBankBranchshortname VARCHAR(50) = NULL
  36. ,@scCustBankBranchName VARCHAR(50) = NULL
  37. ,@scBranchAddress VARCHAR(50) = NULL
  38. ,@scContactPerson VARCHAR(50) = NULL
  39. ,@scContactTelephoneNo VARCHAR(50) = NULL
  40. ,@scCustCountryCode VARCHAR(50) = NULL
  41. ,@scCustCountry VARCHAR(50) = NULL
  42. ,@tbName VARCHAR(50) = NULL
  43. ,@tbArabicName VARCHAR(50) = NULL
  44. ,@tbAddress VARCHAR(50) = NULL
  45. ,@tbAccountNumber VARCHAR(50) = NULL
  46. ,@tbIdNumber VARCHAR(50) = NULL
  47. ,@tbIdtype VARCHAR(50) = NULL
  48. ,@tbBenBankName VARCHAR(50) = NULL
  49. ,@tbBenBankBranchName VARCHAR(50) = NULL
  50. ,@tbBankShortName VARCHAR(50) = NULL
  51. ,@tbBankName VARCHAR(50) = NULL
  52. ,@tbBranchShortName VARCHAR(50) = NULL
  53. ,@tbBranchName VARCHAR(50) = NULL
  54. ,@tbBranchAddress VARCHAR(50) = NULL
  55. ,@tbContactPerson VARCHAR(50) = NULL
  56. ,@tbContactTelephoneNo VARCHAR(50) = NULL
  57. ,@tbIBBank VARCHAR(50) = NULL
  58. ,@tbIBBranch VARCHAR(50) = NULL
  59. ,@tbIBAddress VARCHAR(50) = NULL
  60. ,@tbIBBankAccountno VARCHAR(50) = NULL
  61. ,@tbIBBankDiffernt VARCHAR(50) = NULL
  62. ,@tbIBClearingNumber VARCHAR(50) = NULL
  63. ,@tbIBClearingType VARCHAR(50) = NULL
  64. ,@tbIBSwiftCode VARCHAR(50) = NULL
  65. ,@tbTelephoneNumber VARCHAR(50) = NULL
  66. ,@tbMobileNumber VARCHAR(50) = NULL
  67. ,@tbNationality VARCHAR(50) = NULL
  68. ,@tbBenCountry VARCHAR(50) = NULL
  69. ,@tbFundSource VARCHAR(50) = NULL
  70. ,@tbPin VARCHAR(50) = NULL
  71. ,@tbPurpose VARCHAR(50) = NULL
  72. ,@tbSwiftCode VARCHAR(50) = NULL
  73. ,@tbPaymentAgentCode VARCHAR(50) = NULL
  74. ,@tbPaymentAgentCountryCode VARCHAR(50) = NULL
  75. ,@tbPaymentAgentLocationCode VARCHAR(50) = NULL
  76. ,@tbRecipientName VARCHAR(50) = NULL
  77. ,@tbRecipientAddress VARCHAR(50) = NULL
  78. ,@tbRecipientTelephone VARCHAR(50) = NULL
  79. ,@tbRecipientMessage VARCHAR(50) = NULL
  80. ,@tbReceiverComm VARCHAR(50) = NULL
  81. ,@tbTypeOfTransaction VARCHAR(50) = NULL
  82. ,@tdFxAmount VARCHAR(50) = NULL
  83. ,@tdRate VARCHAR(50) = NULL
  84. ,@tdMktRate VARCHAR(50) = NULL
  85. ,@tdLocalAmount VARCHAR(50) = NULL
  86. ,@tdTotalLocalAmount VARCHAR(50) = NULL
  87. ,@tdCommissionAmount VARCHAR(50) = NULL
  88. ,@tdLocalCurrencyCode VARCHAR(50) = NULL
  89. ,@tdFxCurrencyCode VARCHAR(50) = NULL
  90. ,@apiStatus VARCHAR(50) = NULL
  91. ,@payResponseCode VARCHAR(20) = NULL
  92. ,@payResponseMsg VARCHAR(100) = NULL
  93. ,@recordStatus VARCHAR(50) = NULL
  94. ,@tranPayProcess VARCHAR(20) = NULL
  95. ,@createdDate DATETIME = NULL
  96. ,@paidDate DATETIME = NULL
  97. ,@paidBy VARCHAR(30) = NULL
  98. ,@rContactNo VARCHAR(50) = NULL
  99. ,@nativeCountry VARCHAR(100) = NULL
  100. ,@pBranch INT = NULL
  101. ,@rIdType VARCHAR(30) = NULL
  102. ,@rIdNumber VARCHAR(30) = NULL
  103. ,@rIdPlaceOfIssue VARCHAR(50) = NULL
  104. ,@rIssuedDate DATETIME = NULL
  105. ,@rValidDate DATETIME = NULL
  106. ,@rDob DATETIME = NULL
  107. ,@rAddress VARCHAR(100) = NULL
  108. ,@rCity VARCHAR(100) = NULL
  109. ,@rOccupation VARCHAR(100) = NULL
  110. ,@relationType VARCHAR(50) = NULL
  111. ,@relativeName VARCHAR(100) = NULL
  112. ,@remarks VARCHAR(500) = NULL
  113. ,@cAmt VARCHAR(100) = NULL
  114. ,@pAmt VARCHAR(100) = NULL
  115. ,@tAmt VARCHAR(100) = NULL
  116. ,@sCountry VARCHAR(100) = NULL
  117. ,@pCountry VARCHAR(100) = NULL
  118. ,@pBranchName VARCHAR(100) =NULL
  119. ,@agentName VARCHAR(100) = NULL
  120. ,@provider VARCHAR(100) = NULL
  121. ,@sortBy VARCHAR(50) = NULL
  122. ,@sortOrder VARCHAR(5) = NULL
  123. ,@pageSize INT = NULL
  124. ,@pageNumber INT = NULL
  125. ,@controlNo VARCHAR(50) = NULL
  126. ,@customerId VARCHAR(50) = NULL
  127. ,@membershipId VARCHAR(50) = NULL
  128. ,@rbankName VARCHAR(50) = NULL
  129. ,@rbankBranch VARCHAR(100) = NULL
  130. ,@rcheque VARCHAR(50) = NULL
  131. ,@rAccountNo VARCHAR(50) = NULL
  132. ,@topupMobileNo varchar(50) = null
  133. ,@relationship VARCHAR(100) = NULL
  134. ,@purpose VARCHAR(100) = NULL
  135. )AS
  136. SET NOCOUNT ON
  137. SET XACT_ABORT ON
  138. BEGIN TRY
  139. DECLARE
  140. @SecurityNoEnc VARCHAR(50) = dbo.FNAencryptString(@SecurityNumber)
  141. IF @flag = 's'
  142. BEGIN
  143. DECLARE @table VARCHAR(MAX)
  144. ,@sql_filter VARCHAR(MAX)
  145. ,@select_field_list VARCHAR(MAX)
  146. ,@extra_field_list VARCHAR(MAX)
  147. SET @table = '
  148. (
  149. SELECT
  150. rowId=id
  151. ,''EZREMIT Remit'' AS provider
  152. ,am.agentName
  153. ,dbo.FNADecryptString(SecurityNumber) AS xpin
  154. ,customer = ISNULL(scCustomerName, '''')
  155. ,beneficiary = ISNULL(tbName, '''')
  156. ,customerAddress = ISNULL(scCustomerAddress, '''')
  157. ,beneficiaryAddress = ISNULL(tbAddress, '''')
  158. ,payoutAmount = ez.tdFxAmount
  159. ,payoutDate =ez.paidDate
  160. FROM ezPayHistory ez WITH(NOLOCK)
  161. LEFT JOIN agentMaster am WITH(NOLOCK) ON am.agentId = ez.pBranch
  162. WHERE recordStatus NOT IN(''DRAFT'', ''EXPIRED'')
  163. '
  164. IF @SecurityNumber IS NOT NULL
  165. BEGIN
  166. SET @table = @table + ' AND SecurityNumber = ''' + @SecurityNoEnc + ''''
  167. select @pBranch = pBranch,@user = createdBy from ezPayHistory with(nolock)
  168. where SecurityNumber = @SecurityNoEnc
  169. if @pBranch is null and @user is not null
  170. begin
  171. select @pBranch = agentId from applicationUsers with(nolock)
  172. where userName = @user
  173. update ezPayHistory set pBranch = @pBranch
  174. where SecurityNumber = @SecurityNoEnc
  175. end
  176. END
  177. ELSE
  178. BEGIN
  179. SET @table = @table + ' AND tranPayProcess IS NULL'
  180. END
  181. IF @agentName IS NOT NULL
  182. SET @table = @table + ' AND am.agentName LIKE ''' + @agentName + '%'''
  183. SET @table = @table + '
  184. ) x '
  185. SET @sql_filter = ''
  186. IF @provider IS NOT NULL
  187. SET @sql_filter = @sql_filter + ' AND provider LIKE ''' + @provider + '%'''
  188. SET @select_field_list ='
  189. rowId
  190. ,provider
  191. ,agentName
  192. ,xpin
  193. ,customer
  194. ,beneficiary
  195. ,customerAddress
  196. ,beneficiaryAddress
  197. ,payoutAmount
  198. ,payoutDate
  199. '
  200. EXEC dbo.proc_paging
  201. @table
  202. ,@sql_filter
  203. ,@select_field_list
  204. ,@extra_field_list
  205. ,@sortBy
  206. ,@sortOrder
  207. ,@pageSize
  208. ,@pageNumber
  209. RETURN
  210. END
  211. IF @flag='a'
  212. BEGIN
  213. SELECT TOP 100
  214. rowId = ez.id
  215. ,[controlNo] = dbo.FNADecryptString(ez.SecurityNumber)
  216. ,[sCountry] = ez.scCustCountry
  217. ,[sName] = ez.scCustomerName
  218. ,[sAddress] = ISNULL(ez.scCustomerAddress,'')
  219. ,sCity = null
  220. ,sMobile = isnull(ez.scCustTelephoneNumber,'')+isnull(','+ez.scCustMobileNumber,'')
  221. ,sAgentName = 'EZREMIT LTD'
  222. ,sAgent = 4726
  223. ,[rCountry] = 'Nepal'
  224. ,[rName] = ez.tbName
  225. ,[rAddress] = ez.tbAddress
  226. ,[rCity] = isnull(ez.rCity,'')
  227. ,[rPhone] = ISNULL(ez.tbContactTelephoneNo,'')
  228. ,branchId = ez.pBranch
  229. ,[rIdType] = ez.rIdType
  230. ,[rIdNumber] = ez.rIdNumber
  231. ,[pAmt] = ez.tdFxAmount
  232. ,[pCurr] = ez.tdFxCurrencyCode
  233. ,[pBranch] = am.agentName
  234. ,[pUser] = ez.createdBy
  235. ,transactionMode = 'Cash Payment'
  236. ,PlaceOfIssue = rIdPlaceOfIssue
  237. ,rRelativeName = relativeName
  238. ,RelationType = relationType
  239. ,rContactNo = rContactNo
  240. FROM ezPayHistory ez WITH(NOLOCK)
  241. INNER JOIN agentMaster am WITH(NOLOCK) ON ez.pBranch = am.agentId
  242. WHERE recordStatus <> ('DRAFT') AND ez.id = @rowId
  243. ORDER BY id DESC
  244. RETURN
  245. END
  246. IF @flag='i'
  247. BEGIN
  248. IF EXISTS(
  249. SELECT 'x'
  250. FROM ezPayHistory
  251. WHERE SecurityNumber=@SecurityNoEnc
  252. )
  253. BEGIN
  254. UPDATE ezPayHistory SET
  255. recordStatus = 'EXPIRED'
  256. WHERE SecurityNumber= @SecurityNoEnc AND recordStatus <> 'READYTOPAY'
  257. END
  258. IF @pBranch IS NULL
  259. SELECT @pBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  260. IF @pBranch = '1001'
  261. BEGIN
  262. EXEC [proc_errorHandler] 1, 'Payout branch is missing.', @rowId
  263. RETURN;
  264. END
  265. INSERT INTO ezPayHistory(
  266. TransactionNumber
  267. ,SecurityNumber
  268. ,TransactionDate
  269. ,TypeOfTransaction
  270. ,TransactionStatus
  271. ,scCustomerName
  272. ,scCustomerArabicName
  273. ,scCustomerAddress
  274. ,scCustomerCardNumber
  275. ,scCustID
  276. ,scCustIDType
  277. ,scCustTelephoneNumber
  278. ,scCustMobileNumber
  279. ,scCustNationality
  280. ,scCustEmail
  281. ,sccustDOB
  282. ,scCustMessage
  283. ,scCustOccupation
  284. ,scRelationship
  285. ,scCustBankcode
  286. ,scCustBankShortname
  287. ,scCustBankName
  288. ,scCustBankBranchcode
  289. ,scCustBankBranchshortname
  290. ,scCustBankBranchName
  291. ,scBranchAddress
  292. ,scContactPerson
  293. ,scContactTelephoneNo
  294. ,scCustCountryCode
  295. ,scCustCountry
  296. ,tbName
  297. ,tbArabicName
  298. ,tbAddress
  299. ,tbAccountNumber
  300. ,tbIdNumber
  301. ,tbIdtype
  302. ,tbBenBankName
  303. ,tbBenBankBranchName
  304. ,tbBankShortName
  305. ,tbBankName
  306. ,tbBranchShortName
  307. ,tbBranchName
  308. ,tbBranchAddress
  309. ,tbContactPerson
  310. ,tbContactTelephoneNo
  311. ,tbIBBank
  312. ,tbIBBranch
  313. ,tbIBAddress
  314. ,tbIBBankAccountno
  315. ,tbIBBankDiffernt
  316. ,tbIBClearingNumber
  317. ,tbIBClearingType
  318. ,tbIBSwiftCode
  319. ,tbTelephoneNumber
  320. ,tbMobileNumber
  321. ,tbNationality
  322. ,tbBenCountry
  323. ,tbFundSource
  324. ,tbPin
  325. ,tbPurpose
  326. ,tbSwiftCode
  327. ,tbPaymentAgentCode
  328. ,tbPaymentAgentCountryCode
  329. ,tbPaymentAgentLocationCode
  330. ,tbRecipientName
  331. ,tbRecipientAddress
  332. ,tbRecipientTelephone
  333. ,tbRecipientMessage
  334. ,tbReceiverComm
  335. ,tbTypeOfTransaction
  336. ,tdFxAmount
  337. ,tdRate
  338. ,tdMktRate
  339. ,tdLocalAmount
  340. ,tdTotalLocalAmount
  341. ,tdCommissionAmount
  342. ,tdLocalCurrencyCode
  343. ,tdFxCurrencyCode
  344. ,apiStatus
  345. ,payResponseCode
  346. ,payResponseMsg
  347. ,recordStatus
  348. ,tranPayProcess
  349. ,createdDate
  350. ,createdBy
  351. ,paidDate
  352. ,paidBy
  353. ,rContactNo
  354. ,nativeCountry
  355. ,pBranch
  356. ,rIdType
  357. ,rIdNumber
  358. ,rIdPlaceOfIssue
  359. ,rValidDate
  360. ,rDob
  361. ,rAddress
  362. ,rCity
  363. ,rOccupation
  364. ,relationType
  365. ,relativeName
  366. ,remarks
  367. )SELECT
  368. @TransactionNumber
  369. ,@SecurityNoEnc
  370. ,@TransactionDate
  371. ,@TypeOfTransaction
  372. ,@TransactionStatus
  373. ,@scCustomerName
  374. ,@scCustomerArabicName
  375. ,@scCustomerAddress
  376. ,@scCustomerCardNumber
  377. ,@scCustID
  378. ,@scCustIDType
  379. ,@scCustTelephoneNumber
  380. ,@scCustMobileNumber
  381. ,@scCustNationality
  382. ,@scCustEmail
  383. ,@sccustDOB
  384. ,@scCustMessage
  385. ,@scCustOccupation
  386. ,@scRelationship
  387. ,@scCustBankcode
  388. ,@scCustBankShortname
  389. ,@scCustBankName
  390. ,@scCustBankBranchcode
  391. ,@scCustBankBranchshortname
  392. ,@scCustBankBranchName
  393. ,@scBranchAddress
  394. ,@scContactPerson
  395. ,@scContactTelephoneNo
  396. ,@scCustCountryCode
  397. ,@scCustCountry
  398. ,@tbName
  399. ,@tbArabicName
  400. ,@tbAddress
  401. ,@tbAccountNumber
  402. ,@tbIdNumber
  403. ,@tbIdtype
  404. ,@tbBenBankName
  405. ,@tbBenBankBranchName
  406. ,@tbBankShortName
  407. ,@tbBankName
  408. ,@tbBranchShortName
  409. ,@tbBranchName
  410. ,@tbBranchAddress
  411. ,@tbContactPerson
  412. ,@tbContactTelephoneNo
  413. ,@tbIBBank
  414. ,@tbIBBranch
  415. ,@tbIBAddress
  416. ,@tbIBBankAccountno
  417. ,@tbIBBankDiffernt
  418. ,@tbIBClearingNumber
  419. ,@tbIBClearingType
  420. ,@tbIBSwiftCode
  421. ,@tbTelephoneNumber
  422. ,@tbMobileNumber
  423. ,@tbNationality
  424. ,@tbBenCountry
  425. ,@tbFundSource
  426. ,@tbPin
  427. ,@tbPurpose
  428. ,@tbSwiftCode
  429. ,@tbPaymentAgentCode
  430. ,@tbPaymentAgentCountryCode
  431. ,@tbPaymentAgentLocationCode
  432. ,@tbRecipientName
  433. ,@tbRecipientAddress
  434. ,@tbRecipientTelephone
  435. ,@tbRecipientMessage
  436. ,@tbReceiverComm
  437. ,@tbTypeOfTransaction
  438. ,@tdFxAmount
  439. ,@tdRate
  440. ,@tdMktRate
  441. ,@tdLocalAmount
  442. ,@tdTotalLocalAmount
  443. ,@tdCommissionAmount
  444. ,@tdLocalCurrencyCode
  445. ,@tdFxCurrencyCode
  446. ,@apiStatus
  447. ,@payResponseCode
  448. ,@payResponseMsg
  449. ,@recordStatus
  450. ,@tranPayProcess
  451. ,GETDATE()
  452. ,@user
  453. ,@paidDate
  454. ,@paidBy
  455. ,@rContactNo
  456. ,@nativeCountry
  457. ,@pBranch
  458. ,@rIdType
  459. ,@rIdNumber
  460. ,@rIdPlaceOfIssue
  461. ,@rValidDate
  462. ,@rDob
  463. ,@rAddress
  464. ,@rCity
  465. ,@rOccupation
  466. ,@relationType
  467. ,@relativeName
  468. ,@remarks
  469. SET @rowId = SCOPE_IDENTITY()
  470. EXEC [proc_errorHandler] 0, 'Transaction Has Been Saved Successfully', @rowId
  471. RETURN
  472. END
  473. IF @flag='readyToPay'
  474. BEGIN
  475. --alter table ezPayHistory add topupMobileNo varchar(20)
  476. --alter table ezPayHistory add customerId bigint,membershipId varchar(50)
  477. UPDATE ezPayHistory SET
  478. recordStatus = 'READYTOPAY'
  479. ,pBranch = ISNULL(@pBranch,pBranch)
  480. ,rIdType = @rIdType
  481. ,rIdNumber = @rIdNumber
  482. ,rIdPlaceOfIssue = @rIdPlaceOfIssue
  483. ,rValidDate = @rValidDate
  484. ,rDob = @rDob
  485. ,rAddress = @rAddress
  486. ,rCity = @rCity
  487. ,rOccupation = @rOccupation
  488. ,rContactNo = @rContactNo
  489. ,nativeCountry = @nativeCountry
  490. ,relationType = @relationType
  491. ,relativeName = @relativeName
  492. ,remarks = @remarks
  493. ,rBank = @rbankName
  494. ,rBankBranch = @rbankBranch
  495. ,rAccountNo = @rAccountNo
  496. ,rChequeNo = @rcheque
  497. ,topupMobileNo = @topupMobileNo
  498. ,customerId = @customerId
  499. ,membershipId = @membershipId
  500. ,relWithSender = @relationship
  501. ,purposeOfRemit = @purpose
  502. ,rIssueDate = @rIssuedDate
  503. WHERE id = @rowId
  504. EXEC [proc_errorHandler] 0, 'Ready to pay has been recorded successfully.', @rowId
  505. RETURN
  506. END
  507. IF @flag = 'payError'
  508. BEGIN
  509. UPDATE ezPayHistory SET
  510. recordStatus = 'PAYERROR'
  511. ,payResponseCode = @payResponseCode
  512. ,payResponseMsg = @payResponseMsg
  513. WHERE id = @rowId
  514. EXEC [proc_errorHandler] 0, 'Pay error has been recorded successfully.', @rowId
  515. RETURN
  516. END
  517. IF @flag IN('pay','restore')
  518. BEGIN
  519. IF NOT EXISTS(
  520. SELECT 'x' FROM ezPayHistory WITH(NOLOCK)
  521. WHERE recordStatus IN('READYTOPAY','PAYERROR','PAID')
  522. AND id=@rowId
  523. )
  524. BEGIN
  525. declare @ms varchar(100)='Transaction Not Found! '+Convert(varchar(10),@rowId)
  526. EXEC proc_errorHandler 1,@ms,@rowId
  527. END
  528. DECLARE
  529. @pAgent VARCHAR(100)= NULL
  530. ,@agentType VARCHAR(100)= NULL
  531. ,@pState VARCHAR(100)= NULL
  532. ,@pDistrict VARCHAR(100)= NULL
  533. ,@pLocation VARCHAR(100)= NULL
  534. ,@sAgentMapCode INT = '28100000'
  535. ,@sBranchMapCode INT = '28100100'
  536. ,@sBranch VARCHAR(100)= NULL
  537. ,@sAgent VARCHAR(100)= NULL
  538. ,@sBranchName VARCHAR(100)= NULL
  539. ,@pSuperAgent VARCHAR(100)= NULL
  540. ,@pAgentName VARCHAR(100)= NULL
  541. ,@pSuperAgentName VARCHAR(100)= NULL
  542. ,@sSuperAgent VARCHAR(100)= NULL
  543. ,@sAgentName VARCHAR(100)= NULL
  544. ,@sSuperAgentName VARCHAR(100)= NULL
  545. ,@payoutMethod VARCHAR(100)= NULL
  546. ,@pSuperAgentComm VARCHAR(100)= NULL
  547. ,@pSuperAgentCommCurrency VARCHAR(100)= NULL
  548. ,@pAgentComm VARCHAR(100)= NULL
  549. ,@pAgentCommCurrency VARCHAR(100)= NULL
  550. ,@tranId BIGINT = NULL
  551. ,@MapCodeIntBranch VARCHAR(100)= NULL
  552. ,@tranIdTemp BIGINT
  553. SELECT
  554. @TransactionNumber =ez.TypeOfTransaction
  555. ,@SecurityNumber =ez.SecurityNumber
  556. ,@scCustomerName =ez.scCustomerName
  557. ,@scCustomerAddress =ez.scCustomerAddress
  558. ,@scCustID =ez.scCustID
  559. ,@scCustIDType =ez.scCustIDType
  560. ,@scCustTelephoneNumber =ez.scCustTelephoneNumber
  561. ,@scCustCountry =ez.scCustCountry
  562. ,@scCustNationality =ez.scCustNationality
  563. ,@tbName =ez.tbName
  564. ,@tbAddress =ez.tbAddress
  565. ,@tbPurpose =ez.tbPurpose
  566. ,@tbIdNumber =tbIdNumber
  567. ,@tbTelephoneNumber =ez.tbTelephoneNumber
  568. ,@pCountry =ez.tbBenCountry
  569. ,@tbNationality =ez.tbNationality
  570. ,@cAmt = floor(ez.tdFxAmount)
  571. ,@pAmt = floor(ez.tdFxAmount)
  572. ,@tAmt = floor(ez.tdFxAmount)
  573. ,@tdFxAmount = floor(ez.tdFxAmount)
  574. ,@tdTotalLocalAmount = floor(ez.tdFxAmount)
  575. ,@tdFxCurrencyCode =ez.tdFxCurrencyCode
  576. ,@apiStatus =ez.apiStatus
  577. ,@recordStatus =ez.recordStatus
  578. ,@nativeCountry =ez.nativeCountry
  579. ,@pBranch =isnull(@pBranch,ez.pBranch)
  580. ,@rIdType =ez.rIdType
  581. ,@rIdNumber =ez.rIdNumber
  582. ,@rIdPlaceOfIssue =ez.rIdPlaceOfIssue
  583. ,@rValidDate =ez.rValidDate
  584. ,@rDob =ez.rDob
  585. ,@rOccupation =ez.rOccupation
  586. ,@relationType =ez.relationType
  587. ,@relativeName =ez.relativeName
  588. ,@remarks =ez.remarks
  589. ,@rbankName = rBank
  590. ,@rbankBranch = rBankBranch
  591. ,@rcheque = rAccountNo
  592. ,@rAccountNo = rChequeNo
  593. ,@topupMobileNo = topupMobileNo
  594. ,@customerId = customerId
  595. ,@membershipId = membershipId
  596. ,@rContactNo = rContactNo
  597. ,@purpose = purposeOfRemit
  598. ,@relationship = relWithSender
  599. ,@rIssuedDate = rIssueDate
  600. FROM ezPayHistory ez WITH(NOLOCK)
  601. WHERE id=@rowId
  602. SELECT
  603. @pAgent = parentId,
  604. @pBranchName = agentName,
  605. @agentType = agentType,
  606. @pCountry = agentCountry,
  607. @pState = agentState,
  608. @pDistrict = agentDistrict,
  609. @pLocation = agentLocation,
  610. @MapCodeIntBranch=mapCodeInt
  611. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  612. -- ## check for control number if exist in remittran
  613. IF EXISTS(SELECT 'x' from remitTran WITH(NOLOCK) WHERE controlNo=@SecurityNumber)
  614. BEGIN
  615. DECLARE
  616. @status VARCHAR(50)
  617. ,@msg VARCHAR(100)
  618. SELECT
  619. @agentName =sAgentName
  620. ,@status=payStatus
  621. FROM remitTran WITH(NOLOCK)
  622. WHERE controlNo=@SecurityNumber
  623. SET @msg='This transaction belong to '+@agentName+'and is in status:'+@status
  624. EXEC proc_errorHandler 1,@msg,NULL
  625. RETURN
  626. END
  627. -- ## Set Paying agent detail
  628. SELECT
  629. @pAgent = parentId
  630. ,@pBranchName =agentName
  631. ,@agentType =agentType
  632. ,@pCountry =agentCountry
  633. ,@pState =agentState
  634. ,@pDistrict =agentDistrict
  635. ,@pLocation =agentLocation
  636. ,@MapCodeIntBranch =mapCodeInt
  637. FROM agentMaster WITH(NOLOCK) WHERE agentId=@pBranch
  638. IF @agentType = 2903
  639. BEGIN
  640. SET @pAgent = @pBranch
  641. END
  642. -- ## Find sending agent detail
  643. SELECT
  644. @sBranch =agentId
  645. ,@sAgent =parentId
  646. ,@sBranchName =agentName
  647. ,@agentType =agentType
  648. FROM agentMaster WITH(NOLOCK)
  649. WHERE mapCodeInt = @sBranchMapCode AND ISNULL(isDeleted, 'N') = 'N'
  650. IF @agentType = 2903
  651. BEGIN
  652. SET @sAgent = @sBranch
  653. END
  654. SELECT
  655. @sSuperAgent =parentId
  656. ,@sAgentName =agentName
  657. FROM agentMaster WITH(NOLOCK) WHERE agentId=@sAgent
  658. SELECT @sSuperAgentName=agentName
  659. FROM agentMaster WITH(NOLOCK) WHERE agentId=@sSuperAgent
  660. -- ## Find Payout agent Detail
  661. SELECT
  662. @pSuperAgent =parentId
  663. ,@pAgentName =agentName
  664. FROM agentMaster WITH(NOLOCK)WHERE agentId=@pAgent
  665. SELECT @pSuperAgentName=agentName
  666. FROM agentMaster WITH(NOLOCK)WHERE agentId=@pSuperAgent
  667. -- ## Find Commisssion
  668. DECLARE
  669. @sCountryId INT
  670. ,@deliveryMethodId INT
  671. ,@pCommCheck MONEY
  672. select @sCountry =agentCountry,@sCountryId=agentCountryId
  673. from agentMaster where agentCode='4726'
  674. SET @payoutMethod='Cash Payment'
  675. DECLARE @pCountryId INT=NULL
  676. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK)WHERE countryName = @pCountry
  677. SELECT @deliveryMethodId=serviceTypeId
  678. FROM serviceTypeMaster WITH(NOLOCK)
  679. WHERE typeTitle=@payoutMethod AND ISNULL(isDeleted,'N')='N'
  680. SELECT
  681. @pSuperAgentComm =0
  682. ,@pSuperAgentCommCurrency ='NPR'
  683. SELECT
  684. @pAgentComm =ISNULL(amount,0)
  685. ,@pCommCheck =amount
  686. ,@pAgentCommCurrency=commissionCurrency
  687. FROM dbo.FNAGetPayComm(@sBranch,@sCountryId,NULL,@pSuperAgent,151,
  688. @pLocation,@pBranch,'NPR',@deliveryMethodId,NULL,@tdFxAmount,NULL,NULL,NULL)---tdFxAmount is destination amount
  689. IF @pCommCheck IS NULL
  690. BEGIN
  691. EXEC proc_errorHandler 1,'Payout Commission not defined.',NULL
  692. RETURN
  693. END
  694. -------Compliance Check Begin----------
  695. -- Thirdparty txn doesn't have tranid. Hence, temp tranid is created for compliance checking process. Later on this will replace by actual tranId.
  696. SELECT @tranIdTemp = ABS(CAST(CRYPT_GEN_RANDOM(8) AS BIGINT))
  697. IF NOT EXISTS(SELECT 'X' FROM remitTranCompliancePay WITH(NOLOCK) WHERE tranId = @tranIdTemp AND approvedDate IS NOT NULL)
  698. BEGIN
  699. DECLARE @csMasterId INT, @complianceRes VARCHAR(20), @totalRows INT, @count INT, @compFinalRes VARCHAR(20), @result VARCHAR(MAX),@complianceAction CHAR(1),
  700. @compApproveRemark VARCHAR(200)
  701. DECLARE @csMasterRec TABLE (rowId INT IDENTITY(1,1), masterId INT)
  702. INSERT @csMasterRec(masterId)
  703. SELECT masterId FROM dbo.FNAGetComplianceRuleMaster_Pay(@pBranch, @pCountryId, NULL, @pBranch, NULL, NULL, @customerId)
  704. SELECT @totalRows = COUNT(*) FROM @csMasterRec
  705. DECLARE @denyTxn CHAR(1) = 'N'
  706. IF EXISTS(SELECT 'X' FROM @csMasterRec)
  707. BEGIN
  708. DELETE FROM remitTranCompliancePayTemp WHERE tranId = @tranIdTemp
  709. SET @count = 1
  710. WHILE(@count <= @totalRows)
  711. BEGIN
  712. SELECT @csMasterId = masterId FROM @csMasterRec WHERE rowId = @count
  713. EXEC proc_complianceRuleDetail_Pay
  714. @user = @user
  715. ,@tranId = @tranIdTemp
  716. ,@tAmt = @pAmt
  717. ,@customerId = @customerId
  718. ,@receiverId = @rIdNumber
  719. ,@receiverMemId = @membershipId
  720. ,@receiverName = @tbName
  721. ,@receiverMobile = @rContactNo
  722. ,@receiverAcNo = @rAccountNo
  723. ,@masterId = @csMasterId
  724. ,@paymentMethod = @deliveryMethodId
  725. ,@checkingFor = 'v'
  726. ,@result = @complianceRes OUTPUT
  727. SET @compFinalRes = ISNULL(@compFinalRes, '') + ISNULL(@complianceRes, '')
  728. IF @complianceRes = 'M' AND ISNULL(@complianceAction, '') <> 'C'
  729. SET @complianceAction = 'M'
  730. IF @complianceRes = 'C'
  731. SET @complianceAction = 'C'
  732. SET @count = @count + 1
  733. END
  734. END
  735. IF(ISNULL(@compFinalRes, '') <> '')
  736. BEGIN
  737. IF(@compFinalRes <> '')
  738. BEGIN
  739. IF EXISTS(SELECT 'X' FROM remitTranCompliancePayTemp WITH(NOLOCK) WHERE tranId = @tranIdTemp)
  740. BEGIN
  741. INSERT INTO remitTranCompliancePay(tranId, csDetailTranId, matchTranId)
  742. SELECT @tranIdTemp, csDetailTranId, matchTranId FROM remitTranCompliancePayTemp WITH(NOLOCK) WHERE tranId = @tranIdTemp
  743. --INSERT tranPayCompliance(tranId,provider,controlNo,pBranch,receiverName,rMemId,dob,
  744. --rIdType,rIdNumber,rPlaceOfIssue,rContactNo,rRelationType,rRelativeName,relWithSender,purposeOfRemit,createdBy,createdDate)
  745. --SELECT @tranIdTemp, '4726' , @SecurityNumber,@pBranch,@tbName,@membershipId,@rDob,
  746. --@rIdType,@rIdNumber,@rIdPlaceOfIssue,@rContactNo,@relationType,@relativeName,@relationship,@purpose,@user,GETDATE()
  747. DELETE FROM dbo.remitTranCompliancePayTemp WHERE tranId = @tranIdTemp
  748. END
  749. IF ISNULL(@complianceAction, '') <> ''
  750. BEGIN
  751. --UPDATE remitTran SET
  752. -- tranStatus = 'Hold'
  753. --WHERE id = @tranId
  754. UPDATE remitTranCompliancePay SET
  755. approvedRemarks = 'Marked for Compliance'
  756. ,approvedBy = 'system'
  757. ,approvedDate = GETDATE()
  758. WHERE tranId = @tranIdTemp
  759. --UPDATE tranPayCompliance SET
  760. -- approvedRemarks = 'Marked for Compliance'
  761. -- ,approvedBy = 'system'
  762. -- ,approvedDate = GETDATE()
  763. --WHERE tranId = @tranIdTemp
  764. END
  765. END
  766. END
  767. END
  768. -------Compliance Check End----------
  769. BEGIN TRANSACTION
  770. INSERT INTO remitTran (
  771. [controlNo]
  772. ,[senderName]
  773. ,[sCountry]
  774. ,[sSuperAgent]
  775. ,[sSuperAgentName]
  776. ,[paymentMethod]
  777. ,[cAmt]
  778. ,[pAmt]
  779. ,[tAmt]
  780. ,[pAgentComm]
  781. ,[payoutCurr]
  782. ,[pAgent]
  783. ,[pAgentName]
  784. ,[pSuperAgent]
  785. ,[pSuperAgentName]
  786. ,[receiverName]
  787. ,[pCountry]
  788. ,[pBranch]
  789. ,[pBranchName]
  790. ,[pState]
  791. ,[pDistrict]
  792. ,[pLocation]
  793. ,[purposeofRemit]
  794. ,[pMessage]
  795. ,[createdDate]
  796. ,[createdDateLocal]
  797. ,[createdBy]
  798. ,[approvedDate]
  799. ,[approvedDateLocal]
  800. ,[approvedBy]
  801. ,[paidBy]
  802. ,[paidDate]
  803. ,[paidDateLocal]
  804. --## hardcoded parameters
  805. ,[tranStatus]
  806. ,[payStatus]
  807. ,[collCurr]
  808. ,[controlNo2]
  809. ,[tranType]
  810. ,[sAgent]
  811. ,[sAgentName]
  812. ,[sBranch]
  813. ,[sBranchName]
  814. ,[sCurrCostRate]
  815. )SELECT
  816. @SecurityNumber
  817. ,@scCustomerName
  818. ,@sCountry
  819. ,@sSuperAgent
  820. ,@sSuperAgentName
  821. ,'Cash Payment'--hard core
  822. ,@cAmt --destination amount
  823. ,@pAmt
  824. ,@tAmt
  825. ,@pAgentComm
  826. ,@tdFxCurrencyCode--payout currency
  827. ,@pAgent
  828. ,@pAgentName
  829. ,@pSuperAgent
  830. ,@pSuperAgentName
  831. ,@tbName----benefic name
  832. ,@pCountry
  833. ,@pBranch
  834. ,@pBranchName
  835. ,@pState
  836. ,@pDistrict
  837. ,@pLocation
  838. ,@tbPurpose---remit purpose
  839. ,@remarks
  840. ,GETDATE()
  841. ,dbo.FNAGetDateInNepalTZ()
  842. ,'SWIFT:API'
  843. ,GETDATE()
  844. ,dbo.FNAGetDateInNepalTZ()
  845. ,'SWIFT:API'
  846. ,@user
  847. ,GETDATE()
  848. ,dbo.FNAGetDateInNepalTZ()
  849. ,'Paid'
  850. ,'Paid'
  851. ,@tdFxCurrencyCode--destination currency
  852. ,@SecurityNoEnc--controlNo2
  853. ,'I'
  854. ,@sAgent
  855. ,@sAgentName
  856. ,@sBranch
  857. ,@sBranchName
  858. ,'1'
  859. SET @tranId=SCOPE_IDENTITY();
  860. INSERT INTO tranSenders(
  861. tranId
  862. ,firstName
  863. ,country
  864. ,nativeCountry
  865. ,[address]
  866. ,idType
  867. ,idNumber
  868. ,homePhone
  869. )
  870. SELECT
  871. @tranId
  872. ,@scCustomerName
  873. ,@scCustCountry
  874. ,@scCustNationality
  875. ,@scCustomerAddress
  876. ,@scCustIDType
  877. ,@scCustID
  878. ,@scCustTelephoneNumber
  879. INSERT INTO tranReceivers (
  880. tranId
  881. ,firstName
  882. ,country
  883. ,nativeCountry
  884. ,city
  885. ,[address]
  886. ,homePhone
  887. ,idType
  888. ,idNumber
  889. ,idType2
  890. ,idNumber2
  891. ,dob
  892. ,occupation
  893. ,validDate
  894. ,idPlaceOfIssue
  895. ,relationType
  896. ,relativeName
  897. ,bankName
  898. ,branchName
  899. ,chequeNo
  900. ,accountNo
  901. ,workPhone
  902. ,customerId
  903. ,membershipId
  904. ,mobile
  905. ,relWithSender
  906. ,purposeOfRemit
  907. ,issuedDate2
  908. ,validDate2
  909. )SELECT
  910. @tranId
  911. ,@tbName
  912. ,@pCountry
  913. ,@tbNationality
  914. ,@tbAddress
  915. ,@tbAddress
  916. ,@tbTelephoneNumber
  917. ,@rIdType
  918. ,@rIdNumber
  919. ,@rIdType
  920. ,@rIdNumber
  921. ,@rDob
  922. ,@rOccupation
  923. ,@rValidDate
  924. ,@rIdPlaceOfIssue
  925. ,@relationType
  926. ,@relativeName
  927. ,@rbankName
  928. ,@rbankBranch
  929. ,@rcheque
  930. ,@raccountNo
  931. ,@topupMobileNo
  932. ,@customerId
  933. ,@membershipId
  934. ,@rContactNo
  935. ,@relationship
  936. ,@purpose
  937. ,@rIssuedDate
  938. ,@rValidDate
  939. UPDATE remitTranCompliancePay SET
  940. tranId = @tranId
  941. WHERE tranId = @tranIdTemp
  942. UPDATE tranPayCompliance SET
  943. tranId = @tranId
  944. WHERE tranId = @tranIdTemp
  945. IF @membershipId IS NOT NULL
  946. BEGIN
  947. UPDATE dbo.customerMaster SET
  948. paidTxn = ISNULL(paidTxn,0)+1,
  949. firstTxnDate = ISNULL(firstTxnDate,GETDATE())
  950. WHERE membershipId = @membershipId
  951. END
  952. UPDATE ezPayHistory SET
  953. recordStatus = 'PAID'
  954. ,tranPayProcess = CASE WHEN @flag = 'Pay' THEN 'REGULAR' ELSE 'RESTORED' END
  955. ,payResponseCode = @payResponseCode
  956. ,payResponseMsg = @payResponseMsg
  957. ,paidDate = GETDATE()
  958. ,paidBy = @user
  959. WHERE id = @rowId
  960. EXEC proc_pushToAc @flag= 'i', @controlNoEncrypted = @SecurityNumber
  961. SET @controlNo = dbo.fnadecryptstring(@SecurityNumber)
  962. /*Topup Information Send SMS*/
  963. IF @membershipId IS NOT NULL
  964. BEGIN
  965. EXEC proc_topupQueue
  966. @flag = 'a'
  967. ,@user = @user
  968. ,@tranId = @tranId
  969. ,@tranType = 'I'
  970. END
  971. -- ## Limit Update
  972. EXEC Proc_AgentBalanceUpdate @flag = 'p',@tAmt = @pAmt ,@settlingAgent = @pBranch
  973. IF @@TRANCOUNT>0
  974. COMMIT TRANSACTION
  975. SET @msg=
  976. CASE
  977. WHEN @flag='restore' THEN 'Transaction has been restored successfully' ELSE 'Transaction paid Successfully'
  978. END
  979. EXEC proc_errorHandler 0,@msg, @controlNo
  980. RETURN
  981. END
  982. IF @flag ='byPass'
  983. BEGIN
  984. SELECT @rowId = id FROM ezPayHistory WITH(NOLOCK) WHERE SecurityNumber = DBO.FNAEncryptString(@SecurityNumber) AND recordStatus='PAID'
  985. SELECT CASE WHEN (@rowId IS NOT NULL OR @rowId > 0)THEN '0' ELSE '1' END errorCode
  986. , CASE WHEN (@rowId IS NOT NULL OR @rowId > 0)THEN 'Success' ELSE 'Transaction not found' END msg
  987. , @rowId id, @pAmt extra
  988. END
  989. END TRY
  990. BEGIN CATCH
  991. IF @@TRANCOUNT > 0
  992. ROLLBACK TRANSACTION
  993. SELECT 1 errorCode, ERROR_MESSAGE() msg, NULL id
  994. SELECT ERROR_LINE()
  995. END CATCH
  996. GO