only 1012

// ============================================================================ // 6. Validation for Action Code: MAV_DIR_BB_ACTION_1012 // SPIF vs Comm Deduction (SalesRP = Y, IncentiveType = BONUS) // ============================================================================ if (nvl(BBActionManual_c, '') == 'MAV_DIR_BB_ACTION_1012' && nvl(SalesRP_c, '') == 'Y') { println("[EPA Trigger] *** START Validation Section 6 ***") // Logic: SCDEPA takes precedence over SCDCED if not null def basePaysheetAmount = SCDEPAValue_c != null ? SCDEPAValue_c : SCDCEDValue_c def bonusCED_c = CED_c // 430 in your example 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!"); } // 2. Null/Zero check for base paysheet values if (basePaysheetAmount == null || basePaysheetAmount == 0 || bonusCED_c == null) { throw new oracle.jbo.ValidationException("EPA : Commission EPA/CED is NULL or Zero. 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. Lookup for Country Factor (e.g., 1.0 for 100%) String lookupTag_c = null 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") // Default to 1.0 if tag missing } else { lookupTag_c = "1.0" println("[EPA Trigger] Lookup failed, defaulting factor to 1.0") } // 5. Limit Calculation & Enforcement 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_c as BigDecimal).abs() // Determine the absolute max: The smaller of (Base * Factor) OR the Bonus CED itself maxadjustmentallowed = absBonusCED > limitAmount ? limitAmount : absBonusCED def currentInputAbs = (ExpectedPaymentAmount_c as BigDecimal).abs() // If current EPA (e.g., -430) is "larger" than max allowed (e.g., 200) if (currentInputAbs > maxadjustmentallowed) { BigDecimal correctedEPA = maxadjustmentallowed * -1 println("[EPA Trigger] Correcting EPA from ${ExpectedPaymentAmount_c} to ${correctedEPA}") // Update the field value automatically setAttribute('ExpectedPaymentAmount_c', correctedEPA) throw new oracle.jbo.ValidationException("EPA: SCD action exceeds the allowed limit of " + maxadjustmentallowed + " (Based on SCDEPA/SCDCED threshold). Value has been adjusted."); } } catch (Exception e) { println("[EPA Trigger] Error in limit calculation: " + e.getMessage()) } } } println("[EPA Trigger] *** END Validation Section 6 ***") }

Comments

Popular posts from this blog

dev7 from eror

EPA

Unified Currency Report- Krithika