Search in sources :

Example 1 with PreEncumbranceSourceAccountingLine

use of edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine 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 2 with PreEncumbranceSourceAccountingLine

use of edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine in project cu-kfs by CU-CommunityApps.

the class PreEncumbranceAutoDisEncumberValidation method validate.

public boolean validate(AttributedDocumentEvent event) {
    boolean success = true;
    ParameterService ps = SpringContext.getBean(ParameterService.class);
    try {
        DateFormat transactionDateFormat = new SimpleDateFormat(TRANSACTION_DATE_FORMAT_STRING);
        annualClosingDate = new Date(transactionDateFormat.parse(ps.getParameterValueAsString(KfsParameterConstants.GENERAL_LEDGER_BATCH.class, GeneralLedgerConstants.ANNUAL_CLOSING_TRANSACTION_DATE_PARM)).getTime());
        // this needs to be changed
        annualClosingDate.setYear(annualClosingDate.getYear() + 1);
        LOG.info("Annual closing Date of: " + annualClosingDate);
    } catch (ParseException e) {
        LOG.error("PreEncumbrance validation nnable to parse transaction date", e);
        throw new IllegalArgumentException("Unable to parse transaction date");
    }
    PreEncumbranceDocument ped = (PreEncumbranceDocument) getAccountingDocumentForValidation();
    Iterator<PreEncumbranceSourceAccountingLine> it = ped.getSourceAccountingLines().iterator();
    while (it.hasNext()) {
        PreEncumbranceSourceAccountingLine pesal = it.next();
        auto = true;
        if (checkMinimumRequirements(pesal) && auto) {
            success &= checkDates(pesal);
            success &= checkGenerationValidity(pesal);
        } else {
            if (auto) {
                success &= false;
            }
        }
    }
    return success;
}
Also used : ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PreEncumbranceSourceAccountingLine(edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.sql.Date) PreEncumbranceDocument(edu.cornell.kfs.fp.document.PreEncumbranceDocument)

Aggregations

PreEncumbranceSourceAccountingLine (edu.cornell.kfs.fp.businessobject.PreEncumbranceSourceAccountingLine)2 Date (java.sql.Date)2 PreEncumbranceDocument (edu.cornell.kfs.fp.document.PreEncumbranceDocument)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)1 ValidationException (org.kuali.kfs.krad.exception.ValidationException)1 GeneralLedgerPendingEntry (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry)1 GeneralLedgerPendingEntryService (org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService)1 KfsParameterConstants (org.kuali.kfs.sys.service.impl.KfsParameterConstants)1 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)1