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.businessobject;
20  
21  import java.util.ArrayList;
22  import java.util.LinkedHashMap;
23  import java.util.List;
24  
25  import org.kuali.kfs.integration.ar.AccountsReceivablePredeterminedBillingSchedule;
26  import org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAward;
27  import org.kuali.kfs.integration.cg.ContractsAndGrantsModuleBillingService;
28  import org.kuali.kfs.sys.KFSPropertyConstants;
29  import org.kuali.kfs.sys.context.SpringContext;
30  import org.kuali.rice.core.api.config.property.ConfigurationService;
31  import org.kuali.rice.core.api.util.type.KualiDecimal;
32  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
33  import org.kuali.rice.krad.util.ObjectUtils;
34  
35  
36  
37  /**
38   * Created a Predetermined Billing Schedule maintenance Document parameter
39   */
40  public class PredeterminedBillingSchedule extends PersistableBusinessObjectBase implements AccountsReceivablePredeterminedBillingSchedule {
41  
42      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PredeterminedBillingSchedule.class);
43  
44      private static final String PREDETERMINED_BILLING_SCHEDULE_INQUIRY_TITLE_PROPERTY = "message.inquiry.predetermined.billing.schedule.title";
45      private Long proposalNumber;
46  
47      private String predeterminedBillingScheduleInquiryTitle;
48  
49      private List<Bill> bills;
50      private ContractsAndGrantsBillingAward award;
51  
52      public PredeterminedBillingSchedule() {
53          // Must use ArrayList because its get() method automatically grows the array for Struts.
54          bills = new ArrayList<Bill>();
55      }
56  
57  
58      /**
59       * Constructs an Milestone Schedule with parameter Award
60       *
61       * @param proposal
62       */
63      public PredeterminedBillingSchedule(ContractsAndGrantsBillingAward award) {
64          this();
65      }
66  
67  
68      /**
69       * Gets the proposalNumber attribute.
70       *
71       * @return Returns the proposalNumber.
72       */
73      @Override
74      public Long getProposalNumber() {
75          return proposalNumber;
76      }
77  
78  
79      /**
80       * Sets the proposalNumber attribute value.
81       *
82       * @param proposalNumber The proposalNumber to set.
83       */
84      public void setProposalNumber(Long proposalNumber) {
85  
86          this.proposalNumber = proposalNumber;
87      }
88  
89      /**
90       * Gets the totalAmountScheduled attribute.
91       *
92       * @return Returns the totalAmountScheduled.
93       */
94      @Override
95      public KualiDecimal getTotalAmountScheduled() {
96          KualiDecimal total = KualiDecimal.ZERO;
97          for (Bill bill: bills) {
98              if (ObjectUtils.isNotNull(bill.getEstimatedAmount()) && bill.isActive()) {
99                  total = total.add(bill.getEstimatedAmount());
100             }
101         }
102         return total;
103     }
104 
105     /**
106      * Gets the totalAmountRemaining attribute.
107      *
108      * @return Returns the totalAmountRemaining.
109      */
110     @Override
111     public KualiDecimal getTotalAmountRemaining() {
112         KualiDecimal total = KualiDecimal.ZERO;
113         if (ObjectUtils.isNotNull(award) && ObjectUtils.isNotNull(award.getAwardTotalAmount())) {
114             total = award.getAwardTotalAmount().subtract(getTotalAmountScheduled());
115         }
116         return total;
117     }
118 
119     /**
120      * Gets the predeterminedBillingScheduleInquiryTitle attribute.
121      *
122      * @return Returns the predeterminedBillingScheduleInquiryTitle.
123      */
124     @Override
125     public String getPredeterminedBillingScheduleInquiryTitle() {
126         return SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PREDETERMINED_BILLING_SCHEDULE_INQUIRY_TITLE_PROPERTY);
127 
128     }
129 
130 
131     /**
132      * Sets the predeterminedBillingScheduleInquiryTitle attribute value.
133      *
134      * @param predeterminedBillingScheduleInquiryTitle The predeterminedBillingScheduleInquiryTitle to set.
135      */
136     public void setPredeterminedBillingScheduleInquiryTitle(String predeterminedBillingScheduleInquiryTitle) {
137         this.predeterminedBillingScheduleInquiryTitle = predeterminedBillingScheduleInquiryTitle;
138     }
139 
140 
141     /**
142      * Gets the bills attribute.
143      *
144      * @return Returns the bills.
145      */
146     public List<Bill> getBills() {
147         return bills;
148     }
149 
150 
151     /**
152      * Sets the bills attribute value.
153      *
154      * @param bills The bills to set.
155      */
156     public void setBills(List<Bill> bills) {
157         this.bills = bills;
158     }
159 
160 
161     /**
162      * Gets the award attribute.
163      *
164      * @return Returns the award.
165      */
166     @Override
167     public ContractsAndGrantsBillingAward getAward() {
168         award = SpringContext.getBean(ContractsAndGrantsModuleBillingService.class).updateAwardIfNecessary(proposalNumber, award);
169         return award;
170     }
171 
172 
173     /**
174      * Sets the award attribute value.
175      *
176      * @param award The award to set.
177      */
178     public void setAward(ContractsAndGrantsBillingAward award) {
179         this.award = award;
180     }
181 
182 
183     /**
184      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
185      */
186     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
187         LinkedHashMap<String, String> m = new LinkedHashMap<String, String>();
188         m.put(KFSPropertyConstants.PROPOSAL_NUMBER, this.proposalNumber.toString());
189         m.put("totalAmountScheduled", getTotalAmountScheduled().toString());
190         m.put("totalAmountRemaining", getTotalAmountRemaining().toString());
191         return m;
192     }
193 
194 
195 }