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.

607 lines
48 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_GetExRate_Default] Script Date: 7/4/2019 11:35:48 AM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. CREATE OR ALTER proc [dbo].[proc_GetExRate_Default]
  9. @flag VARCHAR(20),
  10. @user VARCHAR(150) = NULL,
  11. @pCountryId INT = NULL,
  12. @pCurr VARCHAR(5),
  13. @deliveryMethod VARCHAR(20),
  14. @cAmt MONEY,
  15. @pAmt MONEY,
  16. @calBy CHAR(1),
  17. @agentRefId VARCHAR(50) = NULL,
  18. @pCountry VARCHAR(50),
  19. @tpExRate FLOAT = NULL,
  20. @tpPCurr VARCHAR(5) = NULL
  21. AS
  22. SET NOCOUNT ON ;
  23. declare @payOutPartner bigint
  24. declare @sCountryId int=118,@sAgent int=2080,@sSuperAgent int=1008 ,@sBranch int ,@collCurr varchar(5)='KRW'
  25. DECLARE @scValue MONEY,@exRateOffer MONEY,@scDiscount MONEY ,@AmountLimitPerTran MONEY,@AmountLimitPerDay MONEY
  26. DECLARE @place INT,@currDecimal INT,@exRate DECIMAL(30,9),@serviceCharge MONEY,@tAmt MONEY
  27. DECLARE @pSuperAgent INT,@pSuperAgentName VARCHAR(200),@pAgent BIGINT,@pAgentName VARCHAR(200),@pBranch INT,@pBranchName VARCHAR(200)
  28. DECLARE @errorCode INT,@msg VARCHAR(MAX)
  29. IF @pCountryId IS NULL
  30. select @pCountryId = countryId from countryMaster(nolock) where countryName = @pCountry
  31. SELECT @payOutPartner = AgentId FROM TblPartnerwiseCountry (NOLOCK)
  32. WHERE COUNTRYID = @pCountryId
  33. AND ISNULL(PaymentMethod, @deliveryMethod) = @deliveryMethod
  34. AND IsActive = 1
  35. SELECT TOP 1 @pAgent = AM.agentId
  36. FROM agentMaster AM(NOLOCK)
  37. WHERE AM.parentId = @payOutPartner AND agentType=2903 AND AM.isSettlingAgent = 'Y' AND AM.isApiPartner = 1
  38. SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName,
  39. @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName
  40. FROM dbo.FNAGetBranchFullDetails(@pAgent)
  41. IF @flag = 'exRate'
  42. BEGIN
  43. IF @payOutPartner IN (224388,2140,393227,415207,393865,585209) and @pCurr <>'USD' --## TANGLO,MTRADE,QIWI CONTACT
  44. BEGIN
  45. SELECT '5' ErrorCode , 'Thirdparty transaction' Msg , PayoutPartner = @payOutPartner, pCountryId = @pCountryId
  46. RETURN;
  47. END;
  48. IF @payOutPartner IS NULL
  49. BEGIN
  50. SELECT '1' ErrorCode ,
  51. 'Service is currently not available' Msg ,
  52. PayoutPartner = @payOutPartner
  53. RETURN;
  54. END;
  55. SELECT @scValue = 0 ,
  56. @exRateOffer = 0 ,
  57. @scDiscount = 0 ,
  58. @AmountLimitPerTran = 3000,
  59. @AmountLimitPerDay = 20000
  60. SELECT @place = place ,
  61. @currDecimal = currDecimal
  62. FROM currencyPayoutRound(NOLOCK)
  63. WHERE ISNULL(isDeleted, 'N') = 'N'
  64. AND currency = @pCurr AND (tranType IS NULL OR tranType = @deliveryMethod);
  65. SET @currDecimal = ISNULL(@currDecimal, 0);
  66. IF @pCurr IS NULL
  67. BEGIN
  68. SELECT '1' ErrorCode ,
  69. 'Currency not been defined yet for receiving country' Msg ,
  70. amountLimitPerDay = @AmountLimitPerDay ,
  71. customerTotalSentAmt = 0 ,
  72. maxAmountLimitPerTran = @AmountLimitPerTran ,
  73. PerTxnMinimumAmt = @AmountLimitPerDay;
  74. RETURN;
  75. END;
  76. SELECT @exRate =
  77. dbo.FNAGetCustomerRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent, @pCurr,@deliveryMethod);
  78. DECLARE @sAgentSettRate MONEY
  79. SELECT @sAgentSettRate = sAgentSettRate FROM DBO.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethod)
  80. ----## FOR RIA AND CONTACT "LOG" GET ONE TIME RATE FROM PARTNER AND STORE IN TABLE ,"SYSTEM" IS FOR GME RATE,"PARTNER" GET RATE FROM PARTNER END REALTIME
  81. IF EXISTS(SELECT 'X' FROM TblPartnerwiseCountry(NOLOCK) WHERE AgentId = @payOutPartner AND PaymentMethod = @deliveryMethod AND IsActive = 1 AND GetRateFrom='Log'
  82. AND CountryId = @pCountryId)
  83. BEGIN
  84. SET @exRate = NULL
  85. SELECT TOP 1 @exRate = CurrCostRate,@tpPCurr = @pCurr FROM TBL_PARTNER_COST_RATE(NOLOCK)
  86. WHERE ProviderId = @payOutPartner AND GETDATE() BETWEEN EffectiveFrom AND EffectiveTo
  87. AND ToCurr = @pCurr AND FromCurr = 'USD' ORDER BY CreatedDate desc
  88. IF ISNULL(@exRate, 0) = 0
  89. BEGIN
  90. SELECT '5' ErrorCode , 'Thirdparty transaction' Msg , PayoutPartner = @payOutPartner, pCountryId = @pCountryId
  91. RETURN;
  92. END
  93. SELECT @exRate = round(@exRate/@sAgentSettRate, 10)
  94. END
  95. IF @exRate IS NULL
  96. BEGIN
  97. SELECT '1' ErrorCode ,
  98. 'Exchange rate not defined yet for receiving currency ('+ @pCurr + ')' Msg ,
  99. amountLimitPerDay = @AmountLimitPerDay ,
  100. customerTotalSentAmt = 0 ,
  101. maxAmountLimitPerTran = @AmountLimitPerTran ,
  102. PerTxnMinimumAmt = @AmountLimitPerDay;
  103. RETURN;
  104. END;
  105. IF @calBy = 'C'
  106. BEGIN
  107. IF @pCountryId = 36
  108. BEGIN
  109. SET @pAmt = @cAmt * @exRate
  110. SELECT @serviceCharge = amount
  111. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  112. @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr);
  113. END
  114. --ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  115. --BEGIN
  116. -- SELECT @serviceCharge = amount
  117. -- FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  118. -- @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD');
  119. --END
  120. ELSE
  121. BEGIN
  122. SELECT @serviceCharge = amount
  123. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  124. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,@cAmt,@collCurr);
  125. END
  126. IF @serviceCharge IS NULL
  127. BEGIN
  128. SELECT '1' ErrorCode ,
  129. 'Service charge not defined yet for receiving country' Msg ,
  130. amountLimitPerDay = @AmountLimitPerDay ,
  131. customerTotalSentAmt = 0 ,
  132. maxAmountLimitPerTran = @AmountLimitPerTran ,
  133. PerTxnMinimumAmt = @AmountLimitPerDay;
  134. RETURN;
  135. END;
  136. SET @tAmt = @cAmt - @serviceCharge;
  137. SET @pAmt = ( @cAmt-@serviceCharge ) * @exRate
  138. SET @pAmt = ROUND(@pAmt,@currDecimal)
  139. END;
  140. ELSE
  141. IF @calBy = 'P'
  142. BEGIN
  143. SET @tAmt = @pAmt / @exRate
  144. IF @pCountryId = 36
  145. BEGIN
  146. SELECT @serviceCharge = amount
  147. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  148. @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr);
  149. END
  150. --ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  151. --BEGIN
  152. -- SELECT @serviceCharge = amount
  153. -- FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  154. -- @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD');
  155. --END
  156. ELSE
  157. BEGIN
  158. SELECT @serviceCharge = amount
  159. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  160. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,
  161. @tAmt, @collCurr);
  162. END
  163. IF @serviceCharge IS NULL
  164. BEGIN
  165. SELECT '1' ErrorCode ,
  166. 'Service charge not defined yet for receiving country' Msg ,
  167. amountLimitPerDay = @AmountLimitPerDay ,
  168. customerTotalSentAmt = 0 ,
  169. maxAmountLimitPerTran = @AmountLimitPerTran ,
  170. PerTxnMinimumAmt = @AmountLimitPerDay;
  171. RETURN;
  172. END;
  173. SET @tAmt = ROUND(@tAmt, 2);
  174. SET @cAmt = ( @tAmt + @serviceCharge);
  175. SET @cAmt = ROUND(@cAmt, 0);
  176. END;
  177. IF @serviceCharge > @cAmt
  178. BEGIN
  179. SELECT '1' ErrorCode ,
  180. 'COLLECTION AMOUNT SHOULD BE MORE THAN SERVICE CHARGE' Msg ,
  181. amountLimitPerDay = @AmountLimitPerDay ,
  182. customerTotalSentAmt = 0 ,
  183. maxAmountLimitPerTran = @AmountLimitPerTran ,
  184. PerTxnMinimumAmt = @AmountLimitPerDay;
  185. RETURN;
  186. END;
  187. --SELECT cAmt = @tAmt, pAmt = @pAmt, sCountryId = @sCountryId, collMode = NULL
  188. -- ,deliveryMethod = @deliveryMethod,sendingCustType = NULL,pCountryId = @pCountryId,pCurr = @pCurr, collCurr = @collCurr
  189. -- ,pAgent = @pAgent, sAgent = @sAgent, sBranch = @sBranch
  190. --4. Validate Country Sending Limit
  191. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit', @cAmt = @tAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = NULL
  192. ,@deliveryMethod = @deliveryMethod,@sendingCustType = NULL,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  193. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  194. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  195. IF @errorCode <> '0'
  196. BEGIN
  197. SELECT @errorCode ErrorCode ,
  198. @msg Msg ,
  199. amountLimitPerDay = @AmountLimitPerDay ,
  200. customerTotalSentAmt = 0 ,
  201. maxAmountLimitPerTran = @AmountLimitPerTran ,
  202. PerTxnMinimumAmt = @AmountLimitPerDay;
  203. RETURN;
  204. END
  205. --Validate Country Sending Limit END
  206. --5. Validate Country Receiving Limit
  207. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = NULL
  208. ,@deliveryMethod = @deliveryMethod,@sendingCustType = NULL,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  209. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  210. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  211. IF @errorCode <> '0'
  212. BEGIN
  213. SELECT @errorCode ErrorCode ,
  214. @msg Msg ,
  215. amountLimitPerDay = @AmountLimitPerDay ,
  216. customerTotalSentAmt = 0 ,
  217. maxAmountLimitPerTran = @AmountLimitPerTran ,
  218. PerTxnMinimumAmt = @AmountLimitPerDay;
  219. RETURN;
  220. END
  221. --Validate Country Receiving Limit
  222. --End of Limit Checking------------------------------------------------------------------------------------------------------------
  223. SET @msg = 'Success';
  224. ---------Compliance Checking Begin--------------------------------
  225. DECLARE @complianceRuleId INT, @cAmtUSD MONEY,@sCurrCostRate MONEY,@sCurrHoMargin MONEY
  226. SELECT
  227. @sCurrCostRate = sCurrCostRate
  228. ,@sCurrHoMargin = sCurrHoMargin
  229. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  230. IF @sCurrCostRate IS NULL
  231. BEGIN
  232. SELECT @errorCode = '1', @msg = 'Transaction cannot be proceed. Exchange Rate not defined!'
  233. RETURN
  234. END
  235. SET @cAmtUSD = @cAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
  236. DECLARE
  237. @receiverName VARCHAR(50) = NULL
  238. ,@complienceMessage varchar(1000) =NULL
  239. ,@shortMsg varchar(100) =NULL
  240. ,@complienceErrorCode TINYINT = NULL
  241. --Bank compare
  242. DECLARE @bankName VARCHAR(25) = 'Bank', @bankRate MONEY, @bankPayout MONEY, @bankFee MONEY
  243. , @bankSave MONEY, @bankTransafer MONEY
  244. SELECT @bankRate = customerRate, @bankFee = serviceCharge FROM bankTransferSettings(NOLOCK)
  245. SELECT @bankTransafer = @cAmt - @bankFee
  246. SELECT @bankPayout = @bankTransafer * @bankRate
  247. SELECT @bankSave = @pAmt - @bankPayout
  248. SELECT ErrorCode = @errorCode ,
  249. Msg = @msg ,
  250. Id = NULL,
  251. scCharge = @serviceCharge ,
  252. exRateDisplay = ROUND(@exRate , 4, -1),
  253. exRate = @exRate,
  254. place = @place ,
  255. pCurr = @pCurr ,
  256. currDecimal = @currDecimal ,
  257. pAmt = @pAmt ,
  258. sAmt = ROUND(@tAmt, 0) ,
  259. disc = 0.00 ,
  260. --bank data
  261. bankTransafer = @bankTransafer,
  262. bankPayout = @bankPayout,
  263. bankRate = @bankRate,
  264. bankFee = @bankFee,
  265. bankSave = @bankSave,
  266. bankName = @bankName,
  267. collAmt = @cAmt ,
  268. collCurr = @collCurr,
  269. exRateOffer = @exRateOffer ,
  270. scOffer = @scDiscount ,
  271. scAction = NULL ,
  272. scValue = @scValue ,
  273. scDiscount = @scDiscount ,
  274. amountLimitPerTran = @AmountLimitPerTran ,
  275. amountLimitPerDay = @AmountLimitPerDay ,
  276. customerTotalSentAmt = 0 ,
  277. minAmountLimitPerTran = @AmountLimitPerTran ,
  278. maxAmountLimitPerTran = @AmountLimitPerDay ,
  279. PerTxnMinimumAmt = '',
  280. tpExRate = @exRate,
  281. tpPCurr = @pCurr,
  282. schemeAppliedMsg = '',
  283. schemeId = 0
  284. END;
  285. ELSE IF @flag = 'exRate_TP'
  286. BEGIN
  287. SELECT @scValue = 0 ,
  288. @exRateOffer = 0 ,
  289. @scDiscount = 0 ,
  290. @AmountLimitPerTran = 3000,
  291. @AmountLimitPerDay = 20000
  292. SELECT @place = place ,
  293. @currDecimal = currDecimal
  294. FROM currencyPayoutRound(NOLOCK)
  295. WHERE ISNULL(isDeleted, 'N') = 'N'
  296. AND currency = @pCurr AND (tranType IS NULL OR tranType = @deliveryMethod);
  297. IF @pCountryId IS NULL
  298. SELECT @pCountryId = countryId FROM countryMaster (NOLOCK) WHERE countryName = @pCountry
  299. SET @currDecimal = ISNULL(@currDecimal, 0);
  300. IF @pCurr IS NULL
  301. BEGIN
  302. SELECT '1' ErrorCode ,
  303. 'Currency not been defined yet for receiving country' Msg ,
  304. amountLimitPerDay = @AmountLimitPerDay ,
  305. customerTotalSentAmt = 0 ,
  306. maxAmountLimitPerTran = @AmountLimitPerTran ,
  307. PerTxnMinimumAmt = @AmountLimitPerDay;
  308. RETURN;
  309. END;
  310. SELECT @sAgentSettRate = sAgentSettRate FROM DBO.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethod)
  311. IF ISNULL(@sAgentSettRate, 0) = 0
  312. BEGIN
  313. SELECT '1' ErrorCode ,
  314. 'Exchange rate not defined yet for sending currency (' + @collCurr + ')' Msg ,
  315. amountLimitPerDay = @AmountLimitPerDay ,
  316. customerTotalSentAmt = 0 ,
  317. maxAmountLimitPerTran = @AmountLimitPerTran ,
  318. PerTxnMinimumAmt = @AmountLimitPerDay;
  319. RETURN
  320. END
  321. ----## FOR RIA AND CONTACT "LOG" GET ONE TIME RATE FROM PARTNER AND STORE IN TABLE ,"SYSTEM" IS FOR GME RATE,"PARTNER" GET RATE FROM PARTNER END REALTIME
  322. IF EXISTS(SELECT 'X' FROM TblPartnerwiseCountry(NOLOCK) WHERE AgentId = @payOutPartner AND PaymentMethod = @deliveryMethod AND IsActive = 1 AND GetRateFrom='Log')
  323. BEGIN
  324. SELECT TOP 1 @tpExRate = CurrCostRate,@tpPCurr = @pCurr FROM TBL_PARTNER_COST_RATE(NOLOCK)
  325. WHERE ProviderId = @payOutPartner AND GETDATE() BETWEEN EffectiveFrom AND EffectiveTo
  326. AND ToCurr = @pCurr AND FromCurr = 'USD' ORDER BY CreatedDate desc
  327. IF ISNULL(@tpExRate, 0) = 0
  328. BEGIN
  329. SELECT '5' ErrorCode , 'Thirdparty transaction' Msg , PayoutPartner = @payOutPartner, pCountryId = @pCountryId
  330. RETURN
  331. END
  332. END
  333. ELSE IF EXISTS(SELECT 'X' FROM TblPartnerwiseCountry(NOLOCK)
  334. WHERE AgentId = @payOutPartner AND PaymentMethod = @deliveryMethod AND IsActive = 1 AND GetRateFrom='LIVE' AND PartnerRate = 1)
  335. BEGIN
  336. IF ISNULL(@tpExRate, 0) = 0
  337. BEGIN
  338. SELECT '5' ErrorCode , 'Thirdparty transaction' Msg , PayoutPartner = @payOutPartner, pCountryId = @pCountryId
  339. RETURN
  340. END
  341. END
  342. --IF ISNULL(@tpExRate, 0) = 0
  343. --BEGIN
  344. -- SELECT '1' ErrorCode ,
  345. -- 'Third Party Exchange rate fetching error for currency (' + @pCurr + ')' Msg ,
  346. -- amountLimitPerDay = @AmountLimitPerDay ,
  347. -- customerTotalSentAmt = 0 ,
  348. -- maxAmountLimitPerTran = @AmountLimitPerTran ,
  349. -- PerTxnMinimumAmt = @AmountLimitPerDay;
  350. -- RETURN
  351. --END
  352. IF @tpExRate IS NOT NULL
  353. SELECT @exRate = round(@tpExRate/@sAgentSettRate, 10)
  354. ELSE
  355. SELECT @exRate = dbo.FNAGetCustomerRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent, @pCurr,@deliveryMethod);
  356. IF @exRate IS NULL
  357. BEGIN
  358. SELECT '1' ErrorCode ,
  359. 'Exchange rate not defined yet for receiving currency ('+ @pCurr + ')' Msg ,
  360. amountLimitPerDay = @AmountLimitPerDay ,
  361. customerTotalSentAmt = 0 ,
  362. maxAmountLimitPerTran = @AmountLimitPerTran ,
  363. PerTxnMinimumAmt = @AmountLimitPerDay;
  364. RETURN;
  365. END;
  366. IF @calBy = 'C'
  367. BEGIN
  368. SELECT @serviceCharge = amount
  369. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  370. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,@cAmt,@collCurr);
  371. IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  372. BEGIN
  373. SELECT @serviceCharge = amount
  374. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  375. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,@cAmt,'USD');
  376. END
  377. IF @serviceCharge IS NULL
  378. BEGIN
  379. SELECT '1' ErrorCode ,
  380. 'Service charge not defined yet for receiving country' Msg ,
  381. amountLimitPerDay = @AmountLimitPerDay ,
  382. customerTotalSentAmt = 0 ,
  383. maxAmountLimitPerTran = @AmountLimitPerTran ,
  384. PerTxnMinimumAmt = @AmountLimitPerDay;
  385. RETURN;
  386. END;
  387. SET @tAmt = @cAmt - @serviceCharge+ @scDiscount;
  388. SET @pAmt = ( @cAmt - @serviceCharge+ @scDiscount ) * ( @exRate+ @exRateOffer );
  389. SET @pAmt = ROUND(@pAmt,0)
  390. END;
  391. ELSE
  392. IF @calBy = 'P'
  393. BEGIN
  394. SET @tAmt = @pAmt / ( @exRate+ @exRateOffer );
  395. SELECT @serviceCharge = amount
  396. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  397. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,
  398. @tAmt, @collCurr);
  399. IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2
  400. BEGIN
  401. SELECT @serviceCharge = amount
  402. FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch,
  403. @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,
  404. @tAmt, 'USD');
  405. END
  406. IF @serviceCharge IS NULL
  407. BEGIN
  408. SELECT '1' ErrorCode ,
  409. 'Service charge not defined yet for receiving country' Msg ,
  410. amountLimitPerDay = @AmountLimitPerDay ,
  411. customerTotalSentAmt = 0 ,
  412. maxAmountLimitPerTran = @AmountLimitPerTran ,
  413. PerTxnMinimumAmt = @AmountLimitPerDay;
  414. RETURN;
  415. END;
  416. SET @tAmt = ROUND(@tAmt, 2);
  417. SET @cAmt = ( @tAmt + @serviceCharge - @scDiscount );
  418. SET @cAmt = ROUND(@cAmt, 0);
  419. END;
  420. IF @serviceCharge > @cAmt
  421. BEGIN
  422. SELECT '1' ErrorCode ,
  423. 'COLLECTION AMOUNT SHOULD BE MORE THAN SERVICE CHARGE' Msg ,
  424. amountLimitPerDay = @AmountLimitPerDay ,
  425. customerTotalSentAmt = 0 ,
  426. maxAmountLimitPerTran = @AmountLimitPerTran ,
  427. PerTxnMinimumAmt = @AmountLimitPerDay;
  428. RETURN;
  429. END;
  430. --4. Validate Country Sending Limit
  431. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = NULL
  432. ,@deliveryMethod = @deliveryMethod,@sendingCustType = NULL,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  433. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  434. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  435. IF @errorCode <> '0'
  436. BEGIN
  437. SELECT @errorCode ErrorCode ,
  438. @msg Msg ,
  439. amountLimitPerDay = @AmountLimitPerDay ,
  440. customerTotalSentAmt = 0 ,
  441. maxAmountLimitPerTran = @AmountLimitPerTran ,
  442. PerTxnMinimumAmt = @AmountLimitPerDay;
  443. RETURN;
  444. END
  445. --Validate Country Sending Limit END
  446. --5. Validate Country Receiving Limit
  447. EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = NULL
  448. ,@deliveryMethod = @deliveryMethod,@sendingCustType = NULL,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr
  449. ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch
  450. ,@msg = @msg OUT, @errorCode = @errorCode OUT
  451. IF @errorCode <> '0'
  452. BEGIN
  453. SELECT @errorCode ErrorCode ,
  454. @msg Msg ,
  455. amountLimitPerDay = @AmountLimitPerDay ,
  456. customerTotalSentAmt = 0 ,
  457. maxAmountLimitPerTran = @AmountLimitPerTran ,
  458. PerTxnMinimumAmt = @AmountLimitPerDay;
  459. RETURN;
  460. END
  461. --Validate Country Receiving Limit
  462. SET @msg = 'Success';
  463. ---------Validation Begin--------------------------------
  464. SELECT
  465. @sCurrCostRate = sCurrCostRate
  466. ,@sCurrHoMargin = sCurrHoMargin
  467. FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
  468. IF @sCurrCostRate IS NULL
  469. BEGIN
  470. SELECT @errorCode = '1', @msg = 'Transaction cannot be proceed. Exchange Rate not defined!'
  471. RETURN
  472. END
  473. SET @cAmtUSD = @cAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
  474. SELECT @bankRate = customerRate, @bankFee = serviceCharge FROM bankTransferSettings(NOLOCK)
  475. SELECT @bankTransafer = @cAmt - @bankFee
  476. SELECT @bankPayout = @bankTransafer * @bankRate
  477. SELECT @bankSave = @pAmt - @bankPayout
  478. SELECT ErrorCode = @errorCode ,
  479. Msg = @msg ,
  480. Id = NULL,
  481. scCharge = @serviceCharge ,
  482. exRateDisplay = ROUND(@exRate , 4, -1),
  483. exRate = @exRate,
  484. place = @place ,
  485. pCurr = @pCurr ,
  486. currDecimal = @currDecimal ,
  487. pAmt = @pAmt ,
  488. sAmt = ROUND(@tAmt, 0) ,
  489. disc = 0.00 ,
  490. --bank data
  491. bankTransafer = @bankTransafer,
  492. bankPayout = @bankPayout,
  493. bankRate = @bankRate,
  494. bankFee = @bankFee,
  495. bankSave = @bankSave,
  496. bankName = @bankName,
  497. collAmt = @cAmt ,
  498. collCurr = @collCurr,
  499. exRateOffer = @exRateOffer ,
  500. scOffer = @scDiscount ,
  501. scAction = NULL ,
  502. scValue = @scValue ,
  503. scDiscount = @scDiscount ,
  504. amountLimitPerTran = @AmountLimitPerTran ,
  505. amountLimitPerDay = @AmountLimitPerDay ,
  506. customerTotalSentAmt = 0,
  507. minAmountLimitPerTran = @AmountLimitPerTran ,
  508. maxAmountLimitPerTran = @AmountLimitPerDay ,
  509. PerTxnMinimumAmt = '',
  510. tpExRate = @tpExRate,
  511. tpPCurr = @tpPCurr,
  512. schemeAppliedMsg = '',
  513. schemeId = 0,
  514. couponType='',
  515. discountType='',
  516. discountvalue='',
  517. discountPercent=''
  518. END
  519. GO