Search in sources :

Example 1 with OriginationCode

use of org.kuali.kfs.sys.businessobject.OriginationCode in project cu-kfs by CU-CommunityApps.

the class CuPaymentFileValidationServiceImpl method processGroupValidation.

@Override
protected void processGroupValidation(PaymentFileLoad paymentFile, MessageMap errorMap) {
    int groupCount = 0;
    for (PaymentGroup paymentGroup : paymentFile.getPaymentGroups()) {
        groupCount++;
        int noteLineCount = 0;
        int detailCount = 0;
        // We've encountered Payment Files that have address lines exceeding the column size in DB table;
        // so adding extra validation on payment group BO, especially the max length, based on DD definitions.
        // Check that PaymentGroup String properties don't exceed maximum allowed length
        checkPaymentGroupPropertyMaxLength(paymentGroup, errorMap);
        // verify payee id and owner code if customer requires them to be filled in
        if (paymentFile.getCustomer().getPayeeIdRequired() && StringUtils.isBlank(paymentGroup.getPayeeId())) {
            LOG.debug("processGroupValidation, No payee");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_ID_REQUIRED, Integer.toString(groupCount));
        }
        if (paymentFile.getCustomer().getOwnershipCodeRequired() && StringUtils.isBlank(paymentGroup.getPayeeOwnerCd())) {
            LOG.debug("processGroupValidation, no ownership code");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_PAYEE_OWNER_CODE, Integer.toString(groupCount));
        }
        // validate payee id type
        if (StringUtils.isNotBlank(paymentGroup.getPayeeIdTypeCd())) {
            PayeeType payeeType = businessObjectService.findBySinglePrimaryKey(PayeeType.class, paymentGroup.getPayeeIdTypeCd());
            if (payeeType == null) {
                LOG.debug("processGroupValidation, no payee type");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_PAYEE_ID_TYPE, Integer.toString(groupCount), paymentGroup.getPayeeIdTypeCd());
            }
        }
        // validate vendor id and customer institution number
        if (paymentGroup.getPayeeId().split("-").length > 1) {
            try {
                paymentGroup.validateVendorIdAndCustomerInstitutionIdentifier();
            } catch (RuntimeException e1) {
                LOG.error("processGroupValidation, there was an error validating customer institution information", e1);
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, CUKFSKeyConstants.ERROR_BATCH_UPLOAD_PARSING_XML, new String[] { e1.getMessage() });
            }
        } else {
            LOG.debug("processGroupValidation, found a non vendor number payee ID: " + paymentGroup.getPayeeId());
            if (cuPdpEmployeeService.shouldPayeeBeProcessedAsEmployeeForThisCustomer(paymentFile)) {
                Person employee = findPerson(paymentGroup.getPayeeId());
                if (ObjectUtils.isNull(employee)) {
                    LOG.error("processGroupValidation, unable to get a person from the employee id");
                    errorMap.putError(KFSConstants.GLOBAL_ERRORS, CUPdpKeyConstants.ERROR_PDP_PAYMENTLOAD_INVALID_EMPLOYEE_ID, paymentGroup.getPayeeId());
                }
            }
        }
        // validate bank
        String bankCode = paymentGroup.getBankCode();
        if (StringUtils.isNotBlank(bankCode)) {
            Bank bank = bankService.getByPrimaryId(bankCode);
            if (bank == null) {
                LOG.debug("processGroupValidation, no bank");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_BANK_CODE, Integer.toString(groupCount), bankCode);
            } else if (!bank.isActive()) {
                LOG.debug("processGroupValidation, bank isn't active");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INACTIVE_BANK_CODE, Integer.toString(groupCount), bankCode);
            }
        }
        KualiDecimal groupTotal = KualiDecimal.ZERO;
        for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
            detailCount++;
            // Add a line to print the invoice number
            noteLineCount++;
            noteLineCount = noteLineCount + paymentDetail.getNotes().size();
            if ((paymentDetail.getNetPaymentAmount() == null) && (!paymentDetail.isDetailAmountProvided())) {
                paymentDetail.setNetPaymentAmount(paymentDetail.getAccountTotal());
            } else if ((paymentDetail.getNetPaymentAmount() == null) && (paymentDetail.isDetailAmountProvided())) {
                paymentDetail.setNetPaymentAmount(paymentDetail.getCalculatedPaymentAmount());
            }
            // compare net to accounting segments
            if (paymentDetail.getAccountTotal().compareTo(paymentDetail.getNetPaymentAmount()) != 0) {
                LOG.debug("processGroupValidation, account total (" + paymentDetail.getAccountTotal() + ") not equal to net amount total (" + paymentDetail.getNetPaymentAmount() + ")");
                errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_DETAIL_TOTAL_MISMATCH, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getAccountTotal().toString(), paymentDetail.getNetPaymentAmount().toString());
            }
            // validate origin code if given
            if (StringUtils.isNotBlank(paymentDetail.getFinancialSystemOriginCode())) {
                OriginationCode originationCode = originationCodeService.getByPrimaryKey(paymentDetail.getFinancialSystemOriginCode());
                if (originationCode == null) {
                    LOG.debug("processGroupValidation, origination code is null");
                    errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_ORIGIN_CODE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialSystemOriginCode());
                }
            }
            // validate doc type if given
            if (StringUtils.isNotBlank(paymentDetail.getFinancialDocumentTypeCode())) {
                if (!documentTypeService.isActiveByName(paymentDetail.getFinancialDocumentTypeCode())) {
                    LOG.debug("processGroupValidation, " + paymentDetail.getFinancialDocumentTypeCode() + " is not active.");
                    errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_INVALID_DOC_TYPE, Integer.toString(groupCount), Integer.toString(detailCount), paymentDetail.getFinancialDocumentTypeCode());
                }
            }
            groupTotal = groupTotal.add(paymentDetail.getNetPaymentAmount());
        }
        // verify total for group is not negative
        if (groupTotal.doubleValue() < 0) {
            LOG.debug("processGroupValidation, group total less than zero");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_NEGATIVE_GROUP_TOTAL, Integer.toString(groupCount));
        }
        // check that the number of detail items and note lines will fit on a check stub
        if (noteLineCount > getMaxNoteLines()) {
            LOG.debug("processGroupValidation, too many notes");
            errorMap.putError(KFSConstants.GLOBAL_ERRORS, PdpKeyConstants.ERROR_PAYMENT_LOAD_MAX_NOTE_LINES, Integer.toString(groupCount), Integer.toString(noteLineCount), Integer.toString(getMaxNoteLines()));
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("After processGroupValidation: " + printErrorMap(errorMap));
        }
    }
}
Also used : PaymentGroup(org.kuali.kfs.pdp.businessobject.PaymentGroup) Bank(org.kuali.kfs.sys.businessobject.Bank) PayeeType(org.kuali.kfs.pdp.businessobject.PayeeType) PaymentDetail(org.kuali.kfs.pdp.businessobject.PaymentDetail) OriginationCode(org.kuali.kfs.sys.businessobject.OriginationCode) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Person(org.kuali.rice.kim.api.identity.Person)

Example 2 with OriginationCode

use of org.kuali.kfs.sys.businessobject.OriginationCode in project cu-kfs by CU-CommunityApps.

the class ScrubberValidatorImpl method validateOrigination.

/**
 * Validates the origination code of the origin entry
 *
 * @param originEntry  the origin entry being scrubbed
 * @param workingEntry the scrubbed version of the origin entry
 * @return a Message if an error was encountered, otherwise null
 */
protected Message validateOrigination(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, AccountingCycleCachingService accountingCycleCachingService) {
    LOG.debug("validateOrigination() started");
    if (StringUtils.hasText(originEntry.getFinancialSystemOriginationCode())) {
        OriginationCode originEntryOrigination = accountingCycleCachingService.getOriginationCode(originEntry.getFinancialSystemOriginationCode());
        if (originEntryOrigination == null) {
            return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_ORIGIN_CODE_NOT_FOUND, originEntry.getFinancialSystemOriginationCode(), Message.TYPE_FATAL);
        }
        if (!originEntryOrigination.isActive()) {
            return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_ORIGIN_CODE_NOT_ACTIVE, originEntry.getFinancialSystemOriginationCode(), Message.TYPE_FATAL);
        }
        workingEntry.setFinancialSystemOriginationCode(originEntry.getFinancialSystemOriginationCode());
    } else {
        return new Message(kualiConfigurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_ORIGIN_CODE_NOT_FOUND) + " (" + originEntry.getFinancialSystemOriginationCode() + ")", Message.TYPE_FATAL);
    }
    return null;
}
Also used : Message(org.kuali.kfs.sys.Message) OriginationCode(org.kuali.kfs.sys.businessobject.OriginationCode)

Example 3 with OriginationCode

use of org.kuali.kfs.sys.businessobject.OriginationCode in project cu-kfs by CU-CommunityApps.

the class ScrubberValidatorImpl method validateReferenceDocumentFields.

/**
 * If the encumbrance update code = R, ref doc number must exist, ref doc type must be valid and ref origin code must be valid.
 * If encumbrance update code is not R, and ref doc number is empty, make sure ref doc number, ref doc type and ref origin code
 * are null. If encumbrance update code is not R and the ref doc number has a value, ref doc type must be valid and ref origin
 * code must be valid.
 *
 * @param originEntry      the origin entry to check
 * @param workingEntryInfo the copy of the entry to move valid data into
 * @return a Message if an error was encountered, otherwise null
 */
protected List<Message> validateReferenceDocumentFields(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, AccountingCycleCachingService accountingCycleCachingService) {
    LOG.debug("validateReferenceDocument() started");
    // 3148 of cobol
    List<Message> errors = new ArrayList();
    boolean numberNullIndicator = !StringUtils.hasText(originEntry.getReferenceFinancialDocumentNumber());
    boolean typeCodeNullIndicator = !StringUtils.hasText(originEntry.getReferenceFinancialDocumentTypeCode());
    boolean originCodeNullIndicator = !StringUtils.hasText(originEntry.getReferenceFinancialSystemOriginationCode());
    // TODO:- do we need this?
    boolean editReference = true;
    if (numberNullIndicator) {
        workingEntry.setReferenceFinancialDocumentNumber(null);
        workingEntry.setReferenceFinancialDocumentTypeCode(null);
        workingEntry.setReferenceFinancialSystemOriginationCode(null);
        if (KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(originEntry.getTransactionEncumbranceUpdateCode())) {
            errors.add(MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REF_DOC_NOT_BE_SPACE, Message.TYPE_FATAL));
        }
    } else {
        workingEntry.setReferenceFinancialDocumentNumber(originEntry.getReferenceFinancialDocumentNumber());
        if (!typeCodeNullIndicator) {
            if (accountingCycleCachingService.isCurrentActiveAccountingDocumentType(originEntry.getReferenceFinancialDocumentTypeCode())) {
                workingEntry.setReferenceFinancialDocumentTypeCode(originEntry.getReferenceFinancialDocumentTypeCode());
            } else {
                errors.add(MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REFERENCE_DOCUMENT_TYPE_NOT_FOUND, originEntry.getReferenceFinancialDocumentTypeCode(), Message.TYPE_FATAL));
            }
        } else {
            errors.add(MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REFERENCE_FIELDS, " " + KFSPropertyConstants.REFERENCE_FIN_DOCUMENT_TYPE_CODE + " is missing.", Message.TYPE_FATAL));
        }
        if (!originCodeNullIndicator) {
            // Validate reference origin code
            OriginationCode oc = accountingCycleCachingService.getOriginationCode(originEntry.getFinancialSystemOriginationCode());
            if (oc != null) {
                workingEntry.setReferenceFinancialSystemOriginationCode(originEntry.getReferenceFinancialSystemOriginationCode());
            } else {
                errors.add(MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REFERENCE_ORIGINATION_CODE_NOT_FOUND, " (" + originEntry.getReferenceFinancialSystemOriginationCode() + ")", Message.TYPE_FATAL));
            }
        } else {
            errors.add(MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REFERENCE_FIELDS, " " + KFSPropertyConstants.REFERENCE_FINANCIAL_SYSTEM_ORIGINATION_CODE + " is missing.", Message.TYPE_FATAL));
        }
    }
    BalanceType workingEntryBalanceType = accountingCycleCachingService.getBalanceType(workingEntry.getFinancialBalanceTypeCode());
    ObjectType workingEntryObjectType = accountingCycleCachingService.getObjectType(workingEntry.getFinancialObjectTypeCode());
    if (workingEntryBalanceType == null || workingEntryObjectType == null) {
        // It would be nice if we could still validate the entry, but we can't.
        return errors;
    }
    if (workingEntryBalanceType.isFinBalanceTypeEncumIndicator() && !workingEntryObjectType.isFundBalanceIndicator()) {
        if (// KFSMI-5565 : Allow blank/null for encumbrance update code, since it is the same as "N" during processing and should not be an error
        org.apache.commons.lang.StringUtils.isBlank(originEntry.getTransactionEncumbranceUpdateCode()) || KFSConstants.ENCUMB_UPDT_DOCUMENT_CD.equals(originEntry.getTransactionEncumbranceUpdateCode()) || KFSConstants.ENCUMB_UPDT_NO_ENCUMBRANCE_CD.equals(originEntry.getTransactionEncumbranceUpdateCode()) || KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD.equals(originEntry.getTransactionEncumbranceUpdateCode())) {
            workingEntry.setTransactionEncumbranceUpdateCode(originEntry.getTransactionEncumbranceUpdateCode());
        } else {
            errors.add(MessageBuilder.buildMessage(KFSKeyConstants.ERROR_ENC_UPDATE_CODE_NOT_DRN, " (" + originEntry.getTransactionEncumbranceUpdateCode() + ")", Message.TYPE_FATAL));
        }
    } else {
        workingEntry.setTransactionEncumbranceUpdateCode(null);
    }
    return errors;
}
Also used : ObjectType(org.kuali.kfs.coa.businessobject.ObjectType) Message(org.kuali.kfs.sys.Message) OriginationCode(org.kuali.kfs.sys.businessobject.OriginationCode) ArrayList(java.util.ArrayList) BalanceType(org.kuali.kfs.coa.businessobject.BalanceType)

Example 4 with OriginationCode

use of org.kuali.kfs.sys.businessobject.OriginationCode in project cu-kfs by CU-CommunityApps.

the class ScrubberValidatorImpl method validateReferenceOrigination.

protected Message validateReferenceOrigination(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, AccountingCycleCachingService accountingCycleCachingService) {
    LOG.debug("validateOrigination() started");
    String referenceFinancialSystemOriginationCode = originEntry.getReferenceFinancialSystemOriginationCode();
    if (StringUtils.hasText(referenceFinancialSystemOriginationCode)) {
        OriginationCode originEntryOrigination = accountingCycleCachingService.getOriginationCode(referenceFinancialSystemOriginationCode);
        if (originEntryOrigination == null) {
            return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REFERENCE_ORIGIN_CODE_NOT_FOUND, " (" + referenceFinancialSystemOriginationCode + ")", Message.TYPE_FATAL);
        } else {
            workingEntry.setReferenceFinancialSystemOriginationCode(referenceFinancialSystemOriginationCode);
        }
    }
    return null;
}
Also used : OriginationCode(org.kuali.kfs.sys.businessobject.OriginationCode)

Aggregations

OriginationCode (org.kuali.kfs.sys.businessobject.OriginationCode)4 Message (org.kuali.kfs.sys.Message)2 ArrayList (java.util.ArrayList)1 BalanceType (org.kuali.kfs.coa.businessobject.BalanceType)1 ObjectType (org.kuali.kfs.coa.businessobject.ObjectType)1 PayeeType (org.kuali.kfs.pdp.businessobject.PayeeType)1 PaymentDetail (org.kuali.kfs.pdp.businessobject.PaymentDetail)1 PaymentGroup (org.kuali.kfs.pdp.businessobject.PaymentGroup)1 Bank (org.kuali.kfs.sys.businessobject.Bank)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1 Person (org.kuali.rice.kim.api.identity.Person)1