Subversion Repositories SmartDukaan

Rev

Rev 8929 | Rev 9143 | 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;
8606 amar.kumar 21
import in.shop2020.model.v1.order.OrderSource;
3578 mandeep.dh 22
import in.shop2020.model.v1.order.OrderStatus;
7393 anupam.sin 23
import in.shop2020.model.v1.order.StoreOrderDetail;
4689 anupam.sin 24
import in.shop2020.model.v1.order.TransactionServiceException;
4142 mandeep.dh 25
import in.shop2020.model.v1.user.Address;
4689 anupam.sin 26
import in.shop2020.model.v1.user.UserContextException;
2728 vikas 27
import in.shop2020.payments.Attribute;
28
import in.shop2020.payments.Constants;
2674 vikas 29
import in.shop2020.payments.Payment;
2728 vikas 30
import in.shop2020.payments.PaymentException;
4142 mandeep.dh 31
import in.shop2020.payments.PaymentService.Client;
4689 anupam.sin 32
import in.shop2020.serving.auth.CRMAuthorizingRealm;
3090 mandeep.dh 33
import in.shop2020.serving.model.ShipmentUpdate;
5845 mandeep.dh 34
import in.shop2020.serving.services.AramexTrackingService;
3090 mandeep.dh 35
import in.shop2020.serving.services.BlueDartTrackingService;
5303 phani.kuma 36
import in.shop2020.serving.services.DelhiveryTrackingService;
7942 manish.sha 37
import in.shop2020.serving.services.FedExTrackingService;
7200 kshitij.so 38
import in.shop2020.serving.services.RedExpressTrackingService;
3578 mandeep.dh 39
import in.shop2020.thrift.clients.CRMClient;
7190 amar.kumar 40
import in.shop2020.thrift.clients.CatalogClient;
6322 amar.kumar 41
import in.shop2020.thrift.clients.HelperClient;
5845 mandeep.dh 42
import in.shop2020.thrift.clients.LogisticsClient;
3128 rajveer 43
import in.shop2020.thrift.clients.PaymentClient;
44
import in.shop2020.thrift.clients.TransactionClient;
4142 mandeep.dh 45
import in.shop2020.thrift.clients.UserClient;
7065 kshitij.so 46
import in.shop2020.thrift.clients.config.ConfigClient;
7942 manish.sha 47
import in.shop2020.utils.FedExShipAccountInfo;
3546 mandeep.dh 48
import in.shop2020.utils.ModelUtils;
6322 amar.kumar 49
import in.shop2020.warehouse.WarehouseService;
2674 vikas 50
 
6322 amar.kumar 51
import java.io.BufferedInputStream;
52
import java.io.File;
53
import java.io.FileInputStream;
54
import java.io.FileWriter;
55
import java.io.IOException;
56
import java.io.InputStream;
6912 anupam.sin 57
import java.text.SimpleDateFormat;
2674 vikas 58
import java.util.ArrayList;
8824 manish.sha 59
import java.util.Arrays;
6912 anupam.sin 60
import java.util.Calendar;
4416 mandeep.dh 61
import java.util.Collections;
6912 anupam.sin 62
import java.util.Date;
7836 anupam.sin 63
import java.util.HashMap;
4689 anupam.sin 64
import java.util.HashSet;
2674 vikas 65
import java.util.List;
7836 anupam.sin 66
import java.util.Map;
4689 anupam.sin 67
import java.util.Set;
4416 mandeep.dh 68
import java.util.concurrent.Callable;
69
import java.util.concurrent.Executors;
70
import java.util.concurrent.TimeUnit;
2674 vikas 71
 
6322 amar.kumar 72
import javax.servlet.ServletOutputStream;
73
 
4689 anupam.sin 74
import net.htmlparser.jericho.Source;
75
 
5845 mandeep.dh 76
import org.apache.commons.lang.StringUtils;
2674 vikas 77
import org.apache.log4j.Logger;
8824 manish.sha 78
import org.apache.shiro.SecurityUtils;
79
import org.apache.struts2.convention.annotation.Result;
80
import org.apache.struts2.convention.annotation.Results;
2728 vikas 81
import org.apache.thrift.TException;
4142 mandeep.dh 82
import org.apache.thrift.transport.TTransportException;
2674 vikas 83
 
7942 manish.sha 84
import com.ShipWebServiceClient;
8941 manish.sha 85
import com.fedex.ship.stub.AssociatedShipmentDetail;
7942 manish.sha 86
import com.fedex.ship.stub.CompletedPackageDetail;
87
import com.fedex.ship.stub.CompletedShipmentDetail;
8941 manish.sha 88
import com.fedex.ship.stub.OperationalInstruction;
89
import com.fedex.ship.stub.PackageOperationalDetail;
7942 manish.sha 90
import com.fedex.ship.stub.ProcessShipmentReply;
8941 manish.sha 91
import com.fedex.ship.stub.StringBarcode;
7942 manish.sha 92
import com.fedex.ship.stub.TrackingId;
93
 
2674 vikas 94
/**
95
 * @author vikas
3578 mandeep.dh 96
 * 
2674 vikas 97
 */
98
@SuppressWarnings("serial")
99
public class UserOrderInfoController extends BaseController {
7372 kshitij.so 100
	private static Logger                  log                     = Logger.getLogger(Class.class);
101
	private static BlueDartTrackingService blueDartTrackingService = new BlueDartTrackingService();
102
	private static AramexTrackingService aramexTrackingService     = new AramexTrackingService();
103
	private static DelhiveryTrackingService delhiveryTrackingService     = new DelhiveryTrackingService();
104
	private static RedExpressTrackingService redexpressTrackingService = new RedExpressTrackingService();
7942 manish.sha 105
	//Start:- Added by Manish Sharma for fedex Integration- Shipment Tracking on 31-Jul-2013
106
	private static FedExTrackingService fedexTrackingService = new FedExTrackingService();
107
	//End:- Added by Manish Sharma for fedex Integration- Shipment Tracking on 31-Jul-2013
108
 
7372 kshitij.so 109
	private long                 orderId;
110
	private Order                order;
111
	private List<Payment>        payments;
112
	private List<ShipmentUpdate> shipmentUpdates = new ArrayList<ShipmentUpdate>();
113
	private Long                 codTicketId;
114
	private List<Address>        addresses;
115
	private Set<OrderStatus>     setOfcancellableStates;
8824 manish.sha 116
	//Start:- Added by Manish Sharma for Physical Refunds 
117
	private Set<OrderStatus>	 setOfrefundableStates;
8848 manish.sha 118
	private Set<OrderStatus>	 setOfprepaidrefundableStates;
8824 manish.sha 119
	//End:- Added by Manish Sharma for Physical Refunds
7372 kshitij.so 120
	private String               cancellationInitiator;
121
	private String               cancelReason;
122
	private String               body;
123
	private String               line1;
124
	private String               line2;
125
	private String               city;
126
	private String               state;
127
	private String               pin;
128
	private String				 freebieItem;
129
	private String				 dealText;
130
	private String 				 parentOrderIdForFreebieOrder;
131
	private String				 freebieOrderId;
7393 anupam.sin 132
	private double               cashAmount;
133
	private double               cardAmount;
134
    private StoreOrderDetail     storeOrderDetail;
7826 manish.sha 135
    //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7830 anupam.sin 136
    private AmazonOrder          amazonOrder = null;
7836 anupam.sin 137
    private String               providerName = "N/A";
7826 manish.sha 138
    //End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
8296 kshitij.so 139
    private long				 gvAmount;
8824 manish.sha 140
    //Start:- Added by Manish Sharma for Physical Refunds 
141
    private String               rfdRadio;
142
    private String         	     couponDetails;
143
    private String               refundAmountCoupon;
144
    private String               chequeDetails;
145
    private String               refundAmountCheque;
146
    private String 			     refundAmountGateway;
147
    private String			     comments;
148
 
149
    private String 				 errorMsg = "";
150
	private String 				 successmsg = "";
8860 manish.sha 151
 
152
	private List<String>         refundDetails;
8824 manish.sha 153
	//End:- Added by Manish Sharma for Physical Refunds 
2674 vikas 154
 
7372 kshitij.so 155
	public UserOrderInfoController() {
156
		super();
157
		setOfcancellableStates = new HashSet<OrderStatus>();
158
		setOfcancellableStates.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
159
		setOfcancellableStates.add(OrderStatus.INVENTORY_LOW);
160
		setOfcancellableStates.add(OrderStatus.LOW_INV_PO_RAISED);
161
		setOfcancellableStates.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
162
		setOfcancellableStates.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
163
		setOfcancellableStates.add(OrderStatus.ACCEPTED);
164
		setOfcancellableStates.add(OrderStatus.BILLED);
8824 manish.sha 165
 
166
		//Start:- Added by Manish Sharma for Physical Refunds 
167
		setOfrefundableStates = new HashSet<OrderStatus>();
168
		setOfrefundableStates.add(OrderStatus.DOA_VALID_REFUNDED);
169
		setOfrefundableStates.add(OrderStatus.DOA_INVALID_REFUNDED);
170
		setOfrefundableStates.add(OrderStatus.DOA_REFUNDED_RCVD_DAMAGED);
171
		setOfrefundableStates.add(OrderStatus.DOA_REFUNDED_LOST_IN_TRANSIT);
172
		setOfrefundableStates.add(OrderStatus.RTO_DAMAGED_REFUNDED);
173
		setOfrefundableStates.add(OrderStatus.RET_PRODUCT_USABLE_REFUNDED);
174
		setOfrefundableStates.add(OrderStatus.RET_PRODUCT_UNUSABLE_REFUNDED);
175
		setOfrefundableStates.add(OrderStatus.RET_REFUNDED_RCVD_DAMAGED);
176
		setOfrefundableStates.add(OrderStatus.RET_REFUNDED_LOST_IN_TRANSIT);
177
		//End:- Added by Manish Sharma for Physical Refunds 
178
 
8848 manish.sha 179
		setOfprepaidrefundableStates = new HashSet<OrderStatus>();
180
		setOfprepaidrefundableStates.add(OrderStatus.RTO_REFUNDED);
181
		setOfprepaidrefundableStates.add(OrderStatus.RTO_LOST_IN_TRANSIT_REFUNDED);
182
		setOfprepaidrefundableStates.add(OrderStatus.LOST_IN_TRANSIT_REFUNDED);
183
		setOfprepaidrefundableStates.add(OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST);
184
		setOfprepaidrefundableStates.add(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
8824 manish.sha 185
 
8848 manish.sha 186
 
7372 kshitij.so 187
	}
7836 anupam.sin 188
 
189
	public static final Map<Long, String> providerNameMap = new HashMap<Long, String>() {
190
        {
191
            put(1l, "BlueDart");
192
            put(2l, "Aramex");
193
            put(3l, "Delhivery");
194
            put(4l, "SelfPickup");
195
            put(5l, "Runner");
196
            put(6l, "RedExpress");
8356 manish.sha 197
            put(7l, "FedEx");
7836 anupam.sin 198
        }
199
	};
200
 
7372 kshitij.so 201
	public String index() {
202
		try {
203
			PaymentClient paymentServiceClient = new PaymentClient();
204
			TransactionClient transactionServiceClient = new TransactionClient();
7826 manish.sha 205
			LogisticsClient logisticsServiceClient = new LogisticsClient();
206
 
8824 manish.sha 207
			/*List<Provider> providerList = logisticsServiceClient.getClient().getAllProviders();
208
			Map<Long, String> providerNameMap = new HashMap<Long, String>();
209
			for(Provider provider : providerList){
210
				providerNameMap.put(provider.getId(), provider.getName());
211
			}*/
7372 kshitij.so 212
			order = transactionServiceClient.getClient().getOrder(orderId);
7826 manish.sha 213
			//Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7830 anupam.sin 214
			try {
215
			    amazonOrder = transactionServiceClient.getClient().getAmazonOrder(orderId);
216
			} catch (Exception e) {
7959 anupam.sin 217
			    log.error("Exception : No Amazon order found with orderId " + orderId);
7830 anupam.sin 218
			}
7836 anupam.sin 219
			if (order.getLogistics_provider_id() > 0) {
220
			    setProviderName(providerNameMap.get(order.getLogistics_provider_id()));
221
			}
7826 manish.sha 222
			//End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7393 anupam.sin 223
			if(order.getSource() == 2) {
224
    			storeOrderDetail = transactionServiceClient.getClient().getStoreOrderDetail(order.getId(),order.getStoreId());
7399 anupam.sin 225
    			if(order.getStatus().getValue() == 15 || order.getStatus().getValue() == 34) {
226
    			    setCashAmount(storeOrderDetail.getCashRefundAmount());
227
                    setCardAmount(storeOrderDetail.getCardRefundAmount()); 
228
    			} else {
229
        			setCashAmount(storeOrderDetail.getCashAmount());
230
        			setCardAmount(storeOrderDetail.getCardAmount());
231
    			}
7393 anupam.sin 232
			}
7372 kshitij.so 233
			if(order.getFreebieItemId()>0) {
234
				CatalogService.Client catalogClient = new CatalogClient().getClient();
235
				Item item = catalogClient.getItem(order.getFreebieItemId());
236
				freebieItem = item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
237
			}
3090 mandeep.dh 238
 
7372 kshitij.so 239
			if(order.getLineitems().get(0).getDealText()!=null && !order.getLineitems().get(0).getDealText().isEmpty()) {
240
				dealText = order.getLineitems().get(0).getDealText();
241
			}
242
			List<in.shop2020.model.v1.order.Attribute> attributes = 
243
				transactionServiceClient.getClient().getAllAttributesForOrderId(orderId);
3578 mandeep.dh 244
 
7372 kshitij.so 245
			for(in.shop2020.model.v1.order.Attribute attribute: attributes){
246
				if(attribute.getName().equals("parentOrderIdForFreebie")){
247
					parentOrderIdForFreebieOrder = attribute.getValue();
248
				} else if (attribute.getName().equals("freebieOrderId")){
249
					freebieOrderId = attribute.getValue();
250
				}
251
			}
4689 anupam.sin 252
 
7372 kshitij.so 253
			payments = paymentServiceClient.getClient()
254
			.getPaymentForTxnId(order.getTransactionId());
8296 kshitij.so 255
 
256
			gvAmount = order.getGvAmount();
4689 anupam.sin 257
 
4416 mandeep.dh 258
 
3578 mandeep.dh 259
 
7372 kshitij.so 260
			// Spawning a thread to capture shipment updates from Bluedart
261
			// This is done to ensure that response from Crm web app is sent
262
			// within given time limits. Also, we wont be affected in the cases 
263
			// where bluedart site is down or slow
264
			Executors.newSingleThreadExecutor().invokeAll(Collections.singletonList(new Callable<Boolean>() {
265
				public Boolean call() throws Exception {
266
					if (order.getLogistics_provider_id() == 1)
267
						shipmentUpdates = blueDartTrackingService.getUpdates(order.getAirwaybill_no());
268
					else if (order.getLogistics_provider_id() == 2) {
269
						shipmentUpdates = aramexTrackingService.getUpdates(order.getAirwaybill_no());
270
					}
271
					else if (order.getLogistics_provider_id() == 3) {
272
						shipmentUpdates = delhiveryTrackingService.getUpdates(order.getAirwaybill_no());
273
					}
274
					else if (order.getLogistics_provider_id() == 6) {
275
						shipmentUpdates = redexpressTrackingService.getUpdates(order.getAirwaybill_no());
276
					}
7942 manish.sha 277
					//Start:- Added by Manish Sharma for fedex Integration- Shipment Tracking on 31-Jul-2013
278
					else if (order.getLogistics_provider_id() == 7) {
279
						shipmentUpdates = fedexTrackingService.getUpdates(order.getAirwaybill_no());
280
					}
281
					//End:- Added by Manish Sharma for fedex Integration- Shipment Tracking on 31-Jul-2013
7372 kshitij.so 282
					else {
283
						shipmentUpdates = new ArrayList<ShipmentUpdate>();
284
						log.error("Error : providerId = " + order.getLogistics_provider_id() + "for orderId : " + order.getId());
285
					}
286
					return true;
287
				}
288
			}), 60, TimeUnit.SECONDS);
2674 vikas 289
 
7372 kshitij.so 290
			if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
291
				populateCODTicketId(order.getCustomer_id());
292
			}
4142 mandeep.dh 293
 
7372 kshitij.so 294
			if (canEditOrderAddress()) {
295
				userContextServiceClient = new UserClient().getClient();
296
				addresses = userContextServiceClient.getAllAddressesForUser(order.getCustomer_id());
297
			}
3578 mandeep.dh 298
 
7372 kshitij.so 299
		} catch (TTransportException e) {
300
			log.error("Unable to create thrift Client", e);
301
		} catch (TransactionServiceException e) {
302
			addActionError("Invalid order id or no order selected.");
303
		} catch (TException e) {
304
			log.error("Unable to get thrift Client", e);
305
		} catch (PaymentException e) {
306
			log.error("Unable to get payments for transctionId : " + order.getTransactionId(), e);
307
		} catch (InterruptedException e) {
308
			log.error("Thread was interrupted", e);
309
		} catch (UserContextException e) {
310
			log.error("Unable to get addresses for user : " + order.getCustomer_id(), e);
311
		} catch(CatalogServiceException csex) {
312
			log.error("Unable to get item details for itemId: " + order.getFreebieItemId(), csex);
8824 manish.sha 313
		} /*catch (LogisticsServiceException lsex) {
314
			log.error("Unable to get providers infromation: " , lsex);
315
		}*/
7372 kshitij.so 316
		return INDEX;
317
	}
4689 anupam.sin 318
 
7372 kshitij.so 319
	private boolean canEditOrderAddress() {
320
		return false;
321
	}
4689 anupam.sin 322
 
7372 kshitij.so 323
	private void populateCODTicketId(long customerId) {
324
		try {
325
			SearchFilter searchFilter = new SearchFilter();
326
			searchFilter.setTicketCategory(TicketCategory.COD_VERIFICATION);
327
			searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
328
			searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
329
			searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
330
			searchFilter.setCustomerId(customerId);
331
			crmServiceClient = new CRMClient().getClient();
332
			List<Ticket> tickets = crmServiceClient.getTickets(searchFilter);
333
			if (tickets != null && !tickets.isEmpty()) {
334
				codTicketId = tickets.get(0).getId();
335
			}
336
		} catch (TException e) {
337
			log.error("Error fetching tickets for customerId: " + customerId, e);
338
		}
339
	}
4689 anupam.sin 340
 
7372 kshitij.so 341
	public String markOrderForCancellation() {
342
		try{
343
			TransactionClient transactionServiceClient = new TransactionClient();
344
			log.info("URL = " + request.getRequestURI());
345
			log.info("Initiator = " + request.getParameter("cancellationInitiator"));
346
			log.info("orderId = " + request.getParameter("orderId"));
7393 anupam.sin 347
 
348
			order = transactionServiceClient.getClient().getOrder(orderId);
349
 
7499 anupam.sin 350
			/**
351
			 * If the order is from store then refund the order directly.
352
			 */
7393 anupam.sin 353
			if (order.getSource() == 2) {
354
			    String plainTextbody = "";
355
			    if(body!=null && !body.isEmpty()){
356
                    plainTextbody = new Source(body).getTextExtractor().toString();
357
                }
7612 anupam.sin 358
 
359
			    if(cashAmount + cardAmount > order.getAdvanceAmount()) {
360
			        log.error("Could not mark order for Cancellation, OrderId : " + orderId);
361
			        return "index";
362
			    }
363
 
364
			    transactionServiceClient.getClient().saveRefundAmountsForStoreOrder(orderId, order.getStoreId(), cashAmount, cardAmount);
7399 anupam.sin 365
			    if (cancellationInitiator.equals("CUSTOMER")) {
366
			        transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
367
			        transactionServiceClient.getClient().markOrderCancellationRequestConfirmed(orderId);
368
			    }
7393 anupam.sin 369
			    transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
7499 anupam.sin 370
			} else {
371
		         if (cancellationInitiator.equals("CUSTOMER")) {
372
	                transactionServiceClient.getClient().markOrderCancellationRequestReceived(orderId);
373
	                long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
374
	                Ticket ticket = new Ticket();
375
	                String plainTextbody = "";
376
	                if(body!=null && !body.isEmpty()){
377
	                    plainTextbody = new Source(body).getTextExtractor().toString();
378
	                }
379
	                ticket.setDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
380
	                ticket.setCreatorId(creatorId);
381
	                ticket.setStatus(TicketStatus.OPEN);
382
	                ticket.setPriority(TicketPriority.HIGH);
383
	                ticket.setCategory(TicketCategory.ORDER_CANCELLATION);
384
	                ticket.setOrderId(orderId);
4689 anupam.sin 385
 
7499 anupam.sin 386
	                Activity activity = new Activity();
387
	                activity.setDescription("Creating Ticket");
388
	                activity.setType(ActivityType.OTHER);
389
	                activity.setTicketPriority(TicketPriority.HIGH);
390
	                activity.setTicketStatus(TicketStatus.OPEN);
391
	                activity.setCreatorId(creatorId);
392
	                activity.setTicketDescription("Creating ticket for Cancellation Request Received, Reason : " + cancelReason + " : " + plainTextbody);
393
	                activity.setTicketCategory(TicketCategory.ORDER_CANCELLATION);
4689 anupam.sin 394
 
7499 anupam.sin 395
	                ticket.setCustomerId(order.getCustomer_id());
396
	                activity.setCustomerId(order.getCustomer_id());
397
	                ticket.setCustomerName(order.getCustomer_name());
398
	                activity.setCustomerName(order.getCustomer_name());
399
	                ticket.setCustomerEmailId(order.getCustomer_email());
400
	                activity.setCustomerEmailId(order.getCustomer_email());
401
	                ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
402
	                activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
4689 anupam.sin 403
 
7499 anupam.sin 404
	                crmServiceClient = new CRMClient().getClient();
405
	                crmServiceClient.insertTicket(ticket, activity);
406
	            } 
407
	            else if (cancellationInitiator.equals("INTERNAL")) {
408
	                String plainTextbody = "";
409
	                if(body!=null && !body.isEmpty()){
410
	                    plainTextbody = new Source(body).getTextExtractor().toString();
411
	                }
412
	                boolean status_returned = transactionServiceClient.getClient().refundOrder(orderId, currentAgentEmailId, cancelReason + " : " + plainTextbody);
413
	                if (status_returned) {
414
	                    order = transactionServiceClient.getClient().getOrder(orderId);
415
	                    long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
416
	                    Ticket ticket = new Ticket();
417
	                    ticket.setDescription("Creating ticket for Order Cancellation due to Low inventory");
418
	                    ticket.setCreatorId(creatorId);
419
	                    ticket.setAssigneeId(36);
420
	                    ticket.setStatus(TicketStatus.OPEN);
421
	                    ticket.setPriority(TicketPriority.MEDIUM);
422
	                    ticket.setCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
423
	                    ticket.setOrderId(orderId);
424
	                    ticket.setCustomerId(order.getCustomer_id());
425
	                    ticket.setCustomerName(order.getCustomer_name());
426
	                    ticket.setCustomerEmailId(order.getCustomer_email());
427
	                    ticket.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 428
 
7499 anupam.sin 429
	                    Activity activity = new Activity();
430
	                    activity.setDescription("Creating Ticket");
431
	                    activity.setType(ActivityType.OTHER);
432
	                    activity.setTicketPriority(TicketPriority.MEDIUM);
433
	                    activity.setTicketStatus(TicketStatus.OPEN);
434
	                    activity.setCreatorId(creatorId);
435
	                    activity.setTicketAssigneeId(36);
436
	                    activity.setTicketCategory(TicketCategory.LOW_INVENTORY_CANCELLED_ORDERS);
437
	                    activity.setTicketDescription("Creating ticket for Order Cancellation due to Low inventory");
438
	                    activity.setCustomerId(order.getCustomer_id());
439
	                    activity.setCustomerName(order.getCustomer_name());
440
	                    activity.setCustomerEmailId(order.getCustomer_email());
441
	                    activity.setCustomerMobileNumber(order.getCustomer_mobilenumber());
6322 amar.kumar 442
 
7499 anupam.sin 443
	                    crmServiceClient = new CRMClient().getClient();
444
	                    crmServiceClient.insertTicket(ticket, activity);
445
	                }
446
	            }
7372 kshitij.so 447
			}
448
		} catch(Exception e) {
449
			log.error("Could not mark order for Cancellation, OrderId : " + orderId, e);
450
		}
451
		return index();
452
	}
7221 kshitij.so 453
 
7372 kshitij.so 454
	public void getOrderConfirmationMail() throws IOException, TException, ConfigException, TransactionServiceException {
455
		TransactionClient transactionServiceClient = new TransactionClient();
456
		order = transactionServiceClient.getClient().getOrder(orderId);
457
		long source = order.getTransactionId();
458
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
459
		String mail = helperClient.getClient().getOrderConfirmationMail(source);
460
		File file = new File("/tmp/temp");
7643 manish.sha 461
		//Start:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
462
		if(mail.isEmpty() || mail==null || mail=="")
463
			mail="<html><body><p>Sorry, Required e-mail for mentioned order does not exist in the system !!!</p></body></html>";
464
		//End:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
7221 kshitij.so 465
 
7372 kshitij.so 466
		FileWriter writer = new FileWriter(file);
467
		writer.append(mail);
468
		writer.close();
4689 anupam.sin 469
 
7372 kshitij.so 470
		byte[] buffer = new byte[(int)file.length()];
471
		InputStream input = null;
472
		try {
473
			int totalBytesRead = 0;
474
			input = new BufferedInputStream(new FileInputStream(file));
475
			while(totalBytesRead < buffer.length){
476
				int bytesRemaining = buffer.length - totalBytesRead;
477
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
478
				if (bytesRead > 0){
479
					totalBytesRead = totalBytesRead + bytesRead;
480
				}
481
			}
482
		}
483
		finally {
484
			input.close();
485
			file.delete();
486
		}
3578 mandeep.dh 487
 
4142 mandeep.dh 488
 
7372 kshitij.so 489
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
2674 vikas 490
 
7372 kshitij.so 491
		ServletOutputStream sos;
492
		try {
493
			sos = response.getOutputStream();
494
			sos.write(buffer);
495
			sos.flush();
496
		} catch (IOException e) {
497
			System.out.println("Unable to stream the manifest file");
498
		}   
499
	}
4142 mandeep.dh 500
 
7372 kshitij.so 501
	public void getOrderDeliveryMail() throws IOException, TException, ConfigException, TransactionServiceException {
502
		HelperClient helperClient = new HelperClient("helper_service_server","helper_service_server_port");
503
		String mail = helperClient.getClient().getOrderDeliveryMail(orderId);
504
		File file = new File("/tmp/temp");
7643 manish.sha 505
		//Start:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
506
		if(mail.isEmpty() || mail==null || mail=="")
507
			mail="<html><body><p>Sorry, Required e-mail for mentioned order does not exist in the system anymore !!!</p></body></html>";
508
		//End:- Added by Manish Sharma for resolving Exception for getting order delivery and confirmation mail on 27-Jun-2013
7372 kshitij.so 509
		FileWriter writer = new FileWriter(file);
510
		writer.append(mail);
511
		writer.close();
2674 vikas 512
 
7372 kshitij.so 513
		byte[] buffer = new byte[(int)file.length()];
514
		InputStream input = null;
515
		try {
516
			int totalBytesRead = 0;
517
			input = new BufferedInputStream(new FileInputStream(file));
518
			while(totalBytesRead < buffer.length){
519
				int bytesRemaining = buffer.length - totalBytesRead;
520
				int bytesRead = input.read(buffer, totalBytesRead, bytesRemaining); 
521
				if (bytesRead > 0){
522
					totalBytesRead = totalBytesRead + bytesRead;
523
				}
524
			}
525
		}
526
		finally {
527
			input.close();
528
			file.delete();
529
		}
3578 mandeep.dh 530
 
5845 mandeep.dh 531
 
7372 kshitij.so 532
		response.setHeader("Content-disposition", "inline; filename=" + "OrderDetail_"+orderId );
4142 mandeep.dh 533
 
7372 kshitij.so 534
		ServletOutputStream sos;
535
		try {
536
			sos = response.getOutputStream();
537
			sos.write(buffer);
538
			sos.flush();
539
		} catch (IOException e) {
540
			System.out.println("Unable to stream the manifest file");
541
		}   
542
	}
2674 vikas 543
 
7372 kshitij.so 544
	public boolean canOrderBeCancelled() {
545
		if (setOfcancellableStates.contains(order.getStatus())) {
546
			return true;
547
		}
548
		return false;
549
	}
2674 vikas 550
 
7372 kshitij.so 551
	public String getPaymentGateway(Payment payment) {
552
		String gatewayName = "";
2674 vikas 553
 
7372 kshitij.so 554
		try {
555
			Client paymentServiceClient = new PaymentClient().getClient();
556
			gatewayName = paymentServiceClient.getPaymentGateway(payment.getGatewayId()).getName();
557
		} catch (TTransportException e) {
558
		} catch (PaymentException e) {
559
		} catch (TException e) {
560
		}
3090 mandeep.dh 561
 
7372 kshitij.so 562
		return gatewayName;
563
	}
3499 mandeep.dh 564
 
7372 kshitij.so 565
	public int convertDouble(double value) {
566
		return (int)value;
567
	}
4142 mandeep.dh 568
 
7372 kshitij.so 569
	public String getInsuranceExpiryDate(long DeliveryDate) {
570
		if (DeliveryDate == 0) {
571
			return "N/A";
572
		}
573
		Calendar cal = Calendar.getInstance();
574
		cal.setTimeInMillis(DeliveryDate);
575
		cal.add(Calendar.YEAR, 1);
576
		SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy");
577
		return sdf.format(cal.getTime());
578
	}
4142 mandeep.dh 579
 
7372 kshitij.so 580
	public String getShippingAddressOfStore(long storeId) {
581
		try {
582
			in.shop2020.logistics.LogisticsService.Client client = new LogisticsClient().getClient();
583
			PickupStore store = client.getPickupStore(storeId);
584
			return StringUtils.join(new String[] {
585
					store.getName(),
586
					store.getLine1(),
587
					store.getLine2(),
588
					store.getPin(),
589
					store.getCity(),
590
					store.getState(),
591
					store.getPhone()}, ",");
592
		} catch (Exception e) {
593
			return "";
594
		}
595
	}
4241 anupam.sin 596
 
7372 kshitij.so 597
	public String getAddress(Order order) {
598
		return ModelUtils.extractAddressFromOrder(order);
599
	}
4241 anupam.sin 600
 
7372 kshitij.so 601
	public String changeShippingAddress() {
602
		try {
603
			TransactionClient transactionServiceClient = new TransactionClient();
7942 manish.sha 604
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
605
		    = transactionServiceClient.getClient();
606
			transactionClient.changeShippingAddress(orderId, line1, line2, city, state, pin);
607
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
608
			if(t_order.getLogistics_provider_id()==7L){
609
				FedExShipAccountInfo fedexAccountInfo = FedExShipAccountInfo.getFedExInfo();
610
				ProcessShipmentReply  processShipmentReply = ShipWebServiceClient.getShipmentCreationReply(t_order,fedexAccountInfo.getClientDetail(),fedexAccountInfo.getWad(),fedexAccountInfo.getEndPointAddress());
611
				CompletedShipmentDetail completedShipmentDetails = processShipmentReply.getCompletedShipmentDetail();
612
				CompletedPackageDetail completedPackageDetails =  completedShipmentDetails.getCompletedPackageDetails(0);
613
				TrackingId  trackId= completedPackageDetails.getTrackingIds(0);
614
				t_order = transactionClient.updateOrderAWB(t_order.getId(), trackId.getTrackingNumber());
8941 manish.sha 615
				//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
616
				CompletedPackageDetail[] cpd= completedShipmentDetails.getCompletedPackageDetails();
617
				AssociatedShipmentDetail[] asdetails = completedShipmentDetails.getAssociatedShipments();
618
				List<in.shop2020.model.v1.order.Attribute> attrList = new ArrayList<in.shop2020.model.v1.order.Attribute>();
619
				if(t_order.isCod()){
620
					if(asdetails!=null){
621
						for(AssociatedShipmentDetail as : asdetails){
622
							if(as.getType().getValue().equalsIgnoreCase("COD_RETURN")){
623
								PackageOperationalDetail pod = as.getPackageOperationalDetail();
624
								StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
625
								for(StringBarcode bc : barcodes){
626
									in.shop2020.model.v1.order.Attribute attr3 = new in.shop2020.model.v1.order.Attribute();
627
									attr3.setName("FedEx_COD_Return_BarCode");
628
									attr3.setValue(bc.getValue());
629
									attrList.add(attr3);
630
								}
631
 
632
								String codReturnTrackingNo= as.getTrackingId().getTrackingNumber();
633
								in.shop2020.model.v1.order.Attribute attr4 = new in.shop2020.model.v1.order.Attribute();
634
								attr4.setName("FedEx_COD_Return_Tracking_No");
635
								attr4.setValue(codReturnTrackingNo);
636
								attrList.add(attr4);
637
							}
638
						}
639
					}
640
				}
641
				for(CompletedPackageDetail cd : cpd){
642
					PackageOperationalDetail pod = cd.getOperationalDetail();
643
					StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
644
					for(StringBarcode bc : barcodes){
645
						in.shop2020.model.v1.order.Attribute attr1 = new in.shop2020.model.v1.order.Attribute();
646
						attr1.setName("FedEx_Package_BarCode");
647
						attr1.setValue(bc.getValue());
648
						attrList.add(attr1);
649
					}
650
					OperationalInstruction[] ois = pod.getOperationalInstructions();
651
					in.shop2020.model.v1.order.Attribute attr2 = new in.shop2020.model.v1.order.Attribute();
652
					for(OperationalInstruction oi : ois){
653
						if(oi.getNumber().intValue()==5){
654
							attr2.setName("FedEx_Location_Code");
655
							attr2.setValue(oi.getContent());
656
							attrList.add(attr2);
657
						}
658
					}						
659
				}
660
				transactionClient.setOrderAttributes(t_order.getId(), attrList);
661
				//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
662
 
7942 manish.sha 663
			}
7372 kshitij.so 664
		} catch(Exception e) {
665
			log.error("Unable to update address for orderId : " + orderId + "and address : " + 
666
					line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
667
		}
668
		return null;
669
	}
7399 anupam.sin 670
 
7730 anupam.sin 671
	public String convertStoreToNormal() {
672
	    try{
673
	        TransactionClient transactionServiceClient = new TransactionClient();
674
	        transactionServiceClient.getClient().convertStoreToNormal(orderId);
675
	    } catch(Exception e) {
676
	        log.error("Unable to convert to normal order", e);
677
	    }
678
	    return null;
679
	}
680
 
7399 anupam.sin 681
	public String getStoreDetails(long storeId) {
682
	    try {
683
	        TransactionClient tcl = new TransactionClient();
684
	        HotspotStore store = tcl.getClient().getHotspotStore(storeId, "");
685
	        return store.getHotspotId() + " - " + store.getCity(); 
686
	    } catch (Exception e) {
687
	        log.error("Unable to get hostspotStore for id : " + storeId, e);
688
	    }
689
	    return "N/A";
690
	}
4689 anupam.sin 691
 
7372 kshitij.so 692
	public Address getShippingAddress(Order order) {
693
		Address address = new Address();
694
		address.setLine1(order.getCustomer_address1());
695
		address.setLine2(order.getCustomer_address2());
696
		address.setCity(order.getCustomer_city());
697
		address.setState(order.getCustomer_state());
698
		address.setPin(order.getCustomer_pincode());
699
		return address;
700
	}
8606 amar.kumar 701
 
702
	public String getOrderSource(Order order) {
703
		return OrderSource.findByValue((int)(order.getSource())).toString();
704
	}
4689 anupam.sin 705
 
7372 kshitij.so 706
	public String getPaymentMethod(List<Attribute> paymentAttributes) {
707
		String paymentMethod = null;
708
		if (paymentAttributes == null || paymentAttributes.isEmpty()) {
709
			return "N/A";
710
		}
711
		for (Attribute a : paymentAttributes) {
712
			if ("payMethod".equals(a.getName())) {
713
				paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
714
				break;
715
			}
716
		}
717
		return paymentMethod != null ? paymentMethod : "N/A";
718
	}
8824 manish.sha 719
	//Start:- Added by Manish Sharma for Physical Refunds 
720
	public String refundOrderPayment(){
721
		try{
722
			TransactionClient transactionServiceClient = new TransactionClient();
723
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
724
		    = transactionServiceClient.getClient();
725
 
726
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
727
			List<in.shop2020.model.v1.order.Attribute> attrList = new ArrayList<in.shop2020.model.v1.order.Attribute>();
728
			in.shop2020.model.v1.order.Attribute attr1 = new in.shop2020.model.v1.order.Attribute();
729
			attr1.setName("Refund_Option");
730
			in.shop2020.model.v1.order.Attribute attr2 = new in.shop2020.model.v1.order.Attribute();
731
			attr2.setName("Refund_Amount");
8860 manish.sha 732
			in.shop2020.model.v1.order.Attribute attr3 = new in.shop2020.model.v1.order.Attribute();
8893 manish.sha 733
			attr3.setName("Refund_TimeStamp");
8866 manish.sha 734
			SimpleDateFormat timestmapFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
8824 manish.sha 735
			PaymentClient paymentServiceClient = new PaymentClient();
736
			List<Payment> orderPayments =null; 
737
			if(!t_order.isCod()){
738
				orderPayments =paymentServiceClient.getClient()
739
					.getPaymentForTxnId(t_order.getTransactionId());
740
			}
741
 
742
			if(rfdRadio.equalsIgnoreCase("rfdCoupon")){
743
				if((couponDetails!=null && !("").equalsIgnoreCase(couponDetails)) || (refundAmountCoupon!=null &&!("").equalsIgnoreCase(refundAmountCoupon))){
744
					if(Double.parseDouble(refundAmountCoupon) <= t_order.getTotal_amount()){
745
						log.info(Double.parseDouble(refundAmountCoupon));
746
						log.info(t_order.getTotal_amount());
747
						attr1.setValue("Refund By Coupon: "+couponDetails);
748
						attrList.add(attr1);
749
						attr2.setValue(refundAmountCoupon);
750
						attrList.add(attr2);
8860 manish.sha 751
						attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
752
						attrList.add(attr3);
8824 manish.sha 753
						transactionClient.setOrderAttributes(t_order.getId(), attrList);
754
						successmsg = "Refund Marked Successful: Through Coupon";
755
						return "physical-refund-result";
756
					}
8896 manish.sha 757
					else if(orderPayments !=null && !orderPayments.isEmpty()){
758
						Payment payment = orderPayments.get(0);
759
						if(Double.parseDouble(refundAmountCoupon) <= payment.getAmount()){
760
							log.info(Double.parseDouble(refundAmountCoupon));
761
							log.info(payment.getAmount());
762
							attr1.setValue("Refund By Coupon: "+couponDetails);
763
							attrList.add(attr1);
764
							attr2.setValue(refundAmountCoupon);
765
							attrList.add(attr2);
766
							attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
767
							attrList.add(attr3);
768
							transactionClient.setOrderAttributes(t_order.getId(), attrList);
769
							successmsg = "Refund Marked Successful: Through Coupon";
770
							return "physical-refund-result";
771
						}
772
						else{
773
							errorMsg ="Refund Unsuccessful: Due to coupon amount greater than Payment Gateway Amount ";
774
							return "physical-refund-result";
775
						}
776
					}
777
					errorMsg ="Refund Unsuccessful: Due to coupon amount greater than Order Total Amount ";
8824 manish.sha 778
				}
779
				else{
780
					errorMsg ="Refund Unsuccessful: Due to either coupon details or refund amount is blank ";
781
					return "physical-refund-result";
782
				}
783
				errorMsg ="Refund Unsuccessful: Due to coupon amount greater than order total amount ";
784
			}
785
			if(rfdRadio.equalsIgnoreCase("rfdCheque")){
786
				if((chequeDetails!=null && !("").equalsIgnoreCase(chequeDetails)) || (refundAmountCheque!=null &&!("").equalsIgnoreCase(refundAmountCheque))){
787
					if(Double.parseDouble(refundAmountCheque) <= t_order.getTotal_amount()){
788
						attr1.setValue("Refund By Cheque: "+chequeDetails);
789
						attrList.add(attr1);
790
						attr2.setValue(refundAmountCheque);
791
						attrList.add(attr2);
8860 manish.sha 792
						attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
793
						attrList.add(attr3);
8824 manish.sha 794
						transactionClient.setOrderAttributes(t_order.getId(), attrList);
795
						successmsg = "Refund Marked Successful: Through Cheque";
796
						return "physical-refund-result";
797
					}
798
				}
799
				else{
800
					errorMsg ="Refund Unsuccessful: Due to either cheque details or refund amount is blank ";
801
					return "physical-refund-result";
802
				}
803
				errorMsg ="Refund Unsuccessful: Due to cheque amount greater than order total amount ";
804
			}
805
			if(rfdRadio.equalsIgnoreCase("rfdGateway")){
8896 manish.sha 806
				if((comments!=null && !("").equalsIgnoreCase(comments)) 
807
						|| (refundAmountGateway!=null &&!("").equalsIgnoreCase(refundAmountGateway))){
808
					if(orderPayments !=null && !orderPayments.isEmpty()){
809
						Payment payment = orderPayments.get(0);
810
						if(Double.parseDouble(refundAmountGateway) <= payment.getAmount()){
811
							boolean refundResult = paymentServiceClient.getClient().refundPayment(t_order.getTransactionId(), Double.parseDouble(refundAmountGateway), false);
812
							if(refundResult){
813
								attr1.setValue("Refund By Payment Gatway: "+comments);
814
								attrList.add(attr1);
815
								attr2.setValue(refundAmountGateway);
816
								attrList.add(attr2);
817
								attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
818
								attrList.add(attr3);
819
								transactionClient.setOrderAttributes(t_order.getId(), attrList);
820
								successmsg = "Refund Marked Successful: Through Gateway";
821
								return "physical-refund-result";
822
							}
823
							else{
8824 manish.sha 824
								if(payment.getGatewayId()==13L){
825
									attr1.setValue("Refund By Innoviti Gatway: "+comments);
826
									attrList.add(attr1);
827
									attr2.setValue(refundAmountGateway);
828
									attrList.add(attr2);
8860 manish.sha 829
									attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
830
									attrList.add(attr3);
8824 manish.sha 831
									transactionClient.setOrderAttributes(t_order.getId(), attrList);
832
									successmsg = "Refund Marked Successful: Through Innoviti Payment Gateway.";
833
									return "physical-refund-result";
834
								}
8896 manish.sha 835
								errorMsg ="Refund Unsuccessful: at Payment Gateway ";
836
								return "physical-refund-result";
8824 manish.sha 837
							}
8896 manish.sha 838
						}
839
						else{
840
							errorMsg ="Refund Unsuccessful: Due to refund Amount is greater than Payment Gateway Amount ";
8824 manish.sha 841
							return "physical-refund-result";
842
						}
843
					}
8896 manish.sha 844
					errorMsg ="Refund Unsuccessful: There is no Payment to be refunded ";
8824 manish.sha 845
				}
846
				else{
847
					errorMsg ="Refund Unsuccessful: Due to either comments or refund amount is blank ";
848
					return "physical-refund-result";
849
				}
8896 manish.sha 850
 
8824 manish.sha 851
			}
852
 
853
		}
854
		catch(Exception e){
855
			log.error(e);
856
		}
857
		return "physical-refund-result";
858
	}
8862 manish.sha 859
 
8824 manish.sha 860
	public int getRefundEnabledStatus(){
861
		try{
862
			TransactionClient transactionServiceClient = new TransactionClient();
863
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
864
		    = transactionServiceClient.getClient();
865
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
8872 manish.sha 866
			if(OrderSource.WEBSITE.getValue()!=t_order.getSource()){
8871 manish.sha 867
				return 1;
868
			}
8824 manish.sha 869
			String refundOption=transactionClient.getOrderAttributeValue(orderId, "Refund_Option");
870
			String refundAmount=transactionClient.getOrderAttributeValue(orderId, "Refund_Amount");
8860 manish.sha 871
			String refundTimeStamp = transactionClient.getOrderAttributeValue(orderId, "Refund_TimeStamp");
872
			List<String> details = new ArrayList<String>();
873
			if(refundOption!=null && !("").equalsIgnoreCase(refundOption)){
874
				details.add("Refund Option:- "+refundOption);
875
			}
876
 
877
			if(refundAmount!=null && !("").equalsIgnoreCase(refundAmount)){
878
				details.add("Refund Amount:- "+refundAmount);
879
			}
880
 
881
			if(refundTimeStamp!=null && !("").equalsIgnoreCase(refundTimeStamp)){
882
				details.add("Refund TimeStamp:- "+refundTimeStamp);
883
			}
884
			setPhysicalRefundDetails(details);
885
 
8864 manish.sha 886
			if((refundOption!=null && refundAmount!=null) && (!("").equalsIgnoreCase(refundOption)) && !("").equalsIgnoreCase(refundAmount)){
8824 manish.sha 887
				System.out.println("Into the Refund Condition");
888
				return 0;
889
			}
8871 manish.sha 890
 
8848 manish.sha 891
			else if(t_order.isCod()){
892
				if(setOfrefundableStates.contains(t_order.getStatus()) && SecurityUtils.getSubject().hasRole("TeamLead")){
893
					System.out.println("Into the COD Status Condition");
894
					return 2;
895
				}
8824 manish.sha 896
			}
8848 manish.sha 897
			else{
8929 manish.sha 898
				if(( setOfprepaidrefundableStates.contains(t_order.getStatus()) || setOfrefundableStates.contains(t_order.getStatus()) ) && SecurityUtils.getSubject().hasRole("TeamLead") && (t_order.isSetAccepted_timestamp() || t_order.isSetOriginalOrderId())){
8848 manish.sha 899
					System.out.println("Into the Prepaid Status Condition");
900
					return 2;
901
				}
902
			}
8824 manish.sha 903
		}
904
		catch(Exception e){
905
			log.error(e);
906
		}
907
		return 1;
908
	}
8860 manish.sha 909
 
910
	public void setPhysicalRefundDetails(List<String> details){
911
		this.refundDetails = details;
912
	}
913
 
914
	public List<String> getPhysicalRefundDetails(){
915
		return this.refundDetails;
916
	}
8824 manish.sha 917
	//End:- Added by Manish Sharma for Physical Refunds 	
4689 anupam.sin 918
 
7372 kshitij.so 919
	public void setOrderId(String orderId) {
920
		try {
921
			this.orderId = Long.parseLong(orderId);
922
		} catch (NumberFormatException e) {
923
			log.error(e);
924
		}
925
	}
4689 anupam.sin 926
 
7372 kshitij.so 927
	public List<Payment> getPayments() {
928
		return payments;
929
	}
4689 anupam.sin 930
 
7372 kshitij.so 931
	public List<ShipmentUpdate> getShipmentUpdates() {
932
		return shipmentUpdates;
933
	}
4689 anupam.sin 934
 
7372 kshitij.so 935
	public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
936
		this.shipmentUpdates = shipmentUpdates;
937
	}
6985 anupam.sin 938
 
7372 kshitij.so 939
	public Order getOrder() {
940
		return order;
941
	}
6985 anupam.sin 942
 
7372 kshitij.so 943
	public void setOrder(Order order) {
944
		this.order = order;
945
	}
6985 anupam.sin 946
 
7372 kshitij.so 947
	public Long getCodTicketId() {
948
		return codTicketId;
949
	}
6985 anupam.sin 950
 
7372 kshitij.so 951
	public void setCodTicketId(Long codTicketId) {
952
		this.codTicketId = codTicketId;
953
	}
6985 anupam.sin 954
 
7372 kshitij.so 955
	public List<Address> getAddresses() {
956
		return addresses;
957
	}
6985 anupam.sin 958
 
7372 kshitij.so 959
	public void setAddresses(List<Address> addresses) {
960
		this.addresses = addresses;
961
	}
6985 anupam.sin 962
 
7372 kshitij.so 963
	public String getOrderStatusDescription(Order order) {
964
		String status = order.getStatus().getDescription();
6985 anupam.sin 965
 
7372 kshitij.so 966
		if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
967
			status = "Completed";
968
		}
6985 anupam.sin 969
 
7372 kshitij.so 970
		return status;
971
	}
6985 anupam.sin 972
 
7372 kshitij.so 973
	public String getCancellationInitiator() {
974
		return cancellationInitiator;
975
	}
7190 amar.kumar 976
 
7372 kshitij.so 977
	public void setCancellationInitiator(String cancellationInitiator) {
978
		this.cancellationInitiator = cancellationInitiator;
979
	}
980
 
981
	public String getCancelReason() {
982
		return cancelReason;
983
	}
984
 
985
	public void setCancelReason(String cancelReason) {
986
		this.cancelReason = cancelReason;
987
	}
988
 
989
	public String getBody() {
990
		return body;
991
	}
992
 
993
	public void setBody(String body) {
994
		this.body = body;
995
	}
996
 
997
	public String getLine1() {
998
		return line1;
999
	}
1000
 
1001
	public void setLine1(String line1) {
1002
		this.line1 = line1;
1003
	}
1004
 
1005
	public String getLine2() {
1006
		return line2;
1007
	}
1008
 
1009
	public void setLine2(String line2) {
1010
		this.line2 = line2;
1011
	}
1012
 
1013
	public String getCity() {
1014
		return city;
1015
	}
1016
 
1017
	public void setCity(String city) {
1018
		this.city = city;
1019
	}
1020
 
1021
	public String getState() {
1022
		return state;
1023
	}
1024
 
1025
	public void setState(String state) {
1026
		this.state = state;
1027
	}
1028
 
1029
	public String getPin() {
1030
		return pin;
1031
	}
1032
 
1033
	public void setPin(String pin) {
1034
		this.pin = pin;
1035
	}
1036
 
7190 amar.kumar 1037
	public String getFreebieItem() {
1038
		return freebieItem;
1039
	}
1040
 
1041
	public void setFreebieItem(String freebieItem) {
1042
		this.freebieItem = freebieItem;
1043
	}
1044
 
1045
	public String getDealText() {
1046
		return dealText;
1047
	}
1048
 
1049
	public void setDealText(String dealText) {
1050
		this.dealText = dealText;
1051
	}
1052
 
1053
	public String getParentOrderIdForFreebieOrder() {
1054
		return parentOrderIdForFreebieOrder;
1055
	}
1056
 
1057
	public void setParentOrderIdForFreebieOrder(String parentOrderIdForFreebieOrder) {
1058
		this.parentOrderIdForFreebieOrder = parentOrderIdForFreebieOrder;
1059
	}
1060
 
1061
	public String getFreebieOrderId() {
1062
		return freebieOrderId;
1063
	}
1064
 
1065
	public void setFreebieOrderId(String freebieOrderId) {
1066
		this.freebieOrderId = freebieOrderId;
1067
	}
7372 kshitij.so 1068
 
7393 anupam.sin 1069
    public void setCashAmount(double cashAmount) {
1070
        this.cashAmount = cashAmount;
1071
    }
1072
 
1073
    public double getCashAmount() {
1074
        return cashAmount;
1075
    }
1076
 
1077
    public void setCardAmount(double cardAmount) {
1078
        this.cardAmount = cardAmount;
1079
    }
1080
 
1081
    public double getCardAmount() {
1082
        return cardAmount;
1083
    }
1084
 
1085
    public long getOrderId() {
1086
        return orderId;
1087
    }
1088
 
1089
    public void setOrderId(long orderId) {
1090
        this.orderId = orderId;
1091
    }
1092
 
1093
    public StoreOrderDetail getStoreOrderDetail() {
1094
        return storeOrderDetail;
1095
    }
1096
 
1097
    public void setStoreOrderDetail(StoreOrderDetail storeOrderDetail) {
1098
        this.storeOrderDetail = storeOrderDetail;
1099
    }
7826 manish.sha 1100
 
1101
  //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
1102
    public AmazonOrder getAmazonOrder() {
1103
		return amazonOrder;
1104
	}
7393 anupam.sin 1105
 
7826 manish.sha 1106
	public void setAmazonOrder(AmazonOrder amazonOrder) {
1107
		this.amazonOrder = amazonOrder;
1108
	}
1109
 
1110
	//End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
1111
 
7836 anupam.sin 1112
    public void setProviderName(String providerName) {
1113
        this.providerName = providerName;
1114
    }
1115
 
1116
    public String getProviderName() {
1117
        return providerName;
1118
    }
1119
 
1120
    public static void main(String[] args) {
8824 manish.sha 1121
 
7836 anupam.sin 1122
    }
1123
 
8296 kshitij.so 1124
	public void setGvAmount(long gvAmount) {
1125
		this.gvAmount = gvAmount;
1126
	}
1127
 
1128
	public long getGvAmount() {
1129
		return gvAmount;
1130
	}
8824 manish.sha 1131
	//Start:- Added by Manish Sharma for Physical Refunds 
1132
	public String getRfdRadio() {
1133
		return rfdRadio;
1134
	}
8296 kshitij.so 1135
 
8824 manish.sha 1136
 
1137
	public void setRfdRadio(String rfdRadio) {
1138
		this.rfdRadio = rfdRadio;
1139
	}
1140
 
1141
 
1142
	public String getCouponDetails() {
1143
		return couponDetails;
1144
	}
1145
 
1146
 
1147
	public void setCouponDetails(String couponDetails) {
1148
		this.couponDetails = couponDetails;
1149
	}
1150
 
1151
 
1152
	public String getRefundAmountCoupon() {
1153
		return refundAmountCoupon;
1154
	}
1155
 
1156
 
1157
	public void setRefundAmountCoupon(String refundAmountCoupon) {
1158
		this.refundAmountCoupon = refundAmountCoupon;
1159
	}
1160
 
1161
 
1162
	public String getChequeDetails() {
1163
		return chequeDetails;
1164
	}
1165
 
1166
 
1167
	public void setChequeDetails(String chequeDetails) {
1168
		this.chequeDetails = chequeDetails;
1169
	}
1170
 
1171
 
1172
	public String getRefundAmountCheque() {
1173
		return refundAmountCheque;
1174
	}
1175
 
1176
 
1177
	public void setRefundAmountCheque(String refundAmountCheque) {
1178
		this.refundAmountCheque = refundAmountCheque;
1179
	}
1180
 
1181
 
1182
	public String getRefundAmountGateway() {
1183
		return refundAmountGateway;
1184
	}
1185
 
1186
 
1187
	public void setRefundAmountGateway(String refundAmountGateway) {
1188
		this.refundAmountGateway = refundAmountGateway;
1189
	}
1190
 
1191
 
1192
	public String getComments() {
1193
		return comments;
1194
	}
1195
 
1196
 
1197
	public void setComments(String comments) {
1198
		this.comments = comments;
1199
	}
1200
 
1201
	public String getErrorMsg(){
1202
        return this.errorMsg;
1203
    }
1204
 
1205
	public String getSuccessMessage(){
1206
		return this.successmsg ;
1207
	}
1208
	//End:- Added by Manish Sharma for Physical Refunds 
2674 vikas 1209
}