Search in sources :

Example 26 with GeneralLedgerPendingEntry

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry in project cu-kfs by CU-CommunityApps.

the class CUPaymentMethodGeneralLedgerPendingEntryServiceImpl method generateFeeAssessmentEntries.

/**
 * Generates the GL entries to charge the department for the foreign draft and credit the Wire Charge
 * Fee Account as specified by system parameters.
 *
 * @param document Document into which to add the generated GL Entries.
 */
protected boolean generateFeeAssessmentEntries(PaymentMethod pm, AccountingDocument document, GeneralLedgerPendingEntry templatePendingEntry, GeneralLedgerPendingEntrySequenceHelper sequenceHelper, boolean reverseEntries) {
    LOG.debug("generateForeignDraftChargeEntries started");
    PaymentMethodChart pmc = pm.getPaymentMethodChartInfo(templatePendingEntry.getChartOfAccountsCode(), new java.sql.Date(document.getDocumentHeader().getWorkflowDocument().getDateCreated().getMillis()));
    if (pmc == null) {
        LOG.warn("No Applicable PaymentMethodChart found for chart: " + templatePendingEntry.getChartOfAccountsCode() + " and date: " + document.getDocumentHeader().getWorkflowDocument().getDateCreated());
        return false;
    }
    // Get all the parameters which control these entries
    String feeIncomeChartCode = pmc.getFeeIncomeChartOfAccountsCode();
    String feeIncomeAccountNumber = pmc.getFeeIncomeAccountNumber();
    String feeExpenseObjectCode = pmc.getFeeExpenseFinancialObjectCode();
    String feeIncomeObjectCode = pmc.getFeeIncomeFinancialObjectCode();
    KualiDecimal feeAmount = pmc.getFeeAmount();
    // skip creation if the fee has been set to zero
    if (!KualiDecimal.ZERO.equals(feeAmount)) {
        // grab the explicit entry for the first accounting line and adjust for the foreign draft fee
        GeneralLedgerPendingEntry chargeEntry = new GeneralLedgerPendingEntry(document.getGeneralLedgerPendingEntry(0));
        chargeEntry.setTransactionLedgerEntrySequenceNumber(sequenceHelper.getSequenceCounter());
        // change the object code (expense to the department)
        chargeEntry.setFinancialObjectCode(feeExpenseObjectCode);
        chargeEntry.setFinancialSubObjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialSubObjectCode());
        chargeEntry.setTransactionLedgerEntryDescription(StringUtils.left("Automatic debit for " + pm.getPaymentMethodName() + " fee", 40));
        chargeEntry.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
        // retrieve object type
        ObjectCode objectCode = objectCodeService.getByPrimaryIdForCurrentYear(chargeEntry.getChartOfAccountsCode(), chargeEntry.getFinancialObjectCode());
        if (objectCode == null) {
            LOG.fatal("Specified offset object code: " + chargeEntry.getChartOfAccountsCode() + "-" + chargeEntry.getFinancialObjectCode() + " does not exist - failed to generate foreign draft fee entries", new RuntimeException());
            return false;
        }
        chargeEntry.setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());
        // Set the amount from the parameter
        chargeEntry.setTransactionLedgerEntryAmount(feeAmount);
        chargeEntry.setTransactionDebitCreditCode(reverseEntries ? GL_CREDIT_CODE : GL_DEBIT_CODE);
        document.addPendingEntry(chargeEntry);
        sequenceHelper.increment();
        // handle the offset entry
        GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(chargeEntry);
        generalLedgerPendingEntryService.populateOffsetGeneralLedgerPendingEntry(document.getPostingYear(), chargeEntry, sequenceHelper, offsetEntry);
        document.addPendingEntry(offsetEntry);
        sequenceHelper.increment();
        // Now, create the income entry in the AP Foreign draft fee account
        GeneralLedgerPendingEntry feeIncomeEntry = new GeneralLedgerPendingEntry(document.getGeneralLedgerPendingEntry(0));
        feeIncomeEntry.setTransactionLedgerEntrySequenceNumber(sequenceHelper.getSequenceCounter());
        feeIncomeEntry.setChartOfAccountsCode(feeIncomeChartCode);
        feeIncomeEntry.setAccountNumber(feeIncomeAccountNumber);
        feeIncomeEntry.setFinancialObjectCode(feeIncomeObjectCode);
        feeIncomeEntry.setFinancialSubObjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialSubObjectCode());
        feeIncomeEntry.setSubAccountNumber(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankSubAccountNumber());
        feeIncomeEntry.setProjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankProjectCode());
        // retrieve object type
        objectCode = objectCodeService.getByPrimaryIdForCurrentYear(feeIncomeChartCode, feeIncomeObjectCode);
        if (objectCode == null) {
            LOG.fatal("Specified income object code: " + feeIncomeChartCode + "-" + feeIncomeObjectCode + " does not exist - failed to generate foreign draft income entries", new RuntimeException());
            return false;
        }
        feeIncomeEntry.setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());
        feeIncomeEntry.setTransactionLedgerEntryAmount(feeAmount);
        feeIncomeEntry.setTransactionDebitCreditCode(KFSConstants.GL_CREDIT_CODE);
        feeIncomeEntry.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
        document.addPendingEntry(feeIncomeEntry);
        sequenceHelper.increment();
        // create the offset entry
        offsetEntry = new GeneralLedgerPendingEntry(feeIncomeEntry);
        generalLedgerPendingEntryService.populateOffsetGeneralLedgerPendingEntry(document.getPostingYear(), feeIncomeEntry, sequenceHelper, offsetEntry);
        document.addPendingEntry(offsetEntry);
        sequenceHelper.increment();
    }
    return true;
}
Also used : PaymentMethodChart(edu.cornell.kfs.fp.businessobject.PaymentMethodChart) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) KualiDecimal(org.kuali.kfs.core.api.util.type.KualiDecimal) ObjectCode(org.kuali.kfs.coa.businessobject.ObjectCode)

Example 27 with GeneralLedgerPendingEntry

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry in project cu-kfs by CU-CommunityApps.

the class CuPendingTransactionServiceImpl method generateDisbursementVoucherReversalEntries.

/**
 * Generates the reversal entries for the given input DisbursementVoucherDocument.
 *
 * @param doc
 *            the DisbursementVoucherDocument for which we generate the reversal entries
 * @param sequenceHelper
 */
protected void generateDisbursementVoucherReversalEntries(DisbursementVoucherDocument doc, GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
    // generate all the pending entries for the document
    SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(doc);
    // for each pending entry, opposite-ify it and reattach it to the document
    List<GeneralLedgerPendingEntry> glpes = doc.getGeneralLedgerPendingEntries();
    if (glpes != null && glpes.size() > 0) {
        for (GeneralLedgerPendingEntry glpe : glpes) {
            if (KFSConstants.GL_CREDIT_CODE.equalsIgnoreCase(glpe.getTransactionDebitCreditCode())) {
                glpe.setTransactionDebitCreditCode(KFSConstants.GL_DEBIT_CODE);
            } else if (KFSConstants.GL_DEBIT_CODE.equalsIgnoreCase(glpe.getTransactionDebitCreditCode())) {
                glpe.setTransactionDebitCreditCode(KFSConstants.GL_CREDIT_CODE);
            }
            glpe.setTransactionLedgerEntrySequenceNumber(sequenceHelper.getSequenceCounter());
            sequenceHelper.increment();
            Date transactionTimestamp = new Date(getDateTimeService().getCurrentDate().getTime());
            AccountingPeriod fiscalPeriod = getAccountingPeriodService().getByDate(new java.sql.Date(transactionTimestamp.getTime()));
            glpe.setFinancialDocumentApprovedCode(KFSConstants.PENDING_ENTRY_APPROVED_STATUS_CODE.APPROVED);
            glpe.setUniversityFiscalYear(fiscalPeriod.getUniversityFiscalYear());
            glpe.setUniversityFiscalPeriodCode(fiscalPeriod.getUniversityFiscalPeriodCode());
            getBusinessObjectService().save(glpe);
        }
    }
}
Also used : GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod) GeneralLedgerPendingEntryService(org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService) Date(java.sql.Date) Date(java.sql.Date)

Example 28 with GeneralLedgerPendingEntry

use of org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry in project cu-kfs by CU-CommunityApps.

the class DisbursementVoucherDocument method getPendingLedgerEntriesForSufficientFundsChecking.

@Override
public List<GeneralLedgerPendingEntry> getPendingLedgerEntriesForSufficientFundsChecking() {
    List<GeneralLedgerPendingEntry> ples = new ArrayList<>();
    FlexibleOffsetAccountService flexibleOffsetAccountService = SpringContext.getBean(FlexibleOffsetAccountService.class);
    ObjectTypeService objectTypeService = SpringContext.getBean(ObjectTypeService.class);
    for (GeneralLedgerPendingEntry ple : this.getGeneralLedgerPendingEntries()) {
        List<String> expenseObjectTypes = objectTypeService.getExpenseObjectTypes(ple.getUniversityFiscalYear());
        if (expenseObjectTypes.contains(ple.getFinancialObjectTypeCode())) {
            // is an expense object type, keep checking
            ple.refreshNonUpdateableReferences();
            if (ple.getAccount().isPendingAcctSufficientFundsIndicator() && ple.getAccount().getAccountSufficientFundsCode().equals(KFSConstants.SF_TYPE_CASH_AT_ACCOUNT)) {
                // is a cash account
                if (flexibleOffsetAccountService.getByPrimaryIdIfEnabled(ple.getChartOfAccountsCode(), ple.getAccountNumber(), ple.getChart().getFinancialCashObjectCode()) == null && flexibleOffsetAccountService.getByPrimaryIdIfEnabled(ple.getChartOfAccountsCode(), ple.getAccountNumber(), ple.getChart().getFinAccountsPayableObjectCode()) == null) {
                    // does not have a flexible offset for cash or liability, set the object code to cash and add
                    // to list of PLEs to check for SF
                    GeneralLedgerPendingEntry newPle = new GeneralLedgerPendingEntry(ple);
                    newPle.setFinancialObjectCode(newPle.getChart().getFinancialCashObjectCode());
                    newPle.setTransactionDebitCreditCode(newPle.getTransactionDebitCreditCode().equals(KFSConstants.GL_DEBIT_CODE) ? KFSConstants.GL_CREDIT_CODE : KFSConstants.GL_DEBIT_CODE);
                    ples.add(newPle);
                }
            } else {
                // is not a cash account, process as normal
                ples.add(ple);
            }
        }
    }
    return ples;
}
Also used : ObjectTypeService(org.kuali.kfs.coa.service.ObjectTypeService) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) FlexibleOffsetAccountService(org.kuali.kfs.sys.service.FlexibleOffsetAccountService) ArrayList(java.util.ArrayList)

Aggregations

GeneralLedgerPendingEntry (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry)28 Timestamp (java.sql.Timestamp)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 KualiDecimal (org.kuali.kfs.core.api.util.type.KualiDecimal)4 List (java.util.List)3 ObjectCode (org.kuali.kfs.coa.businessobject.ObjectCode)3 SystemOptions (org.kuali.kfs.sys.businessobject.SystemOptions)3 PaymentMethodChart (edu.cornell.kfs.fp.businessobject.PaymentMethodChart)2 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)2 Date (java.sql.Date)2 Map (java.util.Map)2 Account (org.kuali.kfs.coa.businessobject.Account)2 AccountingPeriod (org.kuali.kfs.coa.businessobject.AccountingPeriod)2 OffsetDefinition (org.kuali.kfs.coa.businessobject.OffsetDefinition)2 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)2 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)2 WireCharge (org.kuali.kfs.sys.businessobject.WireCharge)2 GeneralLedgerPostingDocument (org.kuali.kfs.sys.document.GeneralLedgerPostingDocument)2 GeneralLedgerPendingEntryService (org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService)2