Arjun Dhami
7 months ago
62 changed files with 2422 additions and 8 deletions
-
606DB/Functions/FNAGetSendComm.sql
-
606DB/SP's/FNAGetSendComm_PROC - Copy.sql
-
606DB/SP's/FNAGetSendComm_PROC.sql
-
577DB/SP's/PROC_REMIT_INBOUND_TRANSACTION_SEND.sql
-
19DB/eXEC QUERY.sql
-
BINRemitInboundAPI/.vs/ProjectEvaluation/remitinboundapi.metadata.v7.bin
-
BINRemitInboundAPI/.vs/ProjectEvaluation/remitinboundapi.projects.v7.bin
-
BINRemitInboundAPI/.vs/RemitInboundAPI/DesignTimeBuild/.dtbcache.v2
-
BINRemitInboundAPI/.vs/RemitInboundAPI/FileContentIndex/230daa69-897c-46e5-bfcb-7972493b7084.vsidx
-
BINRemitInboundAPI/.vs/RemitInboundAPI/FileContentIndex/31e5f1be-106f-4c89-ab2f-91d20fda133a.vsidx
-
BINRemitInboundAPI/.vs/RemitInboundAPI/FileContentIndex/782cf0ce-0ca8-4927-ae8d-fe5480d0b397.vsidx
-
BINRemitInboundAPI/.vs/RemitInboundAPI/v17/.futdcache.v2
-
BINRemitInboundAPI/.vs/RemitInboundAPI/v17/.suo
-
BINRemitInboundAPI/RemitInboundAPI.Business/bin/Debug/net8.0/RemitInboundAPI.Business.dll
-
BINRemitInboundAPI/RemitInboundAPI.Business/bin/Debug/net8.0/RemitInboundAPI.Business.pdb
-
BINRemitInboundAPI/RemitInboundAPI.Business/bin/Debug/net8.0/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI.Business/bin/Debug/net8.0/RemitInboundAPI.Common.pdb
-
BINRemitInboundAPI/RemitInboundAPI.Business/bin/Debug/net8.0/RemitInboundAPI.Repository.dll
-
BINRemitInboundAPI/RemitInboundAPI.Business/bin/Debug/net8.0/RemitInboundAPI.Repository.pdb
-
2RemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/RemitInboundAPI.Business.AssemblyInfo.cs
-
2RemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/RemitInboundAPI.Business.AssemblyInfoInputs.cache
-
BINRemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/RemitInboundAPI.Business.csproj.AssemblyReference.cache
-
BINRemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/RemitInboundAPI.Business.dll
-
BINRemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/RemitInboundAPI.Business.pdb
-
BINRemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/ref/RemitInboundAPI.Business.dll
-
BINRemitInboundAPI/RemitInboundAPI.Business/obj/Debug/net8.0/refint/RemitInboundAPI.Business.dll
-
BINRemitInboundAPI/RemitInboundAPI.Common/bin/Debug/net8.0/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI.Common/bin/Debug/net8.0/RemitInboundAPI.Common.pdb
-
2RemitInboundAPI/RemitInboundAPI.Common/obj/Debug/net8.0/RemitInboundAPI.Common.AssemblyInfo.cs
-
2RemitInboundAPI/RemitInboundAPI.Common/obj/Debug/net8.0/RemitInboundAPI.Common.AssemblyInfoInputs.cache
-
BINRemitInboundAPI/RemitInboundAPI.Common/obj/Debug/net8.0/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI.Common/obj/Debug/net8.0/RemitInboundAPI.Common.pdb
-
BINRemitInboundAPI/RemitInboundAPI.Common/obj/Debug/net8.0/ref/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI.Common/obj/Debug/net8.0/refint/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI.Repository/bin/Debug/net8.0/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI.Repository/bin/Debug/net8.0/RemitInboundAPI.Common.pdb
-
BINRemitInboundAPI/RemitInboundAPI.Repository/bin/Debug/net8.0/RemitInboundAPI.Repository.dll
-
BINRemitInboundAPI/RemitInboundAPI.Repository/bin/Debug/net8.0/RemitInboundAPI.Repository.pdb
-
2RemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/RemitInboundAPI.Repository.AssemblyInfo.cs
-
2RemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/RemitInboundAPI.Repository.AssemblyInfoInputs.cache
-
BINRemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/RemitInboundAPI.Repository.csproj.AssemblyReference.cache
-
BINRemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/RemitInboundAPI.Repository.dll
-
BINRemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/RemitInboundAPI.Repository.pdb
-
BINRemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/ref/RemitInboundAPI.Repository.dll
-
BINRemitInboundAPI/RemitInboundAPI.Repository/obj/Debug/net8.0/refint/RemitInboundAPI.Repository.dll
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.Business.dll
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.Business.pdb
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.Common.dll
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.Common.pdb
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.Repository.dll
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.Repository.pdb
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.dll
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.exe
-
BINRemitInboundAPI/RemitInboundAPI/bin/Debug/net8.0/RemitInboundAPI.pdb
-
2RemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/RemitInboundAPI.AssemblyInfo.cs
-
2RemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/RemitInboundAPI.AssemblyInfoInputs.cache
-
BINRemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/RemitInboundAPI.csproj.AssemblyReference.cache
-
BINRemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/RemitInboundAPI.dll
-
BINRemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/RemitInboundAPI.pdb
-
BINRemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/apphost.exe
-
BINRemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/ref/RemitInboundAPI.dll
-
BINRemitInboundAPI/RemitInboundAPI/obj/Debug/net8.0/refint/RemitInboundAPI.dll
@ -0,0 +1,606 @@ |
|||
|
|||
ALTER FUNCTION [dbo].[FNAGetSendComm]( |
|||
@sCountry INT, @ssAgent INT, @sAgent INT, @sBranch INT |
|||
,@rCountry INT, @rsAgent INT, @rAgent INT, @rBranch INT |
|||
,@collCurr VARCHAR(3),@serviceType INT |
|||
,@collAmt MONEY |
|||
,@payAmt MONEY |
|||
,@serviceCharge MONEY |
|||
,@hubComm MONEY |
|||
,@agentComm MONEY |
|||
,@sSettlementRate FLOAT |
|||
,@pSettlementRate FLOAT |
|||
) |
|||
RETURNS @list TABLE (masterId BIGINT, masterType CHAR(1), amount MONEY, commissionCurrency VARCHAR(3)) |
|||
AS |
|||
BEGIN |
|||
DECLARE |
|||
@sState INT |
|||
,@sZip VARCHAR(10) |
|||
,@sGroup INT |
|||
,@masterId BIGINT |
|||
,@found BIT = 0 |
|||
,@masterType CHAR(1) |
|||
,@rState INT |
|||
,@rGroup INT |
|||
,@rZip INT |
|||
,@date DATETIME |
|||
,@commissionBase INT |
|||
,@amt MONEY |
|||
,@commGroup INT |
|||
|
|||
DECLARE @commissionRule TABLE(ruleId INT) |
|||
DECLARE @commissionPackage TABLE(packageId INT) |
|||
|
|||
SET @date = CONVERT(VARCHAR, GETDATE(), 101) |
|||
|
|||
DECLARE @agentType INT |
|||
|
|||
--1. Find Sending Agent Details------------------------------------------------------------------------------------------------------- |
|||
SELECT |
|||
@agentType = agentType |
|||
,@sState = csm.stateId |
|||
,@sZip = agentZip |
|||
FROM agentMaster am WITH(NOLOCK) |
|||
LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateName |
|||
WHERE agentId = @sBranch |
|||
|
|||
IF @agentType = 2903 |
|||
BEGIN |
|||
SET @sAgent = @sBranch |
|||
SET @sBranch = NULL |
|||
END |
|||
|
|||
--*****Check For Payout Super Agent***** |
|||
IF @rAgent IS NOT NULL AND @rsAgent IS NULL |
|||
SELECT @rsAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @rAgent |
|||
|
|||
SELECT @sGroup = groupDetail FROM agentGroupMaping WHERE ISNULL(isDeleted, 'N') = 'N' AND groupCat = 6300 AND agentId = ISNULL(@sBranch, @sAgent) |
|||
|
|||
--Location Group |
|||
--Your location Group logic goes here |
|||
IF EXISTS(SELECT 'X' FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = ISNULL(@sBranch, @sAgent) AND ruleType = 'cs') |
|||
BEGIN |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = ISNULL(@sBranch, @sAgent) AND ruleType = 'cs' |
|||
END |
|||
ELSE IF EXISTS(SELECT 'X' FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = @sAgent AND ruleType = 'cs') |
|||
BEGIN |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = @sAgent AND ruleType = 'cs' |
|||
END |
|||
ELSE |
|||
BEGIN |
|||
--Commission Group |
|||
SELECT @commGroup = groupDetail FROM agentGroupMaping WITH(NOLOCK) WHERE groupCat = 6600 AND agentId = ISNULL(@sBranch, @sAgent) AND ISNULL(isDeleted, 'N') = 'N' |
|||
--Commission Package |
|||
INSERT @commissionPackage |
|||
SELECT packageId FROM commissionGroup WITH(NOLOCK) WHERE groupId = @commGroup AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y' |
|||
--Commission Rule |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM commissionPackage WITH(NOLOCK) WHERE packageId IN (SELECT packageId FROM @commissionPackage) AND ruleType = 'CS' AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y' |
|||
END |
|||
|
|||
--2. Find Receiving Agent and Location Details |
|||
IF @rBranch IS NOT NULL |
|||
BEGIN |
|||
SELECT |
|||
@agentType = agentType |
|||
,@rState = csm.stateId |
|||
,@rZip = agentZip |
|||
FROM agentMaster am WITH(NOLOCK) |
|||
LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateName |
|||
WHERE agentId = @rBranch |
|||
|
|||
IF @agentType = 2903 |
|||
BEGIN |
|||
SET @rAgent = @rBranch |
|||
SET @rBranch = NULL |
|||
END |
|||
SELECT @rGroup = groupDetail FROM agentGroupMaping WHERE ISNULL(isDeleted, 'N') = 'N' AND groupCat = 6300 AND agentId = ISNULL(@rBranch, @rAgent) |
|||
END |
|||
|
|||
IF EXISTS( |
|||
SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) |
|||
INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId |
|||
INNER JOIN scSendDetail sd WITH(NOLOCK) ON sm.scSendMasterId = sd.scSendMasterId |
|||
WHERE |
|||
ISNULL(sm.isActive, 'N') = 'Y' |
|||
AND ISNULL(sm.isEnable, 'N') = 'Y' |
|||
AND ISNULL(sm.isDeleted, 'N') = 'N' |
|||
|
|||
AND |
|||
|
|||
( |
|||
(sBranch = @sBranch OR sBranch IS NULL) |
|||
AND (ssAgent = @ssAgent OR ssAgent IS NULL) |
|||
AND (sAgent = @sAgent OR sAgent IS NULL) |
|||
OR [state] = @sState |
|||
OR agentGroup = @sGroup |
|||
OR zip = @sZip |
|||
) |
|||
|
|||
AND |
|||
|
|||
( |
|||
(rBranch = @rBranch OR rBranch IS NULL) |
|||
AND (rAgent = @rAgent OR rAgent IS NULL) |
|||
AND (rCountry = @rCountry OR rCountry IS NULL) |
|||
AND (rsAgent = @rsAgent OR rsAgent IS NULL) |
|||
OR [rState] = @rState |
|||
OR rAgentGroup = @rGroup |
|||
OR rZip = @rZip |
|||
) |
|||
AND baseCurrency = @collCurr |
|||
AND (tranType = @serviceType OR tranType IS NULL) |
|||
AND ISNULL(sd.isActive, 'N') = 'Y' |
|||
AND ISNULL(sd.isDeleted, 'N') = 'N' |
|||
--AND @collAmt BETWEEN fromAmt and toAmt |
|||
AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
) |
|||
|
|||
BEGIN -- Special Setting |
|||
SET @masterType = 'S' |
|||
--1 Branch |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
SELECT @commissionBase = commissionBase FROM scSendMaster WHERE scSendMasterId = @masterId |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--2 Agent and Agent Group |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sAgent = @sAgent AND sBranch IS |
|||
|
|||
NULL AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent |
|||
|
|||
AND sBranch IS NULL AND agentGroup = @sGroup) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, |
|||
|
|||
'2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--3 Super Agent |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry OR rCountry IS NULL) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SET @found = 1 |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, |
|||
|
|||
'2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--4 Zip |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--5 State |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rBranch = |
|||
|
|||
@rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState |
|||
|
|||
AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and AGent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
--INSERT INTO @list |
|||
--SELECT TOP 1 ruleId,@masterId,1,1 FROM @commissionRule |
|||
--RETURN |
|||
--6 Country |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent |
|||
|
|||
IS NULL AND sAgent IS NULL AND sBranch IS NULL AND (rBranch = @rBranch OR rAgent = @rAgent OR (rCountry = @rCountry OR rCountry IS NULL)) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgent = @rAgent AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgent = @rAgent AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND |
|||
|
|||
ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
END |
|||
INSERT INTO @list |
|||
SELECT NULL, NULL, NULL, NULL |
|||
RETURN |
|||
END |
|||
|
|||
|
@ -0,0 +1,606 @@ |
|||
|
|||
ALTER PROC [dbo].[FNAGetSendComm_PROC]( |
|||
@sCountry INT, @ssAgent INT, @sAgent INT, @sBranch INT |
|||
,@rCountry INT, @rsAgent INT, @rAgent INT, @rBranch INT |
|||
,@collCurr VARCHAR(3),@serviceType INT |
|||
,@collAmt MONEY |
|||
,@payAmt MONEY |
|||
,@serviceCharge MONEY |
|||
,@hubComm MONEY |
|||
,@agentComm MONEY |
|||
,@sSettlementRate FLOAT |
|||
,@pSettlementRate FLOAT |
|||
) |
|||
AS |
|||
BEGIN |
|||
DECLARE @list TABLE (masterId BIGINT, masterType CHAR(1), amount MONEY, commissionCurrency VARCHAR(3)) |
|||
DECLARE |
|||
@sState INT |
|||
,@sZip VARCHAR(10) |
|||
,@sGroup INT |
|||
,@masterId BIGINT |
|||
,@found BIT = 0 |
|||
,@masterType CHAR(1) |
|||
,@rState INT |
|||
,@rGroup INT |
|||
,@rZip INT |
|||
,@date DATETIME |
|||
,@commissionBase INT |
|||
,@amt MONEY |
|||
,@commGroup INT |
|||
|
|||
DECLARE @commissionRule TABLE(ruleId INT) |
|||
DECLARE @commissionPackage TABLE(packageId INT) |
|||
|
|||
SET @date = CONVERT(VARCHAR, GETDATE(), 101) |
|||
|
|||
DECLARE @agentType INT |
|||
|
|||
--1. Find Sending Agent Details------------------------------------------------------------------------------------------------------- |
|||
SELECT |
|||
@agentType = agentType |
|||
,@sState = csm.stateId |
|||
,@sZip = agentZip |
|||
FROM agentMaster am WITH(NOLOCK) |
|||
LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateName |
|||
WHERE agentId = @sBranch |
|||
|
|||
IF @agentType = 2903 |
|||
BEGIN |
|||
SET @sAgent = @sBranch |
|||
SET @sBranch = NULL |
|||
END |
|||
|
|||
--*****Check For Payout Super Agent***** |
|||
IF @rAgent IS NOT NULL AND @rsAgent IS NULL |
|||
SELECT @rsAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @rAgent |
|||
|
|||
SELECT @sGroup = groupDetail FROM agentGroupMaping WHERE ISNULL(isDeleted, 'N') = 'N' AND groupCat = 6300 AND agentId = ISNULL(@sBranch, @sAgent) |
|||
|
|||
--Location Group |
|||
--Your location Group logic goes here |
|||
IF EXISTS(SELECT 'X' FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = ISNULL(@sBranch, @sAgent) AND ruleType = 'cs') |
|||
BEGIN |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = ISNULL(@sBranch, @sAgent) AND ruleType = 'cs' |
|||
END |
|||
ELSE IF EXISTS(SELECT 'X' FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = @sAgent AND ruleType = 'cs') |
|||
BEGIN |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = @sAgent AND ruleType = 'cs' |
|||
END |
|||
ELSE |
|||
BEGIN |
|||
--Commission Group |
|||
SELECT @commGroup = groupDetail FROM agentGroupMaping WITH(NOLOCK) WHERE groupCat = 6600 AND agentId = ISNULL(@sBranch, @sAgent) AND ISNULL(isDeleted, 'N') = 'N' |
|||
--Commission Package |
|||
INSERT @commissionPackage |
|||
SELECT packageId FROM commissionGroup WITH(NOLOCK) WHERE groupId = @commGroup AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y' |
|||
--Commission Rule |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM commissionPackage WITH(NOLOCK) WHERE packageId IN (SELECT packageId FROM @commissionPackage) AND ruleType = 'CS' AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y' |
|||
END |
|||
|
|||
--2. Find Receiving Agent and Location Details |
|||
IF @rBranch IS NOT NULL |
|||
BEGIN |
|||
SELECT |
|||
@agentType = agentType |
|||
,@rState = csm.stateId |
|||
,@rZip = agentZip |
|||
FROM agentMaster am WITH(NOLOCK) |
|||
LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateName |
|||
WHERE agentId = @rBranch |
|||
|
|||
IF @agentType = 2903 |
|||
BEGIN |
|||
SET @rAgent = @rBranch |
|||
SET @rBranch = NULL |
|||
END |
|||
SELECT @rGroup = groupDetail FROM agentGroupMaping WHERE ISNULL(isDeleted, 'N') = 'N' AND groupCat = 6300 AND agentId = ISNULL(@rBranch, @rAgent) |
|||
END |
|||
|
|||
IF EXISTS( |
|||
SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) |
|||
INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId |
|||
INNER JOIN scSendDetail sd WITH(NOLOCK) ON sm.scSendMasterId = sd.scSendMasterId |
|||
WHERE |
|||
ISNULL(sm.isActive, 'N') = 'Y' |
|||
AND ISNULL(sm.isEnable, 'N') = 'Y' |
|||
AND ISNULL(sm.isDeleted, 'N') = 'N' |
|||
|
|||
AND |
|||
|
|||
( |
|||
(sBranch = @sBranch OR sBranch IS NULL) |
|||
AND (ssAgent = @ssAgent OR ssAgent IS NULL) |
|||
AND (sAgent = @sAgent OR sAgent IS NULL) |
|||
OR [state] = @sState |
|||
OR agentGroup = @sGroup |
|||
OR zip = @sZip |
|||
) |
|||
|
|||
AND |
|||
|
|||
( |
|||
(rBranch = @rBranch OR rBranch IS NULL) |
|||
AND (rAgent = @rAgent OR rAgent IS NULL) |
|||
AND (rCountry = @rCountry OR rCountry IS NULL) |
|||
AND (rsAgent = @rsAgent OR rsAgent IS NULL) |
|||
OR [rState] = @rState |
|||
OR rAgentGroup = @rGroup |
|||
OR rZip = @rZip |
|||
) |
|||
AND baseCurrency = @collCurr |
|||
AND (tranType = @serviceType OR tranType IS NULL) |
|||
AND ISNULL(sd.isActive, 'N') = 'Y' |
|||
AND ISNULL(sd.isDeleted, 'N') = 'N' |
|||
--AND @collAmt BETWEEN fromAmt and toAmt |
|||
AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
) |
|||
|
|||
BEGIN -- Special Setting |
|||
SET @masterType = 'S' |
|||
--1 Branch |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
SELECT @commissionBase = commissionBase FROM scSendMaster WHERE scSendMasterId = @masterId |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--2 Agent and Agent Group |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sAgent = @sAgent AND sBranch IS |
|||
|
|||
NULL AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent |
|||
|
|||
AND sBranch IS NULL AND agentGroup = @sGroup) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, |
|||
|
|||
'2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--3 Super Agent |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry OR rCountry IS NULL) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SET @found = 1 |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, |
|||
|
|||
'2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--4 Zip |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--5 State |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rBranch = |
|||
|
|||
@rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState |
|||
|
|||
AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and AGent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
--INSERT INTO @list |
|||
--SELECT TOP 1 ruleId,@masterId,1,1 FROM @commissionRule |
|||
--RETURN |
|||
--6 Country |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent |
|||
|
|||
IS NULL AND sAgent IS NULL AND sBranch IS NULL AND (rBranch = @rBranch OR rAgent = @rAgent OR (rCountry = @rCountry OR rCountry IS NULL)) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgent = @rAgent AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgent = @rAgent AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND |
|||
|
|||
ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
END |
|||
INSERT INTO @list |
|||
SELECT NULL, NULL, NULL, NULL |
|||
RETURN |
|||
END |
|||
|
|||
|
@ -0,0 +1,606 @@ |
|||
|
|||
ALTER FUNCTION [dbo].[FNAGetSendComm]( |
|||
@sCountry INT, @ssAgent INT, @sAgent INT, @sBranch INT |
|||
,@rCountry INT, @rsAgent INT, @rAgent INT, @rBranch INT |
|||
,@collCurr VARCHAR(3),@serviceType INT |
|||
,@collAmt MONEY |
|||
,@payAmt MONEY |
|||
,@serviceCharge MONEY |
|||
,@hubComm MONEY |
|||
,@agentComm MONEY |
|||
,@sSettlementRate FLOAT |
|||
,@pSettlementRate FLOAT |
|||
) |
|||
RETURNS @list TABLE (masterId BIGINT, masterType CHAR(1), amount MONEY, commissionCurrency VARCHAR(3)) |
|||
AS |
|||
BEGIN |
|||
DECLARE |
|||
@sState INT |
|||
,@sZip VARCHAR(10) |
|||
,@sGroup INT |
|||
,@masterId BIGINT |
|||
,@found BIT = 0 |
|||
,@masterType CHAR(1) |
|||
,@rState INT |
|||
,@rGroup INT |
|||
,@rZip INT |
|||
,@date DATETIME |
|||
,@commissionBase INT |
|||
,@amt MONEY |
|||
,@commGroup INT |
|||
|
|||
DECLARE @commissionRule TABLE(ruleId INT) |
|||
DECLARE @commissionPackage TABLE(packageId INT) |
|||
|
|||
SET @date = CONVERT(VARCHAR, GETDATE(), 101) |
|||
|
|||
DECLARE @agentType INT |
|||
|
|||
--1. Find Sending Agent Details------------------------------------------------------------------------------------------------------- |
|||
SELECT |
|||
@agentType = agentType |
|||
,@sState = csm.stateId |
|||
,@sZip = agentZip |
|||
FROM agentMaster am WITH(NOLOCK) |
|||
LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateName |
|||
WHERE agentId = @sBranch |
|||
|
|||
IF @agentType = 2903 |
|||
BEGIN |
|||
SET @sAgent = @sBranch |
|||
SET @sBranch = NULL |
|||
END |
|||
|
|||
--*****Check For Payout Super Agent***** |
|||
IF @rAgent IS NOT NULL AND @rsAgent IS NULL |
|||
SELECT @rsAgent = parentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @rAgent |
|||
|
|||
SELECT @sGroup = groupDetail FROM agentGroupMaping WHERE ISNULL(isDeleted, 'N') = 'N' AND groupCat = 6300 AND agentId = ISNULL(@sBranch, @sAgent) |
|||
|
|||
--Location Group |
|||
--Your location Group logic goes here |
|||
IF EXISTS(SELECT 'X' FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = ISNULL(@sBranch, @sAgent) AND ruleType = 'cs') |
|||
BEGIN |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = ISNULL(@sBranch, @sAgent) AND ruleType = 'cs' |
|||
END |
|||
ELSE IF EXISTS(SELECT 'X' FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = @sAgent AND ruleType = 'cs') |
|||
BEGIN |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM agentCommissionRule WITH(NOLOCK) WHERE agentId = @sAgent AND ruleType = 'cs' |
|||
END |
|||
ELSE |
|||
BEGIN |
|||
--Commission Group |
|||
SELECT @commGroup = groupDetail FROM agentGroupMaping WITH(NOLOCK) WHERE groupCat = 6600 AND agentId = ISNULL(@sBranch, @sAgent) AND ISNULL(isDeleted, 'N') = 'N' |
|||
--Commission Package |
|||
INSERT @commissionPackage |
|||
SELECT packageId FROM commissionGroup WITH(NOLOCK) WHERE groupId = @commGroup AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y' |
|||
--Commission Rule |
|||
INSERT @commissionRule |
|||
SELECT DISTINCT ruleId FROM commissionPackage WITH(NOLOCK) WHERE packageId IN (SELECT packageId FROM @commissionPackage) AND ruleType = 'CS' AND ISNULL(isDeleted, 'N') = 'N' AND ISNULL(isActive, 'N') = 'Y' |
|||
END |
|||
|
|||
--2. Find Receiving Agent and Location Details |
|||
IF @rBranch IS NOT NULL |
|||
BEGIN |
|||
SELECT |
|||
@agentType = agentType |
|||
,@rState = csm.stateId |
|||
,@rZip = agentZip |
|||
FROM agentMaster am WITH(NOLOCK) |
|||
LEFT JOIN countryStateMaster csm WITH(NOLOCK) ON am.agentState = csm.stateName |
|||
WHERE agentId = @rBranch |
|||
|
|||
IF @agentType = 2903 |
|||
BEGIN |
|||
SET @rAgent = @rBranch |
|||
SET @rBranch = NULL |
|||
END |
|||
SELECT @rGroup = groupDetail FROM agentGroupMaping WHERE ISNULL(isDeleted, 'N') = 'N' AND groupCat = 6300 AND agentId = ISNULL(@rBranch, @rAgent) |
|||
END |
|||
|
|||
IF EXISTS( |
|||
SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) |
|||
INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId |
|||
INNER JOIN scSendDetail sd WITH(NOLOCK) ON sm.scSendMasterId = sd.scSendMasterId |
|||
WHERE |
|||
ISNULL(sm.isActive, 'N') = 'Y' |
|||
AND ISNULL(sm.isEnable, 'N') = 'Y' |
|||
AND ISNULL(sm.isDeleted, 'N') = 'N' |
|||
|
|||
AND |
|||
|
|||
( |
|||
(sBranch = @sBranch OR sBranch IS NULL) |
|||
AND (ssAgent = @ssAgent OR ssAgent IS NULL) |
|||
AND (sAgent = @sAgent OR sAgent IS NULL) |
|||
OR [state] = @sState |
|||
OR agentGroup = @sGroup |
|||
OR zip = @sZip |
|||
) |
|||
|
|||
AND |
|||
|
|||
( |
|||
(rBranch = @rBranch OR rBranch IS NULL) |
|||
AND (rAgent = @rAgent OR rAgent IS NULL) |
|||
AND (rCountry = @rCountry OR rCountry IS NULL) |
|||
AND (rsAgent = @rsAgent OR rsAgent IS NULL) |
|||
OR [rState] = @rState |
|||
OR rAgentGroup = @rGroup |
|||
OR rZip = @rZip |
|||
) |
|||
AND baseCurrency = @collCurr |
|||
AND (tranType = @serviceType OR tranType IS NULL) |
|||
AND ISNULL(sd.isActive, 'N') = 'Y' |
|||
AND ISNULL(sd.isDeleted, 'N') = 'N' |
|||
--AND @collAmt BETWEEN fromAmt and toAmt |
|||
AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
) |
|||
|
|||
BEGIN -- Special Setting |
|||
SET @masterType = 'S' |
|||
--1 Branch |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sBranch = @sBranch AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
SELECT @commissionBase = commissionBase FROM scSendMaster WHERE scSendMasterId = @masterId |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--2 Agent and Agent Group |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sAgent = @sAgent AND sBranch IS |
|||
|
|||
NULL AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent |
|||
|
|||
AND sBranch IS NULL AND agentGroup = @sGroup) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31' |
|||
|
|||
) |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup = @sGroup) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, |
|||
|
|||
'2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (sAgent = @sAgent AND sBranch IS NULL AND agentGroup IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--3 Super Agent |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry OR rCountry IS NULL) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
--1. Receiving Branch |
|||
SET @found = 1 |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
|
|||
|
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, |
|||
|
|||
'2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND (ssAgent = @ssAgent AND sAgent IS NULL AND sBranch IS NULL) AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--4 Zip |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND (rBranch = @rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
(rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
|
|||
rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND zip = @sZip AND |
|||
rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
|
|||
--5 State |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rBranch = |
|||
|
|||
@rBranch OR rAgent = @rAgent OR rCountry = @rCountry) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState |
|||
|
|||
AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and AGent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup = @rGroup) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND (rAgent = @rAgent AND rBranch IS NULL AND rAgentGroup IS NULL) AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND [state] = @sState AND rCountry IS NULL AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
--INSERT INTO @list |
|||
--SELECT TOP 1 ruleId,@masterId,1,1 FROM @commissionRule |
|||
--RETURN |
|||
--6 Country |
|||
IF EXISTS(SELECT 'x' FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent |
|||
|
|||
IS NULL AND sAgent IS NULL AND sBranch IS NULL AND (rBranch = @rBranch OR rAgent = @rAgent OR (rCountry = @rCountry OR rCountry IS NULL)) AND baseCurrency = @collCurr AND (tranType = @serviceType OR tranType IS NULL) AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31')) |
|||
BEGIN |
|||
SET @found = 1 |
|||
--1. Receiving Branch |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rBranch = @rBranch AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--2. Receiving Agent and Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgent = @rAgent AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgent = @rAgent AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--3. Receiving Super Agent |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rsAgent = @rsAgent AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--4. Receiving Agent Group |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rAgentGroup = @rGroup AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--5. Receiving Zip |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rZip = @rZip AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rZip = @rZip AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--6. Receiving State |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rState = @rState AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rState = @rState AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--7. Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry = @rCountry AND rsAgent IS NULL AND rAgent IS NULL AND rBranch IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND |
|||
|
|||
ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
--8. All Receiving Country |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry IS NULL AND baseCurrency = @collCurr AND tranType = @serviceType AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
IF @masterId IS NULL |
|||
SELECT @masterId = scSendMasterId FROM scSendMaster sm WITH(NOLOCK) INNER JOIN @commissionRule cr ON sm.scSendMasterId = cr.ruleId WHERE ISNULL(isEnable, 'N') = 'Y' AND ISNULL(isActive, 'N') = 'Y' AND ISNULL(isDeleted, 'N') = 'N' AND sCountry = @sCountry AND ssAgent IS NULL AND sAgent IS NULL AND sBranch IS NULL AND rCountry IS NULL AND baseCurrency = @collCurr AND tranType IS NULL AND @date BETWEEN ISNULL(effectiveFrom, '1900-01-01') AND ISNULL(effectiveTo, '2100-12-31') |
|||
|
|||
INSERT INTO @list |
|||
SELECT @masterId, @masterType, [dbo].FNAGetCommission(@masterId, @masterType, @collAmt, @payAmt, @serviceCharge, @hubComm, @agentComm, 's', @sSettlementRate, @pSettlementRate, @collCurr, NULL), baseCurrency FROM scSendMaster WITH(NOLOCK) WHERE scSendMasterId = @masterId |
|||
RETURN |
|||
END |
|||
END |
|||
INSERT INTO @list |
|||
SELECT NULL, NULL, NULL, NULL |
|||
RETURN |
|||
END |
|||
|
|||
|
@ -0,0 +1,577 @@ |
|||
|
|||
|
|||
ALTER PROC PROC_REMIT_INBOUND_TRANSACTION_SEND |
|||
( |
|||
@Flag VARCHAR(20) |
|||
, @UserName VARCHAR(80) = NULL |
|||
, @SendingCountryCode VARCHAR(10) = NULL |
|||
, @PayoutCountryCode VARCHAR(10) = NULL |
|||
, @PayoutTypeCode VARCHAR(10) = NULL |
|||
, @PayoutBankCode VARCHAR(10) = NULL |
|||
, @PayoutBankBranchCode VARCHAR(10) = NULL |
|||
, @PayoutCurrencyCode VARCHAR(10) = NULL |
|||
, @SendingCurrencyCode VARCHAR(10) = NULL |
|||
, @CollectionAmount MONEY = NULL |
|||
, @TransferAmount MONEY = NULL |
|||
, @PayoutAmount MONEY = NULL |
|||
, @ServiceCharge MONEY = NULL |
|||
, @ExchangeRate FLOAT = NULL |
|||
, @RemittancePurpose INT = NULL |
|||
, @SourceOfFund INT = NULL |
|||
, @Relationship INT = NULL |
|||
, @Occupation INT = NULL |
|||
, @PartnerTransactionId VARCHAR(40) = NULL |
|||
, @CalcBy CHAR(1) = NULL |
|||
, @AgentId INT = NULL |
|||
--SENDER DETAILS |
|||
, @SenderFirstName VARCHAR(60) = NULL |
|||
, @SenderMiddleName VARCHAR(60) = NULL |
|||
, @SenderLastName VARCHAR(40) = NULL |
|||
, @SenderIdType INT = NULL |
|||
, @SenderIdNo VARCHAR(20) = NULL |
|||
, @SenderIdIssuedDate VARCHAR(10) = NULL |
|||
, @SenderIdValidDate VARCHAR(10) = NULL |
|||
, @SenderMobile VARCHAR(15) = NULL |
|||
, @SenderNativeCountryCode VARCHAR(10) = NULL |
|||
, @SenderCity VARCHAR(80) = NULL |
|||
, @SenderAddress VARCHAR(150) = NULL |
|||
, @SenderEmail VARCHAR(150) = NULL |
|||
, @SenderGender VARCHAR(10) = NULL |
|||
, @SenderDOB VARCHAR(10) = NULL |
|||
--RECEIVER DETAILS |
|||
, @ReceiverFirstName VARCHAR(60) = NULL |
|||
, @ReceiverMiddleName VARCHAR(60) = NULL |
|||
, @ReceiverLastName VARCHAR(60) = NULL |
|||
, @ReceiverIdType INT = NULL |
|||
, @ReceiverIdNo VARCHAR(20) = NULL |
|||
, @ReceiverIdIssuedDate VARCHAR(10) = NULL |
|||
, @ReceiverIdValidDate VARCHAR(10) = NULL |
|||
, @ReceiverMobile VARCHAR(15) = NULL |
|||
, @ReceiverCity VARCHAR(80) = NULL |
|||
, @ReceiverAddress VARCHAR(150) = NULL |
|||
, @ReceiverEmail VARCHAR(150) = NULL |
|||
, @ReceiverAccountNo VARCHAR(40) = NULL |
|||
, @IpAddress VARCHAR(20) = NULL |
|||
, @CheckOfacFlag CHAR(1) = NULL |
|||
) |
|||
AS; |
|||
SET NOCOUNT ON; |
|||
SET XACT_ABORT ON; |
|||
BEGIN TRY |
|||
BEGIN |
|||
DECLARE @ErrorMsg VARCHAR(MAX) = NULL |
|||
IF @Flag = 'SEND' |
|||
BEGIN |
|||
IF ISNULL(@CheckOfacFlag, '') = '' |
|||
SET @CheckOfacFlag = 'N' |
|||
IF EXISTS(SELECT TOP 1 1 FROM remitTranTemp (NOLOCK) WHERE controlNo2 = dbo.fnaencryptstring(@PartnerTransactionId)) OR EXISTS (SELECT TOP 1 1 FROM remitTran (NOLOCK) WHERE controlNo2 = dbo.fnaencryptstring(@PartnerTransactionId)) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Duplicate partner transaction id.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
DECLARE @PCountryId INT, @DeliveryMethodId INT, @PayoutPartner INT, @ExRateCalcByPartner BIT, @ScountryId INT |
|||
DECLARE @SSuperAgentId INT, @PAgent INT, @SAgentId INT = @AgentId, @PCountryName VARCHAR(80), @SCountryName VARCHAR(80) |
|||
|
|||
SELECT @PCountryId = countryId, @PCountryName = countryName |
|||
FROM COUNTRYMASTER (NOLOCK) |
|||
WHERE countryCode = @PayoutCountryCode |
|||
|
|||
IF ISNULL(@PCountryId, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid PayoutCountryCode, contact Head Office.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SELECT @ScountryId = countryId, @SCountryName = countryName |
|||
FROM COUNTRYMASTER (NOLOCK) |
|||
WHERE countryCode = @SendingCountryCode |
|||
|
|||
IF ISNULL(@ScountryId, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid SendingCountryCode, contact Head Office.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
DECLARE @DeliveryMethodName VARCHAR(40) |
|||
SELECT @DeliveryMethodId = serviceTypeId, @DeliveryMethodName = typeTitle |
|||
FROM SERVICETYPEMASTER (NOLOCK) |
|||
WHERE serviceCode = @PayoutTypeCode |
|||
|
|||
IF ISNULL(@DeliveryMethodId, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid PaymentTypeCode, contact Head Office.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SELECT @PayoutPartner = AGENTID |
|||
,@ExRateCalcByPartner = ISNULL(exRateCalByPartner, 0) |
|||
FROM TblPartnerwiseCountry(NOLOCK) |
|||
WHERE CountryId = @PCountryId |
|||
AND IsActive = 1 |
|||
AND ISNULL(PaymentMethod, @DeliveryMethodId) = @DeliveryMethodId |
|||
|
|||
IF ISNULL(@PayoutPartner, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Pyout partner not defined for selected Payout Country, contact Head Office.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SELECT @PAgent = AGENTID |
|||
FROM AGENTMASTER(NOLOCK) |
|||
WHERE PARENTID = @PayoutPartner |
|||
AND ISNULL(ISSETTLINGAGENT, 'N') = 'Y'; |
|||
|
|||
DECLARE @PSuperAgent INT, @PSuperAgentName VARCHAR(150), @PAgentName VARCHAR(150), @PBranch INT, @PBranchName VARCHAR(150) |
|||
SELECT @PSuperAgent = sSuperAgent |
|||
,@PSuperAgentName = sSuperAgentName |
|||
,@PAgent = sAgent |
|||
,@PAgentName = sAgentName |
|||
,@PBranch = sBranch |
|||
,@PBranchName = sBranchName |
|||
FROM dbo.FNAGetBranchFullDetails(@PAGENT) |
|||
|
|||
DECLARE @PCurrencyCode VARCHAR(10) |
|||
SELECT @PCurrencyCode = pCurrency |
|||
FROM dbo.exRateTreasury WITH (NOLOCK) |
|||
WHERE pCountry = @PCountryId |
|||
AND pAgent = @PAgent |
|||
|
|||
IF @PCurrencyCode IS NULL |
|||
SELECT @PCurrencyCode = pCurrency |
|||
FROM dbo.exRateTreasury WITH (NOLOCK) |
|||
WHERE pCountry = @PCountryId |
|||
AND pAgent IS NULL |
|||
|
|||
IF @PCurrencyCode IS NULL |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Currency not been defined yet for receiving country, contact Head Office.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
IF @PCurrencyCode <> @PayoutCurrencyCode |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid PayoutCurrencyCode, contact Head Office.', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
DECLARE @Place INT, @CurrDecimal INT |
|||
SELECT @Place = place |
|||
,@CurrDecimal = currDecimal |
|||
FROM currencyPayoutRound WITH (NOLOCK) |
|||
WHERE ISNULL(isDeleted, 'N') = 'N' |
|||
AND currency = @PCurrencyCode |
|||
AND ISNULL(tranType, @DeliveryMethodId) = @DeliveryMethodId |
|||
|
|||
SET @currDecimal = ISNULL(@currDecimal, 0) |
|||
|
|||
|
|||
DECLARE @ExRateCalculated FLOAT, @sCurrCostRate FLOAT, @sCurrHoMargin FLOAT, @sCurrAgentMargin FLOAT |
|||
, @pCurrCostRate FLOAT, @pCurrHoMargin FLOAT, @pCurrAgentMargin FLOAT, @agentCrossSettRate FLOAT |
|||
|
|||
SELECT @ExRateCalculated = customerRate |
|||
,@sCurrCostRate = sCurrCostRate |
|||
,@sCurrHoMargin = sCurrHoMargin |
|||
,@sCurrAgentMargin = sCurrAgentMargin |
|||
,@pCurrCostRate = pCurrCostRate |
|||
,@pCurrHoMargin = pCurrHoMargin |
|||
,@pCurrAgentMargin = pCurrAgentMargin |
|||
,@agentCrossSettRate = agentCrossSettRate |
|||
FROM dbo.FNAGetExRate(@ScountryId, @SAgentId, NULL, @SendingCurrencyCode, @pCountryId, @pAgent, @PayoutCurrencyCode, @DeliveryMethodId) |
|||
|
|||
IF ISNULL(@ExRateCalculated, 0) = 0 |
|||
BEGIN |
|||
SET @ErrorMsg = 'Exchange rate not defined yet for receiving currency (' + @PCurrencyCode + ')' |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = @ErrorMsg, @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF ISNULL(@ExRateCalculated, 0) <> ISNULL(@ExchangeRate, -1) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid exchange rate passed or exchange rate changed in the system, recalculate the amount details and try again!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
DECLARE @ServiceChargeCalculated MONEY, @TransferAmountCalculated MONEY, @PayoutAmountCalculated MONEY, @CollectionAmountCalculated MONEY |
|||
DECLARE @SSuperAgentName VARCHAR(150), @SAgentName VARCHAR(150), @SBranch INT, @SBranchName VARCHAR(150) |
|||
SELECT @SSuperAgentId = sSuperAgent |
|||
,@SSuperAgentName = sSuperAgentName |
|||
,@SAgentName = sAgentName |
|||
,@SBranch = sBranch |
|||
,@SBranchName = sBranchName |
|||
FROM dbo.FNAGetBranchFullDetails(@SAgentId) |
|||
|
|||
IF ISNULL(@CalcBy, '') = '' |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Calc by can not be empty!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF @CalcBy NOT IN ('C', 'P') |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Calc by can not be other than ''C'' or ''P''!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF @CalcBy = 'C' AND ISNULL(@CollectionAmount, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Collection amount can not be 0 or empty for Calc By ''C''!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF @CalcBy = 'P' AND ISNULL(@PayoutAmount, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Payout amount can not be 0 or empty for Calc By ''P''!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
IF @CalcBy = 'C' |
|||
BEGIN |
|||
SELECT @ServiceChargeCalculated = amount |
|||
FROM [dbo].FNAGetServiceCharge(@ScountryId, @SSuperAgentId, @SAgentId, NULL, @PCountryId, @PSuperAgent, @PAgent, @PBranch, @DeliveryMethodId, @CollectionAmount, @SendingCurrencyCode) |
|||
|
|||
IF ISNULL(@ServiceChargeCalculated, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Service charge not defined yet for receiving country', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SET @TransferAmountCalculated = @CollectionAmount - @ServiceChargeCalculated |
|||
SET @PayoutAmountCalculated = @TransferAmountCalculated * @ExRateCalculated |
|||
SET @PayoutAmountCalculated = FLOOR(@PayoutAmountCalculated) |
|||
END |
|||
ELSE |
|||
BEGIN |
|||
SET @TransferAmountCalculated = CEILING(@PayoutAmount / (@ExRateCalculated)) |
|||
|
|||
SELECT @ServiceChargeCalculated = amount |
|||
FROM [dbo].FNAGetServiceCharge(@ScountryId, @SSuperAgentId, @SAgentId, NULL, @PCountryId, @PSuperAgent, @PAgent, @PBranch, @DeliveryMethodId, @CollectionAmount, @SendingCurrencyCode) |
|||
|
|||
IF ISNULL(@ServiceChargeCalculated, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Service charge not defined yet for receiving country', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SET @CollectionAmountCalculated = @TransferAmountCalculated + @ServiceChargeCalculated |
|||
SET @CollectionAmountCalculated = CEILING(@CollectionAmountCalculated) |
|||
END |
|||
|
|||
IF @CollectionAmountCalculated <= 0 OR @PayoutAmountCalculated <= 0 OR @TransferAmountCalculated <= 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid payout/transfer amount/collect amount found!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
IF @CalcBy = 'C' |
|||
BEGIN |
|||
IF ISNULL(@PayoutAmount, 0) <> ISNULL(@PayoutAmountCalculated, -1) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid Payout Amount passed/Amount details changed, recalculate the amount details and try again!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF ISNULL(@TransferAmount, 0) <> ISNULL(@TransferAmountCalculated, -1) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid Payout Amount passed/Amount details changed, recalculate the amount details and try again!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
END |
|||
ELSE |
|||
BEGIN |
|||
IF ISNULL(@CollectionAmount, 0) <> ISNULL(@CollectionAmountCalculated, -1) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid Collection Amount passed/Amount details changed, recalculate the amount details and try again!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF ISNULL(@TransferAmount, 0) <> ISNULL(@TransferAmountCalculated, -1) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid Payout Amount passed/Amount details changed, recalculate the amount details and try again!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
END |
|||
|
|||
DECLARE @ErrorCode VARCHAR(10) |
|||
EXEC PROC_CHECKCOUNTRYLIMIT @flag = 's-limit' |
|||
,@cAmt = @CollectionAmount |
|||
,@pAmt = @PayoutAmount |
|||
,@sCountryId = @sCountryId |
|||
,@collMode = NULL |
|||
,@deliveryMethod = @DeliveryMethodId |
|||
,@sendingCustType = NULL |
|||
,@pCountryId = @PCountryId |
|||
,@pCurr = @PayoutCurrencyCode |
|||
,@collCurr = @SendingCurrencyCode |
|||
,@pAgent = @PAgent |
|||
,@sAgent = @SAgentId |
|||
,@sBranch = NULL |
|||
,@msg = @ErrorMsg OUT |
|||
,@errorCode = @ErrorCode OUT |
|||
|
|||
IF @ErrorCode <> '0' |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = @ErrorMsg, @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
EXEC PROC_CHECKCOUNTRYLIMIT @flag = 'r-limit' |
|||
,@cAmt = @CollectionAmount |
|||
,@pAmt = @PayoutAmount |
|||
,@sCountryId = @sCountryId |
|||
,@collMode = NULL |
|||
,@deliveryMethod = @DeliveryMethodId |
|||
,@sendingCustType = NULL |
|||
,@pCountryId = @PCountryId |
|||
,@pCurr = @PayoutCurrencyCode |
|||
,@collCurr = @SendingCurrencyCode |
|||
,@pAgent = @PAgent |
|||
,@sAgent = @SAgentId |
|||
,@sBranch = NULL |
|||
,@msg = @ErrorMsg OUT |
|||
,@errorCode = @ErrorCode OUT |
|||
|
|||
IF @ErrorCode <> '0' |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = @ErrorMsg, @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
DECLARE @PBankId INT, @PBankName VARCHAR(100), @PBankBranchId INT, @PBankBranchName VARCHAR(100) |
|||
IF @PayoutTypeCode = 'BD' |
|||
BEGIN |
|||
IF @PayoutBankCode IS NULL |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Payout Bank can not be null for transaction type Bank Deposit!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
IF @ReceiverAccountNo IS NULL |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Receiver Account Number can not be null for transaction type Bank Deposit!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SELECT @PBankId = BANK_ID, @PBankName = BANK_NAME |
|||
FROM API_BANK_LIST (NOLOCK) |
|||
WHERE JME_BANK_CODE = @PayoutBankCode |
|||
AND API_PARTNER_ID = @PayoutPartner |
|||
|
|||
IF ISNULL(@PBankId, 0) = 0 |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Invalid bank details!!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
|
|||
SELECT @PBankBranchId = BRANCH_ID, @PBankBranchName = BRANCH_NAME |
|||
FROM API_BANK_BRANCH_LIST (NOLOCK) |
|||
WHERE BRANCH_ID = @PayoutBankBranchCode |
|||
END |
|||
|
|||
|
|||
--START OFAC Checking |
|||
DECLARE @ReceiverFullName VARCHAR(200) |
|||
, @SenderFullName VARCHAR(200) |
|||
, @OfacReason VARCHAR(MAX) |
|||
, @OfacReasonReceiver VARCHAR(MAX) |
|||
, @OfacReasonFull VARCHAR(MAX) |
|||
, @OfacErrorMessage VARCHAR(200) = '' |
|||
|
|||
SET @ReceiverFullName = @ReceiverFirstName + ISNULL(' ' + @ReceiverMiddleName, '') + @ReceiverLastName |
|||
SET @SenderFullName = @SenderFirstName + ISNULL(' ' + @SenderMiddleName, '') + @SenderLastName |
|||
|
|||
IF ISNULL(@CheckOfacFlag, 'N') = 'Y' |
|||
BEGIN |
|||
EXEC proc_ofacTracker @flag = 't' |
|||
,@name = @SenderFullName |
|||
,@Result = @OfacReason OUTPUT |
|||
|
|||
SET @OfacReasonFull = @OfacReason |
|||
IF @SenderFullName = @ReceiverFullName |
|||
BEGIN |
|||
SET @OfacReasonReceiver = @OfacReason |
|||
END |
|||
ELSE |
|||
BEGIN |
|||
EXEC proc_ofacTracker @flag = 't' |
|||
,@name = @ReceiverFullName |
|||
,@Result = @OfacReasonReceiver OUTPUT |
|||
|
|||
SET @OfacReasonFull = @OfacReasonFull + ISNULL(',' + @OfacReasonReceiver, '') |
|||
END |
|||
|
|||
IF ISNULL(@OfacReason, '') <> '' |
|||
BEGIN |
|||
SET @OfacErrorMessage = 'OFAC matched by Sender Name' |
|||
END |
|||
IF ISNULL(@OfacReasonReceiver, '') <> '' |
|||
BEGIN |
|||
SET @OfacErrorMessage = 'OFAC matched by Receiver Name' |
|||
END |
|||
|
|||
IF ISNULL(@OfacReason, '') <> '' AND ISNULL(@OfacReasonReceiver, '') <> '' |
|||
BEGIN |
|||
SET @OfacErrorMessage = 'OFAC matched by both Sender Name and Receiver Name' |
|||
END |
|||
END |
|||
|
|||
DECLARE @SendingAgentCommission MONEY, @PayoutAgentCommission MONEY |
|||
DECLARE @PAgentCommCurrency VARCHAR(5), @sAgentCommCurrency VARCHAR(5) |
|||
SELECT @pAgentCommCurrency = DBO.FNAGetPayCommCurrency(@SSuperAgentId, @SAgentId, NULL, @ScountryId, @PSuperAgent, @PBranch, @PCountryId) |
|||
|
|||
SELECT @PayoutAgentCommission = amount |
|||
FROM dbo.FNAGetPayComm(@SAgentId, @ScountryId, NULL, NULL, @PCountryId, NULL, @PAgent, @PAgentCommCurrency, @DeliveryMethodId, @CollectionAmount, @PayoutAmount, @ServiceCharge, @TransferAmount, NULL) |
|||
|
|||
DECLARE @SSettlementRate FLOAT, @PSettlementRate FLOAT |
|||
SET @SSettlementRate = @SCurrCostRate + @SCurrHoMargin |
|||
SET @PSettlementRate = @PCurrCostRate - @PCurrHoMargin |
|||
|
|||
SELECT @SendingAgentCommission = amount, @sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm( |
|||
@ScountryId, @SSuperAgentId, @SAgentId, NULL, |
|||
@pCountryId, @pSuperAgent, @pAgent, NULL, |
|||
@SendingCurrencyCode, @deliveryMethodId, @CollectionAmount, @PayoutAmount, @ServiceCharge, NULL, NULL, |
|||
@SSettlementRate, @PSettlementRate) |
|||
|
|||
DECLARE @ControlNo VARCHAR(20) = '779' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9) |
|||
|
|||
IF EXISTS ( |
|||
SELECT 'X' |
|||
FROM controlNoList WITH (NOLOCK) |
|||
WHERE controlNo = @ControlNo |
|||
) |
|||
BEGIN |
|||
SET @ControlNo = '779' + LEFT(CAST(ABS(CHECKSUM(NEWID())) AS VARCHAR(10)) + '0000000000', 9) |
|||
|
|||
IF EXISTS ( |
|||
SELECT 'X' |
|||
FROM controlNoList WITH (NOLOCK) |
|||
WHERE controlNo = @ControlNo |
|||
) |
|||
BEGIN |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = 'Technical error occurred. Please try again!', @Id = NULL; |
|||
RETURN; |
|||
END |
|||
END |
|||
|
|||
DECLARE @ControlNoEncrypted VARCHAR(20) = dbo.FNAEncryptString(@ControlNo) |
|||
DECLARE @RelationshipName VARCHAR(150), @RemittancePurposeName VARCHAR(150), @SourceOfFundName VARCHAR(150) |
|||
|
|||
SELECT @RelationshipName = detailTitle |
|||
FROM staticDataValue (NOLOCK) |
|||
WHERE valueId = @Relationship |
|||
|
|||
SELECT @RemittancePurposeName = detailTitle |
|||
FROM staticDataValue (NOLOCK) |
|||
WHERE valueId = @RemittancePurpose |
|||
|
|||
SELECT @SourceOfFundName = detailTitle |
|||
FROM staticDataValue (NOLOCK) |
|||
WHERE valueId = @SourceOfFund |
|||
|
|||
INSERT INTO remitTranTemp (controlNo, sCurrCostRate, sCurrHoMargin, sCurrAgentMargin, pCurrCostRate, pCurrHoMargin, pCurrAgentMargin, agentCrossSettRate |
|||
, customerRate, serviceCharge, sAgentComm, sAgentCommCurrency, pAgentComm, pAgentCommCurrency, sSuperAgent, sSuperAgentName, sAgent |
|||
, sAgentName, sBranch, sBranchName, sCountry, pSuperAgent, pSuperAgentName, pAgent, pAgentName, pBranch, pBranchName |
|||
, pCountry, paymentMethod, pBank, pBankName, pBankBranch, pBankBranchName, accountNo, collCurr, tAmt, cAmt |
|||
, pAmt, payoutCurr, relWithSender, purposeOfRemit, sourceOfFund, tranStatus, payStatus, createdDate, createdDateLocal, createdBy |
|||
, tranType, senderName, receiverName, controlNo2, sRouteId) |
|||
|
|||
SELECT @controlNoEncrypted, @sCurrCostRate, @sCurrHoMargin, @sCurrAgentMargin, @pCurrCostRate, @pCurrHoMargin, @pCurrAgentMargin, @agentCrossSettRate |
|||
, @ExRateCalculated, @serviceCharge, @SendingAgentCommission, @sAgentCommCurrency, @PayoutAgentCommission, @PAgentCommCurrency ,@SSuperAgentId, @SSuperAgentName, @SAgentId |
|||
, @SAgentName, @SBranch, @SBranchName, @SCountryName, @PSuperAgent, @PSuperAgentName, @PAgent, @PAgentName, @PBranch, @PBranchName |
|||
, @PCountryName, @DeliveryMethodName, @PBankId, @PBankName, @PBankBranchId, @PBankBranchName, @ReceiverAccountNo, @SendingCurrencyCode, @TransferAmount, @CollectionAmount |
|||
, @PayoutAmount, @PayoutCurrencyCode, @RelationshipName, @RemittancePurposeName, @SourceOfFundName, 'Hold', 'Unpaid', GETDATE(), GETDATE(), @UserName |
|||
, 'I', @SenderFullName, @ReceiverFullName, dbo.FNAEncryptString(@PartnerTransactionId), 'IN' |
|||
|
|||
DECLARE @Id BIGINT = @@IDENTITY |
|||
|
|||
INSERT INTO controlNoList ( |
|||
controlNo |
|||
, createdby |
|||
) |
|||
SELECT @ControlNo |
|||
, @UserName |
|||
|
|||
DECLARE @SenderNativeCountryName VARCHAR(80), @SenderIdTypeName VARCHAR(150), @OccupationName VARCHAR(150) |
|||
|
|||
SELECT @SenderNativeCountryName = CountryName |
|||
FROM COUNTRYMASTER (NOLOCK) |
|||
WHERE countryCode = @SenderNativeCountryCode |
|||
|
|||
SELECT @SenderIdTypeName = detailTitle |
|||
FROM staticDataValue (NOLOCK) |
|||
WHERE valueId = @SenderIdType |
|||
|
|||
SELECT @OccupationName = detailTitle |
|||
FROM staticDataValue (NOLOCK) |
|||
WHERE valueId = @Occupation |
|||
|
|||
INSERT INTO tranSendersTemp (tranId, customerId, membershipId, firstName, middleName, lastName1, fullName, country, [address], city, email, mobile |
|||
, nativeCountry, dob, idType, idNumber, gender, issuedDate, validDate, occupation, ipAddress) |
|||
SELECT @Id, 0, NULL, @SenderFirstName, @SenderMiddleName, @SenderLastName, @SenderFullName, @SCountryName, @SenderAddress, @SenderCity, @SenderEmail, @SenderMobile |
|||
, @SenderNativeCountryName, @SenderDOB, @SenderIdTypeName, @SenderIdNo, @SenderGender, @SenderIdIssuedDate, @SenderIdValidDate, @OccupationName, @IpAddress |
|||
|
|||
DECLARE @ReceiverIdTypeName VARCHAR(150) |
|||
|
|||
SELECT @ReceiverIdTypeName = detailTitle |
|||
FROM staticDataValue (NOLOCK) |
|||
WHERE valueId = @ReceiverIdType |
|||
|
|||
INSERT INTO tranReceiversTemp (tranId, customerId, membershipId, firstName, middleName, lastName1, fullName, country, [address], city, email, mobile |
|||
, idType, idNumber, issuedDate, validDate, accountNo) |
|||
SELECT @id, 0, '', @ReceiverFirstName, @ReceiverMiddleName, @ReceiverLastName, @ReceiverFullName, @PCountryName, @ReceiverAddress, @ReceiverCity, @ReceiverEmail, @ReceiverMobile |
|||
, @ReceiverIdType, @ReceiverIdNo, @ReceiverIdIssuedDate, @ReceiverIdValidDate, @ReceiverAccountNo |
|||
|
|||
IF ISNULL(@CheckOfacFlag, 'N') = 'Y' |
|||
BEGIN |
|||
IF (ISNULL(@OfacReasonFull, '') <> '') |
|||
BEGIN |
|||
CREATE TABLE #temp (sno INT, rmrks NVARCHAR(MAX)) |
|||
|
|||
INSERT INTO #temp (sno, rmrks) |
|||
EXEC proc_sendPageLoadData @flag = 'ofac' |
|||
,@user = @UserName |
|||
,@blackListIds = @OfacReasonFull |
|||
|
|||
DECLARE @OfacResultJson NVARCHAR(MAX) |
|||
|
|||
SET @OfacResultJson = (SELECT * |
|||
FROM #temp |
|||
FOR JSON AUTO) |
|||
|
|||
INSERT remitTranOfac ( |
|||
TranId |
|||
,blackListId |
|||
,reason |
|||
,flag |
|||
,TRACK_BY |
|||
,ofacDetail |
|||
) |
|||
SELECT @id |
|||
,@OfacReasonFull |
|||
,@OfacErrorMessage |
|||
,dbo.FNAGetOFAC_Flag(@OfacReasonFull) |
|||
,'OFAC' |
|||
,@OfacResultJson |
|||
|
|||
UPDATE remitTranTemp |
|||
SET tranStatus = 'OFAC Hold' |
|||
WHERE id = @Id |
|||
END |
|||
END |
|||
|
|||
SELECT ErrorCode = 100 |
|||
, ErrorMessage = CASE WHEN tranStatus = 'OFAC Hold' THEN 'Transaction is successful but is in OFAC hold status and will be manually verified!' ELSE 'Transaction is successful!' END |
|||
, IMEControlNo = @ControlNo |
|||
, PartnerTransactionId = @PartnerTransactionId |
|||
, TranStatus = tranStatus |
|||
, ExRate = customerRate |
|||
--, SendingCommission = sAgentComm |
|||
--, SendingCommissionCurrency = sAgentCommCurrency |
|||
, CollectionAmount = cAmt |
|||
, TransferAmount = tAmt |
|||
, PayoutAmount = pAmt |
|||
FROM remitTranTemp (NOLOCK) |
|||
WHERE id = @Id; |
|||
END |
|||
END |
|||
END TRY |
|||
BEGIN CATCH |
|||
IF @@TRANCOUNT>0 |
|||
ROLLBACK TRANSACTION |
|||
|
|||
SET @ErrorMsg = 'Exception executing SP: ' + ERROR_MESSAGE() |
|||
EXEC SW_PROC_ERROR_HANDLER @ErrorCode = 101, @ErrorMessage = @ErrorMsg, @Id = NULL; |
|||
END CATCH |
@ -0,0 +1,19 @@ |
|||
|
|||
|
|||
|
|||
EXEC PROC_REMIT_INBOUND_TRANSACTION_VALIDATE @Flag = 'VALIDATE', @UserName= 'ajey', @AgentId = '394390', @SendingCountryCode = 'JP', @PayoutCountryCode = 'NP', @PayoutTypeCode = 'CP' |
|||
, @PayoutBankCode = null, @PayoutBankBranchCode = null, @PayoutCurrencyCode = 'NPR', @SendingCurrencyCode = 'JPY', @CollectionAmount = '500000', @TransferAmount = '498500.00' |
|||
, @PayoutAmount = '438580.00', @ServiceCharge = '1500', @ExchangeRate = '00.8798', @RemittancePurpose = '1290', @SourceOfFund = '1120', @Relationship = '1239', @Occupation = '19182' |
|||
, @PartnerTransactionId = '1231231243423432', @CalcBy = 'C', @SenderFirstName = 'ARJUN', @SenderMiddleName = 'SINGH', @SenderLastName = 'DHAMI', @SenderIdType = '120', @SenderIdNo = '93281432' |
|||
, @SenderIdIssued = '2022-01-01', @SenderIdValid = '2030-01-01', @SenderMobile = '981281928', @SenderNativeCountryCode = 'NP', @SenderCity = 'TOKYO', @SenderAddress = 'TOKYO-32, JAPAN' |
|||
, @SenderEmail = 'ARJUNDHAMI554@GMAIL.COM', @SenderGender = 'M', @ReceiverFirstName = 'ARJUN', @ReceiverMiddleName = 'SINGH', @ReceiverLastName = 'DHAMI', @ReceiverIdType = '102' |
|||
, @ReceiverIdNo = '19281982', @ReceiverIdIssued = '2022-01-01', @ReceiverIdValid = '2030-01-01', @ReceiverMobile = '9819281928', @ReceiverCity = 'KATHMANDU', @ReceiverAddress = 'KOTESHWOR-32, KATHMANDU, NEPAL' |
|||
, @ReceiverEmail = 'ARJUNDHAMI554@GMAIL.COM', @ReceiverAccountNo = '02138921839' |
|||
|
|||
|
|||
SELECT SendingAgentCommission = amount, sAgentCommCurrency = commissionCurrency FROM dbo.FNAGetSendComm( |
|||
113, 393877, 394390, NULL, |
|||
151, 394397, 394398, NULL, |
|||
'JPY', 1, 500000.00, 438580.00, 1500.00, NULL, NULL, |
|||
1, 0.8798) |
|||
|
@ -1 +1 @@ |
|||
cf3e26a634283ce0d503764c2b4dbf6bdd620db9b5280d170e095cba1305aa90 |
|||
831577a45a58eaa1b1745ff404e91ac443fa015732883dbcf834659fc30e31e8 |
@ -1 +1 @@ |
|||
5da2ce40eea0aece55eeb2a8c9cde2dbb4d9258d9da8ddf86e762ab20c41a436 |
|||
87e8c18b610b688255ecf959d4b419cefd213e67c4145b5da51f481f68973ab4 |
@ -1 +1 @@ |
|||
154d3801c85428291f40ca89d0c83246e5771f3af66b329ecd85126981f3b845 |
|||
a974456348f41c809c7f39807366095000b9313dc7ea111822f2814ce06bccaa |
@ -1 +1 @@ |
|||
7f53cb3f235e695247d20375d98d020891a2279a5f8ab3710b0cc54464d4ebbf |
|||
81553e38b8c0af341dcf95f42445e229d2d79ca4a76a47006a537b944a7750f5 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue