View Javadoc
1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.ole.sys.businessobject;
18  
19  import java.util.LinkedHashMap;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.coa.businessobject.AccountingPeriod;
23  import org.kuali.ole.fp.businessobject.AdvanceDepositDetail;
24  import org.kuali.ole.fp.document.AdvanceDepositDocument;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.kew.api.exception.WorkflowException;
28  import org.kuali.rice.krad.bo.DocumentHeader;
29  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
30  import org.kuali.rice.krad.service.DocumentService;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  /**
34   * This class is used to represent an electronic payment claim.
35   */
36  public class ElectronicPaymentClaim extends PersistableBusinessObjectBase {
37      
38      public final static class ClaimStatusCodes {
39          public final static String CLAIMED = "C";
40          public final static String UNCLAIMED = "U";
41      }
42  
43      private String documentNumber;
44      private Integer financialDocumentLineNumber;
45      private String referenceFinancialDocumentNumber;
46      private Integer financialDocumentPostingYear;
47      private String financialDocumentPostingPeriodCode;
48      private String paymentClaimStatusCode;
49      
50      private AdvanceDepositDocument generatingDocument;
51      private SourceAccountingLine generatingAccountingLine;
52      private AccountingPeriod financialDocumentPostingPeriod;
53      private DocumentHeader generatingDocumentHeader;
54  
55      /**
56       * Default constructor.  It constructs.
57       */
58      public ElectronicPaymentClaim() {}
59  
60      /**
61       * Gets the documentNumber attribute.
62       * 
63       * @return Returns the documentNumber
64       */
65      public String getDocumentNumber() {
66          return documentNumber;
67      }
68  
69      /**
70       * Sets the documentNumber attribute.
71       * 
72       * @param documentNumber The documentNumber to set.
73       */
74      public void setDocumentNumber(String documentNumber) {
75          this.documentNumber = documentNumber;
76      }
77  
78  
79      /**
80       * Gets the financialDocumentLineNumber attribute.
81       * 
82       * @return Returns the financialDocumentLineNumber
83       */
84      public Integer getFinancialDocumentLineNumber() {
85          return financialDocumentLineNumber;
86      }
87  
88      /**
89       * Sets the financialDocumentLineNumber attribute.
90       * 
91       * @param financialDocumentLineNumber The financialDocumentLineNumber to set.
92       */
93      public void setFinancialDocumentLineNumber(Integer financialDocumentLineNumber) {
94          this.financialDocumentLineNumber = financialDocumentLineNumber;
95      }
96  
97  
98      /**
99       * Gets the referenceFinancialDocumentNumber attribute.
100      * 
101      * @return Returns the referenceFinancialDocumentNumber
102      */
103     public String getReferenceFinancialDocumentNumber() {
104         return referenceFinancialDocumentNumber;
105     }
106 
107     /**
108      * Sets the referenceFinancialDocumentNumber attribute.
109      * 
110      * @param referenceFinancialDocumentNumber The referenceFinancialDocumentNumber to set.
111      */
112     public void setReferenceFinancialDocumentNumber(String referenceFinancialDocumentNumber) {
113         this.referenceFinancialDocumentNumber = referenceFinancialDocumentNumber;
114     }
115 
116 
117     /**
118      * Gets the financialDocumentPostingYear attribute.
119      * 
120      * @return Returns the financialDocumentPostingYear
121      */
122     public Integer getFinancialDocumentPostingYear() {
123         return financialDocumentPostingYear;
124     }
125 
126     /**
127      * Sets the financialDocumentPostingYear attribute.
128      * 
129      * @param financialDocumentPostingYear The financialDocumentPostingYear to set.
130      */
131     public void setFinancialDocumentPostingYear(Integer financialDocumentPostingYear) {
132         this.financialDocumentPostingYear = financialDocumentPostingYear;
133     }
134 
135 
136     /**
137      * Gets the financialDocumentPostingPeriodCode attribute.
138      * 
139      * @return Returns the financialDocumentPostingPeriodCode
140      */
141     public String getFinancialDocumentPostingPeriodCode() {
142         return financialDocumentPostingPeriodCode;
143     }
144 
145     /**
146      * Sets the financialDocumentPostingPeriodCode attribute.
147      * 
148      * @param financialDocumentPostingPeriodCode The financialDocumentPostingPeriodCode to set.
149      */
150     public void setFinancialDocumentPostingPeriodCode(String financialDocumentPostingPeriodCode) {
151         this.financialDocumentPostingPeriodCode = financialDocumentPostingPeriodCode;
152     }
153 
154     /**
155      * Gets the paymentClaimStatusCode attribute. 
156      * @return Returns the paymentClaimStatusCode.
157      */
158     public String getPaymentClaimStatusCode() {
159         return paymentClaimStatusCode;
160     }
161 
162     /**
163      * Sets the paymentClaimStatusCode attribute value.
164      * @param paymentClaimStatusCode The paymentClaimStatusCode to set.
165      */
166     public void setPaymentClaimStatusCode(String paymentClaimStatusCode) {
167         this.paymentClaimStatusCode = paymentClaimStatusCode;
168     }
169 
170     /**
171      * Gets the generatingDocument attribute. 
172      * @return Returns the generatingDocument.
173      */
174     public AdvanceDepositDocument getGeneratingDocument() {
175         final boolean docNumbersAreDifferentAndNotNull = (generatingDocumentHeader != null && !documentNumber.equals(this.generatingDocumentHeader.getDocumentNumber()));
176         if (StringUtils.isNotBlank(documentNumber) && (this.generatingDocument == null || docNumbersAreDifferentAndNotNull)) {
177             try {
178                 generatingDocument = (AdvanceDepositDocument)SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentNumber);
179             }
180             catch (WorkflowException we) {
181                 throw new RuntimeException("Could not retrieve Document #"+documentNumber, we);
182             }
183         }
184         return this.generatingDocument;
185     }
186     
187     /**
188      * Gets the generatingDocumentHeader attribute. 
189      * @return Returns the generatingDocumentHeader.
190      */
191     public DocumentHeader getGeneratingDocumentHeader() {
192         return generatingDocumentHeader;
193     }
194 
195     /**
196      * Sets the generatingDocumentHeader attribute value.
197      * @param generatingDocumentHeader The generatingDocumentHeader to set.
198      * @deprecated
199      */
200     public void setGeneratingDocumentHeader(DocumentHeader generatingDocumentHeader) {
201         this.generatingDocumentHeader = generatingDocumentHeader;
202     }
203 
204     /**
205      * Returns the accounting line on the generating Advance Deposit document for the transaction which generated this record
206      * @return the accounting line that describes the transaction responsible for the creation of this record
207      */
208     public SourceAccountingLine getGeneratingAccountingLine() {
209         if (generatingAccountingLine == null) {
210             final AdvanceDepositDocument generatingDocument = getGeneratingDocument();
211             if (generatingDocument != null && generatingDocument.getSourceAccountingLines() != null) {
212                 int count = 0;
213                 
214                 while (generatingAccountingLine == null && count < generatingDocument.getSourceAccountingLines().size()) {
215                     if (generatingDocument.getSourceAccountingLine(count).getSequenceNumber().equals(getFinancialDocumentLineNumber())) {
216                         generatingAccountingLine = generatingDocument.getSourceAccountingLine(count);
217                     }
218                     count += 1;
219                 }
220                 
221             }
222         }
223         return generatingAccountingLine;
224     }
225     
226     /**
227      * Returns the AdvanceDepositDetail for the first deposit detail on this document
228      * @return the advance deposit detail that describes the transaction responsible for the creation of this record
229      */
230     public AdvanceDepositDetail getGeneratingAdvanceDepositDetail() {
231         final AdvanceDepositDocument generatingDocument = getGeneratingDocument();
232         if (generatingDocument != null && !ObjectUtils.isNull(generatingDocument.getAdvanceDeposits()) && !generatingDocument.getAdvanceDeposits().isEmpty()) {
233             return generatingDocument.getAdvanceDepositDetail(0);
234         }
235         return null;
236     }
237 
238     /**
239      * Gets the financialDocumentPostingPeriod attribute. 
240      * @return Returns the financialDocumentPostingPeriod.
241      */
242     public AccountingPeriod getFinancialDocumentPostingPeriod() {
243         return financialDocumentPostingPeriod;
244     }
245 
246     /**
247      * Sets the financialDocumentPostingPeriod attribute value.
248      * @param financialDocumentPostingPeriod The financialDocumentPostingPeriod to set.
249      */
250     public void setFinancialDocumentPostingPeriod(AccountingPeriod financialDocumentPostingPeriod) {
251         this.financialDocumentPostingPeriod = financialDocumentPostingPeriod;
252     }
253     
254     /**
255      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
256      */
257     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
258         LinkedHashMap m = new LinkedHashMap();
259         m.put(OLEPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
260         if (this.financialDocumentLineNumber != null) {
261             m.put("financialDocumentLineNumber", this.financialDocumentLineNumber.toString());
262         }
263         return m;
264     }
265     
266     /**
267      * Returns the String representation for an Electronic Payment Claim record, to be used by the claimed
268      * checkbox
269      * @param claim a claim to get a String representation for
270      * @return the representation in the form of "{generating document number}::{generating document accounting line sequence number}"
271      */
272     public String getElectronicPaymentClaimRepresentation() {
273         StringBuilder representation = new StringBuilder();
274         representation.append(getDocumentNumber());
275         representation.append("::");
276         representation.append(getFinancialDocumentLineNumber());
277         return representation.toString();
278     }
279     
280     /**
281      * @return a descriptive version of the paymentClaimStatusCode field
282      */
283     public String getPaymentClaimStatus() {
284         return getPaymentClaimStatusCode().equals("C") ? "Claimed" : "Unclaimed";
285     }
286 }