Subversion Repositories SmartDukaan

Rev

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