Subversion Repositories SmartDukaan

Rev

Rev 7399 | Rev 7572 | 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 String getProductName(LineItem lineItem) {
446
		String name = ModelUtils.extractProductNameFromLineItem(lineItem);
3499 mandeep.dh 447
 
7372 kshitij.so 448
		if (lineItem.getColor() != null && !lineItem.getColor().isEmpty()) {
449
			name += "(" + lineItem.getColor() + ")";
450
		}
3578 mandeep.dh 451
 
7372 kshitij.so 452
		return name;
453
	}
3578 mandeep.dh 454
 
7372 kshitij.so 455
	public int convertDouble(double value) {
456
		return (int)value;
457
	}
4142 mandeep.dh 458
 
7372 kshitij.so 459
	public String getInsuranceExpiryDate(long DeliveryDate) {
460
		if (DeliveryDate == 0) {
461
			return "N/A";
462
		}
463
		Calendar cal = Calendar.getInstance();
464
		cal.setTimeInMillis(DeliveryDate);
465
		cal.add(Calendar.YEAR, 1);
466
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
467
		return sdf.format(cal.getTime());
468
	}
4142 mandeep.dh 469
 
7372 kshitij.so 470
	public String getShippingAddressOfStore(long storeId) {
471
		try {
472
			in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
473
			PickupStore store = client.getPickupStore(storeId);
474
			return StringUtils.join(new String[] {
475
					store.getName(),
476
					store.getLine1(),
477
					store.getLine2(),
478
					store.getPin(),
479
					store.getCity(),
480
					store.getState(),
481
					store.getPhone()}, ",");
482
		} catch (Exception e) {
483
			return "";
484
		}
485
	}
4241 anupam.sin 486
 
7372 kshitij.so 487
	public String getAddress(Order order) {
488
		return ModelUtils.extractAddressFromOrder(order);
489
	}
4241 anupam.sin 490
 
7372 kshitij.so 491
	public String changeShippingAddress() {
492
		try {
493
			TransactionClient transactionServiceClient = new TransactionClient();
494
			transactionServiceClient.getClient().changeShippingAddress(orderId, line1, line2, city, state, pin);
495
		} catch(Exception e) {
496
			log.error("Unable to update address for orderId : " + orderId + "and address : " + 
497
					line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
498
		}
499
		return null;
500
	}
7399 anupam.sin 501
 
502
	public String getStoreDetails(long storeId) {
503
	    try {
504
	        TransactionClient tcl = new TransactionClient();
505
	        HotspotStore store = tcl.getClient().getHotspotStore(storeId, "");
506
	        return store.getHotspotId() + " - " + store.getCity(); 
507
	    } catch (Exception e) {
508
	        log.error("Unable to get hostspotStore for id : " + storeId, e);
509
	    }
510
	    return "N/A";
511
	}
4689 anupam.sin 512
 
7372 kshitij.so 513
	public Address getShippingAddress(Order order) {
514
		Address address = new Address();
515
		address.setLine1(order.getCustomer_address1());
516
		address.setLine2(order.getCustomer_address2());
517
		address.setCity(order.getCustomer_city());
518
		address.setState(order.getCustomer_state());
519
		address.setPin(order.getCustomer_pincode());
520
		return address;
521
	}
4689 anupam.sin 522
 
7372 kshitij.so 523
	public String getPaymentMethod(List<Attribute> paymentAttributes) {
524
		String paymentMethod = null;
525
		if (paymentAttributes == null || paymentAttributes.isEmpty()) {
526
			return "N/A";
527
		}
528
		for (Attribute a : paymentAttributes) {
529
			if ("payMethod".equals(a.getName())) {
530
				paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
531
				break;
532
			}
533
		}
534
		return paymentMethod != null ? paymentMethod : "N/A";
535
	}
4689 anupam.sin 536
 
7372 kshitij.so 537
	public void setOrderId(String orderId) {
538
		try {
539
			this.orderId = Long.parseLong(orderId);
540
		} catch (NumberFormatException e) {
541
			log.error(e);
542
		}
543
	}
4689 anupam.sin 544
 
7372 kshitij.so 545
	public List<Payment> getPayments() {
546
		return payments;
547
	}
4689 anupam.sin 548
 
7372 kshitij.so 549
	public List<ShipmentUpdate> getShipmentUpdates() {
550
		return shipmentUpdates;
551
	}
4689 anupam.sin 552
 
7372 kshitij.so 553
	public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
554
		this.shipmentUpdates = shipmentUpdates;
555
	}
6985 anupam.sin 556
 
7372 kshitij.so 557
	public Order getOrder() {
558
		return order;
559
	}
6985 anupam.sin 560
 
7372 kshitij.so 561
	public void setOrder(Order order) {
562
		this.order = order;
563
	}
6985 anupam.sin 564
 
7372 kshitij.so 565
	public Long getCodTicketId() {
566
		return codTicketId;
567
	}
6985 anupam.sin 568
 
7372 kshitij.so 569
	public void setCodTicketId(Long codTicketId) {
570
		this.codTicketId = codTicketId;
571
	}
6985 anupam.sin 572
 
7372 kshitij.so 573
	public List<Address> getAddresses() {
574
		return addresses;
575
	}
6985 anupam.sin 576
 
7372 kshitij.so 577
	public void setAddresses(List<Address> addresses) {
578
		this.addresses = addresses;
579
	}
6985 anupam.sin 580
 
7372 kshitij.so 581
	public String getOrderStatusDescription(Order order) {
582
		String status = order.getStatus().getDescription();
6985 anupam.sin 583
 
7372 kshitij.so 584
		if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
585
			status = "Completed";
586
		}
6985 anupam.sin 587
 
7372 kshitij.so 588
		return status;
589
	}
6985 anupam.sin 590
 
7372 kshitij.so 591
	public String getCancellationInitiator() {
592
		return cancellationInitiator;
593
	}
7190 amar.kumar 594
 
7372 kshitij.so 595
	public void setCancellationInitiator(String cancellationInitiator) {
596
		this.cancellationInitiator = cancellationInitiator;
597
	}
598
 
599
	public String getCancelReason() {
600
		return cancelReason;
601
	}
602
 
603
	public void setCancelReason(String cancelReason) {
604
		this.cancelReason = cancelReason;
605
	}
606
 
607
	public String getBody() {
608
		return body;
609
	}
610
 
611
	public void setBody(String body) {
612
		this.body = body;
613
	}
614
 
615
	public String getLine1() {
616
		return line1;
617
	}
618
 
619
	public void setLine1(String line1) {
620
		this.line1 = line1;
621
	}
622
 
623
	public String getLine2() {
624
		return line2;
625
	}
626
 
627
	public void setLine2(String line2) {
628
		this.line2 = line2;
629
	}
630
 
631
	public String getCity() {
632
		return city;
633
	}
634
 
635
	public void setCity(String city) {
636
		this.city = city;
637
	}
638
 
639
	public String getState() {
640
		return state;
641
	}
642
 
643
	public void setState(String state) {
644
		this.state = state;
645
	}
646
 
647
	public String getPin() {
648
		return pin;
649
	}
650
 
651
	public void setPin(String pin) {
652
		this.pin = pin;
653
	}
654
 
7190 amar.kumar 655
	public String getFreebieItem() {
656
		return freebieItem;
657
	}
658
 
659
	public void setFreebieItem(String freebieItem) {
660
		this.freebieItem = freebieItem;
661
	}
662
 
663
	public String getDealText() {
664
		return dealText;
665
	}
666
 
667
	public void setDealText(String dealText) {
668
		this.dealText = dealText;
669
	}
670
 
671
	public String getParentOrderIdForFreebieOrder() {
672
		return parentOrderIdForFreebieOrder;
673
	}
674
 
675
	public void setParentOrderIdForFreebieOrder(String parentOrderIdForFreebieOrder) {
676
		this.parentOrderIdForFreebieOrder = parentOrderIdForFreebieOrder;
677
	}
678
 
679
	public String getFreebieOrderId() {
680
		return freebieOrderId;
681
	}
682
 
683
	public void setFreebieOrderId(String freebieOrderId) {
684
		this.freebieOrderId = freebieOrderId;
685
	}
7372 kshitij.so 686
 
7393 anupam.sin 687
    public void setCashAmount(double cashAmount) {
688
        this.cashAmount = cashAmount;
689
    }
690
 
691
    public double getCashAmount() {
692
        return cashAmount;
693
    }
694
 
695
    public void setCardAmount(double cardAmount) {
696
        this.cardAmount = cardAmount;
697
    }
698
 
699
    public double getCardAmount() {
700
        return cardAmount;
701
    }
702
 
703
    public long getOrderId() {
704
        return orderId;
705
    }
706
 
707
    public void setOrderId(long orderId) {
708
        this.orderId = orderId;
709
    }
710
 
711
    public StoreOrderDetail getStoreOrderDetail() {
712
        return storeOrderDetail;
713
    }
714
 
715
    public void setStoreOrderDetail(StoreOrderDetail storeOrderDetail) {
716
        this.storeOrderDetail = storeOrderDetail;
717
    }
718
 
2674 vikas 719
}