Subversion Repositories SmartDukaan

Rev

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

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