View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.ar.util;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  
24  import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail;
25  import org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied;
26  import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
27  import org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService;
28  import org.kuali.kfs.sys.context.SpringContext;
29  import org.kuali.rice.core.api.util.type.KualiDecimal;
30  
31  public class CustomerInvoiceBalanceHelper {
32  
33      private CustomerInvoiceDocument invoice;
34      private Collection<InvoicePaidApplied> invoicePaidApplieds;
35      private Collection<CustomerInvoiceDetail> customerInvoiceDetails;
36  
37      public CustomerInvoiceBalanceHelper() {
38  
39      }
40  
41      public CustomerInvoiceBalanceHelper(CustomerInvoiceDocument invoice, Collection<InvoicePaidApplied> invoicePaidApplieds) {
42          this.invoice = invoice;
43          this.invoicePaidApplieds = new ArrayList<InvoicePaidApplied>(invoicePaidApplieds);
44      }
45  
46      /**
47       * This method calculates the invoice document balance as the difference between the open amount and the total applied amount
48       * @return the balance of the customer invoice document
49       */
50      public KualiDecimal getCalculatedBalance() {
51          return invoice.getTotalDollarAmount().subtract(getTotalAppliedAmountForAppDoc());
52      }
53      
54      /**
55       * This method gets the open amount of the ustomer invoice document
56       * @return the open amount of the invoice
57       */
58      public KualiDecimal getOpenAmount() {
59          CustomerInvoiceDocumentService customerInvoiceDocumentService = SpringContext.getBean(CustomerInvoiceDocumentService.class);
60          return customerInvoiceDocumentService.getOpenAmountForCustomerInvoiceDocument(this.invoice.getDocumentNumber());
61      }
62      
63      /**
64       * This method gets the total applied amount 
65       * @return the total applied amount
66       */
67      public KualiDecimal getTotalAppliedAmountForAppDoc() {
68          KualiDecimal appliedAmount = new KualiDecimal(0);
69          for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
70              appliedAmount = appliedAmount.add(invoicePaidApplied.getInvoiceItemAppliedAmount());
71          }
72          return appliedAmount;
73      }
74     
75  
76      /**
77       * This method gets the invoice
78       * @return
79       */
80      public CustomerInvoiceDocument getInvoice() {
81          return invoice;
82      }
83  
84      /**
85       * This method sets the invoice
86       * @param invoice
87       */
88      public void setInvoice(CustomerInvoiceDocument invoice) {
89          this.invoice = invoice;
90      }
91  
92      /**
93       * This method gets the invoice paid applieds
94       * @return
95       */
96      public Collection<InvoicePaidApplied> getInvoicePaidApplieds() {
97          return invoicePaidApplieds;
98      }
99  
100     /**
101      * This method sets the invoice paid applieds
102      * @param invoicePaidApplieds
103      */
104     public void setInvoicePaidApplieds(Collection<InvoicePaidApplied> invoicePaidApplieds) {
105         this.invoicePaidApplieds = invoicePaidApplieds;
106     }
107 
108 }