001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.kuali.kfs.module.cam.document.dataaccess.impl;
018
019 import java.math.BigDecimal;
020 import java.text.NumberFormat;
021 import java.util.ArrayList;
022 import java.util.Calendar;
023 import java.util.Collection;
024 import java.util.HashMap;
025 import java.util.Iterator;
026 import java.util.List;
027 import java.util.Locale;
028
029 import org.apache.ojb.broker.query.Criteria;
030 import org.apache.ojb.broker.query.QueryFactory;
031 import org.apache.ojb.broker.query.ReportQueryByCriteria;
032 import org.kuali.kfs.coa.businessobject.Account;
033 import org.kuali.kfs.module.cam.CamsConstants;
034 import org.kuali.kfs.module.cam.CamsKeyConstants;
035 import org.kuali.kfs.module.cam.CamsPropertyConstants;
036 import org.kuali.kfs.module.cam.businessobject.Asset;
037 import org.kuali.kfs.module.cam.businessobject.AssetObjectCode;
038 import org.kuali.kfs.module.cam.businessobject.AssetPayment;
039 import org.kuali.kfs.module.cam.businessobject.AssetRetirementGlobal;
040 import org.kuali.kfs.module.cam.document.AssetTransferDocument;
041 import org.kuali.kfs.module.cam.document.dataaccess.DepreciableAssetsDao;
042 import org.kuali.kfs.module.cam.document.dataaccess.DepreciationBatchDao;
043 import org.kuali.kfs.sys.KFSConstants;
044 import org.kuali.kfs.sys.KFSPropertyConstants;
045 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry;
046 import org.kuali.kfs.sys.dataaccess.UniversityDateDao;
047 import org.kuali.kfs.sys.service.OptionsService;
048 import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
049 import org.kuali.rice.kns.bo.DocumentHeader;
050 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
051 import org.kuali.rice.kns.service.BusinessObjectService;
052 import org.kuali.rice.kns.service.DateTimeService;
053 import org.kuali.rice.kns.service.KualiConfigurationService;
054 import org.kuali.rice.kns.service.ParameterService;
055 import org.kuali.rice.kns.util.KualiDecimal;
056 import org.kuali.rice.kns.util.spring.CacheNoCopy;
057
058 public class DepreciableAssetsDaoOjb extends PlatformAwareDaoBaseOjb implements DepreciableAssetsDao {
059 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DepreciableAssetsDaoOjb.class);
060 private KualiConfigurationService kualiConfigurationService;
061 private ParameterService parameterService;
062 private DateTimeService dateTimeService;
063 private OptionsService optionsService;
064 private BusinessObjectService businessObjectService;
065 private UniversityDateDao universityDateDao;
066 private DepreciationBatchDao depreciationBatchDao;
067
068 private String errorMsg = new String();
069
070 protected final static String PAYMENT_TO_ASSET_REFERENCE_DESCRIPTOR = "asset.";
071 protected final static String PAYMENT_TO_OBJECT_REFERENCE_DESCRIPTOR = "financialObject.";
072 protected final static String ASSET_TO_ASSET_TYPE_REFERENCE_DESCRIPTOR = "asset.capitalAssetType.";
073 protected final static String[] REPORT_GROUP = { "*** BEFORE RUNNING DEPRECIATION PROCESS ****", "*** AFTER RUNNING DEPRECIATION PROCESS ****" };
074
075
076 /**
077 * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciableAssetsDao#generateStatistics(boolean, java.lang.String,
078 * java.lang.Integer, java.lang.Integer, java.util.Calendar)
079 */
080 public List<String[]> generateStatistics(boolean beforeDepreciationReport, List<String> documentNumbers, Integer fiscalYear, Integer fiscalMonth, Calendar depreciationDate) {
081 LOG.debug("generateStatistics() - started");
082 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "generating statistics for report - " + (beforeDepreciationReport ? "Before part." : "After part"));
083
084 List<String[]> reportLine = new ArrayList<String[]>();
085 boolean processAlreadyRan = false;
086
087 NumberFormat usdFormat = NumberFormat.getCurrencyInstance(Locale.US);
088 KualiDecimal amount = new KualiDecimal(0);
089 String[] columns = new String[2];
090
091
092 columns[1] = "******************";
093 if (beforeDepreciationReport)
094 columns[0] = REPORT_GROUP[0];
095 else
096 columns[0] = REPORT_GROUP[1];
097
098 reportLine.add(columns.clone());
099
100 if (beforeDepreciationReport) {
101 columns[0] = "Depreciation Run Date";
102 columns[1] = (dateTimeService.toDateString(depreciationDate.getTime()));
103 reportLine.add(columns.clone());
104
105
106 columns[0] = "Fiscal Year";
107 columns[1] = (fiscalYear.toString());
108 reportLine.add(columns.clone());
109
110 columns[0] = "Fiscal Month";
111 columns[1] = (fiscalMonth.toString());
112 reportLine.add(columns.clone());
113
114 columns[0] = "Number of assets fully depreciated";
115 columns[1] = depreciationBatchDao.getFullyDepreciatedAssetCount().toString();
116 // columns[1] = getFullyDepreciatedAssetCount().toString();
117 reportLine.add(columns.clone());
118 }
119
120 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting DocumentHeader row count.");
121 Criteria criteria = new Criteria();
122 ReportQueryByCriteria q = QueryFactory.newReportQuery(DocumentHeader.class, new Criteria());
123 q.setAttributes(new String[] { "count(*)" });
124 Iterator<Object> i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
125
126 Object[] data = (Object[]) i.next();
127 columns[0] = "Document header table - record count";
128 columns[1] = (convertCountValueToString(data[0]));
129 reportLine.add(columns.clone());
130
131 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting general ledger pending entry row count.");
132 q = QueryFactory.newReportQuery(GeneralLedgerPendingEntry.class, new Criteria());
133 q.setAttributes(new String[] { "count(*)" });
134 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
135 data = (Object[]) i.next();
136 columns[0] = "General ledger pending entry table - record count";
137 columns[1] = (convertCountValueToString(data[0]));
138 reportLine.add(columns.clone());
139
140 if (beforeDepreciationReport) {
141 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting assets row count.");
142 q = QueryFactory.newReportQuery(Asset.class, new Criteria());
143 q.setAttributes(new String[] { "count(*)" });
144 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
145 data = (Object[]) i.next();
146 columns[0] = "Asset table - record count";
147 columns[1] = (convertCountValueToString(data[0]));
148 reportLine.add(columns.clone());
149 }
150
151 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting assets payment row count, depreciation base amount, accumulated depreciation amount, and every months depreciation amount.");
152 q = QueryFactory.newReportQuery(AssetPayment.class, new Criteria());
153 q.setAttributes(new String[] { "count(*)", "SUM(" + CamsPropertyConstants.AssetPayment.PRIMARY_DEPRECIATION_BASE_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.ACCUMULATED_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PREVIOUS_YEAR_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_1_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_2_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_3_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_4_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_5_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_6_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_7_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_8_DEPRECIATION_AMOUNT + ")",
154 "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_9_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_10_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_11_DEPRECIATION_AMOUNT + ")", "SUM(" + CamsPropertyConstants.AssetPayment.PERIOD_12_DEPRECIATION_AMOUNT + ")" });
155
156 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
157 data = new Object[16];
158 if (i.hasNext()) {
159 data = (Object[]) i.next();
160 }
161 else {
162 for (int c = 0; c < 16; c++)
163 data[c] = new KualiDecimal(0);
164 }
165
166 if (beforeDepreciationReport) {
167 columns[0] = "Asset payment table - record count";
168 columns[1] = (convertCountValueToString(data[0]));
169 reportLine.add(columns.clone());
170 }
171
172 columns[0] = "Depreciation base amount";
173 columns[1] = (usdFormat.format((KualiDecimal) data[1]));
174 reportLine.add(columns.clone());
175
176 columns[0] = "Current year - accumulated depreciation";
177 columns[1] = (usdFormat.format((KualiDecimal) data[2]));
178 reportLine.add(columns.clone());
179
180 columns[0] = "Previous year - accumulated depreciation";
181 columns[1] = (usdFormat.format((KualiDecimal) data[3]));
182 reportLine.add(columns.clone());
183
184 /*
185 * Here I'm getting the column of total depreciation for the current fiscal month. The idea here is to prevent the process
186 * from running a second time for the same fiscal month. 3 + fiscalMonth (variable) => current fiscal month depreciation
187 * column in the array. So if the current fiscal month depreciation column > 0 then depreciation was already ran. Therefore,
188 * it should be stop but, not until part of the pdf report List is populated so it can be written.
189 */
190 processAlreadyRan = false;
191 if (fiscalMonth > 1) {
192 if (((KualiDecimal) data[3 + fiscalMonth]).compareTo(new KualiDecimal(0)) != 0)
193 processAlreadyRan = true;
194 }
195 // *******************************************************************************************************************************
196
197 // Adding monthly depreciation amounts
198 KualiDecimal yearToDateDepreciationAmt = new KualiDecimal(0);
199
200 int fiscalStartMonth = Integer.parseInt(optionsService.getCurrentYearOptions().getUniversityFiscalYearStartMo());
201 boolean isJanuaryTheFirstFiscalMonth = (fiscalStartMonth == 1);
202 int col = 4;
203 int currentMonth = fiscalStartMonth - 1;
204 for (int monthCounter = 1; monthCounter <= 12; monthCounter++, currentMonth++) {
205 columns[0] = CamsConstants.MONTHS[currentMonth] + " depreciation amount";
206 columns[1] = (usdFormat.format((KualiDecimal) data[col]));
207 reportLine.add(columns.clone());
208
209 yearToDateDepreciationAmt = yearToDateDepreciationAmt.add((KualiDecimal) data[col]);
210
211 col++;
212
213 if (!isJanuaryTheFirstFiscalMonth) {
214 if (currentMonth == 11)
215 currentMonth = -1;
216 }
217 }
218
219 columns[0] = "Year to date depreciation amount";
220 columns[1] = (usdFormat.format(yearToDateDepreciationAmt));
221 reportLine.add(columns.clone());
222
223 if (beforeDepreciationReport) {
224 int federallyOwnedAssetPaymentCount = Integer.valueOf(depreciationBatchDao.getFederallyOwnedAssetAndPaymentCount(fiscalYear, fiscalMonth, depreciationDate)[1].toString());
225 int retiredAndTransferredAssetCount = depreciationBatchDao.getTransferDocLockedAssetCount() + depreciationBatchDao.getRetireDocLockedAssetCount();
226
227 columns[0] = "Object code table - record count";
228 columns[1] = (convertCountValueToString(this.getAssetObjectCodesCount(fiscalYear)));
229 reportLine.add(columns.clone());
230
231 columns[0] = "Plant fund account table - record count";
232 columns[1] = (convertCountValueToString(this.getCOAsCount()));
233 reportLine.add(columns.clone());
234
235 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting asset payment row count , depreciation base amount, accumulated depreciation amount, and every months depreciation amount.");
236 data = depreciationBatchDao.getAssetAndPaymentCount(fiscalYear, fiscalMonth, depreciationDate, true);
237 int eligibleAssetPaymentCount = new Integer(data[1].toString());
238
239 int totalAssetPayments = (eligibleAssetPaymentCount + federallyOwnedAssetPaymentCount);
240
241 columns[0] = "Asset payments eligible for depreciation";
242 columns[1] = totalAssetPayments + "";
243 reportLine.add(columns.clone());
244
245 columns[0] = "Number of assets with pending AR or AT documents";
246 columns[1] = retiredAndTransferredAssetCount + "";
247 reportLine.add(columns.clone());
248
249 data = depreciationBatchDao.getAssetAndPaymentCount(fiscalYear, fiscalMonth, depreciationDate, false);
250 eligibleAssetPaymentCount = new Integer(data[1].toString());
251 columns[0] = "Asset payments eligible for depreciation - After excluding AR and AT";
252 columns[1] = "" + (eligibleAssetPaymentCount + federallyOwnedAssetPaymentCount);
253 reportLine.add(columns.clone());
254
255 columns[0] = "Asset payments ineligible for depreciation (Federally owned assets)";
256 columns[1] = federallyOwnedAssetPaymentCount + "";
257 reportLine.add(columns.clone());
258
259 // payments eligible after deleting pending AR and AT documents.!!
260 columns[0] = "Asset payments eligible for depreciation - After excluding federally owned assets";
261 columns[1] = eligibleAssetPaymentCount + "";
262 reportLine.add(columns.clone());
263
264 columns[0] = "Assets eligible for depreciation";
265 columns[1] = data[0].toString();
266 reportLine.add(columns.clone());
267 }
268
269
270 if (!beforeDepreciationReport) {
271 // Generating a list of depreciation expense object codes.
272 List<String> depreExpObjCodes = this.getExpenseObjectCodes(fiscalYear);
273
274 // Generating a list of accumulated depreciation object codes.
275 List<String> accumulatedDepreciationObjCodes = this.getAccumulatedDepreciationObjectCodes(fiscalYear);
276
277 KualiDecimal debits = new KualiDecimal(0);
278 KualiDecimal credits = new KualiDecimal(0);
279
280 // Document Number created
281 columns[0] = "Document Number(s)";
282 columns[1] = documentNumbers.toString();
283 reportLine.add(columns.clone());
284
285 // Expense Debit
286 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "calculating the debit amount for expense object codes.");
287 criteria = new Criteria();
288 criteria.addIn(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, depreExpObjCodes);
289 criteria.addEqualTo(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, KFSConstants.GL_DEBIT_CODE);
290 criteria.addIn(KFSPropertyConstants.DOCUMENT_NUMBER, documentNumbers);
291
292 q = QueryFactory.newReportQuery(GeneralLedgerPendingEntry.class, criteria);
293 q.setAttributes(new String[] { "SUM(" + KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
294 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
295 data = (Object[]) i.next();
296
297 amount = (data[0] == null ? new KualiDecimal(0) : (KualiDecimal) data[0]);
298 KualiDecimal deprAmtDebit = amount;
299 columns[0] = "Debit - Depreciation Expense object codes: " + depreExpObjCodes.toString();
300 columns[1] = (usdFormat.format(amount));
301 reportLine.add(columns.clone());
302 debits = debits.add(amount);
303
304 // Accumulated Depreciation credit
305 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "calculating the credit amount for accumulated depreciation object codes.");
306 criteria = new Criteria();
307 criteria.addIn(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, accumulatedDepreciationObjCodes);
308 criteria.addEqualTo(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, KFSConstants.GL_CREDIT_CODE);
309 criteria.addIn(KFSPropertyConstants.DOCUMENT_NUMBER, documentNumbers);
310
311 q = QueryFactory.newReportQuery(GeneralLedgerPendingEntry.class, criteria);
312 q.setAttributes(new String[] { "SUM(" + KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
313 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
314 data = (Object[]) i.next();
315 amount = (data[0] == null ? new KualiDecimal(0) : (KualiDecimal) data[0]);
316 columns[0] = "Credit - Accumulated depreciation object codes: " + accumulatedDepreciationObjCodes.toString();
317 columns[1] = (usdFormat.format(amount));
318 reportLine.add(columns.clone());
319 credits = credits.add(amount);
320 // ***********************************************************************************************
321
322 // Accumulated Depreciation debit
323 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "calculating the debit amount for accumulated depreciation object codes.");
324 criteria = new Criteria();
325 criteria.addIn(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, accumulatedDepreciationObjCodes);
326 criteria.addEqualTo(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, KFSConstants.GL_DEBIT_CODE);
327 criteria.addIn(KFSPropertyConstants.DOCUMENT_NUMBER, documentNumbers);
328
329 q = QueryFactory.newReportQuery(GeneralLedgerPendingEntry.class, criteria);
330 q.setAttributes(new String[] { "SUM(" + KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
331 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
332 data = (Object[]) i.next();
333 amount = (data[0] == null ? new KualiDecimal(0) : (KualiDecimal) data[0]);
334
335 columns[0] = "Debit - Accumulated depreciation object codes:" + accumulatedDepreciationObjCodes.toString();
336 columns[1] = (usdFormat.format(amount));
337 reportLine.add(columns.clone());
338 debits = debits.add(amount);
339
340 // Expense credit
341 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "calculating the credit amount for expense object codes.");
342 criteria = new Criteria();
343 criteria.addIn(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, depreExpObjCodes);
344 criteria.addEqualTo(KFSPropertyConstants.TRANSACTION_DEBIT_CREDIT_CODE, KFSConstants.GL_CREDIT_CODE);
345 criteria.addIn(KFSPropertyConstants.DOCUMENT_NUMBER, documentNumbers);
346
347 q = QueryFactory.newReportQuery(GeneralLedgerPendingEntry.class, criteria);
348 q.setAttributes(new String[] { "SUM(" + KFSPropertyConstants.TRANSACTION_LEDGER_ENTRY_AMOUNT + ")" });
349 i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
350 data = (Object[]) i.next();
351 amount = (data[0] == null ? new KualiDecimal(0) : (KualiDecimal) data[0]);
352 KualiDecimal deprAmtCredit = amount;
353 columns[0] = "Credit - Depreciation Expense object codes:" + depreExpObjCodes.toString();
354 columns[1] = (usdFormat.format(amount));
355 reportLine.add(columns.clone());
356 credits = credits.add(amount);
357
358 columns[0] = "Current Month";
359 columns[1] = usdFormat.format(deprAmtDebit.subtract(deprAmtCredit));
360 reportLine.add(columns.clone());
361
362 columns[0] = "Total Debits";
363 columns[1] = usdFormat.format(debits);
364 reportLine.add(columns.clone());
365
366 columns[0] = "Total Credits";
367 columns[1] = usdFormat.format(credits);
368 reportLine.add(columns.clone());
369
370 columns[0] = "Total Debits - Total Credits";
371 columns[1] = usdFormat.format(debits.subtract(credits));
372 reportLine.add(columns.clone());
373 }
374 LOG.debug("generateStatistics() - ended");
375
376 if (processAlreadyRan && beforeDepreciationReport) {
377 throw new IllegalStateException(kualiConfigurationService.getPropertyString(CamsKeyConstants.Depreciation.DEPRECIATION_ALREADY_RAN_MSG));
378 }
379 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finished generating statistics for report - " + (beforeDepreciationReport ? "Before part." : "After part"));
380 return reportLine;
381 }
382
383
384 /**
385 * This method returns the number of records found resulting from a join of the organization table and the account table
386 *
387 * @param fiscalYear
388 * @return
389 */
390 protected Object getCOAsCount() {
391 LOG.debug("DepreciableAssetsDaoOjb.getCOAsCount() - started");
392 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting the number of campus plant fund accounts.");
393
394 Criteria criteria = new Criteria();
395 Object[] data;
396 ReportQueryByCriteria q = QueryFactory.newReportQuery(Account.class, criteria);
397 q.setAttributes(new String[] { "count(" + KFSPropertyConstants.ORGANIZATION + "." + KFSPropertyConstants.CAMPUS_PLANT_ACCOUNT_NUMBER + ")" });
398 Iterator<Object> i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
399 if (!i.hasNext()) {
400 data = new Object[1];
401 data[0] = new BigDecimal(0);
402 }
403 else {
404 data = (Object[]) i.next();
405 }
406
407 LOG.debug("DepreciableAssetsDaoOjb.getCOAsCount() - ended");
408 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finised getting the number of campus plant fund accounts.");
409 return data[0];
410 }
411
412 /**
413 * This method the value of the system parameter NON_DEPRECIABLE_FEDERALLY_OWNED_OBJECT_SUB_TYPES
414 *
415 * @return
416 */
417 protected List<String> getFederallyOwnedObjectSubTypes() {
418 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "getting the federally owned object subtype codes.");
419
420 List<String> federallyOwnedObjectSubTypes = new ArrayList<String>();
421 if (parameterService.parameterExists(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.NON_DEPRECIABLE_FEDERALLY_OWNED_OBJECT_SUB_TYPES)) {
422 federallyOwnedObjectSubTypes = parameterService.getParameterValues(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.NON_DEPRECIABLE_FEDERALLY_OWNED_OBJECT_SUB_TYPES);
423 }
424 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finished getting the federally owned object subtype codes which are:" + federallyOwnedObjectSubTypes.toString());
425 return federallyOwnedObjectSubTypes;
426 }
427
428
429 /**
430 * @see org.kuali.kfs.module.cam.document.dataaccess.DepreciableAssetsDao#getAssetObjectCodes(java.lang.Integer)
431 */
432 @CacheNoCopy
433 public Collection<AssetObjectCode> getAssetObjectCodes(Integer fiscalYear) {
434 LOG.debug("DepreciableAssetsDAoOjb.getAssetObjectCodes() - started");
435 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting asset object codes.");
436
437 Collection<AssetObjectCode> assetObjectCodesCollection;
438 HashMap<String, Object> fields = new HashMap<String, Object>();
439 fields.put(CamsPropertyConstants.AssetObject.UNIVERSITY_FISCAL_YEAR, fiscalYear);
440 fields.put(CamsPropertyConstants.AssetObject.ACTIVE, Boolean.TRUE);
441 assetObjectCodesCollection = (Collection<AssetObjectCode>) businessObjectService.findMatching(AssetObjectCode.class, fields);
442
443 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finished getting asset object codes - which are:" + assetObjectCodesCollection.toString());
444 LOG.debug("DepreciableAssetsDAoOjb.getAssetObjectCodes() - ended");
445 return assetObjectCodesCollection;
446 }
447
448 /**
449 * This method gets a list of Expense object codes from the asset object code table for a particular fiscal year
450 *
451 * @param fiscalYear
452 * @return a List<String>
453 */
454 @CacheNoCopy
455 protected List<String> getExpenseObjectCodes(Integer fiscalYear) {
456 LOG.debug("DepreciableAssetsDAoOjb.getExpenseObjectCodes() - started");
457 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting expense object codes");
458
459 List<String> depreExpObjCodes = new ArrayList<String>();
460 Collection<AssetObjectCode> assetObjectCodesCollection = this.getAssetObjectCodes(fiscalYear);
461
462 // Creating a list of depreciation expense object codes.
463 for (Iterator<AssetObjectCode> iterator = assetObjectCodesCollection.iterator(); iterator.hasNext();) {
464 AssetObjectCode assetObjectCode = iterator.next();
465
466 String objCode = assetObjectCode.getDepreciationExpenseFinancialObjectCode();
467 if (objCode != null && !objCode.equals("") && !depreExpObjCodes.contains(objCode)) {
468 depreExpObjCodes.add(objCode);
469 }
470 }
471 LOG.debug("DepreciableAssetsDAoOjb.getExpenseObjectCodes() - ended");
472 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finished getting expense object codes which are:" + depreExpObjCodes.toString());
473 return depreExpObjCodes;
474 }
475
476 /**
477 * This method gets a list of Accumulated Depreciation Object Codes from the asset object code table for a particular fiscal
478 * year.
479 *
480 * @param fiscalYear
481 * @return List<String>
482 */
483 @CacheNoCopy
484 protected List<String> getAccumulatedDepreciationObjectCodes(Integer fiscalYear) {
485 LOG.debug("DepreciableAssetsDAoOjb.getAccumulatedDepreciationObjectCodes() - started");
486 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting accum depreciation object codes");
487
488 List<String> accumulatedDepreciationObjCodes = new ArrayList<String>();
489 Collection<AssetObjectCode> assetObjectCodesCollection = this.getAssetObjectCodes(fiscalYear);
490
491 // Creating a list of depreciation expense object codes.
492 for (Iterator<AssetObjectCode> iterator = assetObjectCodesCollection.iterator(); iterator.hasNext();) {
493 AssetObjectCode assetObjectCode = iterator.next();
494
495 String objCode = assetObjectCode.getAccumulatedDepreciationFinancialObjectCode();
496 if (objCode != null && !objCode.equals("") && !accumulatedDepreciationObjCodes.contains(objCode)) {
497 accumulatedDepreciationObjCodes.add(objCode);
498 }
499 }
500 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finished getting accum depreciation object codes which are:" + accumulatedDepreciationObjCodes.toString());
501 LOG.debug("DepreciableAssetsDAoOjb.getAccumulatedDepreciationObjectCodes() - ended");
502 return accumulatedDepreciationObjCodes;
503 }
504
505 /**
506 * This method counts the number of assets that exist in both chart of accounts object code table and capital asset object code
507 * tables
508 *
509 * @param fiscalYear
510 * @return number of object codes found
511 */
512 protected Object getAssetObjectCodesCount(Integer fiscalYear) {
513 LOG.debug("DepreciableAssetsDAoOjb.getAssetObjectCodesCount() - started");
514 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting asset object code count.");
515
516 Criteria criteria = new Criteria();
517 criteria.addEqualTo(CamsPropertyConstants.AssetObject.UNIVERSITY_FISCAL_YEAR, fiscalYear);
518
519 ReportQueryByCriteria q = QueryFactory.newReportQuery(AssetObjectCode.class, criteria);
520 q.setAttributes(new String[] { "count(" + KFSPropertyConstants.OBJECT_CODE + "." + KFSPropertyConstants.FINANCIAL_OBJECT_CODE + ")" });
521 Iterator<Object> i = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
522 Object[] data = (Object[]) i.next();
523
524 LOG.info(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Finisned getting asset object code count which is: " + data[0]);
525 LOG.debug("DepreciableAssetsDAoOjb.getAssetObjectCodesCount() - ended");
526 return data[0];
527 }
528
529 /**
530 * This method converts a variable of type object to BigDecimal or a Long type in order to return a string
531 *
532 * @param fieldValue
533 * @return String
534 */
535 protected String convertCountValueToString(Object fieldValue) {
536 if (fieldValue == null)
537 return "0.0";
538
539 if (fieldValue instanceof BigDecimal) {
540 return ((BigDecimal) fieldValue).toString();
541 }
542 else {
543 return ((Long) fieldValue).toString();
544 }
545 }
546
547 public void setKualiConfigurationService(KualiConfigurationService kcs) {
548 kualiConfigurationService = kcs;
549 }
550
551 public void setParameterService(ParameterService parameterService) {
552 this.parameterService = parameterService;
553 }
554
555 public void setDateTimeService(DateTimeService dateTimeService) {
556 this.dateTimeService = dateTimeService;
557 }
558
559 public void setOptionsService(OptionsService optionService) {
560 this.optionsService = optionService;
561 }
562
563 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
564 this.businessObjectService = businessObjectService;
565 }
566
567 public void setUniversityDateDao(UniversityDateDao universityDateDao) {
568 this.universityDateDao = universityDateDao;
569 }
570
571 /**
572 * Gets the depreciationBatchDao attribute.
573 *
574 * @return Returns the depreciationBatchDao.
575 */
576 public DepreciationBatchDao getDepreciationBatchDao() {
577 return depreciationBatchDao;
578 }
579
580 /**
581 * Sets the depreciationBatchDao attribute value.
582 *
583 * @param depreciationBatchDao The depreciationBatchDao to set.
584 */
585 public void setDepreciationBatchDao(DepreciationBatchDao depreciationBatchDao) {
586 this.depreciationBatchDao = depreciationBatchDao;
587 }
588 } // end of class