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.

1172 lines
82 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_sendTranIntl] 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_sendTranIntl] (
  9. @flag VARCHAR(50)
  10. ,@user VARCHAR(30)
  11. ,@txnId VARCHAR(30) = NULL
  12. ,@controlNo VARCHAR(20) = NULL
  13. ,@id BIGINT = NULL
  14. ,@senderId BIGINT = NULL
  15. ,@benId INT = NULL
  16. ,@agentId INT = NULL --payout
  17. ,@pBank INT = NULL
  18. ,@pBankBranch INT = NULL
  19. ,@accountNo VARCHAR(30) = NULL
  20. ,@pSuperAgent INT = NULL --payout Super Agent
  21. ,@pCountry VARCHAR(100)= NULL --payout Country
  22. ,@pLocation INT = NULL
  23. ,@pState VARCHAR(100)= NULL --payout State
  24. ,@pDistrict VARCHAR(100)= NULL --payout District
  25. ,@pBranch INT = NULL
  26. ,@collMode INT = NULL
  27. ,@collCurr VARCHAR(3) = NULL
  28. ,@transferAmt FLOAT = NULL
  29. ,@serviceCharge MONEY = NULL
  30. ,@handlingFee MONEY = NULL
  31. ,@cAmt FLOAT = NULL
  32. ,@exRate FLOAT = NULL
  33. ,@pAmt FLOAT = NULL
  34. ,@payoutCurr VARCHAR(3) = NULL
  35. ,@remarks VARCHAR(500)= NULL
  36. ,@deliveryMethod VARCHAR(100)= NULL
  37. ,@purpose VARCHAR(100)= NULL
  38. ,@sourceOfFund VARCHAR(100)= NULL
  39. ,@relationship VARCHAR(100)= NULL
  40. ,@mode VARCHAR(10) = NULL
  41. )
  42. AS
  43. SET NOCOUNT ON
  44. SET XACT_ABORT ON
  45. BEGIN
  46. DECLARE
  47. @sCurrCostRate DECIMAL(15, 9)
  48. ,@sCurrHoMargin DECIMAL(15, 9)
  49. ,@pCurrCostRate DECIMAL(15, 9)
  50. ,@pCurrHoMargin DECIMAL(15, 9)
  51. ,@sCurrAgentMargin DECIMAL(15, 9)
  52. ,@pCurrAgentMargin DECIMAL(15, 9)
  53. ,@sCurrSuperAgentMargin DECIMAL(15, 9)
  54. ,@pCurrSuperAgentMargin DECIMAL(15, 9)
  55. ,@customerRate DECIMAL(15, 9)
  56. ,@sAgentSettRate DECIMAL(15, 9)
  57. ,@pDateCostRate DECIMAL(15, 9)
  58. ,@sAgentComm MONEY
  59. ,@sAgentCommCurrency VARCHAR(3)
  60. ,@sSuperAgentComm MONEY
  61. ,@sSuperAgentCommCurrency VARCHAR(3)
  62. ,@sHubComm MONEY
  63. ,@sHubCommCurrency VARCHAR(3)
  64. ,@pAgentComm MONEY
  65. ,@pAgentCommCurrency VARCHAR(3)
  66. ,@pSuperAgentComm MONEY
  67. ,@pSuperAgentCommCurrency VARCHAR(3)
  68. ,@pHubComm MONEY
  69. ,@pHubCommCurrency VARCHAR(3)
  70. ,@pBankName VARCHAR(100)
  71. ,@pBankBranchName VARCHAR(100)
  72. ,@promotionCode INT
  73. ,@promotionType INT
  74. ,@sCountry VARCHAR(100)
  75. ,@sCountryId INT
  76. ,@sSuperAgent INT
  77. ,@sSuperAgentName VARCHAR(100)
  78. ,@sAgent INT
  79. ,@sAgentName VARCHAR(100)
  80. ,@sBranch INT
  81. ,@sBranchName VARCHAR(100)
  82. ,@pAgent INT
  83. ,@pAgentName VARCHAR(100)
  84. ,@pSuperAgentName VARCHAR(100)
  85. ,@pBranchName VARCHAR(100)
  86. ,@pCountryId INT
  87. ,@pStateId INT
  88. ,@deliveryMethodId INT
  89. ,@settlingAgent INT
  90. ,@agentType INT
  91. ,@senderName VARCHAR(100)
  92. DECLARE
  93. @xAmt MONEY
  94. ,@baseCurrency INT
  95. DECLARE
  96. @limitBal MONEY
  97. ,@sendingCustType INT
  98. ,@sendingCurrency VARCHAR(3)
  99. ,@sendingCurrencyId INT
  100. ,@receivingCustType INT
  101. ,@receivingCurrency VARCHAR(3)
  102. ,@receivingCurrencyId INT
  103. ,@baseCurrencyId INT
  104. DECLARE @currentDate DATETIME
  105. DECLARE @iServiceCharge MONEY
  106. DECLARE @cisMasterId INT, @compIdResult VARCHAR(300)
  107. DECLARE @controlNoEncrypted VARCHAR(20)
  108. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  109. IF @flag = 'v' -- Validation
  110. BEGIN
  111. IF @user IS NULL
  112. BEGIN
  113. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  114. RETURN
  115. END
  116. IF ISNULL(@senderId, 0) = 0
  117. BEGIN
  118. EXEC proc_errorHandler 1, 'Please choose Sender', NULL
  119. RETURN
  120. END
  121. IF ISNULL(@benId, 0) = 0
  122. BEGIN
  123. EXEC proc_errorHandler 1, 'Please choose beneficiary', NULL
  124. RETURN
  125. END
  126. IF ISNULL(@deliveryMethod, '') = ''
  127. BEGIN
  128. EXEC proc_errorHandler 1, 'Please choose delivery method', NULL
  129. RETURN
  130. END
  131. IF @serviceCharge IS NULL
  132. BEGIN
  133. EXEC proc_errorHandler 1, 'Service Charge missing', NULL
  134. RETURN
  135. END
  136. IF ISNULL(@transferAmt, 0) = 0
  137. BEGIN
  138. EXEC proc_errorHandler 1, 'Transfer Amount missing', NULL
  139. RETURN
  140. END
  141. IF ISNULL(@exRate, 0) = 0
  142. BEGIN
  143. EXEC proc_errorHandler 1, 'Exchange Rate missing', NULL
  144. RETURN
  145. END
  146. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user AND ISNULL(isDeleted, 'N') <> 'Y'
  147. --Payout Agent
  148. IF @agentId IS NOT NULL
  149. BEGIN
  150. SET @pBranch = @agentId
  151. SELECT @agentType = agentType, @pBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  152. IF @agentType = 2903
  153. SET @pAgent = @pBranch
  154. ELSE
  155. SELECT DISTINCT @pAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  156. SELECT DISTINCT @pSuperAgent = parentId, @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  157. SELECT DISTINCT @pSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pSuperAgent
  158. END
  159. --Check Compliance ID Rule---------------------------------------------------------------------------------------------------------------------------
  160. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod
  161. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @pCountry
  162. SELECT @pStateId = stateId FROM countryStateMaster WITH(NOLOCK) WHERE stateName = @pState
  163. SELECT @cisMasterId = masterId FROM dbo.FNAGetComplianceIDRuleMaster(@sBranch, @pCountryId, @pStateId, @pBranch, NULL, @senderId, @benId)
  164. EXEC proc_complianceIDRuleDetail @user, @senderId, @transferAmt, @sourceOfFund, @purpose, @relationship, @deliveryMethodId, NULL, @cisMasterId, @compIdResult OUTPUT
  165. IF(@compIdResult <> '')
  166. BEGIN
  167. EXEC proc_errorHandler 1, @compIdResult, NULL
  168. RETURN
  169. END
  170. --Check Compliance ID Rule--------------------------------------------------------------------------------------------------------------------------
  171. --4. Find Branch, Agent, Super Agent and Hub
  172. --Payout Agent
  173. IF @agentId IS NOT NULL
  174. BEGIN
  175. SET @pBranch = @agentId
  176. SELECT @agentType = agentType, @pBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  177. IF @agentType = 2903
  178. SET @pAgent = @pBranch
  179. ELSE
  180. SELECT DISTINCT @pAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  181. SELECT DISTINCT @pSuperAgent = parentId, @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  182. SELECT DISTINCT @pSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pSuperAgent
  183. END
  184. IF (@pBankBranch IS NOT NULL)
  185. BEGIN
  186. SELECT @pBank = parentId, @pBankBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  187. SELECT @pBankName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBank
  188. END
  189. --Sending Agent
  190. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  191. SELECT @agentType = agentType, @sBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  192. IF @agentType = 2903
  193. SET @sAgent = @sBranch
  194. ELSE
  195. SELECT DISTINCT @sAgent = parentId, @sBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  196. SELECT DISTINCT @sSuperAgent = parentId, @sCountry = agentCountry, @sCountryId = agentCountryId, @sAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  197. SELECT DISTINCT @sSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sSuperAgent
  198. --5. Find Settling Agent--------------------------------------------------------------------------------------
  199. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  200. IF @settlingAgent IS NULL
  201. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  202. IF @settlingAgent IS NULL
  203. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sSuperAgent AND isSettlingAgent = 'Y'
  204. --End of Find Settling Agent----------------------------------------------------------------------------------
  205. --6. Check Limit starts
  206. SELECT @sendingCustType = customerType FROM customers WITH(NOLOCK) WHERE customerId = @senderId
  207. SELECT @sendingCurrency = @collCurr
  208. SELECT @sendingCurrencyId = currencyId FROM currencyMaster WITH(NOLOCK) WHERE currencyCode = @collCurr
  209. SELECT @receivingCustType = customerType FROM customers WITH(NOLOCK) WHERE customerId = @benId
  210. SELECT @receivingCurrency = @payoutCurr
  211. SELECT @receivingCurrencyId = currencyId FROM currencyMaster WITH(NOLOCK) WHERE currencyCode = @payoutCurr
  212. SET @currentDate = CONVERT(VARCHAR, GETDATE(), 101)
  213. IF EXISTS(SELECT 'X' FROM remitTran trn WITH(NOLOCK)
  214. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  215. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  216. WHERE
  217. sen.customerId = ISNULL(@senderId, 0)
  218. AND rec.customerId = ISNULL(@benId, 0)
  219. AND trn.tAmt = @transferAmt
  220. AND trn.createdDate BETWEEN @currentDate + '00:00:00' AND @currentDate + '23:59:59'
  221. )
  222. BEGIN
  223. EXEC proc_errorHandler 1, 'Similar Transaction Found', NULL
  224. RETURN
  225. END
  226. -----------------------------------------------------------------------------------------------------------------------------------------
  227. SELECT @limitBal = [dbo].FNAGetLimitBal(@settlingAgent)
  228. SELECT @baseCurrency = currency FROM creditLimit WITH(NOLOCK) WHERE agentId = @settlingAgent AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  229. IF @baseCurrency = @sendingCurrencyId
  230. SELECT @xAmt = @transferAmt
  231. ELSE
  232. SELECT @xAmt = amount FROM dbo.FNAGetExchangeAmount(@sBranch, NULL, @collCurr, @transferAmt, @deliveryMethodId, 'C', @user)
  233. IF @xAmt > @limitBal
  234. BEGIN
  235. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', @controlNo
  236. RETURN
  237. END
  238. IF EXISTS(SELECT 'X' FROM creditLimit WHERE agentId = @settlingAgent AND expiryDate < GETDATE() AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  239. BEGIN
  240. EXEC [proc_errorHandler] 1, 'Your credit limit has been expired. Please contact HO', @controlNo
  241. RETURN
  242. END
  243. IF((SELECT expiryDate FROM creditLimit WHERE agentId = @settlingAgent AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') <> 'Y') <
  244. (SELECT topUpExpiryDate = ISNULL(topUpExpiryDate, '1900-01-01') FROM balanceTopUp WHERE agentId = @settlingAgent))
  245. BEGIN
  246. IF NOT EXISTS(SELECT 'X' FROM balanceTopUp WHERE agentId = @settlingAgent AND topUpExpiryDate >= GETDATE())
  247. BEGIN
  248. EXEC [proc_errorHandler] 1, 'Your Top-up has been expired. Please contact HO', @controlNo
  249. RETURN
  250. END
  251. END
  252. IF EXISTS (
  253. SELECT
  254. 'X'
  255. FROM sendTranLimit
  256. WHERE agentId = @settlingAgent
  257. AND (tranType = @collMode OR tranType IS NULL)
  258. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  259. AND (customerType = @sendingCustType OR customerType IS NULL)
  260. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  261. AND ISNULL(minLimitAmt, 0) > @transferAmt
  262. AND ISNULL(maxlimitAmt, 0) < @transferAmt
  263. AND ISNULL(isActive, 'N') = 'Y'
  264. )
  265. BEGIN
  266. EXEC [proc_errorHandler] 2, 'Agent Sending limit is exceeded.', NULL
  267. RETURN
  268. END
  269. IF NOT EXISTS (
  270. SELECT
  271. 'X'
  272. FROM sendTranLimit
  273. WHERE countryId = @sCountry
  274. AND (tranType = @collMode OR tranType IS NULL)
  275. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  276. AND (customerType = @sendingCustType OR customerType IS NULL)
  277. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  278. AND ISNULL(minLimitAmt, 0) <= @transferAmt
  279. AND ISNULL(maxLimitAmt, 0) >= @transferAmt
  280. AND ISNULL(isActive, 'N') = 'Y'
  281. )
  282. BEGIN
  283. EXEC [proc_errorHandler] 3, 'Country Sending limit is not defined or exceeds.', NULL
  284. RETURN
  285. END
  286. IF @baseCurrency = @receivingCurrencyId
  287. SELECT @xAmt = @pAmt
  288. ELSE
  289. SELECT @xAmt = amount FROM dbo.FNAGetExchangeAmount(@sBranch, @pCountryId, @payoutCurr, @pAmt, @deliveryMethodId, 'C', @user)
  290. --SELECT * FROM receiveTranLimit
  291. --IF NOT EXISTS (
  292. -- SELECT
  293. -- 'X'
  294. -- FROM receiveTranLimit
  295. -- WHERE agentId = @sAgent
  296. -- AND (tranType = @collMode OR tranType IS NULL)
  297. -- AND (customerType = @sendingCustType OR customerType IS NULL)
  298. -- AND currency = @receivingCurrency
  299. -- AND (sendingCountry = @sCountry OR sendingCountry IS NULL)
  300. -- AND ISNULL(limitAmt, 0) >= @pAmt
  301. --)
  302. --BEGIN
  303. -- EXEC [proc_errorHandler] 1, 'Receiving Agent limit is not defined or exceeds.', @controlNo
  304. -- RETURN
  305. --END
  306. IF NOT EXISTS (
  307. SELECT
  308. 'X'
  309. FROM receiveTranLimit
  310. WHERE countryId = @pCountry
  311. AND (tranType = @collMode OR tranType IS NULL)
  312. AND (customerType = @receivingCustType OR customerType IS NULL)
  313. AND (sendingCountry = @sCountry OR sendingCountry IS NULL)
  314. AND ISNULL(maxLimitAmt, 0) >= @pAmt
  315. AND ISNULL(isActive, 'N') = 'Y'
  316. )
  317. BEGIN
  318. EXEC [proc_errorHandler] 1, 'Receiving country limit is not defined or exceeds.', @controlNo
  319. RETURN
  320. END
  321. -----------------------------------------------------------------------------------------------
  322. --7. Exchange Rate Details------------------------------------------------------------------------------------------------------------------
  323. SELECT @id = id FROM dbo.FNAGetExRateForTran(@sBranch, @pBranch, @pCountryId, @collCurr, @payoutCurr, @deliveryMethodId, @user)
  324. IF @id IS NULL
  325. BEGIN
  326. EXEC proc_errorHandler 1, 'Exchange Rate not defined', NULL
  327. RETURN
  328. END
  329. SELECT
  330. @sCurrCostRate = cCurrCostRate
  331. ,@sCurrHoMargin = cCurrHOMargin
  332. ,@sCurrAgentMargin = cCurrAgentMargin
  333. ,@pCurrCostRate = pCurrCostRate
  334. ,@pCurrHoMargin = pCurrHOMargin
  335. ,@pCurrAgentMargin = pCurrAgentMargin
  336. ,@customerRate = customerCrossRate
  337. FROM dbo.FNAGetCrossRate(@id)
  338. --------------------------------------------------------------------------------------------------------------------------------------------
  339. --7. Service Charge Calculation-------------------------------------------------------------------------------------------------------------
  340. SELECT @iServiceCharge = ISNULL(amount, -1) FROM [dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountryId, @pLocation, @agentId , @deliveryMethodId, @transferAmt, @collCurr)
  341. IF @iServiceCharge = -1
  342. BEGIN
  343. EXEC proc_errorHandler 1, 'Service Charge is not defined', NULL
  344. RETURN
  345. END
  346. --End of service charge calculation---------------------------------------------------------------------------------------------------------
  347. --Commission Calculation Start
  348. SELECT @sSuperAgentComm = amount, @sSuperAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm(@sBranch, @pSuperAgent, @pCountryId, NULL, @pBranch, @collCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, NULL)
  349. SELECT @sAgentComm = amount, @sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm(@sBranch, @pSuperAgent, @pCountryId, NULL, @pBranch, @collCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, @sSuperAgentComm)
  350. IF (@sSuperAgentComm IS NULL OR @sAgentComm IS NULL)
  351. BEGIN
  352. EXEC proc_errorHandler 1, 'Commission is not defined', NULL
  353. RETURN
  354. END
  355. --Commission Calculation End
  356. EXEC proc_errorHandler 0, 'Validation successful', NULL
  357. END
  358. IF @flag = 'i'
  359. BEGIN
  360. --1. Field Validation-----------------------------------------------------------
  361. IF @user IS NULL
  362. BEGIN
  363. EXEC proc_errorHandler 1, 'Your session has expired. Cannot send transaction', NULL
  364. RETURN
  365. END
  366. IF (
  367. ISNULL(@deliveryMethod, '') = ''
  368. OR @serviceCharge IS NULL
  369. OR ISNULL(@transferAmt,0) = 0
  370. OR ISNULL(@senderId, 0) = 0
  371. OR ISNULL(@benId, 0) = 0
  372. OR ISNULL(@exRate, 0) = 0
  373. )
  374. BEGIN
  375. EXEC proc_errorHandler 1, 'Mandatory Field(s) missing', NULL
  376. RETURN
  377. END
  378. --2. Select Ids----------------------------------------------------------------------------------------------------------------------------------------
  379. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WHERE ISNULL(isDeleted, 'N') = 'N' AND typeTitle = @deliveryMethod
  380. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N' AND countryName = @pCountry
  381. SELECT @pStateId = stateId FROM countryStateMaster WITH(NOLOCK) WHERE stateName = @pState
  382. ----------------------------------------------------------------------------------------------------------------------------------------------------
  383. --3. Check Compliance ID Rule---------------------------------------------------------------------------------------------------------------------------
  384. SELECT @cisMasterId = masterId FROM dbo.FNAGetComplianceIDRuleMaster(@sBranch, @pCountryId, @pStateId, @pBranch, NULL, @senderId, @benId)
  385. EXEC proc_complianceIDRuleDetail @user, @senderId, @transferAmt, @sourceOfFund, @purpose, @relationship, @deliveryMethodId, NULL, @cisMasterId, @compIdResult OUTPUT
  386. IF(@compIdResult <> '')
  387. BEGIN
  388. EXEC proc_errorHandler 1, @compIdResult, NULL
  389. RETURN
  390. END
  391. --End of Check Compliance ID Rule--------------------------------------------------------------------------------------------------------------------------
  392. --End Field Validation------------------------------------------------------
  393. SET @controlNo = '9' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 10) + 'I'
  394. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  395. --4. Find Branch, Agent, Super Agent and Hub
  396. --Payout Agent
  397. IF @agentId IS NOT NULL
  398. BEGIN
  399. SET @pBranch = @agentId
  400. SELECT @agentType = agentType, @pBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  401. IF @agentType = 2903
  402. SET @pAgent = @pBranch
  403. ELSE
  404. SELECT DISTINCT @pAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBranch
  405. SELECT DISTINCT @pSuperAgent = parentId, @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  406. SELECT DISTINCT @pSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pSuperAgent
  407. END
  408. IF (@pBankBranch IS NOT NULL)
  409. BEGIN
  410. SELECT @pBank = parentId, @pBankBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  411. SELECT @pBankName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBank
  412. END
  413. --Sending Agent
  414. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  415. SELECT @agentType = agentType, @sBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  416. IF @agentType = 2903
  417. SET @sAgent = @sBranch
  418. ELSE
  419. SELECT DISTINCT @sAgent = parentId, @sBranchName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sBranch
  420. SELECT DISTINCT @sSuperAgent = parentId, @sCountry = agentCountry, @sCountryId = agentCountryId, @sAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sAgent
  421. SELECT DISTINCT @sSuperAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @sSuperAgent
  422. --5. Find Settling Agent--------------------------------------------------------------------------------------
  423. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sBranch AND isSettlingAgent = 'Y'
  424. IF @settlingAgent IS NULL
  425. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sAgent AND isSettlingAgent = 'Y'
  426. IF @settlingAgent IS NULL
  427. SELECT @settlingAgent = agentId FROM agentMaster WHERE agentId = @sSuperAgent AND isSettlingAgent = 'Y'
  428. --End of Find Settling Agent----------------------------------------------------------------------------------
  429. --6. Check Limit starts
  430. SELECT @sendingCustType = customerType FROM customers WITH(NOLOCK) WHERE customerId = @senderId
  431. SELECT @sendingCurrency = @collCurr
  432. SELECT @sendingCurrencyId = currencyId FROM currencyMaster WITH(NOLOCK) WHERE currencyCode = @collCurr
  433. SELECT @receivingCustType = customerType FROM customers WITH(NOLOCK) WHERE customerId = @benId
  434. SELECT @receivingCurrency = @payoutCurr
  435. SELECT @receivingCurrencyId = currencyId FROM currencyMaster WITH(NOLOCK) WHERE currencyCode = @payoutCurr
  436. SET @currentDate = CONVERT(VARCHAR, GETDATE(), 101)
  437. IF EXISTS(SELECT 'X' FROM remitTran trn WITH(NOLOCK)
  438. LEFT JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  439. LEFT JOIN tranReceivers rec WITH(NOLOCK) ON trn.id = rec.tranId
  440. WHERE
  441. sen.customerId = ISNULL(@senderId, 0)
  442. AND rec.customerId = ISNULL(@benId, 0)
  443. AND trn.tAmt = @transferAmt
  444. AND trn.createdDate BETWEEN @currentDate + '00:00:00' AND @currentDate + '23:59:59'
  445. )
  446. BEGIN
  447. EXEC proc_errorHandler 1, 'Similar Transaction Found', NULL
  448. RETURN
  449. END
  450. -----------------------------------------------------------------------------------------------------------------------------------------
  451. SELECT @limitBal = [dbo].FNAGetLimitBal(@settlingAgent)
  452. SELECT @baseCurrency = currency FROM creditLimit WITH(NOLOCK) WHERE agentId = @settlingAgent AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'
  453. IF @baseCurrency = @sendingCurrencyId
  454. SELECT @xAmt = @transferAmt
  455. ELSE
  456. SELECT @xAmt = amount FROM dbo.FNAGetExchangeAmount(@sBranch, NULL, @collCurr, @transferAmt, @deliveryMethodId, 'C', @user)
  457. IF @xAmt > @limitBal
  458. BEGIN
  459. EXEC [proc_errorHandler] 1, 'Transfer amount exceeds Limit. Please, Check your available limit.', @controlNo
  460. RETURN
  461. END
  462. IF EXISTS(SELECT 'X' FROM creditLimit WHERE agentId = @settlingAgent AND expiryDate < GETDATE() AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N')
  463. BEGIN
  464. EXEC [proc_errorHandler] 1, 'Your credit limit has been expired. Please contact HO', @controlNo
  465. RETURN
  466. END
  467. /*
  468. IF((SELECT expiryDate FROM creditLimit WHERE agentId = @settlingAgent AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') <> 'Y') <
  469. (SELECT topUpExpiryDate = ISNULL(topUpExpiryDate, '1900-01-01') FROM balanceTopUp WHERE agentId = @settlingAgent))
  470. BEGIN
  471. IF NOT EXISTS(SELECT 'X' FROM balanceTopUp WHERE agentId = @settlingAgent AND topUpExpiryDate >= GETDATE())
  472. BEGIN
  473. EXEC [proc_errorHandler] 1, 'Your Top-up has been expired. Please contact HO', @controlNo
  474. RETURN
  475. END
  476. END
  477. */
  478. IF EXISTS (
  479. SELECT
  480. 'X'
  481. FROM sendTranLimit
  482. WHERE agentId = @settlingAgent
  483. AND (tranType = @collMode OR tranType IS NULL)
  484. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  485. AND (customerType = @sendingCustType OR customerType IS NULL)
  486. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  487. AND ISNULL(minLimitAmt, 0) > @transferAmt
  488. AND ISNULL(maxLimitAmt, 0) < @transferAmt
  489. AND ISNULL(isActive, 'N') = 'Y'
  490. )
  491. BEGIN
  492. EXEC [proc_errorHandler] 2, 'Agent Sending limit is exceeded.', NULL
  493. RETURN
  494. END
  495. IF NOT EXISTS (
  496. SELECT
  497. 'X'
  498. FROM sendTranLimit
  499. WHERE countryId = @sCountry
  500. AND (tranType = @collMode OR tranType IS NULL)
  501. AND (paymentType = @deliveryMethod OR paymentType IS NULL)
  502. AND (customerType = @sendingCustType OR customerType IS NULL)
  503. AND (receivingCountry = @pCountry OR receivingCountry IS NULL)
  504. AND ISNULL(minLimitAmt, 0) <= @transferAmt
  505. AND ISNULL(maxLimitAmt, 0) >= @transferAmt
  506. AND ISNULL(isActive, 'N') = 'Y'
  507. )
  508. BEGIN
  509. EXEC [proc_errorHandler] 3, 'Country Sending limit is not defined or exceeds.', NULL
  510. RETURN
  511. END
  512. IF @baseCurrency = @receivingCurrencyId
  513. SELECT @xAmt = @pAmt
  514. ELSE
  515. SELECT @xAmt = amount FROM dbo.FNAGetExchangeAmount(@sBranch, @pCountryId, @payoutCurr, @pAmt, @deliveryMethodId, 'C', @user)
  516. --SELECT * FROM receiveTranLimit
  517. --IF NOT EXISTS (
  518. -- SELECT
  519. -- 'X'
  520. -- FROM receiveTranLimit
  521. -- WHERE agentId = @sAgent
  522. -- AND (tranType = @collMode OR tranType IS NULL)
  523. -- AND (customerType = @sendingCustType OR customerType IS NULL)
  524. -- AND currency = @receivingCurrency
  525. -- AND (sendingCountry = @sCountry OR sendingCountry IS NULL)
  526. -- AND ISNULL(limitAmt, 0) >= @pAmt
  527. --)
  528. --BEGIN
  529. -- EXEC [proc_errorHandler] 1, 'Receiving Agent limit is not defined or exceeds.', @controlNo
  530. -- RETURN
  531. --END
  532. IF NOT EXISTS (
  533. SELECT
  534. 'X'
  535. FROM receiveTranLimit
  536. WHERE countryId = @pCountry
  537. AND (tranType = @collMode OR tranType IS NULL)
  538. AND (customerType = @receivingCustType OR customerType IS NULL)
  539. AND (sendingCountry = @sCountry OR sendingCountry IS NULL)
  540. AND ISNULL(maxLimitAmt, 0) >= @pAmt
  541. AND ISNULL(isActive, 'N') = 'Y'
  542. )
  543. BEGIN
  544. EXEC [proc_errorHandler] 1, 'Receiving country limit is not defined or exceeds.', @controlNo
  545. RETURN
  546. END
  547. -----------------------------------------------------------------------------------------------
  548. --7. Exchange Rate Details------------------------------------------------------------------------------------------------------------------
  549. SELECT @id = id FROM dbo.FNAGetExRateForTran(@sBranch, @pBranch, @pCountryId, @collCurr, @payoutCurr, @deliveryMethodId, @user)
  550. IF @id IS NULL
  551. BEGIN
  552. EXEC proc_errorHandler 1, 'Transaction failed. Exchange Rate not defined', NULL
  553. RETURN
  554. END
  555. SELECT
  556. @sCurrCostRate = cCurrCostRate
  557. ,@sCurrHoMargin = cCurrHOMargin
  558. ,@sCurrAgentMargin = cCurrAgentMargin
  559. ,@pCurrCostRate = pCurrCostRate
  560. ,@pCurrHoMargin = pCurrHOMargin
  561. ,@pCurrAgentMargin = pCurrAgentMargin
  562. ,@customerRate = customerCrossRate
  563. FROM dbo.FNAGetCrossRate(@id)
  564. --------------------------------------------------------------------------------------------------------------------------------------------
  565. --7. Service Charge Calculation-------------------------------------------------------------------------------------------------------------
  566. SELECT @iServiceCharge = ISNULL(amount, -1) FROM [dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountryId, @pLocation, @agentId , @deliveryMethodId, @transferAmt, @collCurr)
  567. IF @iServiceCharge = -1
  568. BEGIN
  569. EXEC proc_errorHandler 1, 'Transaction failed. Service Charge is not defined', NULL
  570. RETURN
  571. END
  572. --End of service charge calculation---------------------------------------------------------------------------------------------------------
  573. --Commission Calculation Start
  574. SELECT @sSuperAgentComm = amount, @sSuperAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendCommSA(@sBranch, @pSuperAgent, @pCountryId, NULL, @pBranch, @collCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, NULL)
  575. SELECT @sAgentComm = amount, @sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm(@sBranch, @pSuperAgent, @pCountryId, NULL, @pBranch, @collCurr, @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, @sSuperAgentComm)
  576. IF (@sSuperAgentComm IS NULL OR @sAgentComm IS NULL)
  577. BEGIN
  578. EXEC proc_errorHandler 1, 'Transaction failed. Commission is not defined', NULL
  579. RETURN
  580. END
  581. --Commission Calculation End
  582. --OFAC--------------------------------------------------------------------------------------------------------------------------
  583. DECLARE @csMasterId INT, @complianceRes VARCHAR(20), @ofacRes VARCHAR(MAX), @totalRows INT, @count INT, @compFinalRes VARCHAR(20)
  584. DECLARE @csMasterRec TABLE (rowId INT IDENTITY(1,1), masterId INT)
  585. INSERT @csMasterRec(masterId)
  586. SELECT masterId FROM dbo.FNAGetComplianceRuleMaster(@sBranch, @pCountryId, @pStateId, @pBranch, NULL, @senderId, @benId)
  587. SELECT @totalRows = COUNT(*) FROM @csMasterRec
  588. SELECT @senderName = firstName + ISNULL(' ' + middleName, '') + ISNULL(' ' + lastName1, '') + ISNULL(' ' + lastName2, '')
  589. FROM customers WITH(NOLOCK) WHERE customerId = @senderId
  590. EXEC proc_ofacTracker @flag = 't', @name = @senderName, @Result = @ofacRes OUTPUT
  591. --------------------------------------------------------------------------------------------------------------------------------
  592. BEGIN TRANSACTION
  593. --A/C Master
  594. UPDATE creditLimit SET
  595. todaysSent = todaysSent + ISNULL(@xAmt, 0)
  596. WHERE agentId = @settlingAgent
  597. INSERT INTO remitTran(
  598. controlNo
  599. ,sCurrCostRate
  600. ,sCurrHoMargin
  601. ,pCurrCostRate
  602. ,pCurrHoMargin
  603. ,sCurrAgentMargin
  604. ,pCurrAgentMargin
  605. ,sCurrSuperAgentMargin
  606. ,pCurrSuperAgentMargin
  607. ,customerRate
  608. ,sAgentSettRate
  609. ,pDateCostRate
  610. ,serviceCharge
  611. ,handlingFee
  612. ,sAgentComm
  613. ,sAgentCommCurrency
  614. ,sSuperAgentComm
  615. ,sSuperAgentCommCurrency
  616. ,sHubComm
  617. ,sHubCommCurrency
  618. ,pAgentComm
  619. ,pAgentCommCurrency
  620. ,pSuperAgentComm
  621. ,pSuperAgentCommCurrency
  622. ,pHubComm
  623. ,pHubCommCurrency
  624. ,promotionCode
  625. ,promotionType
  626. ,pMessage
  627. ,sSuperAgent
  628. ,sSuperAgentName
  629. ,sAgent
  630. ,sAgentName
  631. ,sBranch
  632. ,sBranchName
  633. ,sCountry
  634. ,pSuperAgent
  635. ,pSuperAgentName
  636. ,pAgent
  637. ,pAgentName
  638. ,pBranch
  639. ,pBranchName
  640. ,pCountry
  641. ,pState
  642. ,pDistrict
  643. ,pLocation
  644. ,paymentMethod
  645. ,pBank
  646. ,pBankName
  647. ,pBankBranch
  648. ,pBankBranchName
  649. ,accountNo
  650. ,collMode
  651. ,collCurr
  652. ,tAmt
  653. ,cAmt
  654. ,pAmt
  655. ,payoutCurr
  656. ,relWithSender
  657. ,purposeOfRemit
  658. ,sourceOfFund
  659. ,tranStatus
  660. ,payStatus
  661. ,createdDate
  662. ,createdDateLocal
  663. ,createdBy
  664. ,tranType
  665. )
  666. SELECT
  667. @controlNoEncrypted
  668. ,@sCurrCostRate
  669. ,@sCurrHoMargin
  670. ,@pCurrCostRate
  671. ,@pCurrHoMargin
  672. ,@sCurrAgentMargin
  673. ,@pCurrAgentMargin
  674. ,@sCurrSuperAgentMargin
  675. ,@pCurrSuperAgentMargin
  676. ,@customerRate
  677. ,@sAgentSettRate
  678. ,@pDateCostRate
  679. ,@serviceCharge
  680. ,@handlingFee
  681. ,@sAgentComm
  682. ,@sAgentCommCurrency
  683. ,@sSuperAgentComm
  684. ,@sSuperAgentCommCurrency
  685. ,@sHubComm
  686. ,@sHubCommCurrency
  687. ,@pAgentComm
  688. ,@pAgentCommCurrency
  689. ,@pSuperAgentComm
  690. ,@pSuperAgentCommCurrency
  691. ,@pHubComm
  692. ,@pHubCommCurrency
  693. ,@promotionCode
  694. ,@promotionType
  695. ,@remarks
  696. ,@sSuperAgent
  697. ,@sSuperAgentName
  698. ,@sAgent
  699. ,@sAgentName
  700. ,@sBranch
  701. ,@sBranchName
  702. ,@sCountry
  703. ,@pSuperAgent
  704. ,@pSuperAgentName
  705. ,@pAgent
  706. ,@pAgentName
  707. ,@pBranch
  708. ,@pBranchName
  709. ,@pCountry
  710. ,@pState
  711. ,@pDistrict
  712. ,@pLocation
  713. ,@deliveryMethod
  714. ,@pBank
  715. ,@pBankName
  716. ,@pBankBranch
  717. ,@pBankBranchName
  718. ,@accountNo
  719. ,@collMode
  720. ,@collCurr
  721. ,@transferAmt
  722. ,@cAmt
  723. ,@pAmt
  724. ,@payoutCurr
  725. ,@relationship
  726. ,@purpose
  727. ,@sourceOfFund
  728. ,'Hold'
  729. ,'Unpaid'
  730. ,GETDATE()
  731. ,DBO.FNADateFormatTZ(GETDATE(), @user)
  732. ,@user
  733. ,'I'
  734. SET @id = SCOPE_IDENTITY()
  735. INSERT INTO tranSenders(
  736. tranId
  737. ,customerId
  738. ,membershipId
  739. ,firstName
  740. ,middleName
  741. ,lastName1
  742. ,lastName2
  743. ,country
  744. ,[address]
  745. ,[state]
  746. ,zipCode
  747. ,city
  748. ,email
  749. ,homePhone
  750. ,workPhone
  751. ,mobile
  752. ,nativeCountry
  753. ,dob
  754. ,placeOfIssue
  755. ,idType
  756. ,idNumber
  757. ,idPlaceOfIssue
  758. ,issuedDate
  759. ,validDate
  760. )
  761. SELECT
  762. @id
  763. ,@senderId
  764. ,membershipId
  765. ,firstName
  766. ,middleName
  767. ,lastName1
  768. ,lastName2
  769. ,sc.countryName
  770. ,[address]
  771. ,ss.stateName
  772. ,zipCode
  773. ,city
  774. ,email
  775. ,homePhone
  776. ,workPhone
  777. ,mobile
  778. ,nativeCountry = nc.countryName
  779. ,dob
  780. ,c.placeOfIssue
  781. ,sdv.detailTitle
  782. ,ci.idNumber
  783. ,ci.PlaceOfIssue
  784. ,ci.issuedDate
  785. ,ci.validDate
  786. FROM customers c WITH(NOLOCK)
  787. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON c.customerId = ci.customerId AND ci.isPrimary = 'Y' AND ISNULL(ci.isDeleted,'N')<>'Y'
  788. LEFT JOIN countryMaster sc WITH(NOLOCK) ON c.country = sc.countryId
  789. LEFT JOIN countryMaster nc WITH(NOLOCK) ON c.nativeCountry = nc.countryId
  790. LEFT JOIN countryStateMaster ss WITH(NOLOCK) ON c.state = ss.stateId
  791. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON ci.idType = sdv.valueId
  792. WHERE c.customerId = @senderId
  793. INSERT INTO tranReceivers(
  794. tranId
  795. ,customerId
  796. ,membershipId
  797. ,firstName
  798. ,middleName
  799. ,lastName1
  800. ,lastName2
  801. ,country
  802. ,[address]
  803. ,[state]
  804. ,zipCode
  805. ,city
  806. ,email
  807. ,homePhone
  808. ,workPhone
  809. ,mobile
  810. ,nativeCountry
  811. ,dob
  812. ,placeOfIssue
  813. ,idType
  814. ,idNumber
  815. ,idPlaceOfIssue
  816. ,issuedDate
  817. ,validDate
  818. )
  819. SELECT
  820. @id
  821. ,@benId
  822. ,membershipId
  823. ,firstName
  824. ,middleName
  825. ,lastName1
  826. ,lastName2
  827. ,sc.countryName
  828. ,[address]
  829. ,ss.stateName
  830. ,zipCode
  831. ,city
  832. ,email
  833. ,homePhone
  834. ,workPhone
  835. ,mobile
  836. ,nativeCountry = nc.countryName
  837. ,dob
  838. ,c.placeOfIssue
  839. ,sdv.detailTitle
  840. ,ci.idNumber
  841. ,ci.PlaceOfIssue
  842. ,ci.issuedDate
  843. ,ci.validDate
  844. FROM customers c WITH(NOLOCK)
  845. LEFT JOIN customerIdentity ci WITH(NOLOCK) ON c.customerId = ci.customerId AND ci.isPrimary = 'Y' AND ISNULL(ci.isDeleted,'N')<>'Y'
  846. LEFT JOIN countryMaster sc WITH(NOLOCK) ON c.country = sc.countryId
  847. LEFT JOIN countryMaster nc WITH(NOLOCK) ON c.nativeCountry = nc.countryId
  848. LEFT JOIN countryStateMaster ss WITH(NOLOCK) ON c.state = ss.stateId
  849. LEFT JOIN staticDataValue sdv WITH(NOLOCK) ON ci.idType = sdv.valueId
  850. WHERE c.customerId = @benId
  851. --10. Compliance----------------------------------------------------------------------------------------------------
  852. SET @count = 1
  853. WHILE(@count <= @totalRows)
  854. BEGIN
  855. SELECT @csMasterId = masterId FROM @csMasterRec WHERE rowId = @count
  856. EXEC proc_complianceRuleDetail @user, @id, @transferAmt, @senderId, @benId, @accountNo, @csMasterId, @deliveryMethodId, @complianceRes OUTPUT
  857. SET @compFinalRes = @compFinalRes + @complianceRes
  858. SET @count = @count + 1
  859. END
  860. IF(@compFinalRes <> '' OR @ofacRes <> '')
  861. BEGIN
  862. IF(@ofacRes <> '')
  863. BEGIN
  864. INSERT remitTranOfac(TranId, blackListId)
  865. SELECT @id, @ofacRes
  866. END
  867. UPDATE remitTran SET
  868. tranStatus = 'Compliance'
  869. WHERE controlNo = @controlNoEncrypted
  870. END
  871. ELSE
  872. BEGIN
  873. --11.Check User Approve Limit---------------------------------------------------------------------------------------
  874. DECLARE @userId INT, @sendLimit MONEY, @payLimit MONEY, @approveFlag CHAR(1)
  875. SELECT @userId = userId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  876. SELECT @sendLimit = ISNULL(sendLimit, 0) FROM userLimit WITH(NOLOCK)
  877. WHERE userId = @userId
  878. AND ISNULL(isDeleted, 'N') <> 'Y'
  879. AND ISNULL(isActive, 'N') = 'Y'
  880. AND ISNULL(isEnable, 'N') = 'Y'
  881. IF @sendLimit > @transferAmt
  882. BEGIN
  883. SET @approveFlag = 'Y'
  884. UPDATE remitTran SET
  885. tranStatus = 'Payment' --Payment
  886. ,approvedBy = @user
  887. ,approvedDate = GETDATE()
  888. ,approvedDateLocal = DBO.FNADateFormatTZ(GETDATE(), @user)
  889. WHERE controlNo = @controlNoEncrypted
  890. END
  891. --End of Approve Limit Checking
  892. END
  893. IF @@TRANCOUNT > 0
  894. COMMIT TRANSACTION
  895. IF(@complianceRes = 'C' OR @ofacRes <> '')
  896. BEGIN
  897. EXEC proc_errorHandler 101, 'Transaction under compliance', @controlNo
  898. RETURN
  899. END
  900. IF @approveFlag = 'Y'
  901. EXEC [proc_errorHandler] 0, 'Transaction has been sent successfully', @controlNo
  902. ELSE
  903. EXEC [proc_errorHandler] 100, 'Transaction waiting for approval', @controlNo
  904. END
  905. ELSE IF @flag = 'u'
  906. BEGIN
  907. UPDATE remitTran SET
  908. modifiedDate = GETDATE()
  909. ,modifiedDateLocal = DBO.FNADateFormatTZ(GETDATE(), @user)
  910. ,modifiedBy = @user
  911. WHERE id = @id
  912. END
  913. ELSE IF @flag = 'a'
  914. BEGIN
  915. SELECT * FROM remitTran WITH(NOLOCK) WHERE id = @id
  916. END
  917. ELSE IF @flag = 'exRate'
  918. BEGIN
  919. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  920. SELECT customerCrossRate = CAST(ISNULL(customerCrossRate, 0) AS DECIMAL(11, 6)) FROM dbo.FNAGetExRateForTran(@sBranch, @pBranch, @pCountry, @collCurr, @payoutCurr, @deliveryMethod, @user)
  921. END
  922. ELSE IF @flag = 'sc'
  923. BEGIN
  924. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @pCountry
  925. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod
  926. --EXEC proc_sendTransactionLoadData @flag = 'sc', @amount= '100000', @pLocation = '109'
  927. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  928. SELECT SC = ISNULL(amount, -1) FROM [dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountryId, @pLocation, @agentId , @deliveryMethodId, @transferAmt, @collCurr)
  929. END
  930. ELSE IF @flag = 'scTBL'
  931. BEGIN
  932. SELECT @pCountryId = countryId FROM countryMaster WITH(NOLOCK) WHERE countryName = @pCountry
  933. DECLARE
  934. @masterId INT
  935. ,@masterType CHAR(1)
  936. ,@sc MONEY
  937. IF @sBranch IS NULL
  938. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  939. SELECT @deliveryMethodId = serviceTypeId FROM serviceTypeMaster WITH(NOLOCK) WHERE typeTitle = @deliveryMethod
  940. IF @deliveryMethod = 'Bank Deposit'
  941. BEGIN
  942. SELECT @pLocation = agentLocation FROM agentMaster WITH(NOLOCK) WHERE agentId = @pBankBranch
  943. END
  944. SELECT
  945. @masterId = masterId
  946. ,@masterType = masterType
  947. ,@sc = amount
  948. FROM [dbo].FNAGetSC(@sBranch, @pSuperAgent, @pCountryId, @pLocation, @agentId , @deliveryMethodId, @transferAmt, @collCurr)
  949. IF(@masterType = 'S')
  950. BEGIN
  951. SELECT fromAmt, toAmt, pcnt, maxAmt, minAmt FROM sscDetail WHERE sscMasterId = @masterId
  952. END
  953. ELSE
  954. BEGIN
  955. SELECT fromAmt, toAmt, pcnt, maxAmt, minAmt FROM dscDetail WHERE dscMasterId = @masterId
  956. END
  957. END
  958. ELSE IF @flag = 'cti' --All transaction information (sender, receiver, payout)
  959. BEGIN
  960. SELECT DISTINCT
  961. c.customerId
  962. ,c.membershipId
  963. ,Name = c.firstName + ISNULL(' ' + c.middleName, '') + ISNULL(' ' + c.lastName1, '') + ISNULL(' ' + c.lastName2, '')
  964. ,Country = ccm.countryName
  965. ,Address
  966. ,[State]
  967. ,Phone = COALESCE(mobile, homePhone, workPhone)
  968. ,city
  969. FROM customers c WITH(NOLOCK)
  970. LEFT JOIN countryMaster ccm WITH(NOLOCK) ON c.country = ccm.countryId
  971. WHERE c.customerId = @senderId
  972. SELECT DISTINCT
  973. c.customerId
  974. ,c.membershipId
  975. ,Name = c.firstName + ISNULL( ' ' + c.middleName, '') + ISNULL( ' ' + c.lastName1, '') + ISNULL( ' ' + c.lastName2, '')
  976. ,Country = ccm.countryName
  977. ,Address
  978. ,[State]
  979. ,Phone = COALESCE(mobile, homePhone, workPhone)
  980. ,city
  981. FROM customers c WITH(NOLOCK)
  982. LEFT JOIN countryMaster ccm WITH(NOLOCK) ON c.country = ccm.countryId
  983. WHERE c.customerId = @benId
  984. IF @agentId > 0
  985. BEGIN
  986. SELECT
  987. DISTINCT
  988. am.agentId
  989. ,am.agentCode
  990. ,name = am.agentName
  991. ,address = am.agentAddress
  992. ,city = agentCity
  993. ,[State] = agentState
  994. ,Phone = COALESCE(agentMobile1, agentMobile2, agentPhone1, agentPhone2)
  995. ,Country = @pCountry
  996. FROM agentMaster am WITH(NOLOCK)
  997. LEFT JOIN agentCurrency ac WITH(NOLOCK) ON am.agentId = ac.agentId
  998. WHERE am.agentId = @agentId
  999. END
  1000. ELSE
  1001. BEGIN
  1002. SELECT
  1003. agentId = NULL
  1004. ,agentCode = NULL
  1005. ,name = 'Any'
  1006. ,address = NULL
  1007. ,city = NULL
  1008. ,state = NULL
  1009. ,Phone = NULL
  1010. ,country = @pCountry
  1011. END
  1012. END
  1013. ELSE IF @flag = 'pcl'
  1014. BEGIN
  1015. SELECT DISTINCT
  1016. cm.countryId
  1017. ,cm.countryName
  1018. FROM countryMaster cm
  1019. INNER JOIN rsList1 rsl ON cm.countryId = rsl.rsCountryId AND roleType = 's' AND listType <> 'ex'
  1020. WHERE agentId = 3882 OR rsCountryId = 151
  1021. END
  1022. ELSE IF @flag = 'scl' --Sender Country List
  1023. BEGIN
  1024. SELECT @sBranch = agentId FROM applicationUsers WITH(NOLOCK) WHERE userName = @user
  1025. SELECT
  1026. countryId
  1027. ,countryName
  1028. FROM countryMaster cm
  1029. INNER JOIN agentMaster am WITH(NOLOCK) ON cm.countryId = am.agentCountryId
  1030. WHERE am.agentId = @sBranch
  1031. END
  1032. ELSE IF @flag = 'controlNo'
  1033. BEGIN
  1034. SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo)
  1035. SELECT
  1036. senderId = sen.customerId
  1037. ,benId = ben.customerId
  1038. ,pCountry = cm.countryId
  1039. ,deliveryMethod = stm.serviceTypeId
  1040. ,tAmt = trn.tAmt
  1041. ,cAmt = trn.cAmt
  1042. ,pAmt = trn.pAmt
  1043. ,customerRate = trn.customerRate
  1044. ,serviceCharge = trn.serviceCharge
  1045. ,trn.collCurr
  1046. ,trn.payoutCurr
  1047. ,agentId = pBranch
  1048. FROM remitTran trn WITH(NOLOCK)
  1049. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  1050. INNER JOIN tranReceivers ben WITH(NOLOCK) ON trn.id = ben.tranId
  1051. INNER JOIN countryMaster cm WITH(NOLOCK) ON trn.pCountry = cm.countryName
  1052. INNER JOIN serviceTypeMaster stm WITH(NOLOCK) ON trn.paymentMethod = stm.typeTitle
  1053. WHERE controlNo = @controlNoEncrypted
  1054. END
  1055. ELSE IF @flag = 'senderId'
  1056. BEGIN
  1057. SELECT TOP 1
  1058. senderId = sen.customerId
  1059. ,benId = ben.customerId
  1060. ,pCountry = cm.countryId
  1061. ,deliveryMethod = stm.serviceTypeId
  1062. ,tAmt = trn.tAmt
  1063. ,cAmt = trn.cAmt
  1064. ,pAmt = trn.pAmt
  1065. ,customerRate = trn.customerRate
  1066. ,serviceCharge = trn.serviceCharge
  1067. ,trn.collCurr
  1068. ,trn.payoutCurr
  1069. ,agentId = pBranch
  1070. FROM remitTran trn WITH(NOLOCK)
  1071. INNER JOIN tranSenders sen WITH(NOLOCK) ON trn.id = sen.tranId
  1072. INNER JOIN tranReceivers ben WITH(NOLOCK) ON trn.id = ben.tranId
  1073. INNER JOIN countryMaster cm WITH(NOLOCK) ON trn.pCountry = cm.countryName
  1074. INNER JOIN serviceTypeMaster stm WITH(NOLOCK) ON trn.paymentMethod = stm.typeTitle
  1075. WHERE sen.customerId = @senderId ORDER BY trn.id DESC
  1076. END
  1077. END
  1078. GO