Subversion Repositories SmartDukaan

Rev

Rev 18070 | Rev 18171 | 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();
18070 manish.sha 645
            in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
13208 kshitij.so 646
            transactionClient.changeShippingAddress(orderId, line1, line2, city, state, pin);
18070 manish.sha 647
            /*
13208 kshitij.so 648
            Warehouse warehouse = getWareHouseForOrder(t_order.getWarehouse_id());			
649
            if(t_order.getLogistics_provider_id()==7L){
650
                FedExShipAccountInfo fedexAccountInfo = FedExShipAccountInfo.getFedExInfo(warehouse.getLogisticsLocation());
651
                ProcessShipmentReply  processShipmentReply = ShipWebServiceClient.getShipmentCreationReply(t_order,fedexAccountInfo.getClientDetail(),fedexAccountInfo.getWad(),fedexAccountInfo.getEndPointAddress());
652
                CompletedShipmentDetail completedShipmentDetails = processShipmentReply.getCompletedShipmentDetail();
653
                CompletedPackageDetail completedPackageDetails =  completedShipmentDetails.getCompletedPackageDetails(0);
654
                TrackingId  trackId= completedPackageDetails.getTrackingIds(0);
655
                t_order = transactionClient.updateOrderAWB(t_order.getId(), trackId.getTrackingNumber());
656
                //Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
657
                CompletedPackageDetail[] cpd= completedShipmentDetails.getCompletedPackageDetails();
658
                AssociatedShipmentDetail[] asdetails = completedShipmentDetails.getAssociatedShipments();
659
                List<in.shop2020.model.v1.order.Attribute> attrList = new ArrayList<in.shop2020.model.v1.order.Attribute>();
660
                if(t_order.isCod()){
661
                    if(asdetails!=null){
662
                        for(AssociatedShipmentDetail as : asdetails){
663
                            if(as.getType().getValue().equalsIgnoreCase("COD_RETURN")){
664
                                PackageOperationalDetail pod = as.getPackageOperationalDetail();
665
                                StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
666
                                for(StringBarcode bc : barcodes){
667
                                    in.shop2020.model.v1.order.Attribute attr3 = new in.shop2020.model.v1.order.Attribute();
668
                                    attr3.setName("FedEx_COD_Return_BarCode");
669
                                    attr3.setValue(bc.getValue());
670
                                    attrList.add(attr3);
671
                                }
4689 anupam.sin 672
 
13208 kshitij.so 673
                                String codReturnTrackingNo= as.getTrackingId().getTrackingNumber();
674
                                in.shop2020.model.v1.order.Attribute attr4 = new in.shop2020.model.v1.order.Attribute();
675
                                attr4.setName("FedEx_COD_Return_Tracking_No");
676
                                attr4.setValue(codReturnTrackingNo);
677
                                attrList.add(attr4);
678
                            }
679
                        }
680
                    }
681
                }
682
                for(CompletedPackageDetail cd : cpd){
683
                    PackageOperationalDetail pod = cd.getOperationalDetail();
684
                    StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
685
                    for(StringBarcode bc : barcodes){
686
                        in.shop2020.model.v1.order.Attribute attr1 = new in.shop2020.model.v1.order.Attribute();
687
                        attr1.setName("FedEx_Package_BarCode");
688
                        attr1.setValue(bc.getValue());
689
                        attrList.add(attr1);
690
                    }
691
                    OperationalInstruction[] ois = pod.getOperationalInstructions();
692
                    in.shop2020.model.v1.order.Attribute attr2 = new in.shop2020.model.v1.order.Attribute();
693
                    for(OperationalInstruction oi : ois){
694
                        if(oi.getNumber().intValue()==5){
695
                            attr2.setName("FedEx_Location_Code");
696
                            attr2.setValue(oi.getContent());
697
                            attrList.add(attr2);
698
                        }
699
                    }						
700
                }
701
                transactionClient.setOrderAttributes(t_order.getId(), attrList);
702
                //End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
18071 manish.sha 703
 
704
            }*/
13208 kshitij.so 705
        } catch(Exception e) {
706
            log.error("Unable to update address for orderId : " + orderId + "and address : " + 
707
                    line1 + ", " + line2+ ", " + city + ", " + state + ", " + pin, e);
708
        }
709
        return null;
710
    }
4689 anupam.sin 711
 
13208 kshitij.so 712
    public String convertStoreToNormal() {
713
        try{
714
            TransactionClient transactionServiceClient = new TransactionClient();
715
            transactionServiceClient.getClient().convertStoreToNormal(orderId);
716
        } catch(Exception e) {
717
            log.error("Unable to convert to normal order", e);
718
        }
719
        return null;
720
    }
4689 anupam.sin 721
 
13208 kshitij.so 722
    public String getStoreDetails(long storeId) {
723
        try {
724
            TransactionClient tcl = new TransactionClient();
725
            HotspotStore store = tcl.getClient().getHotspotStore(storeId, "");
726
            return store.getHotspotId() + " - " + store.getCity(); 
727
        } catch (Exception e) {
728
            log.error("Unable to get hostspotStore for id : " + storeId, e);
729
        }
730
        return "N/A";
731
    }
6985 anupam.sin 732
 
13208 kshitij.so 733
    public Address getShippingAddress(Order order) {
734
        Address address = new Address();
735
        address.setLine1(order.getCustomer_address1());
736
        address.setLine2(order.getCustomer_address2());
737
        address.setCity(order.getCustomer_city());
738
        address.setState(order.getCustomer_state());
739
        address.setPin(order.getCustomer_pincode());
740
        return address;
741
    }
6985 anupam.sin 742
 
13208 kshitij.so 743
    public String getOrderSource(Order order) {
744
        return OrderSource.findByValue((int)(order.getSource())).toString();
745
    }
6985 anupam.sin 746
 
13208 kshitij.so 747
    public String getPaymentMethod(List<Attribute> paymentAttributes) {
748
        String paymentMethod = null;
749
        if (paymentAttributes == null || paymentAttributes.isEmpty()) {
750
            return "N/A";
751
        }
752
        for (Attribute a : paymentAttributes) {
753
            if ("payMethod".equals(a.getName())) {
754
                paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
755
                break;
756
            }
757
        }
758
        return paymentMethod != null ? paymentMethod : "N/A";
759
    }
760
    //Start:- Added by Manish Sharma for Physical Refunds 
761
    public String refundOrderPayment(){
762
        try{
763
            TransactionClient transactionServiceClient = new TransactionClient();
764
            in.shop2020.model.v1.order.TransactionService.Client transactionClient
765
            = transactionServiceClient.getClient();
6985 anupam.sin 766
 
13208 kshitij.so 767
            in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
768
            List<in.shop2020.model.v1.order.Attribute> attrList = new ArrayList<in.shop2020.model.v1.order.Attribute>();
769
            in.shop2020.model.v1.order.Attribute attr1 = new in.shop2020.model.v1.order.Attribute();
770
            attr1.setName("Refund_Option");
771
            in.shop2020.model.v1.order.Attribute attr2 = new in.shop2020.model.v1.order.Attribute();
772
            attr2.setName("Refund_Amount");
773
            in.shop2020.model.v1.order.Attribute attr3 = new in.shop2020.model.v1.order.Attribute();
774
            attr3.setName("Refund_TimeStamp");
775
            SimpleDateFormat timestmapFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
776
            PaymentClient paymentServiceClient = new PaymentClient();
777
            List<Payment> orderPayments =null; 
778
            if(!t_order.isCod()){
779
                orderPayments =paymentServiceClient.getClient()
780
                .getPaymentForTxnId(t_order.getTransactionId());
781
            }
6985 anupam.sin 782
 
13208 kshitij.so 783
            if(rfdRadio.equalsIgnoreCase("rfdCoupon")){
784
                if((couponDetails!=null && !("").equalsIgnoreCase(couponDetails)) || (refundAmountCoupon!=null &&!("").equalsIgnoreCase(refundAmountCoupon))){
785
                    if(Double.parseDouble(refundAmountCoupon) <= t_order.getTotal_amount()){
786
                        log.info(Double.parseDouble(refundAmountCoupon));
787
                        log.info(t_order.getTotal_amount());
788
                        attr1.setValue("Refund By Coupon: "+couponDetails);
789
                        attrList.add(attr1);
790
                        attr2.setValue(refundAmountCoupon);
791
                        attrList.add(attr2);
792
                        attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
793
                        attrList.add(attr3);
794
                        transactionClient.setOrderAttributes(t_order.getId(), attrList);
795
                        successmsg = "Refund Marked Successful: Through Coupon";
796
                        return "physical-refund-result";
797
                    }
798
                    else if(orderPayments !=null && !orderPayments.isEmpty()){
799
                        Payment payment = orderPayments.get(0);
800
                        if(Double.parseDouble(refundAmountCoupon) <= payment.getAmount()){
801
                            log.info(Double.parseDouble(refundAmountCoupon));
802
                            log.info(payment.getAmount());
803
                            attr1.setValue("Refund By Coupon: "+couponDetails);
804
                            attrList.add(attr1);
805
                            attr2.setValue(refundAmountCoupon);
806
                            attrList.add(attr2);
807
                            attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
808
                            attrList.add(attr3);
809
                            transactionClient.setOrderAttributes(t_order.getId(), attrList);
810
                            successmsg = "Refund Marked Successful: Through Coupon";
811
                            return "physical-refund-result";
812
                        }
813
                        else{
814
                            errorMsg ="Refund Unsuccessful: Due to coupon amount greater than Payment Gateway Amount ";
815
                            return "physical-refund-result";
816
                        }
817
                    }
818
                    errorMsg ="Refund Unsuccessful: Due to coupon amount greater than Order Total Amount ";
819
                }
820
                else{
821
                    errorMsg ="Refund Unsuccessful: Due to either coupon details or refund amount is blank ";
822
                    return "physical-refund-result";
823
                }
824
                errorMsg ="Refund Unsuccessful: Due to coupon amount greater than order total amount ";
825
            }
826
            if(rfdRadio.equalsIgnoreCase("rfdCheque")){
827
                if((chequeDetails!=null && !("").equalsIgnoreCase(chequeDetails)) || (refundAmountCheque!=null &&!("").equalsIgnoreCase(refundAmountCheque))){
828
                    if(Double.parseDouble(refundAmountCheque) <= t_order.getTotal_amount()){
829
                        attr1.setValue("Refund By Cheque: "+chequeDetails);
830
                        attrList.add(attr1);
831
                        attr2.setValue(refundAmountCheque);
832
                        attrList.add(attr2);
833
                        attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
834
                        attrList.add(attr3);
835
                        transactionClient.setOrderAttributes(t_order.getId(), attrList);
836
                        successmsg = "Refund Marked Successful: Through Cheque";
837
                        return "physical-refund-result";
838
                    }
839
                }
840
                else{
841
                    errorMsg ="Refund Unsuccessful: Due to either cheque details or refund amount is blank ";
842
                    return "physical-refund-result";
843
                }
844
                errorMsg ="Refund Unsuccessful: Due to cheque amount greater than order total amount ";
845
            }
846
            if(rfdRadio.equalsIgnoreCase("rfdGateway")){
847
                if((comments!=null && !("").equalsIgnoreCase(comments)) 
848
                        || (refundAmountGateway!=null &&!("").equalsIgnoreCase(refundAmountGateway))){
849
                    if(orderPayments !=null && !orderPayments.isEmpty()){
850
                        Payment payment = orderPayments.get(0);
851
                        if(Double.parseDouble(refundAmountGateway) <= payment.getAmount()){
852
                            boolean refundResult = paymentServiceClient.getClient().refundPayment(t_order.getTransactionId(), Double.parseDouble(refundAmountGateway), false);
853
                            if(refundResult){
854
                                attr1.setValue("Refund By Payment Gatway: "+comments);
855
                                attrList.add(attr1);
856
                                attr2.setValue(refundAmountGateway);
857
                                attrList.add(attr2);
858
                                attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
859
                                attrList.add(attr3);
860
                                transactionClient.setOrderAttributes(t_order.getId(), attrList);
861
                                successmsg = "Refund Marked Successful: Through Gateway";
862
                                return "physical-refund-result";
863
                            }
864
                            else{
865
                                if(payment.getGatewayId()==13L){
866
                                    attr1.setValue("Refund By Innoviti Gatway: "+comments);
867
                                    attrList.add(attr1);
868
                                    attr2.setValue(refundAmountGateway);
869
                                    attrList.add(attr2);
870
                                    attr3.setValue(timestmapFormat.format(Calendar.getInstance().getTime()));
871
                                    attrList.add(attr3);
872
                                    transactionClient.setOrderAttributes(t_order.getId(), attrList);
873
                                    successmsg = "Refund Marked Successful: Through Innoviti Payment Gateway.";
874
                                    return "physical-refund-result";
875
                                }
876
                                errorMsg ="Refund Unsuccessful: at Payment Gateway ";
877
                                return "physical-refund-result";
878
                            }
879
                        }
880
                        else{
881
                            errorMsg ="Refund Unsuccessful: Due to refund Amount is greater than Payment Gateway Amount ";
882
                            return "physical-refund-result";
883
                        }
884
                    }
885
                    errorMsg ="Refund Unsuccessful: There is no Payment to be refunded ";
886
                }
887
                else{
888
                    errorMsg ="Refund Unsuccessful: Due to either comments or refund amount is blank ";
889
                    return "physical-refund-result";
890
                }
6985 anupam.sin 891
 
13208 kshitij.so 892
            }
6985 anupam.sin 893
 
13208 kshitij.so 894
        }
895
        catch(Exception e){
896
            log.error(e);
897
        }
898
        return "physical-refund-result";
899
    }
6985 anupam.sin 900
 
13208 kshitij.so 901
    public int getRefundEnabledStatus(){
902
        try{
903
            TransactionClient transactionServiceClient = new TransactionClient();
904
            in.shop2020.model.v1.order.TransactionService.Client transactionClient
905
            = transactionServiceClient.getClient();
906
            in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
907
            if(OrderSource.WEBSITE.getValue()!=t_order.getSource()){
908
                return 1;
909
            }
910
            String refundOption=transactionClient.getOrderAttributeValue(orderId, "Refund_Option");
911
            String refundAmount=transactionClient.getOrderAttributeValue(orderId, "Refund_Amount");
912
            String refundTimeStamp = transactionClient.getOrderAttributeValue(orderId, "Refund_TimeStamp");
913
            List<String> details = new ArrayList<String>();
914
            if(refundOption!=null && !("").equalsIgnoreCase(refundOption)){
915
                details.add("Refund Option:- "+refundOption);
916
            }
6985 anupam.sin 917
 
13208 kshitij.so 918
            if(refundAmount!=null && !("").equalsIgnoreCase(refundAmount)){
919
                details.add("Refund Amount:- "+refundAmount);
920
            }
6985 anupam.sin 921
 
13208 kshitij.so 922
            if(refundTimeStamp!=null && !("").equalsIgnoreCase(refundTimeStamp)){
923
                details.add("Refund TimeStamp:- "+refundTimeStamp);
924
            }
925
            setPhysicalRefundDetails(details);
7190 amar.kumar 926
 
13208 kshitij.so 927
            if((refundOption!=null && refundAmount!=null) && (!("").equalsIgnoreCase(refundOption)) && !("").equalsIgnoreCase(refundAmount)){
928
                System.out.println("Into the Refund Condition");
929
                return 0;
930
            }
7372 kshitij.so 931
 
13208 kshitij.so 932
            else if(t_order.isCod()){
933
                if(setOfrefundableStates.contains(t_order.getStatus()) && SecurityUtils.getSubject().hasRole("TeamLead")){
934
                    System.out.println("Into the COD Status Condition");
935
                    return 2;
936
                }
937
            }
938
            else{
939
                if(( setOfprepaidrefundableStates.contains(t_order.getStatus()) || setOfrefundableStates.contains(t_order.getStatus()) ) && SecurityUtils.getSubject().hasRole("TeamLead") && (payments.get(0).getStatus() == PaymentStatus.SUCCESS || t_order.isSetOriginalOrderId())){
940
                    System.out.println("Into the Prepaid Status Condition");
941
                    return 2;
942
                }
943
            }
944
        }
945
        catch(Exception e){
946
            log.error(e);
947
        }
948
        return 1;
949
    }
7372 kshitij.so 950
 
13208 kshitij.so 951
    public int checkForOriginalOrders(){
952
        try{
953
            TransactionClient transactionServiceClient = new TransactionClient();
954
            in.shop2020.model.v1.order.TransactionService.Client transactionClient
955
            = transactionServiceClient.getClient();
956
            in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
957
            if(t_order.getOriginalOrderId()!=0l && t_order.getOriginalOrderId() > 0l){
958
                in.shop2020.model.v1.order.Order old_order = transactionClient.getOrder(t_order.getOriginalOrderId());
959
                if(old_order.isCod()){
960
                    return 1;
961
                }
962
                else{
963
                    return 2;
964
                }
965
            }
966
        }
967
        catch(Exception e){
968
            log.error(e);
969
        }
970
        return 0;
971
    }
7372 kshitij.so 972
 
13208 kshitij.so 973
    public void setPhysicalRefundDetails(List<String> details){
974
        this.refundDetails = details;
975
    }
7372 kshitij.so 976
 
13208 kshitij.so 977
    public List<String> getPhysicalRefundDetails(){
978
        return this.refundDetails;
979
    }
980
    //End:- Added by Manish Sharma for Physical Refunds 	
7372 kshitij.so 981
 
13208 kshitij.so 982
    public void setOrderId(String orderId) {
983
        try {
984
            this.orderId = Long.parseLong(orderId);
985
        } catch (NumberFormatException e) {
986
            log.error(e);
987
        }
988
    }
7372 kshitij.so 989
 
13208 kshitij.so 990
    public List<Payment> getPayments() {
991
        return payments;
992
    }
7372 kshitij.so 993
 
13208 kshitij.so 994
    public List<ShipmentUpdate> getShipmentUpdates() {
995
        return shipmentUpdates;
996
    }
7372 kshitij.so 997
 
13208 kshitij.so 998
    public void setShipmentUpdates(List<ShipmentUpdate> shipmentUpdates) {
999
        this.shipmentUpdates = shipmentUpdates;
1000
    }
7372 kshitij.so 1001
 
13208 kshitij.so 1002
    public Order getOrder() {
1003
        return order;
1004
    }
7372 kshitij.so 1005
 
13208 kshitij.so 1006
    public void setOrder(Order order) {
1007
        this.order = order;
1008
    }
7372 kshitij.so 1009
 
13208 kshitij.so 1010
    public Long getCodTicketId() {
1011
        return codTicketId;
1012
    }
7372 kshitij.so 1013
 
13208 kshitij.so 1014
    public void setCodTicketId(Long codTicketId) {
1015
        this.codTicketId = codTicketId;
1016
    }
7372 kshitij.so 1017
 
13208 kshitij.so 1018
    public List<Address> getAddresses() {
1019
        return addresses;
1020
    }
7372 kshitij.so 1021
 
13208 kshitij.so 1022
    public void setAddresses(List<Address> addresses) {
1023
        this.addresses = addresses;
1024
    }
7372 kshitij.so 1025
 
13208 kshitij.so 1026
    public String getOrderStatusDescription(Order order) {
1027
        String status = order.getStatus().getDescription();
7190 amar.kumar 1028
 
13208 kshitij.so 1029
        if (order.getStatus() == OrderStatus.DELIVERY_SUCCESS) {
1030
            status = "Completed";
1031
        }
7190 amar.kumar 1032
 
13208 kshitij.so 1033
        return status;
1034
    }
7190 amar.kumar 1035
 
13208 kshitij.so 1036
    public String getCancellationInitiator() {
1037
        return cancellationInitiator;
1038
    }
7190 amar.kumar 1039
 
13208 kshitij.so 1040
    public void setCancellationInitiator(String cancellationInitiator) {
1041
        this.cancellationInitiator = cancellationInitiator;
1042
    }
7190 amar.kumar 1043
 
13208 kshitij.so 1044
    public String getCancelReason() {
1045
        return cancelReason;
1046
    }
7190 amar.kumar 1047
 
13208 kshitij.so 1048
    public void setCancelReason(String cancelReason) {
1049
        this.cancelReason = cancelReason;
1050
    }
7190 amar.kumar 1051
 
13208 kshitij.so 1052
    public String getBody() {
1053
        return body;
1054
    }
7372 kshitij.so 1055
 
13208 kshitij.so 1056
    public void setBody(String body) {
1057
        this.body = body;
1058
    }
1059
 
1060
    public String getLine1() {
1061
        return line1;
1062
    }
1063
 
1064
    public void setLine1(String line1) {
1065
        this.line1 = line1;
1066
    }
1067
 
1068
    public String getLine2() {
1069
        return line2;
1070
    }
1071
 
1072
    public void setLine2(String line2) {
1073
        this.line2 = line2;
1074
    }
1075
 
1076
    public String getCity() {
1077
        return city;
1078
    }
1079
 
1080
    public void setCity(String city) {
1081
        this.city = city;
1082
    }
1083
 
1084
    public String getState() {
1085
        return state;
1086
    }
1087
 
1088
    public void setState(String state) {
1089
        this.state = state;
1090
    }
1091
 
1092
    public String getPin() {
1093
        return pin;
1094
    }
1095
 
1096
    public void setPin(String pin) {
1097
        this.pin = pin;
1098
    }
1099
 
1100
    public String getFreebieItem() {
1101
        return freebieItem;
1102
    }
1103
 
1104
    public void setFreebieItem(String freebieItem) {
1105
        this.freebieItem = freebieItem;
1106
    }
1107
 
1108
    public String getDealText() {
1109
        return dealText;
1110
    }
1111
 
1112
    public void setDealText(String dealText) {
1113
        this.dealText = dealText;
1114
    }
1115
 
1116
    public String getParentOrderIdForFreebieOrder() {
1117
        return parentOrderIdForFreebieOrder;
1118
    }
1119
 
1120
    public void setParentOrderIdForFreebieOrder(String parentOrderIdForFreebieOrder) {
1121
        this.parentOrderIdForFreebieOrder = parentOrderIdForFreebieOrder;
1122
    }
1123
 
1124
    public String getFreebieOrderId() {
1125
        return freebieOrderId;
1126
    }
1127
 
1128
    public void setFreebieOrderId(String freebieOrderId) {
1129
        this.freebieOrderId = freebieOrderId;
1130
    }
1131
 
7393 anupam.sin 1132
    public void setCashAmount(double cashAmount) {
1133
        this.cashAmount = cashAmount;
1134
    }
1135
 
1136
    public double getCashAmount() {
1137
        return cashAmount;
1138
    }
1139
 
1140
    public void setCardAmount(double cardAmount) {
1141
        this.cardAmount = cardAmount;
1142
    }
1143
 
1144
    public double getCardAmount() {
1145
        return cardAmount;
1146
    }
1147
 
1148
    public long getOrderId() {
1149
        return orderId;
1150
    }
1151
 
1152
    public void setOrderId(long orderId) {
1153
        this.orderId = orderId;
1154
    }
1155
 
1156
    public StoreOrderDetail getStoreOrderDetail() {
1157
        return storeOrderDetail;
1158
    }
1159
 
1160
    public void setStoreOrderDetail(StoreOrderDetail storeOrderDetail) {
1161
        this.storeOrderDetail = storeOrderDetail;
1162
    }
13208 kshitij.so 1163
 
1164
    //Start:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7826 manish.sha 1165
    public AmazonOrder getAmazonOrder() {
13208 kshitij.so 1166
        return amazonOrder;
1167
    }
7393 anupam.sin 1168
 
13208 kshitij.so 1169
    public void setAmazonOrder(AmazonOrder amazonOrder) {
1170
        this.amazonOrder = amazonOrder;
1171
    }
7826 manish.sha 1172
 
13208 kshitij.so 1173
    //End:- Added by Manish Sharma for Displaying Logistics Provider Id and Amazon Order Id on 25-Jul-2013
7826 manish.sha 1174
 
7836 anupam.sin 1175
    public void setProviderName(String providerName) {
1176
        this.providerName = providerName;
1177
    }
1178
 
1179
    public String getProviderName() {
1180
        return providerName;
1181
    }
13208 kshitij.so 1182
 
7836 anupam.sin 1183
    public static void main(String[] args) {
13208 kshitij.so 1184
 
7836 anupam.sin 1185
    }
1186
 
13208 kshitij.so 1187
    public void setGvAmount(long gvAmount) {
1188
        this.gvAmount = gvAmount;
1189
    }
8296 kshitij.so 1190
 
13208 kshitij.so 1191
    public long getGvAmount() {
1192
        return gvAmount;
1193
    }
1194
    //Start:- Added by Manish Sharma for Physical Refunds 
1195
    public String getRfdRadio() {
1196
        return rfdRadio;
1197
    }
8296 kshitij.so 1198
 
8824 manish.sha 1199
 
13208 kshitij.so 1200
    public void setRfdRadio(String rfdRadio) {
1201
        this.rfdRadio = rfdRadio;
1202
    }
8824 manish.sha 1203
 
1204
 
13208 kshitij.so 1205
    public String getCouponDetails() {
1206
        return couponDetails;
1207
    }
8824 manish.sha 1208
 
1209
 
13208 kshitij.so 1210
    public void setCouponDetails(String couponDetails) {
1211
        this.couponDetails = couponDetails;
1212
    }
8824 manish.sha 1213
 
1214
 
13208 kshitij.so 1215
    public String getRefundAmountCoupon() {
1216
        return refundAmountCoupon;
1217
    }
8824 manish.sha 1218
 
1219
 
13208 kshitij.so 1220
    public void setRefundAmountCoupon(String refundAmountCoupon) {
1221
        this.refundAmountCoupon = refundAmountCoupon;
1222
    }
8824 manish.sha 1223
 
1224
 
13208 kshitij.so 1225
    public String getChequeDetails() {
1226
        return chequeDetails;
1227
    }
8824 manish.sha 1228
 
1229
 
13208 kshitij.so 1230
    public void setChequeDetails(String chequeDetails) {
1231
        this.chequeDetails = chequeDetails;
1232
    }
8824 manish.sha 1233
 
1234
 
13208 kshitij.so 1235
    public String getRefundAmountCheque() {
1236
        return refundAmountCheque;
1237
    }
8824 manish.sha 1238
 
1239
 
13208 kshitij.so 1240
    public void setRefundAmountCheque(String refundAmountCheque) {
1241
        this.refundAmountCheque = refundAmountCheque;
1242
    }
8824 manish.sha 1243
 
1244
 
13208 kshitij.so 1245
    public String getRefundAmountGateway() {
1246
        return refundAmountGateway;
1247
    }
8824 manish.sha 1248
 
1249
 
13208 kshitij.so 1250
    public void setRefundAmountGateway(String refundAmountGateway) {
1251
        this.refundAmountGateway = refundAmountGateway;
1252
    }
8824 manish.sha 1253
 
1254
 
13208 kshitij.so 1255
    public String getComments() {
1256
        return comments;
1257
    }
8824 manish.sha 1258
 
1259
 
13208 kshitij.so 1260
    public void setComments(String comments) {
1261
        this.comments = comments;
1262
    }
1263
 
1264
    public String getErrorMsg(){
8824 manish.sha 1265
        return this.errorMsg;
1266
    }
13208 kshitij.so 1267
 
1268
    public String getSuccessMessage(){
1269
        return this.successmsg ;
1270
    }
1271
 
1272
    public void setBillingWarehouseName(String billingWarehouseName) {
1273
        this.billingWarehouseName = billingWarehouseName;
1274
    }
1275
 
1276
    public String getBillingWarehouseName() {
1277
        return billingWarehouseName;
1278
    }
1279
 
13440 amit.gupta 1280
 
1281
    public String getGatewayName(Payment payment){
1282
    	return CRMConstants.PAYMENT_GATEWAYS.get(payment.getGatewayId());
1283
    }
13208 kshitij.so 1284
 
13440 amit.gupta 1285
 
2674 vikas 1286
}