Subversion Repositories SmartDukaan

Rev

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