Search in sources :

Example 6 with GeneralLedgerPendingEntry

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

the class PreEncumbranceDocument method processExplicitGeneralLedgerPendingEntry.

/**
 * This method processes all necessary information to build an explicit general ledger entry, and then adds that to the
 * document.
 *
 * @param accountingDocument
 * @param sequenceHelper
 * @param accountingLine
 * @param explicitEntry
 * @return boolean True if the explicit entry generation was successful, false otherwise.
 */
@Override
protected void processExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySequenceHelper sequenceHelper, GeneralLedgerPendingEntrySourceDetail glpeSourceDetail, GeneralLedgerPendingEntry explicitEntry) {
    if (glpeSourceDetail instanceof PreEncumbranceSourceAccountingLine) {
        int rowId = ((AccountingLine) glpeSourceDetail).getSequenceNumber() - 1;
        PreEncumbranceSourceAccountingLine pesal = (PreEncumbranceSourceAccountingLine) glpeSourceDetail;
        if (ObjectUtils.isNotNull(pesal.getAutoDisEncumberType())) {
            if (ObjectUtils.isNull(pesal.getStartDate()) || ObjectUtils.isNull(pesal.getPartialTransactionCount()) || ObjectUtils.isNull(pesal.getPartialAmount())) {
                throw new ValidationException("Insufficient information for GLPE generation");
            }
            Date generatedEndDate = PreEncumbranceAccountingLineUtil.generateEndDate(pesal.getStartDate(), Integer.parseInt(pesal.getPartialTransactionCount()), pesal.getAutoDisEncumberType());
            pesal.setEndDate(generatedEndDate);
            TreeMap<Date, KualiDecimal> datesAndAmounts = PreEncumbranceAccountingLineUtil.generateDatesAndAmounts(pesal.getAutoDisEncumberType(), pesal.getStartDate(), pesal.getEndDate(), Integer.parseInt(pesal.getPartialTransactionCount()), pesal.getAmount(), pesal.getPartialAmount(), rowId);
            Iterator<Date> it = datesAndAmounts.keySet().iterator();
            boolean isErrorCorrection = false;
            Date today = new Date(Calendar.getInstance().getTimeInMillis());
            if (pesal.getAmount().isNegative()) {
                // we are doing error correction
                LOG.info("Error correction!");
                isErrorCorrection = true;
            }
            while (it.hasNext()) {
                Date revDate = it.next();
                if (isErrorCorrection && revDate.before(today)) {
                    break;
                }
                KualiDecimal partialAmount = datesAndAmounts.get(revDate);
                GeneralLedgerPendingEntry explicitPartialEntry = new GeneralLedgerPendingEntry();
                SpringContext.getBean(GeneralLedgerPendingEntryService.class).populateExplicitGeneralLedgerPendingEntry(this, glpeSourceDetail, sequenceHelper, explicitPartialEntry);
                explicitPartialEntry.setFinancialDocumentReversalDate(revDate);
                explicitPartialEntry.setTransactionLedgerEntryAmount(isErrorCorrection ? partialAmount.negated() : partialAmount);
                customizeExplicitGeneralLedgerPendingEntry(glpeSourceDetail, explicitPartialEntry);
                addPendingEntry(explicitPartialEntry);
                sequenceHelper.increment();
                GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(explicitPartialEntry);
                processOffsetGeneralLedgerPendingEntry(sequenceHelper, glpeSourceDetail, explicitPartialEntry, offsetEntry);
                sequenceHelper.increment();
            }
            // no need to do the following stuff, as we're generating a bunch of custom GL pending entries above
            return;
        }
    }
    // populate the explicit entry
    SpringContext.getBean(GeneralLedgerPendingEntryService.class).populateExplicitGeneralLedgerPendingEntry(this, glpeSourceDetail, sequenceHelper, explicitEntry);
    // hook for children documents to implement document specific GLPE field mappings
    customizeExplicitGeneralLedgerPendingEntry(glpeSourceDetail, explicitEntry);
    addPendingEntry(explicitEntry);
    sequenceHelper.increment();
    // handle the offset entry
    GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(explicitEntry);
    boolean success = processOffsetGeneralLedgerPendingEntry(sequenceHelper, glpeSourceDetail, explicitEntry, offsetEntry);
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) PreEncumbranceSourceAccountingLine(edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine) GeneralLedgerPendingEntryService(org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService) KualiDecimal(org.kuali.rice.core.api.util.type.KualiDecimal) Date(java.sql.Date)

Example 7 with GeneralLedgerPendingEntry

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

the class CuPurapGeneralLedgerServiceImpl method getNextAvailableSequence.

protected int getNextAvailableSequence(String documentNumber) {
    LOG.debug("getNextAvailableSequence() started");
    Map fieldValues = new HashMap();
    fieldValues.put("financialSystemOriginationCode", PURAP_ORIGIN_CODE);
    fieldValues.put("documentNumber", documentNumber);
    List<GeneralLedgerPendingEntry> glpes = (List<GeneralLedgerPendingEntry>) SpringContext.getBean(org.kuali.kfs.krad.service.BusinessObjectService.class).findMatching(GeneralLedgerPendingEntry.class, fieldValues);
    // KFSPTS-2632 : Bankoffset will not be posted by nightly batch job because its status is 'N'.
    // so, we need to find the highest transactionsequence.  Otherwise it may cause OLE
    int count = 0;
    if (CollectionUtils.isNotEmpty(glpes)) {
        for (GeneralLedgerPendingEntry glpe : glpes) {
            if (glpe.getTransactionLedgerEntrySequenceNumber() > count) {
                count = glpe.getTransactionLedgerEntrySequenceNumber();
            }
        }
    }
    return count + 1;
}
Also used : HashMap(java.util.HashMap) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with GeneralLedgerPendingEntry

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

the class CUPaymentMethodGeneralLedgerPendingEntryServiceImpl method getNextAvailableSequence.

/**
 * Retrieves the next available sequence number from the general ledger pending entry table for this document
 *
 * @param documentNumber
 *            Document number to find next sequence number
 * @return Next available sequence number
 */
protected int getNextAvailableSequence(String documentNumber) {
    LOG.debug("getNextAvailableSequence() started");
    Map fieldValues = new HashMap();
    fieldValues.put("financialSystemOriginationCode", PURAP_ORIGIN_CODE);
    fieldValues.put("documentNumber", documentNumber);
    List<GeneralLedgerPendingEntry> glpes = (List<GeneralLedgerPendingEntry>) (SpringContext.getBean(BusinessObjectService.class)).findMatching(GeneralLedgerPendingEntry.class, fieldValues);
    int count = 0;
    if (CollectionUtils.isNotEmpty(glpes)) {
        for (GeneralLedgerPendingEntry glpe : glpes) {
            if (glpe.getTransactionLedgerEntrySequenceNumber() > count) {
                count = glpe.getTransactionLedgerEntrySequenceNumber();
            }
        }
    }
    return count + 1;
}
Also used : HashMap(java.util.HashMap) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) BusinessObjectService(org.kuali.kfs.krad.service.BusinessObjectService)

Example 9 with GeneralLedgerPendingEntry

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

the class CUPaymentMethodGeneralLedgerPendingEntryServiceImpl method generateClearingAccountOffsetEntries.

/**
 * When the "A" payment method is used for AP Credit Cards - generate the needed entries in the clearing account.
 *
 * @param document Document into which to add the generated GL Entries.
 * @param sequenceHelper helper class to keep track of GLPE sequence
 */
public boolean generateClearingAccountOffsetEntries(PaymentMethod pm, AccountingDocument document, GeneralLedgerPendingEntrySequenceHelper sequenceHelper, Map<String, KualiDecimal> actualTotalsByChart) {
    if (actualTotalsByChart == null) {
        actualTotalsByChart = getNonOffsetActualTotalsByChart(document);
    }
    for (String chart : actualTotalsByChart.keySet()) {
        KualiDecimal offsetAmount = actualTotalsByChart.get(chart);
        if (!KualiDecimal.ZERO.equals(offsetAmount)) {
            PaymentMethodChart pmc = pm.getPaymentMethodChartInfo(chart, new java.sql.Date(document.getDocumentHeader().getWorkflowDocument().getDateCreated().getMillis()));
            if (pmc == null) {
                LOG.warn("No Applicable PaymentMethodChart found for chart: " + chart + " and date: " + document.getDocumentHeader().getWorkflowDocument().getDateCreated());
                // skip this line - still attempt for other charts
                continue;
            }
            String clearingChartCode = pmc.getClearingChartOfAccountsCode();
            String clearingAccountNumber = pmc.getClearingAccountNumber();
            // liability object code
            String clearingObjectCode = pmc.getClearingFinancialObjectCode();
            GeneralLedgerPendingEntry apOffsetEntry = new GeneralLedgerPendingEntry(document.getGeneralLedgerPendingEntry(0));
            apOffsetEntry.setTransactionLedgerEntrySequenceNumber(new Integer(sequenceHelper.getSequenceCounter()));
            apOffsetEntry.setChartOfAccountsCode(clearingChartCode);
            apOffsetEntry.setAccountNumber(clearingAccountNumber);
            apOffsetEntry.setFinancialObjectCode(clearingObjectCode);
            // if internal billing
            if (StringUtils.equals(PaymentMethod.PM_CODE_INTERNAL_BILLING, pm.getPaymentMethodCode())) {
                apOffsetEntry.setFinancialSubObjectCode(pmc.getClearingFinancialSubObjectCode());
                apOffsetEntry.setSubAccountNumber(pmc.getClearingSubAccountNumber());
            } else {
                apOffsetEntry.setFinancialSubObjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialSubObjectCode());
                apOffsetEntry.setSubAccountNumber(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankSubAccountNumber());
            }
            apOffsetEntry.setProjectCode(GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankProjectCode());
            // retrieve object type
            ObjectCode objectCode = getObjectCodeService().getByPrimaryIdForCurrentYear(clearingChartCode, clearingObjectCode);
            if (objectCode == null) {
                LOG.fatal("Specified offset object code: " + clearingChartCode + "-" + clearingObjectCode + " does not exist - failed to generate CC offset entries", new RuntimeException());
                return false;
            }
            apOffsetEntry.setFinancialObjectTypeCode(objectCode.getFinancialObjectTypeCode());
            apOffsetEntry.setTransactionLedgerEntryAmount(offsetAmount.abs());
            apOffsetEntry.setTransactionDebitCreditCode(offsetAmount.isNegative() ? KFSConstants.GL_DEBIT_CODE : KFSConstants.GL_CREDIT_CODE);
            apOffsetEntry.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL);
            document.addPendingEntry(apOffsetEntry);
            sequenceHelper.increment();
            // handle the offset entry
            GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(apOffsetEntry);
            getGeneralLedgerPendingEntryService().populateOffsetGeneralLedgerPendingEntry(document.getPostingYear(), apOffsetEntry, 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.rice.core.api.util.type.KualiDecimal) ObjectCode(org.kuali.kfs.coa.businessobject.ObjectCode)

Example 10 with GeneralLedgerPendingEntry

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

the class RecurringDisbursementVoucherDocumentServiceImpl method updateGLPEDatesAndAddRecurringDocumentLinks.

private void updateGLPEDatesAndAddRecurringDocumentLinks(DisbursementVoucherDocument dv, String recurringDisbursemntVoucherDocumentNumber) {
    for (GeneralLedgerPendingEntry glpe : dv.getGeneralLedgerPendingEntries()) {
        glpe.setTransactionDate(dv.getDisbursementVoucherDueDate());
        glpe.setReferenceFinancialDocumentTypeCode(CuFPConstants.RecurringDisbursementVoucherDocumentConstants.RECURRING_DV_DOCUMENT_TYPE_NAME);
        glpe.setReferenceFinancialDocumentNumber(recurringDisbursemntVoucherDocumentNumber);
        AccountingPeriod ap = getAccountingPeriodService().getByDate(dv.getDisbursementVoucherDueDate());
        glpe.setAccountingPeriod(ap);
        glpe.setUniversityFiscalPeriodCode(ap.getUniversityFiscalPeriodCode());
        glpe.setUniversityFiscalYear(ap.getUniversityFiscalYear());
        getBusinessObjectService().save(glpe);
    }
}
Also used : GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) AccountingPeriod(org.kuali.kfs.coa.businessobject.AccountingPeriod)

Aggregations

GeneralLedgerPendingEntry (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry)25 Timestamp (java.sql.Timestamp)6 ArrayList (java.util.ArrayList)6 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)6 HashMap (java.util.HashMap)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 GeneralLedgerPostingDocument (org.kuali.kfs.sys.document.GeneralLedgerPostingDocument)2 GeneralLedgerPendingEntryService (org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService)2 KfsParameterConstants (org.kuali.kfs.sys.service.impl.KfsParameterConstants)2