EPA validations

// ============================================================================ // VALIDATION SCRIPT - All Validation Checks // ============================================================================ // ============================================================================ // Validation for Action Code: MAV_DIR_BB_ACTION_1006 // ============================================================================ 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!"); } } // ============================================================================ // Validation for Section 2: REC Payout Adjustment // Action Code: MAV_DIR_BB_ACTION_1008 // ============================================================================ 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') { // Check if values are not null before validation 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 ***") } // ============================================================================ // Validation for Section 3: NNREC Payout Adjustment // Action Code: MAV_DIR_BB_ACTION_1009 // ============================================================================ 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') { // Check if values are not null before validation 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 ***") } // ============================================================================ // Validation for Section 4: MPA to Write Off // Action Code: MAV_DIR_BB_ACTION_1010 // ============================================================================ 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') { // 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!"); } } println("[EPA Trigger] *** END Validation Section 4 ***") } // ============================================================================ // Validation for Section 5: MPA to Payroll Collections // Action Code: MAV_DIR_BB_ACTION_1011 // ============================================================================ if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1011' && EmploymentCountry_c != 'RO') { println("[EPA Trigger] *** START Validation Section 5: MPA to Payroll Collections ***") // Validation for Section 5.1: SalesRP_c == 'Y' if ((IncentiveType_c == 'COMMISSION' || IncentiveType_c == 'BONUS') && SalesRP_c == 'Y') { println("[EPA Trigger] Sub-Section 5.1 (SalesRP_c=Y) validation check.") // Check if values are not null before validation 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).") } } // Validation for Section 5.2: SalesRP_c == 'N' 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 check ** if (EmployeeConsent_c == 'N') { throw new oracle.jbo.ValidationException("EPA : Employee Consent is required for non salesrep!"); } // Check if values are not null before validation if (ExpectedPaymentAmount_c != null && CED_c != null) { // ** 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).") } } println("[EPA Trigger] *** END Validation Section 5 ***") } // ============================================================================ // Validation for Section 6: SPIF vs Comm Deduction // Action Code: MAV_DIR_BB_ACTION_1012 // ============================================================================ if (BBActionManual_c == 'MAV_DIR_BB_ACTION_1012' && SalesRP_c == 'Y') { println("[EPA Trigger] *** START Validation Section 6: SPIF vs Comm Deduction ***") 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 basePaysheetAmount = SCDEPAValue_c ?: SCDCEDValue_c // ** NULL CHECK VALIDATION ** if (basePaysheetAmount == null || ExpectedPaymentAmount_c == null) { 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 or CED is NULL. MPA cannot be compared!!"); } // ** 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).") // ** 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 ** // Calculate MPAGenerated_c for validation purposes (temporary calculation) 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()) // 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): ${tempMPAGenerated.abs()}") println("[EPA Trigger] Calculated Limit (Absolute): ${limitAmount.abs()}") // Perform the validation comparison if (tempMPAGenerated.abs() > limitAmount.abs()) { def formattedLimit = limitAmount.toString() throw new oracle.jbo.ValidationException("EPA : MPA generated should not be greater than " + formattedLimit); } } 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

Popular posts from this blog

Section 15-Done

Section 16-Done

Section 13-Done