Subversion Repositories SmartDukaan

Rev

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