Advertisement
mugs

AssetDepreciationServiceImpl.diff

Dec 3rd, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 23.05 KB | None | 0 0
  1. diff --git a/web/src/main/java/za/org/kuali/kfs/module/cam/batch/service/impl/AssetDepreciationServiceImpl.java b/web/src/main/java/za/org/kuali/kfs/module/cam/batch/service/impl/AssetDepreciationServiceImpl.java
  2. index b758d6d..ba193e1 100644
  3. --- a/web/src/main/java/za/org/kuali/kfs/module/cam/batch/service/impl/AssetDepreciationServiceImpl.java
  4. +++ b/web/src/main/java/za/org/kuali/kfs/module/cam/batch/service/impl/AssetDepreciationServiceImpl.java
  5. @@ -1,8 +1,15 @@
  6.  package za.org.kuali.kfs.module.cam.batch.service.impl;
  7.  
  8. +import java.util.ArrayList;
  9. +import java.util.Calendar;
  10. +import java.util.Collection;
  11. +import java.util.HashMap;
  12. +import java.util.List;
  13. +import java.util.Map;
  14. +import java.util.SortedMap;
  15. +import java.util.TreeMap;
  16. +
  17.  import org.apache.commons.lang.StringUtils;
  18. -import org.joda.time.LocalDate;
  19. -import org.joda.time.Months;
  20.  import org.kuali.kfs.coa.businessobject.ObjectCode;
  21.  import org.kuali.kfs.module.cam.CamsConstants;
  22.  import org.kuali.kfs.module.cam.CamsKeyConstants;
  23. @@ -14,14 +21,19 @@ import org.kuali.kfs.module.cam.businessobject.AssetObjectCode;
  24.  import org.kuali.kfs.sys.KFSConstants;
  25.  import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
  26.  import org.kuali.rice.core.api.util.type.KualiDecimal;
  27. +import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
  28. +import org.kuali.rice.coreservice.framework.parameter.ParameterService;
  29. +import org.kuali.rice.krad.service.BusinessObjectService;
  30.  import org.kuali.rice.krad.service.KRADServiceLocator;
  31.  import org.kuali.rice.krad.util.ObjectUtils;
  32. +
  33.  import za.org.kuali.kfs.module.cam.businessobject.AssetPaymentExtension;
  34.  
  35. -import java.util.*;
  36. +
  37.  
  38.  public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch.service.impl.AssetDepreciationServiceImpl {
  39.      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AssetDepreciationServiceImpl.class);
  40. +    private BusinessObjectService businessObjectService;
  41.  
  42.      @Override
  43.      protected SortedMap<String, AssetDepreciationTransaction> calculateDepreciation(Integer fiscalYear, Integer fiscalMonth, Collection<AssetPaymentInfo> depreciableAssetsCollection, Calendar depreciationDate, Collection<AssetObjectCode> assetObjectCodes) {
  44. @@ -32,31 +44,31 @@ public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch
  45.          SortedMap<String, AssetDepreciationTransaction> depreciationTransactionSummary = new TreeMap<String, AssetDepreciationTransaction>();
  46.          double monthsElapsed = 0d;
  47.          double assetLifeInMonths = 0d;
  48. -        KualiDecimal accumulatedDepreciationAmount = KualiDecimal.ZERO;
  49. +        KualiDecimal calculatedAccumulatedDepreciation = KualiDecimal.ZERO;
  50.          Calendar assetDepreciationDate = Calendar.getInstance();
  51.          boolean assetReclass = false;
  52.          boolean salvageRate = false;
  53.          try {
  54.              LOG.debug(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Getting the parameters for the plant fund object sub types.");
  55.              // Getting system parameters needed.
  56. -            if (parameterService.parameterExists(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_ORGANIZATON_PLANT_FUND_SUB_OBJECT_TYPES)) {
  57. -                organizationPlantFundObjectSubType = new ArrayList<String>( parameterService.getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_ORGANIZATON_PLANT_FUND_SUB_OBJECT_TYPES) );
  58. +            if (getParameterService().parameterExists(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_ORGANIZATON_PLANT_FUND_SUB_OBJECT_TYPES)) {
  59. +                organizationPlantFundObjectSubType = new ArrayList<String>( getParameterService().getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_ORGANIZATON_PLANT_FUND_SUB_OBJECT_TYPES) );
  60.              }
  61. -            if (parameterService.parameterExists(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_CAMPUS_PLANT_FUND_OBJECT_SUB_TYPES)) {
  62. -                campusPlantFundObjectSubType = new ArrayList<String>( parameterService.getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_CAMPUS_PLANT_FUND_OBJECT_SUB_TYPES) );
  63. +            if (getParameterService().parameterExists(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_CAMPUS_PLANT_FUND_OBJECT_SUB_TYPES)) {
  64. +                campusPlantFundObjectSubType = new ArrayList<String>( getParameterService().getParameterValuesAsString(KfsParameterConstants.CAPITAL_ASSETS_BATCH.class, CamsConstants.Parameters.DEPRECIATION_CAMPUS_PLANT_FUND_OBJECT_SUB_TYPES) );
  65.              }
  66.              // Initializing the asset payment table.
  67. -            depreciationBatchDao.resetPeriodValuesWhenFirstFiscalPeriod(fiscalMonth);
  68. +            getDepreciationBatchDao().resetPeriodValuesWhenFirstFiscalPeriod(fiscalMonth);
  69.              LOG.debug("getBaseAmountOfAssets(Collection<AssetPayment> depreciableAssetsCollection) - Started.");
  70.              // Invoking method that will calculate the base amount for each asset payment transactions, which could be more than 1
  71.              // per asset.
  72.              LOG.debug(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Calculating the base amount for each asset.");
  73. -            Map<Long, KualiDecimal> salvageValueAssetDeprAmounts = depreciationBatchDao.getPrimaryDepreciationBaseAmountForSV();
  74. +            Map<Long, KualiDecimal> salvageValueAssetDeprAmounts = getDepreciationBatchDao().getPrimaryDepreciationBaseAmountForSV();
  75.              // Retrieving the object asset codes.
  76.              Map<String, AssetObjectCode> assetObjectCodeMap = buildChartObjectToCapitalizationObjectMap(assetObjectCodes);
  77.              Map<String, ObjectCode> capitalizationObjectCodes = new HashMap<String, ObjectCode>();
  78.  
  79. -            // Reading asset payments
  80. +            // iterating over asset payments
  81.              LOG.debug(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Reading collection with eligible asset payment details.");
  82.              int counter = 0;
  83.              List<AssetPaymentInfo> saveList = new ArrayList<AssetPaymentInfo>();
  84. @@ -85,8 +97,6 @@ public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch
  85.                  }
  86.                  Long assetNumber = assetPaymentInfo.getCapitalAssetNumber();
  87.                  assetDepreciationDate.setTime(assetPaymentInfo.getDepreciationDate());
  88. -                accumulatedDepreciationAmount = KualiDecimal.ZERO;
  89. -                KualiDecimal deprAmountSum = salvageValueAssetDeprAmounts.get(assetNumber);
  90.                  // Calculating the life of the asset in months.
  91.                  assetLifeInMonths = assetPaymentInfo.getDepreciableLifeLimit() * 12;
  92.                  // Calculating the months elapsed for the asset using the depreciation date and the asset service date.
  93. @@ -96,38 +106,37 @@ public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch
  94.                  // CALCULATING ACCUMULATED DEPRECIATION BASED ON FORMULA FOR SINGLE LINE AND SALVAGE VALUE DEPRECIATION METHODS.
  95.                  // **************************************************************************************************************
  96.                  KualiDecimal primaryDepreciationBaseAmount = assetPaymentInfo.getPrimaryDepreciationBaseAmount();
  97. -                Asset asset = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(Asset.class,assetNumber );
  98. +                Asset asset = getBusinessObjectService().findBySinglePrimaryKey(Asset.class,assetNumber );
  99.  
  100.                  if (primaryDepreciationBaseAmount == null) {
  101. -                    assetPaymentInfo.setPrimaryDepreciationBaseAmount(KualiDecimal.ZERO);
  102. +                   primaryDepreciationBaseAmount = KualiDecimal.ZERO;
  103.                  }
  104.                  if (ObjectUtils.isNull(asset.getCapitalAssetType())) {
  105.                      asset.refreshReferenceObject(CamsPropertyConstants.Asset.CAPITAL_ASSET_TYPE);
  106.                  }
  107.                  if (ObjectUtils.isNotNull(asset) && asset.getCapitalAssetType().getSalvageRate() != null) {
  108. -                    assetPaymentInfo.setPrimaryDepreciationBaseAmount(asset.getTotalCostAmount().subtract(asset.getSalvageAmount()));
  109. +                   primaryDepreciationBaseAmount = asset.getTotalCostAmount().subtract(asset.getSalvageAmount());
  110.                      salvageRate = true;
  111. -                    primaryDepreciationBaseAmount = assetPaymentInfo.getPrimaryDepreciationBaseAmount();
  112.                  }
  113.  
  114. -                if (assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount() == null) {
  115. -                    assetPaymentInfo.setAccumulatedPrimaryDepreciationAmount(KualiDecimal.ZERO);
  116. +                KualiDecimal existingAccumulatedPrimaryDepreciation = assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount();
  117. +               if (existingAccumulatedPrimaryDepreciation == null) {
  118. +                   existingAccumulatedPrimaryDepreciation = KualiDecimal.ZERO;
  119.                  }
  120.  
  121.                  //Asset Reclassifications NWUKFS-1107
  122.                  Map<String, Object> params = new HashMap<String, Object>();
  123.                  params.put("capitalAssetNumber",assetPaymentInfo.getCapitalAssetNumber());
  124.                  params.put("paymentSequenceNumber",assetPaymentInfo.getPaymentSequenceNumber());
  125. -                AssetPaymentExtension extension = KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(AssetPaymentExtension.class,params);
  126. +                AssetPaymentExtension extension = getBusinessObjectService().findByPrimaryKey(AssetPaymentExtension.class,params);
  127.                  if (extension != null) {
  128.                      if (extension.getAssetReclassificationIndicator().equals("Y")) {
  129.                          assetReclass = true;
  130.                          if(salvageRate) {
  131. -                            assetPaymentInfo.setPrimaryDepreciationBaseAmount(assetPaymentInfo.getPrimaryDepreciationBaseAmount().subtract(assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount()));
  132. +                           primaryDepreciationBaseAmount = primaryDepreciationBaseAmount.subtract(existingAccumulatedPrimaryDepreciation);
  133.                          }else{
  134. -                            assetPaymentInfo.setPrimaryDepreciationBaseAmount(asset.getTotalCostAmount().subtract(assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount()));
  135. +                           primaryDepreciationBaseAmount = asset.getTotalCostAmount().subtract(existingAccumulatedPrimaryDepreciation);
  136.                          }
  137. -                        primaryDepreciationBaseAmount = assetPaymentInfo.getPrimaryDepreciationBaseAmount();
  138.                          //Normal depr monthElapsed adding extra month we don't want.
  139.                          monthsElapsed = (depreciationDate.get(Calendar.MONTH) - assetDepreciationDate.get(Calendar.MONTH) + (depreciationDate.get(Calendar.YEAR) - assetDepreciationDate.get(Calendar.YEAR)) * 12);
  140.                          //monthsElapsed = Months.monthsBetween(LocalDate.fromCalendarFields(assetDepreciationDate), LocalDate.fromCalendarFields(depreciationDate)).getMonths();
  141. @@ -135,40 +144,18 @@ public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch
  142.                          assetLifeInMonths = assetLifeInMonths - monthsElapsed;
  143.                      }
  144.                  }
  145. -
  146. -                // If the months elapsed >= to the life of the asset (in months) then, the accumulated depreciation should be:
  147. -                if (monthsElapsed >= assetLifeInMonths) {
  148. -                    if (CamsConstants.Asset.DEPRECIATION_METHOD_STRAIGHT_LINE_CODE.equals(assetPaymentInfo.getPrimaryDepreciationMethodCode())) {
  149. -                        accumulatedDepreciationAmount = primaryDepreciationBaseAmount;
  150. -                    }
  151. -                    else if (CamsConstants.Asset.DEPRECIATION_METHOD_SALVAGE_VALUE_CODE.equals(assetPaymentInfo.getPrimaryDepreciationMethodCode()) && deprAmountSum != null && deprAmountSum.isNonZero()) {
  152. -                        accumulatedDepreciationAmount = primaryDepreciationBaseAmount.subtract((primaryDepreciationBaseAmount.divide(deprAmountSum)).multiply(assetPaymentInfo.getSalvageAmount()));
  153. -                    }
  154. -                } // If the month elapse < to the life of the asset (in months) then....
  155. -                else {
  156. -                    if (CamsConstants.Asset.DEPRECIATION_METHOD_STRAIGHT_LINE_CODE.equals(assetPaymentInfo.getPrimaryDepreciationMethodCode())) {
  157. -                        accumulatedDepreciationAmount = new KualiDecimal((monthsElapsed / assetLifeInMonths) * primaryDepreciationBaseAmount.doubleValue());
  158. -                    }
  159. -                    else if (CamsConstants.Asset.DEPRECIATION_METHOD_SALVAGE_VALUE_CODE.equals(assetPaymentInfo.getPrimaryDepreciationMethodCode()) && deprAmountSum != null && deprAmountSum.isNonZero()) {
  160. -                        accumulatedDepreciationAmount = new KualiDecimal((monthsElapsed / assetLifeInMonths) * (primaryDepreciationBaseAmount.subtract((primaryDepreciationBaseAmount.divide(deprAmountSum)).multiply(assetPaymentInfo.getSalvageAmount()))).doubleValue());
  161. -                    }
  162. -                }
  163. -                // Calculating in process fiscal month depreciation amount
  164. -                KualiDecimal transactionAmount = KualiDecimal.ZERO;
  165. -                if (!assetReclass) {
  166. -                    transactionAmount = accumulatedDepreciationAmount.subtract(assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount());
  167. -                } else {
  168. -                    if (assetLifeInMonths > 0) {
  169. -                        if (CamsConstants.Asset.DEPRECIATION_METHOD_STRAIGHT_LINE_CODE.equals(assetPaymentInfo.getPrimaryDepreciationMethodCode())) {
  170. -                            transactionAmount = primaryDepreciationBaseAmount.divide(new KualiDecimal(assetLifeInMonths));
  171. -                            accumulatedDepreciationAmount = assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount().add(transactionAmount);
  172. -                        } else if (CamsConstants.Asset.DEPRECIATION_METHOD_SALVAGE_VALUE_CODE.equals(assetPaymentInfo.getPrimaryDepreciationMethodCode()) && deprAmountSum != null && deprAmountSum.isNonZero()) {
  173. -                            transactionAmount = (primaryDepreciationBaseAmount.subtract(assetPaymentInfo.getSalvageAmount())).divide(new KualiDecimal(assetLifeInMonths));
  174. -                            accumulatedDepreciationAmount = assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount().add(transactionAmount);
  175. -                        }
  176. -                    }
  177. -                }
  178. -
  179. +                
  180. +                final String primaryDepreciationMethodCode = assetPaymentInfo.getPrimaryDepreciationMethodCode();
  181. +                KualiDecimal salvageValueAssetDeprAmount = salvageValueAssetDeprAmounts.get(assetNumber);
  182. +                // start proposed carve-out to test the effect of negative amounts, asset older than depreciable life
  183. +                KualiDecimal[] depreciation = calculateDepreciation(
  184. +                       monthsElapsed, assetLifeInMonths,
  185. +                       assetReclass, salvageValueAssetDeprAmount,
  186. +                       primaryDepreciationBaseAmount, primaryDepreciationMethodCode,
  187. +                       existingAccumulatedPrimaryDepreciation, assetPaymentInfo.getSalvageAmount());
  188. +                KualiDecimal transactionAmount = depreciation[0];
  189. +                calculatedAccumulatedDepreciation = depreciation[1];
  190. +                // end of proposed carve-out
  191.  
  192.                  String transactionType = KFSConstants.GL_DEBIT_CODE;
  193.                  if (transactionAmount.isNegative()) {
  194. @@ -191,9 +178,10 @@ public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch
  195.                      LOG.error(CamsConstants.Depreciation.DEPRECIATION_BATCH + "Plant COA is " + plantCOA + " and plant account is " + plantAccount + " for Financial Object SubType Code = " + assetPaymentInfo.getFinancialObjectSubTypeCode() + " so Asset payment is not included in depreciation " + assetPaymentInfo.getCapitalAssetNumber() + " - " + assetPaymentInfo.getPaymentSequenceNumber());
  196.                      continue;
  197.                  }
  198. -                LOG.debug("Asset#: " + assetNumber + " - Payment sequence#:" + assetPaymentInfo.getPaymentSequenceNumber() + " - Asset Depreciation date:" + assetDepreciationDate + " - Life:" + assetLifeInMonths + " - Depreciation base amt:" + primaryDepreciationBaseAmount + " - Accumulated depreciation:" + assetPaymentInfo.getAccumulatedPrimaryDepreciationAmount() + " - Month Elapsed:" + monthsElapsed + " - Calculated accum depreciation:" + accumulatedDepreciationAmount + " - Depreciation amount:" + transactionAmount.toString() + " - Depreciation Method:" + assetPaymentInfo.getPrimaryDepreciationMethodCode() + " - Salvage Rate:" + salvageRate + "- Asset Reclass:" + assetReclass);
  199. -                assetPaymentInfo.setAccumulatedPrimaryDepreciationAmount(accumulatedDepreciationAmount);
  200. +                LOG.debug("Asset#: " + assetNumber + " - Payment sequence#:" + assetPaymentInfo.getPaymentSequenceNumber() + " - Asset Depreciation date:" + assetDepreciationDate + " - Life:" + assetLifeInMonths + " - Depreciation base amt:" + primaryDepreciationBaseAmount + " - Accumulated depreciation:" + existingAccumulatedPrimaryDepreciation + " - Month Elapsed:" + monthsElapsed + " - Calculated accum depreciation:" + calculatedAccumulatedDepreciation + " - Depreciation amount:" + transactionAmount.toString() + " - Depreciation Method:" + primaryDepreciationMethodCode + " - Salvage Rate:" + salvageRate + "- Asset Reclass:" + assetReclass);
  201. +                assetPaymentInfo.setAccumulatedPrimaryDepreciationAmount(calculatedAccumulatedDepreciation);
  202.                  assetPaymentInfo.setTransactionAmount(transactionAmount);
  203. +                assetPaymentInfo.setPrimaryDepreciationBaseAmount(primaryDepreciationBaseAmount);
  204.                  counter++;
  205.                  saveList.add(assetPaymentInfo);
  206.                  // Saving depreciation amount in the asset payment table
  207. @@ -217,4 +205,82 @@ public class AssetDepreciationServiceImpl extends org.kuali.kfs.module.cam.batch
  208.              throw new IllegalStateException(kualiConfigurationService.getPropertyValueAsString(CamsKeyConstants.Depreciation.ERROR_WHEN_CALCULATING_DEPRECIATION) + " :" + e.getMessage());
  209.          }
  210.      }
  211. +
  212. +   /**
  213. +    * @return the businessObjectService
  214. +    */
  215. +   public BusinessObjectService getBusinessObjectService() {
  216. +       if (businessObjectService == null) {
  217. +           businessObjectService = KRADServiceLocator.getBusinessObjectService();
  218. +       }
  219. +       return businessObjectService;
  220. +   }
  221. +  
  222. +   public ParameterService getParameterService() {
  223. +        if (parameterService == null) {
  224. +           parameterService = CoreFrameworkServiceLocator.getParameterService();
  225. +        }
  226. +        
  227. +        return parameterService;
  228. +    }
  229. +  
  230. +   /**
  231. +    * @param monthsElapsed - months since the asset was created
  232. +    * @param assetLifeInMonths - the asset Life In Months
  233. +    * @param assetReclass - whether asset reclassification has been done on this asset
  234. +    * @param salvageValueAssetDeprAmount - @see {@link org.kuali.kfs.module.cam.document.dataaccess.impl.DepreciationBatchDaoJdbc#getPrimaryDepreciationBaseAmountForSV()}
  235. +    * @param primaryDepreciationBaseAmount @see {@link org.kuali.kfs.module.cam.batch.AssetPaymentInfo#getPrimaryDepreciationBaseAmount()}
  236. +    * @param primaryDepreciationMethodCode - @see {@link org.kuali.kfs.module.cam.batch.AssetPaymentInfo#getPrimaryDepreciationMethodCode()}
  237. +    * @param existingAccumulatedPrimaryDepreciation - @see {@link org.kuali.kfs.module.cam.batch.AssetPaymentInfo#getAccumulatedPrimaryDepreciationAmount()}
  238. +    * @param salvageAmount - @see {@link org.kuali.kfs.module.cam.batch.AssetPaymentInfo#getSalvageAmount()}
  239. +    * @return an array with the depreciation amount for the current fiscal period at index 0, the calculated accumulated depreciation at index 1
  240. +    */
  241. +   protected KualiDecimal[] calculateDepreciation (double monthsElapsed,
  242. +           double assetLifeInMonths,
  243. +           boolean assetReclass, KualiDecimal salvageValueAssetDeprAmount,
  244. +           KualiDecimal primaryDepreciationBaseAmount,
  245. +           final String primaryDepreciationMethodCode,
  246. +           KualiDecimal existingAccumulatedPrimaryDepreciation, KualiDecimal salvageAmount) {
  247. +       KualiDecimal transactionAmount = KualiDecimal.ZERO;
  248. +       KualiDecimal accumulatedDepreciationAmount = KualiDecimal.ZERO;
  249. +       // If the months elapsed >= to the life of the asset (in months) then, the accumulated depreciation should be:
  250. +      
  251. +       if (monthsElapsed >= assetLifeInMonths) {
  252. +           if (CamsConstants.Asset.DEPRECIATION_METHOD_STRAIGHT_LINE_CODE.equals(primaryDepreciationMethodCode)) {
  253. +               accumulatedDepreciationAmount = primaryDepreciationBaseAmount;
  254. +           }
  255. +           else if (CamsConstants.Asset.DEPRECIATION_METHOD_SALVAGE_VALUE_CODE.equals(primaryDepreciationMethodCode) && salvageValueAssetDeprAmount != null && salvageValueAssetDeprAmount.isNonZero()) {
  256. +               accumulatedDepreciationAmount = primaryDepreciationBaseAmount.subtract((primaryDepreciationBaseAmount.divide(salvageValueAssetDeprAmount)).multiply(salvageAmount));
  257. +           }
  258. +       } // If the month elapse < to the life of the asset (in months) then....
  259. +       else {
  260. +           if (CamsConstants.Asset.DEPRECIATION_METHOD_STRAIGHT_LINE_CODE.equals(primaryDepreciationMethodCode)) {
  261. +               accumulatedDepreciationAmount = new KualiDecimal((monthsElapsed / assetLifeInMonths) * primaryDepreciationBaseAmount.doubleValue());
  262. +           }
  263. +           else if (CamsConstants.Asset.DEPRECIATION_METHOD_SALVAGE_VALUE_CODE.equals(primaryDepreciationMethodCode) && salvageValueAssetDeprAmount != null && salvageValueAssetDeprAmount.isNonZero()) {
  264. +               accumulatedDepreciationAmount = new KualiDecimal((monthsElapsed / assetLifeInMonths) * (primaryDepreciationBaseAmount.subtract((primaryDepreciationBaseAmount.divide(salvageValueAssetDeprAmount)).multiply(salvageAmount))).doubleValue());
  265. +           }
  266. +       }
  267. +       // Calculating in process fiscal month depreciation amount
  268. +      
  269. +       if (!assetReclass) {
  270. +           transactionAmount = accumulatedDepreciationAmount.subtract(existingAccumulatedPrimaryDepreciation);
  271. +       } else {
  272. +           if (assetLifeInMonths > 0) {
  273. +               if (CamsConstants.Asset.DEPRECIATION_METHOD_STRAIGHT_LINE_CODE.equals(primaryDepreciationMethodCode)) {
  274. +                   transactionAmount = primaryDepreciationBaseAmount.divide(new KualiDecimal(assetLifeInMonths));
  275. +                   accumulatedDepreciationAmount = existingAccumulatedPrimaryDepreciation.add(transactionAmount);
  276. +               } else if (CamsConstants.Asset.DEPRECIATION_METHOD_SALVAGE_VALUE_CODE.equals(primaryDepreciationMethodCode) && salvageValueAssetDeprAmount != null && salvageValueAssetDeprAmount.isNonZero()) {
  277. +                   transactionAmount = (primaryDepreciationBaseAmount.subtract(salvageAmount)).divide(new KualiDecimal(assetLifeInMonths));
  278. +                   accumulatedDepreciationAmount = existingAccumulatedPrimaryDepreciation.add(transactionAmount);
  279. +               }
  280. +           }
  281. +       }
  282. +      
  283. +       KualiDecimal[] results = new KualiDecimal[2];
  284. +       results[0] = transactionAmount;
  285. +       results[1] = accumulatedDepreciationAmount;
  286. +      
  287. +       return results;
  288. +   }
  289.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement