|
|
USE [FastMoneyPro_Remit] GO
ALTER PROC [dbo].proc_Online_sendTxn_Test ( @flag VARCHAR(50) , @user VARCHAR(100) , @senderId VARCHAR(50) = NULL , @sIpAddress VARCHAR(50) = NULL , @benId VARCHAR(50) = NULL , @rfName VARCHAR(100) = NULL , @sIdType VARCHAR(100) =NULL, @sIdNo VARCHAR(100) =NULL, @sMobile VARCHAR(50) = NULL , @rIdType VARCHAR(100) = NULL , @rIdNo VARCHAR(50) = NULL , @rIdValid DATETIME = NULL , @rdob DATETIME = NULL , @rTel VARCHAR(20) = NULL , @rMobile VARCHAR(20) = NULL , @rNaCountry VARCHAR(50) = NULL , @rcity VARCHAR(100) = NULL , @rAdd1 VARCHAR(150) = NULL , @rEmail VARCHAR(100) = NULL , @raccountNo VARCHAR(50) = NULL , @pCountry VARCHAR(50) = NULL -- pay country
,@pCountryId INT = NULL -- PAY COUNTRY ID
,@deliveryMethod VARCHAR(50) = NULL -- payment mode
,@deliveryMethodId INT = NULL -- payment mode ID
,@pBank INT = NULL , @pBankName VARCHAR(100) = NULL , @pBankBranch INT = NULL , @pBankBranchName VARCHAR(100) = NULL , @pAgent INT = NULL , @pAgentName VARCHAR(100) = NULL , @pBranch INT = NULL , @pBranchName VARCHAR(100) = NULL , @pBankType CHAR(1) = NULL , @pSuperAgent INT = NULL , @pCurr VARCHAR(3) = NULL , @collCurr VARCHAR(3) = NULL , @cAmt MONEY = NULL , @pAmt MONEY = NULL , @tAmt MONEY = NULL , @serviceCharge MONEY = NULL , @discount MONEY = NULL , @exRate FLOAT = NULL , @purpose VARCHAR(150) = NULL , @sourceOfFund VARCHAR(150) = NULL , @relationship VARCHAR(100) = NULL , @occupation VARCHAR(100) = NULL , @payMsg VARCHAR(1000) = NULL , @controlNo VARCHAR(20) = NULL , @sCountryId INT = NULL , @sCountry VARCHAR(100) = NULL , @sBranch INT = NULL , @sBranchName VARCHAR(100) = NULL , @sAgent INT = NULL , @sAgentName VARCHAR(100) = NULL , @sSuperAgent INT = NULL , @sSuperAgentName VARCHAR(100) = NULL , @settlingAgent INT = NULL , @branchMapCode VARCHAR(10) = NULL , @agentMapCode VARCHAR(10) = NULL , @collMode VARCHAR(50) = NULL , @depositMode VARCHAR(50) = NULL, -- DEPOSIT MODE CASH OR BANK
@calBy CHAR(1) = NULL , @scDiscount MONEY = NULL , @cardOnline VARCHAR(50) = NULL , @memberShipId VARCHAR(50) = NULL , @agentRefId VARCHAR(50) = NULL , @couponCode VARCHAR(20) = NULL , @schemeId BIGINT = NULL , @tranId VARCHAR(50) = NULL , @ScOrderNo BIGINT = NULL , @unitaryBankAccountNo VARCHAR(50) = NULL , @RState VARCHAR(10) = NULL, @RStateText VARCHAR(150) = NULL, @RLocation VARCHAR(20) = NULL, @RLocationText VARCHAR(150) = NULL, @VoucherXML XML=NULL, @tpRefNo VARCHAR(20) = NULL, @tpTranId VARCHAR(20) = NULL, @payOutPartner BIGINT = NULL, @FOREX_SESSION_ID VARCHAR(40) = NULL, @kftcLogId BIGINT = NULL, @paymentType VARCHAR(20) = NULL ) AS SET NOCOUNT ON; SET XACT_ABORT ON; IF @paymentType IS NULL set @paymentType ='wallet'
IF @paymentType='autodebit' BEGIN DECLARE @DATE DATETIME, @NextDate datetime
select @DATE = CAST(GETDATE() AS DATE) SELECT @NextDate = DATEADD(DAY,1,@DATE)
SELECT @DATE = @DATE+' 23:20:00',@NextDate = @NextDate+' 00:40:00'
IF GETDATE() BETWEEN @DATE AND @NextDate BEGIN SELECT '1' ErrorCode ,'KFTC service is not available between 11:30 PM to 12:30 AM' Msg ,NULL ID RETURN END END
BEGIN TRY BEGIN DECLARE @sCurrCostRate FLOAT , @sCurrHoMargin FLOAT , @pCurrCostRate FLOAT , @pCurrHoMargin FLOAT , @sCurrAgentMargin FLOAT , @pCurrAgentMargin FLOAT , @sCurrSuperAgentMargin FLOAT , @pCurrSuperAgentMargin FLOAT , @customerRate FLOAT , @sAgentSettRate FLOAT , @pDateCostRate FLOAT , @agentCrossSettRate FLOAT , @treasuryTolerance FLOAT , @customerPremium FLOAT , @schemePremium MONEY = NULL, @sharingValue MONEY , @sharingType CHAR(1) , @sAgentComm MONEY , @sAgentCommCurrency VARCHAR(3) , @sSuperAgentComm MONEY , @sSuperAgentCommCurrency VARCHAR(3) , @pAgentComm MONEY , @pAgentCommCurrency VARCHAR(3) , @pCommissionType CHAR(1) , @pSuperAgentComm MONEY , @pSuperAgentCommCurrency VARCHAR(3) , @pSuperAgentName VARCHAR(100), @pStateId INT, @senderName VARCHAR(100) , @id INT , @customerStatus VARCHAR(20) , @idExpiryDate DATETIME; DECLARE @errorCode CHAR(1)= '0' ,@agentAvlLimit MONEY;
DECLARE @rowId INT; DECLARE @scValue MONEY , @exRateOffer MONEY , @scAction VARCHAR(5) , @AmountLimitPerTran MONEY , @AmountLimitPerDay MONEY , @todaysTotalSent MONEY , @tranMinimum MONEY , @tranMaximum MONEY DECLARE @ad FLOAT;
DECLARE @xAmt MONEY , @sendingCustType INT , @msg VARCHAR(MAX); DECLARE @iServiceCharge MONEY , @iTAmt MONEY , @iPAmt MONEY , @iCAmt MONEY , @iCustomerRate FLOAT
DECLARE @place INT , @currDecimal INT; DECLARE @controlNoEncrypted VARCHAR(20); DECLARE @csMasterId INT , @count INT , @compFinalRes VARCHAR(20); DECLARE @GMTDate VARCHAR(50); DECLARE @createdDate DATETIME; DECLARE @SENDERS_IDENTITY_TYPE VARCHAR(50); SET @GMTDate = dbo.FNAGMTOnline(GETDATE(), @user); SELECT @sAgent = sAgent, @sAgentName = sAgentName, @sBranch = sBranch, @sBranchName = sBranchName, @sSuperAgent = sSuperAgent, @sSuperAgentName = sSuperAgentName FROM dbo.FNAGetBranchFullDetails(@sBranch)
IF @pCountryId IS NULL SELECT @pCountryId = countryId FROM countryMaster (NOLOCK) WHERE countryName = @pCountry
IF @pCountry LIKE '%?%' SELECT @pCountry = COUNTRYNAME FROM COUNTRYMASTER (NOLOCK) WHERE COUNTRYID = @pCountryId
SELECT @pBank = @pAgent, @pBankName = @pAgentName, @pBankBranch = @pBranch , @pBankBranchName = CASE WHEN @pBranchName IS NULL THEN (SELECT agentName FROM agentMaster(NOLOCK) WHERE agentId = @pBranch) ELSE @pBranchName END; SELECT @pAgent = null , @pAgentName = NULL , @pBranch = NULL , @pBranchName = NULL; DECLARE @discountType VARCHAR(2) = null, @discountvalue money =null, @couponType VARCHAR(3) = NULL, @discountPercent money = null, @couponName VARCHAR(20) = NULL
SET @sCountryId = 118 SET @sCountry = 'South Korea' SET @sAgentCommCurrency = 'KRW'
if @pCountryId in(151) begin set @pAgent = @payOutPartner end else begin SELECT TOP 1 @pAgent = AM.agentId FROM agentMaster AM(NOLOCK) WHERE AM.parentId = @payOutPartner AND agentType=2903 AND AM.isSettlingAgent = 'Y' AND AM.isApiPartner = 1 end
IF @pBank = '2093' ----## IF VCBR AGENT
SET @pAgent = 393229 ELSE IF @pBank = '2121' ----## IF SACOM AGENT
SET @pAgent = 393862 ELSE IF @pBank =393848 ----## AGRANI BANK LTD(EXRATE FROM LOCAL SETUP)
SELECT @pAgent = 404526 ELSE IF @pBank = 566989 ----## Islami Bank Bangladesh Limited(EXRATE FROM LOCAL SETUP)
SELECT @pAgent = 566853
SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName, @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName FROM dbo.FNAGetBranchFullDetails(@pAgent) IF @flag = 'exRate' --Get Exchange Rate, Service Charge, Scheme/Offer and amount details BEGIN IF @payOutPartner IN (224388,2140,393227,415207) and @pCurr <>'USD' --## TANGLO,MTRADE
BEGIN SELECT '1' ErrorCode , 'Oops, something went wrong.Please perform the transaction again!' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; SELECT TOP 1 @senderId = customerId , @idExpiryDate = idExpiryDate , @createdDate = createdDate, @sIdNo = idNumber, @sIdType = idType, @agentAvlLimit = dbo.FNAGetCustomerACBal(@user), @customerStatus = CASE WHEN customerStatus IS NULL THEN 'pending' ELSE 'verified' END, @todaysTotalSent = ISNULL(todaysSent, 0) FROM customerMaster WITH ( NOLOCK ) WHERE email = @user;
SELECT @sIdType = detailTitle FROM staticDataValue(NOLOCK) WHERE valueId = @sIdType
SELECT @scValue = 0 , @exRateOffer = 0 , @scDiscount = 0 , @AmountLimitPerTran = 3000, @AmountLimitPerDay = 20000 -- IF ( @idExpiryDate < GETDATE() AND @sIdType <> 'National ID')
-- BEGIN
-- SELECT '1' ErrorCode ,
-- 'Your provided photo id has been expired. Please contact GME Support Team by writing email to support@gmeremit.com or call on +44 (0) 20 8861 2264.' Msg ,
-- amountLimitPerDay = @AmountLimitPerDay ,
-- customerTotalSentAmt = @todaysTotalSent ,
-- maxAmountLimitPerTran = @tranMaximum ,
-- PerTxnMinimumAmt = @tranMinimum;
-- RETURN;
--END; SELECT @place = place , @currDecimal = currDecimal FROM currencyPayoutRound(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N' AND currency = @pCurr AND (tranType IS NULL OR tranType = @deliveryMethod); SET @currDecimal = ISNULL(@currDecimal,0)
IF @pCurr IS NULL BEGIN SELECT '1' ErrorCode , 'Currency not been defined yet for receiving country' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; SELECT @exRate = dbo.FNAGetCustomerRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent, @pCurr,@deliveryMethod); IF @exRate IS NULL BEGIN SELECT '1' ErrorCode , 'Exchange rate not defined yet for receiving currency ('+ @pCurr + ')' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END;
----- Calculation service charge using coupon
IF EXISTS (SELECT '1' FROM CouponIssue(NOLOCK) AS CI INNER JOIN CouponSetup(NOLOCK) AS CS ON CI.couponId = CS.rowId WHERE CI.customerId = @senderId AND CI.endDate >= GETDATE() AND CI.isActive = 'Y' AND CS.endDate >= GETDATE() AND CS.isActive = 'Y' AND CS.couponType = '1' AND (ISNULL(CS.usageLimit,0) = 0 OR ISNULL(CS.usageLimit,0) > ISNULL(CI.usedCount,0)) ) BEGIN SELECT TOP(1) @discountType = CS.discountType, @couponName = CS.couponName, @discountvalue = CS.discountValue, @schemeId = CI.rowId, -- ADD coponIssue ID
@couponType = CS.couponType FROM CouponIssue(NOLOCK) CI INNER JOIN CouponSetup(NOLOCK) CS ON CI.couponId = CS.rowId WHERE CI.isActive = 'Y' AND CI.endDate >= GETDATE() AND CS.endDate >= GETDATE() AND CS.isActive = 'Y' AND CS.couponType = '1' AND CI.customerId = @senderId AND (ISNULL(CS.usageLimit,0) = 0 OR ISNULL(CS.usageLimit,0) > ISNULL(CI.usedCount,0)) ORDER BY CI.rowId ASC
-- @discountType 1: PERCENTAGE, 2: MONEY
IF @discountType ='2' BEGIN SET @scDiscount = @discountvalue END END IF @calBy = 'C' BEGIN IF @pCountryId = 36 BEGIN SET @pAmt = @cAmt * @exRate SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr); END ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2 BEGIN SET @pAmt = @cAmt * @exRate SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD'); END ELSE BEGIN SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod,@cAmt,@collCurr); END IF @serviceCharge IS NULL BEGIN SELECT '1' ErrorCode , 'Service charge not defined yet for receiving country' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; -- @discountType 1: PERCENTAGE, 2: MONEY
IF @discountType = '1' BEGIN SET @discountPercent = @discountvalue SET @discountvalue = @serviceCharge * (@discountvalue/100) SET @scDiscount = @discountvalue END
SET @tAmt = @cAmt - @serviceCharge; SET @pAmt = ( @cAmt-@serviceCharge ) * @exRate SET @pAmt = ROUND(@pAmt,@currDecimal) END; ELSE IF @calBy = 'P' BEGIN SET @tAmt = @pAmt / @exRate
IF @pCountryId = 36 BEGIN SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,@collCurr); END ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethod = 2 BEGIN SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethod,@pAmt,'USD'); END ELSE BEGIN SELECT @serviceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,@pBranch,@deliveryMethod, @tAmt, @collCurr); END
IF @serviceCharge IS NULL BEGIN SELECT '1' ErrorCode , 'Service charge not defined yet for receiving country' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; -- @discountType 1: PERCENTAGE, 2: MONEY
IF @discountType = '1' BEGIN SET @discountPercent = @discountvalue SET @discountvalue = @serviceCharge * (@discountvalue/100) SET @scDiscount = @discountvalue END SET @tAmt = ROUND(@tAmt, 0); SET @cAmt = ( @tAmt + @serviceCharge ); SET @cAmt = ROUND(@cAmt, 0); END; IF @serviceCharge > @cAmt BEGIN SELECT '1' ErrorCode , 'COLLECTION AMOUNT SHOULD BE MORE THAN SERVICE CHARGE' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; --4. Validate Country Sending Limit EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = @collMode ,@deliveryMethod = @deliveryMethod,@sendingCustType = @sendingCustType,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch ,@msg = @msg OUT, @errorCode = @errorCode OUT
IF @errorCode <> '0' BEGIN SELECT @errorCode ErrorCode , @msg Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END --Validate Country Sending Limit END --5. Validate Country Receiving Limit EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit', @cAmt = @cAmt, @pAmt = @pAmt, @sCountryId = @sCountryId, @collMode = @collMode ,@deliveryMethod = @deliveryMethod,@sendingCustType = @sendingCustType,@pCountryId = @pCountryId,@pCurr = @pCurr, @collCurr = @collCurr ,@pAgent = @pAgent, @sAgent = @sAgent, @sBranch = @sBranch ,@msg = @msg OUT, @errorCode = @errorCode OUT IF @errorCode <> '0' BEGIN SELECT @errorCode ErrorCode , @msg Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END --Validate Country Receiving Limit --End of Limit Checking------------------------------------------------------------------------------------------------------------
SET @msg = 'Success'; IF ISNULL(@paymentType,'wallet') = 'wallet' BEGIN IF ISNULL(@agentAvlLimit, 1) < ISNULL(@cAmt, 0) BEGIN SELECT '1' ErrorCode ,'You donot have sufficient balance to do the transaction' Msg , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; END ---------Compliance Checking Begin--------------------------------
DECLARE @complianceRuleId INT, @cAmtUSD MONEY SELECT @sCurrCostRate = sCurrCostRate ,@sCurrHoMargin = sCurrHoMargin ,@pCurrCostRate = pCurrCostRate ,@pCurrHoMargin = pCurrHoMargin ,@pCurrAgentMargin = pCurrAgentMargin ,@agentCrossSettRate = agentCrossSettRate ,@treasuryTolerance = treasuryTolerance ,@customerPremium = customerPremium ,@sharingValue = sharingValue ,@sharingType = sharingType FROM dbo.FNAGetExRate(@sCountryId, @sAgent, @sBranch, @collCurr, @pCountryId, @pAgent, @pCurr, @deliveryMethod)
IF @sCurrCostRate IS NULL BEGIN SELECT @errorCode = '1', @msg = 'Transaction cannot be proceed. Exchange Rate not defined!' RETURN END SET @cAmtUSD = @cAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0))
DECLARE @receiverName VARCHAR(50) = NULL ,@complienceMessage varchar(1000) =NULL ,@shortMsg varchar(100) =NULL ,@complienceErrorCode TINYINT = NULL EXEC [proc_complianceRuleDetail] @flag = 'sender-limit' ,@user = @user ,@sIdType = @sIdType ,@sIdNo = @sIdNo ,@cAmt = @cAmt ,@cAmtUSD = @cAmtUSD ,@customerId = @senderId ,@pCountryId = @pCountryId ,@deliveryMethod= @deliveryMethod ,@message = @complienceMessage OUTPUT ,@shortMessage = @shortMsg OUTPUT ,@errCode = @complienceErrorCode OUTPUT ,@ruleId = @complianceRuleId OUTPUT DECLARE @compErrorCode INT
IF(@complienceErrorCode <> 0) BEGIN IF(@complienceErrorCode = 1) BEGIN SET @compErrorCode=101 --SELECT 101 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype END ELSE BEGIN SET @compErrorCode=102 INSERT remitTranComplianceTemp(csDetailTranId, matchTranId, agentRefId) SELECT @complianceRuleId, NULL, @agentRefId
--SELECT 102 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype END
INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName , receiverCountry,payOutAmt,complianceId,complianceReason,complainceDetailMessage,createdBy,createdDate,logType)
SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName , @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE(),'sender-limit' END IF @complienceErrorCode = '1' BEGIN SELECT @compErrorCode ErrorCode , @complienceErrorCode Id , @shortMsg Msg , '' vtype , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = @todaysTotalSent , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = @tranMinimum; RETURN; END; ----------Compliance Validation End---------------------------------
--Bank compare --DECLARE @bankName VARCHAR(25) = 'Bank', @bankRate MONEY, @bankPayout MONEY, @bankFee MONEY -- , @bankSave MONEY, @bankTransafer MONEY
--SELECT @bankRate = customerRate, @bankFee = serviceCharge FROM bankTransferSettings(NOLOCK)
--SELECT @bankTransafer = @cAmt - @bankFee --SELECT @bankPayout = @bankTransafer * @bankRate --SELECT @bankSave = @pAmt - @bankPayout SET @FOREX_SESSION_ID = NEWID()
----## lock ex rate for individual txn
INSERT INTO exRateCalcHistory ( CUSTOMER_ID,[USER_ID],FOREX_SESSION_ID,serviceCharge,pAmt,customerRate,sCurrCostRate,sCurrHoMargin ,sCurrAgentMargin,pCurrCostRate,pCurrHoMargin,pCurrAgentMargin,agentCrossSettRate,treasuryTolerance,customerPremium ,sharingValue,sharingType,createdDate,isExpired,tAmt,schemeId ) SELECT @senderId,@user,@FOREX_SESSION_ID,@serviceCharge,@pAmt,@exRate,@sCurrCostRate,@sCurrHoMargin ,@sCurrAgentMargin,@pCurrCostRate,@pCurrHoMargin,@pCurrAgentMargin ,@agentCrossSettRate,@treasuryTolerance ,@customerPremium ,@sharingValue,@sharingType,GETDATE(),0,@tAmt,@schemeId
SELECT ErrorCode = @errorCode , Msg = @msg , Id = NULL, scCharge = @serviceCharge , exRateDisplay = ROUND(@exRate , 4, -1), exRate = CAST(@exRate AS DECIMAL(12,9)), place = @place , pCurr = @pCurr , currDecimal = @currDecimal , pAmt = @pAmt , sAmt = ROUND(@tAmt, 0) , disc = 0.00 , --bank data bankTransafer = 0.00, bankPayout = 0.00, bankRate = 0.00, bankFee = 0.00, bankSave = 0.00, bankName = '',
collAmt = @cAmt , collCurr = @collCurr, exRateOffer = @exRateOffer , scOffer = @scDiscount , scAction = @scAction , scValue = @scValue , scDiscount = @scDiscount , amountLimitPerTran = @AmountLimitPerTran , amountLimitPerDay = @AmountLimitPerDay , customerTotalSentAmt = ISNULL(@todaysTotalSent,0) , minAmountLimitPerTran = @tranMinimum , maxAmountLimitPerTran = @tranMaximum , PerTxnMinimumAmt = '', tpExRate = @exRate, tpPCurr = @pCurr, schemeAppliedMsg = '', schemeId = ISNULL(@schemeId,''), EXRATEID = @FOREX_SESSION_ID, couponType = ISNULL(@couponType,''), discountType = ISNULL(@discountType,''), discountvalue = ISNULL(@scDiscount,''), ISNULL(@discountPercent,'') AS discountPercent, ISNULL(@couponName,'') AS couponName END;
IF @flag = 'i' --Send Transaction BEGIN IF @user in('demo.gme@gmeremit.com') BEGIN EXEC proc_errorHandler 1,'You can not send money through test GME acocunt :(', NULL; RETURN; END ELSE IF @pBank IN(404527,393940,566989) ----## AGRANI BANK LTD/DUTCH BANGLA BANK/Islami Bank Bangladesh Limited/@payOutPartner = mtrade JUST TO CHECK SETUP EXISTS ON TblPartnerwiseCountry OR NOT(EXRATE FROM LOCAL SETUP)
SELECT TOP 1 @payOutPartner = AgentId FROM TblPartnerwiseCountry(NOLOCK) WHERE CountryId = @pCountryId AND ISNULL(PaymentMethod,@deliveryMethodId) = @deliveryMethodId and IsActive = 1
IF NOT EXISTS(SELECT '' FROM TblPartnerwiseCountry(NOLOCK) WHERE AgentId = @payOutPartner and CountryId = @pCountryId AND ISNULL(PaymentMethod,@deliveryMethodId) = @deliveryMethodId and IsActive = 1 ) BEGIN EXEC proc_errorHandler 1,'Oops, something went wrong.Please perform the transaction again!' ,null RETURN; END IF @pAgent IS NULL BEGIN EXEC proc_errorHandler 1,'Oops, something went wrong.Please perform the transaction again!' ,null RETURN; END
IF NOT EXISTS (SELECT 'X' FROM dbo.customerMaster(nolock) WHERE email = @user and approvedDate is not null) BEGIN EXEC proc_errorHandler 1,'You are not authorized to perform transaction :(', NULL; RETURN; END
IF ISNULL(@paymentType,'') NOT IN ('wallet', 'autodebit') BEGIN EXEC proc_errorHandler 1,'Invalid payment method.Please perform the transaction again!', NULL; RETURN; END
SELECT @SENDERS_IDENTITY_TYPE = CASE WHEN idType = '1302'THEN 'P' WHEN idType = '7316' THEN 'N' END , @sIdNo = idNumber , @senderName = isnull(fullName, firstname), @agentAvlLimit = ISNULL(availableBalance, 0) FROM customerMaster (NOLOCK) WHERE customerId = @senderId;
IF @rfName IS NULL BEGIN EXEC proc_errorHandler 1,'Receiver First Name missing', NULL; RETURN; END;
IF @rAdd1 IS NULL BEGIN EXEC proc_errorHandler 1,'Receiver Address missing', NULL; RETURN; END; IF ISNULL(@deliveryMethod, '') = '' BEGIN EXEC proc_errorHandler 1,'Please choose payment mode', NULL; RETURN; END; IF @serviceCharge IS NULL BEGIN EXEC proc_errorHandler 1, 'Service Charge missing',NULL; RETURN; END; IF ISNULL(@tAmt, 0) = 0 BEGIN EXEC proc_errorHandler 1,'Transfer Amount missing', NULL; RETURN; END; IF ISNULL(@exRate, 0) = 0 BEGIN EXEC proc_errorHandler 1, 'Exchange Rate missing',NULL; RETURN; END; IF ISNULL(@cAmt, 0) = 0 BEGIN EXEC proc_errorHandler 1, 'Collection Amount is missing. Cannot send transaction',NULL; RETURN; END; SET @controlNo = '80' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9); SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo); IF EXISTS (SELECT 'X' FROM pinQueueList WITH(NOLOCK) WHERE icn = @controlNoEncrypted) BEGIN SET @controlNo = '80' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9); SELECT @controlNoEncrypted = dbo.FNAEncryptString(@controlNo);
IF EXISTS(SELECT 'X' FROM pinQueueList WITH(NOLOCK) WHERE icn = @controlNoEncrypted) BEGIN EXEC proc_errorHandler 1, 'Technical error occurred. Please try again',NULL; RETURN; END END; IF @deliveryMethod = 'Bank Deposit' BEGIN IF NOT EXISTS(SELECT 'A' FROM agentMaster(nolock) where agentId = @pBank and agenttype =2903 and IsIntl = 1) BEGIN EXEC proc_errorHandler 1, 'Invalid bank selected', NULL return END IF EXISTS(SELECT 'A' FROM AgentBankMapping(NOLOCK) WHERE bankId = @pBank AND @pcountryId = 151) BEGIN SELECT @pAgent = bankpartnerId from AgentBankMapping(NOLOCK) WHERE bankId = @pBank SELECT @pSuperAgent = sSuperAgent,@pSuperAgentName = sSuperAgentName, @pAgent = sAgent,@pAgentName = sAgentName ,@pBranch = sBranch,@pBranchName = sBranchName FROM dbo.FNAGetBranchFullDetails(@pAgent) END END; SELECT @pAgentCommCurrency = commissionCurrency FROM SCPAYMASTER(NOLOCK) where rCountry = @pCountryId and ISNULL(tranType,@deliveryMethodId) = @deliveryMethodId and rsAgent = @pSuperAgent SET @pAgentCommCurrency = CASE WHEN @pAgent = 221271 THEN @pCurr ELSE @pAgentCommCurrency END
SELECT @pAgentComm = (SELECT amount FROM dbo.[FNAGetPayComm](@sAgent, @sCountryId, NULL, NULL, @pCountryId, NULL, @pAgent, @pAgentCommCurrency , @deliveryMethodId, @cAmt, @pAmt, @serviceCharge, NULL, NULL)) --Get Service Charge----------------------------------------------------------------------------------------------------------------------
IF @pCountryId = 36 ----## FOR CAMBODIA
BEGIN SELECT @iServiceCharge = ISNULL(amount, -1) FROM [dbo].FNAGetServiceCharge( @sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, NULL, @deliveryMethodId, @pAmt, @collCurr ) END ELSE IF @pCountryId = 42 AND @pCurr = 'USD' and @deliveryMethodId = 2 BEGIN SELECT @iServiceCharge = amount FROM [dbo].FNAGetServiceCharge(@sCountryId,@sSuperAgent,@sAgent,@sBranch, @pCountryId,@pSuperAgent,@pAgent,NULL,@deliveryMethodId,@pAmt,'USD'); END ELSE BEGIN SELECT @iServiceCharge = ISNULL(amount, -1) FROM [dbo].FNAGetServiceCharge( @sCountryId, @sSuperAgent, @sAgent, @sBranch, @pCountryId, @pSuperAgent, @pAgent, @pBranch, @deliveryMethodId, @cAmt, @collCurr ) END IF @iServiceCharge = -1 BEGIN EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Service Charge is not defined', NULL RETURN END IF isnull(@iServiceCharge,0) <> isnull(@serviceCharge,1) BEGIN EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Amount detail not match', NULL RETURN END SELECT @iServiceCharge = @serviceCharge , @customerRate = @exRate; --End Service Charge-------------------------------------------------------------------------------------------------------------------------------------
--4. Get Exchange Rate Details------------------------------------------------------------------------------------------------------------------
SELECT @customerRate = customerRate ,@sCurrCostRate = sCurrCostRate ,@sCurrHoMargin = sCurrHoMargin ,@sCurrAgentMargin = sCurrAgentMargin ,@pCurrCostRate = pCurrCostRate ,@pCurrHoMargin = pCurrHoMargin ,@pCurrAgentMargin = pCurrAgentMargin ,@agentCrossSettRate = agentCrossSettRate ,@treasuryTolerance = treasuryTolerance ,@customerPremium = customerPremium ,@sharingValue = sharingValue ,@sharingType = sharingType FROM dbo.FNAGetExRate(@sCountryId,@sAgent,@sBranch,@collCurr,@pCountryId,@pAgent,@pCurr,@deliveryMethodId) IF @customerRate IS NULL BEGIN EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined', NULL RETURN END
SELECT @customerRate = customerRate ,@sCurrCostRate = sCurrCostRate ,@sCurrHoMargin = sCurrHoMargin ,@sCurrAgentMargin = sCurrAgentMargin ,@pCurrCostRate = pCurrCostRate ,@pCurrHoMargin = pCurrHoMargin ,@pCurrAgentMargin = pCurrAgentMargin ,@agentCrossSettRate = agentCrossSettRate ,@treasuryTolerance = treasuryTolerance ,@customerPremium = customerPremium ,@sharingValue = sharingValue ,@sharingType = sharingType ,@serviceCharge = serviceCharge ,@iPAmt = pAmt FROM exRateCalcHistory(NOLOCK) WHERE FOREX_SESSION_ID = @FOREX_SESSION_ID AND [USER_ID] = @user
------------Find Coupon---------------
IF ISNULL(@schemeId,'') <> '' BEGIN IF EXISTS (SELECT '1' FROM CouponIssue(NOLOCK) AS CI INNER JOIN CouponSetup(NOLOCK) AS CS ON CI.couponId = CS.rowId WHERE CI.rowId = @schemeId AND CI.endDate >= GETDATE() AND CI.isActive = 'Y' AND CS.endDate >= GETDATE() AND CS.isActive = 'Y' AND CS.couponType = '1' AND (ISNULL(CS.usageLimit,0) = 0 OR ISNULL(CS.usageLimit,0) > ISNULL(CI.usedCount,0)) ) BEGIN DECLARE @CurrentCount int = 0 SELECT TOP(1) @discountvalue = CS.discountValue, @CurrentCount = ISNULL(CI.usedCount,0), @discountType = CS.discountType FROM CouponIssue(NOLOCK) CI INNER JOIN CouponSetup(NOLOCK) CS ON CI.couponId = CS.rowId WHERE CI.isActive = 'Y' AND CI.endDate >= GETDATE() AND CS.endDate >= GETDATE() AND CS.isActive = 'Y' AND CS.couponType = '1' AND CI.rowId = @schemeId AND (ISNULL(CS.usageLimit,0) = 0 OR ISNULL(CS.usageLimit,0) > ISNULL(CI.usedCount,0)) ORDER BY CI.rowId ASC IF @discountType = '1' BEGIN SET @schemePremium = @serviceCharge * (@discountvalue/100) END IF @discountType ='2' BEGIN SET @schemePremium = @discountvalue END
END
ELSE BEGIN EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Coupon Checked. But, Can Not Find Coupon', NULL RETURN END END
IF @paymentType = 'wallet' BEGIN IF ISNULL(@agentAvlLimit, 1) < ISNULL(@cAmt, 0) BEGIN EXEC proc_errorHandler 1,'You donot have sufficient balance to do the transaction!', NULL; RETURN; END; END ELSE IF @paymentType = 'autodebit' BEGIN DECLARE @tranAmt MONEY = NULL SELECT @tranAmt = tranAmt FROM KFTC_CUSTOMER_TRANSFER (NOLOCK) WHERE rowId = @kftcLogId IF @tranAmt IS NULL BEGIN EXEC proc_errorHandler 1,'Invalid auto debit request.Please perform the transaction again!', NULL; RETURN; END IF @tranAmt <> @cAmt - ISNULL(@schemePremium,0) BEGIN EXEC proc_errorHandler 1,'Invalid transaction amount. Please contact GME Support!', NULL; RETURN; END END ELSE BEGIN EXEC proc_errorHandler 1,'Invalid payment method.Please perform the transaction again!', NULL; RETURN; END IF @customerRate IS NULL BEGIN EXEC proc_errorHandler 1, 'Transaction cannot be proceed. Exchange Rate not defined', NULL RETURN END IF @pCurr IN ('VND','IDR','MNT') BEGIN SET @customerRate = CAST(@customerRate AS DECIMAL(15,10)) END --DECLARE @iMsg VARCHAR(MAX) IF ISNULL(@exRate,0) <> ISNULL(@customerRate,1) BEGIN --SET @iMsg = 'Amount detail not match. Please re-calculate the amount again' + CAST(isnull(@exRate,0) AS VARCHAR) + ' : ' + CAST(isnull(@customerRate,1) AS VARCHAR) EXEC proc_errorHandler 1, 'Amount detail not match. Please re-calculate the amount again', NULL RETURN END
IF @benId IS NOT NULL BEGIN IF NOT EXISTS(SELECT 1 FROM receiverInformation (NOLOCK) WHERE customerId = @senderId AND receiverId = @benId) BEGIN EXEC proc_errorHandler 1,'Invalid receiver Id!', NULL; RETURN; END END
DECLARE @scDisc MONEY
SELECT @iCustomerRate = @exRate, @iTAmt = @cAmt - @iServiceCharge
SELECT @place = place, @currDecimal = currDecimal FROM currencyPayoutRound WITH(NOLOCK) WHERE ISNULL(isDeleted, 'N') = 'N' AND currency = @pCurr AND (tranType IS NULL OR tranType = @deliveryMethodId) SET @currDecimal = ISNULL(@currDecimal, 0) SET @place = ISNULL(@place, 0) --SET @iPAmt = ROUND(@iTAmt * @iCustomerRate, @currDecimal) ------## WHILE CALCULATING FROM PAYOUT AMOUNT CONSIDARING 10 VND
--IF @pCurr IN ('VND','IDR','MNT') AND ISNULL(@iPAmt,0) < ISNULL(@pAmt,1)+10 --BEGIN -- SET @iPAmt = @pAmt
--END IF ISNULL(@iPAmt,0) <> ISNULL(@pAmt,1) BEGIN --SET @iMsg = 'Amount detail not match. Please re-calculate the amount again.' + CAST(@iPAmt AS VARCHAR) + ' - ' + CAST(@pAmt AS VARCHAR) EXEC proc_errorHandler 1, 'Amount detail not match. Please re-calculate the amount again.', NULL RETURN END --OFAC Checking DECLARE @receiverOfacRes VARCHAR(MAX), @ofacRes VARCHAR(MAX), @ofacReason VARCHAR(200) EXEC proc_ofacTracker @flag = 't', @name = @senderName, @Result = @ofacRes OUTPUT EXEC proc_ofacTracker @flag = 't', @name = @rfName, @Result = @receiverOfacRes OUTPUT DECLARE @result VARCHAR(MAX) IF ISNULL(@ofacRes, '') <> '' BEGIN SET @ofacReason = 'Matched by sender name' END IF ISNULL(@receiverOfacRes, '') <> '' BEGIN SET @ofacRes = ISNULL(@ofacRes + ',' + @receiverOfacRes, '' + @receiverOfacRes) SET @ofacReason = 'Matched by receiver name' END IF ISNULL(@ofacRes, '') <> '' AND ISNULL(@receiverOfacRes, '') <> '' BEGIN SET @ofacReason = 'Matched by both sender name and receiver name' END --Ofac Checking End ----@camt = (@tAmt+@serviceCharge) SET @cAmtUSD = @cAmt / (@sCurrCostRate + ISNULL(@sCurrHoMargin, 0)) --Compliance Checking EXEC [proc_complianceRuleDetail] @flag = 'receiver-limit' ,@user = @user ,@sIdType = @sIdType ,@sIdNo = @sIdNo ,@receiverName = @rfName ,@cAmt = @cAmt ,@cAmtUSD = @cAmtUSD ,@customerId = @senderId ,@pCountryId = @pCountryId ,@receiverMobile = @rMobile ,@deliveryMethod = @deliveryMethodId ,@message = @complienceMessage OUTPUT ,@shortMessage = @shortMsg OUTPUT ,@errCode = @complienceErrorCode OUTPUT ,@ruleId = @complianceRuleId OUTPUT IF(@complienceErrorCode <> 0) BEGIN IF(@complienceErrorCode = 1) BEGIN SET @compErrorCode=101 --SELECT 101 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype END ELSE BEGIN SET @compErrorCode=102 INSERT remitTranComplianceTemp(csDetailTranId, matchTranId, agentRefId) SELECT @complianceRuleId, NULL, @agentRefId
--SELECT 102 errorCode,@msg msg, @complienceErrorCode id, @complienceMessage compApproveRemark,'compliance' vtype END
INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName , receiverCountry,payOutAmt,complianceId,complianceReason,complainceDetailMessage,createdBy,createdDate,logType)
SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName , @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE(),'receiver-limit'
DECLARE @tempCompId BIGINT = @@IDENTITY END IF @complienceErrorCode = 1 BEGIN EXEC proc_errorHandler 1, @shortMsg, NULL RETURN; END; --Compliance checking end --**********Customer Per Day Limit Checking********** DECLARE @remitTranTemp TABLE ( tranId BIGINT,controlNo VARCHAR(20),cAmt MONEY,receiverName VARCHAR(200) , receiverIdType VARCHAR(100),receiverIdNumber VARCHAR(50),dot DATETIME
); INSERT INTO @remitTranTemp( tranId ,controlNo ,cAmt ,receiverName ,receiverIdType ,receiverIdNumber ,dot ) SELECT rt.id ,rt.controlNo ,rt.cAmt ,rt.receiverName ,rec.idType ,rec.idNumber ,rt.createdDateLocal FROM vwRemitTran rt WITH(NOLOCK) INNER JOIN vwTranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId INNER JOIN vwTranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId WHERE sen.customerId = @senderId AND ( rt.approvedDate BETWEEN CONVERT(VARCHAR,GETDATE(),101) AND CONVERT(VARCHAR,GETDATE(),101)+ ' 23:59:59' OR ( approvedBy IS NULL AND cancelApprovedBy IS NULL ) ); IF EXISTS ( SELECT 'X' FROM @remitTranTemp WHERE cAmt = @cAmt AND ( receiverName = @rfName ) AND DATEDIFF(MI, dot, GETDATE()) <= 2 ) BEGIN EXEC proc_errorHandler 1, 'Similar transaction found. Please perform the transaction after 2 minutes.', NULL; RETURN; END;
-- #########country and occupation risk point
DECLARE @countryRisk INT ,@OccupationRisk INT
DECLARE @VNo VARCHAR(20);
IF @pCountryId=151 AND ISNULL(@pBank,'')<>1056 --- if pcountry is nepal and pagent is not global ime bank then set this value to null
BEGIN SELECT @pAgent=NULL,@pAgentName=NULL--, @pAgentComm=NULL, @pAgentCommCurrency=NULL END
BEGIN TRANSACTION; INSERT INTO remitTranTempOnline ( controlNo ,sCurrCostRate ,sCurrHoMargin ,sCurrSuperAgentMargin ,sCurrAgentMargin ,pCurrCostRate ,pCurrHoMargin ,pCurrSuperAgentMargin , pCurrAgentMargin ,agentCrossSettRate ,customerRate ,sAgentSettRate ,pDateCostRate ,treasuryTolerance ,customerPremium ,schemePremium ,sharingValue , sharingType ,serviceCharge ,handlingFee ,sAgentComm ,sAgentCommCurrency ,sSuperAgentComm ,sSuperAgentCommCurrency ,pAgentComm ,pAgentCommCurrency , pCommissionType ,pSuperAgentComm ,pSuperAgentCommCurrency ,promotionCode ,pMessage ,sSuperAgent ,sSuperAgentName ,sAgent ,sAgentName ,sBranch , sBranchName ,sCountry ,pSuperAgent ,pSuperAgentName ,pAgent ,pAgentName ,pBranch ,pBranchName ,pCountry ,paymentMethod ,pBank ,pBankName ,pBankBranch ,pBankBranchName , accountNo ,pBankType ,expectedPayoutAgent ,collMode ,collCurr ,tAmt ,cAmt ,pAmt ,payoutCurr ,relWithSender ,purposeOfRemit ,sourceOfFund ,tranStatus ,payStatus ,createdDate , createdDateLocal ,createdBy ,tranType ,voucherNo ,senderName ,receiverName ,calBy ,isOnlineTxn ,schemeId ,ScOrderNo ,UnitaryBankAccountNo,pState,pDistrict, sRouteId ) SELECT @controlNoEncrypted ,@sCurrCostRate ,@sCurrHoMargin ,@sCurrSuperAgentMargin ,@sCurrAgentMargin ,@pCurrCostRate ,@pCurrHoMargin ,@pCurrSuperAgentMargin , @pCurrAgentMargin ,@agentCrossSettRate ,@customerRate ,@sAgentSettRate ,@pDateCostRate ,@treasuryTolerance ,@customerPremium ,ISNULL(@schemePremium, 0) , @sharingValue , @sharingType , @serviceCharge ,ISNULL(@scDiscount, 0) ,@sAgentComm ,@sAgentCommCurrency ,@sSuperAgentComm ,@sSuperAgentCommCurrency ,@pAgentComm ,@pAgentCommCurrency , @pCommissionType , @pSuperAgentComm ,@pSuperAgentCommCurrency ,@agentRefId ,@payMsg ,@sSuperAgent , @sSuperAgentName ,@sAgent ,@sAgentName ,@sBranch ,@sBranchName ,@sCountry , @pSuperAgent , @pSuperAgentName , @pAgent , @pAgentName , @pBranch ,@pBranchName ,@pCountry ,@deliveryMethod ,@pBank , @pBankName ,@pBankBranch ,@pBankBranchName ,@raccountNo ,@pBankType , @pAgentName ,@collMode , @collCurr ,@tAmt , @cAmt , @pAmt , @pCurr , @relationship , @purpose ,@sourceOfFund ,'Hold' ,'Unpaid' ,@GMTDate , GETDATE() , @user ,ISNULL(@pBankType,'O') , @VNo , @senderName , @rfName ,@calBy , 'Y' ,@schemeId ,@ScOrderNo ,@unitaryBankAccountNo,@RLocation,@RState, CASE WHEN @paymentType = 'wallet' THEN 'w' WHEN @paymentType = 'autodebit' THEN 'a' END SET @id = SCOPE_IDENTITY();
INSERT INTO tranSendersTempOnline ( tranId , customerId ,membershipId ,firstName , middleName ,lastName1 ,lastName2 , fullName ,country ,[address] ,address2 ,zipCode ,city ,email ,homePhone , workPhone ,mobile ,nativeCountry ,dob ,placeOfIssue ,idType ,idNumber ,idPlaceOfIssue , issuedDate ,validDate ,occupation ,countryRiskPoint ,customerRiskPoint , ipAddress ) SELECT TOP 1 @id ,@senderId ,membershipId ,firstName ,middleName ,lastName1 ,lastName2 , @senderName ,sc.countryName ,[address] ,address2 ,zipCode ,city ,email ,homePhone , workPhone ,LEFT(mobile, 15) ,nativeCountry = nc.countryName ,dob ,c.placeOfIssue ,sdv.detailTitle ,c.idNumber ,c.placeOfIssue , c.idIssueDate ,c.idExpiryDate ,om.detailTitle ,@countryRisk ,( @countryRisk + @OccupationRisk ) , @sIpAddress FROM dbo.customerMaster c WITH ( NOLOCK ) LEFT JOIN countryMaster sc WITH ( NOLOCK ) ON c.country = sc.countryId LEFT JOIN countryMaster nc WITH ( NOLOCK ) ON c.nativeCountry = nc.countryId LEFT JOIN staticDataValue sdv WITH ( NOLOCK ) ON c.idType = sdv.valueId LEFT JOIN occupationMaster om WITH ( NOLOCK ) ON c.occupation = om.occupationId WHERE c.customerId = @senderId; DECLARE @fName VARCHAR(100) , @mName VARCHAR(100) , @lName VARCHAR(100) , @lName2 VARCHAR(100); SELECT @fName =firstName, @mName =middleName, @lName =lastName1, @lName2 =lastName2 FROM dbo.FNASplitName(@rfName);
DECLARE @firstName VARCHAR(100) DECLARE @midName VARCHAR(100) DECLARE @lastName VARCHAR(100) DECLARE @lastName2 VARCHAR(100) DECLARE @payCountry VARCHAR(100) DECLARE @recAdd1 VARCHAR(100) DECLARE @reccity VARCHAR(100) DECLARE @recEmail VARCHAR(100) DECLARE @recTel VARCHAR(100) DECLARE @recMobile VARCHAR(100) DECLARE @recRelationship VARCHAR(100) DECLARE @recState VARCHAR(100) declare @recDistrict VARCHAR(100) IF @benId IS NULL BEGIN IF NOT EXISTS ( SELECT 'X' FROM receiverInformation(nolock) WHERE ISNULL(firstName, '') = ISNULL(@fName, '') AND ISNULL(middleName, '') = ISNULL(@mName, '') AND ISNULL(lastName1, '') = ISNULL(@lName, '') AND ISNULL(lastName2, '') = ISNULL(@lName2, '') AND customerId = @senderId ) BEGIN INSERT INTO receiverInformation ( customerId ,firstName,middleName,lastName1,lastName2 ,country ,address ,city ,email ,homePhone ,workPhone ,mobile ,relationship,state,district) SELECT @senderId ,firstName,middleName,lastName1,lastName2,@pCountry,@rAdd1,@rCity,@rEmail,@rTel ,@rTel,@rMobile,@relationship,@RLocationText,@RStateText FROM dbo.FNASplitName(@rfName); SET @benId = @@IDENTITY; END; ELSE BEGIN SELECT TOP 1 @benId = receiverId FROM receiverInformation(nolock) WHERE ISNULL(firstName, '') = @fName AND ISNULL(middleName, '') = @mName AND ISNULL(lastName1, '') = @lName AND ISNULL(lastName2, '') = @lName2 AND customerId = @senderId; END; END; IF @benId IS NOT NULL BEGIN SELECT @firstName =firstName ,@midName =middleName ,@lastName =lastName1 ,@lastName2 =lastName2 ,@payCountry =country ,@recAdd1 =address ,@reccity =city ,@recEmail =email ,@recTel =homePhone ,@recMobile =mobile ,@recRelationship =relationship ,@recState =state ,@recDistrict =district FROM dbo.receiverInformation(nolock) WHERE receiverId = @benId UPDATE dbo.receiverInformation SET firstName =ISNULL( @fName ,@firstName) , middleName =ISNULL( @mName ,@midName) , lastName1 =ISNULL( @lName ,@lastName) , lastName2 =ISNULL( @lName2 ,@lastName2) , country =ISNULL( @pCountry ,@payCountry) , address =ISNULL( @rAdd1 ,@recAdd1) , city =ISNULL( @rCity ,@reccity) , state =isnull( @RLocationText,@recState) , district =isnull(@RStateText ,@recDistrict) , email =ISNULL( @rEmail ,@recEmail) , homePhone =ISNULL( @rTel ,@recTel) , workPhone =ISNULL( @rTel ,@recTel) , mobile =ISNULL( @rMobile ,@recMobile) , relationship =ISNULL( @relationship,@recRelationship) WHERE receiverId = @benId END INSERT INTO tranReceiversTempOnline( tranId ,customerId ,membershipId ,firstName ,middleName ,lastName1 ,lastName2 ,fullName , country ,[address] ,[state] ,district ,zipCode ,city ,email ,homePhone ,workPhone ,mobile ,nativeCountry ,dob , placeOfIssue ,idType ,idNumber ,idPlaceOfIssue ,issuedDate ,relationType,validDate ,gender ) SELECT @id ,@benId ,NULL ,firstName ,middleName ,lastName1 ,lastName2 ,@rfName , @pCountry ,@rAdd1 ,@RLocationText ,@RStateText ,null ,@rCity, @rEmail ,@rTel ,@rTel ,@rMobile ,@rNaCountry ,@rdob , NULL ,@rIdType ,@rIdNo ,NULL ,NULL ,@relationship,@rIdValid ,NULL FROM dbo.FNASplitName(@rfName); INSERT INTO collectionDetailsOnline ( tranId ,collMode ,countryBankId ,amt ,collDate ,narration ,branchId ,createdBy ,createdDate ) SELECT @id ,@collMode ,0 ,@cAmt ,@GMTDate ,'online' ,NULL ,@senderId ,GETDATE(); EXEC proc_online_temp_to_main @id = @id OUTPUT,@voucherDetails= @VoucherXML IF @paymentType = 'wallet' EXEC proc_UpdateCustomerBalance @controlNo = @controlNoEncrypted, @type = 'deduct' ELSE IF @paymentType = 'autodebit' UPDATE KFTC_CUSTOMER_TRANSFER SET tranId = @id WHERE rowId = @kftcLogId
----## map locked ex rate with transaction for history
UPDATE exRateCalcHistory set controlNo = @controlNoEncrypted,AGENT_TXN_REF_ID=@id where FOREX_SESSION_ID = @FOREX_SESSION_ID --------------------------#########------------OFAC/COMPLIANCE INSERT (IF EXISTS)---------------########----------------------
IF EXISTS(SELECT 'X' FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @agentRefId) BEGIN INSERT INTO remitTranCompliance(TranId, csDetailTranId, matchTranId) SELECT @id, csDetailTranId, matchTranId FROM remitTranComplianceTemp WITH(NOLOCK) WHERE agentRefId = @agentRefId SET @compFinalRes = 'C' END
IF(ISNULL(@compFinalRes, '') <> '' OR ISNULL(@ofacRes, '') <> '' OR ISNULL(@receiverOfacRes, '') <> '') BEGIN IF @pCountryId IN (36) BEGIN SET @complienceMessage = ISNULL('Compliance: ' + @shortMsg, '') + ISNULL('Ofac: ' + @ofacRes, '') + ISNULL(' ' + @receiverOfacRes, '') INSERT INTO ComplianceLog(senderName, senderCountry, senderIdType, senderIdNumber, senderMobile, receiverName , receiverCountry,payOutAmt,complianceId,complianceReason,complainceDetailMessage,createdBy,createdDate,logType) SELECT @senderName, @sCountry, @sIdType, @sIdNo, @sMobile, @receiverName , @pCountry, @cAmt, @complianceRuleId, @shortMsg, @complienceMessage, @user, GETDATE(),'reject_log'
SET @tempCompId = @@IDENTITY
SET @msg = 'Your transaction is under Compliance/OFAC Please refer ' + CAST(ISNULL(@tempCompId, 0) AS VARCHAR) + ' code to HEAD OFFICE'; EXEC proc_errorHandler 1, @msg, NULL; EXEC proc_ApproveHoldedTXN @flag = 'reject', @user = @user , @id = @id COMMIT TRANSACTION RETURN END
IF((ISNULL(@ofacRes, '') <> '' OR ISNULL(@receiverOfacRes, '') <> '') AND ISNULL(@compFinalRes, '') = '') BEGIN IF ISNULL(@ofacRes, '') <> '' INSERT remitTranOfac(TranId, blackListId, reason, flag) SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes) IF ISNULL(@receiverOfacRes, '') <> '' INSERT remitTranOfac(TranId, blackListId, reason, flag) SELECT @tranId, @receiverOfacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@receiverOfacRes)
UPDATE remitTranTemp SET
tranStatus = 'OFAC Hold' WHERE id = @id END ELSE IF(@compFinalRes <> '' AND (ISNULL(@ofacRes, '') = '' OR ISNULL(@receiverOfacRes, '') = '')) BEGIN UPDATE remitTranTemp SET
tranStatus = 'Compliance Hold' WHERE id = @id END ELSE IF(ISNULL(@compFinalRes, '') <> '' AND (ISNULL(@ofacRes, '') <> '' OR ISNULL(@receiverOfacRes, '') <> '')) BEGIN IF ISNULL(@ofacRes, '') <> '' INSERT remitTranOfac(TranId, blackListId, reason, flag) SELECT @tranId, @ofacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@ofacRes) IF ISNULL(@receiverOfacRes, '') <> '' INSERT remitTranOfac(TranId, blackListId, reason, flag) SELECT @tranId, @receiverOfacRes, @ofacReason, dbo.FNAGetOFAC_Flag(@receiverOfacRes) UPDATE remitTranTemp SET
tranStatus = 'OFAC/Compliance Hold' WHERE id = @id END END --Compliance checking
-------START update used coupon status --- 위에서 밸리데이션을 한다.
IF EXISTS(SELECT '1' FROM CouponIssue(NOLOCK) WHERE rowId = @schemeId AND isActive = 'Y' ) BEGIN UPDATE CouponIssue SET usedCount = @CurrentCount +1 WHERE rowId = @schemeId AND customerId = @senderId AND GETDATE() BETWEEN startDate AND endDate AND isActive = 'Y'
-------Start insert Coupon History INSERT INTO CouponHistory (couponIssueId,customerId,actualDiscountValue,usedCount,holdTranId,couponStatus,createdBy,createdDate) VALUES (@schemeId,@senderId,@schemePremium,@CurrentCount + 1,@id,'1',@user, GETDATE()) -------End insert Coupon History
END -------END update used coupon status
IF @@TRANCOUNT > 0 COMMIT TRANSACTION; SElect 0 errorCode, 'Transaction has been sent successfully' msg, @id id, @controlNo extra; IF @pCountryId <> 36 exec [proc_ApproveHoldedTXN] @flag = 'approve', @id = @id,@user = 'admin' RETURN END; ELSE IF @flag = 'approve-wing' BEGIN select @id = id, @deliveryMethod = paymentMethod from remitTranTemp (nolock) where controlno = dbo.FNAEncryptString(@controlNo) if @deliveryMethod <> 'Mobile Wallet' update remitTranTemp set controlno = dbo.FNAEncryptString(@tpRefNo),controlNo2 = dbo.FNAEncryptString(@controlNo) where id = @id IF EXISTS( select 'A' from remittran(nolock) where controlno = dbo.FNAEncryptString(@tpRefNo) AND pCountry = 'Cambodia' AND pAgent = 221226 -- AND DATEDIFF(DAY,createddate,GETDATE()) > 30
) BEGIN UPDATE remittran SET controlno = dbo.FNAEncryptString(@tpRefNo+'A') where controlno = dbo.FNAEncryptString(@tpRefNo) UPDATE PINQUEUELIST SET ICN = dbo.FNAEncryptString(@tpRefNo+'A') WHERE ICN = dbo.FNAEncryptString(@tpRefNo) UPDATE FastMoneyPro_Account.DBO.tran_master set field1 = @tpRefNo+'A' where field1 = @tpRefNo and field2 = 'remittance Voucher' END
EXEC [proc_ApproveHoldedTXN] @flag = 'approve', @id = @id,@user = 'admin'
SELECT @id = id FROM remitTran (NOLOCK) WHERE controlno = case when @deliveryMethod = 'Mobile Wallet' then dbo.FNAEncryptString(@controlNo) else dbo.FNAEncryptString(@tpRefNo) end AND paystatus = 'UNPAID' IF @id IS NOT NULL BEGIN UPDATE remitTran SET controlno = case when @deliveryMethod = 'Mobile Wallet' then dbo.FNAEncryptString(@controlNo) else dbo.FNAEncryptString(@tpRefNo) end ,controlNo2 = dbo.FNAEncryptString(@controlNo) ,ContNo = @tpTranId ,paystatus = 'Post' ,postedBy = @user ,postedDate = getdate() ,postedDateLocal = getdate() WHERE id = @id AND paystatus = 'UNPAID' END SELECT 0 ErrorCode,'Transaction has been sent successfully' Msg, @id id, case when @deliveryMethod = 'Mobile Wallet' then @controlNo else @tpRefNo end extra
END;
ELSE IF @flag = 'showLimit' BEGIN SELECT [paymentType] = sdv.detailTitle , limit.id , currency , sendingLimit = CAST(CAST(maximum AS DECIMAL(10,2)) AS VARCHAR) , cm.countryName , limitType = CASE WHEN ISNULL(limitType,'T') = 'T' THEN 'Per Transactioin' ELSE 'Per Day' END FROM onlineCustomerLimitSetup limit WITH ( NOLOCK ) INNER JOIN staticDataValue sdv WITH ( NOLOCK ) ON sdv.valueId = limit.payBy INNER JOIN countryMaster cm WITH ( NOLOCK ) ON cm.countryId = limit.receivingCountry WHERE customerVerification = @customerStatus AND limitType = 'T' AND limit.receivingCountry = '151'; END;
ELSE IF @flag ='lastTxnsOfBank' BEGIN select top 3 value= 'rFullName='+isnull(receiverName,'')+'=v-::-cmbAgent='+isnull(CAST(pBank AS VARCHAR),'')+ '=d-::-cmbAgentName='+isnull(pBankName,'')+'=v-::-hddBranch='+cast(isnull(pBankBranch,'') as varchar)+ '=v-::-hddBranchName='+isnull(pBankBranchName,'')+'=v-::-txtAccountNo='+isnull(rt.accountNo,'')+ '=v-::-receiverrelation='+isnull(rt.relWithSender,'')+'=d-::-RAddress='+isnull(address,'')+'=v-::-rState='+isnull([STATE],'')+ '=v-::-rCity='+isnull(city,'')+'=v-::-receiverMobile='+ isnull(mobile,'')+'=v-::-receiverEmail='+isnull(email,'')+ '=v-::-rTelephone='+isnull(homePhone,'')+'=v-::-ddllstReceiver='+isnull(cast(ts.customerId as varchar),'')+'=d' ,[text]= isnull(receiverName,'')+' | '+isnull(pBankName,'')+' | '+isnull(rt.accountNo,'') from dbo.vwRemitTran rt WITH(NOLOCK) LEFT JOIN dbo.vwTranReceivers ts WITH(NOLOCK) ON ts.tranId = rt.id WHERE tranType='O' AND rt.createdBy = @user AND isnull(paymentMethod,'CASH PAYMENT') = 'BANK DEPOSIT' AND rt.pCountry = @pCountry ORDER BY rt.holdTranId desc
RETURN END
ELSE IF @flag = 'isProVoucherUsed' BEGIN IF NOT EXISTS ( SELECT 'x' FROM remitTran(nolock) WHERE promotionCode IS NOT NULL AND createdBy = @user ) BEGIN SELECT '1' errorCode , 'Promotional Code already used.' , NULL; END; ELSE BEGIN SELECT '0' errorCode , 'Promotional Code not used.' , NULL; END; END; ELSE IF @flag = 'getTtranDetail' BEGIN SELECT cm.countryId , rt.pCountry, rt.tAmt, rt.pAmt, rt.payoutCurr, rt.pAgentName, rt.purposeOfRemit, rt.sourceOfFund, rt.pBankName, rt.pBankBranchName, rt.serviceCharge, rt.collCurr, customerRate =CASE WHEN rt.pAgent IN (224389,2129) THEN 0 ELSE rt.customerRate END, pAgentId = rt.pAgent,pBranchId =rt.pBranch,rt.cAmt,rt.pBank,rt.pBankBranch,payoutMethod = rt.paymentMethod, paymentMethod = s.serviceTypeId, rt.receiverName ,tr.address , tr.[state], tr.city , tr.mobile , tr.email , phone = tr.homePhone , relationship = rt.relWithSender , cAmt = CAST(cAmt AS DECIMAL(10, 2)) , collCurr , collMode , pAgent = CAST(pBank AS VARCHAR) + ISNULL('|' + pBankType, '') , pAgentName = pBankName , pBranch = pBankBranch , pBranchName = pBankBranchName , rt.accountNo , RI.receiverId, tr.firstName, tr.middleName, tr.lastName1, tr.state, tr.city, tr.address, tr.country, tr.relationType, tr.mobile, tr.email FROM RemitTran rt WITH ( NOLOCK ) INNER JOIN countryMaster cm WITH ( NOLOCK ) ON rt.pCountry = cm.countryName INNER JOIN TranReceivers tr WITH ( NOLOCK ) ON tr.tranId = rt.id INNER JOIN serviceTypeMaster s(nolock) on s.typeTitle = rt.paymentMethod LEFT JOIN dbo.receiverInformation RI (NOLOCK) ON RI.receiverId = tr.customerId WHERE rt.id = @tranId; END;
ELSE IF @flag = 'mostRecentTxn' BEGIN DECLARE @totalSend MONEY, @totalSendText VARCHAR(200), @YearStart DATE, @YearEnd DATETIME,@vYearlyLimit MONEY
SELECT @YearStart = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) ,@YearEnd = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, -1)+' 23:59:59' SELECT @totalSend = SUM(ROUND(R.cAmt/(R.sCurrCostRate + ISNULL(R.sCurrHoMargin, 0)), 2, 0)) FROM REMITTRAN R(NOLOCK) INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID WHERE T.CUSTOMERID = @senderId AND R.TRANSTATUS <> 'Cancel' AND R.approvedDate BETWEEN @YearStart AND @YearEnd
SELECT @vYearlyLimit = amount FROM dbo.csDetail CD(NOLOCK) INNER JOIN csMaster CM(NOLOCK) ON CM.csMasterId = CD.csMasterId WHERE CD.period = 365 AND CD.condition = 4600 AND ISNULL(CD.isActive, 'Y') = 'Y' AND ISNULL(CD.isDeleted, 'N') = 'N' AND ISNULL(CD.isEnable, 'Y') = 'Y' AND ISNULL(CM.isActive, 'Y') = 'Y' AND ISNULL(CM.isDeleted, 'N') = 'N'
SET @totalSendText = 'Remaining sending limit for the year '+FORMAT(GETDATE(),'yyyy')+' = USD '+FORMAT((@vYearlyLimit - ISNULL(@totalSend, 0)),'0,00'); SELECT DISTINCT TOP 3 R.id , createdDate = CONVERT(VARCHAR, createdDate, 101) , receiverName , paymentMethod , cAmt = CAST(cAmt AS DECIMAL(10, 2)) , tranStatus , collCurr,pCountry FROM REMITTRAN R ( NOLOCK ) -- needs to be remitTran For Every Successful Transaction
INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID WHERE T.CUSTOMERID = @senderId AND R.TRANSTATUS <> 'Cancel' ORDER BY R.ID DESC;
SELECT totalSendText = @totalSendText END
ELSE IF @flag = 'txnSummary' BEGIN SELECT DISTINCT id , holdTranId, createdDate = CONVERT(VARCHAR, createdDate, 101) , receiverName , paymentMethod , cAmt = CAST(cAmt AS DECIMAL(10, 2)) , tranStatus , collCurr FROM dbo.vwRemitTran WITH ( NOLOCK ) -- needs to be remitTran For Every Successful Transaction
where createdby = @user AND sAgent=@sAgent --needs to retrieve for the specific sending agent --WHERE tranType = 'O' -- AND createdBy = @user -- for sepecific user for now commented
ORDER BY holdTranId DESC; END;
ELSE IF @flag = 'hasScheme' BEGIN DECLARE @todayDate DATETIME; SET @todayDate = GETDATE(); IF EXISTS ( SELECT 'X' FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' ) BEGIN IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry = @pCountryId AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(couponCode, 'x') = @couponCode; IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry = @pCountryId AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry IS NULL AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry = @pCountryId AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry IS NULL AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; END; IF EXISTS ( SELECT 'X' FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' ) BEGIN IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry = @pCountryId AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry IS NULL AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; END; IF EXISTS ( SELECT 'X' FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' ) BEGIN IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry = @pCountryId AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; IF @schemeId IS NULL SELECT @schemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry IS NULL AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N'; END; IF @schemeId IS NOT NULL BEGIN DECLARE @multipleSchemeId INT; SELECT @multipleSchemeId = rowId FROM dbo.schemeSetup WITH ( NOLOCK ) WHERE rCountry = @pCountryId AND @todayDate BETWEEN schemeStartDate AND schemeEndDate AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND couponCode = @couponCode; IF @multipleSchemeId IS NOT NULL SELECT '0' errorCode , 'Scheme is Available.' msg , @multipleSchemeId id; ELSE SELECT '0' errorCode , 'Scheme is Available.' msg , @schemeId id; END; ELSE BEGIN SELECT '1' errorCode , 'Scheme is NOT Available.' msg , @schemeId id; END; END;
ELSE IF @flag = 'checkSingleTxn' BEGIN IF ( SELECT approvedDate FROM customerMaster WITH ( NOLOCK ) WHERE customerId = @user AND ISNULL(onlineUser, 'N') = 'Y' ) IS NULL BEGIN SELECT '1' ErrorCode , 'Sorry! Your customer verification is in pending.
Kindly visit to our nearest agent/branch to verify your document.' Msg,
@user Id; RETURN; END;
ELSE IF (SELECT availableBalance FROM dbo.customerMaster WITH (NOLOCK) WHERE customerId=@user AND ISNULL(onlineUser,'N')='Y') IS NULL BEGIN SELECT '1' ErrorCode, 'Sorry! You have no balance in your GME Wallet' Msg, @user Id; RETURN; END
ELSE BEGIN SELECT '0' ErrorCode ,'You are authorised to send transaction.' Msg , @user Id; RETURN; END; END; END; END TRY BEGIN CATCH IF @@TRANCOUNT <> 0 ROLLBACK TRANSACTION; DECLARE @errorMessage VARCHAR(MAX); SET @errorMessage = ERROR_MESSAGE(); EXEC proc_errorHandler 1, @errorMessage, @user; END CATCH
|