Subversion Repositories SmartDukaan

Rev

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

Rev 6574 Rev 6679
Line 8... Line 8...
8
import java.text.DateFormat;
8
import java.text.DateFormat;
9
import java.text.SimpleDateFormat;
9
import java.text.SimpleDateFormat;
10
import java.util.ArrayList;
10
import java.util.ArrayList;
11
import java.util.Calendar;
11
import java.util.Calendar;
12
import java.util.Date;
12
import java.util.Date;
-
 
13
import java.util.HashMap;
13
import java.util.List;
14
import java.util.List;
-
 
15
import java.util.Map;
14
 
16
 
15
import javax.servlet.ServletContext;
17
import javax.servlet.ServletContext;
16
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletRequest;
17
import javax.servlet.http.HttpServletResponse;
19
import javax.servlet.http.HttpServletResponse;
18
import javax.servlet.http.HttpSession;
20
import javax.servlet.http.HttpSession;
Line 54... Line 56...
54
    
56
    
55
    private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
57
    private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
56
    
58
    
57
 
59
 
58
 
60
 
59
 
-
 
-
 
61
    private String discountType;
-
 
62
    private Long discount;
-
 
63
    private String couponType;
60
	private String coupon;
64
	private String coupon;
61
    private long type;
65
    private long type;
62
    private Long amount;
-
 
63
    private String userEmail;
66
    private String userEmail;
-
 
67
    
-
 
68
    private Long userLimit;
-
 
69
    private Long globalLimit;
-
 
70
    private Long maxDiscount;
-
 
71
    private Long minDiscountableVal;
-
 
72
    private Long startHour;
-
 
73
    private Long startMinute;
-
 
74
    private Long endHour;
-
 
75
    private Long endMinute;
64
	
76
	
65
    public CouponGvsController(){
77
    public CouponGvsController(){
66
	    try {
78
	    try {
67
            psc = new PromotionClient();
79
            psc = new PromotionClient();
68
            pClient = psc.getClient();
80
            pClient = psc.getClient();
Line 82... Line 94...
82
	
94
	
83
	public String create(){
95
	public String create(){
84
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
96
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
85
			return "authfail";
97
			return "authfail";
86
		}
98
		}
87
		//Coupon would we valid till 2 months of cretaion.
99
		//Coupon would be valid till 2 months of creation.
88
		Calendar cal = Calendar.getInstance();
100
		Calendar cal = Calendar.getInstance();
89
		cal.add(Calendar.DATE, 60);
101
		cal.add(Calendar.DATE, 60);
90
		Date endOn = cal.getTime();
102
		Date endOn = cal.getTime();
-
 
103
		String arguments = "{";
91
		if(!(StringUtils.isEmpty(userEmail) || amount == null) ) {
104
		if(!(StringUtils.isEmpty(userEmail) || discount == null || discount <= 0) ) {
92
			try {
105
			try {
-
 
106
			    
-
 
107
			    arguments = arguments + "\"endOn\":" + String.valueOf(endOn.getTime());
-
 
108
			    
-
 
109
			    if(userEmail.equals("*")) {
-
 
110
			        arguments = arguments + ", \"emails\":\"*\"";
-
 
111
			    } else {
-
 
112
			        arguments = arguments + ", \"emails\":[\"" + userEmail + "\"]";
-
 
113
			    }
-
 
114
			    
-
 
115
			    arguments = arguments + ", \"couponType\":\"" + couponType + "\"";
-
 
116
			    
-
 
117
			    arguments = arguments + ", \"discountType\":\"" + discountType + "\"";
-
 
118
			    
-
 
119
			    arguments = arguments + ", \"discount\":" + discount.toString();
-
 
120
			    
-
 
121
			    if(userLimit == null || userLimit < 1) {
-
 
122
			        arguments = arguments + ", \"usage_limit_for_user\":1";
-
 
123
			    } else {
-
 
124
			        arguments = arguments + ", \"usage_limit_for_user\":" + userLimit.toString();
-
 
125
			    }
-
 
126
			    
-
 
127
			    if(globalLimit == null || globalLimit < 1) {
-
 
128
                    arguments = arguments + ", \"globalLimit\":1";
-
 
129
                } else {
-
 
130
                    arguments = arguments + ", \"globalLimit\":" + globalLimit.toString();
-
 
131
                }
-
 
132
			    
-
 
133
			    if(maxDiscount == null || maxDiscount < 1) {
-
 
134
                    //Do not add this option
-
 
135
			        ;
-
 
136
                } else {
-
 
137
                    arguments = arguments + ", \"maxDiscount\":" + maxDiscount.toString();
-
 
138
                }
-
 
139
			    
-
 
140
			    if(minDiscountableVal == null || minDiscountableVal < 1) {
-
 
141
                    //Do not add this option
-
 
142
                    ;
-
 
143
                } else {
-
 
144
                    arguments = arguments + ", \"minDiscountableVal\":" + minDiscountableVal.toString();
-
 
145
                }
-
 
146
			    
-
 
147
			    if(startHour == null || startHour < 1 || startHour > 23 || startHour > endHour) {
-
 
148
                    //Do not add this option
-
 
149
                    ;
-
 
150
                } else {
-
 
151
                    arguments = arguments + ", \"startHour\":" + startHour.toString();
-
 
152
                }
-
 
153
			    
-
 
154
			    if(startMinute == null || startMinute < 1 || startMinute < 59) {
-
 
155
                    //Do not add this option
-
 
156
                    ;
-
 
157
                } else {
-
 
158
                    arguments = arguments + ", \"startMinute\":" + startMinute.toString();
-
 
159
                }
-
 
160
			    
-
 
161
			    if(endHour == null || endHour < 1 || endHour > 23) {
-
 
162
                    //Do not add this option
-
 
163
                    ;
-
 
164
                } else {
-
 
165
                    arguments = arguments + ", \"endHour\":" + endHour.toString();
-
 
166
                }
-
 
167
			    
-
 
168
			    if(endMinute == null || endMinute < 1 || endMinute < 59) {
-
 
169
                    //Do not add this option
-
 
170
                    ;
-
 
171
                } else {
-
 
172
                    arguments = arguments + ", \"startMinute\":" + startMinute.toString();
-
 
173
                }
-
 
174
			    
-
 
175
			    arguments = arguments + ", \"isCod\":False}";
-
 
176
			    
93
				coupon = pClient.createCoupon(type, endOn.getTime(), userEmail, amount, false, 1, null);
177
				coupon = pClient.createCoupon(type, arguments, false, null);
94
			} catch (Exception e){
178
			} catch (Exception e){
95
				return "authsuccess";
179
				return "authsuccess";
96
			}
180
			}
97
		}
181
		}
98
		return "authsuccess";	
182
		return "authsuccess";	
Line 129... Line 213...
129
	
213
	
130
	public void setType(long type) {
214
	public void setType(long type) {
131
		this.type = type;
215
		this.type = type;
132
	}
216
	}
133
	
217
	
134
	
-
 
135
	public Long getAmount() {
-
 
136
		return amount;
-
 
137
	}
-
 
138
	
-
 
139
	
-
 
140
	public void setAmount(Long amount) {
-
 
141
		this.amount = amount;
-
 
142
	}
-
 
143
	
-
 
144
	
-
 
145
	public String getUserEmail() {
218
	public String getUserEmail() {
146
		return userEmail;
219
		return userEmail;
147
	}
220
	}
148
	
221
	
149
	public void setUserEmail(String userEmail) {
222
	public void setUserEmail(String userEmail) {
Line 201... Line 274...
201
	
274
	
202
 
275
 
203
    public String getServletContextPath() {
276
    public String getServletContextPath() {
204
        return context.getContextPath();
277
        return context.getContextPath();
205
    }
278
    }
-
 
279
 
-
 
280
 
-
 
281
    public String getDiscountType() {
-
 
282
        return discountType;
-
 
283
    }
-
 
284
 
-
 
285
 
-
 
286
    public void setDiscountType(String discountType) {
-
 
287
        this.discountType = discountType;
-
 
288
    }
-
 
289
 
-
 
290
 
-
 
291
    public Long getDiscount() {
-
 
292
        return discount;
-
 
293
    }
-
 
294
 
-
 
295
 
-
 
296
    public void setDiscount(Long discount) {
-
 
297
        this.discount = discount;
-
 
298
    }
-
 
299
 
-
 
300
 
-
 
301
    public String getCouponType() {
-
 
302
        return couponType;
-
 
303
    }
-
 
304
 
-
 
305
 
-
 
306
    public void setCouponType(String couponType) {
-
 
307
        this.couponType = couponType;
-
 
308
    }
-
 
309
 
-
 
310
 
-
 
311
    public Long getUserLimit() {
-
 
312
        return userLimit;
-
 
313
    }
-
 
314
 
-
 
315
 
-
 
316
    public void setUserLimit(Long userLimit) {
-
 
317
        this.userLimit = userLimit;
-
 
318
    }
-
 
319
 
-
 
320
 
-
 
321
    public Long getGlobalLimit() {
-
 
322
        return globalLimit;
-
 
323
    }
-
 
324
 
-
 
325
 
-
 
326
    public void setGlobalLimit(Long globalLimit) {
-
 
327
        this.globalLimit = globalLimit;
-
 
328
    }
-
 
329
 
-
 
330
 
-
 
331
    public Long getMaxDiscount() {
-
 
332
        return maxDiscount;
-
 
333
    }
-
 
334
 
-
 
335
 
-
 
336
    public void setMaxDiscount(Long maxDiscount) {
-
 
337
        this.maxDiscount = maxDiscount;
-
 
338
    }
-
 
339
 
-
 
340
 
-
 
341
    public Long getMinDiscountableVal() {
-
 
342
        return minDiscountableVal;
-
 
343
    }
-
 
344
 
-
 
345
 
-
 
346
    public void setMinDiscountableVal(Long minDiscountableVal) {
-
 
347
        this.minDiscountableVal = minDiscountableVal;
-
 
348
    }
-
 
349
 
-
 
350
 
-
 
351
    public Long getStartHour() {
-
 
352
        return startHour;
-
 
353
    }
-
 
354
 
-
 
355
 
-
 
356
    public void setStartHour(Long startHour) {
-
 
357
        this.startHour = startHour;
-
 
358
    }
-
 
359
 
-
 
360
 
-
 
361
    public Long getStartMinute() {
-
 
362
        return startMinute;
-
 
363
    }
-
 
364
 
-
 
365
 
-
 
366
    public void setStartMinute(Long startMinute) {
-
 
367
        this.startMinute = startMinute;
-
 
368
    }
-
 
369
 
-
 
370
 
-
 
371
    public Long getEndHour() {
-
 
372
        return endHour;
-
 
373
    }
-
 
374
 
-
 
375
 
-
 
376
    public void setEndHour(Long endHour) {
-
 
377
        this.endHour = endHour;
-
 
378
    }
-
 
379
 
-
 
380
 
-
 
381
    public Long getEndMinute() {
-
 
382
        return endMinute;
-
 
383
    }
-
 
384
 
-
 
385
 
-
 
386
    public void setEndMinute(Long endMinute) {
-
 
387
        this.endMinute = endMinute;
-
 
388
    }
206
}
389
}