View Javadoc
1   /*
2    * Copyright 2006-2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * Created on Feb 28, 2006
18   *
19   */
20  package org.kuali.ole.module.purap.businessobject;
21  
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.core.api.datetime.DateTimeService;
24  import org.kuali.rice.core.api.util.type.KualiDecimal;
25  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
26  
27  import java.sql.Timestamp;
28  import java.util.LinkedHashMap;
29  
30  public class ElectronicInvoiceLoadSummary extends PersistableBusinessObjectBase {
31  
32      private Integer invoiceLoadSummaryIdentifier;
33      private String vendorDunsNumber; // this is string constant if DUNS not found
34      private Integer vendorHeaderGeneratedIdentifier;
35      private Integer vendorDetailAssignedIdentifier;
36      private String vendorName;
37      private Integer invoiceLoadSuccessCount = new Integer(0);
38      private KualiDecimal invoiceLoadSuccessAmount = new KualiDecimal(0.00);
39      private Integer invoiceLoadFailCount = new Integer(0);
40      private KualiDecimal invoiceLoadFailAmount = new KualiDecimal(0.00);
41      private Boolean isEmpty = Boolean.TRUE;
42      private Timestamp fileProcessTimestamp;
43  
44      public ElectronicInvoiceLoadSummary() {
45          super();
46      }
47  
48      public ElectronicInvoiceLoadSummary(String vendorDunsNumber) {
49          super();
50          this.vendorDunsNumber = vendorDunsNumber;
51      }
52  
53      public void addSuccessfulInvoiceOrder(KualiDecimal amount,
54                                            ElectronicInvoice eInvoice) {
55          isEmpty = Boolean.FALSE;
56          invoiceLoadSuccessCount = new Integer(invoiceLoadSuccessCount.intValue() + 1);
57          fileProcessTimestamp = SpringContext.getBean(DateTimeService.class).getCurrentTimestamp();
58  
59          if (amount != null) {
60              invoiceLoadSuccessAmount = invoiceLoadSuccessAmount.add(amount);
61          }
62  
63          setupVendorInformation(eInvoice);
64      }
65  
66      public void addFailedInvoiceOrder(KualiDecimal amount,
67                                        ElectronicInvoice eInvoice) {
68          isEmpty = Boolean.FALSE;
69          invoiceLoadFailCount = new Integer(invoiceLoadFailCount.intValue() + 1);
70          fileProcessTimestamp = SpringContext.getBean(DateTimeService.class).getCurrentTimestamp();
71  
72          if (amount != null) {
73              invoiceLoadFailAmount = invoiceLoadFailAmount.add(amount);
74          }
75  
76          setupVendorInformation(eInvoice);
77      }
78  
79      public void addFailedInvoiceOrder(ElectronicInvoice ei) {
80          this.addFailedInvoiceOrder(new KualiDecimal(0), ei);
81      }
82  
83      public void addFailedInvoiceOrder() {
84          this.addFailedInvoiceOrder(new KualiDecimal(0), null);
85      }
86  
87      private void setupVendorInformation(ElectronicInvoice eInvoice) {
88  
89          if (eInvoice != null &&
90                  getVendorHeaderGeneratedIdentifier() == null &&
91                  getVendorDetailAssignedIdentifier() == null) {
92  
93              setVendorHeaderGeneratedIdentifier(eInvoice.getVendorHeaderID());
94              setVendorDetailAssignedIdentifier(eInvoice.getVendorDetailID());
95              setVendorName(eInvoice.getVendorName());
96  
97          }
98      }
99  
100     public String getVendorDescriptor() {
101         String kualiDescriptor = null;
102         if ((this.vendorName != null) && (this.vendorHeaderGeneratedIdentifier != null) && (this.vendorDetailAssignedIdentifier != null)) {
103             kualiDescriptor = "  (Kuali Match:  " + this.vendorName + "  ~  " + vendorHeaderGeneratedIdentifier + "-" + vendorDetailAssignedIdentifier + ")";
104         } else if ((this.vendorHeaderGeneratedIdentifier != null) && (this.vendorDetailAssignedIdentifier != null)) {
105             kualiDescriptor = "  (Kuali Match:  " + vendorHeaderGeneratedIdentifier + "-" + vendorDetailAssignedIdentifier + ")";
106         } else if (this.vendorName != null) {
107             kualiDescriptor = "  (Kuali Match:  " + this.vendorName + ")";
108         }
109         return this.getVendorDunsNumber() + ((kualiDescriptor != null) ? kualiDescriptor : "");
110     }
111 
112     /**
113      * @return the vendorDetailAssignedIdentifier
114      */
115     public Integer getVendorDetailAssignedIdentifier() {
116         return vendorDetailAssignedIdentifier;
117     }
118 
119     /**
120      * @param vendorDetailAssignedIdentifier the vendorDetailAssignedIdentifier to set
121      */
122     public void setVendorDetailAssignedIdentifier(Integer kualiVendorDetailId) {
123         this.vendorDetailAssignedIdentifier = kualiVendorDetailId;
124     }
125 
126     /**
127      * @return the vendorHeaderGeneratedIdentifier
128      */
129     public Integer getVendorHeaderGeneratedIdentifier() {
130         return vendorHeaderGeneratedIdentifier;
131     }
132 
133     /**
134      * @param vendorHeaderGeneratedIdentifier
135      *         the vendorHeaderGeneratedIdentifier to set
136      */
137     public void setVendorHeaderGeneratedIdentifier(Integer kualiVendorHeaderId) {
138         this.vendorHeaderGeneratedIdentifier = kualiVendorHeaderId;
139     }
140 
141     /**
142      * @return the vendorName
143      */
144     public String getVendorName() {
145         return vendorName;
146     }
147 
148     /**
149      * @param vendorName the vendorName to set
150      */
151     public void setVendorName(String kualiVendorName) {
152         this.vendorName = kualiVendorName;
153     }
154 
155     /**
156      * @return the invoiceLoadFailAmount
157      */
158     public KualiDecimal getInvoiceLoadFailAmount() {
159         return invoiceLoadFailAmount;
160     }
161 
162     /**
163      * @param invoiceLoadFailAmount the invoiceLoadFailAmount to set
164      */
165     public void setInvoiceLoadFailAmount(KualiDecimal failAmount) {
166         this.invoiceLoadFailAmount = failAmount;
167     }
168 
169     /**
170      * @return the invoiceLoadFailCount
171      */
172     public Integer getInvoiceLoadFailCount() {
173         return invoiceLoadFailCount;
174     }
175 
176     /**
177      * @param invoiceLoadFailCount the invoiceLoadFailCount to set
178      */
179     public void setInvoiceLoadFailCount(Integer failCount) {
180         this.invoiceLoadFailCount = failCount;
181     }
182 
183     /**
184      * @return the invoiceLoadSummaryIdentifier
185      */
186     public Integer getInvoiceLoadSummaryIdentifier() {
187         return invoiceLoadSummaryIdentifier;
188     }
189 
190     /**
191      * @param invoiceLoadSummaryIdentifier the invoiceLoadSummaryIdentifier to set
192      */
193     public void setInvoiceLoadSummaryIdentifier(Integer id) {
194         this.invoiceLoadSummaryIdentifier = id;
195     }
196 
197     /**
198      * @return the isEmpty
199      */
200     public Boolean isEmpty() {
201         return isEmpty;
202     }
203 
204     /**
205      * @param isEmpty the isEmpty to set
206      */
207     public void setIsEmpty(Boolean isEmpty) {
208         this.isEmpty = isEmpty;
209     }
210 
211     /**
212      * @return the invoiceLoadSuccessAmount
213      */
214     public KualiDecimal getInvoiceLoadSuccessAmount() {
215         return invoiceLoadSuccessAmount;
216     }
217 
218     /**
219      * @param invoiceLoadSuccessAmount the invoiceLoadSuccessAmount to set
220      */
221     public void setInvoiceLoadSuccessAmount(KualiDecimal successAmount) {
222         this.invoiceLoadSuccessAmount = successAmount;
223     }
224 
225     /**
226      * @return the invoiceLoadSuccessCount
227      */
228     public Integer getInvoiceLoadSuccessCount() {
229         return invoiceLoadSuccessCount;
230     }
231 
232     /**
233      * @param invoiceLoadSuccessCount the invoiceLoadSuccessCount to set
234      */
235     public void setInvoiceLoadSuccessCount(Integer successCount) {
236         this.invoiceLoadSuccessCount = successCount;
237     }
238 
239     /**
240      * @return the vendorDunsNumber
241      */
242     public String getVendorDunsNumber() {
243         return vendorDunsNumber;
244     }
245 
246     /**
247      * @param vendorDunsNumber the vendorDunsNumber to set
248      */
249     public void setVendorDunsNumber(String vendorDunsNumber) {
250         this.vendorDunsNumber = vendorDunsNumber;
251     }
252 
253     public Timestamp getFileProcessTimestamp() {
254         return fileProcessTimestamp;
255     }
256 
257     public void setFileProcessTimestamp(Timestamp fileProcessTimestamp) {
258         this.fileProcessTimestamp = fileProcessTimestamp;
259     }
260 
261     /**
262      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
263      */
264     protected LinkedHashMap toStringMapper() {
265         LinkedHashMap m = new LinkedHashMap();
266         m.put("invoiceLoadSummaryIdentifier", this.invoiceLoadSummaryIdentifier);
267         return m;
268     }
269 }