Search in sources :

Example 1 with TransactionOverride

use of edu.cornell.kfs.tax.businessobject.TransactionOverride in project cu-kfs by CU-CommunityApps.

the class TransactionOverrideMaintenanceDocumentRule method processCustomRouteDocumentBusinessRules.

@Override
protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
    boolean valid = super.processCustomRouteDocumentBusinessRules(document);
    // For 1099 transaction overrides, make sure tax bucket value is not too long.
    TransactionOverride transactionOverride = (TransactionOverride) document.getNewMaintainableObject().getDataObject();
    if (CUTaxConstants.TAX_TYPE_1099.equals(transactionOverride.getTaxType()) && StringUtils.isNotEmpty(transactionOverride.getBoxNumber()) && transactionOverride.getBoxNumber().length() > CUTaxConstants.TAX_1099_MAX_BUCKET_LENGTH) {
        putFieldError("boxNumber", CUTaxKeyConstants.ERROR_DOCUMENT_TRANSACTIONOVERRIDEMAINTENANCE_1099_BOX_LENGTH, new String[] { Integer.toString(CUTaxConstants.TAX_1099_MAX_BUCKET_LENGTH) });
        valid = false;
    }
    return valid;
}
Also used : TransactionOverride(edu.cornell.kfs.tax.businessobject.TransactionOverride) TransactionOverride(edu.cornell.kfs.tax.businessobject.TransactionOverride)

Example 2 with TransactionOverride

use of edu.cornell.kfs.tax.businessobject.TransactionOverride in project cu-kfs by CU-CommunityApps.

the class TransactionOverrideCsvBatchInputFileType method convertParsedLineToVO.

/**
 * Transforms each parsed line into a TransactionOverride BO if content is valid,
 * or into a String representation of the parsed line if content is invalid.
 * Assumes that TransactionOverrideCsv is the header enum.
 *
 * @param parsedLine The line to process, as a Map from header names to values.
 * @param lineNumber The current line number, starting from 1.
 * @param docNumberMaxLength The max length of the BO's document number property.
 * @param boxNumberMaxLength The max length of the BO's tax box property.
 * @return A TransactionOverride object if a valid line, otherwise a tab-delimited String representation of the line.
 */
protected Object convertParsedLineToVO(Map<String, String> parsedLine, int lineNumber, int docNumberMaxLength, int boxNumberMaxLength) {
    boolean valid = true;
    TransactionOverride transOverride = new TransactionOverride();
    // Verify that exactly one type of tax box was specified, and that the tax box has the expected max length. Also setup tax box properties if valid.
    String box1099 = parsedLine.get(TransactionOverrideCsv.Form_1099_Box.toString());
    String box1042S = parsedLine.get(TransactionOverrideCsv.Form_1042S_Box.toString());
    if (StringUtils.isBlank(box1099)) {
        if (StringUtils.isBlank(box1042S)) {
            LOG.error("Found a line that does not specify a 1099 or 1042S tax box override. Line number: " + Integer.toString(lineNumber));
            valid = false;
        } else if (box1042S.length() > boxNumberMaxLength) {
            LOG.error("Found a line with a 1042S box number that is too long. Line number: " + Integer.toString(lineNumber));
            valid = false;
        } else {
            // Validation succeeded; configure override of a 1042S tax box.
            transOverride.setTaxType(CUTaxConstants.TAX_TYPE_1042S);
            transOverride.setBoxNumber(NULL_STRING.equalsIgnoreCase(box1042S) ? CUTaxConstants.TAX_1042S_UNKNOWN_BOX_KEY : box1042S);
        }
    } else if (StringUtils.isNotBlank(box1042S)) {
        LOG.error("Found a line that specifies both a 1099 and 1042S tax box override. Line number: " + Integer.toString(lineNumber));
        valid = false;
    } else if (box1099.length() > CUTaxConstants.TAX_1099_MAX_BUCKET_LENGTH && !NULL_STRING.equalsIgnoreCase(box1099)) {
        LOG.error("Found a line with a 1099 box number that is too long. Line number: " + Integer.toString(lineNumber));
        valid = false;
    } else {
        // Validation succeeded; configure override of a 1099 tax box.
        transOverride.setTaxType(CUTaxConstants.TAX_TYPE_1099);
        transOverride.setBoxNumber(NULL_STRING.equalsIgnoreCase(box1099) ? CUTaxConstants.TAX_1099_UNKNOWN_BOX_KEY : box1099);
    }
    // Setup document number, and verify that the value is non-blank and is not too large.
    transOverride.setDocumentNumber(parsedLine.get(TransactionOverrideCsv.Doc_Number.toString()));
    if (StringUtils.isBlank(transOverride.getDocumentNumber())) {
        LOG.error("Found a line with a blank document number. Line number: " + Integer.toString(lineNumber));
        valid = false;
    } else if (transOverride.getDocumentNumber().length() > docNumberMaxLength) {
        LOG.error("Found a line with a document number that is too long. Line number: " + Integer.toString(lineNumber));
        valid = false;
    }
    // Setup document line number, which should be a valid integer.
    try {
        transOverride.setFinancialDocumentLineNumber(Integer.valueOf(parsedLine.get(TransactionOverrideCsv.Doc_Line_Number.toString())));
    } catch (NumberFormatException e) {
        LOG.error("Found a line whose document line number is null or invalid. Line number: " + Integer.toString(lineNumber));
        valid = false;
    }
    // Setup university/payment date, which should be a valid SQL Date.
    try {
        transOverride.setUniversityDate((java.sql.Date) dateFormatter.convertFromPresentationFormat(parsedLine.get(TransactionOverrideCsv.Payment_Date.toString())));
        if (transOverride.getUniversityDate() == null) {
            LOG.error("Found a line with a null payment date. Line number: " + Integer.toString(lineNumber));
            valid = false;
        }
    } catch (FormatException | ClassCastException e) {
        LOG.error("Found a line with an invalid payment date. Line number: " + Integer.toString(lineNumber));
        valid = false;
    }
    if (valid) {
        // No validation errors found; return the newly-constructed object.
        return transOverride;
    } else {
        // Validation failed; return the line as a tab-limited String instead (with the values ordered accordingly).
        List<String> lineValues = new ArrayList<String>();
        for (String headerName : getCsvHeaderList()) {
            lineValues.add(parsedLine.get(headerName));
        }
        return StringUtils.join(lineValues, '\t');
    }
}
Also used : TransactionOverride(edu.cornell.kfs.tax.businessobject.TransactionOverride) ArrayList(java.util.ArrayList) FormatException(org.kuali.rice.core.web.format.FormatException)

Example 3 with TransactionOverride

use of edu.cornell.kfs.tax.businessobject.TransactionOverride in project cu-kfs by CU-CommunityApps.

the class TransactionOverrideCsvBatchInputFileType method process.

/**
 * Overridden to save Transaction Override BOs and also print errors to an output file accordingly.
 *
 * @see org.kuali.kfs.sys.batch.CsvBatchInputFileTypeBase#process(java.lang.String, java.lang.Object)
 */
@Override
public void process(String fileName, Object parsedFileContents) {
    List<?> parsedObjects = (List<?>) parsedFileContents;
    List<String> invalidLines = new ArrayList<String>();
    // Save the valid transaction overrides, and aggregate the invalid lines.
    for (Object parsedObject : parsedObjects) {
        if (parsedObject instanceof TransactionOverride) {
            // Valid line; add new override or update existing override.
            TransactionOverride transOverride = (TransactionOverride) parsedObject;
            String oldBoxOverride = NONE_STRING;
            transOverride.setActive(true);
            // Check if override already exists.
            List<TransactionOverride> existingOverride = criteriaLookupService.lookup(TransactionOverride.class, QueryByCriteria.Builder.fromPredicates(PredicateFactory.equal(KFSPropertyConstants.UNIVERSITY_DATE, transOverride.getUniversityDate()), PredicateFactory.equal(KFSPropertyConstants.DOCUMENT_NUMBER, transOverride.getDocumentNumber()), PredicateFactory.equal(KFSPropertyConstants.FINANCIAL_DOCUMENT_LINE_NUMBER, transOverride.getFinancialDocumentLineNumber()), PredicateFactory.equal(CUTaxPropertyConstants.TAX_TYPE, transOverride.getTaxType()))).getResults();
            if (!existingOverride.isEmpty()) {
                // If override already exists, copy appropriate properties to the updated object.
                transOverride.setObjectId(existingOverride.get(0).getObjectId());
                transOverride.setVersionNumber(existingOverride.get(0).getVersionNumber());
                oldBoxOverride = existingOverride.get(0).getBoxNumber();
            }
            // Save and log addition/update.
            transOverride = businessObjectService.save(transOverride);
            LOG.info("Saved override for date " + transOverride.getUniversityDate() + ", doc " + transOverride.getDocumentNumber() + ", line " + transOverride.getFinancialDocumentLineNumber() + ", and tax type " + transOverride.getTaxType() + " --- Old Box Override: " + oldBoxOverride + ", New Box Override: " + transOverride.getBoxNumber());
        } else if (parsedObject instanceof String) {
            // Invalid line; add to list.
            invalidLines.add((String) parsedObject);
        }
    }
    // Print any invalid lines to an error output file.
    if (!invalidLines.isEmpty()) {
        writeValidationErrorFile(fileName, invalidLines);
    }
}
Also used : TransactionOverride(edu.cornell.kfs.tax.businessobject.TransactionOverride) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransactionOverride(edu.cornell.kfs.tax.businessobject.TransactionOverride)

Aggregations

TransactionOverride (edu.cornell.kfs.tax.businessobject.TransactionOverride)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1 FormatException (org.kuali.rice.core.web.format.FormatException)1