Subversion Repositories SmartDukaan

Rev

Rev 7499 | Rev 7612 | 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
 
7499 anupam.sin 243
			/**
244
			 * If the order is from store then refund the order directly.
245
			 */
7393 anupam.sin 246
			if (order.getSource() == 2) {
247
			    String plainTextbody = "";
248
			    if(body!=null && !body.isEmpty()){
249
                    plainTextbody = new Source(body).getTextExtractor().toString();
250
                }
7399 anupam.sin 251
			    if (cancellationInitiator.equals("CUSTOMER")) {
252
			        transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
253
			        transactionServiceClient.getClient().markOrderCancellationRequestConfirmed(orderId);
254
			    }
7393 anupam.sin 255
			    transactionServiceClient.getClient().saveRefundAmountsForStoreOrder(orderId, order.getStoreId(), cashAmount, cardAmount);
256
			    transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
7499 anupam.sin 257
			} else {
258
		         if (cancellationInitiator.equals("CUSTOMER")) {
259
	                transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
260
	                long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
261
	                Ticket ticket = new Ticket();
262
	                String plainTextbody = "";
263
	                if(body!=null && !body.isEmpty()){
264
	                    plainTextbody = new Source(body).getTextExtractor().toString();
265
	                }
266
	                ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
267
	                ticket.setCreatorId(creatorId);
268
	                ticket.setStatus(TicketStatus.OPEN);
269
	                ticket.setPriority(TicketPriority.HIGH);
270
	                ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
271
	                ticket.setOrderId(orderId);
4689 anupam.sin 272
 
7499 anupam.sin 273
	                Activity activity = new Activity();
274
	                activity.setDescription("Creating Ticket");
275
	                activity.setType(ActivityType.OTHER);
276
	                activity.setTicketPriority(TicketPriority.HIGH);
277
	                activity.setTicketStatus(TicketStatus.OPEN);
278
	                activity.setCreatorId(creatorId);
279
	                activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
280
	                activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
4689 anupam.sin 281
 
7499 anupam.sin 282
	                ticket.setCustomerId(order.getCustomer_id());
283
	                activity.setCustomerId(order.getCustomer_id());
284
	                ticket.setCustomerName(order.getCustomer_name());
285
	                activity.setCustomerName(order.getCustomer_name());
286
	                ticket.setCustomerEmailId(order.getCustomer_email());
287
	                activity.setCustomerEmailId(order.getCustomer_email());
288
	                ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
289
	                activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
4689 anupam.sin 290
 
7499 anupam.sin 291
	                crmServiceClient = new CRMClient().getClient();
292
	                crmServiceClient.insertTicket(ticket, activity);
293
	            } 
294
	            else if (cancellationInitiator.equals("INTERNAL")) {
295
	                String plainTextbody = "";
296
	                if(body!=null && !body.isEmpty()){
297
	                    plainTextbody = new Source(body).getTextExtractor().toString();
298
	                }
299
	                boolean status_returned = transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
300
	                if (status_returned) {
301
	                    order = transactionServiceClient.getClient().getOrder(orderId);
302
	                    long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
303
	                    Ticket ticket = new Ticket();
304
	                    ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
305
	                    ticket.setCreatorId(creatorId);
306
	                    ticket.setAssigneeId(36);
307
	                    ticket.setStatus(TicketStatus.OPEN);
308
	                    ticket.setPriority(TicketPriority.MEDIUM);
309
	                    ticket.setCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
310
	                    ticket.setOrderId(orderId);
311
	                    ticket.setCustomerId(order.getCustomer_id());
312
	                    ticket.setCustomerName(order.getCustomer_name());
313
	                    ticket.setCustomerEmailId(order.getCustomer_email());
314
	                    ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 315
 
7499 anupam.sin 316
	                    Activity activity = new Activity();
317
	                    activity.setDescription("Creating Ticket");
318
	                    activity.setType(ActivityType.OTHER);
319
	                    activity.setTicketPriority(TicketPriority.MEDIUM);
320
	                    activity.setTicketStatus(TicketStatus.OPEN);
321
	                    activity.setCreatorId(creatorId);
322
	                    activity.setTicketAssigneeId(36);
323
	                    activity.setTicketCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
324
	                    activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
325
	                    activity.setCustomerId(order.getCustomer_id());
326
	                    activity.setCustomerName(order.getCustomer_name());
327
	                    activity.setCustomerEmailId(order.getCustomer_email());
328
	                    activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 329
 
7499 anupam.sin 330
	                    crmServiceClient = new CRMClient().getClient();
331
	                    crmServiceClient.insertTicket(ticket, activity);
332
	                }
333
	            }
7372 kshitij.so 334
			}
335
		} catch(Exception e) {
336
			log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
337
		}
338
		return index();
339
	}
7221 kshitij.so 340
 
7372 kshitij.so 341
	public void getOrderConfirmationMail() throws IOException, TException, ConfigException, TransactionServiceException {
342
		TransactionClient transactionServiceClient = new TransactionClient();
343
		order = transactionServiceClient.getClient().getOrder(orderId);
344
		long source = order.getTransactionId();
345
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
346
		String mail = helperClient.getClient().getOrderConfirmationMail(source);
347
		File file = new File("/tmp/temp");
7221 kshitij.so 348
 
7372 kshitij.so 349
		FileWriter writer = new FileWriter(file);
350
		writer.append(mail);
351
		writer.close();
4689 anupam.sin 352
 
7372 kshitij.so 353
		byte[] buffer = new byte[(int)file.length()];
354
		InputStream input = null;
355
		try {
356
			int totalBytesRead = 0;
357
			input = new BufferedInputStream(new FileInputStream(file));
358
			while(totalBytesRead < buffer.length){
359
				int bytesRemaining = buffer.length - totalBytesRead;
360
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
361
				if (bytesRead > 0){
362
					totalBytesRead = totalBytesRead + bytesRead;
363
				}
364
			}
365
		}
366
		finally {
367
			input.close();
368
			file.delete();
369
		}
3578 mandeep.dh 370
 
4142 mandeep.dh 371
 
7372 kshitij.so 372
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
2674 vikas 373
 
7372 kshitij.so 374
		ServletOutputStream sos;
375
		try {
376
			sos = response.getOutputStream();
377
			sos.write(buffer);
378
			sos.flush();
379
		} catch (IOException e) {
380
			System.out.println("Unable to stream the manifest file");
381
		}   
382
	}
4142 mandeep.dh 383
 
7372 kshitij.so 384
	public void getOrderDeliveryMail() throws IOException, TException, ConfigException, TransactionServiceException {
385
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
386
		String mail = helperClient.getClient().getOrderDeliveryMail(orderId);
387
		File file = new File("/tmp/temp");
4142 mandeep.dh 388
 
7372 kshitij.so 389
		FileWriter writer = new FileWriter(file);
390
		writer.append(mail);
391
		writer.close();
2674 vikas 392
 
7372 kshitij.so 393
		byte[] buffer = new byte[(int)file.length()];
394
		InputStream input = null;
395
		try {
396
			int totalBytesRead = 0;
397
			input = new BufferedInputStream(new FileInputStream(file));
398
			while(totalBytesRead < buffer.length){
399
				int bytesRemaining = buffer.length - totalBytesRead;
400
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
401
				if (bytesRead > 0){
402
					totalBytesRead = totalBytesRead + bytesRead;
403
				}
404
			}
405
		}
406
		finally {
407
			input.close();
408
			file.delete();
409
		}
3578 mandeep.dh 410
 
5845 mandeep.dh 411
 
7372 kshitij.so 412
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
4142 mandeep.dh 413
 
7372 kshitij.so 414
		ServletOutputStream sos;
415
		try {
416
			sos = response.getOutputStream();
417
			sos.write(buffer);
418
			sos.flush();
419
		} catch (IOException e) {
420
			System.out.println("Unable to stream the manifest file");
421
		}   
422
	}
2674 vikas 423
 
7372 kshitij.so 424
	public boolean canOrderBeCancelled() {
425
		if (setOfcancellableStates.contains(order.getStatus())) {
426
			return true;
427
		}
428
		return false;
429
	}
2674 vikas 430
 
7372 kshitij.so 431
	public String getPaymentGateway(Payment payment) {
432
		String gatewayName = "";
2674 vikas 433
 
7372 kshitij.so 434
		try {
435
			Client paymentServiceClient = new PaymentClient().getClient();
436
			gatewayName = paymentServiceClient.getPaymentGateway(payment.getGatewayId()).getName();
437
		} catch (TTransportException e) {
438
		} catch (PaymentException e) {
439
		} catch (TException e) {
440
		}
3090 mandeep.dh 441
 
7372 kshitij.so 442
		return gatewayName;
443
	}
3499 mandeep.dh 444
 
7372 kshitij.so 445
	public int convertDouble(double value) {
446
		return (int)value;
447
	}
4142 mandeep.dh 448
 
7372 kshitij.so 449
	public String getInsuranceExpiryDate(long DeliveryDate) {
450
		if (DeliveryDate == 0) {
451
			return "N/A";
452
		}
453
		Calendar cal = Calendar.getInstance();
454
		cal.setTimeInMillis(DeliveryDate);
455
		cal.add(Calendar.YEAR, 1);
456
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
457
		return sdf.format(cal.getTime());
458
	}
4142 mandeep.dh 459
 
7372 kshitij.so 460
	public String getShippingAddressOfStore(long storeId) {
461
		try {
462
			in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
463
			PickupStore store = client.getPickupStore(storeId);
464
			return StringUtils.join(new String[] {
465
					store.getName(),
466
					store.getLine1(),
467
					store.getLine2(),
468
					store.getPin(),
469
					store.getCity(),
470
					store.getState(),
471
					store.getPhone()}, ",");
472
		} catch (Exception e) {
473
			return "";
474
		}
475
	}
4241 anupam.sin 476
 
7372 kshitij.so 477
	public String getAddress(Order order) {
478
		return ModelUtils.extractAddressFromOrder(order);
479
	}
4241 anupam.sin 480
 
7372 kshitij.so 481
	public String changeShippingAddress() {
482
		try {
483
			TransactionClient transactionServiceClient = new TransactionClient();
484
			transactionServiceClient.getClient().changeShippingAddress(orderId, line1, line2, city, state, pin);
485
		} catch(Exception e) {
486
			log.error("Unable to update address for orderId : " + orderId + "and address : " + 
487
					line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
488
		}
489
		return null;
490
	}
7399 anupam.sin 491
 
492
	public String getStoreDetails(long storeId) {
493
	    try {
494
	        TransactionClient tcl = new TransactionClient();
495
	        HotspotStore store = tcl.getClient().getHotspotStore(storeId, "");
496
	        return store.getHotspotId() + " - " + store.getCity(); 
497
	    } catch (Exception e) {
498
	        log.error("Unable to get hostspotStore for id : " + storeId, e);
499
	    }
500
	    return "N/A";
501
	}
4689 anupam.sin 502
 
7372 kshitij.so 503
	public Address getShippingAddress(Order order) {
504
		Address address = new Address();
505
		address.setLine1(order.getCustomer_address1());
506
		address.setLine2(order.getCustomer_address2());
507
		address.setCity(order.getCustomer_city());
508
		address.setState(order.getCustomer_state());
509
		address.setPin(order.getCustomer_pincode());
510
		return address;
511
	}
4689 anupam.sin 512
 
7372 kshitij.so 513
	public String getPaymentMethod(List<Attribute> paymentAttributes) {
514
		String paymentMethod = null;
515
		if (paymentAttributes == null || paymentAttributes.isEmpty()) {
516
			return "N/A";
517
		}
518
		for (Attribute a : paymentAttributes) {
519
			if ("payMethod".equals(a.getName())) {
520
				paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
521
				break;
522
			}
523
		}
524
		return paymentMethod != null ? paymentMethod : "N/A";
525
	}
4689 anupam.sin 526
 
7372 kshitij.so 527
	public void setOrderId(String orderId) {
528
		try {
529
			this.orderId = Long.parseLong(orderId);
530
		} catch (NumberFormatException e) {
531
			log.error(e);
532
		}
533
	}
4689 anupam.sin 534
 
7372 kshitij.so 535
	public List<Payment> getPayments() {
536
		return payments;
537
	}
4689 anupam.sin 538
 
7372 kshitij.so 539
	public List<ShipmentUpdate> getShipmentUpdates() {
540
		return shipmentUpdates;
541
	}
4689 anupam.sin 542
 
7372 kshitij.so 543
	public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
544
		this.shipmentUpdates = shipmentUpdates;
545
	}
6985 anupam.sin 546
 
7372 kshitij.so 547
	public Order getOrder() {
548
		return order;
549
	}
6985 anupam.sin 550
 
7372 kshitij.so 551
	public void setOrder(Order order) {
552
		this.order = order;
553
	}
6985 anupam.sin 554
 
7372 kshitij.so 555
	public Long getCodTicketId() {
556
		return codTicketId;
557
	}
6985 anupam.sin 558
 
7372 kshitij.so 559
	public void setCodTicketId(Long codTicketId) {
560
		this.codTicketId = codTicketId;
561
	}
6985 anupam.sin 562
 
7372 kshitij.so 563
	public List<Address> getAddresses() {
564
		return addresses;
565
	}
6985 anupam.sin 566
 
7372 kshitij.so 567
	public void setAddresses(List<Address> addresses) {
568
		this.addresses = addresses;
569
	}
6985 anupam.sin 570
 
7372 kshitij.so 571
	public String getOrderStatusDescription(Order order) {
572
		String status = order.getStatus().getDescription();
6985 anupam.sin 573
 
7372 kshitij.so 574
		if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
575
			status = "Completed";
576
		}
6985 anupam.sin 577
 
7372 kshitij.so 578
		return status;
579
	}
6985 anupam.sin 580
 
7372 kshitij.so 581
	public String getCancellationInitiator() {
582
		return cancellationInitiator;
583
	}
7190 amar.kumar 584
 
7372 kshitij.so 585
	public void setCancellationInitiator(String cancellationInitiator) {
586
		this.cancellationInitiator = cancellationInitiator;
587
	}
588
 
589
	public String getCancelReason() {
590
		return cancelReason;
591
	}
592
 
593
	public void setCancelReason(String cancelReason) {
594
		this.cancelReason = cancelReason;
595
	}
596
 
597
	public String getBody() {
598
		return body;
599
	}
600
 
601
	public void setBody(String body) {
602
		this.body = body;
603
	}
604
 
605
	public String getLine1() {
606
		return line1;
607
	}
608
 
609
	public void setLine1(String line1) {
610
		this.line1 = line1;
611
	}
612
 
613
	public String getLine2() {
614
		return line2;
615
	}
616
 
617
	public void setLine2(String line2) {
618
		this.line2 = line2;
619
	}
620
 
621
	public String getCity() {
622
		return city;
623
	}
624
 
625
	public void setCity(String city) {
626
		this.city = city;
627
	}
628
 
629
	public String getState() {
630
		return state;
631
	}
632
 
633
	public void setState(String state) {
634
		this.state = state;
635
	}
636
 
637
	public String getPin() {
638
		return pin;
639
	}
640
 
641
	public void setPin(String pin) {
642
		this.pin = pin;
643
	}
644
 
7190 amar.kumar 645
	public String getFreebieItem() {
646
		return freebieItem;
647
	}
648
 
649
	public void setFreebieItem(String freebieItem) {
650
		this.freebieItem = freebieItem;
651
	}
652
 
653
	public String getDealText() {
654
		return dealText;
655
	}
656
 
657
	public void setDealText(String dealText) {
658
		this.dealText = dealText;
659
	}
660
 
661
	public String getParentOrderIdForFreebieOrder() {
662
		return parentOrderIdForFreebieOrder;
663
	}
664
 
665
	public void setParentOrderIdForFreebieOrder(String parentOrderIdForFreebieOrder) {
666
		this.parentOrderIdForFreebieOrder = parentOrderIdForFreebieOrder;
667
	}
668
 
669
	public String getFreebieOrderId() {
670
		return freebieOrderId;
671
	}
672
 
673
	public void setFreebieOrderId(String freebieOrderId) {
674
		this.freebieOrderId = freebieOrderId;
675
	}
7372 kshitij.so 676
 
7393 anupam.sin 677
    public void setCashAmount(double cashAmount) {
678
        this.cashAmount = cashAmount;
679
    }
680
 
681
    public double getCashAmount() {
682
        return cashAmount;
683
    }
684
 
685
    public void setCardAmount(double cardAmount) {
686
        this.cardAmount = cardAmount;
687
    }
688
 
689
    public double getCardAmount() {
690
        return cardAmount;
691
    }
692
 
693
    public long getOrderId() {
694
        return orderId;
695
    }
696
 
697
    public void setOrderId(long orderId) {
698
        this.orderId = orderId;
699
    }
700
 
701
    public StoreOrderDetail getStoreOrderDetail() {
702
        return storeOrderDetail;
703
    }
704
 
705
    public void setStoreOrderDetail(StoreOrderDetail storeOrderDetail) {
706
        this.storeOrderDetail = storeOrderDetail;
707
    }
708
 
2674 vikas 709
}