EPA code to be fixed
// ============================================================================
// Section 1: Hold Beginning Balance (Full BB on Hold Until next month)
// Action Code: MAV_DIR_BB_ACTION_1007
// ============================================================================
if (BBAction_c == 'MAV_DIR_BB_ACTION_1007') {
println("[EPA Trigger] *** START Section 1: Hold Beginning Balance ***")
println("[EPA Trigger] Action Code: ${BBAction_c}")
println("[EPA Trigger] IncentiveType: ${IncentiveType_c}")
println("[EPA Trigger] CED_c: ${CED_c}")
println("[EPA Trigger] Current ExpectedPaymentAmount_c: ${ExpectedPaymentAmount_c}")
// Verify the Incentive Type condition (COMMISSION or BONUS, not SPIFF)
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
println("[EPA Trigger] IncentiveType check passed.")
// ** NULL-AWARE CALCULATION **
if (ExpectedPaymentAmount_c == null || CED_c == null) {
println("[EPA Trigger] WARNING: Calculation skipped. ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
}
println("[EPA Trigger] Section 1 completed successfully")
} else {
println("[EPA Trigger] IncentiveType not COMMISSION or BONUS - skipping Section 1 logic.")
}
println("[EPA Trigger] *** END Section 1 ***")
}
// ----------------------------------------------------------------------------
// ============================================================================
// Section 2: REC Payout Adjustment (Analyst needs to fill in Expected Payout)
// Action Code: MAV_DIR_BB_ACTION_1008
// ============================================================================
if (BBAction_c == 'MAV_DIR_BB_ACTION_1008') {
println("[EPA Trigger] *** START Section 2: REC Payout Adjustment ***")
println("[EPA Trigger] Action Code: ${BBAction_c}")
println("[EPA Trigger] IncentiveType: ${IncentiveType_c}")
println("[EPA Trigger] CED_c: ${CED_c}")
println("[EPA Trigger] Current ExpectedPaymentAmount_c: ${ExpectedPaymentAmount_c}")
// Verify the Incentive Type condition (COMMISSION or BONUS, not SPIFF)
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
println("[EPA Trigger] IncentiveType check passed.")
def calculationExecuted = false
// ** NULL-AWARE CHECK BEFORE VALIDATION/CALCULATION **
if (ExpectedPaymentAmount_c == null || CED_c == null) {
println("[EPA Trigger] WARNING: Calculation and Status setting skipped. ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// ** Validation remains in Section 2 (MAV_DIR_BB_ACTION_1008) **
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.")
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
// Set MPAStatus_c based on MPAGenerated_c
if (MPAGenerated_c <= 0) {
MPAStatus_c = 'Auto approved'
println("[EPA Trigger] Setting MPAStatus_c to: Auto approved (since MPAGenerated_c <= 0)")
} else { // MPAGenerated_c > 0
MPAStatus_c = 'Manual approved'
println("[EPA Trigger] Setting MPAStatus_c to: Manual approved (since MPAGenerated_c > 0)")
}
calculationExecuted = true
}
if (calculationExecuted) {
println("[EPA Trigger] Section 2 completed successfully")
}
} else {
println("[EPA Trigger] IncentiveType not COMMISSION or BONUS - skipping Section 2 logic.")
}
println("[EPA Trigger] *** END Section 2 ***")
}
// ----------------------------------------------------------------------------
// ============================================================================
// Section 3: NNREC Payout Adjustment (Analyst needs to fill in Expected Payout)
// Action Code: MAV_DIR_BB_ACTION_1009
// ============================================================================
if (BBAction_c == 'MAV_DIR_BB_ACTION_1009') {
println("[EPA Trigger] *** START Section 3: NNREC Payout Adjustment ***")
println("[EPA Trigger] Action Code: ${BBAction_c}")
println("[EPA Trigger] IncentiveType: ${IncentiveType_c}")
println("[EPA Trigger] CED_c: ${CED_c}")
println("[EPA Trigger] Current ExpectedPaymentAmount_c: ${ExpectedPaymentAmount_c}")
// Verify the Incentive Type condition (COMMISSION or BONUS, not SPIFF)
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
println("[EPA Trigger] IncentiveType check passed.")
def calculationExecuted = false
// ** NULL-AWARE CHECK BEFORE VALIDATION/CALCULATION **
if (ExpectedPaymentAmount_c == null || CED_c == null) {
println("[EPA Trigger] WARNING: Calculation skipped. ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// ** Validation remains in Section 3 (MAV_DIR_BB_ACTION_1009) **
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.")
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
calculationExecuted = true
}
if (calculationExecuted) {
println("[EPA Trigger] Section 3 completed successfully")
}
} else {
println("[EPA Trigger] IncentiveType not COMMISSION or BONUS - skipping Section 3 logic.")
}
println("[EPA Trigger] *** END Section 3 ***")
}
// ----------------------------------------------------------------------------
// ============================================================================
// Section 4: MPA to Write Off (Action Code: MAV_DIR_BB_ACTION_1010)
// Covers original Sections 5, 6, 7
// ============================================================================
if (BBAction_c == 'MAV_DIR_BB_ACTION_1010') {
println("[EPA Trigger] *** START Section 4: MPA to Write Off ***")
println("[EPA Trigger] Action Code: ${BBAction_c}")
println("[EPA Trigger] IncentiveType: ${IncentiveType_c}")
println("[EPA Trigger] CED_c: ${CED_c}")
println("[EPA Trigger] Current ExpectedPaymentAmount_c: ${ExpectedPaymentAmount_c}")
// Verify the Incentive Type condition (COMMISSION or BONUS)
if (IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') {
println("[EPA Trigger] IncentiveType check passed.")
// ** NULL-AWARE CALCULATION **
if (ExpectedPaymentAmount_c == null || CED_c == null) {
println("[EPA Trigger] WARNING: Calculation skipped. ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
}
println("[EPA Trigger] Section 4 completed successfully")
} else {
println("[EPA Trigger] IncentiveType not COMMISSION or BONUS - skipping Section 4 logic.")
}
println("[EPA Trigger] *** END Section 4 ***")
}
// ----------------------------------------------------------------------------
// ============================================================================
// Section 5: MPA to Payroll Collections (Action Code: MAV_DIR_BB_ACTION_1011)
// Covers original Sections 8 & 9
// ============================================================================
if (BBAction_c == 'MAV_DIR_BB_ACTION_1011' && EmploymentCountry_c != 'RO') {
println("[EPA Trigger] *** START Section 5: MPA to Payroll Collections ***")
println("[EPA Trigger] Action Code: ${BBAction_c}")
println("[EPA Trigger] IncentiveType: ${IncentiveType_c}")
println("[EPA Trigger] CED_c: ${CED_c}")
println("[EPA Trigger] Current ExpectedPaymentAmount_c: ${ExpectedPaymentAmount_c}")
// ------------------------------------------------------------------------
// Section 5.1 (Original Section 8): SalesRP_c == 'Y'
// ------------------------------------------------------------------------
if ((IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') && SalesRP_c == 'Y') {
println("[EPA Trigger] Sub-Section 5.1 (SalesRP_c=Y) check passed.")
def calculationExecuted = false
// ** NULL-AWARE CHECK BEFORE VALIDATION/CALCULATION **
if (ExpectedPaymentAmount_c == null || CED_c == null) {
println("[EPA Trigger] WARNING: Calculation skipped. ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// ** VALIDATION for Section 5.1 **
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).")
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
calculationExecuted = true
}
if (calculationExecuted) {
println("[EPA Trigger] Sub-Section 5.1 completed successfully")
}
} else {
println("[EPA Trigger] Sub-Section 5.1 conditions not met (Incentive or SalesRP_c).")
}
// ------------------------------------------------------------------------
// Section 5.2 (Original Section 9): SalesRP_c == 'N'
// ------------------------------------------------------------------------
if ((IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') && SalesRP_c == 'N') {
println("[EPA Trigger] Sub-Section 5.2 (SalesRP_c=N) check passed.")
// ** VALIDATION 1: Employee Consent check **
if (EmployeeConsent_c == 'N') {
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for non salesrep!");
}
def calculationExecuted = false
// ** NULL-AWARE CHECK BEFORE VALIDATION/CALCULATION **
if (ExpectedPaymentAmount_c == null || CED_c == null) {
println("[EPA Trigger] WARNING: Calculation skipped. ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// ** VALIDATION 2: Expected Payment Amount **
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).")
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
calculationExecuted = true
}
if (calculationExecuted) {
println("[EPA Trigger] Sub-Section 5.2 completed successfully")
}
} else {
println("[EPA Trigger] Sub-Section 5.2 conditions not met (Incentive or SalesRP_c).")
}
println("[EPA Trigger] *** END Section 5 (Original 8 & 9) ***")
}
// ----------------------------------------------------------------------------
// ============================================================================
// Section 6: SPIF vs Comm Deduction (Action Code: MAV_DIR_BB_ACTION_1012)
// Covers original Sections 10 & 11
// ============================================================================
if (BBAction_c == 'MAV_DIR_BB_ACTION_1012' && SalesRP_c == 'Y') {
println("[EPA Trigger] *** START Section 6: SPIF vs Comm Deduction ***")
println("[EPA Trigger] Action Code: ${BBAction_c}")
println("[EPA Trigger] IncentiveType: ${IncentiveType_c}")
println("[EPA Trigger] CED_c: ${CED_c}")
println("[EPA Trigger] Current ExpectedPaymentAmount_c: ${ExpectedPaymentAmount_c}")
// Verify the Incentive Type condition (BONUS only in original code)
if (IncentiveType_c == 'BONUS') {
println("[EPA Trigger] IncentiveType check passed (BONUS).")
// ** VALIDATION 1: Employee Consent check **
if (EmployeeConsent_c == 'N') {
throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for salesrep!");
}
def calculationExecuted = false
// ** NULL-AWARE CHECK BEFORE VALIDATION/CALCULATION **
if (TotalPaysheetAmountInLHC_c == null || ExpectedPaymentAmount_c == null) {
println("[EPA Trigger] WARNING: Calculation skipped. TotalPaysheetAmountInLHC_c (${TotalPaysheetAmountInLHC_c}) or ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) is null.")
MPAGenerated_c = null // Set to null if inputs are missing
} else {
// ** VALIDATION 2: Expected Payment Amount **
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).")
// Calculate MPAGenerated_c and CAP TO 4 DECIMAL PLACES
MPAGenerated_c = (TotalPaysheetAmountInLHC_c - ExpectedPaymentAmount_c).setScale(4, BigDecimal.ROUND_HALF_UP)
println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 4 Decimals)")
calculationExecuted = true
}
//-Lookup validation
String lookupMeaning_c = null // Initialize
String lookupTag_c = null // Initialize
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}")
// 3. Apply the criteria and execute the query
voLookUp.appendViewCriteria(str1SearchExpression)
voLookUp.executeQuery()
if (voLookUp.getEstimatedRowCount() > 0) {
while(voLookUp.hasNext()) {
def rowLookup = voLookUp.next();
// Retrieve attributes using nvl(value, default) for null-safe access
// Assuming 'Description' is the Meaning and 'Tag' is the Tag attribute
lookupMeaning_c = nvl(rowLookup?.Description, "")
lookupTag_c = nvl(rowLookup?.Tag, "")
// Break after finding the first match
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}")
}
// Clean up the VO (optional but good practice)
voLookUp.reset()
if (MPAGenerated_c > TotalPaysheetAmountInLHC_c*lookupTag_c )
{
throw new oracle.jbo.ValidationException("EPA : MPA generated should not be greater than "+TotalPaysheetAmountInLHC_c*lookupTag_c);
}
if (calculationExecuted) {
println("[EPA Trigger] Section 6 completed successfully")
}
} else {
println("[EPA Trigger] IncentiveType not BONUS - skipping Section 6 logic.")
}
println("[EPA Trigger] *** END Section 6 (Original 10 & 11) ***")
}
Comments
Post a Comment