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.

1070 lines
30 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendTranDomestic] Script Date: 7/4/2019 11:35:48 AM ******/
  4. DROP PROCEDURE [dbo].[proc_sendTranDomestic]
  5. GO
  6. /****** Object: StoredProcedure [dbo].[proc_sendTranDomestic] 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_sendTranDomestic] (
  12. @flag VARCHAR(50)
  13. ,@user VARCHAR(30)
  14. ,@id BIGINT = NULL
  15. ,@membershipId VARCHAR(20) = NULL
  16. ,@agentUniqueRefId VARCHAR(30) = NULL
  17. ,@senderId BIGINT = NULL
  18. ,@sMemId VARCHAR(20) = NULL
  19. ,@sFirstName VARCHAR(50) = NULL
  20. ,@sMiddleName VARCHAR(50) = NULL
  21. ,@sLastName1 VARCHAR(50) = NULL
  22. ,@sLastName2 VARCHAR(50) = NULL
  23. ,@sAddress VARCHAR(200)= NULL
  24. ,@sContactNo VARCHAR(20) = NULL
  25. ,@sIdType VARCHAR(50) = NULL
  26. ,@sIdNo VARCHAR(30) = NULL
  27. ,@sEmail VARCHAR(50) = NULL
  28. ,@receiverId BIGINT = NULL
  29. ,@rMemId VARCHAR(20) = NULL
  30. ,@rFirstName VARCHAR(50) = NULL
  31. ,@rMiddleName VARCHAR(50) = NULL
  32. ,@rLastName1 VARCHAR(50) = NULL
  33. ,@rLastName2 VARCHAR(50) = NULL
  34. ,@rAddress VARCHAR(200)= NULL
  35. ,@rContactNo VARCHAR(20) = NULL
  36. ,@rIdType VARCHAR(50) = NULL
  37. ,@rIdNo VARCHAR(30) = NULL
  38. ,@remarks VARCHAR(200)= NULL
  39. ,@sBranch INT = NULL
  40. ,@sBranchName VARCHAR(100)= NULL
  41. ,@sAgent INT = NULL
  42. ,@sAgentName VARCHAR(100)= NULL
  43. ,@sSuperAgent INT = NULL
  44. ,@sSuperAgentName VARCHAR(100)= NULL
  45. ,@settlingAgent INT = NULL
  46. ,@mapCode VARCHAR(8) = NULL
  47. ,@mapCodeDom VARCHAR(8) = NULL
  48. ,@pBranch INT = NULL
  49. ,@pBank INT = NULL
  50. ,@pBankBranch INT = NULL
  51. ,@accountNo VARCHAR(30) = NULL
  52. ,@pCountry VARCHAR(100)= NULL --payout Country
  53. ,@pState VARCHAR(100)= NULL --payout State
  54. ,@pDistrict VARCHAR(100)= NULL --payout District
  55. ,@pLocation INT = NULL --payout Location
  56. ,@collMode VARCHAR(50) = NULL
  57. ,@collCurr VARCHAR(3) = NULL
  58. ,@transferAmt MONEY = NULL
  59. ,@serviceCharge MONEY = NULL
  60. ,@handlingFee MONEY = NULL
  61. ,@cAmt MONEY = NULL
  62. ,@exRate MONEY = NULL
  63. ,@pAmt MONEY = NULL
  64. ,@payoutCurr VARCHAR(3) = NULL
  65. ,@deliveryMethod VARCHAR(50) = NULL
  66. ,@purpose VARCHAR(100)= NULL
  67. ,@sourceOfFund VARCHAR(100)= NULL
  68. ,@relationship VARCHAR(100)= NULL
  69. ,@controlNo VARCHAR(20) = NULL
  70. ,@txnId INT = NULL
  71. ,@enableApi CHAR(1) = NULL
  72. )
  73. AS
  74. SET XACT_ABORT ON
  75. BEGIN
  76. DECLARE
  77. @sCurrCostRate DECIMAL(15, 9)
  78. ,@sCurrHoMargin DECIMAL(15, 9)
  79. ,@pCurrCostRate DECIMAL(15, 9)
  80. ,@pCurrHoMargin DECIMAL(15, 9)
  81. ,@sCurrAgentMargin DECIMAL(15, 9)
  82. ,@pCurrAgentMargin DECIMAL(15, 9)
  83. ,@sCurrSuperAgentMargin DECIMAL(15, 9)
  84. ,@pCurrSuperAgentMargin DECIMAL(15, 9)
  85. ,@customerRate DECIMAL(15, 9)
  86. ,@sAgentSettRate DECIMAL(15, 9)
  87. ,@pDateCostRate DECIMAL(15, 9)
  88. ,@sAgentComm MONEY
  89. ,@sAgentCommCurrency VARCHAR(3)
  90. ,@sSuperAgentComm MONEY
  91. ,@sSuperAgentCommCurrency VARCHAR(3)
  92. ,@sHubComm MONEY
  93. ,@sHubCommCurrency VARCHAR(3)
  94. ,@pAgentComm MONEY
  95. ,@pAgentCommCurrency VARCHAR(3)
  96. ,@pSuperAgentComm MONEY
  97. ,@pSuperAgentCommCurrency VARCHAR(3)
  98. ,@pHubComm MONEY
  99. ,@pHubCommCurrency VARCHAR(3)
  100. ,@pBankName VARCHAR(100)
  101. ,@pBankBranchName VARCHAR(100)
  102. ,@promotionCode INT
  103. ,@promotionType INT
  104. ,@sCountry VARCHAR(100)
  105. ,@pSuperAgent INT
  106. ,@pSuperAgentName VARCHAR(100)
  107. ,@pAgent INT
  108. ,@pAgentName VARCHAR(100)
  109. ,@pBranchName VARCHAR(100)
  110. ,@code VARCHAR(50)
  111. ,@userName VARCHAR(50)
  112. ,@password VARCHAR(50)
  113. DECLARE
  114. @limitBal MONEY
  115. ,@sendingCustType INT
  116. ,@sendingCurrency VARCHAR(3)
  117. ,@receivingCurrency VARCHAR(3)
  118. ,@receivingCustType INT
  119. DECLARE
  120. @sendingCount INT
  121. ,@sendingAmount MONEY
  122. ,@receivingCount INT
  123. ,@receivingAmount MONEY
  124. ,@tranCount INT
  125. ,@tranAmount MONEY
  126. ,@period INT
  127. ,@nextAction INT
  128. DECLARE
  129. @pCountryId INT
  130. ,@deliveryMethodId INT
  131. ,@agentType INT
  132. ,@actAsBranchFlag CHAR(1)
  133. ,@approveFlag CHAR(1)
  134. DECLARE @controlNoEncrypted VARCHAR(20)
  135. IF @flag = 'm' --Select Customer according to membership Id
  136. BEGIN
  137. IF NOT EXISTS(SELECT 'X' FROM customers WITH(NOLOCK) WHERE membershipId = @membershipId AND ISNULL(isDeleted, 'N') <> 'Y')
  138. BEGIN
  139. EXEC proc_errorHandler 1, 'Customer with this Membership Id not found', NULL
  140. END
  141. ELSE IF EXISTS(SELECT 'X' FROM customers WITH(NOLOCK)
  142. WHERE membershipId = @membershipId
  143. AND ISNULL(isDeleted, 'N') <> 'Y'
  144. AND ISNULL(isBlackListed, 'N') = 'Y')
  145. BEGIN
  146. EXEC proc_errorHandler 1, 'This customer is blacklisted. Cannot proceed for transaction.', NULL
  147. END
  148. ELSE
  149. BEGIN
  150. EXEC proc_errorHandler 0, 'Customer Found', NULL
  151. END
  152. SELECT
  153. cust.*
  154. ,ci.idType
  155. ,ci.idNumber
  156. FROM customers cust WITH(NOLOCK)
  157. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON cust.customerId = ci.customerId AND ci.isPrimary = 'Y' AND ISNULL(ci.isDeleted, 'N') <> 'Y' AND ISNULL(ci.isActive, 'Y') = 'Y'
  158. WHERE cust.membershipId = @membershipId AND ISNULL(cust.isDeleted, 'N') <> 'Y'
  159. RETURN
  160. END
  161. ELSE IF @flag = 'u'
  162. BEGIN
  163. UPDATE remitTran SET
  164. modifiedDate = GETDATE()
  165. ,modifiedDateLocal = DBO.FNADateFormatTZ(GETDATE(), @user)
  166. ,modifiedBy = @user
  167. WHERE id = @id
  168. END
  169. ELSE IF @flag = 'a'
  170. BEGIN
  171. SELECT * FROM remitTran WITH(NOLOCK) WHERE id = @id
  172. END
  173. ELSE IF @flag = 'v' --Verify Transaction
  174. BEGIN
  175. --Necessary Parameter: @user, @sBranch, @sAgent, @sSuperAgent, @settlingAgent, @transferAmt
  176. --1. Find Sender Information
  177. SELECT @sCountry = 'Nepal'
  178. --2. Check Limit starts--------------------------------------------------------------------------------------------
  179. SET @limitBal = [dbo].FNAGetLimitBal(@settlingAgent)
  180. IF @transferAmt > @limitBal
  181. BEGIN
  182. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', NULL
  183. RETURN
  184. END
  185. EXEC proc_errorHandler 0, 'Verification Successful', NULL
  186. END
  187. ELSE IF @flag = 'i' --Local DB Insert
  188. BEGIN
  189. --Field Validation-----------------------------------------------------------
  190. IF @user IS NULL
  191. BEGIN
  192. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  193. RETURN
  194. END
  195. IF (
  196. (ISNULL(@pLocation, 0) = 0 and ISNULL(@deliveryMethod, '')='Cash Payment')
  197. OR ISNULL(@deliveryMethod, '') = ''
  198. OR ISNULL(@transferAmt,0) = 0
  199. OR @sFirstName IS NULL
  200. OR @rFirstName IS NULL
  201. )
  202. BEGIN
  203. EXEC proc_errorHandler 1, 'Mandatory Field(s) missing', NULL
  204. RETURN
  205. END
  206. --End Field Validation------------------------------------------------------
  207. SET @controlNo = '777' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '00000000', 8) + 'B'
  208. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  209. IF EXISTS(SELECT 'X' FROM dbo.controlNoListDomestic WITH(NOLOCK) WHERE controlNo = @controlNo)
  210. BEGIN
  211. EXEC proc_errorHandler 1, 'Technical error occured. Please try again.', NULL
  212. RETURN
  213. END
  214. --1. Find Branch, Agent, Super Agent and Hub
  215. --Payout
  216. IF (@pBranch IS NOT NULL)
  217. BEGIN
  218. SELECT @pAgent = parentId, @pBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  219. SELECT @pSuperAgent = parentId, @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  220. SELECT @pSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pSuperAgent
  221. END
  222. IF (@pBankBranch IS NOT NULL)
  223. BEGIN
  224. SELECT @pBank = parentId, @pBankBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  225. SELECT @pBankName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBank
  226. END
  227. SELECT @pCountry = 'Nepal'
  228. IF (@sBranch IS NULL)
  229. BEGIN
  230. EXEC proc_errorHandler 1, 'Mandatory Field(s) missing', NULL
  231. RETURN
  232. END
  233. SELECT @sCountry = 'Nepal'
  234. /*
  235. SELECT @agentType = agentType, @sAgent = parentId, @sBranchName = agentName, @sCountry = agentCountry FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  236. --Check for Branch or Agent Acting as Branch
  237. IF @agentType = 2903 --Agent
  238. BEGIN
  239. SET @sAgent = @sBranch
  240. END
  241. SELECT DISTINCT @sSuperAgent = parentId, @sAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  242. SELECT DISTINCT @sSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sSuperAgent
  243. */
  244. /*
  245. --2. Find Settling Agent--------------------------------------------------------------------------------------
  246. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  247. IF @settlingAgent IS NULL
  248. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  249. IF @settlingAgent IS NULL
  250. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sSuperAgent AND isSettlingAgent = 'Y'
  251. */
  252. --Validation Start
  253. IF EXISTS(SELECT 'X' FROM customers WHERE mobile = @sContactNo AND ISNULL(isDeleted, 'N') <> 'Y' AND isBlackListed = 'Y')
  254. BEGIN
  255. EXEC proc_errorHandler 1, 'Sending Customer is blacklisted. Cannot proceed transaction', NULL
  256. RETURN
  257. END
  258. IF EXISTS(SELECT 'X' FROM customers WHERE mobile = @rContactNo AND ISNULL(isDeleted, 'N') <> 'Y' AND isBlackListed = 'Y')
  259. BEGIN
  260. EXEC proc_errorHandler 1, 'Receiving Customer is blacklisted. Cannot proceed transaction', NULL
  261. RETURN
  262. END
  263. --3. Check Limit starts--------------------------------------------------------------------------------------------
  264. SELECT @collCurr = 'NPR', @payoutCurr = 'NPR'
  265. SELECT @sendingCustType = customerType FROM customers WHERE customerId = @senderId
  266. SELECT @sendingCurrency = @collCurr
  267. SELECT @receivingCustType = customerType FROM customers WHERE customerId = @receiverId
  268. SELECT @receivingCurrency = @payoutCurr
  269. SET @limitBal = [dbo].FNAGetLimitBal(@settlingAgent)
  270. DECLARE @currentDate DATETIME
  271. SET @currentDate = GETDATE()
  272. IF EXISTS(SELECT 'X' FROM remitTran trn WITH(NOLOCK)
  273. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  274. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  275. WHERE
  276. sen.firstName = @sFirstName
  277. AND ISNULL(sen.middleName, '') = ISNULL(@sMiddleName, '')
  278. AND ISNULL(sen.lastName1, '') = ISNULL(@sLastName1, '')
  279. AND ISNULL(sen.lastName2, '') = ISNULL(@sLastName2, '')
  280. AND rec.firstName = @rFirstName
  281. AND ISNULL(rec.middleName, '') = ISNULL(@rMiddleName, '')
  282. AND ISNULL(rec.lastName1, '') = ISNULL(@rLastName1, '')
  283. AND ISNULL(rec.lastName2, '') = ISNULL(@rLastName2, '')
  284. AND trn.tAmt = @transferAmt
  285. AND trn.pLocation = @pLocation
  286. AND DATEDIFF(MI, trn.createdDate, @currentDate) <= 2
  287. )
  288. BEGIN
  289. EXEC proc_errorHandler 1, 'Similar Transaction Found', NULL
  290. RETURN
  291. END
  292. IF @transferAmt > @limitBal
  293. BEGIN
  294. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', NULL
  295. RETURN
  296. END
  297. /*
  298. IF NOT EXISTS(SELECT 'X' FROM creditLimit WHERE agentId = @settlingAgent AND expiryDate >= GETDATE() AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') <> 'Y')
  299. BEGIN
  300. EXEC [proc_errorHandler] 1, 'Your credit limit has been expired. Please contact HO', NULL
  301. RETURN
  302. END
  303. */
  304. IF EXISTS (
  305. SELECT
  306. 'X'
  307. FROM sendTranLimit
  308. WHERE agentId = @settlingAgent
  309. AND (tranType = @collMode OR tranType IS NULL)
  310. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  311. AND (customerType = @sendingCustType OR customerType IS NULL)
  312. AND currency = @sendingCurrency
  313. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  314. AND ISNULL(minLimitAmt, 0) > @transferAmt
  315. AND ISNULL(maxLimitAmt, 0) < @transferAmt
  316. AND ISNULL(isActive, 'N') = 'Y'
  317. )
  318. BEGIN
  319. EXEC [proc_errorHandler] 2, 'Agent Sending limit is exceeded.', NULL
  320. RETURN
  321. END
  322. IF NOT EXISTS (
  323. SELECT
  324. 'X'
  325. FROM sendTranLimit
  326. WHERE countryId = @sCountry
  327. AND (tranType = @collMode OR tranType IS NULL)
  328. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  329. AND (customerType = @sendingCustType OR customerType IS NULL)
  330. AND currency = @sendingCurrency
  331. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  332. AND ISNULL(minLimitAmt, 0) <= @transferAmt
  333. AND ISNULL(maxLimitAmt, 0) >= @transferAmt
  334. AND ISNULL(isActive, 'N') = 'Y'
  335. )
  336. BEGIN
  337. EXEC [proc_errorHandler] 3, 'Country Sending limit is not defined or exceeds.', NULL
  338. RETURN
  339. END
  340. --End of Limit Checking-----------------------------------------------------------------------------------
  341. --4.Compliance Checking-----------------------------------------------------------------------------------
  342. SELECT
  343. @tranCount = 1000 --tranCount
  344. ,@tranAmount = 1000000-- amount
  345. ,@period = 5 --period
  346. --,@nextAction = nextAction
  347. --FROM csDetail
  348. --WHERE
  349. --ISNULL(isActive, 'N') = 'Y'
  350. --AND ISNULL(isDeleted, 'N') <> 'Y'
  351. --AND condition = 4600
  352. --Sending Customer
  353. SELECT
  354. @sendingCount = COUNT(*)
  355. ,@sendingAmount = SUM(tAmt)
  356. FROM remitTran rt WITH(NOLOCK)
  357. INNER JOIN tranSenders ts WITH(NOLOCK) ON rt.id = ts.tranId
  358. WHERE ts.customerId = @senderId
  359. AND rt.createdDate BETWEEN CONVERT(VARCHAR, (GETDATE() - @period), 101) AND GETDATE()
  360. --Receiving Customer
  361. SELECT
  362. @receivingCount = COUNT(*)
  363. ,@receivingAmount = SUM(pAmt)
  364. FROM remitTran rt WITH(NOLOCK)
  365. INNER JOIN tranSenders ts WITH(NOLOCK) ON rt.id = ts.tranId
  366. WHERE ts.customerId = @receiverId
  367. AND rt.createdDate BETWEEN CONVERT(VARCHAR, (GETDATE() - @period), 101) AND GETDATE()
  368. IF @sendingCount > @tranCount
  369. BEGIN
  370. EXEC [proc_errorHandler] 11, 'Sending transaction count limit exceeds.', NULL
  371. RETURN
  372. END
  373. IF @sendingAmount > @tranAmount
  374. BEGIN
  375. EXEC [proc_errorHandler] 12, 'Sending transaction amount limit exceeds.', NULL
  376. RETURN
  377. END
  378. IF @receivingCount > @tranCount
  379. BEGIN
  380. EXEC [proc_errorHandler] 13, 'Receiving transaction count limit exceeds.', NULL
  381. RETURN
  382. END
  383. IF @receivingAmount > @tranAmount
  384. BEGIN
  385. EXEC [proc_errorHandler] 14, 'Receiving transaction amount limit exceeds.', NULL
  386. RETURN
  387. END
  388. -----------------------------------------------------------------------------------------------
  389. --Compliance Check Starts
  390. --Compliance Check Ends
  391. -- select * from csMaster
  392. -- select * from csDetail
  393. --End of Compliance Checking-----------------------------------------------------------------------------------
  394. --5.Txn Amount and Service Charge Validation-------------------------------------------------------------------
  395. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod AND ISNULL(isDeleted, 'N') = 'N'
  396. IF @deliveryMethod = 'Bank Deposit'
  397. BEGIN
  398. SELECT @pLocation = agentLocation FROM agentMaster WHERE agentId = @pBankBranch
  399. END
  400. ELSE
  401. BEGIN
  402. SELECT
  403. @pAgentComm = ISNULL(pAgentComm, 0)
  404. ,@pSuperAgentComm = ISNULL(psAgentComm, 0)
  405. FROM dbo.FNAGetDomesticPayCommForCancel(@sBranch, @pLocation, @deliveryMethodId, @transferAmt)
  406. END
  407. SELECT @pCountryId = 151
  408. --6.Domestic Service Charge and Commission Calculation
  409. SELECT
  410. @serviceCharge = ISNULL(serviceCharge, 0)
  411. ,@sAgentComm = ISNULL(sAgentComm, 0)
  412. ,@sSuperAgentComm = ISNULL(ssAgentComm, 0)
  413. FROM dbo.FNAGetDomesticSendComm(@sBranch, NULL, @pLocation, @deliveryMethodId, @transferAmt)
  414. SELECT @sSuperAgentCommCurrency = 'NPR', @sAgentCommCurrency = 'NPR', @pSuperAgentCommCurrency = 'NPR', @pAgentCommCurrency = 'NPR'
  415. IF (@cAmt IS NULL)
  416. BEGIN
  417. SET @cAmt = @transferAmt + @serviceCharge
  418. END
  419. DECLARE @iCollectAmount MONEY
  420. SET @iCollectAmount = @transferAmt + @serviceCharge
  421. IF(@cAmt <> @iCollectAmount)
  422. BEGIN
  423. EXEC proc_errorHandler 1, 'Collection Amount not match', NULL
  424. RETURN
  425. END
  426. IF @transferAmt > @limitBal
  427. BEGIN
  428. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', NULL
  429. RETURN
  430. END
  431. --End of Txn Amount and Service Charge Validation--------------------------------------------------------------
  432. --7.Transaction Insert-----------------------------------------------------------------------------------------------
  433. BEGIN TRANSACTION
  434. /*
  435. --8.Update A/C Balance-------------------------------------------------------------------------------------------
  436. UPDATE creditLimit SET
  437. todaysSent = ISNULL(todaysSent, 0) + ISNULL(@cAmt, 0)
  438. WHERE agentId = @settlingAgent
  439. ---------------------------------------------------------------------------------------------------------------
  440. */
  441. INSERT INTO remitTran(
  442. controlNo
  443. ,sCurrCostRate
  444. ,sCurrHoMargin
  445. ,pCurrCostRate
  446. ,pCurrHoMargin
  447. ,sCurrAgentMargin
  448. ,pCurrAgentMargin
  449. ,sCurrSuperAgentMargin
  450. ,pCurrSuperAgentMargin
  451. ,customerRate
  452. ,sAgentSettRate
  453. ,pDateCostRate
  454. ,serviceCharge
  455. ,handlingFee
  456. ,sAgentComm
  457. ,sAgentCommCurrency
  458. ,sSuperAgentComm
  459. ,sSuperAgentCommCurrency
  460. ,sHubComm
  461. ,sHubCommCurrency
  462. ,pAgentComm
  463. ,pAgentCommCurrency
  464. ,pSuperAgentComm
  465. ,pSuperAgentCommCurrency
  466. ,pHubComm
  467. ,pHubCommCurrency
  468. ,promotionCode
  469. ,promotionType
  470. ,pMessage
  471. ,sSuperAgent
  472. ,sSuperAgentName
  473. ,sAgent
  474. ,sAgentName
  475. ,sBranch
  476. ,sBranchName
  477. ,sCountry
  478. ,pSuperAgent
  479. ,pSuperAgentName
  480. ,pAgent
  481. ,pAgentName
  482. ,pBranch
  483. ,pBranchName
  484. ,pCountry
  485. ,pState
  486. ,pDistrict
  487. ,pLocation
  488. ,paymentMethod
  489. ,pBank
  490. ,pBankName
  491. ,pBankBranch
  492. ,pBankBranchName
  493. ,accountNo
  494. ,collMode
  495. ,collCurr
  496. ,tAmt
  497. ,cAmt
  498. ,pAmt
  499. ,payoutCurr
  500. ,relWithSender
  501. ,purposeOfRemit
  502. ,sourceOfFund
  503. ,tranStatus
  504. ,payStatus
  505. ,createdDate
  506. ,createdDateLocal
  507. ,createdBy
  508. ,approvedBy
  509. ,approvedDate
  510. ,approvedDateLocal
  511. ,tranType
  512. )
  513. SELECT
  514. @controlNoEncrypted
  515. ,@sCurrCostRate
  516. ,@sCurrHoMargin
  517. ,@pCurrCostRate
  518. ,@pCurrHoMargin
  519. ,@sCurrAgentMargin
  520. ,@pCurrAgentMargin
  521. ,@sCurrSuperAgentMargin
  522. ,@pCurrSuperAgentMargin
  523. ,@customerRate
  524. ,@sAgentSettRate
  525. ,@pDateCostRate
  526. ,@serviceCharge
  527. ,@handlingFee
  528. ,@sAgentComm
  529. ,@sAgentCommCurrency
  530. ,@sSuperAgentComm
  531. ,@sSuperAgentCommCurrency
  532. ,@sHubComm
  533. ,@sHubCommCurrency
  534. ,@pAgentComm
  535. ,@pAgentCommCurrency
  536. ,@pSuperAgentComm
  537. ,@pSuperAgentCommCurrency
  538. ,@pHubComm
  539. ,@pHubCommCurrency
  540. ,@promotionCode
  541. ,@promotionType
  542. ,@remarks
  543. ,@sSuperAgent
  544. ,@sSuperAgentName
  545. ,@sAgent
  546. ,@sAgentName
  547. ,@sBranch
  548. ,@sBranchName
  549. ,@sCountry
  550. ,@pSuperAgent
  551. ,@pSuperAgentName
  552. ,@pAgent
  553. ,@pAgentName
  554. ,@pBranch
  555. ,@pBranchName
  556. ,@pCountry
  557. ,@pState
  558. ,@pDistrict
  559. ,@pLocation
  560. ,@deliveryMethod
  561. ,@pBank
  562. ,@pBankName
  563. ,@pBankBranch
  564. ,@pBankBranchName
  565. ,@accountNo
  566. ,@collMode
  567. ,@collCurr
  568. ,@transferAmt
  569. ,@cAmt
  570. ,@pAmt
  571. ,@payoutCurr
  572. ,@relationship
  573. ,@purpose
  574. ,@sourceOfFund
  575. ,'Payment'
  576. ,'Unpaid'
  577. ,GETDATE()
  578. ,DBO.FNADateFormatTZ(GETDATE(), @user)
  579. ,@user
  580. ,@user
  581. ,GETDATE()
  582. ,DBO.FNADateFormatTZ(GETDATE(), @user)
  583. ,'D'
  584. SET @id = SCOPE_IDENTITY()
  585. ---End of Transaction Insert-----------------------------------------------------------------------------------
  586. ---9.Customer Insert---------------------------------------------------------------------------------------------
  587. IF (ISNULL(@senderId, 0) <> 0)
  588. BEGIN
  589. INSERT INTO tranSenders(
  590. tranId
  591. ,customerId
  592. ,membershipId
  593. ,firstName
  594. ,middleName
  595. ,lastName1
  596. ,lastName2
  597. ,country
  598. ,[address]
  599. ,[state]
  600. ,zipCode
  601. ,city
  602. ,email
  603. ,homePhone
  604. ,workPhone
  605. ,mobile
  606. ,nativeCountry
  607. ,dob
  608. ,placeOfIssue
  609. ,idType
  610. ,idNumber
  611. ,idPlaceOfIssue
  612. ,issuedDate
  613. ,validDate
  614. )
  615. SELECT
  616. @id
  617. ,@senderId
  618. ,membershipId
  619. ,@sFirstName
  620. ,@sMiddleName
  621. ,@sLastName1
  622. ,@sLastName2
  623. ,sc.countryName
  624. ,@sAddress
  625. ,ss.stateName
  626. ,zipCode
  627. ,city
  628. ,@sEmail
  629. ,homePhone
  630. ,workPhone
  631. ,@sContactNo
  632. ,nativeCountry = nc.countryName
  633. ,dob
  634. ,c.placeOfIssue
  635. ,@sIdType
  636. ,@sIdNo
  637. ,ci.PlaceOfIssue
  638. ,ci.issuedDate
  639. ,ci.validDate
  640. FROM customers c WITH(NOLOCK)
  641. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON c.customerId = ci.customerId AND ci.isPrimary = 'Y' AND ISNULL(ci.isDeleted,'N')<>'Y'
  642. LEFT JOIN countryMaster sc WITH(NOLOCK) ON c.country = sc.countryId
  643. LEFT JOIN countryMaster nc WITH(NOLOCK) ON c.nativeCountry = nc.countryId
  644. LEFT JOIN countryStateMaster ss WITH(NOLOCK) ON c.state = ss.stateId
  645. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON ci.idType = sdv.valueId
  646. WHERE c.customerId = @senderId
  647. END
  648. ELSE
  649. BEGIN
  650. INSERT INTO tranSenders(
  651. tranId
  652. ,membershipId
  653. ,firstName
  654. ,middleName
  655. ,lastName1
  656. ,lastName2
  657. ,country
  658. ,[address]
  659. ,[state]
  660. ,zipCode
  661. ,city
  662. ,email
  663. ,homePhone
  664. ,workPhone
  665. ,mobile
  666. ,nativeCountry
  667. ,dob
  668. ,placeOfIssue
  669. ,idType
  670. ,idNumber
  671. ,idPlaceOfIssue
  672. ,issuedDate
  673. ,validDate
  674. )
  675. SELECT
  676. @id
  677. ,@sMemId
  678. ,@sFirstName
  679. ,@sMiddleName
  680. ,@sLastName1
  681. ,@sLastName2
  682. ,'Nepal'
  683. ,@sAddress
  684. ,NULL
  685. ,NULL
  686. ,NULL
  687. ,@sEmail
  688. ,NULL
  689. ,NULL
  690. ,@sContactNo
  691. ,NULL
  692. ,NULL
  693. ,NULL
  694. ,@sIdType
  695. ,@sIdNo
  696. ,NULL
  697. ,NULL
  698. ,NULL
  699. END
  700. IF (ISNULL(@receiverId, 0) <> 0)
  701. BEGIN
  702. INSERT INTO tranReceivers(
  703. tranId
  704. ,customerId
  705. ,membershipId
  706. ,firstName
  707. ,middleName
  708. ,lastName1
  709. ,lastName2
  710. ,country
  711. ,[address]
  712. ,[state]
  713. ,zipCode
  714. ,city
  715. ,email
  716. ,homePhone
  717. ,workPhone
  718. ,mobile
  719. ,nativeCountry
  720. ,dob
  721. ,placeOfIssue
  722. ,idType
  723. ,idNumber
  724. ,idPlaceOfIssue
  725. ,issuedDate
  726. ,validDate
  727. )
  728. SELECT
  729. @id
  730. ,@receiverId
  731. ,membershipId
  732. ,@rFirstName
  733. ,@rMiddleName
  734. ,@rLastName1
  735. ,@rLastName2
  736. ,sc.countryName
  737. ,@rAddress
  738. ,ss.stateName
  739. ,zipCode
  740. ,city
  741. ,email
  742. ,homePhone
  743. ,workPhone
  744. ,@rContactNo
  745. ,nativeCountry = nc.countryName
  746. ,dob
  747. ,c.placeOfIssue
  748. ,@rIdType
  749. ,@rIdNo
  750. ,ci.PlaceOfIssue
  751. ,ci.issuedDate
  752. ,ci.validDate
  753. FROM customers c WITH(NOLOCK)
  754. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON c.customerId = ci.customerId AND ci.isPrimary = 'Y' AND ISNULL(ci.isDeleted,'N')<>'Y'
  755. LEFT JOIN countryMaster sc WITH(NOLOCK) ON c.country = sc.countryId
  756. LEFT JOIN countryMaster nc WITH(NOLOCK) ON c.nativeCountry = nc.countryId
  757. LEFT JOIN countryStateMaster ss WITH(NOLOCK) ON c.state = ss.stateId
  758. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON ci.idType = sdv.valueId
  759. WHERE c.customerId = @receiverId
  760. END
  761. ELSE
  762. BEGIN
  763. INSERT INTO tranReceivers(
  764. tranId
  765. ,membershipId
  766. ,firstName
  767. ,middleName
  768. ,lastName1
  769. ,lastName2
  770. ,country
  771. ,[address]
  772. ,[state]
  773. ,zipCode
  774. ,city
  775. ,email
  776. ,homePhone
  777. ,workPhone
  778. ,mobile
  779. ,nativeCountry
  780. ,dob
  781. ,placeOfIssue
  782. ,idType
  783. ,idNumber
  784. ,idPlaceOfIssue
  785. ,issuedDate
  786. ,validDate
  787. )
  788. SELECT
  789. @id
  790. ,@rMemId
  791. ,@rFirstName
  792. ,@rMiddleName
  793. ,@rLastName1
  794. ,@rLastName2
  795. ,'Nepal'
  796. ,@rAddress
  797. ,NULL
  798. ,NULL
  799. ,NULL
  800. ,NULL
  801. ,NULL
  802. ,NULL
  803. ,@rContactNo
  804. ,NULL
  805. ,NULL
  806. ,NULL
  807. ,@rIdType
  808. ,@rIdNo
  809. ,NULL
  810. ,NULL
  811. ,NULL
  812. END
  813. --End of Customer Insert-----------------------------------------------------------------------------------------
  814. INSERT INTO controlNoListDomestic(controlNo)
  815. SELECT @controlNo
  816. IF @@TRANCOUNT > 0
  817. COMMIT TRANSACTION
  818. EXEC [proc_errorHandler] 0, 'Transaction has been sent successfully', @controlNo
  819. --11. Accounting Server------------------------------------------------------------------------------------------
  820. --SELECT * FROM [192.168.1.234].IME_TEST.dbo.[REMIT_TRN_LOCAL] WHERE TRN_REF_NO = dbo.encryptDBlocal('7115830246D') ORDER BY tran_id DESC
  821. --UPDATE [192.168.1.234].IME_TEST.dbo.[REMIT_TRN_LOCAL] SET S_BRANCH = S_AGENT WHERE TRN_REF_NO = dbo.encryptDBlocal('7115830246D')
  822. --SELECT * FROM [192.168.1.234].IME_TEST.dbo.[REMIT_TRN_MASTER]
  823. --SELECT * FROM [192.168.1.234].IME_TEST.dbo.[ac_master] ORDER BY tran_id DESC
  824. EXEC FastMoneyPro_Account.dbo.[PROC_REMIT_DATA_UPDATE]
  825. @flag = 's'
  826. ,@controlNo = @controlNo
  827. ,@mapCode = @mapCodeDom
  828. ,@sFirstName = @sFirstName
  829. ,@sMiddleName = @sMiddleName
  830. ,@sLastName1 = @sLastName1
  831. ,@sLastName2 = @sLastName2
  832. ,@rFirstName = @rFirstName
  833. ,@rMiddleName = @rMiddleName
  834. ,@rLastName1 = @rLastName1
  835. ,@rLastName2 = @rLastName2
  836. ,@cAmt = @cAmt
  837. ,@pAmt = @pAmt
  838. ,@serviceCharge = @serviceCharge
  839. ,@sAgentComm = @sAgentComm
  840. ,@pAgentComm = @pAgentComm
  841. ,@pBank = @pBank
  842. ,@pBankName = @pBankName
  843. ,@pBankBranch = @pBankBranch
  844. ,@deliveryMethod = @deliveryMethod
  845. ,@user = @user
  846. ,@tranId = @id
  847. /*
  848. INSERT INTO [192.168.1.234].IME_TEST.dbo.[REMIT_TRN_LOCAL] (
  849. [TRN_REF_NO],[S_AGENT]
  850. ,[SENDER_NAME]
  851. ,[RECEIVER_NAME]
  852. ,[S_AMT],[P_AMT],[ROUND_AMT],[TOTAL_SC],[OTHER_SC],[S_SC], [R_SC]
  853. ,[R_BANK],[R_BANK_NAME],[R_BRANCH]
  854. ,[TRN_TYPE]
  855. ,TRN_STATUS,PAY_STATUS
  856. ,[TRN_DATE],CONFIRM_DATE
  857. ,SEMPID
  858. )
  859. SELECT
  860. dbo.encryptDBlocal(@controlNo),@mapCodeDom
  861. ,@sFirstName + ISNULL(' ' + @sMiddleName, '') + ISNULL(' ' + @sLastName1, '') + ISNULL(' ' + @sLastName2, '')
  862. ,@rFirstName + ISNULL(' ' + @rMiddleName, '') + ISNULL(' ' + @rLastName1, '') + ISNULL(' ' + @rLastName2, '')
  863. ,@cAmt,@pAmt,@pAmt,@serviceCharge,0,@sAgentComm,0
  864. ,@pBank,@pBankName,@pBankBranch
  865. ,CASE WHEN @deliveryMethod = 'Cash Payment' THEN 'Cash Pay' WHEN @deliveryMethod = 'Bank Deposit' THEN 'Bank Transfer' END
  866. ,'Unpaid','Payment'
  867. ,GETDATE(),GETDATE()
  868. ,@user
  869. */
  870. END
  871. ELSE IF @flag = 'scTBL'
  872. BEGIN
  873. DECLARE @masterId INT
  874. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod AND ISNULL(isDeleted, 'N') = 'N'
  875. IF @deliveryMethod = 'Bank Deposit'
  876. BEGIN
  877. SELECT @pLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  878. END
  879. SELECT
  880. @masterId = masterId
  881. FROM dbo.FNAGetDomesticSendComm(@sBranch, NULL, @pLocation, @deliveryMethodId, @transferAmt)
  882. SELECT
  883. fromAmt = fromAmt
  884. ,toAmt = toAmt
  885. ,pcnt = serviceChargePcnt
  886. ,maxAmt = serviceChargeMaxAmt
  887. ,minAmt = serviceChargeMinAmt
  888. FROM scDetail WHERE scMasterId = @masterId
  889. ORDER BY fromAmt
  890. END
  891. ELSE IF @flag = 'sc'
  892. BEGIN
  893. --EXEC proc_sendTranDomestic @flag = 'sc', @transferAmt = '10000', @pLocation = '109', @sBranch = '10004', @user = 'imeadmin'
  894. --EXEC proc_sendTranDomestic @flag = 'sc', @pLocation = null, @deliveryMethod = 'Bank Deposit', @transferAmt = '1000', @sBranch = '10011', @pBankBranch = '10004', @user = 'imeadmin'
  895. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod AND ISNULL(isDeleted, 'N') = 'N'
  896. IF @deliveryMethod = 'Bank Deposit'
  897. BEGIN
  898. SELECT @pLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  899. END
  900. ELSE IF @deliveryMethod = 'Cash Payment' AND @transferAmt > dbo.FNAGetDomesticSendLimit() --AND @transferAmt > 100000
  901. BEGIN
  902. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit.', NULL
  903. RETURN
  904. END
  905. SELECT sc = ISNULL(serviceCharge, -1) FROM dbo.FNAGetDomesticSendComm(@sBranch, NULL, @pLocation, @deliveryMethodId, @transferAmt)
  906. END
  907. ELSE IF @flag = 'acBal'
  908. BEGIN
  909. --EXEC proc_sendTranDomestic @flag = 'acBal', @settlingAgent = '1227', @user = 'bajrasub123'
  910. SELECT
  911. availableBal = ISNULL(dbo.FNAGetLimitBal(@settlingAgent), 0)
  912. ,balCurrency = cm.currencyCode
  913. ,limExpiry = ISNULL(CONVERT(VARCHAR, expiryDate, 101), 'N/A')
  914. FROM creditLimit cl
  915. LEFT JOIN currencyMaster cm WITH(NOLOCK) ON cl.currency = cm.currencyId
  916. WHERE agentId = @settlingAgent
  917. END
  918. -- ## Get Service Charge V2
  919. IF @flag = 'sc-v2'
  920. BEGIN
  921. -- ## transaction varification
  922. SET @limitBal = [dbo].FNAGetLimitBal(@settlingAgent)
  923. IF @transferAmt > @limitBal
  924. BEGIN
  925. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', NULL
  926. RETURN
  927. END
  928. -- ## service charge calculation
  929. SELECT @deliveryMethodId = serviceTypeId
  930. FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod AND ISNULL(isDeleted, 'N') = 'N'
  931. IF @deliveryMethod = 'Bank Deposit'
  932. BEGIN
  933. SELECT @pLocation = agentLocation
  934. FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  935. END
  936. ELSE IF @deliveryMethod = 'Cash Payment' AND @transferAmt > dbo.FNAGetDomesticSendLimit() --AND @transferAmt > 100000
  937. BEGIN
  938. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit.', NULL
  939. RETURN
  940. END
  941. SELECT @serviceCharge = ISNULL(serviceCharge, 0)
  942. FROM dbo.FNAGetDomesticSendComm(@sBranch, NULL, @pLocation, @deliveryMethodId, @transferAmt)
  943. if @serviceCharge = 0
  944. BEGIN
  945. EXEC [proc_errorHandler] 1, 'Service Charge not defined.', NULL
  946. RETURN
  947. END
  948. IF (@transferAmt + @serviceCharge) > @limitBal
  949. BEGIN
  950. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', NULL
  951. RETURN
  952. END
  953. -- ## invoice print
  954. DECLARE
  955. @method VARCHAR(20) = NULL
  956. ,@userId INT
  957. ,@sendLimit MONEY
  958. ,@invPrint CHAR(1)
  959. SELECT @userId = userId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  960. SELECT @sendLimit = sendLimit FROM userLimit WITH(NOLOCK)
  961. WHERE
  962. userId = @userId
  963. AND ISNULL(isDeleted, 'N') <> 'Y'
  964. AND ISNULL(isActive, 'N') = 'Y'
  965. AND ISNULL(isEnable, 'N') = 'Y'
  966. SELECT @method = invoicePrintMethod
  967. FROM agentBusinessFunction WITH(NOLOCK)
  968. WHERE agentId = (SELECT agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user)
  969. IF(@sendLimit > @transferAmt)
  970. SELECT @invPrint = 'Y'
  971. ELSE IF(@method = 'ba')
  972. SELECT @invPrint ='Y'
  973. ELSE
  974. SELECT @invPrint = 'N'
  975. SET @cAmt = @transferAmt + @serviceCharge
  976. SELECT 0 errorCode, dbo.ShowDecimal(@serviceCharge) serviceCharge, dbo.ShowDecimal(@cAmt) cAmt,@invPrint invoiceMethod
  977. RETURN
  978. END
  979. END
  980. GO