43 lines
1.9 KiB
JavaScript
43 lines
1.9 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Monthly commission cap checks per referrer (beneficiary).
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.resolveEffectiveLevelCaps = resolveEffectiveLevelCaps;
|
|
exports.wouldExceedMonthlyCommissionCap = wouldExceedMonthlyCommissionCap;
|
|
exports.wouldExceedMonthlyCapAtSettlement = wouldExceedMonthlyCapAtSettlement;
|
|
/** Level caps of 0 inherit from global program settings. */
|
|
function resolveEffectiveLevelCaps(global, level) {
|
|
const levelAmount = level ? BigInt(level.monthlyMaxAmountRaw) : 0n;
|
|
const levelCount = level?.monthlyMaxCount ?? 0;
|
|
if (levelAmount > 0n || levelCount > 0) {
|
|
return {
|
|
maxAmountRaw: levelAmount > 0n ? levelAmount : global.maxAmountRaw,
|
|
maxCount: levelCount > 0 ? levelCount : global.maxCount,
|
|
source: 'level',
|
|
};
|
|
}
|
|
return { ...global, source: 'global' };
|
|
}
|
|
/** Returns whether adding a commission would exceed configured monthly caps (0 = unlimited). */
|
|
function wouldExceedMonthlyCommissionCap(input) {
|
|
if (input.maxCount > 0 && input.currentReservedCount + 1 > input.maxCount) {
|
|
return { exceeded: true, reason: 'count' };
|
|
}
|
|
if (input.maxAmountRaw > 0n &&
|
|
input.currentReservedAmount + input.newCommissionAmount > input.maxAmountRaw) {
|
|
return { exceeded: true, reason: 'amount' };
|
|
}
|
|
return { exceeded: false };
|
|
}
|
|
/** Validates reserved totals already include the payout being settled (no double-count). */
|
|
function wouldExceedMonthlyCapAtSettlement(input) {
|
|
if (input.maxCount > 0 && input.reservedCount > input.maxCount) {
|
|
return { exceeded: true, reason: 'count' };
|
|
}
|
|
if (input.maxAmountRaw > 0n && input.reservedAmount > input.maxAmountRaw) {
|
|
return { exceeded: true, reason: 'amount' };
|
|
}
|
|
return { exceeded: false };
|
|
}
|
|
//# sourceMappingURL=referralCapService.js.map
|