Subversion Repositories SmartDukaan

Rev

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