Subversion Repositories SmartDukaan

Rev

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