View Javadoc
1   /*
2    * Copyright 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  package org.kuali.ole.pdp.businessobject;
17  
18  import java.sql.Timestamp;
19  import java.text.ParseException;
20  import java.util.ArrayList;
21  import java.util.LinkedHashMap;
22  import java.util.List;
23  
24  import org.kuali.ole.pdp.PdpPropertyConstants;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.core.api.datetime.DateTimeService;
28  import org.kuali.rice.core.api.util.type.KualiDecimal;
29  import org.kuali.rice.core.api.util.type.KualiInteger;
30  import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
31  
32  /**
33   * Represents the parsed contents of an incoming payment file.
34   */
35  public class PaymentFileLoad extends TransientBusinessObjectBase {
36      // header fields
37      private String chart;
38      private String unit;
39      private String subUnit;
40      protected Timestamp creationDate;
41  
42      // trailer fields
43      private int paymentCount;
44      private KualiDecimal paymentTotalAmount;
45  
46      // data
47      private List<PaymentGroup> paymentGroups;
48  
49      // load vars
50      private KualiInteger batchId;
51      private boolean fileThreshold;
52      private boolean detailThreshold;
53      private boolean taxEmailRequired;
54  
55      private List<PaymentDetail> thresholdPaymentDetails;
56      private CustomerProfile customer;
57  
58      private boolean passedValidation;
59  
60      public PaymentFileLoad() {
61          super();
62          paymentGroups = new ArrayList<PaymentGroup>();
63          fileThreshold = false;
64          detailThreshold = false;
65          taxEmailRequired = false;
66          passedValidation = false;
67          thresholdPaymentDetails = new ArrayList<PaymentDetail>();
68      }
69  
70      /**
71       * @return number of detail records loaded
72       */
73      public int getActualPaymentCount() {
74          int count = 0;
75  
76          for (PaymentGroup paymentGroup : paymentGroups) {
77              for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
78                  count++;
79              }
80          }
81  
82          return count;
83      }
84  
85      /**
86       * @return total amount of all payments
87       */
88      public KualiDecimal getCalculatedPaymentTotalAmount() {
89          KualiDecimal totalAmount = KualiDecimal.ZERO;
90  
91          for (PaymentGroup paymentGroup : paymentGroups) {
92              for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) {
93                  totalAmount = totalAmount.add(paymentDetail.getAccountTotal());
94              }
95          }
96  
97          return totalAmount;
98      }
99  
100     /**
101      * Gets the chart attribute.
102      * 
103      * @return Returns the chart.
104      */
105     public String getChart() {
106         return chart;
107     }
108 
109     /**
110      * Sets the chart attribute value.
111      * 
112      * @param chart The chart to set.
113      */
114     public void setChart(String chart) {
115         this.chart = chart;
116     }
117 
118     /**
119      * Gets the unit attribute.
120      * 
121      * @return Returns the unit.
122      */
123     public String getUnit() {
124         return unit;
125     }
126 
127     /**
128      * Sets the unit attribute value.
129      * 
130      * @param unit The unit to set.
131      */
132     public void setUnit(String unit) {
133         this.unit = unit;
134     }
135 
136     /**
137      * Gets the subUnit attribute.
138      * 
139      * @return Returns the subUnit.
140      */
141     public String getSubUnit() {
142         return subUnit;
143     }
144 
145     /**
146      * Sets the subUnit attribute value.
147      * 
148      * @param subUnit The subUnit to set.
149      */
150     public void setSubUnit(String subUnit) {
151         this.subUnit = subUnit;
152     }
153 
154     /**
155      * Gets the creationDate attribute.
156      * 
157      * @return Returns the creationDate.
158      */
159     public Timestamp getCreationDate() {
160         return creationDate;
161     }
162 
163     /**
164      * Sets the creationDate attribute value.
165      * 
166      * @param creationDate The creationDate to set.
167      */
168     public void setCreationDate(Timestamp creationDate) {
169         this.creationDate = creationDate;
170     }
171     
172     /**
173      * Takes a <code>String</code> and attempt to format as <code>Timestamp</code for setting the
174      * creationDate field
175      * 
176      * @param creationDate Timestamp as string
177      */
178     public void setCreationDate(String creationDate) {
179         try {
180             this.creationDate = SpringContext.getBean(DateTimeService.class).convertToSqlTimestamp(creationDate);
181         }
182         catch (ParseException e) {
183             throw new RuntimeException("Unable to convert create timestamp value " + creationDate + " :" + e.getMessage(), e);
184         }
185     }
186 
187     /**
188      * Gets the paymentCount attribute.
189      * 
190      * @return Returns the paymentCount.
191      */
192     public int getPaymentCount() {
193         return paymentCount;
194     }
195 
196     /**
197      * Sets the paymentCount attribute value.
198      * 
199      * @param paymentCount The paymentCount to set.
200      */
201     public void setPaymentCount(int paymentCount) {
202         this.paymentCount = paymentCount;
203     }
204 
205     /**
206      * Helper method to set the paymentCount int from a string.
207      * 
208      * @param paymentCount String payment count
209      */
210     public void setPaymentCount(String paymentCount) {
211         this.paymentCount = Integer.parseInt(paymentCount);
212     }
213 
214     /**
215      * Gets the paymentTotalAmount attribute.
216      * 
217      * @return Returns the paymentTotalAmount.
218      */
219     public KualiDecimal getPaymentTotalAmount() {
220         return paymentTotalAmount;
221     }
222 
223     /**
224      * Sets the paymentTotalAmount attribute value.
225      * 
226      * @param paymentTotalAmount The paymentTotalAmount to set.
227      */
228     public void setPaymentTotalAmount(KualiDecimal paymentTotalAmount) {
229         this.paymentTotalAmount = paymentTotalAmount;
230     }
231     
232     public void setPaymentTotalAmount(String paymentTotalAmount) {
233         this.paymentTotalAmount = new KualiDecimal(paymentTotalAmount);
234     }
235 
236     /**
237      * Gets the paymentGroups attribute.
238      * 
239      * @return Returns the paymentGroups.
240      */
241     public List<PaymentGroup> getPaymentGroups() {
242         return paymentGroups;
243     }
244 
245     /**
246      * Sets the paymentGroups attribute value.
247      * 
248      * @param paymentGroups The paymentGroups to set.
249      */
250     public void setPaymentGroups(List<PaymentGroup> paymentGroups) {
251         this.paymentGroups = paymentGroups;
252     }
253 
254     /**
255      * Adds a <code>PaymentGroup</code> to the group <code>List</code>
256      * 
257      * @param paymentGroup <code>PaymentGroup</code> to add
258      */
259     public void addPaymentGroup(PaymentGroup paymentGroup) {
260         this.paymentGroups.add(paymentGroup);
261     }
262 
263     /**
264      * Gets the fileThreshold attribute.
265      * 
266      * @return Returns the fileThreshold.
267      */
268     public boolean isFileThreshold() {
269         return fileThreshold;
270     }
271 
272     /**
273      * Sets the fileThreshold attribute value.
274      * 
275      * @param fileThreshold The fileThreshold to set.
276      */
277     public void setFileThreshold(boolean fileThreshold) {
278         this.fileThreshold = fileThreshold;
279     }
280 
281     /**
282      * Gets the detailThreshold attribute.
283      * 
284      * @return Returns the detailThreshold.
285      */
286     public boolean isDetailThreshold() {
287         return detailThreshold;
288     }
289 
290     /**
291      * Sets the detailThreshold attribute value.
292      * 
293      * @param detailThreshold The detailThreshold to set.
294      */
295     public void setDetailThreshold(boolean detailThreshold) {
296         this.detailThreshold = detailThreshold;
297     }
298 
299 
300     /**
301      * Gets the batchId attribute.
302      * 
303      * @return Returns the batchId.
304      */
305     public KualiInteger getBatchId() {
306         return batchId;
307     }
308 
309     /**
310      * Sets the batchId attribute value.
311      * 
312      * @param batchId The batchId to set.
313      */
314     public void setBatchId(KualiInteger batchId) {
315         this.batchId = batchId;
316     }
317 
318     /**
319      * Gets the taxEmailRequired attribute.
320      * 
321      * @return Returns the taxEmailRequired.
322      */
323     public boolean isTaxEmailRequired() {
324         return taxEmailRequired;
325     }
326 
327     /**
328      * Sets the taxEmailRequired attribute value.
329      * 
330      * @param taxEmailRequired The taxEmailRequired to set.
331      */
332     public void setTaxEmailRequired(boolean taxEmailRequired) {
333         this.taxEmailRequired = taxEmailRequired;
334     }
335 
336     /**
337      * Gets the thresholdPaymentDetails attribute.
338      * 
339      * @return Returns the thresholdPaymentDetails.
340      */
341     public List<PaymentDetail> getThresholdPaymentDetails() {
342         return thresholdPaymentDetails;
343     }
344 
345     /**
346      * Sets the thresholdPaymentDetails attribute value.
347      * 
348      * @param thresholdPaymentDetails The thresholdPaymentDetails to set.
349      */
350     public void setThresholdPaymentDetails(List<PaymentDetail> thresholdPaymentDetails) {
351         this.thresholdPaymentDetails = thresholdPaymentDetails;
352     }
353 
354     /**
355      * Gets the passedValidation attribute.
356      * 
357      * @return Returns the passedValidation.
358      */
359     public boolean isPassedValidation() {
360         return passedValidation;
361     }
362 
363     /**
364      * Sets the passedValidation attribute value.
365      * 
366      * @param passedValidation The passedValidation to set.
367      */
368     public void setPassedValidation(boolean passedValidation) {
369         this.passedValidation = passedValidation;
370     }
371 
372 
373     /**
374      * Gets the customer attribute.
375      * 
376      * @return Returns the customer.
377      */
378     public CustomerProfile getCustomer() {
379         return customer;
380     }
381 
382     /**
383      * Sets the customer attribute value.
384      * 
385      * @param customer The customer to set.
386      */
387     public void setCustomer(CustomerProfile customer) {
388         this.customer = customer;
389     }
390 
391     
392     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
393         LinkedHashMap m = new LinkedHashMap();
394 
395         m.put(OLEPropertyConstants.CHART, this.chart);
396         m.put(PdpPropertyConstants.UNIT, this.unit);
397         m.put(PdpPropertyConstants.SUB_UNIT, this.subUnit);
398         m.put(PdpPropertyConstants.CREATION_DATE, this.creationDate);
399 
400         return m;
401     }
402 
403 }