View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.cam.document.service;
20  
21  import java.util.List;
22  
23  import org.kuali.kfs.module.cam.CamsConstants;
24  import org.kuali.kfs.module.cam.businessobject.Asset;
25  import org.kuali.kfs.module.cam.businessobject.AssetPayment;
26  import org.kuali.kfs.module.cam.businessobject.AssetRetirementGlobal;
27  import org.kuali.kfs.module.cam.businessobject.AssetRetirementGlobalDetail;
28  import org.kuali.kfs.module.cam.document.gl.AssetRetirementGeneralLedgerPendingEntrySource;
29  import org.kuali.kfs.module.cam.fixture.AssetRetirementGlobalMaintainableFixture;
30  import org.kuali.kfs.sys.ConfigureContext;
31  import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
32  import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
33  import org.kuali.kfs.sys.context.KualiTestBase;
34  import org.kuali.kfs.sys.context.SpringContext;
35  import org.kuali.kfs.sys.fixture.UserNameFixture;
36  import org.kuali.kfs.sys.service.UniversityDateService;
37  import org.kuali.rice.core.api.util.type.KualiDecimal;
38  import org.kuali.rice.kns.document.MaintenanceDocument;
39  import org.kuali.rice.krad.service.DocumentService;
40  
41  public class AssetRetirementServiceTest extends KualiTestBase {
42      private AssetRetirementService assetRetirementService;
43      private UniversityDateService universityDateService;
44  
45      @Override
46      @ConfigureContext(session = UserNameFixture.bomiddle, shouldCommitTransactions = false)
47      protected void setUp() throws Exception {
48          super.setUp();
49          assetRetirementService = SpringContext.getBean(AssetRetirementService.class);
50          universityDateService = SpringContext.getBean(UniversityDateService.class);
51      }
52  
53  
54      /**
55       * Test capital asset with active payments
56       * 
57       * @throws Exception
58       */
59      @ConfigureContext(session = UserNameFixture.bomiddle, shouldCommitTransactions = false)
60      public void testCreateGLPostables_Success() throws Exception {
61          MaintenanceDocument document = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getNewDocument(CamsConstants.DocumentTypeName.ASSET_RETIREMENT_GLOBAL);
62          AssetRetirementGlobal assetRetirementGlobal = AssetRetirementGlobalMaintainableFixture.RETIREMENT1.newAssetRetirement();
63          // create poster
64          AssetRetirementGeneralLedgerPendingEntrySource assetRetirementGlPoster = new AssetRetirementGeneralLedgerPendingEntrySource((FinancialSystemDocumentHeader) document.getDocumentHeader());
65          assetRetirementService.createGLPostables(assetRetirementGlobal, assetRetirementGlPoster);
66          List<GeneralLedgerPendingEntrySourceDetail> postables = assetRetirementGlPoster.getPostables();
67  
68          assertFalse(postables.isEmpty());
69          assertEquals(10, postables.size());
70  
71          int i = 0;
72          for (AssetRetirementGlobalDetail detail : assetRetirementGlobal.getAssetRetirementGlobalDetails()) {
73              Asset asset = detail.getAsset();
74              // assert gl postable for first payment
75              AssetPayment payment1 = asset.getAssetPayments().get(0);
76              assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment1.getAccountChargeAmount(), "9520004", "Asset retirement cost reversal entry", "8610");
77              assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment1.getAccumulatedPrimaryDepreciationAmount(), "9520004", "Asset retirement depreciation reversal", "8910");
78              assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment1.getAccountChargeAmount().subtract(payment1.getAccumulatedPrimaryDepreciationAmount()), "9520004", "Asset retirement fund balance adjustment", "4998");
79  
80              AssetPayment payment2 = asset.getAssetPayments().get(1);
81              assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment2.getAccountChargeAmount(), "9520004", "Asset retirement cost reversal entry", "8610");
82              assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment2.getAccumulatedPrimaryDepreciationAmount(), "9520004", "Asset retirement depreciation reversal", "8910");
83          }
84      }
85  
86      /**
87       * Assert GL postable entry
88       * 
89       * @param glPostable
90       * @param chartOfAccountsCode
91       * @param amount
92       * @param plantAccount
93       * @param financialLineDesc
94       * @param financialObjectCode
95       */
96      private void assertGLPostable(GeneralLedgerPendingEntrySourceDetail glPostable, String chartOfAccountsCode, KualiDecimal amount, String plantAccount, String financialLineDesc, String financialObjectCode) {
97          assertEquals(plantAccount, glPostable.getAccountNumber());
98          assertEquals(amount, glPostable.getAmount());
99          assertEquals(CamsConstants.Postable.GL_BALANCE_TYPE_CODE_AC, glPostable.getBalanceTypeCode());
100         assertEquals(chartOfAccountsCode, glPostable.getChartOfAccountsCode());
101         assertEquals(financialLineDesc, glPostable.getFinancialDocumentLineDescription());
102         assertEquals(financialObjectCode, glPostable.getFinancialObjectCode());
103         assertEquals(this.universityDateService.getCurrentFiscalYear(), glPostable.getPostingYear());
104         assertNull(glPostable.getOrganizationReferenceId());
105         assertNull(glPostable.getProjectCode());
106         assertNull(glPostable.getReferenceNumber());
107         assertNull(glPostable.getReferenceOriginCode());
108         assertNull(glPostable.getReferenceTypeCode());
109     }
110 }
111