Search in sources :

Example 1 with ScrubberProcessTransactionError

use of org.kuali.kfs.gl.businessobject.ScrubberProcessTransactionError 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;
}
Also used : Message(org.kuali.kfs.sys.Message) HashMap(java.util.HashMap) IOException(java.io.IOException) InvalidFlexibleOffsetException(org.kuali.kfs.sys.exception.InvalidFlexibleOffsetException) ScrubberStep(org.kuali.kfs.gl.batch.ScrubberStep) Transaction(org.kuali.kfs.gl.businessobject.Transaction) OffsetDefinition(org.kuali.kfs.coa.businessobject.OffsetDefinition) List(java.util.List) SystemOptions(org.kuali.kfs.sys.businessobject.SystemOptions) OriginEntryFull(org.kuali.kfs.gl.businessobject.OriginEntryFull) ScrubberProcessTransactionError(org.kuali.kfs.gl.businessobject.ScrubberProcessTransactionError) A21SubAccount(org.kuali.kfs.coa.businessobject.A21SubAccount)

Example 2 with ScrubberProcessTransactionError

use of org.kuali.kfs.gl.businessobject.ScrubberProcessTransactionError in project cu-kfs by CU-CommunityApps.

the class CuScrubberProcessImpl method setupEntryWithPotentialContinuation.

/**
 * Helper method for configuring the chart, account and sub-account on the cost-share-source-account entry,
 * using the cost share account's continuation account or descendant (up to a depth of 10) in the
 * event of a closed cost share account.
 *
 * @param costShareSourceAccountEntry The origin entry to configure.
 * @param scrubbedEntryA21SubAccount The A21 sub-account from the original scrubbed origin entry.
 * @return A ScrubberProcessTransactionError if a valid cost share or continuation account could not be found, null otherwise.
 */
protected ScrubberProcessTransactionError setupEntryWithPotentialContinuation(OriginEntryFull costShareSourceAccountEntry, A21SubAccount scrubbedEntryA21SubAccount) {
    Account costShareAccount = accountingCycleCachingService.getAccount(scrubbedEntryA21SubAccount.getCostShareChartOfAccountCode(), scrubbedEntryA21SubAccount.getCostShareSourceAccountNumber());
    if (ObjectUtils.isNotNull(costShareAccount) && costShareAccount.isClosed()) {
        // Cost share source account is closed; check for a valid continuation account.
        Account continuationAccount = costShareAccount;
        for (int i = 0; i < CONTINUATION_ACCOUNT_DEPTH_LIMIT && ObjectUtils.isNotNull(continuationAccount) && continuationAccount.isClosed(); i++) {
            continuationAccount = accountingCycleCachingService.getAccount(continuationAccount.getContinuationFinChrtOfAcctCd(), continuationAccount.getContinuationAccountNumber());
        }
        if (ObjectUtils.isNull(continuationAccount) || costShareAccount == continuationAccount || continuationAccount.isClosed()) {
            // Could not find a valid Cost Share continuation account; return an error.
            return new ScrubberProcessTransactionError(costShareSourceAccountEntry, new Message(MessageFormat.format(configurationService.getPropertyValueAsString(CUKFSKeyConstants.ERROR_CSACCOUNT_CONTINUATION_ACCOUNT_CLOSED), scrubbedEntryA21SubAccount.getCostShareChartOfAccountCode(), scrubbedEntryA21SubAccount.getCostShareSourceAccountNumber()), Message.TYPE_FATAL));
        } else {
            // Found a valid Cost Share continuation account, so use it.
            LOG.warn(MessageFormat.format(configurationService.getPropertyValueAsString(CUKFSKeyConstants.WARNING_CSACCOUNT_CONTINUATION_ACCOUNT_USED), scrubbedEntryA21SubAccount.getCostShareChartOfAccountCode(), scrubbedEntryA21SubAccount.getCostShareSourceAccountNumber(), continuationAccount.getChartOfAccountsCode(), continuationAccount.getAccountNumber()));
            costShareSourceAccountEntry.setChartOfAccountsCode(continuationAccount.getChartOfAccountsCode());
            costShareSourceAccountEntry.setAccountNumber(continuationAccount.getAccountNumber());
            costShareSourceAccountEntry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
        }
    } else {
        // Cost Share source account is still open, so use it.
        costShareSourceAccountEntry.setChartOfAccountsCode(scrubbedEntryA21SubAccount.getCostShareChartOfAccountCode());
        costShareSourceAccountEntry.setAccountNumber(scrubbedEntryA21SubAccount.getCostShareSourceAccountNumber());
        costShareSourceAccountEntry.setSubAccountNumber(scrubbedEntryA21SubAccount.getCostShareSourceSubAccountNumber());
    }
    return null;
}
Also used : Account(org.kuali.kfs.coa.businessobject.Account) A21SubAccount(org.kuali.kfs.coa.businessobject.A21SubAccount) Message(org.kuali.kfs.sys.Message) ScrubberProcessTransactionError(org.kuali.kfs.gl.businessobject.ScrubberProcessTransactionError)

Aggregations

A21SubAccount (org.kuali.kfs.coa.businessobject.A21SubAccount)2 ScrubberProcessTransactionError (org.kuali.kfs.gl.businessobject.ScrubberProcessTransactionError)2 Message (org.kuali.kfs.sys.Message)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Account (org.kuali.kfs.coa.businessobject.Account)1 OffsetDefinition (org.kuali.kfs.coa.businessobject.OffsetDefinition)1 ScrubberStep (org.kuali.kfs.gl.batch.ScrubberStep)1 OriginEntryFull (org.kuali.kfs.gl.businessobject.OriginEntryFull)1 Transaction (org.kuali.kfs.gl.businessobject.Transaction)1 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)1 InvalidFlexibleOffsetException (org.kuali.kfs.sys.exception.InvalidFlexibleOffsetException)1