Subversion Repositories SmartDukaan

Rev

Rev 3936 | Rev 5149 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3936 Rev 5148
Line 16... Line 16...
16
import org.apache.struts2.convention.annotation.InterceptorRef;
16
import org.apache.struts2.convention.annotation.InterceptorRef;
17
import org.apache.struts2.convention.annotation.InterceptorRefs;
17
import org.apache.struts2.convention.annotation.InterceptorRefs;
18
import org.apache.struts2.convention.annotation.Result;
18
import org.apache.struts2.convention.annotation.Result;
19
import org.apache.struts2.convention.annotation.Results;
19
import org.apache.struts2.convention.annotation.Results;
20
import org.apache.struts2.interceptor.ServletRequestAware;
20
import org.apache.struts2.interceptor.ServletRequestAware;
-
 
21
import org.json.JSONException;
21
import org.json.JSONObject;
22
import org.json.JSONObject;
22
import org.slf4j.Logger;
23
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24
import org.slf4j.LoggerFactory;
24
 
25
 
25
@InterceptorRefs({
26
@InterceptorRefs({
Line 45... Line 46...
45
		this.request = req;
46
		this.request = req;
46
		this.session = req.getSession();
47
		this.session = req.getSession();
47
	}
48
	}
48
	
49
	
49
	public String index() {
50
	public String index() {
50
        if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))	{
51
//        if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))	{
51
            return "authfail";
52
//            return "authfail";
52
        }
53
//        }
53
		try {
54
		try {
54
			PromotionClient promotionServiceClient = new PromotionClient();
55
			PromotionClient promotionServiceClient = new PromotionClient();
55
			promotionClient = promotionServiceClient.getClient();
56
			promotionClient = promotionServiceClient.getClient();
56
			
57
			
57
			UserClient userServiceClient = new UserClient();
58
			UserClient userServiceClient = new UserClient();
Line 59... Line 60...
59
			
60
			
60
			coupons = new ArrayList<CouponInfo>();
61
			coupons = new ArrayList<CouponInfo>();
61
			CouponInfo couponInfo;
62
			CouponInfo couponInfo;
62
			
63
			
63
			for (Coupon coupon: promotionClient.getActiveCoupons())	{
64
			for (Coupon coupon: promotionClient.getActiveCoupons())	{
-
 
65
				try	{
64
				couponInfo = new CouponInfo(coupon.getCouponCode());
66
					couponInfo = new CouponInfo(coupon.getCouponCode());
65
				couponInfo.setPaymentsCount(promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode()));
67
					couponInfo.setPaymentsCount(promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode()));
66
				couponInfo.setCartsCount(userClient.getCartsWithCouponCount(coupon.getCouponCode()));
68
					couponInfo.setCartsCount(userClient.getCartsWithCouponCount(coupon.getCouponCode()));
67
				
-
 
68
				String args = coupon.getArguments();
-
 
69
				String description;
-
 
70
				
-
 
71
				if(args == null)	{
-
 
72
					description = promotionClient.getRuleDocString(coupon.getPromotion().getRuleExecutionSrc());
-
 
73
					couponInfo.setDescription("<pre>" + description + "</pre>");
-
 
74
					
69
					
75
				} else	{
70
					String args = coupon.getArguments();
76
					JSONObject argsJSON = new JSONObject(args);
71
					String description;
77
					
72
					
-
 
73
					if(args == null)	{
-
 
74
						description = promotionClient.getRuleDocString(coupon.getPromotion().getRuleExecutionSrc());
-
 
75
						couponInfo.setDescription("<pre>" + description + "</pre>");
-
 
76
						
-
 
77
					} else	{
-
 
78
						JSONObject argsJSON = new JSONObject(args);
-
 
79
						
78
					description = "Rs." + argsJSON.getString("discount");
80
						description = "Rs." + argsJSON.getString("discount");
79
					description += " off on " + argsJSON.getString("handset_display_name");
81
						description += " off on " + argsJSON.getString("handset_display_name");
80
					description += " (Max " + argsJSON.getString("usage_limit") + " uses)";
82
						description += " (Max " + argsJSON.getString("usage_limit") + " uses)";
-
 
83
						
-
 
84
						couponInfo.setDescription("<i>" + description + "</i>");
-
 
85
					}
-
 
86
					coupons.add(couponInfo);
81
					
87
					
-
 
88
				} catch (JSONException e) {
82
					couponInfo.setDescription("<i>" + description + "</i>");
89
					log.error("" + e);
83
				}
90
				}
84
				coupons.add(couponInfo);
-
 
85
			}
91
			}
86
		} catch (Exception e) {
92
		} catch (Exception e) {
87
			log.error(e.getStackTrace().toString());
93
			log.error("" + e);
88
		}
94
		}
89
		return "index";
95
		return "index";
90
	}
96
	}
91
	
97
	
92
	public List<CouponInfo> getActiveCoupons()	{
98
	public List<CouponInfo> getActiveCoupons()	{