Subversion Repositories SmartDukaan

Rev

Rev 8296 | Rev 8606 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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