001/* 002 * Copyright 2008 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.pdp.businessobject; 017 018import java.sql.Timestamp; 019import java.text.ParseException; 020import java.util.ArrayList; 021import java.util.LinkedHashMap; 022import java.util.List; 023 024import org.kuali.ole.pdp.PdpPropertyConstants; 025import org.kuali.ole.sys.OLEPropertyConstants; 026import org.kuali.ole.sys.context.SpringContext; 027import org.kuali.rice.core.api.datetime.DateTimeService; 028import org.kuali.rice.core.api.util.type.KualiDecimal; 029import org.kuali.rice.core.api.util.type.KualiInteger; 030import org.kuali.rice.krad.bo.TransientBusinessObjectBase; 031 032/** 033 * Represents the parsed contents of an incoming payment file. 034 */ 035public class PaymentFileLoad extends TransientBusinessObjectBase { 036 // header fields 037 private String chart; 038 private String unit; 039 private String subUnit; 040 protected Timestamp creationDate; 041 042 // trailer fields 043 private int paymentCount; 044 private KualiDecimal paymentTotalAmount; 045 046 // data 047 private List<PaymentGroup> paymentGroups; 048 049 // load vars 050 private KualiInteger batchId; 051 private boolean fileThreshold; 052 private boolean detailThreshold; 053 private boolean taxEmailRequired; 054 055 private List<PaymentDetail> thresholdPaymentDetails; 056 private CustomerProfile customer; 057 058 private boolean passedValidation; 059 060 public PaymentFileLoad() { 061 super(); 062 paymentGroups = new ArrayList<PaymentGroup>(); 063 fileThreshold = false; 064 detailThreshold = false; 065 taxEmailRequired = false; 066 passedValidation = false; 067 thresholdPaymentDetails = new ArrayList<PaymentDetail>(); 068 } 069 070 /** 071 * @return number of detail records loaded 072 */ 073 public int getActualPaymentCount() { 074 int count = 0; 075 076 for (PaymentGroup paymentGroup : paymentGroups) { 077 for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) { 078 count++; 079 } 080 } 081 082 return count; 083 } 084 085 /** 086 * @return total amount of all payments 087 */ 088 public KualiDecimal getCalculatedPaymentTotalAmount() { 089 KualiDecimal totalAmount = KualiDecimal.ZERO; 090 091 for (PaymentGroup paymentGroup : paymentGroups) { 092 for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) { 093 totalAmount = totalAmount.add(paymentDetail.getAccountTotal()); 094 } 095 } 096 097 return totalAmount; 098 } 099 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}