Search in sources :

Example 1 with AssetObjectCode

use of org.kuali.kfs.module.cam.businessobject.AssetObjectCode 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 *******");
    }
}
Also used : UniversityDate(org.kuali.kfs.sys.businessobject.UniversityDate) AssetPaymentInfo(org.kuali.kfs.module.cam.batch.AssetPaymentInfo) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) AssetDepreciationTransaction(org.kuali.kfs.module.cam.businessobject.AssetDepreciationTransaction) AssetObjectCode(org.kuali.kfs.module.cam.businessobject.AssetObjectCode) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) AssetDepreciationStep(org.kuali.kfs.module.cam.batch.AssetDepreciationStep)

Example 2 with AssetObjectCode

use of org.kuali.kfs.module.cam.businessobject.AssetObjectCode in project cu-kfs by CU-CommunityApps.

the class AssetGlobalServiceImpl method createAssetGlpePostable.

/**
 * Creates an instance of AssetGlpeSourceDetail depending on the source flag
 *
 * @param document           University Date Service
 * @param assetPaymentDetail Payment record for which postable is created
 * @param amountCategory
 * @return GL Postable source detail
 */
protected AssetGlpeSourceDetail createAssetGlpePostable(AssetGlobal document, AssetPaymentDetail assetPaymentDetail, AmountCategory amountCategory) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Start - createAssetGlpePostable (" + document.getDocumentNumber() + "-" + assetPaymentDetail.getAccountNumber() + ")");
    }
    AssetGlpeSourceDetail postable = new AssetGlpeSourceDetail();
    assetPaymentDetail.refreshReferenceObject(CamsPropertyConstants.AssetPaymentDetail.ACCOUNT);
    postable.setAccount(assetPaymentDetail.getAccount());
    postable.setAmount(assetPaymentDetail.getAmount());
    postable.setAccountNumber(assetPaymentDetail.getAccountNumber());
    postable.setBalanceTypeCode(CamsConstants.Postable.GL_BALANCE_TYPE_CODE_AC);
    postable.setChartOfAccountsCode(assetPaymentDetail.getChartOfAccountsCode());
    postable.setDocumentNumber(document.getDocumentNumber());
    postable.setFinancialSubObjectCode(assetPaymentDetail.getFinancialSubObjectCode());
    postable.setPostingYear(assetPaymentDetail.getPostingYear());
    postable.setPostingPeriodCode(assetPaymentDetail.getPostingPeriodCode());
    postable.setProjectCode(assetPaymentDetail.getProjectCode());
    postable.setSubAccountNumber(assetPaymentDetail.getSubAccountNumber());
    postable.setOrganizationReferenceId(assetPaymentDetail.getOrganizationReferenceId());
    assetPaymentDetail.refreshReferenceObject(CamsPropertyConstants.AssetPaymentDetail.OBJECT_CODE);
    ObjectCode objectCode = objectCodeService.getByPrimaryIdForCurrentYear(assetPaymentDetail.getChartOfAccountsCode(), assetPaymentDetail.getFinancialObjectCode());
    AssetObjectCode assetObjectCode = assetObjectCodeService.findAssetObjectCode(assetPaymentDetail.getChartOfAccountsCode(), objectCode.getFinancialObjectSubTypeCode());
    OffsetDefinition offsetDefinition = offsetDefinitionService.getByPrimaryId(universityDateService.getCurrentFiscalYear(), assetPaymentDetail.getChartOfAccountsCode(), CamsConstants.AssetTransfer.DOCUMENT_TYPE_CODE, CamsConstants.Postable.GL_BALANCE_TYPE_CODE_AC);
    document.refreshReferenceObject(CamsPropertyConstants.AssetGlobal.ACQUISITION_TYPE);
    amountCategory.setParams(postable, assetPaymentDetail, assetObjectCode, offsetDefinition, document.getAcquisitionType());
    if (LOG.isDebugEnabled()) {
        LOG.debug("End - createAssetGlpePostable(" + document.getDocumentNumber() + "-" + assetPaymentDetail.getAccountNumber() + "-" + ")");
    }
    return postable;
}
Also used : AssetObjectCode(org.kuali.kfs.module.cam.businessobject.AssetObjectCode) AssetGlpeSourceDetail(org.kuali.kfs.module.cam.businessobject.AssetGlpeSourceDetail) OffsetDefinition(org.kuali.kfs.coa.businessobject.OffsetDefinition) ObjectCode(org.kuali.kfs.coa.businessobject.ObjectCode) AssetObjectCode(org.kuali.kfs.module.cam.businessobject.AssetObjectCode)

Aggregations

AssetObjectCode (org.kuali.kfs.module.cam.businessobject.AssetObjectCode)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 ObjectCode (org.kuali.kfs.coa.businessobject.ObjectCode)1 OffsetDefinition (org.kuali.kfs.coa.businessobject.OffsetDefinition)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 AssetGlpeSourceDetail (org.kuali.kfs.module.cam.businessobject.AssetGlpeSourceDetail)1 UniversityDate (org.kuali.kfs.sys.businessobject.UniversityDate)1