EPA

// ============================================================================ // Section 1: Hold Beginning Balance (Full BB on Hold Until next month) // Action Code: MAV_DIR_BB_ACTION_1007 // ============================================================================ // - new validation if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1006') { 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!"); } } if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1007') { println("[EPA Trigger] *** START Section 1: Hold Beginning Balance ***") println("[EPA Trigger] Action Code: ${BBActionManual_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) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null. Upstream data required for calculation.") MPAGenerated_c = null // Set to null if inputs are missing } else { // Calculate MPAGenerated_c and CAP TO 2 DECIMAL PLACES MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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 (BBActionManual_c == 'MAV_DIR_BB_ACTION_1008') { println("[EPA Trigger] *** START Section 2: REC Payout Adjustment ***") println("[EPA Trigger] Action Code: ${BBActionManual_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) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null. Upstream data required for calculation and status setting skipped.") 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 2 DECIMAL PLACES MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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 = 'Unsubmitted' println("[EPA Trigger] Setting MPAStatus_c to: Unsubmitted (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 (BBActionManual_c == 'MAV_DIR_BB_ACTION_1009') { println("[EPA Trigger] *** START Section 3: NNREC Payout Adjustment ***") println("[EPA Trigger] Action Code: ${BBActionManual_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) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null. Upstream data required for calculation.") 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 2 DECIMAL PLACES MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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 (BBActionManual_c == 'MAV_DIR_BB_ACTION_1010') { println("[EPA Trigger] *** START Section 4: MPA to Write Off ***") println("[EPA Trigger] Action Code: ${BBActionManual_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.") // negative validation 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!"); } // ** NULL-AWARE CALCULATION ** if (ExpectedPaymentAmount_c == null || CED_c == null) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null. Upstream data required for calculation.") MPAGenerated_c = null // Set to null if inputs are missing } else { // Calculate MPAGenerated_c and CAP TO 2 DECIMAL PLACES MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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 (BBActionManual_c == 'MAV_DIR_BB_ACTION_1011' && EmploymentCountry_c != 'RO') { println("[EPA Trigger] *** START Section 5: MPA to Payroll Collections ***") println("[EPA Trigger] Action Code: ${BBActionManual_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) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null. Upstream data required for calculation.") 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 2 DECIMAL PLACES MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) or CED_c (${CED_c}) is null. Upstream data required for calculation.") 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 2 DECIMAL PLACES MPAGenerated_c = (ExpectedPaymentAmount_c - CED_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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 (BBActionManual_c == 'MAV_DIR_BB_ACTION_1012' && SalesRP_c == 'Y') { println("[EPA Trigger] *** START Section 6: SPIF vs Comm Deduction ***") println("[EPA Trigger] Action Code: ${BBActionManual_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).") if (MPAStatus_c != 'Unsubmitted') { println("[BBAction Trigger] Setting MPAStatus from '${MPAStatus_c}' to 'Unsubmitted'") MPAStatus_c = 'Unsubmitted' } else { println("[BBAction Trigger] MPAStatus already 'Unsubmitted' - no change needed") } // Set RecoverableFlagV1_c to 'Y' if (RecoverableFlagV1_c != 'Y') { println("[BBAction Trigger] Setting RecoverableFlagV1 from '${RecoverableFlagV1_c}' to 'Y'") RecoverableFlagV1_c = 'Y' } else { println("[BBAction Trigger] RecoverableFlagV1 already 'Y' - no change needed") } // ** VALIDATION 1: Employee Consent check ** if (EmployeeConsent_c == 'N') { // BBActionManual_c = null // FIX: Reset the action field on validation failure throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for salesrep!"); } def calculationExecuted = false // --- START FIX: Update null check to use the correct variables --- // Calculate the base paysheet amount for the later null check, using Groovy Elvis operator (?:) for safety def basePaysheetAmount = SCDEPAValue_c ?: SCDCEDValue_c // ** NULL-AWARE CHECK BEFORE VALIDATION/CALCULATION ** // Replaced TotalPaysheetAmountInLHC_c with the newly introduced fields SCDEPAValue_c/SCDCEDValue_c if (basePaysheetAmount == null || ExpectedPaymentAmount_c == null) { // WARNING MESSAGE ADDED/MODIFIED println("[EPA Trigger] WARNING: MPAGenerated_c set to NULL because paysheet calculation input (SCDEPAValue_c or SCDCEDValue_c) or ExpectedPaymentAmount_c (${ExpectedPaymentAmount_c}) is null. Upstream data required for calculation.") MPAGenerated_c = null // Set to null if inputs are missing // BBActionManual_c = null // FIX: Reset the action field on validation failure throw new oracle.jbo.ValidationException("EPA : Commision EPA or CED is NULL. MPA cannot be compared!!"); } else { // --- END FIX --- // ** VALIDATION 2: Expected Payment Amount ** if (ExpectedPaymentAmount_c > 0) { println("[EPA Trigger] ** VALIDATION FAILED ** ExpectedPaymentAmount_c is Positive: ${ExpectedPaymentAmount_c}") // BBActionManual_c = null // FIX: Reset the action field on validation failure 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 2 DECIMAL PLACES MPAGenerated_c = ((-1)*ExpectedPaymentAmount_c).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated MPAGenerated_c: ${MPAGenerated_c} (Capped to 2 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 lookupMeaning_c = nvl(rowLookup?.Description, "") lookupTag_c = nvl(rowLookup?.Tag, "") // This is retrieved as a String // 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() // --- FIXED VALIDATION LOGIC START (2 Decimals) --- def limitAmount = null // Ensure all required variables are non-null and lookupTag_c is not empty // Replaced TotalPaysheetAmountInLHC_c with basePaysheetAmount (which contains SCDEPAValue_c or SCDCEDValue_c) if (MPAGenerated_c != null && basePaysheetAmount != null && lookupTag_c != null && lookupTag_c.trim() != '') { try { // Define explicit BigDecimal variables to avoid 'unpegged token *' error // FIX: Use Groovy's Elvis operator (?:) for clearer, standard null-coalescing logic. def paysheetAmount = (SCDEPAValue_c ?: SCDCEDValue_c) as BigDecimal // total paysheet amount is scdepaalue or scencedvalue def tagLimitFactor = new BigDecimal(lookupTag_c.trim()) // Calculate the limit amount, and cap the result to 2 decimal places. limitAmount = (paysheetAmount * tagLimitFactor).setScale(2, BigDecimal.ROUND_HALF_UP) println("[EPA Trigger] Calculated Limit (2 Decimals): ${limitAmount}") println("[EPA Trigger] Calculated MPAGenerated_c (Absolute): ${MPAGenerated_c.abs()}") println("[EPA Trigger] Calculated Limit (Absolute): ${limitAmount.abs()}") // Perform the validation comparison: Using absolute values for both sides for magnitude check. // FIX: Using .abs() on limitAmount as requested. if (MPAGenerated_c.abs() > limitAmount.abs()) { // Throw the exception, using the 2-decimal capped limitAmount in the message def formattedLimit = limitAmount.toString() // BBActionManual_c = null // FIX: Reset the action field on validation failure // MPAGenerated_c = null // ADDED: Reset the calculated field to prevent 'dirty' state throw new oracle.jbo.ValidationException("EPA : MPA generated should not be greater than " + formattedLimit); } } catch (NumberFormatException e) { // Handle case where lookupTag_c is not a valid number 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).") } // --- FIXED VALIDATION LOGIC END --- 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

Popular posts from this blog

Section 15-Done

Section 16-Done

Section 13-Done