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.cab.businessobject;
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.LinkedHashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.kfs.module.cab.CabConstants;
29  import org.kuali.kfs.module.cab.CabPropertyConstants;
30  import org.kuali.kfs.module.purap.document.PaymentRequestDocument;
31  import org.kuali.kfs.module.purap.document.VendorCreditMemoDocument;
32  import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
33  import org.kuali.kfs.sys.context.SpringContext;
34  import org.kuali.rice.kew.api.KewApiServiceLocator;
35  import org.kuali.rice.kew.api.doctype.DocumentType;
36  import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
37  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
38  import org.kuali.rice.krad.service.BusinessObjectService;
39  import org.kuali.rice.krad.util.ObjectUtils;
40  
41  /**
42   * @author Kuali Nervous System Team (kualidev@oncourse.iu.edu)
43   */
44  public class PurchasingAccountsPayableDocument extends PersistableBusinessObjectBase {
45  
46      private String documentNumber;
47      private Integer purapDocumentIdentifier;
48      private Integer purchaseOrderIdentifier;
49      private String documentTypeCode;
50      private String activityStatusCode;
51  
52      // References
53      private DocumentTypeEBO financialSystemDocumentTypeCode;
54      private FinancialSystemDocumentHeader documentHeader;
55      private List<PurchasingAccountsPayableItemAsset> purchasingAccountsPayableItemAssets;
56  
57      // non-persistent
58      private boolean active;
59      private String purApContactEmailAddress;
60      private String purApContactPhoneNumber;
61      private String statusDescription;
62      private String capitalAssetSystemTypeCodeFromPurAp;
63  
64      public PurchasingAccountsPayableDocument() {
65          this.purchasingAccountsPayableItemAssets = new ArrayList<PurchasingAccountsPayableItemAsset>();
66      }
67  
68  
69      /**
70       * Gets the capitalAssetSystemTypeCodeFromPurAp attribute.
71       * @return Returns the capitalAssetSystemTypeCodeFromPurAp.
72       */
73      public String getCapitalAssetSystemTypeCodeFromPurAp() {
74          return capitalAssetSystemTypeCodeFromPurAp;
75      }
76  
77  
78      /**
79       * Sets the capitalAssetSystemTypeCodeFromPurAp attribute value.
80       * @param capitalAssetSystemTypeCodeFromPurAp The capitalAssetSystemTypeCodeFromPurAp to set.
81       */
82      public void setCapitalAssetSystemTypeCodeFromPurAp(String capitalAssetSystemTypeCodeFromPurAp) {
83          this.capitalAssetSystemTypeCodeFromPurAp = capitalAssetSystemTypeCodeFromPurAp;
84      }
85  
86  
87      /**
88       * Gets the documentNumber attribute.
89       *
90       * @return Returns the documentNumber.
91       */
92      public String getDocumentNumber() {
93          return documentNumber;
94      }
95  
96  
97      /**
98       * Sets the documentNumber attribute value.
99       *
100      * @param documentNumber The documentNumber to set.
101      */
102     public void setDocumentNumber(String documentNumber) {
103         this.documentNumber = documentNumber;
104     }
105 
106 
107     /**
108      * Gets the purapDocumentIdentifier attribute.
109      *
110      * @return Returns the purapDocumentIdentifier.
111      */
112     public Integer getPurapDocumentIdentifier() {
113         return purapDocumentIdentifier;
114     }
115 
116 
117     /**
118      * Sets the purapDocumentIdentifier attribute value.
119      *
120      * @param purapDocumentIdentifier The purapDocumentIdentifier to set.
121      */
122     public void setPurapDocumentIdentifier(Integer purapDocumentIdentifier) {
123         this.purapDocumentIdentifier = purapDocumentIdentifier;
124     }
125 
126 
127     /**
128      * Gets the purchaseOrderIdentifier attribute.
129      *
130      * @return Returns the purchaseOrderIdentifier.
131      */
132     public Integer getPurchaseOrderIdentifier() {
133         return purchaseOrderIdentifier;
134     }
135 
136 
137     /**
138      * Sets the purchaseOrderIdentifier attribute value.
139      *
140      * @param purchaseOrderIdentifier The purchaseOrderIdentifier to set.
141      */
142     public void setPurchaseOrderIdentifier(Integer purchaseOrderIdentifier) {
143         this.purchaseOrderIdentifier = purchaseOrderIdentifier;
144     }
145 
146 
147     /**
148      * Gets the documentTypeCode attribute.
149      *
150      * @return Returns the documentTypeCode.
151      */
152     public String getDocumentTypeCode() {
153         return documentTypeCode;
154     }
155 
156 
157     /**
158      * Sets the documentTypeCode attribute value.
159      *
160      * @param documentTypeCode The documentTypeCode to set.
161      */
162     public void setDocumentTypeCode(String documentTypeCode) {
163         this.documentTypeCode = documentTypeCode;
164     }
165 
166 
167     /**
168      * Gets the active attribute.
169      *
170      * @return Returns the active.
171      */
172     public boolean isActive() {
173         return CabConstants.ActivityStatusCode.NEW.equalsIgnoreCase(this.getActivityStatusCode()) || CabConstants.ActivityStatusCode.MODIFIED.equalsIgnoreCase(this.getActivityStatusCode());
174     }
175 
176 
177     /**
178      * Gets the activityStatusCode attribute.
179      *
180      * @return Returns the activityStatusCode.
181      */
182     public String getActivityStatusCode() {
183         return activityStatusCode;
184     }
185 
186 
187     /**
188      * Sets the activityStatusCode attribute value.
189      *
190      * @param activityStatusCode The activityStatusCode to set.
191      */
192     public void setActivityStatusCode(String activityStatusCode) {
193         this.activityStatusCode = activityStatusCode;
194     }
195 
196 
197     /**
198      * Gets the financialSystemDocumentTypeCode attribute.
199      *
200      * @return Returns the financialSystemDocumentTypeCode.
201      */
202     public DocumentTypeEBO getFinancialSystemDocumentTypeCode() {
203         if ( financialSystemDocumentTypeCode == null || !StringUtils.equals(financialSystemDocumentTypeCode.getName(), documentTypeCode) ) {
204             financialSystemDocumentTypeCode = null;
205             if ( StringUtils.isNotBlank(documentTypeCode) ) {
206                 DocumentType docType = KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeCode);
207                 if ( docType != null ) {
208                     financialSystemDocumentTypeCode = org.kuali.rice.kew.doctype.bo.DocumentType.from(docType);
209                 }
210             }
211         }
212         return financialSystemDocumentTypeCode;
213     }
214 
215     /**
216      * Gets the documentHeader attribute.
217      *
218      * @return Returns the documentHeader.
219      */
220     public FinancialSystemDocumentHeader getDocumentHeader() {
221         return documentHeader;
222     }
223 
224 
225     /**
226      * Sets the documentHeader attribute value.
227      *
228      * @param documentHeader The documentHeader to set.
229      */
230     public void setDocumentHeader(FinancialSystemDocumentHeader documentHeader) {
231         this.documentHeader = documentHeader;
232     }
233 
234 
235     /**
236      * Gets the purchasingAccountsPayableItemAssets attribute.
237      *
238      * @return Returns the purchasingAccountsPayableItemAssets.
239      */
240     public List<PurchasingAccountsPayableItemAsset> getPurchasingAccountsPayableItemAssets() {
241         return purchasingAccountsPayableItemAssets;
242     }
243 
244 
245     /**
246      * Sets the purchasingAccountsPayableItemAssets attribute value.
247      *
248      * @param purchasingAccountsPayableItemAssets The purchasingAccountsPayableItemAssets to set.
249      */
250     public void setPurchasingAccountsPayableItemAssets(List<PurchasingAccountsPayableItemAsset> purchasingAccountsPayableItemAssets) {
251         this.purchasingAccountsPayableItemAssets = purchasingAccountsPayableItemAssets;
252     }
253 
254 
255     /**
256      * Gets the purApContactEmailAddress attribute.
257      *
258      * @return Returns the purApContactEmailAddress.
259      */
260     public String getPurApContactEmailAddress() {
261         return purApContactEmailAddress;
262     }
263 
264 
265     /**
266      * Sets the purApContactEmailAddress attribute value.
267      *
268      * @param purApContactEmailAddress The purApContactEmailAddress to set.
269      */
270     public void setPurApContactEmailAddress(String purApContactEmailAddress) {
271         this.purApContactEmailAddress = purApContactEmailAddress;
272     }
273 
274 
275     /**
276      * Gets the purApContactPhoneNumber attribute.
277      *
278      * @return Returns the purApContactPhoneNumber.
279      */
280     public String getPurApContactPhoneNumber() {
281         return purApContactPhoneNumber;
282     }
283 
284 
285     /**
286      * Sets the purApContactPhoneNumber attribute value.
287      *
288      * @param purApContactPhoneNumber The purApContactPhoneNumber to set.
289      */
290     public void setPurApContactPhoneNumber(String purApContactPhoneNumber) {
291         this.purApContactPhoneNumber = purApContactPhoneNumber;
292     }
293 
294 
295     /**
296      * Gets the statusDescription attribute.
297      *
298      * @return Returns the statusDescription.
299      */
300     public String getStatusDescription() {
301         String statusCode;
302 
303         if (StringUtils.isNotBlank(this.statusDescription)) {
304             return this.statusDescription;
305         }
306         else {
307             Map objectKeys = new HashMap();
308             objectKeys.put(CabPropertyConstants.PurchasingAccountsPayableDocument.PURAP_DOCUMENT_IDENTIFIER, this.getPurapDocumentIdentifier());
309 
310             if (CabConstants.PREQ.equals(this.documentTypeCode)) {
311 
312                 PaymentRequestDocument paymentRequestDocument = (PaymentRequestDocument) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(PaymentRequestDocument.class, objectKeys);
313                 if (ObjectUtils.isNotNull(paymentRequestDocument)) {
314                     statusDescription = paymentRequestDocument.getApplicationDocumentStatus();
315                 }
316             }
317             else {
318                 VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(VendorCreditMemoDocument.class, objectKeys);
319                 if (ObjectUtils.isNotNull(vendorCreditMemoDocument)) {
320                     statusDescription = vendorCreditMemoDocument.getApplicationDocumentStatus();
321                 }
322             }
323         }
324 
325         return statusDescription;
326     }
327 
328 
329     /**
330      * Sets the statusDescription attribute value.
331      *
332      * @param statusDescription The statusDescription to set.
333      */
334     public void setStatusDescription(String statusDescription) {
335         this.statusDescription = statusDescription;
336     }
337 
338 
339     /**
340      * Need to override this method, so we can save item assets, the framework can delete the allocated item assets.
341      *
342      * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#buildListOfDeletionAwareLists()
343      */
344 
345     @Override
346     public List buildListOfDeletionAwareLists() {
347         List<List> managedLists = new ArrayList<List>();
348 
349         managedLists.add(getPurchasingAccountsPayableItemAssets());
350         return managedLists;
351     }
352 
353     /**
354      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
355      */
356     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
357         LinkedHashMap m = new LinkedHashMap();
358         m.put("documentNumber", this.documentNumber);
359         return m;
360     }
361 
362     public PurchasingAccountsPayableItemAsset getPurchasingAccountsPayableItemAsset(int index) {
363         int size = getPurchasingAccountsPayableItemAssets().size();
364         while (size <= index || getPurchasingAccountsPayableItemAssets().get(index) == null) {
365             getPurchasingAccountsPayableItemAssets().add(size++, new PurchasingAccountsPayableItemAsset());
366         }
367         return getPurchasingAccountsPayableItemAssets().get(index);
368 
369     }
370 
371 }