Subversion Repositories SmartDukaan

Rev

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

Rev 7859 Rev 7874
Line 34... Line 34...
34
	private static Logger log = Logger.getLogger(Class.class);	
34
	private static Logger log = Logger.getLogger(Class.class);	
35
	private String id;
35
	private String id;
36
	private long itemId;
36
	private long itemId;
37
	private String pincode;
37
	private String pincode;
38
	private String days = "-1";
38
	private String days = "-1";
-
 
39
	private long businessDays = -1;
39
	private boolean isCODAvailable;
40
	private boolean isCODAvailable;
40
	private boolean isOTGAvailable;
41
	private boolean isOTGAvailable;
41
	private String codDays = "-1";
42
	private String codDays = "-1";
42
	private Map<String, String> response = new HashMap<String, String>();
43
	private Map<String, String> response = new HashMap<String, String>();
43
	
44
	
Line 45... Line 46...
45
		super();
46
		super();
46
	}
47
	}
47
    
48
    
48
    // GET /logout
49
    // GET /logout
49
    public HttpHeaders show(){
50
    public HttpHeaders show(){
50
    	Calendar cal = Calendar.getInstance();
-
 
51
    	LogisticsClient logisticsServiceClient = null;
51
    	LogisticsClient logisticsServiceClient = null;
52
    	try {
52
    	try {
53
			logisticsServiceClient = new LogisticsClient();
53
			logisticsServiceClient = new LogisticsClient();
54
			Client logisticsClient = logisticsServiceClient.getClient();
54
			Client logisticsClient = logisticsServiceClient.getClient();
55
			LogisticsInfo logistincInfo = logisticsClient.getLogisticsEstimation(itemId, pincode, DeliveryType.PREPAID);
55
			LogisticsInfo logistincInfo = logisticsClient.getLogisticsEstimation(itemId, pincode, DeliveryType.PREPAID);
Line 58... Line 58...
58
				days = getDeliveryDateString((int)logistincInfo.getDeliveryTime(), DeliveryType.PREPAID);
58
				days = getDeliveryDateString((int)logistincInfo.getDeliveryTime(), DeliveryType.PREPAID);
59
				if(logistincInfo.isCodAllowed()){
59
				if(logistincInfo.isCodAllowed()){
60
					codDays = getDeliveryDateString((int)(logistincInfo.getDeliveryTime()), DeliveryType.COD);
60
					codDays = getDeliveryDateString((int)(logistincInfo.getDeliveryTime()), DeliveryType.COD);
61
				}
61
				}
62
			}
62
			}
63
			
-
 
-
 
63
			businessDays = logistincInfo.getDeliveryTime();
64
			isCODAvailable = logistincInfo.isCodAllowed();
64
			isCODAvailable = logistincInfo.isCodAllowed();
65
			isOTGAvailable = logistincInfo.isOtgAvailable();
65
			isOTGAvailable = logistincInfo.isOtgAvailable();
66
    	} catch (LogisticsServiceException e)	{
66
    	} catch (LogisticsServiceException e)	{
67
    		days = "-1";
67
    		days = "-1";
68
    		isCODAvailable = false;
68
    		isCODAvailable = false;
Line 75... Line 75...
75
		}
75
		}
76
		response.put("delivery_estimate", days);
76
		response.put("delivery_estimate", days);
77
		response.put("cod_delivery_estimate", codDays);
77
		response.put("cod_delivery_estimate", codDays);
78
		response.put("is_cod_available_for_location", Boolean.toString(isCODAvailable));
78
		response.put("is_cod_available_for_location", Boolean.toString(isCODAvailable));
79
		response.put("on_time_guarantee", Boolean.toString(isOTGAvailable));
79
		response.put("on_time_guarantee", Boolean.toString(isOTGAvailable));
80
		SimpleDateFormat dateformat = new SimpleDateFormat("EEE dd-MMM-yy");
-
 
81
		response.put("system_date", dateformat.format(cal.getTime()));
80
		response.put("business_days", businessDays + "");
82
		
81
		
83
		try{
82
		try{
84
			if(pincode.length() == 6 && !pincode.equals("110001")){
83
			if(pincode.length() == 6 && !pincode.equals("110001")){
85
				String requestOrigin = request.getHeader("referer").contains("cart")?"Cart":"Product";
84
				String requestOrigin = request.getHeader("referer").contains("cart")?"Cart":"Product";
86
				DataLogger.logData(EventType.DELIVERY_ESTIMATE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
85
				DataLogger.logData(EventType.DELIVERY_ESTIMATE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
Line 95... Line 94...
95
    
94
    
96
    
95
    
97
    public static String getDeliveryDateString(int days, DeliveryType type) throws TException {
96
    public static String getDeliveryDateString(int days, DeliveryType type) throws TException {
98
    	Calendar now = new GregorianCalendar();
97
    	Calendar now = new GregorianCalendar();
99
    	int hour = now.get(Calendar.HOUR_OF_DAY);
98
    	int hour = now.get(Calendar.HOUR_OF_DAY);
100
    	if(type == DeliveryType.COD && hour < 15){
99
    	if(type == DeliveryType.COD && hour < 21){
101
			days = days + 1;
100
			days = days + 1;
102
		}
101
		}
103
    	if(businessDayToActualDateMap.containsKey(days)){
102
    	if(businessDayToActualDateMap.containsKey(days)){
104
    		if(hour != 0){	
103
    		if(hour != 0){	
105
    			return businessDayToActualDateMap.get(days);
104
    			return businessDayToActualDateMap.get(days);
Line 116... Line 115...
116
	
115
	
117
		logisticsServiceClient = new LogisticsClient();
116
		logisticsServiceClient = new LogisticsClient();
118
		Client logisticsClient = logisticsServiceClient.getClient();
117
		Client logisticsClient = logisticsServiceClient.getClient();
119
		
118
		
120
    	List<Long> holidays = logisticsClient.getHolidays(now.getTimeInMillis(), to_range.getTimeInMillis());
119
    	List<Long> holidays = logisticsClient.getHolidays(now.getTimeInMillis(), to_range.getTimeInMillis());
121
 
120
    	
-
 
121
    	boolean tomorrow = true;
122
    	boolean check= true;
122
    	boolean check= true;
123
    	outer:while(check){
123
    	outer:while(check){
124
    		if(Calendar.SUNDAY==now.get(Calendar.DAY_OF_WEEK)){
124
    		if(Calendar.SUNDAY==now.get(Calendar.DAY_OF_WEEK)){
125
    			now.add(Calendar.DAY_OF_MONTH, 1);
125
    			now.add(Calendar.DAY_OF_MONTH, 1);
-
 
126
    			tomorrow = false;
126
    			check = true;
127
    			check = true;
127
    			continue outer;
128
    			continue outer;
128
    		}
129
    		}
129
    		for(int i=0; i<holidays.size(); i++){
130
    		for(int i=0; i<holidays.size(); i++){
130
    			long now_in_long= now.getTimeInMillis();
131
    			long now_in_long= now.getTimeInMillis();
131
    			if(now_in_long==holidays.get(i)){
132
    			if(now_in_long==holidays.get(i)){
132
    				now.add(Calendar.DAY_OF_MONTH, 1);
133
    				now.add(Calendar.DAY_OF_MONTH, 1);
-
 
134
    				tomorrow = false;
133
    				check = true;
135
    				check = true;
134
    				continue outer;
136
    				continue outer;
135
    			}
137
    			}
136
    		}
138
    		}
-
 
139
    		if(tomorrow && days == 1){
-
 
140
        		tomorrow = true;
-
 
141
    		}	
137
    		check= false;
142
    		check= false;
138
    		SimpleDateFormat dateformat = new SimpleDateFormat("EEE dd-MMM-yy");
143
    		SimpleDateFormat dateformat = new SimpleDateFormat("EEE dd-MMM-yy");
-
 
144
    		if(tomorrow){
-
 
145
    			businessDayToActualDateMap.put(days, "Tomorrow, " + dateformat.format(now.getTime()));
-
 
146
    		}else{
139
			businessDayToActualDateMap.put(days, dateformat.format(now.getTime()));
147
    			businessDayToActualDateMap.put(days, dateformat.format(now.getTime()));
-
 
148
    		}
140
    	}
149
    	}
141
    	return businessDayToActualDateMap.get(days);
150
    	return businessDayToActualDateMap.get(days);
142
	}
151
	}
143
    
152
    
144
    /**
153
    /**