section final - 6
// ============================================================================
// 6. Validation for Action Code: MAV_DIR_BB_ACTION_1012
// SPIF vs Comm Deduction (Precedence: SCDEPA > SCDCED)
// ============================================================================
if (nvl(BBActionManual_c, '') == 'MAV_DIR_BB_ACTION_1012' && nvl(SalesRP_c, '') == 'Y') {
println("[EPA Trigger] *** START Validation Section 6 ***")
// Precedence Logic: Use SCDEPA if not null, otherwise fall back to SCDCED
def basePaysheetAmount = (SCDEPAValue_c != null) ? SCDEPAValue_c : SCDCEDValue_c
def bonusCED_val = CED_c
def maxadjustmentallowed = 0.0
if (nvl(IncentiveType_c, '') == 'BONUS') {
// 1. Employee Consent Check
if (nvl(EmployeeConsent_c, 'N') == 'N') {
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for salesrep!");
}
// 2. Null/Zero check for comparison fields
if (basePaysheetAmount == null || basePaysheetAmount == 0 || bonusCED_val == null) {
throw new oracle.jbo.ValidationException("EPA : Commission EPA/CED is NULL or 0. Comparison not possible!");
}
// 3. EPA must be negative (Deduction)
if (ExpectedPaymentAmount_c != null && ExpectedPaymentAmount_c >= 0) {
throw new oracle.jbo.ValidationException("EPA : Positive Or 0 Value Not Allowed!");
}
// 4. Fetch Country Factor from Lookup
String lookupTag_c = "1.0"
def voLookUp = newView("CommonLookup")
voLookUp.appendViewCriteria("LookupType = 'MTQ_ICM_BB_COUNTRY_LKP' AND LookupCode = '${EmploymentCountry_c}'")
voLookUp.executeQuery()
if (voLookUp.hasNext()) {
lookupTag_c = nvl(voLookUp.next()?.Tag, "1.0")
}
// 5. Calculation and Auto-Correction
if (ExpectedPaymentAmount_c != null) {
try {
def tagLimitFactor = new BigDecimal(lookupTag_c.trim())
def absBaseAmount = (basePaysheetAmount as BigDecimal).abs()
def limitAmount = (absBaseAmount * tagLimitFactor).setScale(2, BigDecimal.ROUND_HALF_UP)
def absBonusCED = (bonusCED_val as BigDecimal).abs()
// Determine max allowed magnitude
maxadjustmentallowed = (absBonusCED > limitAmount) ? limitAmount : absBonusCED
def currentInputAbs = (ExpectedPaymentAmount_c as BigDecimal).abs()
// If user input exceeds calculated threshold
if (currentInputAbs > maxadjustmentallowed) {
BigDecimal correctedEPA = maxadjustmentallowed * -1
// Update field value automatically
setAttribute('ExpectedPaymentAmount_c', correctedEPA)
def formattedLimit = maxadjustmentallowed.toString()
// Throw exception with requested format
throw new oracle.jbo.ValidationException("EPA: SCD action must not exceed the relevant monthly commission payout of " + formattedLimit + "(Commission EPA/CED adjusted to SCD threshold of " + tagLimitFactor + " )");
}
} catch (Exception e) {
println("[EPA Trigger] Section 6 Error: " + e.getMessage())
}
}
}
println("[EPA Trigger] *** END Validation Section 6 ***")
}
Comments
Post a Comment