Subversion Repositories SmartDukaan

Rev

Rev 7826 | Rev 7836 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2674 vikas 1
package in.shop2020.serving.controllers;
2
 
7065 kshitij.so 3
import in.shop2020.config.ConfigException;
4689 anupam.sin 4
import in.shop2020.crm.Activity;
5
import in.shop2020.crm.ActivityType;
3578 mandeep.dh 6
import in.shop2020.crm.SearchFilter;
7
import in.shop2020.crm.Ticket;
8
import in.shop2020.crm.TicketCategory;
4689 anupam.sin 9
import in.shop2020.crm.TicketPriority;
3578 mandeep.dh 10
import in.shop2020.crm.TicketStatus;
7826 manish.sha 11
import in.shop2020.logistics.LogisticsServiceException;
5845 mandeep.dh 12
import in.shop2020.logistics.PickupStore;
7826 manish.sha 13
import in.shop2020.logistics.Provider;
7190 amar.kumar 14
import in.shop2020.model.v1.catalog.CatalogService;
15
import in.shop2020.model.v1.catalog.CatalogServiceException;
16
import in.shop2020.model.v1.catalog.Item;
7826 manish.sha 17
import in.shop2020.model.v1.order.AmazonOrder;
7399 anupam.sin 18
import in.shop2020.model.v1.order.HotspotStore;
2674 vikas 19
import in.shop2020.model.v1.order.LineItem;
20
import in.shop2020.model.v1.order.Order;
3578 mandeep.dh 21
import in.shop2020.model.v1.order.OrderStatus;
7393 anupam.sin 22
import in.shop2020.model.v1.order.StoreOrderDetail;
4689 anupam.sin 23
import in.shop2020.model.v1.order.TransactionServiceException;
4142 mandeep.dh 24
import in.shop2020.model.v1.user.Address;
4689 anupam.sin 25
import in.shop2020.model.v1.user.UserContextException;
2728 vikas 26
import in.shop2020.payments.Attribute;
27
import in.shop2020.payments.Constants;
2674 vikas 28
import in.shop2020.payments.Payment;
2728 vikas 29
import in.shop2020.payments.PaymentException;
4142 mandeep.dh 30
import in.shop2020.payments.PaymentService.Client;
4689 anupam.sin 31
import in.shop2020.serving.auth.CRMAuthorizingRealm;
3090 mandeep.dh 32
import in.shop2020.serving.model.ShipmentUpdate;
5845 mandeep.dh 33
import in.shop2020.serving.services.AramexTrackingService;
3090 mandeep.dh 34
import in.shop2020.serving.services.BlueDartTrackingService;
5303 phani.kuma 35
import in.shop2020.serving.services.DelhiveryTrackingService;
7200 kshitij.so 36
import in.shop2020.serving.services.RedExpressTrackingService;
3578 mandeep.dh 37
import in.shop2020.thrift.clients.CRMClient;
7190 amar.kumar 38
import in.shop2020.thrift.clients.CatalogClient;
6322 amar.kumar 39
import in.shop2020.thrift.clients.HelperClient;
5845 mandeep.dh 40
import in.shop2020.thrift.clients.LogisticsClient;
3128 rajveer 41
import in.shop2020.thrift.clients.PaymentClient;
42
import in.shop2020.thrift.clients.TransactionClient;
4142 mandeep.dh 43
import in.shop2020.thrift.clients.UserClient;
7065 kshitij.so 44
import in.shop2020.thrift.clients.config.ConfigClient;
3546 mandeep.dh 45
import in.shop2020.utils.ModelUtils;
6322 amar.kumar 46
import in.shop2020.warehouse.WarehouseService;
2674 vikas 47
 
6322 amar.kumar 48
import java.io.BufferedInputStream;
49
import java.io.File;
50
import java.io.FileInputStream;
51
import java.io.FileWriter;
52
import java.io.IOException;
53
import java.io.InputStream;
6912 anupam.sin 54
import java.text.SimpleDateFormat;
2674 vikas 55
import java.util.ArrayList;
6912 anupam.sin 56
import java.util.Calendar;
4416 mandeep.dh 57
import java.util.Collections;
6912 anupam.sin 58
import java.util.Date;
4689 anupam.sin 59
import java.util.HashSet;
2674 vikas 60
import java.util.List;
4689 anupam.sin 61
import java.util.Set;
4416 mandeep.dh 62
import java.util.concurrent.Callable;
63
import java.util.concurrent.Executors;
64
import java.util.concurrent.TimeUnit;
2674 vikas 65
 
6322 amar.kumar 66
import javax.servlet.ServletOutputStream;
67
 
4689 anupam.sin 68
import net.htmlparser.jericho.Source;
69
 
5845 mandeep.dh 70
import org.apache.commons.lang.StringUtils;
2674 vikas 71
import org.apache.log4j.Logger;
2728 vikas 72
import org.apache.thrift.TException;
4142 mandeep.dh 73
import org.apache.thrift.transport.TTransportException;
2674 vikas 74
 
75
/**
76
 * @author vikas
3578 mandeep.dh 77
 * 
2674 vikas 78
 */
79
@SuppressWarnings("serial")
80
public class UserOrderInfoController extends BaseController {
7372 kshitij.so 81
	private static Logger                  log                     = Logger.getLogger(Class.class);
82
	private static BlueDartTrackingService blueDartTrackingService = new BlueDartTrackingService();
83
	private static AramexTrackingService aramexTrackingService     = new AramexTrackingService();
84
	private static DelhiveryTrackingService delhiveryTrackingService     = new DelhiveryTrackingService();
85
	private static RedExpressTrackingService redexpressTrackingService = new RedExpressTrackingService();
3090 mandeep.dh 86
 
7372 kshitij.so 87
	private long                 orderId;
88
	private Order                order;
89
	private List<Payment>        payments;
90
	private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
91
	private Long                 codTicketId;
92
	private List<Address>        addresses;
93
	private Set<OrderStatus>     setOfcancellableStates;
94
	private String               cancellationInitiator;
95
	private String               cancelReason;
96
	private String               body;
97
	private String               line1;
98
	private String               line2;
99
	private String               city;
100
	private String               state;
101
	private String               pin;
102
	private String				 freebieItem;
103
	private String				 dealText;
104
	private String 				 parentOrderIdForFreebieOrder;
105
	private String				 freebieOrderId;
7393 anupam.sin 106
	private double               cashAmount;
107
	private double               cardAmount;
108
    private StoreOrderDetail     storeOrderDetail;
7826 manish.sha 109
    //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7830 anupam.sin 110
    private AmazonOrder          amazonOrder = null;
7826 manish.sha 111
    private Provider             provider;
112
    //End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
2674 vikas 113
 
7372 kshitij.so 114
	public UserOrderInfoController() {
115
		super();
116
		setOfcancellableStates = new HashSet<OrderStatus>();
117
		setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
118
		setOfcancellableStates.add(OrderStatus.INVENTORY_LOW);
119
		setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
120
		setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
121
		setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
122
		setOfcancellableStates.add(OrderStatus.ACCEPTED);
123
		setOfcancellableStates.add(OrderStatus.BILLED);
124
	}
2674 vikas 125
 
7372 kshitij.so 126
	public String index() {
127
		try {
128
			PaymentClient paymentServiceClient = new PaymentClient();
129
			TransactionClient transactionServiceClient = new TransactionClient();
7826 manish.sha 130
			LogisticsClient logisticsServiceClient = new LogisticsClient();
131
 
7372 kshitij.so 132
			order = transactionServiceClient.getClient().getOrder(orderId);
7826 manish.sha 133
			//Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7830 anupam.sin 134
			try {
135
			    amazonOrder = transactionServiceClient.getClient().getAmazonOrder(orderId);
136
			} catch (Exception e) {
137
			    log.error("No Amazon order found with orderId " + orderId, e);
138
			}
7826 manish.sha 139
			provider = logisticsServiceClient.getClient().getProvider(order.getLogistics_provider_id());
140
			//End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7393 anupam.sin 141
			if(order.getSource() == 2) {
142
    			storeOrderDetail = transactionServiceClient.getClient().getStoreOrderDetail(order.getId(),order.getStoreId());
7399 anupam.sin 143
    			if(order.getStatus().getValue() == 15 || order.getStatus().getValue() == 34) {
144
    			    setCashAmount(storeOrderDetail.getCashRefundAmount());
145
                    setCardAmount(storeOrderDetail.getCardRefundAmount()); 
146
    			} else {
147
        			setCashAmount(storeOrderDetail.getCashAmount());
148
        			setCardAmount(storeOrderDetail.getCardAmount());
149
    			}
7393 anupam.sin 150
			}
7372 kshitij.so 151
			if(order.getFreebieItemId()>0) {
152
				CatalogService.Client catalogClient = new CatalogClient().getClient();
153
				Item item = catalogClient.getItem(order.getFreebieItemId());
154
				freebieItem = item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
155
			}
3090 mandeep.dh 156
 
7372 kshitij.so 157
			if(order.getLineitems().get(0).getDealText()!=null && !order.getLineitems().get(0).getDealText().isEmpty()) {
158
				dealText = order.getLineitems().get(0).getDealText();
159
			}
160
			List<in.shop2020.model.v1.order.Attribute> attributes = 
161
				transactionServiceClient.getClient().getAllAttributesForOrderId(orderId);
3578 mandeep.dh 162
 
7372 kshitij.so 163
			for(in.shop2020.model.v1.order.Attribute attribute: attributes){
164
				if(attribute.getName().equals("parentOrderIdForFreebie")){
165
					parentOrderIdForFreebieOrder = attribute.getValue();
166
				} else if (attribute.getName().equals("freebieOrderId")){
167
					freebieOrderId = attribute.getValue();
168
				}
169
			}
4689 anupam.sin 170
 
7372 kshitij.so 171
			payments = paymentServiceClient.getClient()
172
			.getPaymentForTxnId(order.getTransactionId());
4689 anupam.sin 173
 
4416 mandeep.dh 174
 
3578 mandeep.dh 175
 
7372 kshitij.so 176
			// Spawning a thread to capture shipment updates from Bluedart
177
			// This is done to ensure that response from Crm web app is sent
178
			// within given time limits. Also, we wont be affected in the cases 
179
			// where bluedart site is down or slow
180
			Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
181
				public Boolean call() throws Exception {
182
					if (order.getLogistics_provider_id() == 1)
183
						shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
184
					else if (order.getLogistics_provider_id() == 2) {
185
						shipmentUpdates = aramexTrackingService.getUpdates(order.getAirwaybill_no());
186
					}
187
					else if (order.getLogistics_provider_id() == 3) {
188
						shipmentUpdates = delhiveryTrackingService.getUpdates(order.getAirwaybill_no());
189
					}
190
					else if (order.getLogistics_provider_id() == 6) {
191
						shipmentUpdates = redexpressTrackingService.getUpdates(order.getAirwaybill_no());
192
					}
193
					else {
194
						shipmentUpdates = new ArrayList<ShipmentUpdate>();
195
						log.error("Error : providerId = " + order.getLogistics_provider_id() + "for orderId : " + order.getId());
196
					}
197
					return true;
198
				}
199
			}), 60, TimeUnit.SECONDS);
2674 vikas 200
 
7372 kshitij.so 201
			if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
202
				populateCODTicketId(order.getCustomer_id());
203
			}
4142 mandeep.dh 204
 
7372 kshitij.so 205
			if (canEditOrderAddress()) {
206
				userContextServiceClient = new UserClient().getClient();
207
				addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
208
			}
3578 mandeep.dh 209
 
7372 kshitij.so 210
		} catch (TTransportException e) {
211
			log.error("Unable to create thrift Client", e);
212
		} catch (TransactionServiceException e) {
213
			addActionError("Invalid order id or no order selected.");
214
		} catch (TException e) {
215
			log.error("Unable to get thrift Client", e);
216
		} catch (PaymentException e) {
217
			log.error("Unable to get payments for transctionId : " + order.getTransactionId(), e);
218
		} catch (InterruptedException e) {
219
			log.error("Thread was interrupted", e);
220
		} catch (UserContextException e) {
221
			log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
222
		} catch(CatalogServiceException csex) {
223
			log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
224
		}
7826 manish.sha 225
		catch (LogisticsServiceException e) {
226
			log.error("Unable to get provider for logictics provider id : " + order.getLogistics_provider_id(), e);
227
		}
7372 kshitij.so 228
		return INDEX;
229
	}
4689 anupam.sin 230
 
7372 kshitij.so 231
	private boolean canEditOrderAddress() {
232
		return false;
233
	}
4689 anupam.sin 234
 
7372 kshitij.so 235
	private void populateCODTicketId(long customerId) {
236
		try {
237
			SearchFilter searchFilter = new SearchFilter();
238
			searchFilter.setTicketCategory(TicketCategory.COD_VERIFICATION);
239
			searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
240
			searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
241
			searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
242
			searchFilter.setCustomerId(customerId);
243
			crmServiceClient = new CRMClient().getClient();
244
			List<Ticket> tickets = crmServiceClient.getTickets(searchFilter);
245
			if (tickets != null && !tickets.isEmpty()) {
246
				codTicketId = tickets.get(0).getId();
247
			}
248
		} catch (TException e) {
249
			log.error("Error fetching tickets for customerId: " + customerId, e);
250
		}
251
	}
4689 anupam.sin 252
 
7372 kshitij.so 253
	public String markOrderForCancellation() {
254
		try{
255
			TransactionClient transactionServiceClient = new TransactionClient();
256
			log.info("URL = " + request.getRequestURI());
257
			log.info("Initiator = " + request.getParameter("cancellationInitiator"));
258
			log.info("orderId = " + request.getParameter("orderId"));
7393 anupam.sin 259
 
260
			order = transactionServiceClient.getClient().getOrder(orderId);
261
 
7499 anupam.sin 262
			/**
263
			 * If the order is from store then refund the order directly.
264
			 */
7393 anupam.sin 265
			if (order.getSource() == 2) {
266
			    String plainTextbody = "";
267
			    if(body!=null && !body.isEmpty()){
268
                    plainTextbody = new Source(body).getTextExtractor().toString();
269
                }
7612 anupam.sin 270
 
271
			    if(cashAmount + cardAmount > order.getAdvanceAmount()) {
272
			        log.error("Could not mark order for Cancellation, OrderId : " + orderId);
273
			        return "index";
274
			    }
275
 
276
			    transactionServiceClient.getClient().saveRefundAmountsForStoreOrder(orderId, order.getStoreId(), cashAmount, cardAmount);
7399 anupam.sin 277
			    if (cancellationInitiator.equals("CUSTOMER")) {
278
			        transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
279
			        transactionServiceClient.getClient().markOrderCancellationRequestConfirmed(orderId);
280
			    }
7393 anupam.sin 281
			    transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
7499 anupam.sin 282
			} else {
283
		         if (cancellationInitiator.equals("CUSTOMER")) {
284
	                transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
285
	                long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
286
	                Ticket ticket = new Ticket();
287
	                String plainTextbody = "";
288
	                if(body!=null && !body.isEmpty()){
289
	                    plainTextbody = new Source(body).getTextExtractor().toString();
290
	                }
291
	                ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
292
	                ticket.setCreatorId(creatorId);
293
	                ticket.setStatus(TicketStatus.OPEN);
294
	                ticket.setPriority(TicketPriority.HIGH);
295
	                ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
296
	                ticket.setOrderId(orderId);
4689 anupam.sin 297
 
7499 anupam.sin 298
	                Activity activity = new Activity();
299
	                activity.setDescription("Creating Ticket");
300
	                activity.setType(ActivityType.OTHER);
301
	                activity.setTicketPriority(TicketPriority.HIGH);
302
	                activity.setTicketStatus(TicketStatus.OPEN);
303
	                activity.setCreatorId(creatorId);
304
	                activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
305
	                activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
4689 anupam.sin 306
 
7499 anupam.sin 307
	                ticket.setCustomerId(order.getCustomer_id());
308
	                activity.setCustomerId(order.getCustomer_id());
309
	                ticket.setCustomerName(order.getCustomer_name());
310
	                activity.setCustomerName(order.getCustomer_name());
311
	                ticket.setCustomerEmailId(order.getCustomer_email());
312
	                activity.setCustomerEmailId(order.getCustomer_email());
313
	                ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
314
	                activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
4689 anupam.sin 315
 
7499 anupam.sin 316
	                crmServiceClient = new CRMClient().getClient();
317
	                crmServiceClient.insertTicket(ticket, activity);
318
	            } 
319
	            else if (cancellationInitiator.equals("INTERNAL")) {
320
	                String plainTextbody = "";
321
	                if(body!=null && !body.isEmpty()){
322
	                    plainTextbody = new Source(body).getTextExtractor().toString();
323
	                }
324
	                boolean status_returned = transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
325
	                if (status_returned) {
326
	                    order = transactionServiceClient.getClient().getOrder(orderId);
327
	                    long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
328
	                    Ticket ticket = new Ticket();
329
	                    ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
330
	                    ticket.setCreatorId(creatorId);
331
	                    ticket.setAssigneeId(36);
332
	                    ticket.setStatus(TicketStatus.OPEN);
333
	                    ticket.setPriority(TicketPriority.MEDIUM);
334
	                    ticket.setCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
335
	                    ticket.setOrderId(orderId);
336
	                    ticket.setCustomerId(order.getCustomer_id());
337
	                    ticket.setCustomerName(order.getCustomer_name());
338
	                    ticket.setCustomerEmailId(order.getCustomer_email());
339
	                    ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 340
 
7499 anupam.sin 341
	                    Activity activity = new Activity();
342
	                    activity.setDescription("Creating Ticket");
343
	                    activity.setType(ActivityType.OTHER);
344
	                    activity.setTicketPriority(TicketPriority.MEDIUM);
345
	                    activity.setTicketStatus(TicketStatus.OPEN);
346
	                    activity.setCreatorId(creatorId);
347
	                    activity.setTicketAssigneeId(36);
348
	                    activity.setTicketCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
349
	                    activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
350
	                    activity.setCustomerId(order.getCustomer_id());
351
	                    activity.setCustomerName(order.getCustomer_name());
352
	                    activity.setCustomerEmailId(order.getCustomer_email());
353
	                    activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 354
 
7499 anupam.sin 355
	                    crmServiceClient = new CRMClient().getClient();
356
	                    crmServiceClient.insertTicket(ticket, activity);
357
	                }
358
	            }
7372 kshitij.so 359
			}
360
		} catch(Exception e) {
361
			log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
362
		}
363
		return index();
364
	}
7221 kshitij.so 365
 
7372 kshitij.so 366
	public void getOrderConfirmationMail() throws IOException, TException, ConfigException, TransactionServiceException {
367
		TransactionClient transactionServiceClient = new TransactionClient();
368
		order = transactionServiceClient.getClient().getOrder(orderId);
369
		long source = order.getTransactionId();
370
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
371
		String mail = helperClient.getClient().getOrderConfirmationMail(source);
372
		File file = new File("/tmp/temp");
7643 manish.sha 373
		//Start:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
374
		if(mail.isEmpty() || mail==null || mail=="")
375
			mail="<html><body><p>Sorry, Required e-mail for mentioned order does not exist in the system !!!</p></body></html>";
376
		//End:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
7221 kshitij.so 377
 
7372 kshitij.so 378
		FileWriter writer = new FileWriter(file);
379
		writer.append(mail);
380
		writer.close();
4689 anupam.sin 381
 
7372 kshitij.so 382
		byte[] buffer = new byte[(int)file.length()];
383
		InputStream input = null;
384
		try {
385
			int totalBytesRead = 0;
386
			input = new BufferedInputStream(new FileInputStream(file));
387
			while(totalBytesRead < buffer.length){
388
				int bytesRemaining = buffer.length - totalBytesRead;
389
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
390
				if (bytesRead > 0){
391
					totalBytesRead = totalBytesRead + bytesRead;
392
				}
393
			}
394
		}
395
		finally {
396
			input.close();
397
			file.delete();
398
		}
3578 mandeep.dh 399
 
4142 mandeep.dh 400
 
7372 kshitij.so 401
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
2674 vikas 402
 
7372 kshitij.so 403
		ServletOutputStream sos;
404
		try {
405
			sos = response.getOutputStream();
406
			sos.write(buffer);
407
			sos.flush();
408
		} catch (IOException e) {
409
			System.out.println("Unable to stream the manifest file");
410
		}   
411
	}
4142 mandeep.dh 412
 
7372 kshitij.so 413
	public void getOrderDeliveryMail() throws IOException, TException, ConfigException, TransactionServiceException {
414
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
415
		String mail = helperClient.getClient().getOrderDeliveryMail(orderId);
416
		File file = new File("/tmp/temp");
7643 manish.sha 417
		//Start:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
418
		if(mail.isEmpty() || mail==null || mail=="")
419
			mail="<html><body><p>Sorry, Required e-mail for mentioned order does not exist in the system anymore !!!</p></body></html>";
420
		//End:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
7372 kshitij.so 421
		FileWriter writer = new FileWriter(file);
422
		writer.append(mail);
423
		writer.close();
2674 vikas 424
 
7372 kshitij.so 425
		byte[] buffer = new byte[(int)file.length()];
426
		InputStream input = null;
427
		try {
428
			int totalBytesRead = 0;
429
			input = new BufferedInputStream(new FileInputStream(file));
430
			while(totalBytesRead < buffer.length){
431
				int bytesRemaining = buffer.length - totalBytesRead;
432
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
433
				if (bytesRead > 0){
434
					totalBytesRead = totalBytesRead + bytesRead;
435
				}
436
			}
437
		}
438
		finally {
439
			input.close();
440
			file.delete();
441
		}
3578 mandeep.dh 442
 
5845 mandeep.dh 443
 
7372 kshitij.so 444
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
4142 mandeep.dh 445
 
7372 kshitij.so 446
		ServletOutputStream sos;
447
		try {
448
			sos = response.getOutputStream();
449
			sos.write(buffer);
450
			sos.flush();
451
		} catch (IOException e) {
452
			System.out.println("Unable to stream the manifest file");
453
		}   
454
	}
2674 vikas 455
 
7372 kshitij.so 456
	public boolean canOrderBeCancelled() {
457
		if (setOfcancellableStates.contains(order.getStatus())) {
458
			return true;
459
		}
460
		return false;
461
	}
2674 vikas 462
 
7372 kshitij.so 463
	public String getPaymentGateway(Payment payment) {
464
		String gatewayName = "";
2674 vikas 465
 
7372 kshitij.so 466
		try {
467
			Client paymentServiceClient = new PaymentClient().getClient();
468
			gatewayName = paymentServiceClient.getPaymentGateway(payment.getGatewayId()).getName();
469
		} catch (TTransportException e) {
470
		} catch (PaymentException e) {
471
		} catch (TException e) {
472
		}
3090 mandeep.dh 473
 
7372 kshitij.so 474
		return gatewayName;
475
	}
3499 mandeep.dh 476
 
7372 kshitij.so 477
	public int convertDouble(double value) {
478
		return (int)value;
479
	}
4142 mandeep.dh 480
 
7372 kshitij.so 481
	public String getInsuranceExpiryDate(long DeliveryDate) {
482
		if (DeliveryDate == 0) {
483
			return "N/A";
484
		}
485
		Calendar cal = Calendar.getInstance();
486
		cal.setTimeInMillis(DeliveryDate);
487
		cal.add(Calendar.YEAR, 1);
488
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
489
		return sdf.format(cal.getTime());
490
	}
4142 mandeep.dh 491
 
7372 kshitij.so 492
	public String getShippingAddressOfStore(long storeId) {
493
		try {
494
			in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
495
			PickupStore store = client.getPickupStore(storeId);
496
			return StringUtils.join(new String[] {
497
					store.getName(),
498
					store.getLine1(),
499
					store.getLine2(),
500
					store.getPin(),
501
					store.getCity(),
502
					store.getState(),
503
					store.getPhone()}, ",");
504
		} catch (Exception e) {
505
			return "";
506
		}
507
	}
4241 anupam.sin 508
 
7372 kshitij.so 509
	public String getAddress(Order order) {
510
		return ModelUtils.extractAddressFromOrder(order);
511
	}
4241 anupam.sin 512
 
7372 kshitij.so 513
	public String changeShippingAddress() {
514
		try {
515
			TransactionClient transactionServiceClient = new TransactionClient();
516
			transactionServiceClient.getClient().changeShippingAddress(orderId, line1, line2, city, state, pin);
517
		} catch(Exception e) {
518
			log.error("Unable to update address for orderId : " + orderId + "and address : " + 
519
					line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
520
		}
521
		return null;
522
	}
7399 anupam.sin 523
 
7730 anupam.sin 524
	public String convertStoreToNormal() {
525
	    try{
526
	        TransactionClient transactionServiceClient = new TransactionClient();
527
	        transactionServiceClient.getClient().convertStoreToNormal(orderId);
528
	    } catch(Exception e) {
529
	        log.error("Unable to convert to normal order", e);
530
	    }
531
	    return null;
532
	}
533
 
7399 anupam.sin 534
	public String getStoreDetails(long storeId) {
535
	    try {
536
	        TransactionClient tcl = new TransactionClient();
537
	        HotspotStore store = tcl.getClient().getHotspotStore(storeId, "");
538
	        return store.getHotspotId() + " - " + store.getCity(); 
539
	    } catch (Exception e) {
540
	        log.error("Unable to get hostspotStore for id : " + storeId, e);
541
	    }
542
	    return "N/A";
543
	}
4689 anupam.sin 544
 
7372 kshitij.so 545
	public Address getShippingAddress(Order order) {
546
		Address address = new Address();
547
		address.setLine1(order.getCustomer_address1());
548
		address.setLine2(order.getCustomer_address2());
549
		address.setCity(order.getCustomer_city());
550
		address.setState(order.getCustomer_state());
551
		address.setPin(order.getCustomer_pincode());
552
		return address;
553
	}
4689 anupam.sin 554
 
7372 kshitij.so 555
	public String getPaymentMethod(List<Attribute> paymentAttributes) {
556
		String paymentMethod = null;
557
		if (paymentAttributes == null || paymentAttributes.isEmpty()) {
558
			return "N/A";
559
		}
560
		for (Attribute a : paymentAttributes) {
561
			if ("payMethod".equals(a.getName())) {
562
				paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
563
				break;
564
			}
565
		}
566
		return paymentMethod != null ? paymentMethod : "N/A";
567
	}
4689 anupam.sin 568
 
7372 kshitij.so 569
	public void setOrderId(String orderId) {
570
		try {
571
			this.orderId = Long.parseLong(orderId);
572
		} catch (NumberFormatException e) {
573
			log.error(e);
574
		}
575
	}
4689 anupam.sin 576
 
7372 kshitij.so 577
	public List<Payment> getPayments() {
578
		return payments;
579
	}
4689 anupam.sin 580
 
7372 kshitij.so 581
	public List<ShipmentUpdate> getShipmentUpdates() {
582
		return shipmentUpdates;
583
	}
4689 anupam.sin 584
 
7372 kshitij.so 585
	public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
586
		this.shipmentUpdates = shipmentUpdates;
587
	}
6985 anupam.sin 588
 
7372 kshitij.so 589
	public Order getOrder() {
590
		return order;
591
	}
6985 anupam.sin 592
 
7372 kshitij.so 593
	public void setOrder(Order order) {
594
		this.order = order;
595
	}
6985 anupam.sin 596
 
7372 kshitij.so 597
	public Long getCodTicketId() {
598
		return codTicketId;
599
	}
6985 anupam.sin 600
 
7372 kshitij.so 601
	public void setCodTicketId(Long codTicketId) {
602
		this.codTicketId = codTicketId;
603
	}
6985 anupam.sin 604
 
7372 kshitij.so 605
	public List<Address> getAddresses() {
606
		return addresses;
607
	}
6985 anupam.sin 608
 
7372 kshitij.so 609
	public void setAddresses(List<Address> addresses) {
610
		this.addresses = addresses;
611
	}
6985 anupam.sin 612
 
7372 kshitij.so 613
	public String getOrderStatusDescription(Order order) {
614
		String status = order.getStatus().getDescription();
6985 anupam.sin 615
 
7372 kshitij.so 616
		if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
617
			status = "Completed";
618
		}
6985 anupam.sin 619
 
7372 kshitij.so 620
		return status;
621
	}
6985 anupam.sin 622
 
7372 kshitij.so 623
	public String getCancellationInitiator() {
624
		return cancellationInitiator;
625
	}
7190 amar.kumar 626
 
7372 kshitij.so 627
	public void setCancellationInitiator(String cancellationInitiator) {
628
		this.cancellationInitiator = cancellationInitiator;
629
	}
630
 
631
	public String getCancelReason() {
632
		return cancelReason;
633
	}
634
 
635
	public void setCancelReason(String cancelReason) {
636
		this.cancelReason = cancelReason;
637
	}
638
 
639
	public String getBody() {
640
		return body;
641
	}
642
 
643
	public void setBody(String body) {
644
		this.body = body;
645
	}
646
 
647
	public String getLine1() {
648
		return line1;
649
	}
650
 
651
	public void setLine1(String line1) {
652
		this.line1 = line1;
653
	}
654
 
655
	public String getLine2() {
656
		return line2;
657
	}
658
 
659
	public void setLine2(String line2) {
660
		this.line2 = line2;
661
	}
662
 
663
	public String getCity() {
664
		return city;
665
	}
666
 
667
	public void setCity(String city) {
668
		this.city = city;
669
	}
670
 
671
	public String getState() {
672
		return state;
673
	}
674
 
675
	public void setState(String state) {
676
		this.state = state;
677
	}
678
 
679
	public String getPin() {
680
		return pin;
681
	}
682
 
683
	public void setPin(String pin) {
684
		this.pin = pin;
685
	}
686
 
7190 amar.kumar 687
	public String getFreebieItem() {
688
		return freebieItem;
689
	}
690
 
691
	public void setFreebieItem(String freebieItem) {
692
		this.freebieItem = freebieItem;
693
	}
694
 
695
	public String getDealText() {
696
		return dealText;
697
	}
698
 
699
	public void setDealText(String dealText) {
700
		this.dealText = dealText;
701
	}
702
 
703
	public String getParentOrderIdForFreebieOrder() {
704
		return parentOrderIdForFreebieOrder;
705
	}
706
 
707
	public void setParentOrderIdForFreebieOrder(String parentOrderIdForFreebieOrder) {
708
		this.parentOrderIdForFreebieOrder = parentOrderIdForFreebieOrder;
709
	}
710
 
711
	public String getFreebieOrderId() {
712
		return freebieOrderId;
713
	}
714
 
715
	public void setFreebieOrderId(String freebieOrderId) {
716
		this.freebieOrderId = freebieOrderId;
717
	}
7372 kshitij.so 718
 
7393 anupam.sin 719
    public void setCashAmount(double cashAmount) {
720
        this.cashAmount = cashAmount;
721
    }
722
 
723
    public double getCashAmount() {
724
        return cashAmount;
725
    }
726
 
727
    public void setCardAmount(double cardAmount) {
728
        this.cardAmount = cardAmount;
729
    }
730
 
731
    public double getCardAmount() {
732
        return cardAmount;
733
    }
734
 
735
    public long getOrderId() {
736
        return orderId;
737
    }
738
 
739
    public void setOrderId(long orderId) {
740
        this.orderId = orderId;
741
    }
742
 
743
    public StoreOrderDetail getStoreOrderDetail() {
744
        return storeOrderDetail;
745
    }
746
 
747
    public void setStoreOrderDetail(StoreOrderDetail storeOrderDetail) {
748
        this.storeOrderDetail = storeOrderDetail;
749
    }
7826 manish.sha 750
 
751
  //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
752
    public AmazonOrder getAmazonOrder() {
753
		return amazonOrder;
754
	}
7393 anupam.sin 755
 
7826 manish.sha 756
	public void setAmazonOrder(AmazonOrder amazonOrder) {
757
		this.amazonOrder = amazonOrder;
758
	}
759
 
760
	public Provider getProvider() {
761
		return provider;
762
	}
763
 
764
	public void setProvider(Provider provider) {
765
		this.provider = provider;
766
	}
767
	//End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
768
 
2674 vikas 769
}