Subversion Repositories SmartDukaan

Rev

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