EPA validation
// ============================================================================
// 1. Validation for Action Code: MAV_DIR_BB_ACTION_1006
// Negative EPA not allowed
// ============================================================================
if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1006') {
println("[EPA Trigger] *** START Validation Section 1: Action 1006 ***")
if (ExpectedPaymentAmount_c != null && ExpectedPaymentAmount_c < 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Negative: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : NULL / Negative Value Not Allowed!");
}
println("[EPA Trigger] *** END Validation Section 1 ***")
}
// ============================================================================
// 2. Validation for Action Code: MAV_DIR_BB_ACTION_1008
// REC Payout Adjustment
// Negative EPA not allowed (when not null)
// ============================================================================
if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1008') {
println("[EPA Trigger] *** START Validation Section 2: REC Payout Adjustment ***")
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
if (ExpectedPaymentAmount_c != null && CED_c != null) {
if (ExpectedPaymentAmount_c < 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Negative: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : NULL / Negative Value Not Allowed!");
}
println("[EPA Trigger] Validation Passed. ExpectedPaymentAmount_c is valid.")
}
}
println("[EPA Trigger] *** END Validation Section 2 ***")
}
// ============================================================================
// 3. Validation for Action Code: MAV_DIR_BB_ACTION_1009
// NNREC Payout Adjustment
// Negative EPA not allowed (when not null)
// ============================================================================
if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1009') {
println("[EPA Trigger] *** START Validation Section 3: NNREC Payout Adjustment ***")
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
if (ExpectedPaymentAmount_c != null && CED_c != null) {
if (ExpectedPaymentAmount_c < 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Negative: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : NULL / Negative Value Not Allowed!");
}
println("[EPA Trigger] Validation Passed. ExpectedPaymentAmount_c is valid.")
}
}
println("[EPA Trigger] *** END Validation Section 3 ***")
}
// ============================================================================
// 4. Validation for Action Code: MAV_DIR_BB_ACTION_1010
// MPA to Write Off
// Negative EPA not allowed
// ============================================================================
if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1010') {
println("[EPA Trigger] *** START Validation Section 4: MPA to Write Off ***")
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
if (ExpectedPaymentAmount_c != null && ExpectedPaymentAmount_c < 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Negative: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : NULL / Negative Value Not Allowed!");
}
}
println("[EPA Trigger] *** END Validation Section 4 ***")
}
// ============================================================================
// 5. Validation for Action Code: MAV_DIR_BB_ACTION_1011
// MPA to Payroll Collections (Sales / Non‑Sales)
// ============================================================================
if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1011' && EmploymentCountry_c != 'RO') {
println("[EPA Trigger] *** START Validation Section 5: MPA to Payroll Collections ***")
// 5.1 SalesRP_c == 'Y' : EPA must be <= 0
if ((IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') && SalesRP_c == 'Y') {
println("[EPA Trigger] Sub-Section 5.1 (SalesRP_c=Y) validation check.")
if (ExpectedPaymentAmount_c != null && CED_c != null) {
if (ExpectedPaymentAmount_c > 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Positive: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : Positive Value Not Allowed!");
}
println("[EPA Trigger] Validation Passed. ExpectedPaymentAmount_c is valid (<= 0).")
}
}
// 5.2 SalesRP_c == 'N' : consent required + EPA must be <= 0
if ((IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') && SalesRP_c == 'N') {
println("[EPA Trigger] Sub-Section 5.2 (SalesRP_c=N) validation check.")
// VALIDATION 1: Employee Consent
if (EmployeeConsent_c == 'N') {
println("[EPA Trigger] ** VALIDATION FAILED ** Employee Consent is 'N'")
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for non salesrep!");
}
// VALIDATION 2: Expected Payment Amount
if (ExpectedPaymentAmount_c != null && CED_c != null) {
if (ExpectedPaymentAmount_c >= 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Positive: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : 0 and Positive Value Not Allowed!");
}
println("[EPA Trigger] Validation Passed. ExpectedPaymentAmount_c is valid (<= 0).")
}
}
println("[EPA Trigger] *** END Validation Section 5 ***")
}
// ============================================================================
// 6. Validation for Action Code: MAV_DIR_BB_ACTION_1012
// SPIF vs Comm Deduction (SalesRP = Y, IncentiveType = BONUS)
// Includes:
// - Employee Consent check
// - Null checks for paysheet / EPA
// - EPA must be <= 0
// - Limit validation based on lookup
// ============================================================================
if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1012' && SalesRP_c == 'Y') {
println("[EPA Trigger] *** START Validation Section 6: SPIF vs Comm Deduction ***")
def basePaysheetAmount = SCDEPAValue_c ?: SCDCEDValue_c
def bonusCED_c = CED_c
def maxadjustmentallowed = 0
if (IncentiveType_c == 'BONUS') {
println("[EPA Trigger] IncentiveType check passed (BONUS).")
// VALIDATION 1: Employee Consent
if (EmployeeConsent_c == 'N') {
println("[EPA Trigger] ** VALIDATION FAILED ** Employee Consent is 'N'")
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for salesrep!");
}
// VALIDATION 2: Null check for paysheet & EPA
if (basePaysheetAmount == null || bonusCED_c == null || basePaysheetAmount == 0 ) {
println("[EPA Trigger] ** VALIDATION FAILED ** Paysheet calculation input (SCDEPAValue_c or SCDCEDValue_c) or ExpectedPaymentAmount_c is null.")
throw new oracle.jbo.ValidationException("EPA : Commision EPA/CED is NULL. MPA cannot be compared!!");
}
// VALIDATION 3: EPA must be <= 0
if (ExpectedPaymentAmount_c >= 0) {
println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Positive: ${ExpectedPaymentAmount_c}")
throw new oracle.jbo.ValidationException("EPA : Positive Or 0 Value Not Allowed!");
}
println("[EPA Trigger] Validation Passed. ExpectedPaymentAmount_c is valid (<= 0).")
// LOOKUP VALIDATION
String lookupMeaning_c = null
String lookupTag_c = null
def lookupType = 'MTQ_ICM_BB_COUNTRY_LKP'
def lookupCode = EmploymentCountry_c
println("[EPA Trigger] Lookup Attempt: VO='CommonLookup', Type=${lookupType}, Code=${lookupCode}")
def voLookUp = newView("CommonLookup");
def str1SearchExpression = "LookupType = '${lookupType}' AND LookupCode = '${lookupCode}'"
println("[EPA Trigger] Applying View Criteria: ${str1SearchExpression}")
voLookUp.appendViewCriteria(str1SearchExpression)
voLookUp.executeQuery()
if (voLookUp.getEstimatedRowCount() > 0) {
while (voLookUp.hasNext()) {
def rowLookup = voLookUp.next();
lookupMeaning_c = nvl(rowLookup?.Description, "")
lookupTag_c = nvl(rowLookup?.Tag, "")
break
}
println("[EPA Trigger] Lookup Successful. Meaning: ${lookupMeaning_c}, Tag: ${lookupTag_c}")
} else {
println("[EPA Trigger] Lookup Failed: No matching row found for Type=${lookupType}, Code=${lookupCode}")
}
voLookUp.reset()
// LIMIT AMOUNT VALIDATION
def tempMPAGenerated = null
if (ExpectedPaymentAmount_c != null) {
tempMPAGenerated = ((-1) * ExpectedPaymentAmount_c).setScale(2, BigDecimal.ROUND_HALF_UP)
}
def limitAmount = null
if (tempMPAGenerated != null &&
basePaysheetAmount != null &&
lookupTag_c != null &&
lookupTag_c.trim() != '') {
try {
def paysheetAmount = (SCDEPAValue_c ?: SCDCEDValue_c) as BigDecimal
def tagLimitFactor = new BigDecimal(lookupTag_c.trim())
limitAmount = (paysheetAmount * tagLimitFactor).setScale(2, BigDecimal.ROUND_HALF_UP)
if ( bonusCED_c.abs() > limitAmount.abs() )
{
maxadjustmentallowed = limitAmount.abs
}
if (bonusCED_c.abs() <= limitAmount.abs() )
{
maxadjustmentallowed = bonusCED_c.abs()
}
println("[EPA Trigger] Calculated Limit (2 Decimals): ${limitAmount}")
println("[EPA Trigger] Calculated MPAGenerated_c (Absolute): ${tempMPAGenerated.abs()}")
println("[EPA Trigger] Calculated Limit (Absolute): ${limitAmount.abs()}")
if (tempMPAGenerated.abs() > maxadjustmentallowed.abs()) {
def formattedLimit = maxadjustmentallowed.toString()
println("[EPA Trigger] ** VALIDATION FAILED ** MPA (${tempMPAGenerated.abs()}) exceeds limit (${maxadjustmentallowed.abs()})")
// automatically set EPA to max value allowed
ExpectedPaymentAmount_c = (-1)*maxadjustmentallowed.abs()
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 (NumberFormatException e) {
println("[EPA Trigger] ERROR: Failed to convert lookupTag_c ('${lookupTag_c}') to a number. Skipping limit validation.")
}
} else {
println("[EPA Trigger] WARNING: Limit validation skipped due to missing values (MPAGenerated_c, basePaysheetAmount, or lookupTag_c).")
}
}
println("[EPA Trigger] *** END Validation Section 6 ***")
}
Comments
Post a Comment