001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.pdp.businessobject; 017 018 import java.sql.Timestamp; 019 import java.text.ParseException; 020 import java.util.ArrayList; 021 import java.util.Date; 022 import java.util.LinkedHashMap; 023 import java.util.List; 024 025 import org.kuali.kfs.pdp.PdpPropertyConstants; 026 import org.kuali.kfs.sys.KFSPropertyConstants; 027 import org.kuali.kfs.sys.context.SpringContext; 028 import org.kuali.rice.kns.bo.TransientBusinessObjectBase; 029 import org.kuali.rice.kns.service.DateTimeService; 030 import org.kuali.rice.kns.util.KualiDecimal; 031 import org.kuali.rice.kns.util.KualiInteger; 032 033 /** 034 * Represents the parsed contents of an incoming payment file. 035 */ 036 public class PaymentFileLoad extends TransientBusinessObjectBase { 037 // header fields 038 private String chart; 039 private String unit; 040 private String subUnit; 041 private Timestamp creationDate; 042 043 // trailer fields 044 private int paymentCount; 045 private KualiDecimal paymentTotalAmount; 046 047 // data 048 private List<PaymentGroup> paymentGroups; 049 050 // load vars 051 private KualiInteger batchId; 052 private boolean fileThreshold; 053 private boolean detailThreshold; 054 private boolean taxEmailRequired; 055 056 private List<PaymentDetail> thresholdPaymentDetails; 057 private CustomerProfile customer; 058 059 private boolean passedValidation; 060 061 public PaymentFileLoad() { 062 super(); 063 paymentGroups = new ArrayList<PaymentGroup>(); 064 fileThreshold = false; 065 detailThreshold = false; 066 taxEmailRequired = false; 067 passedValidation = false; 068 thresholdPaymentDetails = new ArrayList<PaymentDetail>(); 069 } 070 071 /** 072 * @return number of detail records loaded 073 */ 074 public int getActualPaymentCount() { 075 int count = 0; 076 077 for (PaymentGroup paymentGroup : paymentGroups) { 078 for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) { 079 count++; 080 } 081 } 082 083 return count; 084 } 085 086 /** 087 * @return total amount of all payments 088 */ 089 public KualiDecimal getCalculatedPaymentTotalAmount() { 090 KualiDecimal totalAmount = KualiDecimal.ZERO; 091 092 for (PaymentGroup paymentGroup : paymentGroups) { 093 for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) { 094 totalAmount = totalAmount.add(paymentDetail.getAccountTotal()); 095 } 096 } 097 098 return totalAmount; 099 } 100 101 /** 102 * Gets the chart attribute. 103 * 104 * @return Returns the chart. 105 */ 106 public String getChart() { 107 return chart; 108 } 109 110 /** 111 * Sets the chart attribute value. 112 * 113 * @param chart The chart to set. 114 */ 115 public void setChart(String chart) { 116 this.chart = chart; 117 } 118 119 /** 120 * Gets the unit attribute. 121 * 122 * @return Returns the unit. 123 */ 124 public String getUnit() { 125 return unit; 126 } 127 128 /** 129 * Sets the unit attribute value. 130 * 131 * @param unit The unit to set. 132 */ 133 public void setUnit(String unit) { 134 this.unit = unit; 135 } 136 137 /** 138 * Gets the subUnit attribute. 139 * 140 * @return Returns the subUnit. 141 */ 142 public String getSubUnit() { 143 return subUnit; 144 } 145 146 /** 147 * Sets the subUnit attribute value. 148 * 149 * @param subUnit The subUnit to set. 150 */ 151 public void setSubUnit(String subUnit) { 152 this.subUnit = subUnit; 153 } 154 155 /** 156 * Gets the creationDate attribute. 157 * 158 * @return Returns the creationDate. 159 */ 160 public Timestamp getCreationDate() { 161 return creationDate; 162 } 163 164 /** 165 * Sets the creationDate attribute value. 166 * 167 * @param creationDate The creationDate to set. 168 */ 169 public void setCreationDate(Timestamp creationDate) { 170 this.creationDate = creationDate; 171 } 172 173 /** 174 * Takes a <code>String</code> and attempt to format as <code>Timestamp</code for setting the 175 * creationDate field 176 * 177 * @param creationDate Timestamp as string 178 */ 179 public void setCreationDate(String creationDate) { 180 try { 181 this.creationDate = SpringContext.getBean(DateTimeService.class).convertToSqlTimestamp(creationDate); 182 } 183 catch (ParseException e) { 184 throw new RuntimeException("Unable to convert create timestamp value " + creationDate + " :" + e.getMessage(), e); 185 } 186 } 187 188 /** 189 * Gets the paymentCount attribute. 190 * 191 * @return Returns the paymentCount. 192 */ 193 public int getPaymentCount() { 194 return paymentCount; 195 } 196 197 /** 198 * Sets the paymentCount attribute value. 199 * 200 * @param paymentCount The paymentCount to set. 201 */ 202 public void setPaymentCount(int paymentCount) { 203 this.paymentCount = paymentCount; 204 } 205 206 /** 207 * Helper method to set the paymentCount int from a string. 208 * 209 * @param paymentCount String payment count 210 */ 211 public void setPaymentCount(String paymentCount) { 212 this.paymentCount = Integer.parseInt(paymentCount); 213 } 214 215 /** 216 * Gets the paymentTotalAmount attribute. 217 * 218 * @return Returns the paymentTotalAmount. 219 */ 220 public KualiDecimal getPaymentTotalAmount() { 221 return paymentTotalAmount; 222 } 223 224 /** 225 * Sets the paymentTotalAmount attribute value. 226 * 227 * @param paymentTotalAmount The paymentTotalAmount to set. 228 */ 229 public void setPaymentTotalAmount(KualiDecimal paymentTotalAmount) { 230 this.paymentTotalAmount = paymentTotalAmount; 231 } 232 233 public void setPaymentTotalAmount(String paymentTotalAmount) { 234 this.paymentTotalAmount = new KualiDecimal(paymentTotalAmount); 235 } 236 237 /** 238 * Gets the paymentGroups attribute. 239 * 240 * @return Returns the paymentGroups. 241 */ 242 public List<PaymentGroup> getPaymentGroups() { 243 return paymentGroups; 244 } 245 246 /** 247 * Sets the paymentGroups attribute value. 248 * 249 * @param paymentGroups The paymentGroups to set. 250 */ 251 public void setPaymentGroups(List<PaymentGroup> paymentGroups) { 252 this.paymentGroups = paymentGroups; 253 } 254 255 /** 256 * Adds a <code>PaymentGroup</code> to the group <code>List</code> 257 * 258 * @param paymentGroup <code>PaymentGroup</code> to add 259 */ 260 public void addPaymentGroup(PaymentGroup paymentGroup) { 261 this.paymentGroups.add(paymentGroup); 262 } 263 264 /** 265 * Gets the fileThreshold attribute. 266 * 267 * @return Returns the fileThreshold. 268 */ 269 public boolean isFileThreshold() { 270 return fileThreshold; 271 } 272 273 /** 274 * Sets the fileThreshold attribute value. 275 * 276 * @param fileThreshold The fileThreshold to set. 277 */ 278 public void setFileThreshold(boolean fileThreshold) { 279 this.fileThreshold = fileThreshold; 280 } 281 282 /** 283 * Gets the detailThreshold attribute. 284 * 285 * @return Returns the detailThreshold. 286 */ 287 public boolean isDetailThreshold() { 288 return detailThreshold; 289 } 290 291 /** 292 * Sets the detailThreshold attribute value. 293 * 294 * @param detailThreshold The detailThreshold to set. 295 */ 296 public void setDetailThreshold(boolean detailThreshold) { 297 this.detailThreshold = detailThreshold; 298 } 299 300 301 /** 302 * Gets the batchId attribute. 303 * 304 * @return Returns the batchId. 305 */ 306 public KualiInteger getBatchId() { 307 return batchId; 308 } 309 310 /** 311 * Sets the batchId attribute value. 312 * 313 * @param batchId The batchId to set. 314 */ 315 public void setBatchId(KualiInteger batchId) { 316 this.batchId = batchId; 317 } 318 319 /** 320 * Gets the taxEmailRequired attribute. 321 * 322 * @return Returns the taxEmailRequired. 323 */ 324 public boolean isTaxEmailRequired() { 325 return taxEmailRequired; 326 } 327 328 /** 329 * Sets the taxEmailRequired attribute value. 330 * 331 * @param taxEmailRequired The taxEmailRequired to set. 332 */ 333 public void setTaxEmailRequired(boolean taxEmailRequired) { 334 this.taxEmailRequired = taxEmailRequired; 335 } 336 337 /** 338 * Gets the thresholdPaymentDetails attribute. 339 * 340 * @return Returns the thresholdPaymentDetails. 341 */ 342 public List<PaymentDetail> getThresholdPaymentDetails() { 343 return thresholdPaymentDetails; 344 } 345 346 /** 347 * Sets the thresholdPaymentDetails attribute value. 348 * 349 * @param thresholdPaymentDetails The thresholdPaymentDetails to set. 350 */ 351 public void setThresholdPaymentDetails(List<PaymentDetail> thresholdPaymentDetails) { 352 this.thresholdPaymentDetails = thresholdPaymentDetails; 353 } 354 355 /** 356 * Gets the passedValidation attribute. 357 * 358 * @return Returns the passedValidation. 359 */ 360 public boolean isPassedValidation() { 361 return passedValidation; 362 } 363 364 /** 365 * Sets the passedValidation attribute value. 366 * 367 * @param passedValidation The passedValidation to set. 368 */ 369 public void setPassedValidation(boolean passedValidation) { 370 this.passedValidation = passedValidation; 371 } 372 373 374 /** 375 * Gets the customer attribute. 376 * 377 * @return Returns the customer. 378 */ 379 public CustomerProfile getCustomer() { 380 return customer; 381 } 382 383 /** 384 * Sets the customer attribute value. 385 * 386 * @param customer The customer to set. 387 */ 388 public void setCustomer(CustomerProfile customer) { 389 this.customer = customer; 390 } 391 392 @Override 393 protected LinkedHashMap toStringMapper() { 394 LinkedHashMap m = new LinkedHashMap(); 395 396 m.put(KFSPropertyConstants.CHART, this.chart); 397 m.put(PdpPropertyConstants.UNIT, this.unit); 398 m.put(PdpPropertyConstants.SUB_UNIT, this.subUnit); 399 m.put(PdpPropertyConstants.CREATION_DATE, this.creationDate); 400 401 return m; 402 } 403 404 }