View Javadoc
1   /*
2    * Copyright 2007 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  package org.kuali.ole.vnd.businessobject;
18  
19  import java.sql.Date;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.apache.commons.lang.builder.EqualsBuilder;
25  import org.apache.log4j.Logger;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.ole.vnd.document.service.VendorService;
28  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
29  import org.kuali.rice.core.api.util.type.KualiDecimal;
30  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
31  import org.kuali.rice.krad.util.ObjectUtils;
32  
33  /**
34   * Purchasing Contracts with specific Vendors.
35   */
36  public class VendorContract extends PersistableBusinessObjectBase implements VendorRoutingComparable, MutableInactivatable {
37      protected static final Logger LOG = Logger.getLogger(VendorContract.class);
38  
39      protected Integer vendorContractGeneratedIdentifier;
40      protected Integer vendorHeaderGeneratedIdentifier;
41      protected Integer vendorDetailAssignedIdentifier;
42      protected String vendorNumber; // not persisted in db, only for lookup page
43      protected String vendorContractName;
44      protected String vendorContractDescription;
45      protected String vendorCampusCode;
46      protected Date vendorContractBeginningDate;
47      protected Date vendorContractEndDate;
48      protected Integer contractManagerCode;
49      protected String purchaseOrderCostSourceCode;
50      protected String vendorPaymentTermsCode;
51      protected String vendorShippingPaymentTermsCode;
52      protected String vendorShippingTitleCode;
53      protected Date vendorContractExtensionDate;
54      protected Boolean vendorB2bIndicator;
55      protected KualiDecimal organizationAutomaticPurchaseOrderLimit;
56      protected boolean active;
57  
58      protected List<VendorContractOrganization> vendorContractOrganizations;
59  
60      protected VendorDetail vendorDetail;
61      protected CampusParameter vendorCampus;
62      protected ContractManager contractManager;
63      protected PurchaseOrderCostSource purchaseOrderCostSource;
64      protected PaymentTermType vendorPaymentTerms;
65      protected ShippingPaymentTerms vendorShippingPaymentTerms;
66      protected ShippingTitle vendorShippingTitle;
67  
68      /**
69       * Default constructor.
70       */
71      public VendorContract() {
72          vendorContractOrganizations = new ArrayList<VendorContractOrganization>();
73      }
74  
75      public Integer getVendorContractGeneratedIdentifier() {
76  
77          return vendorContractGeneratedIdentifier;
78      }
79  
80      public void setVendorContractGeneratedIdentifier(Integer vendorContractGeneratedIdentifier) {
81          this.vendorContractGeneratedIdentifier = vendorContractGeneratedIdentifier;
82      }
83  
84      public Integer getVendorHeaderGeneratedIdentifier() {
85  
86          return vendorHeaderGeneratedIdentifier;
87      }
88  
89      public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
90          this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
91      }
92  
93      public Integer getVendorDetailAssignedIdentifier() {
94  
95          return vendorDetailAssignedIdentifier;
96      }
97  
98      public void setVendorDetailAssignedIdentifier(Integer vendorDetailAssignedIdentifier) {
99          this.vendorDetailAssignedIdentifier = vendorDetailAssignedIdentifier;
100     }
101 
102     public String getVendorContractName() {
103 
104         return vendorContractName;
105     }
106 
107     public void setVendorContractName(String vendorContractName) {
108         this.vendorContractName = vendorContractName;
109     }
110 
111     public String getVendorContractDescription() {
112 
113         return vendorContractDescription;
114     }
115 
116     public void setVendorContractDescription(String vendorContractDescription) {
117         this.vendorContractDescription = vendorContractDescription;
118     }
119 
120     public String getVendorCampusCode() {
121 
122         return vendorCampusCode;
123     }
124 
125     public void setVendorCampusCode(String vendorCampusCode) {
126         this.vendorCampusCode = vendorCampusCode;
127     }
128 
129     public Date getVendorContractBeginningDate() {
130 
131         return vendorContractBeginningDate;
132     }
133 
134     public void setVendorContractBeginningDate(Date vendorContractBeginningDate) {
135         this.vendorContractBeginningDate = vendorContractBeginningDate;
136     }
137 
138     public Date getVendorContractEndDate() {
139 
140         return vendorContractEndDate;
141     }
142 
143     public void setVendorContractEndDate(Date vendorContractEndDate) {
144         this.vendorContractEndDate = vendorContractEndDate;
145     }
146 
147     public Integer getContractManagerCode() {
148 
149         return contractManagerCode;
150     }
151 
152     public void setContractManagerCode(Integer contractManagerCode) {
153         this.contractManagerCode = contractManagerCode;
154     }
155 
156     public String getPurchaseOrderCostSourceCode() {
157 
158         return purchaseOrderCostSourceCode;
159     }
160 
161     public void setPurchaseOrderCostSourceCode(String purchaseOrderCostSourceCode) {
162         this.purchaseOrderCostSourceCode = purchaseOrderCostSourceCode;
163     }
164 
165     public String getVendorPaymentTermsCode() {
166 
167         return vendorPaymentTermsCode;
168     }
169 
170     public void setVendorPaymentTermsCode(String vendorPaymentTermsCode) {
171         this.vendorPaymentTermsCode = vendorPaymentTermsCode;
172     }
173 
174     public String getVendorShippingPaymentTermsCode() {
175 
176         return vendorShippingPaymentTermsCode;
177     }
178 
179     public void setVendorShippingPaymentTermsCode(String vendorShippingPaymentTermsCode) {
180         this.vendorShippingPaymentTermsCode = vendorShippingPaymentTermsCode;
181     }
182 
183     public String getVendorShippingTitleCode() {
184 
185         return vendorShippingTitleCode;
186     }
187 
188     public void setVendorShippingTitleCode(String vendorShippingTitleCode) {
189         this.vendorShippingTitleCode = vendorShippingTitleCode;
190     }
191 
192     public Date getVendorContractExtensionDate() {
193 
194         return vendorContractExtensionDate;
195     }
196 
197     public void setVendorContractExtensionDate(Date vendorContractExtensionDate) {
198         this.vendorContractExtensionDate = vendorContractExtensionDate;
199     }
200 
201     public Boolean getVendorB2bIndicator() {
202 
203         return vendorB2bIndicator;
204     }
205 
206     public void setVendorB2bIndicator(Boolean vendorB2bIndicator) {
207         this.vendorB2bIndicator = vendorB2bIndicator;
208     }
209 
210     public KualiDecimal getOrganizationAutomaticPurchaseOrderLimit() {
211 
212         return organizationAutomaticPurchaseOrderLimit;
213     }
214 
215     public void setOrganizationAutomaticPurchaseOrderLimit(KualiDecimal organizationAutomaticPurchaseOrderLimit) {
216         this.organizationAutomaticPurchaseOrderLimit = organizationAutomaticPurchaseOrderLimit;
217     }
218 
219     @Override
220     public boolean isActive() {
221 
222         return active;
223     }
224 
225     @Override
226     public void setActive(boolean active) {
227         this.active = active;
228     }
229 
230     public VendorDetail getVendorDetail() {
231 
232         return vendorDetail;
233     }
234 
235     /**
236      * Sets the vendorDetail attribute.
237      * 
238      * @param vendorDetail The vendorDetail to set.
239      * @deprecated
240      */
241     public void setVendorDetail(VendorDetail vendorDetail) {
242         this.vendorDetail = vendorDetail;
243     }
244 
245 
246     public CampusParameter getVendorCampus() {
247         return vendorCampus;
248     }
249 
250     /**
251      * Sets the vendorCampus attribute.
252      * 
253      * @param vendorCampus The vendorCampus to set.
254      * @deprecated
255      */
256     public void setVendorCampus(CampusParameter vendorCampus) {
257         this.vendorCampus = vendorCampus;
258     }
259 
260     public ContractManager getContractManager() {
261 
262         return contractManager;
263     }
264 
265     /**
266      * Sets the contractManager attribute.
267      * 
268      * @param contractManager The contractManager to set.
269      * @deprecated
270      */
271     public void setContractManager(ContractManager contractManager) {
272         this.contractManager = contractManager;
273     }
274 
275     public PurchaseOrderCostSource getPurchaseOrderCostSource() {
276 
277         return purchaseOrderCostSource;
278     }
279 
280     /**
281      * Sets the purchaseOrderCostSource attribute.
282      * 
283      * @param purchaseOrderCostSource The purchaseOrderCostSource to set.
284      * @deprecated
285      */
286     public void setPurchaseOrderCostSource(PurchaseOrderCostSource purchaseOrderCostSource) {
287         this.purchaseOrderCostSource = purchaseOrderCostSource;
288     }
289 
290     public PaymentTermType getVendorPaymentTerms() {
291 
292         return vendorPaymentTerms;
293     }
294 
295     /**
296      * Sets the vendorPaymentTerms attribute.
297      * 
298      * @param vendorPaymentTerms The vendorPaymentTerms to set.
299      * @deprecated
300      */
301     public void setVendorPaymentTerms(PaymentTermType vendorPaymentTerms) {
302         this.vendorPaymentTerms = vendorPaymentTerms;
303     }
304 
305     public ShippingPaymentTerms getVendorShippingPaymentTerms() {
306 
307         return vendorShippingPaymentTerms;
308     }
309 
310     /**
311      * Sets the vendorShippingPaymentTerms attribute.
312      * 
313      * @param vendorShippingPaymentTerms The vendorShippingPaymentTerms to set.
314      * @deprecated
315      */
316     public void setVendorShippingPaymentTerms(ShippingPaymentTerms vendorShippingPaymentTerms) {
317         this.vendorShippingPaymentTerms = vendorShippingPaymentTerms;
318     }
319 
320     public ShippingTitle getVendorShippingTitle() {
321 
322         return vendorShippingTitle;
323     }
324 
325     /**
326      * Sets the vendorShippingTitle attribute.
327      * 
328      * @param vendorShippingTitle The vendorShippingTitle to set.
329      * @deprecated
330      */
331     public void setVendorShippingTitle(ShippingTitle vendorShippingTitle) {
332         this.vendorShippingTitle = vendorShippingTitle;
333     }
334 
335     public List<VendorContractOrganization> getVendorContractOrganizations() {
336 
337         return vendorContractOrganizations;
338     }
339 
340     public void setVendorContractOrganizations(List<VendorContractOrganization> vendorContractOrganizations) {
341         this.vendorContractOrganizations = vendorContractOrganizations;
342     }
343 
344     /**
345      * A concatenation of the vendorHeaderGeneratedIdentifier, a dash, and the vendorDetailAssignedIdentifier
346      * 
347      * @return Returns the vendorNumber.
348      */
349     public String getVendorNumber() {
350         String headerId = "";
351         String detailId = "";
352         String vendorNumber = "";
353         if (ObjectUtils.isNotNull(this.vendorHeaderGeneratedIdentifier)) {
354             headerId = this.vendorHeaderGeneratedIdentifier.toString();
355         }
356         if (ObjectUtils.isNotNull(this.vendorDetailAssignedIdentifier)) {
357             detailId = this.vendorDetailAssignedIdentifier.toString();
358         }
359         if (!StringUtils.isEmpty(headerId) && !StringUtils.isEmpty(detailId)) {
360             vendorNumber = headerId + "-" + detailId;
361         }
362 
363         return vendorNumber;
364     }
365 
366     /**
367      * Sets the vendorNumber attribute value.
368      * 
369      * @param vendorNumber The vendorNumber to set.
370      */
371     public void setVendorNumber(String vendorNumber) {
372         if (!StringUtils.isEmpty(vendorNumber)) {
373             int dashInd = vendorNumber.indexOf("-");
374             if (vendorNumber.length() >= dashInd) {
375                 String vndrHdrGenId = vendorNumber.substring(0, dashInd);
376                 String vndrDetailAssgnedId = vendorNumber.substring(dashInd + 1);
377                 if (!StringUtils.isEmpty(vndrHdrGenId) && !StringUtils.isEmpty(vndrDetailAssgnedId)) {
378                     this.vendorHeaderGeneratedIdentifier = new Integer(vndrHdrGenId);
379                     this.vendorDetailAssignedIdentifier = new Integer(vndrDetailAssgnedId);
380                 }
381             }
382         }
383         else {
384             this.vendorNumber = vendorNumber;
385         }
386     }
387     
388     /**
389      * @see org.kuali.ole.vnd.document.routing.VendorRoutingComparable#isEqualForRouting(java.lang.Object)
390      */
391     @Override
392     public boolean isEqualForRouting(Object toCompare) {
393         if ((ObjectUtils.isNull(toCompare)) || !(toCompare instanceof VendorContract)) {
394             return false;
395         }
396         else {
397             VendorContract vc = (VendorContract) toCompare;
398             boolean eq = new EqualsBuilder().append(this.getVendorContractGeneratedIdentifier(), vc.getVendorContractGeneratedIdentifier()).append(this.getVendorHeaderGeneratedIdentifier(), vc.getVendorHeaderGeneratedIdentifier()).append(this.getVendorDetailAssignedIdentifier(), vc.getVendorDetailAssignedIdentifier()).append(this.getVendorContractName(), vc.getVendorContractName()).append(this.getVendorContractDescription(), vc.getVendorContractDescription()).append(this.getVendorCampusCode(), vc.getVendorCampusCode()).append(this.getVendorContractBeginningDate(), vc.getVendorContractBeginningDate()).append(this.getVendorContractEndDate(), vc.getVendorContractEndDate()).append(this.getContractManagerCode(), vc.getContractManagerCode()).append(this.getPurchaseOrderCostSourceCode(), vc.getPurchaseOrderCostSourceCode()).append(this.getVendorPaymentTermsCode(), vc.getVendorPaymentTermsCode()).append(this.getVendorShippingPaymentTermsCode(), vc.getVendorShippingPaymentTermsCode())
399                     .append(this.getVendorShippingTitleCode(), vc.getVendorShippingTitleCode()).append(this.getVendorContractExtensionDate(), vc.getVendorContractExtensionDate()).append(this.getVendorB2bIndicator(), vc.getVendorB2bIndicator()).append(this.getOrganizationAutomaticPurchaseOrderLimit(), vc.getOrganizationAutomaticPurchaseOrderLimit()).isEquals();
400             eq &= SpringContext.getBean(VendorService.class).equalMemberLists(this.getVendorContractOrganizations(), vc.getVendorContractOrganizations());
401 
402             return eq;
403         }
404     }
405 
406 }