Subversion Repositories SmartDukaan

Rev

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

Rev 5149 Rev 6360
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.apache.velocity.util.introspection.MethodMap.AmbiguousException;
21
import org.json.JSONException;
22
import org.json.JSONException;
22
import org.json.JSONObject;
23
import org.json.JSONObject;
23
import org.slf4j.Logger;
24
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25
import org.slf4j.LoggerFactory;
25
 
26
 
Line 38... Line 39...
38
	private HttpSession session;
39
	private HttpSession session;
39
	private Client promotionClient;
40
	private Client promotionClient;
40
	private UserContextService.Client userClient;
41
	private UserContextService.Client userClient;
41
 
42
 
42
	private List<CouponInfo> coupons;
43
	private List<CouponInfo> coupons;
-
 
44
	private List<VoucherInfo> vouchers;
43
 
45
 
44
	@Override
46
	@Override
45
	public void setServletRequest(HttpServletRequest req) {
47
	public void setServletRequest(HttpServletRequest req) {
46
		this.request = req;
48
		this.request = req;
47
		this.session = req.getSession();
49
		this.session = req.getSession();
Line 59... Line 61...
59
			userClient = userServiceClient.getClient();
61
			userClient = userServiceClient.getClient();
60
			
62
			
61
			coupons = new ArrayList<CouponInfo>();
63
			coupons = new ArrayList<CouponInfo>();
62
			CouponInfo couponInfo;
64
			CouponInfo couponInfo;
63
			
65
			
-
 
66
			long voucherIssued = 0;
-
 
67
			long voucherRedeemed = 0;
-
 
68
			long voucherInCart = 0;
-
 
69
			double voucherAmountRedeemed = 0d;
-
 
70
			
64
			for (Coupon coupon: promotionClient.getActiveCoupons())	{
71
			for (Coupon coupon: promotionClient.getActiveCoupons())	{
-
 
72
				if(!promotionClient.isGiftVoucher(coupon.getCouponCode())) {
65
				try	{
73
					try	{
66
					couponInfo = new CouponInfo(coupon.getCouponCode());
74
						couponInfo = new CouponInfo(coupon.getCouponCode());
67
					couponInfo.setPaymentsCount(promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode()));
75
						couponInfo.setPaymentsCount(promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode()));
68
					couponInfo.setCartsCount(userClient.getCartsWithCouponCount(coupon.getCouponCode()));
76
						couponInfo.setCartsCount(userClient.getCartsWithCouponCount(coupon.getCouponCode()));
69
					
-
 
70
					String args = coupon.getArguments();
-
 
71
					String description;
-
 
72
					
-
 
73
					if(args == null)	{
-
 
74
						description = promotionClient.getRuleDocString(coupon.getPromotion().getRuleExecutionSrc());
-
 
75
						couponInfo.setDescription("<pre>" + description + "</pre>");
-
 
76
						
77
						
77
					} else	{
78
						String args = coupon.getArguments();
78
						JSONObject argsJSON = new JSONObject(args);
79
						String description;
79
						
80
						
-
 
81
						if(args == null)	{
-
 
82
							description = promotionClient.getRuleDocString(coupon.getPromotion().getRuleExecutionSrc());
-
 
83
							couponInfo.setDescription("<pre>" + description + "</pre>");
-
 
84
							
-
 
85
						} else	{
-
 
86
							JSONObject argsJSON = new JSONObject(args);
-
 
87
							
80
						description = "Rs." + argsJSON.getString("discount");
88
							description = "Rs." + argsJSON.getString("discount");
81
						description += " off on " + argsJSON.getString("handset_display_name");
89
							description += " off on " + argsJSON.getString("handset_display_name");
82
						description += " (Max " + argsJSON.getString("usage_limit") + " uses)";
90
							description += " (Max " + argsJSON.getString("usage_limit") + " uses)";
-
 
91
							
-
 
92
							couponInfo.setDescription("<i>" + description + "</i>");
-
 
93
						}
-
 
94
						coupons.add(couponInfo);
83
						
95
						
-
 
96
					} catch (JSONException e) {
-
 
97
						log.error("" + e);
-
 
98
					}
-
 
99
				} else {
-
 
100
					try {
-
 
101
						voucherIssued++;
-
 
102
						long redeemeCount = promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode());
-
 
103
						voucherRedeemed += redeemeCount;
-
 
104
						voucherInCart += userClient.getCartsWithCouponCount(coupon.getCouponCode());
-
 
105
						JSONObject argsJSON = new JSONObject(coupon.getArguments());
-
 
106
						if(redeemeCount > 0){
84
						couponInfo.setDescription("<i>" + description + "</i>");
107
							voucherAmountRedeemed += argsJSON.getDouble("discount");
-
 
108
						}
-
 
109
					} catch (Exception e) {
-
 
110
						log.error("" + e);
85
					}
111
					}
86
					coupons.add(couponInfo);
-
 
87
					
-
 
88
				} catch (JSONException e) {
-
 
89
					log.error("" + e);
-
 
90
				}
112
				}
-
 
113
				VoucherInfo v = new VoucherInfo("Recharge Gift Voucher");
-
 
114
				v.setTotalAmountRedeemed(voucherAmountRedeemed);
-
 
115
				v.setTotalVoucherIssued(voucherIssued);
-
 
116
				v.setTotalVouchersRedeemed(voucherRedeemed);
-
 
117
				v.setTotalVouchersInCart(voucherInCart);
-
 
118
				vouchers = new ArrayList<VoucherInfo>();
-
 
119
				vouchers.add(v);
91
			}
120
			}
92
		} catch (Exception e) {
121
		} catch (Exception e) {
93
			log.error("" + e);
122
			log.error("" + e);
94
		}
123
		}
95
		return "index";
124
		return "index";
96
	}
125
	}
97
	
126
	
98
	public List<CouponInfo> getActiveCoupons()	{
127
	public List<CouponInfo> getActiveCoupons()	{
99
		return coupons;
128
		return coupons;
100
	}
129
	}
-
 
130
 
-
 
131
	public List<VoucherInfo> getActiveGiftVouchers()	{
-
 
132
		return vouchers;
-
 
133
	}
101
	
134
	
102
	public static class CouponInfo {
135
	public static class CouponInfo {
103
		private String code;
136
		private String code;
104
		private long paymentsCount;
137
		private long paymentsCount;
105
		private long cartsCount;
138
		private long cartsCount;
Line 142... Line 175...
142
		
175
		
143
		public String toString()	{
176
		public String toString()	{
144
			return code + " " + paymentsCount + " " + cartsCount + " " + description;
177
			return code + " " + paymentsCount + " " + cartsCount + " " + description;
145
		}
178
		}
146
	}
179
	}
-
 
180
	
-
 
181
	public static class VoucherInfo {
-
 
182
		private String promotionName;
-
 
183
		private long totalVoucherIssued;
-
 
184
		private long totalVouchersInCart;
-
 
185
		private long totalVouchersRedeemed;
-
 
186
		private double totalAmountRedeemed;
-
 
187
		
-
 
188
		public VoucherInfo(String promotionName){
-
 
189
			this.promotionName = promotionName;
-
 
190
			this.totalVoucherIssued = 0;
-
 
191
			this.totalAmountRedeemed = 0d;
-
 
192
			this.totalVouchersInCart = 0;
-
 
193
		}
-
 
194
 
-
 
195
		public String getPromotionName() {
-
 
196
			return promotionName;
-
 
197
		}
-
 
198
		public void setPromotionName(String promotionName) {
-
 
199
			this.promotionName = promotionName;
-
 
200
		}
-
 
201
		public long getTotalVoucherIssued() {
-
 
202
			return totalVoucherIssued;
-
 
203
		}
-
 
204
		public void setTotalVoucherIssued(long totalVoucherIssued) {
-
 
205
			this.totalVoucherIssued = totalVoucherIssued;
-
 
206
		}
-
 
207
		public long getTotalVouchersInCart() {
-
 
208
			return totalVouchersInCart;
-
 
209
		}
-
 
210
		public void setTotalVouchersInCart(long totalVouchersInCart) {
-
 
211
			this.totalVouchersInCart = totalVouchersInCart;
-
 
212
		}
-
 
213
		public long getTotalVouchersRedeemed() {
-
 
214
			return totalVouchersRedeemed;
-
 
215
		}
-
 
216
		public void setTotalVouchersRedeemed(long totalVouchersRedeemed) {
-
 
217
			this.totalVouchersRedeemed = totalVouchersRedeemed;
-
 
218
		}
-
 
219
		public double getTotalAmountRedeemed() {
-
 
220
			return totalAmountRedeemed;
-
 
221
		}
-
 
222
		public void setTotalAmountRedeemed(double totalAmountRedeemed) {
-
 
223
			this.totalAmountRedeemed = totalAmountRedeemed;
-
 
224
		}
-
 
225
		
-
 
226
		
-
 
227
	}
147
}
228
}
148
229