use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.DvSourceRow in project cu-kfs by CU-CommunityApps.
the class TransactionRowDvBuilder method getSqlForSelect.
@Override
String getSqlForSelect(T summary) {
StringBuilder fullSql = new StringBuilder(GETTER_BUILDER_SIZE);
DvSourceRow dvRow = summary.dvRow;
// Build the query.
TaxSqlUtils.appendQuery(fullSql, SqlText.SELECT, dvRow.orderedFields, SqlText.FROM, dvRow.tables, SqlText.WHERE, SqlText.PAREN_OPEN, SqlText.PAREN_OPEN, // If not a foreign draft or wire transfer, make sure the DV was paid during the given time period.
dvRow.paidDate, SqlText.IS_NOT_NULL, SqlText.AND, dvRow.paidDate, SqlText.BETWEEN, SqlText.PARAMETER, SqlText.AND, SqlText.PARAMETER, SqlText.AND, dvRow.universityDate, SqlText.EQUALS, dvRow.paidDate, SqlText.PAREN_CLOSE, SqlText.OR, SqlText.PAREN_OPEN, // If a foreign draft or wire transfer, make sure the DV was finalized during the given time period.
dvRow.documentDisbVchrPaymentMethodCode, SqlText.IN, "('F','W')", SqlText.AND, dvRow.paidDate, SqlText.IS_NULL, SqlText.AND, TaxSqlUtils.getInListCriteria(dvRow.dvDocumentNumber, finalizedDvDocuments.size(), true, true), SqlText.AND, dvRow.universityDate, SqlText.EQUALS, SqlText.PARAMETER, SqlText.PAREN_CLOSE, SqlText.PAREN_CLOSE, // Add doc number criteria.
SqlText.AND, dvRow.payeeDetailDocumentNumber, SqlText.EQUALS, dvRow.nraDocumentNumber, SqlText.AND, dvRow.payeeDetailDocumentNumber, SqlText.EQUALS, dvRow.accountingLineDocumentNumber, SqlText.AND, dvRow.payeeDetailDocumentNumber, SqlText.EQUALS, dvRow.dvDocumentNumber, // Add various IS NOT NULL criteria.
SqlText.AND, dvRow.payeeDetailDocumentNumber, SqlText.IS_NOT_NULL, SqlText.AND, dvRow.accountingLineDocumentNumber, SqlText.IS_NOT_NULL, SqlText.AND, dvRow.accountingLineSequenceNumber, SqlText.IS_NOT_NULL, SqlText.AND, dvRow.financialDocumentLineTypeCode, SqlText.IS_NOT_NULL, // And vendor criteria and tax-type-specific criteria.
SqlText.AND, dvRow.disbursementVoucherPayeeTypeCode, SqlText.EQUALS, "'V'", SqlText.AND, TaxSqlUtils.getPayeeIdToVendorHeaderIdCriteria(dvRow.disbVchrPayeeIdNumber, dvRow.vendorHeaderGeneratedId), getTaxTypeSpecificConditionForSelect(summary), SqlText.AND, dvRow.vendorForeignInd, SqlText.EQUALS, SqlText.PARAMETER, // Build the ORDER BY clause.
SqlText.ORDER_BY, new Object[][] { { dvRow.vendorTaxNumber }, { dvRow.extractDate }, { dvRow.dvDocumentNumber }, { dvRow.accountingLineSequenceNumber } });
// Log and return the full query.
if (LOG.isDebugEnabled()) {
LOG.debug("Final DV selection query: " + fullSql.toString());
}
return fullSql.toString();
}
use of edu.cornell.kfs.tax.dataaccess.impl.TaxTableRow.DvSourceRow in project cu-kfs by CU-CommunityApps.
the class TransactionRowDvBuilder method buildTransactionRows.
@Override
void buildTransactionRows(ResultSet rs, PreparedStatement insertStatement, T summary) throws SQLException {
DvSourceRow dvRow = summary.dvRow;
TransactionDetailRow detailRow = summary.transactionDetailRow;
int offset = detailRow.insertOffset;
Set<String> docIds = new HashSet<String>();
String documentId;
String financialObjectCode;
BigDecimal netPaymentAmount;
int currentBatchSize = 0;
while (rs.next()) {
// Initialize variables for current row.
documentId = rs.getString(dvRow.payeeDetailDocumentNumber.index);
financialObjectCode = rs.getString(dvRow.financialObjectCode.index);
netPaymentAmount = rs.getBigDecimal(dvRow.amount.index);
// Add doc ID to map if non-blank.
if (StringUtils.isNotBlank(documentId)) {
docIds.add(documentId);
}
// If net payment amount is null, then set to zero. Otherwise, negate it if it's a debit amount.
if (netPaymentAmount == null) {
netPaymentAmount = summary.zeroAmount;
} else if (KFSConstants.GL_DEBIT_CODE.equals(rs.getString(dvRow.debitCreditCode.index))) {
netPaymentAmount = netPaymentAmount.negate();
}
// Perform extra 1099-specific or 1042S-specific setup as needed.
doTaxSpecificRowSetup(rs, insertStatement, financialObjectCode, summary);
/*
* Prepare to insert another transaction detail row.
*
* NOTE: We temporarily store the payment method code in the doc title slot,
* to be processed and replaced on the next pass.
*
* NOTE: It is expected that subclasses use the "doTaxSpecificRowSetup"
* method to populate the following prepared statement arguments:
*
* INCOME_CODE
* INCOME_CODE_SUB_TYPE
* FORM_1099_BOX
* FORM_1099_OVERRIDDEN_BOX
* FORM_1042S_BOX
* FORM_1042S_OVERRIDDEN_BOX
*
* In addition, it is expected that updateTransactionRowsFromWorkflowDocuments()
* will update the following fields after they've been set by this method:
*
* FDOC_NBR (if null, in which case it should be set to "0" or some other constant)
* DOC_TITLE
* INITIATOR_NETID
* PMT_DT (if the row represents a Foreign Draft or Wire Transfer)
* VENDOR_TAX_NBR (if null, in which case it should be set to an auto-generated value)
* DV_CHK_STUB_TXT (if it contains non-printable characters, in which case they should be removed)
*/
insertStatement.setInt(detailRow.reportYear.index - offset, summary.reportYear);
insertStatement.setString(detailRow.documentNumber.index - offset, StringUtils.isNotBlank(documentId) ? documentId : null);
insertStatement.setString(detailRow.documentType.index - offset, DisbursementVoucherConstants.DOCUMENT_TYPE_CODE);
insertStatement.setInt(detailRow.financialDocumentLineNumber.index - offset, rs.getInt(dvRow.accountingLineSequenceNumber.index));
insertStatement.setString(detailRow.finObjectCode.index - offset, financialObjectCode);
insertStatement.setBigDecimal(detailRow.netPaymentAmount.index - offset, netPaymentAmount);
insertStatement.setString(detailRow.documentTitle.index - offset, rs.getString(dvRow.documentDisbVchrPaymentMethodCode.index));
insertStatement.setString(detailRow.vendorTaxNumber.index - offset, rs.getString(dvRow.vendorTaxNumber.index));
insertStatement.setString(detailRow.dvCheckStubText.index - offset, rs.getString(dvRow.disbVchrCheckStubText.index));
insertStatement.setString(detailRow.payeeId.index - offset, rs.getString(dvRow.disbVchrPayeeIdNumber.index));
insertStatement.setString(detailRow.vendorTypeCode.index - offset, rs.getString(dvRow.vendorTypeCode.index));
insertStatement.setString(detailRow.vendorOwnershipCode.index - offset, rs.getString(dvRow.vendorOwnershipCode.index));
insertStatement.setString(detailRow.vendorOwnershipCategoryCode.index - offset, rs.getString(dvRow.vendorOwnershipCategoryCode.index));
insertStatement.setString(detailRow.vendorForeignIndicator.index - offset, rs.getString(dvRow.vendorForeignInd.index));
insertStatement.setString(detailRow.nraPaymentIndicator.index - offset, rs.getString(dvRow.disbVchrAlienPaymentCode.index));
insertStatement.setDate(detailRow.paymentDate.index - offset, rs.getDate(dvRow.paidDate.index));
insertStatement.setString(detailRow.paymentPayeeName.index - offset, rs.getString(dvRow.disbVchrPayeePersonName.index));
insertStatement.setString(detailRow.incomeClassCode.index - offset, rs.getString(dvRow.incomeClassCode.index));
insertStatement.setString(detailRow.incomeTaxTreatyExemptIndicator.index - offset, rs.getString(dvRow.incomeTaxTreatyExemptCode.index));
insertStatement.setString(detailRow.foreignSourceIncomeIndicator.index - offset, rs.getString(dvRow.foreignSourceIncomeCode.index));
insertStatement.setBigDecimal(detailRow.federalIncomeTaxPercent.index - offset, rs.getBigDecimal(dvRow.federalIncomeTaxPercent.index));
insertStatement.setString(detailRow.paymentDescription.index - offset, rs.getString(dvRow.financialDocumentLineDescription.index));
insertStatement.setString(detailRow.paymentLine1Address.index - offset, rs.getString(dvRow.disbVchrPayeeLine1Addr.index));
insertStatement.setString(detailRow.paymentCountryName.index - offset, rs.getString(dvRow.disbVchrPayeeCountryCode.index));
insertStatement.setString(detailRow.chartCode.index - offset, rs.getString(dvRow.chartOfAccountsCode.index));
insertStatement.setString(detailRow.accountNumber.index - offset, rs.getString(dvRow.accountNumber.index));
insertStatement.setString(detailRow.paymentReasonCode.index - offset, rs.getString(dvRow.disbVchrPaymentReasonCode.index));
insertNullsForTransactionRow(insertStatement, detailRow, offset);
// Add to batch, and execute batch if needed.
insertStatement.addBatch();
currentBatchSize++;
if (currentBatchSize == CUTaxConstants.INSERT_BATCH_SIZE) {
insertStatement.executeBatch();
currentBatchSize = 0;
}
}
// Execute any remaining insertions that were not included in a prior batch.
if (currentBatchSize > 0) {
insertStatement.executeBatch();
}
// Prepare collected docIds for next processing iteration.
prepareForSecondPass(summary, docIds);
}
Aggregations