Subversion Repositories SmartDukaan

Rev

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