use of org.kuali.kfs.gl.businessobject.Transaction in project cu-kfs by CU-CommunityApps.
the class CuScrubberProcessImpl method generateCostShareEntries.
/**
* Overridden to update cost share source account entries so that they will post to the
* continuation account if the cost share account is closed.
*
* @see org.kuali.kfs.gl.batch.service.impl.ScrubberProcessImpl#generateCostShareEntries(
* org.kuali.kfs.gl.businessobject.OriginEntryInformation, org.kuali.kfs.gl.service.ScrubberReportData)
*/
@Override
protected ScrubberProcessTransactionError generateCostShareEntries(OriginEntryInformation scrubbedEntry, ScrubberReportData scrubberReport) {
// 3000-COST-SHARE to 3100-READ-OFSD in the cobol Generate Cost Share Entries
LOG.debug("generateCostShareEntries() started");
try {
OriginEntryFull costShareEntry = OriginEntryFull.copyFromOriginEntryable(scrubbedEntry);
SystemOptions scrubbedEntryOption = accountingCycleCachingService.getSystemOptions(scrubbedEntry.getUniversityFiscalYear());
A21SubAccount scrubbedEntryA21SubAccount = accountingCycleCachingService.getA21SubAccount(scrubbedEntry.getChartOfAccountsCode(), scrubbedEntry.getAccountNumber(), scrubbedEntry.getSubAccountNumber());
costShareEntry.setFinancialObjectCode(parameterService.getParameterValueAsString(ScrubberStep.class, GeneralLedgerConstants.GlScrubberGroupParameters.COST_SHARE_OBJECT_CODE_PARM_NM));
costShareEntry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
costShareEntry.setFinancialObjectTypeCode(scrubbedEntryOption.getFinancialObjectTypeTransferExpenseCd());
costShareEntry.setTransactionLedgerEntrySequenceNumber(new Integer(0));
StringBuffer description = new StringBuffer();
description.append(costShareDescription);
description.append(" ").append(scrubbedEntry.getAccountNumber());
description.append(offsetString);
costShareEntry.setTransactionLedgerEntryDescription(description.toString());
costShareEntry.setTransactionLedgerEntryAmount(scrubCostShareAmount);
if (scrubCostShareAmount.isPositive()) {
costShareEntry.setTransactionDebitCreditCode(KFSConstants.GL_DEBIT_CODE);
} else {
costShareEntry.setTransactionDebitCreditCode(KFSConstants.GL_CREDIT_CODE);
costShareEntry.setTransactionLedgerEntryAmount(scrubCostShareAmount.negated());
}
costShareEntry.setTransactionDate(runDate);
costShareEntry.setOrganizationDocumentNumber(null);
costShareEntry.setProjectCode(KFSConstants.getDashProjectCode());
costShareEntry.setOrganizationReferenceId(null);
costShareEntry.setReferenceFinancialDocumentTypeCode(null);
costShareEntry.setReferenceFinancialSystemOriginationCode(null);
costShareEntry.setReferenceFinancialDocumentNumber(null);
costShareEntry.setFinancialDocumentReversalDate(null);
costShareEntry.setTransactionEncumbranceUpdateCode(null);
createOutputEntry(costShareEntry, OUTPUT_GLE_FILE_ps);
scrubberReport.incrementCostShareEntryGenerated();
OriginEntryFull costShareOffsetEntry = new OriginEntryFull(costShareEntry);
costShareOffsetEntry.setTransactionLedgerEntryDescription(getOffsetMessage());
OffsetDefinition offsetDefinition = accountingCycleCachingService.getOffsetDefinition(scrubbedEntry.getUniversityFiscalYear(), scrubbedEntry.getChartOfAccountsCode(), KFSConstants.TRANSFER_FUNDS, scrubbedEntry.getFinancialBalanceTypeCode());
if (offsetDefinition != null) {
if (offsetDefinition.getFinancialObject() == null) {
StringBuffer objectCodeKey = new StringBuffer();
objectCodeKey.append(offsetDefinition.getUniversityFiscalYear());
objectCodeKey.append("-").append(offsetDefinition.getChartOfAccountsCode());
objectCodeKey.append("-").append(offsetDefinition.getFinancialObjectCode());
Message m = new Message(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_OFFSET_DEFINITION_OBJECT_CODE_NOT_FOUND) + " (" + objectCodeKey.toString() + ")", Message.TYPE_FATAL);
LOG.debug("generateCostShareEntries() Error 1 object not found");
return new ScrubberProcessTransactionError(costShareEntry, m);
}
costShareOffsetEntry.setFinancialObjectCode(offsetDefinition.getFinancialObjectCode());
costShareOffsetEntry.setFinancialObject(offsetDefinition.getFinancialObject());
costShareOffsetEntry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
} else {
Map<Transaction, List<Message>> errors = new HashMap<Transaction, List<Message>>();
StringBuffer offsetKey = new StringBuffer("cost share transfer ");
offsetKey.append(scrubbedEntry.getUniversityFiscalYear());
offsetKey.append("-");
offsetKey.append(scrubbedEntry.getChartOfAccountsCode());
offsetKey.append("-TF-");
offsetKey.append(scrubbedEntry.getFinancialBalanceTypeCode());
Message m = new Message(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_OFFSET_DEFINITION_NOT_FOUND) + " (" + offsetKey.toString() + ")", Message.TYPE_FATAL);
LOG.debug("generateCostShareEntries() Error 2 offset not found");
return new ScrubberProcessTransactionError(costShareEntry, m);
}
costShareOffsetEntry.setFinancialObjectTypeCode(offsetDefinition.getFinancialObject().getFinancialObjectTypeCode());
if (costShareEntry.isCredit()) {
costShareOffsetEntry.setTransactionDebitCreditCode(KFSConstants.GL_DEBIT_CODE);
} else {
costShareOffsetEntry.setTransactionDebitCreditCode(KFSConstants.GL_CREDIT_CODE);
}
try {
flexibleOffsetAccountService.updateOffset(costShareOffsetEntry);
} catch (InvalidFlexibleOffsetException e) {
Message m = new Message(e.getMessage(), Message.TYPE_FATAL);
if (LOG.isDebugEnabled()) {
LOG.debug("generateCostShareEntries() Cost Share Transfer Flexible Offset Error: " + e.getMessage());
}
return new ScrubberProcessTransactionError(costShareEntry, m);
}
createOutputEntry(costShareOffsetEntry, OUTPUT_GLE_FILE_ps);
scrubberReport.incrementCostShareEntryGenerated();
OriginEntryFull costShareSourceAccountEntry = new OriginEntryFull(costShareEntry);
description = new StringBuffer();
description.append(costShareDescription);
description.append(" ").append(scrubbedEntry.getAccountNumber());
description.append(offsetString);
costShareSourceAccountEntry.setTransactionLedgerEntryDescription(description.toString());
// CU Customization: If Cost Share account is closed, use its continuation account instead.
ScrubberProcessTransactionError continuationError = setupEntryWithPotentialContinuation(costShareSourceAccountEntry, scrubbedEntryA21SubAccount);
if (continuationError != null) {
return continuationError;
}
setCostShareObjectCode(costShareSourceAccountEntry, scrubbedEntry);
if (StringHelper.isNullOrEmpty(costShareSourceAccountEntry.getSubAccountNumber())) {
costShareSourceAccountEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
}
costShareSourceAccountEntry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
costShareSourceAccountEntry.setFinancialObjectTypeCode(scrubbedEntryOption.getFinancialObjectTypeTransferExpenseCd());
costShareSourceAccountEntry.setTransactionLedgerEntrySequenceNumber(new Integer(0));
costShareSourceAccountEntry.setTransactionLedgerEntryAmount(scrubCostShareAmount);
if (scrubCostShareAmount.isPositive()) {
costShareSourceAccountEntry.setTransactionDebitCreditCode(KFSConstants.GL_CREDIT_CODE);
} else {
costShareSourceAccountEntry.setTransactionDebitCreditCode(KFSConstants.GL_DEBIT_CODE);
costShareSourceAccountEntry.setTransactionLedgerEntryAmount(scrubCostShareAmount.negated());
}
costShareSourceAccountEntry.setTransactionDate(runDate);
costShareSourceAccountEntry.setOrganizationDocumentNumber(null);
costShareSourceAccountEntry.setProjectCode(KFSConstants.getDashProjectCode());
costShareSourceAccountEntry.setOrganizationReferenceId(null);
costShareSourceAccountEntry.setReferenceFinancialDocumentTypeCode(null);
costShareSourceAccountEntry.setReferenceFinancialSystemOriginationCode(null);
costShareSourceAccountEntry.setReferenceFinancialDocumentNumber(null);
costShareSourceAccountEntry.setFinancialDocumentReversalDate(null);
costShareSourceAccountEntry.setTransactionEncumbranceUpdateCode(null);
createOutputEntry(costShareSourceAccountEntry, OUTPUT_GLE_FILE_ps);
scrubberReport.incrementCostShareEntryGenerated();
OriginEntryFull costShareSourceAccountOffsetEntry = new OriginEntryFull(costShareSourceAccountEntry);
costShareSourceAccountOffsetEntry.setTransactionLedgerEntryDescription(getOffsetMessage());
// Lookup the new offset definition.
offsetDefinition = accountingCycleCachingService.getOffsetDefinition(scrubbedEntry.getUniversityFiscalYear(), scrubbedEntry.getChartOfAccountsCode(), KFSConstants.TRANSFER_FUNDS, scrubbedEntry.getFinancialBalanceTypeCode());
if (offsetDefinition != null) {
if (offsetDefinition.getFinancialObject() == null) {
Map<Transaction, List<Message>> errors = new HashMap<Transaction, List<Message>>();
StringBuffer objectCodeKey = new StringBuffer();
objectCodeKey.append(costShareEntry.getUniversityFiscalYear());
objectCodeKey.append("-").append(scrubbedEntry.getChartOfAccountsCode());
objectCodeKey.append("-").append(scrubbedEntry.getFinancialObjectCode());
Message m = new Message(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_OFFSET_DEFINITION_OBJECT_CODE_NOT_FOUND) + " (" + objectCodeKey.toString() + ")", Message.TYPE_FATAL);
LOG.debug("generateCostShareEntries() Error 3 object not found");
return new ScrubberProcessTransactionError(costShareSourceAccountEntry, m);
}
costShareSourceAccountOffsetEntry.setFinancialObjectCode(offsetDefinition.getFinancialObjectCode());
costShareSourceAccountOffsetEntry.setFinancialObject(offsetDefinition.getFinancialObject());
costShareSourceAccountOffsetEntry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
} else {
Map<Transaction, List<Message>> errors = new HashMap<Transaction, List<Message>>();
StringBuffer offsetKey = new StringBuffer("cost share transfer source ");
offsetKey.append(scrubbedEntry.getUniversityFiscalYear());
offsetKey.append("-");
offsetKey.append(scrubbedEntry.getChartOfAccountsCode());
offsetKey.append("-TF-");
offsetKey.append(scrubbedEntry.getFinancialBalanceTypeCode());
Message m = new Message(configurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_OFFSET_DEFINITION_NOT_FOUND) + " (" + offsetKey.toString() + ")", Message.TYPE_FATAL);
LOG.debug("generateCostShareEntries() Error 4 offset not found");
return new ScrubberProcessTransactionError(costShareSourceAccountEntry, m);
}
costShareSourceAccountOffsetEntry.setFinancialObjectTypeCode(offsetDefinition.getFinancialObject().getFinancialObjectTypeCode());
if (scrubbedEntry.isCredit()) {
costShareSourceAccountOffsetEntry.setTransactionDebitCreditCode(KFSConstants.GL_DEBIT_CODE);
} else {
costShareSourceAccountOffsetEntry.setTransactionDebitCreditCode(KFSConstants.GL_CREDIT_CODE);
}
try {
flexibleOffsetAccountService.updateOffset(costShareSourceAccountOffsetEntry);
} catch (InvalidFlexibleOffsetException e) {
Message m = new Message(e.getMessage(), Message.TYPE_FATAL);
if (LOG.isDebugEnabled()) {
LOG.debug("generateCostShareEntries() Cost Share Transfer Account Flexible Offset Error: " + e.getMessage());
}
return new ScrubberProcessTransactionError(costShareEntry, m);
}
createOutputEntry(costShareSourceAccountOffsetEntry, OUTPUT_GLE_FILE_ps);
scrubberReport.incrementCostShareEntryGenerated();
scrubCostShareAmount = KualiDecimal.ZERO;
} catch (IOException ioe) {
LOG.error("generateCostShareEntries() Stopped: " + ioe.getMessage());
throw new RuntimeException("generateCostShareEntries() Stopped: " + ioe.getMessage(), ioe);
}
LOG.debug("generateCostShareEntries() successful");
return null;
}
Aggregations