1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.fp.document;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.kuali.ole.fp.businessobject.InternalBillingItem;
23  import org.kuali.ole.integration.cam.CapitalAssetManagementModuleService;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.businessobject.AccountingLine;
26  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.sys.document.AmountTotaling;
29  import org.kuali.ole.sys.document.Correctable;
30  import org.kuali.ole.sys.document.service.DebitDeterminerService;
31  import org.kuali.rice.core.api.util.type.KualiDecimal;
32  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
33  import org.kuali.rice.kns.service.DataDictionaryService;
34  import org.kuali.rice.krad.document.Copyable;
35  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
36  import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
37  
38  
39  
40  
41  
42  
43  
44  public class InternalBillingDocument extends CapitalAccountingLinesDocumentBase implements Copyable, Correctable, AmountTotaling {
45  
46      protected List items;
47      protected Integer nextItemLineNumber;
48  
49      protected transient CapitalAssetManagementModuleService capitalAssetManagementModuleService;
50  
51      
52  
53  
54      public InternalBillingDocument() {
55          super();
56          setItems(new ArrayList());
57          this.nextItemLineNumber = new Integer(1);
58      }
59  
60      
61  
62  
63  
64  
65  
66  
67  
68  
69  
70      @Override
71      public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) {
72          DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
73          return isDebitUtils.isDebitConsideringSection(this, (AccountingLine) postable);
74      }
75      
76      
77  
78  
79  
80  
81      public void addItem(InternalBillingItem item) {
82          item.setItemSequenceId(this.nextItemLineNumber);
83          this.items.add(item);
84          this.nextItemLineNumber = new Integer(this.nextItemLineNumber.intValue() + 1);
85      }
86  
87      
88  
89  
90  
91  
92  
93  
94      public InternalBillingItem getItem(int index) {
95          while (getItems().size() <= index) {
96              getItems().add(new InternalBillingItem());
97          }
98          return (InternalBillingItem) getItems().get(index);
99      }
100 
101     
102 
103 
104     public List getItems() {
105         return items;
106     }
107 
108     
109 
110 
111 
112 
113     public KualiDecimal getItemTotal() {
114         KualiDecimal total = KualiDecimal.ZERO;
115         for (Iterator iterator = items.iterator(); iterator.hasNext();) {
116             total = total.add(((InternalBillingItem) iterator.next()).getTotal());
117         }
118         return total;
119     }
120 
121     
122 
123 
124 
125 
126     public Integer getNextItemLineNumber() {
127         return this.nextItemLineNumber;
128     }
129 
130     
131 
132 
133     public void setItems(List items) {
134         this.items = items;
135     }
136 
137     
138 
139 
140 
141 
142 
143     public void setNextItemLineNumber(Integer nextItemLineNumber) {
144         this.nextItemLineNumber = nextItemLineNumber;
145     }
146 
147     
148 
149 
150     @Override
151     public String getSourceAccountingLinesSectionTitle() {
152         return OLEConstants.INCOME;
153     }
154 
155     
156 
157 
158     @Override
159     public String getTargetAccountingLinesSectionTitle() {
160         return OLEConstants.EXPENSE;
161     }
162 
163     
164 
165 
166     @Override
167     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
168         super.doRouteStatusChange(statusChangeEvent);
169         this.getCapitalAssetManagementModuleService().deleteDocumentAssetLocks(this);
170     }
171 
172 
173     
174 
175 
176     @Override
177     public void postProcessSave(KualiDocumentEvent event) {
178         super.postProcessSave(event);
179         if (!(event instanceof SaveDocumentEvent)) { 
180             String documentTypeName = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass());
181             this.getCapitalAssetManagementModuleService().generateCapitalAssetLock(this, documentTypeName);
182         }
183     }
184 
185 
186     
187 
188 
189     CapitalAssetManagementModuleService getCapitalAssetManagementModuleService() {
190         if (capitalAssetManagementModuleService == null) {
191             capitalAssetManagementModuleService = SpringContext.getBean(CapitalAssetManagementModuleService.class);
192         }
193         return capitalAssetManagementModuleService;
194     }
195 }