use of org.kuali.kfs.sys.businessobject.UniversityDate in project cu-kfs by CU-CommunityApps.
the class ScrubberValidatorImpl method validateReversalDate.
/**
* Validates the reversal date of the origin entry
*
* @param originEntry the origin entry being scrubbed
* @param workingEntry the scrubbed version of the origin entry
* @return a Message if an error was encountered, otherwise null
*/
protected Message validateReversalDate(OriginEntryInformation originEntry, OriginEntryInformation workingEntry, AccountingCycleCachingService accountingCycleCachingService) {
LOG.debug("validateReversalDate() started");
if (originEntry.getFinancialDocumentReversalDate() != null) {
// UniversityDate universityDate = universityDateDao.getByPrimaryKey(originEntry.getFinancialDocumentReversalDate());
UniversityDate universityDate = accountingCycleCachingService.getUniversityDate(originEntry.getFinancialDocumentReversalDate());
if (universityDate == null) {
Date reversalDate = originEntry.getFinancialDocumentReversalDate();
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT_STRING);
return MessageBuilder.buildMessage(KFSKeyConstants.ERROR_REVERSAL_DATE_NOT_FOUND, format.format(reversalDate), Message.TYPE_FATAL);
} else {
workingEntry.setFinancialDocumentReversalDate(originEntry.getFinancialDocumentReversalDate());
}
}
return null;
}
use of org.kuali.kfs.sys.businessobject.UniversityDate in project cu-kfs by CU-CommunityApps.
the class ScrubberValidatorImpl method validateForInquiry.
/**
* Validate a transaction for use in balance inquiry
*
* @param entry Input transaction
* @see org.kuali.module.gl.service.ScrubberValidator#validateForInquiry(org.kuali.kfs.bo.GeneralLedgerPendingEntry)
*/
@Override
public void validateForInquiry(GeneralLedgerPendingEntry entry) {
LOG.debug("validateForInquiry() started");
UniversityDate today = null;
if (entry.getUniversityFiscalYear() == null) {
// FIXME! - date service should be injected
today = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate();
entry.setUniversityFiscalYear(today.getUniversityFiscalYear());
}
if (entry.getUniversityFiscalPeriodCode() == null) {
if (today == null) {
// FIXME! - date service should be injected
today = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate();
}
entry.setUniversityFiscalPeriodCode(today.getUniversityFiscalAccountingPeriod());
}
if ((entry.getSubAccountNumber() == null) || (!StringUtils.hasText(entry.getSubAccountNumber()))) {
entry.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
}
if ((entry.getFinancialSubObjectCode() == null) || (!StringUtils.hasText(entry.getFinancialSubObjectCode()))) {
entry.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
}
if ((entry.getProjectCode() == null) || (!StringUtils.hasText(entry.getProjectCode()))) {
entry.setProjectCode(KFSConstants.getDashProjectCode());
}
}
use of org.kuali.kfs.sys.businessobject.UniversityDate in project cu-kfs by CU-CommunityApps.
the class CuAssetDepreciationServiceImpl method runDepreciation.
@Override
public void runDepreciation() {
LOG.debug("runDepreciation() started");
Integer fiscalYear = -1;
Integer fiscalMonth = -1;
String errorMsg = "";
List<String> documentNos = new ArrayList<>();
List<String[]> reportLog = new ArrayList<>();
Collection<AssetObjectCode> assetObjectCodes = new ArrayList<>();
boolean hasErrors = false;
Calendar depreciationDate = dateTimeService.getCurrentCalendar();
String depreciationDateParameter = null;
DateFormat dateFormat = new SimpleDateFormat(CamsConstants.DateFormats.YEAR_MONTH_DAY, Locale.US);
boolean executeJob = false;
String errorMessage = kualiConfigurationService.getPropertyValueAsString(CamsKeyConstants.Depreciation.DEPRECIATION_ALREADY_RAN_MSG);
try {
executeJob = runAssetDepreciation();
if (executeJob) {
LOG.info("*******" + CamsConstants.Depreciation.DEPRECIATION_BATCH + " HAS BEGUN *******");
if (parameterService.parameterExists(AssetDepreciationStep.class, CamsParameterConstants.DEPRECIATION_DATE_PARAMETER)) {
depreciationDateParameter = parameterService.getParameterValueAsString(AssetDepreciationStep.class, CamsParameterConstants.DEPRECIATION_DATE_PARAMETER);
}
if (StringUtils.isBlank(depreciationDateParameter)) {
depreciationDateParameter = dateFormat.format(dateTimeService.getCurrentDate());
}
// This validates the system parameter depreciation_date has a valid format of YYYY-MM-DD.
if (!StringUtils.isBlank(depreciationDateParameter)) {
try {
depreciationDate.setTime(dateFormat.parse(depreciationDateParameter.trim()));
} catch (ParseException e) {
throw new IllegalArgumentException(kualiConfigurationService.getPropertyValueAsString(CamsKeyConstants.Depreciation.INVALID_DEPRECIATION_DATE_FORMAT));
}
}
LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Depreciation run date: " + depreciationDateParameter);
/**
* CU Customization to use java.sql.Date
*/
UniversityDate universityDate = businessObjectService.findBySinglePrimaryKey(UniversityDate.class, new java.sql.Date(depreciationDate.getTimeInMillis()));
if (universityDate == null) {
throw new IllegalStateException(kualiConfigurationService.getPropertyValueAsString(KFSKeyConstants.ERROR_UNIV_DATE_NOT_FOUND));
}
fiscalYear = universityDate.getUniversityFiscalYear();
fiscalMonth = new Integer(universityDate.getUniversityFiscalAccountingPeriod());
assetObjectCodes = getAssetObjectCodes(fiscalYear);
// If the depreciation date is not = to the system date then, the depreciation process cannot run.
LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Fiscal Year = " + fiscalYear + " & Fiscal Period=" + fiscalMonth);
int fiscalStartMonth = Integer.parseInt(optionsService.getCurrentYearOptions().getUniversityFiscalYearStartMo());
reportLog.addAll(depreciableAssetsDao.generateStatistics(true, null, fiscalYear, fiscalMonth, depreciationDate, dateTimeService.toDateString(depreciationDate.getTime()), assetObjectCodes, fiscalStartMonth, errorMessage));
// update if fiscal period is 12
// depreciationBatchDao.updateAssetsCreatedInLastFiscalPeriod(fiscalMonth, fiscalYear);
updateAssetsDatesForLastFiscalPeriod(fiscalMonth, fiscalYear);
// Retrieving eligible asset payment details
LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting list of asset payments " + "eligible for depreciation.");
Collection<AssetPaymentInfo> depreciableAssetsCollection = depreciationBatchDao.getListOfDepreciableAssetPaymentInfo(fiscalYear, fiscalMonth, depreciationDate);
// transactions
if (depreciableAssetsCollection != null && !depreciableAssetsCollection.isEmpty()) {
SortedMap<String, AssetDepreciationTransaction> depreciationTransactions = this.calculateDepreciation(fiscalYear, fiscalMonth, depreciableAssetsCollection, depreciationDate, assetObjectCodes);
processGeneralLedgerPendingEntry(fiscalYear, fiscalMonth, documentNos, depreciationTransactions);
} else {
throw new IllegalStateException(kualiConfigurationService.getPropertyValueAsString(CamsKeyConstants.Depreciation.NO_ELIGIBLE_FOR_DEPRECIATION_ASSETS_FOUND));
}
}
} catch (Exception e) {
LOG.error("Error occurred");
LOG.error(CamsConstants.Depreciation.DEPRECIATION_BATCH + "**************************************************************************");
LOG.error(CamsConstants.Depreciation.DEPRECIATION_BATCH + "AN ERROR HAS OCCURRED! - ERROR: " + e.getMessage(), e);
LOG.error(CamsConstants.Depreciation.DEPRECIATION_BATCH + "**************************************************************************");
hasErrors = true;
errorMsg = "Depreciation process ran unsuccessfully.\nReason:" + e.getMessage();
} finally {
if (!hasErrors && executeJob) {
int fiscalStartMonth = Integer.parseInt(optionsService.getCurrentYearOptions().getUniversityFiscalYearStartMo());
reportLog.addAll(depreciableAssetsDao.generateStatistics(false, documentNos, fiscalYear, fiscalMonth, depreciationDate, dateTimeService.toDateString(depreciationDate.getTime()), assetObjectCodes, fiscalStartMonth, errorMessage));
}
// the report will be generated only when there is an error or when the log has something.
if (!reportLog.isEmpty() || !errorMsg.trim().equals("")) {
reportService.generateDepreciationReport(reportLog, errorMsg, depreciationDateParameter);
}
LOG.debug("*******" + CamsConstants.Depreciation.DEPRECIATION_BATCH + " HAS ENDED *******");
}
}
use of org.kuali.kfs.sys.businessobject.UniversityDate in project cu-kfs by CU-CommunityApps.
the class AccountingPeriodServiceImpl method getByDate.
/**
* This method is a helper method to get the current period.
*/
@Override
@Cacheable(cacheNames = AccountingPeriod.CACHE_NAME, key = "'{getByDate}-date='+#p0")
public AccountingPeriod getByDate(Date date) {
Map<String, Object> primaryKeys = new HashMap<>();
primaryKeys.put(KFSPropertyConstants.UNIVERSITY_DATE, date);
UniversityDate universityDate = businessObjectService.findByPrimaryKey(UniversityDate.class, primaryKeys);
primaryKeys.clear();
primaryKeys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityDate.getUniversityFiscalYear());
primaryKeys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, universityDate.getUniversityFiscalAccountingPeriod());
return businessObjectService.findByPrimaryKey(AccountingPeriod.class, primaryKeys);
}
use of org.kuali.kfs.sys.businessobject.UniversityDate in project cu-kfs by CU-CommunityApps.
the class AssetRetirementGlobal method setAssetForPersist.
/**
* This method set asset fields for update
*
* @param persistables
*/
protected void setAssetForPersist(Asset asset, List<PersistableBusinessObject> persistables, AssetRetirementService retirementService) {
UniversityDateService universityDateService = SpringContext.getBean(UniversityDateService.class);
// load the object by key
asset.setInventoryStatusCode(CamsConstants.InventoryStatusCode.CAPITAL_ASSET_RETIRED);
asset.setRetirementReasonCode(retirementReasonCode);
// set retirement fiscal year and period code into asset
UniversityDate currentUniversityDate = universityDateService.getCurrentUniversityDate();
if (ObjectUtils.isNotNull(currentUniversityDate)) {
asset.setRetirementFiscalYear(universityDateService.getCurrentUniversityDate().getUniversityFiscalYear());
asset.setRetirementPeriodCode(universityDateService.getCurrentUniversityDate().getUniversityFiscalAccountingPeriod());
}
if (retirementService.isAssetRetiredByTheft(this) && StringUtils.isNotBlank(this.getPaidCaseNumber())) {
asset.setCampusPoliceDepartmentCaseNumber(this.getPaidCaseNumber());
} else if (retirementService.isAssetRetiredBySold(this) || retirementService.isAssetRetiredByAuction(this)) {
asset.setRetirementChartOfAccountsCode(this.getRetirementChartOfAccountsCode());
asset.setRetirementAccountNumber(this.getRetirementAccountNumber());
asset.setCashReceiptFinancialDocumentNumber(this.getCashReceiptFinancialDocumentNumber());
asset.setSalePrice(this.getSalePrice());
asset.setEstimatedSellingPrice(this.getEstimatedSellingPrice());
} else if (retirementService.isAssetRetiredByMerged(this)) {
asset.setTotalCostAmount(KualiDecimal.ZERO);
asset.setSalvageAmount(KualiDecimal.ZERO);
} else if (retirementService.isAssetRetiredByExternalTransferOrGift(this)) {
persistables.add(setOffCampusLocationObjectsForPersist(asset));
}
asset.setLastInventoryDate(new Timestamp(SpringContext.getBean(DateTimeService.class).getCurrentSqlDate().getTime()));
persistables.add(asset);
}
Aggregations