EPA validation 2
// ============================================================================
// 1. Validation for Action Code: MAV_DIR_BB_ACTION_1006
// ============================================================================
if (nvl(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 & 3. Validation for Action Codes: 1008 & 1009
// ============================================================================
if (nvl(BBActionManual_c, '') in ['MAV_DIR_BB_ACTION_1008', 'MAV_DIR_BB_ACTION_1009']) {
println("[EPA Trigger] *** START Validation Section 2/3: Payout Adjustment ***")
if (nvl(IncentiveType_c, '') in ['COMMISSION', '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] *** END Validation Section 2/3 ***")
}
// ============================================================================
// 4. Validation for Action Code: MAV_DIR_BB_ACTION_1010
// ============================================================================
if (nvl(BBActionManual_c, '') == 'MAV_DIR_BB_ACTION_1010') {
if (nvl(IncentiveType_c, '') in ['COMMISSION', 'BONUS']) {
if (ExpectedPaymentAmount_c != null && ExpectedPaymentAmount_c < 0) {
throw new oracle.jbo.ValidationException("EPA : NULL / Negative Value Not Allowed!");
}
}
}
// ============================================================================
// 5. Validation for Action Code: MAV_DIR_BB_ACTION_1011
// ============================================================================
if (nvl(BBActionManual_c, '') == 'MAV_DIR_BB_ACTION_1011' && nvl(EmploymentCountry_c, '') != 'RO') {
println("[EPA Trigger] *** START Validation Section 5: MPA to Payroll Collections ***")
boolean isCheckableIncentive = nvl(IncentiveType_c, '') in ['COMMISSION', 'BONUS']
if (isCheckableIncentive && SalesRP_c == 'Y') {
if (ExpectedPaymentAmount_c != null && CED_c != null && ExpectedPaymentAmount_c > 0) {
throw new oracle.jbo.ValidationException("EPA : Positive Value Not Allowed!");
}
}
if (isCheckableIncentive && SalesRP_c == 'N') {
if (nvl(EmployeeConsent_c, 'N') == 'N') {
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for non salesrep!");
}
if (ExpectedPaymentAmount_c != null && CED_c != null && ExpectedPaymentAmount_c >= 0) {
throw new oracle.jbo.ValidationException("EPA : 0 and Positive Value Not Allowed!");
}
}
println("[EPA Trigger] *** END Validation Section 5 ***")
}
// ============================================================================
// 6. Validation for Action Code: MAV_DIR_BB_ACTION_1012
// ============================================================================
if (nvl(BBActionManual_c, '') == 'MAV_DIR_BB_ACTION_1012' && nvl(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.0
if (nvl(IncentiveType_c, '') == 'BONUS') {
// 1. Consent Check
if (nvl(EmployeeConsent_c, 'N') == 'N') {
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for salesrep!");
}
// 2. Null check for paysheet & EPA
if (basePaysheetAmount == null || bonusCED_c == null || basePaysheetAmount == 0) {
throw new oracle.jbo.ValidationException("EPA : Commision EPA/CED is NULL. MPA cannot be compared!!");
}
// 3. EPA must be <= 0
if (ExpectedPaymentAmount_c != null && ExpectedPaymentAmount_c >= 0) {
throw new oracle.jbo.ValidationException("EPA : Positive Or 0 Value Not Allowed!");
}
// 4. Lookup Logic
def lookupType = 'MTQ_ICM_BB_COUNTRY_LKP'
def lookupCode = EmploymentCountry_c
def lookupTag_c = null
def voLookUp = newView("CommonLookup")
voLookUp.appendViewCriteria("LookupType = '${lookupType}' AND LookupCode = '${lookupCode}'")
voLookUp.executeQuery()
if (voLookUp.hasNext()) {
def rowLookup = voLookUp.next()
lookupTag_c = nvl(rowLookup?.Tag, "")
}
// 5. Limit Validation
if (ExpectedPaymentAmount_c != null && lookupTag_c != null && lookupTag_c.trim() != '') {
try {
def tagLimitFactor = new BigDecimal(lookupTag_c.trim())
def paysheetAmount = (basePaysheetAmount as BigDecimal).abs()
def limitAmount = (paysheetAmount * tagLimitFactor).setScale(2, BigDecimal.ROUND_HALF_UP)
def absBonusCED = (bonusCED_c as BigDecimal).abs()
def absLimit = limitAmount.abs()
// Logic: Max adjustment is the lower of the absolute CED or the absolute Limit
maxadjustmentallowed = absBonusCED > absLimit ? absLimit : absBonusCED
def tempMPAGeneratedAbs = (ExpectedPaymentAmount_c as BigDecimal).abs()
if (tempMPAGeneratedAbs > maxadjustmentallowed) {
// Automatically set EPA to max negative value allowed
setAttribute('ExpectedPaymentAmount_c', (maxadjustmentallowed * -1))
throw new oracle.jbo.ValidationException("EPA: SCD action must not exceed the relevant monthly commission payout of " + maxadjustmentallowed + " (Commission EPA/CED adjusted to SCD threshold of " + tagLimitFactor + ")");
}
} catch (Exception e) {
println("[EPA Trigger] ERROR in Calculation: " + e.getMessage())
}
}
}
println("[EPA Trigger] *** END Validation Section 6 ***")
}
Comments
Post a Comment