1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.shopping.model.impl;
16  
17  import com.liferay.portal.kernel.util.CalendarUtil;
18  import com.liferay.portlet.shopping.model.ShoppingCoupon;
19  
20  import java.util.Date;
21  
22  /**
23   * <a href="ShoppingCouponImpl.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class ShoppingCouponImpl
28      extends ShoppingCouponModelImpl implements ShoppingCoupon {
29  
30      public static final String DISCOUNT_TYPE_ACTUAL = "actual";
31  
32      public static final String DISCOUNT_TYPE_FREE_SHIPPING = "free-shipping";
33  
34      public static final String DISCOUNT_TYPE_PERCENTAGE = "percentage";
35  
36      public static final String DISCOUNT_TYPE_TAX_FREE = "tax-free";
37  
38      public static final String[] DISCOUNT_TYPES = {
39          "percentage", "actual", "free-shipping", "tax-free"
40      };
41  
42      public ShoppingCouponImpl() {
43      }
44  
45      public boolean hasValidDateRange() {
46          if (hasValidStartDate() && hasValidEndDate()) {
47              return true;
48          }
49          else {
50              return false;
51          }
52      }
53  
54      public boolean hasValidEndDate() {
55          if (getEndDate() != null) {
56              Date now = new Date();
57  
58              if (now.after(getEndDate())) {
59                  return false;
60              }
61          }
62  
63          return true;
64      }
65  
66      public boolean hasValidStartDate() {
67          Date now = new Date();
68  
69          if (CalendarUtil.beforeByDay(now, getStartDate())) {
70              return false;
71          }
72          else {
73              return true;
74          }
75      }
76  
77  }