Subversion Repositories SmartDukaan

Rev

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