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.fp.document;
20  
21  import static org.kuali.kfs.sys.KFSConstants.FROM;
22  import static org.kuali.kfs.sys.KFSConstants.TO;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.fp.businessobject.GECSourceAccountingLine;
26  import org.kuali.kfs.fp.businessobject.GECTargetAccountingLine;
27  import org.kuali.kfs.integration.cam.CapitalAssetManagementModuleService;
28  import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry;
29  import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
30  import org.kuali.kfs.sys.context.SpringContext;
31  import org.kuali.kfs.sys.document.AmountTotaling;
32  import org.kuali.kfs.sys.document.Correctable;
33  import org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE;
34  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
35  import org.kuali.rice.kns.service.DataDictionaryService;
36  import org.kuali.rice.krad.document.Copyable;
37  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
38  import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
39  
40  
41  /**
42   * This is the business object that represents the GeneralErrorCorrectionDocument in Kuali. This is a transactional document that
43   * will eventually post transactions to the G/L. It integrates with workflow and also contains two groupings of accounting lines:
44   * from and to. From lines are the source lines, to lines are the target lines.
45   */
46  public class GeneralErrorCorrectionDocument extends CapitalAccountingLinesDocumentBase implements Copyable, Correctable, AmountTotaling, CapitalAssetEditable {
47      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(GeneralErrorCorrectionDocument.class);
48  
49      protected transient CapitalAssetManagementModuleService capitalAssetManagementModuleService;
50  
51      /**
52       * Initializes the array lists and some basic info.
53       */
54      public GeneralErrorCorrectionDocument() {
55          super();
56      }
57  
58      /**
59       * Overrides the base implementation to return "From".
60       * 
61       * @see org.kuali.kfs.sys.document.AccountingDocument#getSourceAccountingLinesSectionTitle()
62       */
63      @Override
64      public String getSourceAccountingLinesSectionTitle() {
65          return FROM;
66      }
67  
68      /**
69       * Overrides the base implementation to return "To".
70       * 
71       * @see org.kuali.kfs.sys.document.AccountingDocument#getTargetAccountingLinesSectionTitle()
72       */
73      @Override
74      public String getTargetAccountingLinesSectionTitle() {
75          return TO;
76      }
77  
78      /**
79       * @see org.kuali.kfs.sys.document.AccountingDocumentBase#getSourceAccountingLineClass()
80       */
81      @Override
82      public Class getSourceAccountingLineClass() {
83          return GECSourceAccountingLine.class;
84      }
85  
86      /**
87       * @see org.kuali.kfs.sys.document.AccountingDocumentBase#getTargetAccountingLineClass()
88       */
89      @Override
90      public Class getTargetAccountingLineClass() {
91          return GECTargetAccountingLine.class;
92      }
93  
94      /**
95       * Customizes a GLPE by setting financial document number, financial system origination code and document type code to null
96       * 
97       * @param transactionalDocument submitted accounting document
98       * @param accountingLine accounting line in document
99       * @param explicitEntry general ledger pending entry
100      * @see FinancialDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(FinancialDocument, AccountingLine,
101      *      GeneralLedgerPendingEntry)
102      */
103     @Override
104     public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
105         explicitEntry.setTransactionLedgerEntryDescription(buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(postable));
106 
107         // Clearing fields that are already handled by the parent algorithm - we don't actually want
108         // these to copy over from the accounting lines b/c they don't belong in the GLPEs
109         // if the aren't nulled, then GECs fail to post
110         explicitEntry.setReferenceFinancialDocumentNumber(null);
111         explicitEntry.setReferenceFinancialSystemOriginationCode(null);
112         explicitEntry.setReferenceFinancialDocumentTypeCode(null);
113     }
114 
115     /**
116      * Builds an appropriately formatted string to be used for the <code>transactionLedgerEntryDescription</code>. It is built
117      * using information from the <code>{@link AccountingLine}</code>. Format is "01-12345: blah blah blah".
118      * 
119      * @param line accounting line
120      * @param transactionalDocument submitted accounting document
121      * @return String formatted string to be used for transaction ledger entry description
122      */
123     protected String buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(GeneralLedgerPendingEntrySourceDetail line) {
124         String description = "";
125         description = line.getReferenceOriginCode() + "-" + line.getReferenceNumber();
126 
127         if (StringUtils.isNotBlank(line.getFinancialDocumentLineDescription())) {
128             description += ": " + line.getFinancialDocumentLineDescription();
129         }
130         else {
131             description += ": " + getDocumentHeader().getDocumentDescription();
132         }
133 
134         if (description.length() > GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH) {
135             description = description.substring(0, GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH - 3) + "...";
136         }
137 
138         return description;
139     }
140 
141     /**
142      * @see org.kuali.kfs.sys.document.GeneralLedgerPostingDocumentBase#doRouteStatusChange()
143      */
144     @Override
145     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
146         super.doRouteStatusChange(statusChangeEvent);
147         this.getCapitalAssetManagementModuleService().deleteDocumentAssetLocks(this);
148     }
149 
150 
151     /**
152      * @see org.kuali.rice.krad.document.DocumentBase#postProcessSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
153      */
154     @Override
155     public void postProcessSave(KualiDocumentEvent event) {
156         super.postProcessSave(event);
157         if (!(event instanceof SaveDocumentEvent)) { // don't lock until they route
158             String documentTypeName = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass());
159             this.getCapitalAssetManagementModuleService().generateCapitalAssetLock(this, documentTypeName);
160         }
161     }
162 
163     /**
164      * @return CapitalAssetManagementModuleService
165      */
166     public CapitalAssetManagementModuleService getCapitalAssetManagementModuleService() {
167         if (capitalAssetManagementModuleService == null) {
168             capitalAssetManagementModuleService = SpringContext.getBean(CapitalAssetManagementModuleService.class);
169         }
170         return capitalAssetManagementModuleService;
171     }
172 }