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.module.ar.document.web.struts;
017
018 import java.io.Serializable;
019 import java.util.ArrayList;
020 import java.util.List;
021
022 import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail;
023 import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
024 import org.kuali.rice.kns.util.KualiDecimal;
025
026 public class PaymentApplicationInvoiceApply implements Serializable {
027
028 private CustomerInvoiceDocument invoice;
029 private List<PaymentApplicationInvoiceDetailApply> detailApplications;
030
031 private String payAppDocNumber;
032 private boolean quickApply;
033 private boolean quickApplyOldValue;
034
035 public PaymentApplicationInvoiceApply(String payAppDocNumber, CustomerInvoiceDocument invoice) {
036 this.invoice = invoice;
037 this.detailApplications = new ArrayList<PaymentApplicationInvoiceDetailApply>();
038 for (CustomerInvoiceDetail invoiceDetail : invoice.getCustomerInvoiceDetailsWithoutDiscounts()) {
039 this.detailApplications.add(new PaymentApplicationInvoiceDetailApply(payAppDocNumber, invoiceDetail));
040 }
041 this.quickApply = false;
042 this.quickApplyOldValue = false;
043 this.payAppDocNumber = payAppDocNumber;
044 }
045
046 public KualiDecimal getAmountToApply() {
047 KualiDecimal applyAmount = KualiDecimal.ZERO;
048 for (PaymentApplicationInvoiceDetailApply detailApplication : detailApplications) {
049 applyAmount = applyAmount.add(detailApplication.getAmountApplied());
050 }
051 return applyAmount;
052 }
053
054 // yes this method name is awkward. Blame JSP that expects an is* or get*
055 public boolean isAnyAppliedAmounts() {
056 for (PaymentApplicationInvoiceDetailApply detailApplication : detailApplications) {
057 if (detailApplication.getAmountApplied().isGreaterThan(KualiDecimal.ZERO)) {
058 return true;
059 }
060 }
061 return false;
062 }
063
064 public List<PaymentApplicationInvoiceDetailApply> getDetailApplications() {
065 return detailApplications;
066 }
067
068 public String getDocumentNumber() {
069 return invoice.getDocumentNumber();
070 }
071
072 public KualiDecimal getOpenAmount() {
073 return invoice.getOpenAmount();
074 }
075
076 public boolean isQuickApply() {
077 return quickApply;
078 }
079
080 public void setQuickApply(boolean quickApply) {
081 this.quickApplyOldValue = this.quickApply;
082 this.quickApply = quickApply;
083 for (PaymentApplicationInvoiceDetailApply detailApplication : detailApplications) {
084 detailApplication.setInvoiceQuickApplied(quickApply);
085 }
086 }
087
088 public boolean isQuickApplyChanged() {
089 return quickApply != quickApplyOldValue;
090 }
091
092 public CustomerInvoiceDocument getInvoice() {
093 return invoice;
094 }
095
096 }