Search in sources :

Example 1 with TransactionDetailRow

use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow in project cu-kfs by CU-CommunityApps.

the class TransactionRow1042SProcessor method processTaxRows.

@Override
void processTaxRows(ResultSet rs, Transaction1042SSummary summary) throws SQLException, IOException {
    boolean keepLooping = true;
    boolean taxIdChanged = false;
    TransactionDetailRow detailRow;
    encryptionService = CoreApiServiceLocator.getEncryptionService();
    dvStats = new OriginSpecificStats();
    pdpStats = new OriginSpecificStats();
    // Set default values as needed.
    grossAmountP.value = summary.zeroAmount;
    ftwAmountP.value = summary.zeroAmount;
    sitwAmountP.value = summary.zeroAmount;
    // Setup values that are not expected to change between each iteration.
    taxEINValueP.value = summary.scrubbedOutput ? CUTaxConstants.MASKED_VALUE_9_CHARS : summary.taxEIN;
    stateCodeP.value = summary.stateCode;
    endDateP.value = summary.getEndDate();
    rsDummy = new DummyResultSet();
    detailRow = summary.transactionDetailRow;
    vendorRow = summary.vendorRow;
    vendorAddressRow = summary.vendorAddressRow;
    docNoteTextField = summary.documentNoteRow.noteText;
    grossAmountField = summary.derivedValues.grossAmount;
    ftwAmountField = summary.derivedValues.fedTaxWithheldAmount;
    sitwAmountField = summary.derivedValues.stateIncomeTaxWithheldAmount;
    // Perform initial processing for first row, if there is one.
    if (rs.next()) {
        // If at least one row exists, then update counters and retrieve field values as needed.
        numTransactionRows++;
        nextTaxId = rs.getString(detailRow.vendorTaxNumber.index);
        nextPayeeId = rs.getString(detailRow.payeeId.index);
        nextIncomeCode = rs.getString(detailRow.incomeCode.index);
        nextIncomeCodeSubType = rs.getString(detailRow.incomeCodeSubType.index);
        vendorHeaderId = Integer.parseInt(nextPayeeId.substring(0, nextPayeeId.indexOf('-')));
        vendorDetailId = Integer.parseInt(nextPayeeId.substring(nextPayeeId.indexOf('-') + 1));
        taxIdChanged = true;
        if (StringUtils.isBlank(nextTaxId)) {
            throw new RuntimeException("Could not find tax ID for initial row with payee " + nextPayeeId);
        }
        LOG.info("Starting transaction row processing for 1042S tax reporting...");
    } else {
        // Skip processing if no detail rows were found.
        keepLooping = false;
        LOG.info("No transaction rows found for 1042S tax reporting, skipping processing...");
    }
    // Iterate over the transaction detail rows.
    while (keepLooping) {
        // Initialize transaction detail variables from the current detail line.
        loadTransactionRowValuesFromResults(rs);
        // Setup defaults as needed.
        if (paymentAmountP.value == null) {
            paymentAmountP.value = summary.zeroAmount;
        }
        // Derive helper "key" for logging purposes.
        rowKey = new StringBuilder(MED_BUILDER_SIZE).append(rowIdP.value).append(' ').append(docNumberP.value).append(' ').append(docLineNumberP.value).append(' ').append(payeeIdP.value).append(' ').append(docTypeP.value).append(' ').append(objectCodeP.value).append(' ').append(incomeCodeP.value).append(' ').append(incomeCodeSubTypeP.value).append(' ').append(paymentAmountP.value).append(' ').append(paymentDateP.value).toString();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Processing transaction row with key: " + rowKey);
        }
        // Derive Boolean values.
        taxTreatyExemptIncomeInd = StringUtils.isNotBlank(taxTreatyExemptIncomeYesNoP.value) ? Boolean.valueOf(KRADConstants.YES_INDICATOR_VALUE.equals(taxTreatyExemptIncomeYesNoP.value)) : null;
        foreignSourceIncomeInd = StringUtils.isNotBlank(foreignSourceIncomeYesNoP.value) ? Boolean.valueOf(KRADConstants.YES_INDICATOR_VALUE.equals(foreignSourceIncomeYesNoP.value)) : null;
        // Derive or reset remaining values.
        chartAndAccountCombo = new StringBuilder().append(chartCodeP.value).append('-').append(accountNumberP.value).toString();
        isDVRow = DisbursementVoucherConstants.DOCUMENT_TYPE_CODE.equals(docTypeP.value);
        currentStats = isDVRow ? dvStats : pdpStats;
        excludeTransaction = false;
        foundExclusion = false;
        royaltiesObjInclusionInd = null;
        royaltiesInclusionInd = null;
        fedTaxWithheldInclusionInd = null;
        stateIncTaxWithheldInclusionInd = null;
        taxBox = null;
        // Load new vendor if necessary.
        if (taxIdChanged) {
            loadNewVendor(summary);
        }
        // If necessary, check for exclusions and identify the type of amount.
        if (!summary.zeroAmount.equals(paymentAmountP.value)) {
            checkForExclusionsAndAmounts(summary);
        }
        // Perform final inclusion/exclusion processing, and update amounts accordingly.
        processExclusionsAndAmounts(rs, detailRow, summary);
        // Update current row's vendor-related data.
        rs.updateString(detailRow.vendorName.index, vendorNameForOutput);
        rs.updateString(detailRow.parentVendorName.index, parentVendorNameForOutput);
        rs.updateString(detailRow.vendorEmailAddress.index, vendorEmailAddressP.value);
        rs.updateString(detailRow.vendorChapter4StatusCode.index, rsVendor.getString(vendorRow.vendorChapter4StatusCode.index));
        rs.updateString(detailRow.vendorGIIN.index, rsVendor.getString(vendorRow.vendorGIIN.index));
        rs.updateString(detailRow.vendorLine1Address.index, vendorUSAddressLine1P.value);
        rs.updateString(detailRow.vendorLine2Address.index, rsVendorUSAddress.getString(vendorAddressRow.vendorLine2Address.index));
        rs.updateString(detailRow.vendorCityName.index, rsVendorUSAddress.getString(vendorAddressRow.vendorCityName.index));
        rs.updateString(detailRow.vendorStateCode.index, rsVendorUSAddress.getString(vendorAddressRow.vendorStateCode.index));
        rs.updateString(detailRow.vendorZipCode.index, rsVendorUSAddress.getString(vendorAddressRow.vendorZipCode.index));
        rs.updateString(detailRow.vendorForeignLine1Address.index, vendorForeignAddressLine1P.value);
        rs.updateString(detailRow.vendorForeignLine2Address.index, rsVendorForeignAddress.getString(vendorAddressRow.vendorLine2Address.index));
        rs.updateString(detailRow.vendorForeignCityName.index, rsVendorForeignAddress.getString(vendorAddressRow.vendorCityName.index));
        rs.updateString(detailRow.vendorForeignZipCode.index, rsVendorForeignAddress.getString(vendorAddressRow.vendorZipCode.index));
        rs.updateString(detailRow.vendorForeignCountryCode.index, rsVendorForeignAddress.getString(vendorAddressRow.vendorCountryCode.index));
        // Store any changes made to the current transaction detail row.
        rs.updateRow();
        // Move to next row (if any) and update the looping flag as needed.
        if (rs.next()) {
            // If more rows are available, then update counters and retrieve field values as needed.
            numTransactionRows++;
            nextTaxId = rs.getString(detailRow.vendorTaxNumber.index);
            nextPayeeId = rs.getString(detailRow.payeeId.index);
            nextIncomeCode = rs.getString(detailRow.incomeCode.index);
            nextIncomeCodeSubType = rs.getString(detailRow.incomeCodeSubType.index);
            vendorHeaderId = Integer.parseInt(nextPayeeId.substring(0, nextPayeeId.indexOf('-')));
            vendorDetailId = Integer.parseInt(nextPayeeId.substring(nextPayeeId.indexOf('-') + 1));
            // Check for changes to the tax ID between rows. The prior tax ID should be non-null at this point.
            taxIdChanged = StringUtils.isBlank(nextTaxId) || !taxIdP.value.equals(nextTaxId);
        } else {
            // If no more rows, then prepare to exit the loop and process any leftover data from the previous iterations.
            keepLooping = false;
            writeWsDetailRecord = true;
        }
        // Automatically abort with an error if the current row has no tax ID.
        if (StringUtils.isBlank(nextTaxId)) {
            throw new RuntimeException("Could not find tax ID for row with payee " + nextPayeeId);
        }
        // If necessary, determine whether changes to tax ID, income code or subtype warrant writing a detail line.
        if (!writeWsDetailRecord) {
            if ((StringUtils.isNotBlank(incomeCodeP.value) && (StringUtils.isBlank(nextIncomeCode) || !incomeCodeP.value.equals(nextIncomeCode))) || (taxIdChanged && foundAmount)) {
                // Write record due to change from non-blank code to new or blank code, or due to tax ID change if gross/ftw/sitw amounts were found.
                writeWsDetailRecord = true;
            } else if (StringUtils.isNotBlank(incomeCodeSubTypeP.value) && (StringUtils.isBlank(nextIncomeCodeSubType) || !incomeCodeSubTypeP.value.equals(nextIncomeCodeSubType))) {
                // Write record due to change from non-blank subtype to new or blank subtype.
                writeWsDetailRecord = true;
            }
        }
        /*
             * Do not write a new line to the file if no valid gross/ftw/sitw amount was found yet OR (as per Lori Kanellis) the following criteria are met:
             * 
             * The line does NOT have an Exemption Code of 3 (Foreign Source) or 4 (Treaty Exempt)
             * AND it does NOT have a Federal tax withholding RATE
             * AND it does NOT have a Federal Tax Withholding amount
             */
        if (!foundAmount || (!Boolean.TRUE.equals(taxTreatyExemptIncomeInd) && !Boolean.TRUE.equals(foreignSourceIncomeInd) && (fedIncomeTaxPctP.value == null || summary.zeroAmount.equals(fedIncomeTaxPctP.value)) && summary.zeroAmount.equals(ftwAmountP.value))) {
            writeWsDetailRecord = false;
        }
        /*
             * If needed, write new detail and/or biographic records to the appropriate output files.
             */
        if (writeWsDetailRecord) {
            writeLinesToFiles(summary);
        }
    // END OF LOOP
    }
    LOG.info("Finished transaction row processing for 1042S tax reporting.");
}
Also used : TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow)

Example 2 with TransactionDetailRow

use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow in project cu-kfs by CU-CommunityApps.

the class TransactionRow1042SProcessor method getMinimumFields.

@Override
Set<TaxTableField> getMinimumFields(TaxFieldSource fieldSource, Transaction1042SSummary summary) {
    Set<TaxTableField> minFields = new HashSet<TaxTableField>();
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    DerivedValuesRow derivedValues = summary.derivedValues;
    switch(fieldSource) {
        case BLANK:
            throw new IllegalArgumentException("Cannot find minimum fields for BLANK type");
        case STATIC:
            throw new IllegalArgumentException("Cannot find minimum fields for STATIC type");
        case DETAIL:
            minFields.addAll(Arrays.asList(detailRow.transactionDetailId, detailRow.documentNumber, detailRow.documentType, detailRow.financialDocumentLineNumber, detailRow.finObjectCode, detailRow.netPaymentAmount, detailRow.vendorTaxNumber, detailRow.incomeCode, detailRow.incomeCodeSubType, detailRow.dvCheckStubText, detailRow.payeeId, detailRow.vendorOwnershipCode, detailRow.paymentDate, detailRow.incomeTaxTreatyExemptIndicator, detailRow.foreignSourceIncomeIndicator, detailRow.federalIncomeTaxPercent, detailRow.paymentLine1Address, detailRow.chartCode, detailRow.accountNumber, detailRow.paymentReasonCode));
            break;
        case VENDOR:
            // Leave Set empty.
            break;
        case VENDOR_US_ADDRESS:
            // Leave Set empty.
            break;
        case VENDOR_FOREIGN_ADDRESS:
            // Leave Set empty.
            break;
        case VENDOR_ANY_ADDRESS:
            // Leave Set empty.
            break;
        case DERIVED:
            minFields.addAll(Arrays.asList(derivedValues.vendorLastName, derivedValues.vendorFirstName, derivedValues.vendorEmailAddress, derivedValues.vendorUSAddressLine1, derivedValues.vendorForeignAddressLine1, derivedValues.ssn, derivedValues.itin, derivedValues.chapter3StatusCode, derivedValues.chapter3ExemptionCode, derivedValues.chapter4ExemptionCode, derivedValues.incomeCode, derivedValues.ein, derivedValues.chapter3TaxRate, derivedValues.grossAmount, derivedValues.fedTaxWithheldAmount, derivedValues.stateIncomeTaxWithheldAmount, derivedValues.stateCode, derivedValues.endDate));
            break;
        default:
            throw new IllegalArgumentException("Invalid piece type");
    }
    return minFields;
}
Also used : DerivedValuesRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.DerivedValuesRow) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) HashSet(java.util.HashSet)

Example 3 with TransactionDetailRow

use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow in project cu-kfs by CU-CommunityApps.

the class TransactionRow1099Processor method processTaxRows.

@Override
void processTaxRows(ResultSet rs, Transaction1099Summary summary) throws SQLException, IOException {
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    boolean keepLooping = true;
    boolean taxIdChanged = false;
    encryptionService = CoreApiServiceLocator.getEncryptionService();
    dvStats = new OriginSpecificStats(summary.derivedValues.orderedFields.size());
    pdpStats = new OriginSpecificStats(summary.derivedValues.orderedFields.size());
    boxNumberMappingsWithStatistics = getTaxBoxNumberMappingsWithStatistics(summary);
    // Setup defaults.
    resetTaxBoxes(summary);
    foundAmount = false;
    writeTabRecord = false;
    // Setup values that are not expected to change between each iteration.
    tabSiteIdP.value = summary.tabSiteId;
    rsDummy = new DummyResultSet();
    vendorRow = summary.vendorRow;
    vendorAddressRow = summary.vendorAddressRow;
    docNoteTextField = summary.documentNoteRow.noteText;
    if (summary.scrubbedOutput) {
        outputTaxIdP.value = CUTaxConstants.MASKED_VALUE_9_CHARS;
    }
    // Print header.
    resetBuffer(HEADER_BUFFER_INDEX);
    appendPieces(HEADER_BUFFER_INDEX);
    writeBufferToOutput(HEADER_BUFFER_INDEX, TAX_1099_WRITER_INDEX);
    // Perform initial processing for first row, if there is one.
    if (rs.next()) {
        // If at least one row exists, then update counters and retrieve field values as needed.
        numTransactionRows++;
        nextTaxId = rs.getString(detailRow.vendorTaxNumber.index);
        nextPayeeId = rs.getString(detailRow.payeeId.index);
        vendorHeaderId = Integer.parseInt(nextPayeeId.substring(0, nextPayeeId.indexOf('-')));
        vendorDetailId = Integer.parseInt(nextPayeeId.substring(nextPayeeId.indexOf('-') + 1));
        taxIdChanged = true;
        if (StringUtils.isBlank(nextTaxId)) {
            throw new RuntimeException("Could not find tax ID for initial row with payee " + nextPayeeId);
        }
        LOG.info("Starting transaction row processing for 1099 tax reporting...");
    } else {
        // Skip processing if no detail rows were found.
        keepLooping = false;
        LOG.info("No transaction rows found for 1099 tax reporting, skipping processing...");
    }
    // Iterate over the transaction detail rows.
    while (keepLooping) {
        // Populate "piece" objects from the current transaction row.
        loadTransactionRowValuesFromResults(rs);
        // Set payment amount to zero if null.
        if (paymentAmountP.value == null) {
            paymentAmountP.value = summary.zeroAmount;
        }
        // Setup row "key" string for logging purposes.
        rowKey = new StringBuilder(MED_BUILDER_SIZE).append(rowIdP.value).append(' ').append(docNumberP.value).append(' ').append(docLineNumberP.value).append(' ').append(payeeIdP.value).append(' ').append(docTypeP.value).append(' ').append(objectCodeP.value).append(' ').append(paymentAmountP.value).append(' ').append(paymentDateP.value).toString();
        // Setup other values as needed.
        foundExclusion = false;
        excludeTransaction = false;
        dvCheckStubInclusionInd = null;
        royaltiesObjChartAccountInclusionInd = null;
        nonEmployeeCompVendorNameInclusionInd = null;
        nonEmployeeCompParentVendorNameInclusionInd = null;
        nonEmployeeCompDocTitleInclusionInd = null;
        isDVRow = DisbursementVoucherConstants.DOCUMENT_TYPE_CODE.equals(docTypeP.value);
        currentStats = isDVRow ? dvStats : pdpStats;
        chartAndAccountCombo = new StringBuilder().append(chartCodeP.value).append('-').append(accountNumberP.value).toString();
        taxBox = null;
        // Load data for vendor, if first row or if moving to the next tax ID.
        if (taxIdChanged) {
            resetTaxBoxes(summary);
            foundAmount = false;
            writeTabRecord = false;
            loadVendorData(rs, summary);
        }
        // Determine which tax box applies, and check for exclusions.
        if (!summary.excludedPayeeIds.contains(nextPayeeId)) {
            if (!summary.zeroAmount.equals(paymentAmountP.value)) {
                checkForGeneralExclusionsAndFindTaxBox(rs, summary);
            }
        } else {
            excludeTransaction = true;
        }
        // Determine final inclusion/exclusion state, and update tax boxes accordingly.
        processExclusionsAndAmounts(rs, detailRow, summary);
        // Update current row's vendor-related data.
        rs.updateString(detailRow.vendorName.index, vendorNameForOutput);
        rs.updateString(detailRow.parentVendorName.index, parentVendorNameForOutput);
        rs.updateString(detailRow.vendorEmailAddress.index, vendorEmailAddressP.value);
        rs.updateString(detailRow.vendorChapter4StatusCode.index, rsVendor.getString(vendorRow.vendorChapter4StatusCode.index));
        rs.updateString(detailRow.vendorGIIN.index, rsVendor.getString(vendorRow.vendorGIIN.index));
        rs.updateString(detailRow.vendorLine1Address.index, vendorAddressLine1P.value);
        rs.updateString(detailRow.vendorLine2Address.index, rsVendorAnyAddress.getString(vendorAddressRow.vendorLine2Address.index));
        rs.updateString(detailRow.vendorCityName.index, rsVendorAnyAddress.getString(vendorAddressRow.vendorCityName.index));
        rs.updateString(detailRow.vendorStateCode.index, rsVendorAnyAddress.getString(vendorAddressRow.vendorStateCode.index));
        rs.updateString(detailRow.vendorZipCode.index, rsVendorAnyAddress.getString(vendorAddressRow.vendorZipCode.index));
        // Store any changes made to the current transaction detail row.
        rs.updateRow();
        // Move to next row (if any) and update the looping flag as needed.
        if (rs.next()) {
            // If more rows are available, then update counters and retrieve field values as needed.
            numTransactionRows++;
            nextTaxId = rs.getString(detailRow.vendorTaxNumber.index);
            nextPayeeId = rs.getString(detailRow.payeeId.index);
            vendorHeaderId = Integer.parseInt(nextPayeeId.substring(0, nextPayeeId.indexOf('-')));
            vendorDetailId = Integer.parseInt(nextPayeeId.substring(nextPayeeId.indexOf('-') + 1));
            // Check for changes to the tax ID between rows. The prior tax ID should be non-null at this point.
            taxIdChanged = StringUtils.isBlank(nextTaxId) || !taxIdP.value.equals(nextTaxId);
        } else {
            // If no more rows, then prepare to exit the loop and process any leftover data from the previous iterations.
            keepLooping = false;
            writeTabRecord = true;
        }
        // Automatically abort with an error if no tax ID (even an auto-generated one) could be found.
        if (StringUtils.isBlank(nextTaxId)) {
            throw new RuntimeException("Could not find tax ID for row with payee " + nextPayeeId);
        }
        // If necessary, check if a new tab record needs to be written.
        if (!writeTabRecord && taxIdChanged) {
            // Potentially write new tab record in response to a tax ID change.
            writeTabRecord = true;
        }
        // Do not write a tab record if no tax box amounts have been identified yet for the current tax ID.
        if (!foundAmount) {
            writeTabRecord = false;
        }
        // If needed, write a new tab record to the output file.
        if (writeTabRecord) {
            writeTabLineToFile(summary);
        }
    // END OF LOOP
    }
    LOG.info("Finished transaction row processing for 1099 tax reporting.");
}
Also used : TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow)

Example 4 with TransactionDetailRow

use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow in project cu-kfs by CU-CommunityApps.

the class TransactionRow1099Processor method getMinimumFields.

@Override
Set<TaxTableField> getMinimumFields(TaxFieldSource fieldSource, Transaction1099Summary summary) {
    Set<TaxTableField> minFields = new HashSet<TaxTableField>();
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    DerivedValuesRow derivedValues = summary.derivedValues;
    switch(fieldSource) {
        case BLANK:
            throw new IllegalArgumentException("Cannot find minimum fields for BLANK type");
        case STATIC:
            throw new IllegalArgumentException("Cannot find minimum fields for STATIC type");
        case DETAIL:
            minFields.addAll(Arrays.asList(detailRow.transactionDetailId, detailRow.documentNumber, detailRow.documentType, detailRow.documentTitle, detailRow.financialDocumentLineNumber, detailRow.finObjectCode, detailRow.netPaymentAmount, detailRow.vendorTaxNumber, detailRow.dvCheckStubText, detailRow.payeeId, detailRow.vendorName, detailRow.parentVendorName, detailRow.paymentDate, detailRow.paymentLine1Address, detailRow.chartCode, detailRow.accountNumber, detailRow.initiatorNetId, detailRow.paymentReasonCode));
            break;
        case PDP:
            // Leave Set empty.
            break;
        case DV:
            // Leave Set empty.
            break;
        case VENDOR:
            // Leave Set empty.
            break;
        case VENDOR_US_ADDRESS:
            // Leave Set empty.
            break;
        case VENDOR_FOREIGN_ADDRESS:
            // Leave Set empty.
            break;
        case VENDOR_ANY_ADDRESS:
            // Leave Set empty.
            break;
        case DERIVED:
            minFields.addAll(Arrays.asList(derivedValues.vendorEmailAddress, derivedValues.vendorAnyAddressLine1, derivedValues.vendorZipCodeNumOnly, derivedValues.ssn, derivedValues.tabSiteId, derivedValues.box1, derivedValues.box2, derivedValues.box3, derivedValues.box4, derivedValues.box5, derivedValues.box6, derivedValues.box7, derivedValues.box8, derivedValues.box10, derivedValues.box11, derivedValues.box12, derivedValues.box13, derivedValues.box14, derivedValues.box15a, derivedValues.box15b, derivedValues.box16, derivedValues.box18));
            break;
        default:
            throw new IllegalArgumentException("Invalid piece type");
    }
    return minFields;
}
Also used : DerivedValuesRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.DerivedValuesRow) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) HashSet(java.util.HashSet)

Example 5 with TransactionDetailRow

use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow in project cu-kfs by CU-CommunityApps.

the class TransactionRowDvBuilder method updateTransactionRowsFromWorkflowDocuments.

@Override
void updateTransactionRowsFromWorkflowDocuments(ResultSet rs, T summary) throws SQLException {
    TransactionDetailRow detailRow = summary.transactionDetailRow;
    Pattern nonPrintableCharsPattern = Pattern.compile("[^\\p{Graph}\\p{Space}]");
    String documentId;
    String initiatorPrincipalId;
    String initiatorPrincipalName;
    String paymentMethodCode;
    String vendorTaxNumber;
    String checkStubText;
    Matcher checkStubMatcher;
    java.sql.Date dateFinalized;
    Document document;
    DocumentStatus documentStatus = null;
    boolean processCurrentRow;
    boolean useDateFinalized;
    java.sql.Date startDate = summary.getStartDate();
    java.sql.Date endDate = summary.getEndDate();
    // Update or remove rows as needed.
    while (rs.next()) {
        // Only update DV-related rows.
        if (DisbursementVoucherConstants.DOCUMENT_TYPE_CODE.equals(rs.getString(detailRow.documentType.index))) {
            // Initialized minimal variables for current row.
            processCurrentRow = true;
            documentId = rs.getString(detailRow.documentNumber.index);
            initiatorPrincipalId = null;
            documentStatus = null;
            dateFinalized = null;
            useDateFinalized = false;
            // Retrieve document info.
            document = getWorkflowDocumentForTaxRow(documentId, summary);
            if (document != null) {
                initiatorPrincipalId = document.getInitiatorPrincipalId();
                documentStatus = document.getStatus();
                if (document.getDateFinalized() != null) {
                    dateFinalized = new java.sql.Date(document.getDateFinalized().getMillis());
                }
            }
            // Retrieve payment method, which is temporarily stored in the doc title field.
            paymentMethodCode = rs.getString(detailRow.documentTitle.index);
            // Depending on payment method, verify that the DV has indeed been finalized during the given time period.
            if (summary.foreignDraftCode.equals(paymentMethodCode) || summary.wireTransferCode.equals(paymentMethodCode)) {
                // If a Foreign Draft or Wire Transfer, check the doc finalization date and status.
                if (DocumentStatus.FINAL.equals(documentStatus) && dateFinalized != null && dateFinalized.compareTo(startDate) >= 0 && dateFinalized.compareTo(endDate) <= 0) {
                    // If finalized during the current reporting period, then increment counters accordingly and use finalize date as payment date.
                    useDateFinalized = true;
                    if (summary.foreignDraftCode.equals(paymentMethodCode)) {
                        numForeignDraftsSelected++;
                    } else if (summary.wireTransferCode.equals(paymentMethodCode)) {
                        numWireTransfersSelected++;
                    }
                } else {
                    // If not finalized or if in the wrong reporting period, then skip the current DV data row.
                    if (summary.foreignDraftCode.equals(paymentMethodCode)) {
                        numForeignDraftsIgnored++;
                    } else if (summary.wireTransferCode.equals(paymentMethodCode)) {
                        numWireTransfersIgnored++;
                    }
                    // Skip any further processing for the current row.
                    processCurrentRow = false;
                }
            }
            if (processCurrentRow) {
                // Finish initialization.
                vendorTaxNumber = rs.getString(detailRow.vendorTaxNumber.index);
                checkStubText = rs.getString(detailRow.dvCheckStubText.index);
                checkStubMatcher = nonPrintableCharsPattern.matcher((checkStubText != null) ? checkStubText : KRADConstants.EMPTY_STRING);
                // Check for null objects as needed, and get the initiator's principal name.
                initiatorPrincipalName = checkForEntityAndAccountAndOrgExistence(initiatorPrincipalId, rs.getString(detailRow.chartCode.index), rs.getString(detailRow.accountNumber.index), summary);
                // If vendor tax number is blank, then replace with a generated value accordingly.
                if (StringUtils.isBlank(vendorTaxNumber)) {
                    vendorTaxNumber = getReplacementVendorTaxNumber(rs.getString(detailRow.payeeId.index), summary);
                    rs.updateString(detailRow.vendorTaxNumber.index, vendorTaxNumber);
                }
                // Remove unprintable characters from the check stub text if necessary.
                if (checkStubMatcher.find()) {
                    checkStubText = checkStubMatcher.replaceAll(KRADConstants.EMPTY_STRING);
                    rs.updateString(detailRow.dvCheckStubText.index, checkStubText);
                    numDvCheckStubTextsAltered++;
                } else {
                    numDvCheckStubTextsNotAltered++;
                }
                // Do tax-type-specific updates.
                doTaxSpecificSecondPassRowSetup(rs, summary);
                // Update other fields as needed.
                if (StringUtils.isBlank(documentId)) {
                    rs.updateString(detailRow.documentNumber.index, CUTaxConstants.DOC_ID_ZERO);
                }
                rs.updateString(detailRow.documentTitle.index, (document != null && StringUtils.isNotBlank(document.getTitle())) ? document.getTitle() : CUTaxConstants.DOC_TITLE_IF_NOT_FOUND);
                rs.updateString(detailRow.initiatorNetId.index, StringUtils.isNotBlank(initiatorPrincipalName) ? initiatorPrincipalName : CUTaxConstants.NETID_IF_NOT_FOUND);
                if (useDateFinalized) {
                    rs.updateDate(detailRow.paymentDate.index, dateFinalized);
                }
                // Update the transaction row.
                rs.updateRow();
            } else {
                // If a Foreign Draft or Wire Transfer that wasn't finalized or was in the wrong reporting period, then delete the row.
                rs.deleteRow();
            }
        }
    }
}
Also used : DocumentStatus(org.kuali.rice.kew.api.document.DocumentStatus) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) TransactionDetailRow(edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow) Document(org.kuali.rice.kew.api.document.Document)

Aggregations

TransactionDetailRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.TransactionDetailRow)13 HashSet (java.util.HashSet)5 DerivedValuesRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.DerivedValuesRow)4 BigDecimal (java.math.BigDecimal)3 Document (org.kuali.rice.kew.api.document.Document)3 ArrayList (java.util.ArrayList)2 Pattern (java.util.regex.Pattern)2 DocumentStatus (org.kuali.rice.kew.api.document.DocumentStatus)2 DvSourceRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.DvSourceRow)1 PRNCSourceRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.PRNCSourceRow)1 PdpSourceRow (edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.PdpSourceRow)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Matcher (java.util.regex.Matcher)1 EncryptionService (org.kuali.rice.core.api.encryption.EncryptionService)1