Search in sources :

Example 1 with AttributedRouteDocumentEvent

use of org.kuali.kfs.sys.document.validation.event.AttributedRouteDocumentEvent in project cu-kfs by CU-CommunityApps.

the class CuAccountsPayableBankCodeValidation method validate.

@Override
public boolean validate(AttributedDocumentEvent event) {
    AccountsPayableDocumentBase apDocument = (AccountsPayableDocumentBase) getAccountingDocumentForValidation();
    // check if one of the extended UA documents, if so, take the payment method into account, otherwise, revert to baseline behavior
    boolean isValid = true;
    if (apDocument instanceof PaymentRequestDocument) {
        if (StringUtils.isNotBlank(apDocument.getBankCode())) {
            // PREQ bank code is not required
            isValid = CuBankCodeValidation.validate(apDocument.getBankCode(), "document." + PurapPropertyConstants.BANK_CODE, ((CuPaymentRequestDocument) apDocument).getPaymentMethodCode(), false, true);
            if (isValid) {
                if (!(event instanceof AttributedRouteDocumentEvent) && StringUtils.isNotBlank(apDocument.getBankCode()) && !CuBankCodeValidation.doesBankCodeNeedToBePopulated(((CuPaymentRequestDocument) apDocument).getPaymentMethodCode())) {
                    apDocument.setBank(null);
                    apDocument.setBankCode(null);
                }
            }
        }
    } else if (apDocument instanceof VendorCreditMemoDocument) {
        if (StringUtils.isNotBlank(apDocument.getBankCode())) {
            isValid = CuBankCodeValidation.validate(apDocument.getBankCode(), "document." + PurapPropertyConstants.BANK_CODE, ((CuVendorCreditMemoDocument) apDocument).getPaymentMethodCode(), false, true);
            if (isValid) {
                // clear out the bank code on the document if not needed (per the message set by the call above)
                if (StringUtils.isNotBlank(apDocument.getBankCode()) && !CuBankCodeValidation.doesBankCodeNeedToBePopulated(((CuVendorCreditMemoDocument) apDocument).getPaymentMethodCode())) {
                    apDocument.setBank(null);
                    apDocument.setBankCode(null);
                }
            }
        }
    } else {
        isValid = CuBankCodeValidation.validate(apDocument.getBankCode(), "document." + PurapPropertyConstants.BANK_CODE, false, true);
    }
    return isValid;
}
Also used : AccountsPayableDocumentBase(org.kuali.kfs.module.purap.document.AccountsPayableDocumentBase) CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) AttributedRouteDocumentEvent(org.kuali.kfs.sys.document.validation.event.AttributedRouteDocumentEvent) CuVendorCreditMemoDocument(edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) CuPaymentRequestDocument(edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)

Aggregations

CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 CuVendorCreditMemoDocument (edu.cornell.kfs.module.purap.document.CuVendorCreditMemoDocument)1 AccountsPayableDocumentBase (org.kuali.kfs.module.purap.document.AccountsPayableDocumentBase)1 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)1 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)1 AttributedRouteDocumentEvent (org.kuali.kfs.sys.document.validation.event.AttributedRouteDocumentEvent)1