Search in sources :

Example 6 with UniversityDate

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

the class ScrubberValidatorImpl method validateTransactionDate.

/**
 * Validates the transaction date of the origin entry, make sure it is a valid university date
 *
 * @param originEntry       the origin entry being scrubbed
 * @param workingEntry      the scrubbed version of the origin entry
 * @param universityRunDate the university date when this scrubber process is being run
 * @return a Message if an error was encountered, otherwise null
 */
protected Message validateTransactionDate(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, UniversityDate universityRunDate, AccountingCycleCachingService accountingCycleCachingService) {
    LOG.debug("validateTransactionDate() started");
    Date transactionDate = new Date(universityRunDate.getUniversityDate().getTime());
    if (originEntry.getTransactionDate() == null) {
        // Set the transaction date to the run date.
        originEntry.setTransactionDate(transactionDate);
        workingEntry.setTransactionDate(transactionDate);
    } else {
        workingEntry.setTransactionDate(originEntry.getTransactionDate());
    }
    // Next, we have to validate the transaction date against the university date table.
    if (accountingCycleCachingService.getUniversityDate(originEntry.getTransactionDate()) == null) {
        // FSKD-193, KFSMI-5441
        // return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_TRANSACTION_DATE_INVALID, originEntry.getTransactionDate().toString(), Message.TYPE_FATAL);
        originEntry.setTransactionDate(transactionDate);
        workingEntry.setTransactionDate(transactionDate);
    }
    return null;
}
Also used : UniversityDate(org.kuali.kfs.sys.businessobject.UniversityDate) Date(java.sql.Date)

Example 7 with UniversityDate

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

the class CuUniversityDateFiscalYearMakerImpl method performCustomProcessing.

/**
 * @see org.kuali.kfs.coa.batch.dataaccess.impl.FiscalYearMakerHelperImpl#performCustomProcessing(java.lang.Integer)
 */
@Override
public void performCustomProcessing(Integer baseFiscalYear, boolean firstCopyYear) {
    int fiscalYearStartMonth = getFiscalYearStartMonth(baseFiscalYear);
    boolean replaceMode = parameterService.getParameterValueAsBoolean(FiscalYearMakerStep.class, KFSConstants.ChartApcParms.FISCAL_YEAR_MAKER_REPLACE_MODE);
    // determine start date year, if start month is not January the year will be one behind the fiscal year
    int startDateYear = baseFiscalYear;
    if (Calendar.JANUARY == fiscalYearStartMonth) {
        startDateYear += 1;
    }
    getPersistenceBrokerTemplate();
    // start with first day of fiscal year and create records for each year up to end date
    GregorianCalendar univPeriodDate = new GregorianCalendar(startDateYear, fiscalYearStartMonth, 1);
    // setup end date
    GregorianCalendar enddate = new GregorianCalendar(univPeriodDate.get(Calendar.YEAR), univPeriodDate.get(Calendar.MONTH), univPeriodDate.get(Calendar.DAY_OF_MONTH));
    enddate.add(Calendar.MONTH, 12);
    enddate.add(Calendar.DAY_OF_MONTH, -1);
    // the fiscal year is always the year of the ending date of the fiscal year
    Integer nextFiscalYear = enddate.get(Calendar.YEAR);
    // get rid of any records already existing for next fiscal year
    // deleteNewYearRows(nextFiscalYear);
    // initialize the period variables
    int period = 1;
    String periodString = String.format("%02d", period);
    int compareMonth = univPeriodDate.get(Calendar.MONTH);
    int currentMonth = compareMonth;
    // loop through the dates until we are past end date
    while (univPeriodDate.compareTo(enddate) <= 0) {
        // if we hit period 13 something went wrong
        if (period == 13) {
            LOG.error("Hit period 13 while creating university date records");
            throw new RuntimeException("Hit period 13 while creating university date records");
        }
        UniversityDate universityDate = null;
        // check if the university date exists and if it does and we are in replace mode then update the record, otherwise create a new one
        Map<String, Date> fields = new HashMap<String, Date>();
        fields.put(KFSPropertyConstants.UNIVERSITY_DATE, new Date(univPeriodDate.getTimeInMillis()));
        int count = businessObjectService.countMatching(UniversityDate.class, fields);
        if (count != 0) {
            if (replaceMode) {
                universityDate = businessObjectService.findByPrimaryKey(UniversityDate.class, fields);
                if (ObjectUtils.isNotNull(universityDate)) {
                    if (ObjectUtils.isNotNull(nextFiscalYear) && nextFiscalYear.equals(universityDate.getUniversityFiscalYear()) && StringUtils.isNotEmpty(periodString) && periodString.equals(universityDate.getUniversityFiscalAccountingPeriod())) {
                    // do nothing
                    } else {
                        universityDate.setUniversityFiscalYear(nextFiscalYear);
                        universityDate.setUniversityFiscalAccountingPeriod(periodString);
                        businessObjectService.save(universityDate);
                    }
                }
            }
        } else {
            // create the university date record
            universityDate = new UniversityDate();
            universityDate.setUniversityDate(new Date(univPeriodDate.getTimeInMillis()));
            universityDate.setUniversityFiscalYear(nextFiscalYear);
            universityDate.setUniversityFiscalAccountingPeriod(periodString);
            businessObjectService.save(universityDate);
        }
        // add one to day for the next record
        univPeriodDate.add(Calendar.DAY_OF_MONTH, 1);
        // does this kick us into a new month and therefore a new accounting period?
        compareMonth = univPeriodDate.get(Calendar.MONTH);
        if (currentMonth != compareMonth) {
            period = period + 1;
            periodString = String.format("%02d", period);
            currentMonth = compareMonth;
        }
    }
}
Also used : UniversityDate(org.kuali.kfs.sys.businessobject.UniversityDate) HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) UniversityDate(org.kuali.kfs.sys.businessobject.UniversityDate) Date(java.sql.Date)

Example 8 with UniversityDate

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

the class CuGeneralLedgerPendingEntryServiceImpl method setFiscalPeriodYearToToday.

/**
 * This method takes updates the provided GLPE with the current fiscal period and fiscal year.
 * @param glpe
 */
private void setFiscalPeriodYearToToday(GeneralLedgerPendingEntry glpe) {
    UniversityDate ud = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate();
    glpe.setUniversityFiscalYear(ud.getUniversityFiscalYear());
    glpe.setUniversityFiscalPeriodCode(ud.getUniversityFiscalAccountingPeriod());
}
Also used : UniversityDate(org.kuali.kfs.sys.businessobject.UniversityDate) UniversityDateService(org.kuali.kfs.sys.service.UniversityDateService)

Aggregations

UniversityDate (org.kuali.kfs.sys.businessobject.UniversityDate)8 Date (java.sql.Date)3 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 UniversityDateService (org.kuali.kfs.sys.service.UniversityDateService)2 Timestamp (java.sql.Timestamp)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 AssetDepreciationStep (org.kuali.kfs.module.cam.batch.AssetDepreciationStep)1 AssetPaymentInfo (org.kuali.kfs.module.cam.batch.AssetPaymentInfo)1 AssetDepreciationTransaction (org.kuali.kfs.module.cam.businessobject.AssetDepreciationTransaction)1 AssetObjectCode (org.kuali.kfs.module.cam.businessobject.AssetObjectCode)1 Cacheable (org.springframework.cache.annotation.Cacheable)1