Subversion Repositories SmartDukaan

Rev

Rev 20172 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3137 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
3339 mandeep.dh 6
import in.shop2020.crm.Activity;
7
import in.shop2020.crm.ActivityType;
3137 mandeep.dh 8
import in.shop2020.crm.Agent;
3390 mandeep.dh 9
import in.shop2020.crm.SearchFilter;
3137 mandeep.dh 10
import in.shop2020.crm.Ticket;
3339 mandeep.dh 11
import in.shop2020.crm.TicketCategory;
12
import in.shop2020.crm.TicketPriority;
3137 mandeep.dh 13
import in.shop2020.crm.TicketStatus;
5791 anupam.sin 14
import in.shop2020.model.v1.order.Attribute;
3546 mandeep.dh 15
import in.shop2020.model.v1.order.LineItem;
16
import in.shop2020.model.v1.order.Order;
17
import in.shop2020.model.v1.order.OrderStatus;
4267 anupam.sin 18
import in.shop2020.model.v1.order.Transaction;
3546 mandeep.dh 19
import in.shop2020.model.v1.order.TransactionServiceException;
4267 anupam.sin 20
import in.shop2020.model.v1.order.TransactionStatus;
3137 mandeep.dh 21
import in.shop2020.model.v1.user.User;
22
import in.shop2020.model.v1.user.UserContextException;
3578 mandeep.dh 23
import in.shop2020.payments.Payment;
24
import in.shop2020.payments.PaymentException;
25
import in.shop2020.payments.PaymentStatus;
3390 mandeep.dh 26
import in.shop2020.serving.auth.CRMAuthorizingRealm;
27
import in.shop2020.thrift.clients.CRMClient;
3405 mandeep.dh 28
import in.shop2020.thrift.clients.HelperClient;
3578 mandeep.dh 29
import in.shop2020.thrift.clients.PaymentClient;
3546 mandeep.dh 30
import in.shop2020.thrift.clients.TransactionClient;
3390 mandeep.dh 31
import in.shop2020.thrift.clients.UserClient;
3405 mandeep.dh 32
import in.shop2020.util.CRMConstants;
20152 aman.kumar 33
import in.shop2020.util.CRMConstants.Actionable;
4020 mandeep.dh 34
import in.shop2020.util.CRMConstants.EscalationMatrix;
16244 manish.sha 35
import in.shop2020.util.CRMConstants.PMEscalationMatrix;
17196 manish.sha 36
import in.shop2020.util.SendGrid;
16642 manish.sha 37
import in.shop2020.util.SendGridException;
17196 manish.sha 38
import in.shop2020.utils.GmailUtils;
3405 mandeep.dh 39
import in.shop2020.utils.HelperService.Client;
40
import in.shop2020.utils.HelperServiceException;
3546 mandeep.dh 41
import in.shop2020.utils.ModelUtils;
3137 mandeep.dh 42
 
17083 manish.sha 43
import java.io.File;
3397 mandeep.dh 44
import java.text.ParseException;
5791 anupam.sin 45
import java.text.SimpleDateFormat;
3137 mandeep.dh 46
import java.util.ArrayList;
5791 anupam.sin 47
import java.util.Arrays;
3578 mandeep.dh 48
import java.util.Calendar;
3390 mandeep.dh 49
import java.util.Collections;
3405 mandeep.dh 50
import java.util.Date;
4490 anupam.sin 51
import java.util.HashMap;
3137 mandeep.dh 52
import java.util.List;
5909 amar.kumar 53
import java.util.Map;
3137 mandeep.dh 54
 
17083 manish.sha 55
import javax.mail.MessagingException;
56
 
4256 mandeep.dh 57
import net.htmlparser.jericho.Source;
58
 
3405 mandeep.dh 59
import org.apache.shiro.SecurityUtils;
3137 mandeep.dh 60
import org.apache.thrift.TException;
3546 mandeep.dh 61
import org.apache.thrift.transport.TTransportException;
3137 mandeep.dh 62
 
63
/**
64
 * @author mandeep
65
 * 
66
 */
67
public class TicketsController extends BaseController {
68
 
69
    /**
70
     * 
71
     */
72
    private static final long serialVersionUID = 1L;
73
 
74
    List<Ticket>              tickets          = new ArrayList<Ticket>();
14882 manish.sha 75
 
3405 mandeep.dh 76
    private String            customerEmailId;
3339 mandeep.dh 77
    private String            description;
78
    private String            assigneeEmailId;
79
    private String            priority;
80
    private String            category;
81
    private String            orderId;
3397 mandeep.dh 82
    private String[]          agentIds;
83
    private String            startTimestamp;
84
    private String            endTimestamp;
3137 mandeep.dh 85
 
3405 mandeep.dh 86
    private String            userId;
87
    private String            id;
88
    private String            activityDescription;
89
    private String            status;
90
    private String            activityType;
91
    private Ticket            ticket;
92
    private List<Activity>    activities;
93
    private String            subject;
94
    private String            body;
95
    private String            customerName;
96
    private String            customerMobileNumber;
3546 mandeep.dh 97
    private User              user;
98
    private String            orderStatus;
99
    private List<Order>       orders;
19072 manish.sha 100
    private Map<Long, Order>  transactions;
101
	private Map<Long, Long>   transactionShipping;
102
    private Map<Long, Long>   transactionTotal;
4267 anupam.sin 103
    private List<Payment>     payments;
4020 mandeep.dh 104
    private String            escalate;
4241 anupam.sin 105
    private String            cancelReason;
4267 anupam.sin 106
    private String            transactionId;
5791 anupam.sin 107
    private String            pickupExtension;
5909 amar.kumar 108
    private Map<String, Long> ticketCategorycountMap;
7645 anupam.sin 109
    private String premises = "";
110
    private String closureType = "";
4438 anupam.sin 111
    private String paymentId;
20152 aman.kumar 112
    private String quantity;
113
    private String disposition;
114
    private List<String> actionable;
4438 anupam.sin 115
 
4490 anupam.sin 116
    private HashMap<String, String> allAttachmentsForTicket;
117
 
3405 mandeep.dh 118
    public String index() {
119
        try {
120
            if (id != null && !id.isEmpty()) {
121
                SearchFilter searchFilter = new SearchFilter();
122
                crmServiceClient = new CRMClient().getClient();
123
                searchFilter.setTicketId(Long.parseLong(id));
124
                tickets = crmServiceClient.getTickets(searchFilter);
125
            }
126
        } catch (TException e) {
127
            log.error("Error while getting tickets", e);
128
            return EXCEPTION;
129
        }
130
 
131
        return INDEX;
132
    }
133
 
134
    public String edit() {
135
        try {
136
            long ticketId = Long.parseLong(id);
137
            SearchFilter searchFilter = new SearchFilter();
138
            searchFilter.setTicketId(ticketId);
139
            crmServiceClient = new CRMClient().getClient();
140
            ticket = crmServiceClient.getTickets(searchFilter).get(0);
141
            activities = crmServiceClient.getActivities(searchFilter);
4490 anupam.sin 142
            populateAttachments();
3405 mandeep.dh 143
            subject = createSubjectString(ticket);
144
 
145
            if (ticket.isSetCustomerId()) {
146
                userId = String.valueOf(ticket.getCustomerId());
3546 mandeep.dh 147
                userContextServiceClient = new UserClient().getClient();
148
 
149
                try {
150
                    user = userContextServiceClient.getUserById(ticket
151
                            .getCustomerId());
152
                } catch (UserContextException e) {
153
                    log.error("Could not fetch user details", e);
154
                }
3405 mandeep.dh 155
            }
156
 
157
            customerEmailId = ticket.getCustomerEmailId();
4689 anupam.sin 158
 
20152 aman.kumar 159
            setSuitableActionable(ticket.getCategory());
160
            //log.info("actionable list "+ getActionable());
161
 
4277 anupam.sin 162
            if (TicketCategory.ORDER_CANCELLATION.equals(ticket.getCategory())) {
163
                log.info("Fetching orders for " + ticket.getCustomerId());
164
                orders = new ArrayList<Order>();
165
                transactionServiceClient = new TransactionClient().getClient();
4689 anupam.sin 166
                for (Order order : transactionServiceClient
167
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
168
                                Collections.singletonList(OrderStatus.CANCEL_REQUEST_RECEIVED))) {
169
                    log.info("Processing Order: " + order.getId());
4287 anupam.sin 170
                    orders.add(order);
171
                }
4277 anupam.sin 172
            }
3546 mandeep.dh 173
 
174
            if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
175
                log.info("Fetching orders for " + ticket.getCustomerId());
176
                orders = new ArrayList<Order>();
18341 amit.gupta 177
                transactions = new HashMap<Long, Order>();
18343 amit.gupta 178
                transactionShipping = new HashMap<Long, Long>();
179
                transactionTotal = new HashMap<Long, Long>();
3546 mandeep.dh 180
                transactionServiceClient = new TransactionClient().getClient();
181
                for (Order order : transactionServiceClient
182
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
4663 rajveer 183
                                Collections.singletonList(OrderStatus.COD_VERIFICATION_PENDING))) {
3546 mandeep.dh 184
                    log.info("Processing Order: " + order);
185
                    if (order.isCod()) {
18341 amit.gupta 186
                    	transactions.put(order.getTransactionId(), order);
19072 manish.sha 187
                    	if (!transactionShipping.containsKey(order.getTransactionId())){
18342 amit.gupta 188
                    		transactionShipping.put(order.getTransactionId(), (long)order.getShippingCost());
18341 amit.gupta 189
                    	} else {
18342 amit.gupta 190
                    		transactionShipping.put(order.getTransactionId(), transactionShipping.get(order.getTransactionId()).longValue() + (long)order.getShippingCost());
18341 amit.gupta 191
                    	}
19072 manish.sha 192
                    	if (!transactionTotal.containsKey(order.getTransactionId())){
18342 amit.gupta 193
                    		transactionTotal.put(order.getTransactionId(), (long)order.getTotal_amount()-(long)order.getGvAmount());
18341 amit.gupta 194
                    	} else {
18342 amit.gupta 195
                    		transactionTotal.put(order.getTransactionId(), transactionTotal.get(order.getTransactionId()).longValue() + (long)order.getTotal_amount()-(long)order.getGvAmount());
18341 amit.gupta 196
                    	}
19072 manish.sha 197
                    	orders.add(order);
3546 mandeep.dh 198
                    }
199
                }
18341 amit.gupta 200
 
3546 mandeep.dh 201
            }
4689 anupam.sin 202
 
4490 anupam.sin 203
            if (TicketCategory.DOA_RECEIVED.equals(ticket.getCategory())) {
204
                log.info("Fetching orders for " + ticket.getCustomerId());
205
                orders = new ArrayList<Order>();
206
                transactionServiceClient = new TransactionClient().getClient();
207
                for (Order order : transactionServiceClient
208
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
209
                                Collections.singletonList(OrderStatus.DOA_REQUEST_RECEIVED))) {
210
                    log.info("Processing Order: " + order);
211
                    if (order != null) {
212
                        orders.add(order);
213
                    }
214
                }
215
            }
4689 anupam.sin 216
 
4490 anupam.sin 217
            if (TicketCategory.RETURN_FORM.equals(ticket.getCategory())) {
218
                log.info("Fetching orders for " + ticket.getCustomerId());
219
                orders = new ArrayList<Order>();
220
                transactionServiceClient = new TransactionClient().getClient();
221
                for (Order order : transactionServiceClient
222
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
223
                                Collections.singletonList(OrderStatus.RET_REQUEST_RECEIVED))) {
224
                    log.info("Processing Order: " + order);
225
                    if (order != null) {
226
                        orders.add(order);
227
                    }
228
                }
229
            }
3578 mandeep.dh 230
 
4267 anupam.sin 231
            if (TicketCategory.PAYMENT_FLAGGED.equals(ticket.getCategory())) {
232
                log.info("Fetching orders for " + ticket.getCustomerId());
233
                payments = new ArrayList<Payment>();
234
                in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
235
                transactionServiceClient = new TransactionClient().getClient();
236
                for (Transaction transaction : transactionServiceClient
237
                        .getTransactionsForCustomer(ticket.getCustomerId(), 0, 0, TransactionStatus.FLAGGED)) {
238
                    log.info("Processing Transaction: " + transaction);
239
                    for ( Payment payment : paymentClient.getPaymentForTxnId(transaction.getId())) {
240
                        if( payment.getStatus().equals(PaymentStatus.AUTHORIZED)) {
241
                            payments.add(payment);
242
                        }
243
                    }
244
                }
245
            }
246
 
3578 mandeep.dh 247
            if (TicketCategory.FAILED_PAYMENTS.equals(ticket.getCategory())) {
248
                log.info("Fetching orders for " + ticket.getCustomerId());
249
                orders = new ArrayList<Order>();
250
                in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
251
 
252
                long failedTransactionId = -1;
253
                long lastfailedTransactionTimestamp = -1;
254
                for (Payment payment : paymentClient.getPaymentsForUser(ticket.getCustomerId(), 0, getTomorrow().getTime(), PaymentStatus.FAILED, 0)) {
255
                    if (payment.getErrorTimestamp() > lastfailedTransactionTimestamp) {
256
                        failedTransactionId = payment.getMerchantTxnId();
257
                    }
258
                }
259
 
260
                transactionServiceClient = new TransactionClient().getClient();
261
                orders.addAll(transactionServiceClient.getOrdersForTransaction(failedTransactionId, ticket.getCustomerId()));
262
            }
4008 mandeep.dh 263
 
264
            if (TicketCategory.DELAYED_DELIVERY.equals(ticket.getCategory())) {
265
                log.info("Fetching orders for " + ticket.getCustomerId());
266
                orders = new ArrayList<Order>();
267
                transactionServiceClient = new TransactionClient().getClient();
268
 
269
                for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0, null)) {
270
                    if (order.getExpected_delivery_time() > order.getPromised_delivery_time() && order.getExpected_delivery_time() > new Date().getTime()) {
271
                        orders.add(order);
272
                    }
273
                }
274
            }
5791 anupam.sin 275
 
276
            if (TicketCategory.STORE_PICKUP.equals(ticket.getCategory())) {
277
                log.info("Fetching orders for " + ticket.getCustomerId());
278
                orders = new ArrayList<Order>();
279
                transactionServiceClient = new TransactionClient().getClient();
280
                for (Order order : transactionServiceClient
281
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
282
                                Collections.singletonList(OrderStatus.RECEIVED_AT_STORE))) {
283
                    log.info("Processing Order: " + order.getId());
284
                    orders.add(order);
285
                }
286
            }
287
 
3405 mandeep.dh 288
        } catch (TException e) {
3546 mandeep.dh 289
            log.error("Error loading edit page", e);
290
        } catch (NumberFormatException e) {
291
            log.error("Error parsing orderId", e);
292
        } catch (TransactionServiceException e) {
293
            log.error("Error fetching orders for " + ticket.getCustomerId(), e);
3578 mandeep.dh 294
        } catch (PaymentException e) {
295
            log.error("Error fetching payments for " + ticket.getCustomerId(), e);
3405 mandeep.dh 296
        }
297
 
298
        return EDIT;
299
    }
300
 
4490 anupam.sin 301
    private void populateAttachments() {
302
        allAttachmentsForTicket = new HashMap<String, String>();
303
        for (Activity activity : activities) {
304
            log.info("" + activity.getId());
305
            String attachment = activity.getAttachments();
306
            if (attachment != null && !attachment.isEmpty()) {
307
                log.info("" + attachment);
308
                String [] attachmentList = attachment.split(";");
309
                for (String attachmentName : attachmentList) {
310
                    if (attachmentName != null && !attachmentName.isEmpty()) {
311
                        log.info("" + attachmentName);
312
                        allAttachmentsForTicket.put(activity.getId() + "-" + attachmentName, attachmentName);
313
                    }
314
                }
315
            }
316
        }
317
    }
318
 
5791 anupam.sin 319
    public static void main(String[] args) throws TException {
320
        SearchFilter s = new SearchFilter();
321
//      s.setTicketId(200l);
322
//      s.setTicketAssigneeIds(null);
323
//      s.setTicketAssigneeIds(new ArrayList<Long>());
324
//      s.setActivityCreatorIds(Collections.singletonList(2l));
325
//      s.setEndTimestamp(new Date());
326
      //s.setTicketCategory(TicketCategory.STORE_PICKUP);
327
      s.setTicketId((long) 51345);
328
      in.shop2020.crm.CRMService.Client crmServiceClient = new CRMClient().getClient();
329
      Ticket ticket = crmServiceClient.getTickets(s).get(0);
330
      System.out.println(ticket.getCategory().name());
4490 anupam.sin 331
    }
332
 
3405 mandeep.dh 333
    private String createSubjectString(Ticket ticket) {
14882 manish.sha 334
    	if(!profitMandiTicketCategoryList.contains(ticket.getCategory())){
335
	        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
336
	                + " " + ticket.getCategory().name();
337
    	}else{
338
    		return CRMConstants.PROFIT_MANDI_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
339
            + " " + ticket.getCategory().name();
340
    	}
3405 mandeep.dh 341
    }
342
 
3578 mandeep.dh 343
    private Date getTomorrow() {
344
        Calendar calendar = Calendar.getInstance();
345
        calendar.setTime(new Date());
346
        calendar.add(Calendar.DAY_OF_MONTH, 1);
347
        return calendar.getTime();
348
    }
349
 
3339 mandeep.dh 350
    public String create() {
351
        try {
3546 mandeep.dh 352
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
353
                    .getId();
3339 mandeep.dh 354
            Ticket ticket = new Ticket();
355
            ticket.setDescription(description);
356
            ticket.setCreatorId(creatorId);
357
            ticket.setStatus(TicketStatus.OPEN);
358
            ticket.setPriority(TicketPriority.valueOf(priority));
359
            ticket.setCategory(TicketCategory.valueOf(category));
360
 
361
            Activity activity = new Activity();
362
            activity.setDescription("Creating Ticket");
363
            activity.setType(ActivityType.OTHER);
364
            activity.setTicketPriority(TicketPriority.valueOf(priority));
365
            activity.setTicketStatus(TicketStatus.OPEN);
366
            activity.setCreatorId(creatorId);
367
            activity.setTicketCategory(TicketCategory.valueOf(category));
368
            activity.setTicketDescription(description);
369
 
370
            if (orderId != null && !orderId.isEmpty()) {
371
                ticket.setOrderId(Long.parseLong(orderId));
372
            }
4490 anupam.sin 373
 
374
            if (TicketCategory.valueOf(category) == TicketCategory.DOA_RECEIVED) {
375
                transactionServiceClient = new TransactionClient().getClient();
20091 kshitij.so 376
                if (!transactionServiceClient.markOrderDoaRequestReceived(Long.parseLong(orderId))) {
4490 anupam.sin 377
                    throw new Exception("Order cannot be marked as DOA Received");
20091 kshitij.so 378
                }
4490 anupam.sin 379
                log.info("" + userId);
19765 manish.sha 380
                try{
381
	                Order order = transactionServiceClient.getOrder(Long.parseLong(orderId));
382
	                log.info("In order table id is : " + order.getCustomer_id());
383
	                if (userId == null || userId.isEmpty() || order.getCustomer_id() != Long.parseLong(userId)) {
384
	                    throw new Exception("This order is not associated with this user Id");
385
	                }
386
                }catch(Exception e){
387
                	throw new Exception("No Order Found for given order id");
4490 anupam.sin 388
                }
389
            }
390
 
391
            if (TicketCategory.valueOf(category) == TicketCategory.RETURN_FORM) {
392
                transactionServiceClient = new TransactionClient().getClient();
20091 kshitij.so 393
                if (!transactionServiceClient.markOrderReturnRequestReceived(Long.parseLong(orderId))) {
4490 anupam.sin 394
                    throw new Exception("Order cannot be marked as Return Requested");
20091 kshitij.so 395
                }
4490 anupam.sin 396
                log.info("" + userId);
19765 manish.sha 397
                try{
398
	                Order order = transactionServiceClient.getOrder(Long.parseLong(orderId));
399
	                log.info("In order table id is : " + order.getCustomer_id());
400
	                if (userId == null || userId.isEmpty() || order.getCustomer_id() != Long.parseLong(userId)) {
401
	                    throw new Exception("This order is not associated with this user Id");
402
	                }
403
                }catch(Exception e){
404
                	throw new Exception("No Order Found for given order id");
4490 anupam.sin 405
                }
406
            }
4681 amar.kumar 407
            if(body!=null && !body.isEmpty()){
408
            	String plainTextbody = new Source(body).getTextExtractor().toString();
409
            	ticket.setDescription(description + " : " + plainTextbody);
410
            }
4490 anupam.sin 411
 
3405 mandeep.dh 412
            if (userId != null && !userId.isEmpty()) {
413
                ticket.setCustomerId(Long.parseLong(userId));
414
                activity.setCustomerId(Long.parseLong(userId));
3546 mandeep.dh 415
            } else {
3390 mandeep.dh 416
                User user = null;
417
                userContextServiceClient = new UserClient().getClient();
418
                try {
3405 mandeep.dh 419
                    if (customerName != null && !customerName.isEmpty()) {
420
                        ticket.setCustomerName(customerName);
421
                        activity.setCustomerName(customerName);
422
                    }
423
 
424
                    if (customerEmailId != null && !customerEmailId.isEmpty()) {
425
                        ticket.setCustomerEmailId(customerEmailId);
426
                        activity.setCustomerEmailId(customerEmailId);
3546 mandeep.dh 427
                        user = userContextServiceClient
428
                                .getUserByEmail(customerEmailId);
3405 mandeep.dh 429
                    }
430
 
3546 mandeep.dh 431
                    if ((user == null || user.getUserId() == -1)
432
                            && customerMobileNumber != null
433
                            && !customerMobileNumber.isEmpty()) {
3405 mandeep.dh 434
                        ticket.setCustomerMobileNumber(customerMobileNumber);
435
                        activity.setCustomerMobileNumber(customerMobileNumber);
3546 mandeep.dh 436
                        user = userContextServiceClient
437
                                .getUserByMobileNumber(Long
438
                                        .parseLong(customerMobileNumber));
3405 mandeep.dh 439
                    }
3390 mandeep.dh 440
                } catch (UserContextException e) {
3546 mandeep.dh 441
                    log.error("Could not fetch user for: " + customerEmailId
442
                            + " " + customerMobileNumber + " " + customerName,
443
                            e);
3390 mandeep.dh 444
                }
3546 mandeep.dh 445
 
3390 mandeep.dh 446
                if (user != null && user.getUserId() != -1) {
447
                    ticket.setCustomerId(user.getUserId());
448
                    activity.setCustomerId(user.getUserId());
449
                }
3339 mandeep.dh 450
            }
451
 
452
            // handling null values appropriately
453
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
3546 mandeep.dh 454
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
455
                        .getId();
3339 mandeep.dh 456
                ticket.setAssigneeId(assigneeId);
457
                activity.setTicketAssigneeId(assigneeId);
458
            }
459
 
3546 mandeep.dh 460
            crmServiceClient = new CRMClient().getClient();
461
            id = String
462
                    .valueOf(crmServiceClient.insertTicket(ticket, activity));
3339 mandeep.dh 463
        } catch (TException e) {
464
            log.error("Error while creating ticket", e);
465
            return EXCEPTION;
4490 anupam.sin 466
        } catch (NumberFormatException e) {
467
            log.error("Error while parsing Order Id", e);
468
            return EXCEPTION;
469
        } catch (TransactionServiceException e) {
470
            log.error("Error while updating order status", e);
471
            return EXCEPTION;
472
        } catch (Exception e) {
473
            log.error(e.getMessage());
474
            return EXCEPTION;
3339 mandeep.dh 475
        }
476
 
3405 mandeep.dh 477
        return index();
3339 mandeep.dh 478
    }
479
 
3405 mandeep.dh 480
    public boolean isAssigneeEditable() {
8847 manish.sha 481
        return (SecurityUtils.getSubject().hasRole("TeamLead") || SecurityUtils.getSubject().hasRole("Outbound"));
3405 mandeep.dh 482
    }
483
 
3397 mandeep.dh 484
    public String searchTickets() throws ParseException {
3137 mandeep.dh 485
        try {
3397 mandeep.dh 486
            SearchFilter searchFilter = new SearchFilter();
3405 mandeep.dh 487
            if (userId != null && !userId.isEmpty()) {
488
                searchFilter.setCustomerId(Long.parseLong(userId));
489
            }
490
 
3397 mandeep.dh 491
            if (agentIds != null && agentIds.length != 0) {
492
                searchFilter.setTicketAssigneeIds(new ArrayList<Long>());
493
                for (String agentId : agentIds) {
3546 mandeep.dh 494
                    searchFilter.getTicketAssigneeIds().add(
495
                            CRMAuthorizingRealm.getAgent(agentId).getId());
3397 mandeep.dh 496
                }
497
            }
7595 kshitij.so 498
 
499
            //Start:- Added By Manish Sharma for Searching Tickets/Activities using  Mobile No. on 21-Jun-2013
500
            if(customerMobileNumber!=null && !customerMobileNumber.isEmpty()){
501
            	searchFilter.setCustomerMobileNumber(customerMobileNumber);
502
            }
503
            //End:- Added By Manish Sharma for Searching Tickets/Activities using  Mobile No. on 21-Jun-2013
504
 
3397 mandeep.dh 505
            if (startTimestamp != null && !startTimestamp.isEmpty()) {
3546 mandeep.dh 506
                searchFilter.setStartTimestamp(SDF.parse(startTimestamp)
507
                        .getTime());
3397 mandeep.dh 508
            }
509
 
510
            if (endTimestamp != null && !endTimestamp.isEmpty()) {
511
                searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());
512
            }
513
 
3422 mandeep.dh 514
            if (id != null && !id.isEmpty()) {
515
                searchFilter.setTicketId(Long.parseLong(id));
516
            }
517
 
3499 mandeep.dh 518
            if (status != null && !status.isEmpty()) {
3972 mandeep.dh 519
                searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
520
                searchFilter.getTicketStatuses().add(TicketStatus.valueOf(status));
521
                if (TicketStatus.OPEN.name().equals(status)) {
522
                    searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
523
                }
3499 mandeep.dh 524
            }
525
 
526
            if (category != null && !category.isEmpty()) {
3546 mandeep.dh 527
                searchFilter
528
                        .setTicketCategory(TicketCategory.valueOf(category));
3499 mandeep.dh 529
            }
530
 
3546 mandeep.dh 531
            crmServiceClient = new CRMClient().getClient();
3405 mandeep.dh 532
            tickets = crmServiceClient.getTickets(searchFilter);
3137 mandeep.dh 533
        } catch (TException e) {
534
            String errorString = "Error getting tickets for "
535
                    + currentAgentEmailId;
536
            log.error(errorString, e);
537
            addActionError(errorString);
538
        }
539
 
3405 mandeep.dh 540
        return index();
3137 mandeep.dh 541
    }
542
 
543
    public String getUnassignedTickets() {
544
        try {
16244 manish.sha 545
        	tickets = new ArrayList<Ticket>();
3546 mandeep.dh 546
            crmServiceClient = new CRMClient().getClient();
16244 manish.sha 547
            List<Ticket> unassignedTickets = crmServiceClient.getUnassignedTickets();
548
            for(Ticket unassignedTicket: unassignedTickets){
549
            	if(isSaholicAndProfitMandiAllowed()){
550
            		tickets.add(unassignedTicket);
551
            	}else if(isProfitMandiAgent()){
552
            		if(profitMandiTicketCategoryList.contains(unassignedTicket.getCategory())){
553
            			tickets.add(unassignedTicket);
554
            		}
555
            	}else{
556
            		if(!profitMandiTicketCategoryList.contains(unassignedTicket.getCategory())){
557
            			tickets.add(unassignedTicket);
558
            		}
559
            	}
560
            }
3137 mandeep.dh 561
        } catch (TException e) {
3339 mandeep.dh 562
            String errorString = "Error getting tickets for "
563
                    + currentAgentEmailId;
3137 mandeep.dh 564
            log.error(errorString, e);
565
            addActionError(errorString);
566
        }
567
 
3405 mandeep.dh 568
        return index();
3137 mandeep.dh 569
    }
570
 
3405 mandeep.dh 571
    public String update() {
17083 manish.sha 572
    	String commonDescription ="";
20172 aman.kumar 573
    	String addTo[]= new String[]{"amit.sirohi@shop2020.in","rajneesh.arora@saholic.com","khushal.bhatia@saholic.com"};
3405 mandeep.dh 574
        try {
575
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
576
                    .getId();
577
 
3546 mandeep.dh 578
            SearchFilter searchFilter = new SearchFilter();
579
            searchFilter.setTicketId(Long.parseLong(id));
580
            crmServiceClient = new CRMClient().getClient();
581
            Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
3405 mandeep.dh 582
            ticket.setDescription(description);
583
            ticket.setPriority(TicketPriority.valueOf(priority));
584
 
585
            // Update when a ticket is closed!
3578 mandeep.dh 586
            if (TicketStatus.CLOSED.name().equals(status) || TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
3546 mandeep.dh 587
                if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())
588
                        && pendingCODOrders(ticket.getCustomerId())) {
589
                    addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");
590
                } else {
591
                    ticket.setCategory(TicketCategory.valueOf(category));
592
                    ticket.setStatus(TicketStatus.valueOf(status));
593
                    ticket.setCloseDate(new Date().getTime());
594
                }
3405 mandeep.dh 595
            }
3546 mandeep.dh 596
            else {
597
                ticket.setCategory(TicketCategory.valueOf(category));
3578 mandeep.dh 598
                ticket.setStatus(TicketStatus.valueOf(status));
3546 mandeep.dh 599
            }
3405 mandeep.dh 600
 
601
            if (activityDescription == null || activityDescription.isEmpty()) {
4241 anupam.sin 602
                activityDescription = "Ticket fields updated";
3405 mandeep.dh 603
            }
604
 
605
            Activity activity = new Activity();
606
            activity.setDescription(activityDescription);
20152 aman.kumar 607
            if(getDisposition()!=null&&!Actionable.NO_ACTION.toString().equals(getDisposition())){
608
            	activity.setDescription(getDisposition()+" -> "+activityDescription);
609
            }
3405 mandeep.dh 610
            activity.setType(ActivityType.valueOf(activityType));
3546 mandeep.dh 611
            activity.setTicketPriority(ticket.getPriority());
612
            activity.setTicketStatus(ticket.getStatus());
3405 mandeep.dh 613
            activity.setCreatorId(creatorId);
3546 mandeep.dh 614
            activity.setTicketCategory(ticket.getCategory());
615
            activity.setTicketDescription(ticket.getDescription());
3405 mandeep.dh 616
 
617
            if (userId != null && !userId.isEmpty()) {
618
                activity.setCustomerId(Long.parseLong(userId));
619
            }
620
 
4035 mandeep.dh 621
            // Handling null values appropriately
622
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
623
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
624
                        .getId();
625
                ticket.setAssigneeId(assigneeId);
626
                activity.setTicketAssigneeId(assigneeId);
627
            }
628
 
3405 mandeep.dh 629
            if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
630
                log.info("Sending mail");
631
                Client helperClient = new HelperClient().getClient();
14882 manish.sha 632
                if(!profitMandiTicketCategoryList.contains(ticket.getCategory())){
633
	                activity.setUserEmailId(helperClient.saveUserEmailForSending(
634
	                        Arrays.asList(customerEmailId), CRMConstants.CRM_EMAIL_SENDOR,
635
	                        subject, body, null, CRMConstants.CRM_EMAIL_TYPE, null, null, 1));
636
                }else{
16524 manish.sha 637
                	try{
16642 manish.sha 638
                		sendMailToUser();          		
16524 manish.sha 639
 
640
                	} catch(Exception e){
16644 manish.sha 641
                		log.info("Error while sending mail to user:- "+customerEmailId+" ticket Id:- "+ticket.getId());
16524 manish.sha 642
                		log.error("Error while sending mail to user:- "+customerEmailId+" ticket Id:- "+ticket.getId(), e);
643
                	}
644
 
645
                	/*activity.setUserEmailId(helperClient.saveUserEmailForSending(
14882 manish.sha 646
	                        Arrays.asList(customerEmailId), CRMConstants.PROFIT_MANDI_EMAIL_SENDER,
16524 manish.sha 647
	                        subject, body, null, CRMConstants.PROFIT_MANDI_EMAIL_TYPE, null, null, 1));*/
14882 manish.sha 648
                }
3405 mandeep.dh 649
 
4256 mandeep.dh 650
                String plainTextbody = new Source(body).getTextExtractor().toString();
651
 
3405 mandeep.dh 652
                // We change activityType to OTHER when pop up box for email
653
                // closes
654
                activity.setDescription("Subject: " + subject + "\n\n"
4256 mandeep.dh 655
                        + "Body: " + plainTextbody);
4206 mandeep.dh 656
 
657
                String activityDesc = activity.getDescription();
658
                if (activityDesc.length() > CRMConstants.DESCRIPTION_MAX_WIDTH) {
659
                    activityDesc = activityDesc.substring(0, CRMConstants.DESCRIPTION_MAX_WIDTH);
660
                    activityDesc += "\n\nTHIS TEXT IS TRUNCATED. PLEASE VISIT INBOX TO SEE COMPLETE DETAILS.";
661
                }
662
 
663
                activity.setDescription(activityDesc);
3405 mandeep.dh 664
            }
665
 
4020 mandeep.dh 666
            if (ActivityType.ESCALATE_TICKET.equals(activity.getType())) {
667
                log.info("Sending escalation mail");
16244 manish.sha 668
                if(escalate.startsWith("PM")){
669
                	PMEscalationMatrix escalation = CRMConstants.PMEscalationMatrix.valueOf(escalate);
670
                	List<Integer> escalationReceipients = escalation.getAgentIds();
671
 
672
                	List<String> toMailIds = new ArrayList<String>();
673
                    for (Integer agentId : escalationReceipients) {
674
                        toMailIds.add(CRMAuthorizingRealm.getAgent(agentId).getEmailId());
4020 mandeep.dh 675
 
16244 manish.sha 676
                        // Setting last agent as assignee
677
                        ticket.setAssigneeId(agentId);
678
                        activity.setTicketAssigneeId(agentId);
679
                    }
4034 mandeep.dh 680
 
16244 manish.sha 681
                    Client helperClient = new HelperClient().getClient();
682
                    String escalationMailSubject = createPMEscalationMailSubject(ticket, escalation);
683
                    String escalationMailBody = createEscalationMailBody(ticket);
16402 manish.sha 684
 
685
                    if(profitMandiTicketCategoryList.contains(ticket.getCategory())){
4020 mandeep.dh 686
 
16402 manish.sha 687
	                    activity.setUserEmailId(helperClient.saveUserEmailForSending(
688
	                            toMailIds, CRMConstants.PROFIT_MANDI_EMAIL_SENDER,
689
	                            escalationMailSubject, escalationMailBody,
690
	                            null, CRMConstants.PROFIT_MANDI_EMAIL_TYPE, null, null, 1));
691
                    }else{
692
                    	activity.setUserEmailId(helperClient.saveUserEmailForSending(
693
    	                        Arrays.asList(customerEmailId), CRMConstants.CRM_EMAIL_SENDOR,
694
    	                        subject, body, null, CRMConstants.CRM_EMAIL_TYPE, null, null, 1));
695
                    }
4020 mandeep.dh 696
 
16244 manish.sha 697
                    // We change activityType to OTHER when pop up box for email
698
                    // closes
699
                    activity.setDescription("To: " + toMailIds + "\n\nSubject: " + escalationMailSubject + "\n\n"
700
                            + "Body: " + escalationMailBody);
701
                }else{
702
	                EscalationMatrix escalation = CRMConstants.EscalationMatrix.valueOf(escalate);
703
	                List<Integer> escalationReceipients = escalation.getAgentIds();
704
 
705
	                List<String> toMailIds = new ArrayList<String>();
706
	                for (Integer agentId : escalationReceipients) {
707
	                    toMailIds.add(CRMAuthorizingRealm.getAgent(agentId).getEmailId());
708
 
709
	                    // Setting last agent as assignee
710
	                    ticket.setAssigneeId(agentId);
711
	                    activity.setTicketAssigneeId(agentId);
712
	                }
713
 
714
	                Client helperClient = new HelperClient().getClient();
715
	                String escalationMailSubject = createEscalationMailSubject(ticket, escalation);
716
	                String escalationMailBody = createEscalationMailBody(ticket);
4020 mandeep.dh 717
 
16244 manish.sha 718
	                activity.setUserEmailId(helperClient.saveUserEmailForSending(
719
	                        toMailIds, CRMConstants.CRM_EMAIL_SENDOR,
720
	                        escalationMailSubject, escalationMailBody,
721
	                        null, CRMConstants.CRM_EMAIL_TYPE, null, null, 1));
722
 
723
	                // We change activityType to OTHER when pop up box for email
724
	                // closes
725
	                activity.setDescription("To: " + toMailIds + "\n\nSubject: " + escalationMailSubject + "\n\n"
726
	                        + "Body: " + escalationMailBody);
727
                }
4020 mandeep.dh 728
            }
17196 manish.sha 729
            if(isProfitMandiAgent()){
730
	            try{
731
	    	        if (ActivityType.RECEIVED_CALL_FROM_CUSTOMER.equals(activity.getType())) {
732
 
733
	    	        	commonDescription = "Received Call From Customer || Email Id- ";
734
		        		if (customerEmailId != null && !customerEmailId.isEmpty()) {
735
		        			commonDescription = commonDescription+customerEmailId;
736
		        		}
737
		        		if(customerMobileNumber != null
738
		                        && !customerMobileNumber.isEmpty()) {
739
		        			commonDescription = commonDescription+" & Mobile No:- "+customerMobileNumber;
740
		        		}
17198 manish.sha 741
		        		commonDescription = "PM Ticket: "+ commonDescription; 
17196 manish.sha 742
		        		sendMailtoManagersUsingGmailUtils(commonDescription, addTo, description);
743
	    	        }
744
	            }
745
	    	    catch(Exception e){
746
	    	    	e.printStackTrace();
747
	    	    	try{
748
	    	    		sendMailToManagers(commonDescription, addTo, description);
749
	    	    	}
750
	    	    	catch(Exception e1){
751
	    	    		e1.printStackTrace();
752
	    	    	}
753
	    	    }
17080 manish.sha 754
            }
4020 mandeep.dh 755
 
3405 mandeep.dh 756
            User user = null;
757
            userContextServiceClient = new UserClient().getClient();
758
            try {
759
                if (customerName != null && !customerName.isEmpty()) {
760
                    ticket.setCustomerName(customerName);
761
                    activity.setCustomerName(customerName);
762
                }
763
 
764
                if (customerEmailId != null && !customerEmailId.isEmpty()) {
765
                    ticket.setCustomerEmailId(customerEmailId);
766
                    activity.setCustomerEmailId(customerEmailId);
3546 mandeep.dh 767
                    user = userContextServiceClient
768
                            .getUserByEmail(customerEmailId);
3405 mandeep.dh 769
                }
770
 
3546 mandeep.dh 771
                if ((user == null || user.getUserId() == -1)
772
                        && customerMobileNumber != null
773
                        && !customerMobileNumber.isEmpty()) {
3405 mandeep.dh 774
                    ticket.setCustomerMobileNumber(customerMobileNumber);
775
                    activity.setCustomerMobileNumber(customerMobileNumber);
3546 mandeep.dh 776
                    user = userContextServiceClient.getUserByMobileNumber(Long
777
                            .parseLong(customerMobileNumber));
3405 mandeep.dh 778
                }
779
            } catch (UserContextException e) {
780
                log.error("Could not fetch user for: " + customerEmailId + " "
781
                        + customerMobileNumber + " " + customerName, e);
782
            }
3546 mandeep.dh 783
 
3405 mandeep.dh 784
            if (user != null && user.getUserId() != -1) {
785
                ticket.setCustomerId(user.getUserId());
786
                activity.setCustomerId(user.getUserId());
787
            }
788
 
789
            crmServiceClient = new CRMClient().getClient();
790
            crmServiceClient.updateTicket(ticket, activity);
20152 aman.kumar 791
 
792
            if(getDisposition()!=null&&!Actionable.NO_ACTION.toString().equals(getDisposition())){
793
            	if(Actionable.EMAIL_PROVIDER_REATTEMPT_DELIVERY.toString().equals(getDisposition())){
794
            TransactionClient transactionServiceClient = new TransactionClient();
795
 
796
            Order order = transactionServiceClient.getClient().getOrder(ticket.getOrderId());
797
            CRMConstants.LogisticProvider lgp = CRMConstants.LogisticProvider.findByValue(order.getLogistics_provider_id());
798
 
799
            List<String> emailDetails = CRMConstants.LOGISTIC_PROVIDER_MAP.get(lgp);
800
            if(emailDetails!=null){
801
            	String to[] = emailDetails.get(0).split(",");
802
            	String cc[] = emailDetails.get(1).split(",");
803
            	String awb = order.getAirwaybill_no();
804
            	String subject = "Arrange the delivery on priority - "+awb;
805
            	String masterOrderId = order.getLogisticsTransactionId();
806
            	String emailBody = "Hi,\n\nPlease find the below shipment details as customer is ready "
807
            			+ "to take delivery. So please arrange the delivery on priority.\n\nOrder "
808
            			+ "details: Master Order Id:- "+masterOrderId+"\n\nAirway Bill No : "+awb+
20307 amit.gupta 809
            			"\nLogitics Provider : "+lgp.toString()+"\n\nRegards,\nRitesh Chauhan\nHotspot Sales "
20152 aman.kumar 810
            					+ "& Solution Pvt Ltd.\nContact-: +91-8826003137, 0120-3859501";
811
 
812
 
813
 
814
            	//send mail
815
            	log.info("Sending delivery attempt mail to logistic provider :- "+to[0]);
816
 
817
            	GmailUtils mailer = new GmailUtils();
818
            	mailer.sendSSLMessage(to,cc, subject, emailBody, CRMConstants.ADWORDS_EMAIL, 
819
            			CRMConstants.ADWORDS_PASSWORD, new ArrayList<File>());
820
        		log.info("Mail sent to logistic provider:- "+to[0]+" "+cc[0]);
821
 
822
 
823
            }
824
            	}
825
            }
3405 mandeep.dh 826
        } catch (TException e) {
827
            log.error("Error while updating ticket", e);
828
            return EXCEPTION;
829
        } catch (HelperServiceException hse) {
830
            log.error("Error while sending mail", hse);
831
            return EXCEPTION;
20152 aman.kumar 832
        } catch (TransactionServiceException e) {
833
        	log.error("Error while fetching order details", e);
834
            return EXCEPTION;
835
		} catch (MessagingException e) {
836
			// TODO Auto-generated catch block
837
			e.printStackTrace();
838
		}
3405 mandeep.dh 839
 
14882 manish.sha 840
        return INDEX;
3405 mandeep.dh 841
    }
842
 
16244 manish.sha 843
    private String createEscalationMailBody(Ticket ticket)
4020 mandeep.dh 844
    {
845
        return body + "<br />Please visit following URL to check ticket details.<br />" + 
846
            "http://cs.shop2020.in:8080/crm?ticketId=" + ticket.getId();
847
    }
848
 
849
    private String createEscalationMailSubject(Ticket ticket,
850
            EscalationMatrix escalation)
851
    {
852
        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId() + " - ESCALATION FROM CRM - Type: " + escalation.name();
853
    }
16244 manish.sha 854
 
855
    private String createPMEscalationMailSubject(Ticket ticket,
856
            PMEscalationMatrix escalation)
857
    {
858
        return CRMConstants.PROFIT_MANDI_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId() + " - ESCALATION FROM CRM - Type: " + escalation.name();
859
    }
4020 mandeep.dh 860
 
3546 mandeep.dh 861
    private boolean pendingCODOrders(long customerId) {
862
        try {
863
            log.info("Trying to fetch orders for " + customerId);
864
            transactionServiceClient = new TransactionClient().getClient();
865
            for (Order order : transactionServiceClient.getOrdersForCustomer(
866
                    customerId, 0, 0,
4663 rajveer 867
                    Collections.singletonList(OrderStatus.COD_VERIFICATION_PENDING))) {
3546 mandeep.dh 868
                log.info("Processing order: " + order.getId() + " with COD: " + order.isCod());
869
                if (order.isCod()) {
870
                    log.info("Returning true from pendingCODOrders() for " + customerId);
871
                    return true;
872
                }
873
            }
874
        } catch (TTransportException e) {
875
            log.error("Error while creating thrift client", e);
876
        } catch (TransactionServiceException e) {
877
            log.error("Error fetching orders", e);
878
        } catch (TException e) {
879
            log.error("Error fetching orders", e);
880
        }
881
 
882
        log.info("Returning false from pendingCODOrders() for " + customerId);
883
        return false;
884
    }
5791 anupam.sin 885
 
886
    public String extendExpiry() {
887
        try {
888
            log.info("order Id = " + orderId);
889
            log.info("pickup : " + pickupExtension);
890
            Attribute newAttribute = new Attribute();
891
            List<Attribute> attributes = new ArrayList<Attribute>();
892
            String extendedBy = "0";
893
            transactionServiceClient = new TransactionClient().getClient();
894
            attributes = transactionServiceClient.getAllAttributesForOrderId(Long.parseLong(orderId));
895
            for (Attribute attribute : attributes) {
896
                if (attribute.getName().equals("pickupExtension")) {
897
                    extendedBy = attribute.getValue();
898
                    break;
899
                }
900
            }
901
            log.info("ATTR = " + attributes);
902
            log.info("1");
903
            if (extendedBy.equals("0")) {
904
                newAttribute.setName("pickupExtension");
905
                newAttribute.setValue(pickupExtension);
906
                attributes.add(newAttribute);
907
                log.info("2");
908
            } else {
909
                Long totalExtension = Long.parseLong(extendedBy) + Long.parseLong(pickupExtension);
910
                for (Attribute attribute : attributes) {
911
                    if (attribute.getName().equals("pickupExtension")) {
912
                        attribute.setValue(totalExtension.toString());
913
                        log.info("3");
914
                    }
915
                }
916
            }
917
            transactionServiceClient = new TransactionClient().getClient();
918
            transactionServiceClient.setOrderAttributes(Long.parseLong(orderId), attributes);
5919 anupam.sin 919
 
920
            SearchFilter searchFilter = new SearchFilter();
921
            searchFilter.setTicketId(Long.parseLong(id));
922
            crmServiceClient = new CRMClient().getClient();
923
            Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
924
 
925
            // Inserting activity
926
            Activity activity = new Activity();
927
            activity.setDescription("Pickup extended by " + pickupExtension
928
                    + " Days.");
929
            activity.setType(ActivityType.OTHER);
930
            activity.setTicketPriority(ticket.getPriority());
931
            activity.setTicketStatus(ticket.getStatus());
932
            activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
933
            activity.setTicketCategory(ticket.getCategory());
934
            activity.setTicketDescription(ticket.getDescription());
935
            activity.setCustomerId(ticket.getCustomerId());
936
            activity.setTicketAssigneeId(ticket.getAssigneeId());
937
 
938
            crmServiceClient = new CRMClient().getClient();
939
            crmServiceClient.updateTicket(ticket, activity);
940
 
5917 anupam.sin 941
            //transactionServiceClient = new TransactionClient().getClient();
942
            //transactionServiceClient.enqueueExpiryExtensionEmail(orderId);
5791 anupam.sin 943
        } catch (NumberFormatException e) {
944
            e.printStackTrace();
945
        } catch (TException e) {
946
            e.printStackTrace();
947
        }
5917 anupam.sin 948
        return edit();
5791 anupam.sin 949
    }
950
 
951
    public String getPickupExpiryDate(long id, long deliveryTimestamp) {
952
        try {
953
            log.info("orderID" + id);
954
            log.info("Delivery Time : " + deliveryTimestamp);
955
            Date deliveryDate = new Date(deliveryTimestamp);
956
            Calendar cal = Calendar.getInstance();
957
            cal.setTime(deliveryDate);
958
 
959
            log.info("Orig Del Date :" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));
960
 
961
            cal.add(Calendar.DATE, 5);
962
 
963
            log.info("After adding 5 days" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));
964
 
965
            transactionServiceClient = new TransactionClient().getClient();
966
            List<Attribute> attributes = new ArrayList<Attribute>();
967
            String extendedBy = "0";
968
            attributes = transactionServiceClient.getAllAttributesForOrderId(id);
969
            for (Attribute attribute : attributes) {
970
                if (attribute.getName().equals("pickupExtension")) {
971
                    extendedBy = attribute.getValue();
972
                }
973
            }
974
            cal.add(Calendar.DATE, Integer.parseInt(extendedBy));
975
 
976
            log.info("Extended by" + extendedBy);
977
 
978
            log.info("Final : " + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));
979
 
980
            SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy");
981
            return SDF.format(cal.getTime());
982
 
983
        } catch (NumberFormatException e) {
984
            e.printStackTrace();
985
        } catch (TException e) {
986
            e.printStackTrace();
987
        }
988
        return "N/A";
989
    }
3546 mandeep.dh 990
 
4277 anupam.sin 991
    public String updateOrderStatus() {
992
        long creatorId;
993
        OrderStatus orderStatusEnum = null;
994
        try {
995
            creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
996
 
997
            if(orderStatus.equals("DENY_CANCEL_REQUEST")) {
998
                transactionServiceClient = new TransactionClient().getClient();
999
                transactionServiceClient.markOrderCancellationRequestDenied(Long.parseLong(orderId));
1000
            } 
3546 mandeep.dh 1001
 
4277 anupam.sin 1002
            else {
3546 mandeep.dh 1003
 
4277 anupam.sin 1004
                orderStatusEnum = OrderStatus.valueOf(orderStatus);
1005
                transactionServiceClient = new TransactionClient().getClient();
3578 mandeep.dh 1006
 
4277 anupam.sin 1007
                if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {
1008
                    transactionServiceClient.verifyOrder(Long.parseLong(orderId));
5348 anupam.sin 1009
                    transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));
4277 anupam.sin 1010
                }
4682 rajveer 1011
                else if (OrderStatus.COD_VERIFICATION_FAILED.equals(orderStatusEnum)) {
4277 anupam.sin 1012
                    transactionServiceClient.refundOrder(Long.parseLong(orderId), currentAgentEmailId, cancelReason);
5348 anupam.sin 1013
                    transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));
4277 anupam.sin 1014
                }
1015
                else if (OrderStatus.CANCEL_REQUEST_CONFIRMED.equals(orderStatusEnum)) {
1016
                    transactionServiceClient.markOrderCancellationRequestConfirmed(Long.parseLong(orderId));
1017
                }
1018
                else {
1019
                    throw new UnsupportedOperationException("Cannot update status of orderId: " + orderId + " to: " + orderStatus);
1020
                }
1021
            }
1022
 
1023
            SearchFilter searchFilter = new SearchFilter();
1024
            searchFilter.setTicketId(Long.parseLong(id));
1025
            crmServiceClient = new CRMClient().getClient();
1026
            Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
3546 mandeep.dh 1027
 
4277 anupam.sin 1028
            // Inserting activity
1029
            Activity activity = new Activity();
1030
            activity.setDescription("Status updated for Order Id: " + orderId
1031
                    + " to " + orderStatus + ", Reason: " + cancelReason + body);
1032
            activity.setType(ActivityType.OTHER);
1033
            activity.setTicketPriority(ticket.getPriority());
1034
            activity.setTicketStatus(ticket.getStatus());
1035
            activity.setCreatorId(creatorId);
1036
            activity.setTicketCategory(ticket.getCategory());
1037
            activity.setTicketDescription(ticket.getDescription());
1038
            activity.setCustomerId(ticket.getCustomerId());
1039
            activity.setTicketAssigneeId(ticket.getAssigneeId());
3546 mandeep.dh 1040
 
4277 anupam.sin 1041
            crmServiceClient = new CRMClient().getClient();
1042
            crmServiceClient.updateTicket(ticket, activity);
3546 mandeep.dh 1043
 
4277 anupam.sin 1044
        } catch (TException e) {
1045
            log.info("Thrift exception", e);
1046
        } catch (NumberFormatException e) {
1047
            log.info("Could not convert to long", e);
1048
        } catch (TransactionServiceException e) {
1049
            log.info("Transaction client exception", e);
1050
        }
1051
 
3546 mandeep.dh 1052
        return edit();
1053
    }
4277 anupam.sin 1054
 
19072 manish.sha 1055
    public String updateTxnStatus() {
1056
    	long creatorId;
1057
        OrderStatus orderStatusEnum = null;
1058
        try {
1059
            creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
1060
 
1061
            orderStatusEnum = OrderStatus.valueOf(orderStatus);
1062
            transactionServiceClient = new TransactionClient().getClient();
1063
 
1064
            if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {
1065
                transactionServiceClient.verifyOrderForTransaction(Long.parseLong(transactionId));
1066
                transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));
1067
            }
1068
            else if (OrderStatus.COD_VERIFICATION_FAILED.equals(orderStatusEnum)) {
1069
                transactionServiceClient.refundTransaction(Long.parseLong(transactionId), currentAgentEmailId, cancelReason);
1070
                transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));
1071
            }
1072
            else {
1073
                throw new UnsupportedOperationException("Cannot update status of transactionId: " + transactionId + " to: " + orderStatus);
1074
            }
1075
 
1076
            SearchFilter searchFilter = new SearchFilter();
1077
            searchFilter.setTicketId(Long.parseLong(id));
1078
            crmServiceClient = new CRMClient().getClient();
1079
            Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1080
 
1081
            // Inserting activity
1082
            Activity activity = new Activity();
1083
            activity.setDescription("Status updated for Transaction Id: " + transactionId
1084
                    + " to " + orderStatus + ", Reason: " + cancelReason + body);
1085
            activity.setType(ActivityType.OTHER);
1086
            activity.setTicketPriority(ticket.getPriority());
1087
            activity.setTicketStatus(ticket.getStatus());
1088
            activity.setCreatorId(creatorId);
1089
            activity.setTicketCategory(ticket.getCategory());
1090
            activity.setTicketDescription(ticket.getDescription());
1091
            activity.setCustomerId(ticket.getCustomerId());
1092
            activity.setTicketAssigneeId(ticket.getAssigneeId());
1093
 
1094
            crmServiceClient = new CRMClient().getClient();
1095
            crmServiceClient.updateTicket(ticket, activity);
1096
 
1097
        } catch (TException e) {
1098
            log.info("Thrift exception", e);
1099
        } catch (NumberFormatException e) {
1100
            log.info("Could not convert to long", e);
1101
        } catch (TransactionServiceException e) {
1102
            log.info("Transaction client exception", e);
1103
        }
1104
 
1105
    	return edit();
1106
    }
1107
 
3137 mandeep.dh 1108
    public User getUser(Long userId) {
1109
        User user = null;
1110
 
1111
        try {
3390 mandeep.dh 1112
            userContextServiceClient = new UserClient().getClient();
3137 mandeep.dh 1113
            user = userContextServiceClient.getUserById(userId);
1114
        } catch (UserContextException e) {
1115
            String errorString = "Could not fetch user for " + userId;
1116
            log.error(errorString, e);
1117
            addActionError(errorString);
1118
        } catch (TException e) {
1119
            String errorString = "Could not create client";
1120
            log.error(errorString, e);
1121
            addActionError(errorString);
1122
        }
1123
 
1124
        return user;
1125
    }
4267 anupam.sin 1126
 
4438 anupam.sin 1127
    public String allowPayment() {
1128
        try {
1129
            log.info("Allowing payment for paymentId = " + paymentId);
1130
            transactionServiceClient = new TransactionClient().getClient();
1131
            transactionServiceClient.markTransactionAsPaymentFlagRemoved(Long.parseLong(transactionId));
1132
            if (id != null && !id.isEmpty()) {
1133
                SearchFilter searchFilter = new SearchFilter();
1134
                crmServiceClient = new CRMClient().getClient();
1135
                searchFilter.setTicketId(Long.parseLong(id));
1136
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1137
                // Inserting activity
1138
                if(ticket != null) {
1139
                    Activity activity = new Activity();
1140
                    activity.setDescription("Flagged Payment allowed");
1141
                    activity.setType(ActivityType.OTHER);
1142
                    activity.setTicketPriority(ticket.getPriority());
1143
                    activity.setTicketStatus(ticket.getStatus());
1144
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
1145
                    activity.setTicketCategory(ticket.getCategory());
1146
                    activity.setTicketDescription(ticket.getDescription());
1147
                    activity.setCustomerId(ticket.getCustomerId());
1148
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
1149
 
1150
                    crmServiceClient = new CRMClient().getClient();
1151
                    crmServiceClient.updateTicket(ticket, activity);
1152
                }
1153
            }
1154
 
1155
        } catch (TException e) {
1156
            log.error("Error while getting tickets", e);
1157
            return EXCEPTION;
1158
        } catch (NumberFormatException e) {
1159
            log.error("Invalid ticket Id", e);
1160
            return EXCEPTION;
1161
        } catch (TransactionServiceException e) {
1162
            log.error("Error while marking transactions as Flag removed", e);
1163
            return EXCEPTION;
1164
        }
4267 anupam.sin 1165
        return edit();
1166
    }
1167
 
4490 anupam.sin 1168
    public String blockPayment() {
4438 anupam.sin 1169
        try {
1170
            log.info("Blocking payment for paymentId = " + paymentId);
1171
            transactionServiceClient = new TransactionClient().getClient();
1172
            transactionServiceClient.refundTransaction(Long.parseLong(transactionId), currentAgentEmailId, "FLAGGED_PAYMENT_CANCELLED");
1173
            if (id != null && !id.isEmpty()) {
1174
                SearchFilter searchFilter = new SearchFilter();
1175
                crmServiceClient = new CRMClient().getClient();
1176
                searchFilter.setTicketId(Long.parseLong(id));
1177
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1178
                // Inserting activity
1179
                if(ticket != null) {
1180
                    Activity activity = new Activity();
1181
                    activity.setDescription("Flagged Payment allowed");
1182
                    activity.setType(ActivityType.OTHER);
1183
                    activity.setTicketPriority(ticket.getPriority());
1184
                    activity.setTicketStatus(ticket.getStatus());
1185
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
1186
                    activity.setTicketCategory(ticket.getCategory());
1187
                    activity.setTicketDescription(ticket.getDescription());
1188
                    activity.setCustomerId(ticket.getCustomerId());
1189
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
1190
 
1191
                    crmServiceClient = new CRMClient().getClient();
1192
                    crmServiceClient.updateTicket(ticket, activity);
1193
                }
1194
            }
1195
 
1196
        } catch (TException e) {
1197
            log.error("Error while getting tickets", e);
1198
            return EXCEPTION;
1199
        } catch (NumberFormatException e) {
1200
            log.error("Invalid ticket Id", e);
1201
            return EXCEPTION;
1202
        } catch (TransactionServiceException e) {
1203
            log.error("Error while allowing flagged payment", e);
1204
            return EXCEPTION;
1205
        }
4267 anupam.sin 1206
        return edit();
1207
    }
4490 anupam.sin 1208
 
1209
    public String authorizeReturn() {
1210
        try {
1211
            log.info("Authorizing OrderId =" + orderId);
7645 anupam.sin 1212
            boolean isReship = false;
1213
            boolean fromStore  = false;
4490 anupam.sin 1214
            transactionServiceClient = new TransactionClient().getClient();
7645 anupam.sin 1215
            if(premises.equals("store")) {
1216
                fromStore = true;
1217
            }
1218
 
1219
            if(closureType.equals("reship")) {
1220
                isReship = true;
1221
            }
1222
            transactionServiceClient.markOrderReturnRequestAuthorized(Long.parseLong(orderId), true, fromStore, isReship);
4490 anupam.sin 1223
            if (id != null && !id.isEmpty()) {
1224
                SearchFilter searchFilter = new SearchFilter();
1225
                crmServiceClient = new CRMClient().getClient();
1226
                searchFilter.setTicketId(Long.parseLong(id));
1227
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1228
                // Inserting activity
1229
                if(ticket != null) {
1230
                    Activity activity = new Activity();
1231
                    activity.setDescription("Return Authorized");
1232
                    activity.setType(ActivityType.OTHER);
1233
                    activity.setTicketPriority(ticket.getPriority());
1234
                    activity.setTicketStatus(ticket.getStatus());
1235
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
1236
                    activity.setTicketCategory(ticket.getCategory());
1237
                    activity.setTicketDescription(ticket.getDescription());
1238
                    activity.setCustomerId(ticket.getCustomerId());
1239
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
3137 mandeep.dh 1240
 
4490 anupam.sin 1241
                    crmServiceClient = new CRMClient().getClient();
1242
                    crmServiceClient.updateTicket(ticket, activity);
1243
                }
1244
            }
1245
 
1246
        } catch (TException e) {
1247
            log.error("Error while getting tickets", e);
1248
            return EXCEPTION;
1249
        } catch (NumberFormatException e) {
1250
            log.error("Invalid ticket Id", e);
1251
            return EXCEPTION;
1252
        } catch (TransactionServiceException e) {
1253
            log.error("Error while authorizing Return", e);
1254
            return EXCEPTION;
1255
        }
1256
        return edit();
1257
    }
1258
 
1259
    public String denyReturn() {
1260
        try {
1261
            log.info("Denying OrderId =" + orderId);
1262
            transactionServiceClient = new TransactionClient().getClient();
7645 anupam.sin 1263
            transactionServiceClient.markOrderReturnRequestAuthorized(Long.parseLong(orderId), false, false, false);
4490 anupam.sin 1264
            if (id != null && !id.isEmpty()) {
1265
                SearchFilter searchFilter = new SearchFilter();
1266
                crmServiceClient = new CRMClient().getClient();
1267
                searchFilter.setTicketId(Long.parseLong(id));
1268
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1269
                // Inserting activity
1270
                if(ticket != null) {
1271
                    Activity activity = new Activity();
1272
                    activity.setDescription("Return Denied");
1273
                    activity.setType(ActivityType.OTHER);
1274
                    activity.setTicketPriority(ticket.getPriority());
1275
                    activity.setTicketStatus(ticket.getStatus());
1276
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
1277
                    activity.setTicketCategory(ticket.getCategory());
1278
                    activity.setTicketDescription(ticket.getDescription());
1279
                    activity.setCustomerId(ticket.getCustomerId());
1280
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
1281
 
1282
                    crmServiceClient = new CRMClient().getClient();
1283
                    crmServiceClient.updateTicket(ticket, activity);
1284
                }
1285
            }
1286
 
1287
        } catch (TException e) {
1288
            log.error("Error while getting tickets", e);
1289
            return EXCEPTION;
1290
        } catch (NumberFormatException e) {
1291
            log.error("Invalid ticket Id", e);
1292
            return EXCEPTION;
1293
        } catch (TransactionServiceException e) {
1294
            log.error("Error while denying Return", e);
1295
            return EXCEPTION;
1296
        }
1297
        return edit();
1298
    }
1299
 
1300
    public String authorizeDOA() {
1301
        try {
1302
            log.info("Authorizing OrderId =" + orderId);
7645 anupam.sin 1303
            boolean isReship = false;
1304
            boolean fromStore  = false;
4490 anupam.sin 1305
            transactionServiceClient = new TransactionClient().getClient();
7645 anupam.sin 1306
            if(premises.equals("store")) {
1307
                fromStore = true;
1308
            }
1309
 
1310
            if(closureType.equals("reship")) {
1311
                isReship = true;
1312
            }
1313
            transactionServiceClient.markOrderDoaRequestAuthorized(Long.parseLong(orderId), true, fromStore, isReship);
4490 anupam.sin 1314
            if (id != null && !id.isEmpty()) {
1315
                SearchFilter searchFilter = new SearchFilter();
1316
                crmServiceClient = new CRMClient().getClient();
1317
                searchFilter.setTicketId(Long.parseLong(id));
1318
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1319
                // Inserting activity
1320
                if(ticket != null) {
1321
                    Activity activity = new Activity();
1322
                    activity.setDescription("DOA Authorized");
1323
                    activity.setType(ActivityType.OTHER);
1324
                    activity.setTicketPriority(ticket.getPriority());
1325
                    activity.setTicketStatus(ticket.getStatus());
1326
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
1327
                    activity.setTicketCategory(ticket.getCategory());
1328
                    activity.setTicketDescription(ticket.getDescription());
1329
                    activity.setCustomerId(ticket.getCustomerId());
1330
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
1331
 
1332
                    crmServiceClient = new CRMClient().getClient();
1333
                    crmServiceClient.updateTicket(ticket, activity);
1334
                }
1335
            }
1336
 
1337
        } catch (TException e) {
1338
            log.error("Error while getting tickets", e);
1339
            return EXCEPTION;
1340
        } catch (NumberFormatException e) {
1341
            log.error("Invalid ticket Id", e);
1342
            return EXCEPTION;
1343
        } catch (TransactionServiceException e) {
1344
            log.error("Error while authorizing DOA", e);
1345
            return EXCEPTION;
1346
        }
1347
        return edit();
1348
    }
1349
 
1350
    public String denyDOA() {
1351
        try {
1352
            log.info("Denying OrderId =" + orderId);
1353
            transactionServiceClient = new TransactionClient().getClient();
7645 anupam.sin 1354
            transactionServiceClient.markOrderDoaRequestAuthorized(Long.parseLong(orderId), false, false, false);
4490 anupam.sin 1355
            if (id != null && !id.isEmpty()) {
1356
                SearchFilter searchFilter = new SearchFilter();
1357
                crmServiceClient = new CRMClient().getClient();
1358
                searchFilter.setTicketId(Long.parseLong(id));
1359
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
1360
                // Inserting activity
1361
                if(ticket != null) {
1362
                    Activity activity = new Activity();
1363
                    activity.setDescription("DOA Denied");
1364
                    activity.setType(ActivityType.OTHER);
1365
                    activity.setTicketPriority(ticket.getPriority());
1366
                    activity.setTicketStatus(ticket.getStatus());
1367
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
1368
                    activity.setTicketCategory(ticket.getCategory());
1369
                    activity.setTicketDescription(ticket.getDescription());
1370
                    activity.setCustomerId(ticket.getCustomerId());
1371
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
1372
 
1373
                    crmServiceClient = new CRMClient().getClient();
1374
                    crmServiceClient.updateTicket(ticket, activity);
1375
                }
1376
            }
1377
 
1378
        } catch (TException e) {
1379
            log.error("Error while getting tickets", e);
1380
            return EXCEPTION;
1381
        } catch (NumberFormatException e) {
1382
            log.error("Invalid ticket Id", e);
1383
            return EXCEPTION;
1384
        } catch (TransactionServiceException e) {
1385
            log.error("Error while denying DOA", e);
1386
            return EXCEPTION;
1387
        }
1388
        return edit();
1389
    }
5407 amar.kumar 1390
 
14882 manish.sha 1391
    public String loadProfitMandiTickets() throws ParseException {
1392
    	try {
1393
            SearchFilter searchFilter = new SearchFilter();
1394
            searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
1395
            searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
1396
            searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
1397
            crmServiceClient = new CRMClient().getClient();
1398
            tickets = new ArrayList<Ticket>();
16244 manish.sha 1399
            searchFilter.setTicketCategoryList(profitMandiTicketCategoryList);
14882 manish.sha 1400
            tickets.addAll(crmServiceClient.getTickets(searchFilter));
1401
        } catch (TException e) {
1402
            String errorString = "Error getting tickets for "
1403
                    + currentAgentEmailId;
1404
            log.error(errorString, e);
1405
            addActionError(errorString);
1406
        }
1407
    	return index();
1408
    }
1409
 
5909 amar.kumar 1410
    public String getAllOpenTickets() {
1411
    	try {
1412
    		ticketCategorycountMap= new HashMap<String, Long>();
1413
            crmServiceClient = new CRMClient().getClient();
1414
            ticketCategorycountMap = crmServiceClient.getOpenTicketsMap();
1415
        } catch (TException e) {
1416
            String errorString = "Error getting tickets for "
1417
                    + currentAgentEmailId;
1418
            log.error(errorString, e);
1419
            addActionError(errorString);
1420
        }
1421
        return OPEN;
1422
    }
1423
 
5407 amar.kumar 1424
    public double getCustomerTrustLevel(long userId) {
1425
    	try {
1426
			userContextServiceClient = new UserClient().getClient();
1427
			return userContextServiceClient.getTrustLevel(userId);
1428
		} catch (TException e) {
1429
			log.info("Exception while getting trustLevel for " +
1430
					"userId " + userId);
1431
		}
1432
		return 0;
1433
    }
4490 anupam.sin 1434
 
4020 mandeep.dh 1435
    public EscalationMatrix[] getEscalationMatrix () {
1436
        return CRMConstants.EscalationMatrix.values();
1437
    }
16244 manish.sha 1438
 
1439
    public PMEscalationMatrix[] getPMEscalationMatrix () {
1440
        return CRMConstants.PMEscalationMatrix.values();
1441
    }
4020 mandeep.dh 1442
 
3546 mandeep.dh 1443
    public String getAddress(Order order) {
1444
        return ModelUtils.extractAddressFromOrder(order);
1445
    }
1446
 
1447
    public String getProductName(LineItem lineItem) {
4008 mandeep.dh 1448
        return ModelUtils.extractProductNameFromLineItem(lineItem) + " " + lineItem.getColor();
3546 mandeep.dh 1449
    }
1450
 
3405 mandeep.dh 1451
    public ActivityType[] getActivityTypes() {
1452
        return ActivityType.values();
1453
    }
1454
 
1455
    public TicketStatus[] getTicketStatuses() {
1456
        return TicketStatus.values();
1457
    }
1458
 
3390 mandeep.dh 1459
    public Agent getAgent(long agentId) throws TException {
1460
        return CRMAuthorizingRealm.getAgent(agentId);
3137 mandeep.dh 1461
    }
1462
 
3339 mandeep.dh 1463
    public List<Agent> getAllAgents() {
16244 manish.sha 1464
    	List<Agent> allagents = CRMAuthorizingRealm.getAgents();
1465
    	List<Agent> requiredAgents = new ArrayList<Agent>();
1466
    	if(isSaholicAndProfitMandiAllowed()){
1467
    		return allagents;
1468
    	} else if(isProfitMandiAgent()){
1469
    		for(Agent agent: allagents){
1470
    			if(agent.isIs_pmCrmUser()){
1471
    				requiredAgents.add(agent);
1472
    			}
1473
    		}
1474
    		return requiredAgents;
1475
    	} else{
1476
    		for(Agent agent: allagents){
1477
    			if(!agent.isIs_pmCrmUser()||agent.isIs_allAssignable()){
1478
    				requiredAgents.add(agent);
1479
    			}
1480
    		}
1481
    		return requiredAgents;
1482
    	}
3339 mandeep.dh 1483
    }
1484
 
16248 manish.sha 1485
    public List<TicketCategory> getTicketCategories() {
1486
    	List<TicketCategory> allCategories = Arrays.asList(TicketCategory.values());
1487
    	List<TicketCategory> requiredCategories = new ArrayList<TicketCategory>();
1488
    	if(isSaholicAndProfitMandiAllowed()){
1489
    		return allCategories;
1490
    	}else if(isProfitMandiAgent()){
1491
    		for(TicketCategory tkCategory: allCategories){
1492
    			if(profitMandiTicketCategoryList.contains(tkCategory)){
1493
    				requiredCategories.add(tkCategory);
1494
    			}
1495
    		}
1496
    		return requiredCategories;
1497
    	}else{
1498
    		for(TicketCategory tkCategory: allCategories){
1499
    			if(!profitMandiTicketCategoryList.contains(tkCategory)){
1500
    				requiredCategories.add(tkCategory);
1501
    			}
1502
    		}
1503
    		return requiredCategories;
1504
    	}
3339 mandeep.dh 1505
    }
16642 manish.sha 1506
 
1507
    private void sendMailToUser() throws SendGridException{
16645 manish.sha 1508
    	log.info("Sending mail to user:- "+customerEmailId);
16642 manish.sha 1509
    	SendGrid sendgrid = new SendGrid("profitmandi", "pma20aug");
1510
		SendGrid.Email email = new SendGrid.Email();
1511
		email.setFrom(CRMConstants.PROFIT_MANDI_EMAIL_SENDER);
1512
		email.setFromName("ProfitMandi");
1513
		email.addTo(customerEmailId);
1514
		email.addBcc("backup@saholic.com");
1515
		email.setSubject(subject);
16655 manish.sha 1516
		email.setHtml(body);
16649 manish.sha 1517
		log.info("Mail Body:- "+body);
16650 manish.sha 1518
		sendgrid.send(email);
1519
		log.info("Mail sent to user:- "+customerEmailId);
16642 manish.sha 1520
    }
17080 manish.sha 1521
 
1522
    private void sendMailToManagers(String subject, String[] addTo, String body) throws SendGridException{
1523
    	SendGrid sendgrid = new SendGrid("profitmandi", "pma20aug");
1524
		SendGrid.Email email = new SendGrid.Email();
1525
		email.setFrom(CRMConstants.PROFIT_MANDI_EMAIL_SENDER);
1526
		email.setFromName("ProfitMandi");
1527
		email.addTo(addTo);
1528
		email.addBcc("backup@saholic.com");
1529
		email.setSubject(subject);
1530
		email.setHtml(body);
1531
		log.info("Mail Body:- "+body);
1532
		sendgrid.send(email);
1533
		log.info("Mail sent to user:- "+addTo);
1534
    }
17083 manish.sha 1535
 
1536
    public void sendMailtoManagersUsingGmailUtils(String subject, String[] addTo, String body) throws MessagingException{
1537
    	GmailUtils mailer = new GmailUtils();
1538
		mailer.sendSSLMessage(addTo, subject, body, "build-staging@shop2020.in", "shop2020", new ArrayList<File>());
1539
    }
3339 mandeep.dh 1540
 
1541
    public TicketPriority[] getTicketPriorities() {
1542
        return TicketPriority.values();
1543
    }
1544
 
3137 mandeep.dh 1545
    public List<Ticket> getTickets() {
1546
        return tickets;
1547
    }
1548
 
1549
    public void setTickets(List<Ticket> tickets) {
1550
        this.tickets = tickets;
1551
    }
3339 mandeep.dh 1552
 
3405 mandeep.dh 1553
    public String getCustomerEmailId() {
1554
        return customerEmailId;
3339 mandeep.dh 1555
    }
1556
 
3405 mandeep.dh 1557
    public void setCustomerEmailId(String customerEmailId) {
1558
        this.customerEmailId = customerEmailId;
3339 mandeep.dh 1559
    }
1560
 
1561
    public String getDescription() {
1562
        return description;
1563
    }
1564
 
1565
    public void setDescription(String description) {
1566
        this.description = description;
1567
    }
1568
 
1569
    public String getAssigneeEmailId() {
1570
        return assigneeEmailId;
1571
    }
1572
 
1573
    public void setAssigneeEmailId(String assigneeEmailId) {
1574
        this.assigneeEmailId = assigneeEmailId;
1575
    }
1576
 
1577
    public String getPriority() {
1578
        return priority;
1579
    }
1580
 
1581
    public void setPriority(String priority) {
1582
        this.priority = priority;
1583
    }
1584
 
1585
    public String getCategory() {
1586
        return category;
1587
    }
1588
 
1589
    public void setCategory(String category) {
1590
        this.category = category;
1591
    }
1592
 
1593
    public String getOrderId() {
1594
        return orderId;
1595
    }
1596
 
1597
    public void setOrderId(String orderId) {
1598
        this.orderId = orderId;
1599
    }
3397 mandeep.dh 1600
 
1601
    public String[] getAgentIds() {
1602
        return agentIds;
1603
    }
1604
 
1605
    public void setAgentIds(String[] agentIds) {
1606
        this.agentIds = agentIds;
1607
    }
1608
 
1609
    public String getStartTimestamp() {
1610
        return startTimestamp;
1611
    }
1612
 
1613
    public void setStartTimestamp(String startTimestamp) {
1614
        this.startTimestamp = startTimestamp;
1615
    }
1616
 
1617
    public String getEndTimestamp() {
1618
        return endTimestamp;
1619
    }
1620
 
1621
    public void setEndTimestamp(String endTimestamp) {
1622
        this.endTimestamp = endTimestamp;
1623
    }
3405 mandeep.dh 1624
 
1625
    public String getUserId() {
1626
        return userId;
1627
    }
1628
 
1629
    public void setUserId(String userId) {
1630
        this.userId = userId;
1631
    }
1632
 
1633
    public String getId() {
1634
        return id;
1635
    }
1636
 
1637
    public void setId(String id) {
1638
        this.id = id;
1639
    }
1640
 
1641
    public String getActivityDescription() {
1642
        return activityDescription;
1643
    }
1644
 
1645
    public void setActivityDescription(String activityDescription) {
1646
        this.activityDescription = activityDescription;
1647
    }
1648
 
1649
    public String getStatus() {
1650
        return status;
1651
    }
1652
 
1653
    public void setStatus(String status) {
1654
        this.status = status;
1655
    }
1656
 
1657
    public String getActivityType() {
1658
        return activityType;
1659
    }
1660
 
1661
    public void setActivityType(String activityType) {
1662
        this.activityType = activityType;
1663
    }
1664
 
1665
    public Ticket getTicket() {
1666
        return ticket;
1667
    }
1668
 
1669
    public void setTicket(Ticket ticket) {
1670
        this.ticket = ticket;
1671
    }
1672
 
1673
    public List<Activity> getActivities() {
1674
        return activities;
1675
    }
1676
 
1677
    public void setActivities(List<Activity> activities) {
1678
        this.activities = activities;
1679
    }
1680
 
1681
    public String getSubject() {
1682
        return subject;
1683
    }
1684
 
1685
    public void setSubject(String subject) {
1686
        this.subject = subject;
1687
    }
1688
 
1689
    public String getBody() {
1690
        return body;
1691
    }
1692
 
1693
    public void setBody(String body) {
1694
        this.body = body;
1695
    }
1696
 
1697
    public String getCustomerName() {
1698
        return customerName;
1699
    }
1700
 
1701
    public void setCustomerName(String customerName) {
1702
        this.customerName = customerName;
1703
    }
1704
 
1705
    public String getCustomerMobileNumber() {
1706
        return customerMobileNumber;
1707
    }
1708
 
1709
    public void setCustomerMobileNumber(String customerMobileNumber) {
1710
        this.customerMobileNumber = customerMobileNumber;
1711
    }
3546 mandeep.dh 1712
 
1713
    public User getUser() {
1714
        return user;
1715
    }
1716
 
1717
    public void setUser(User user) {
1718
        this.user = user;
1719
    }
1720
 
1721
    public String getOrderStatus() {
1722
        return orderStatus;
1723
    }
1724
 
1725
    public void setOrderStatus(String orderStatus) {
1726
        this.orderStatus = orderStatus;
1727
    }
1728
 
1729
    public List<Order> getOrders() {
1730
        return orders;
1731
    }
1732
 
1733
    public void setOrders(List<Order> orders) {
1734
        this.orders = orders;
1735
    }
4020 mandeep.dh 1736
 
1737
    public String getEscalate() {
1738
        return escalate;
1739
    }
1740
 
1741
    public void setEscalate(String escalate) {
1742
        this.escalate = escalate;
1743
    }
4241 anupam.sin 1744
 
1745
    public String getCancelReason() {
1746
        return cancelReason;
1747
    }
1748
 
1749
    public void setCancelReason(String cancelReason) {
1750
        this.cancelReason = cancelReason;
1751
    }
4267 anupam.sin 1752
 
1753
    public List<Payment> getPayments() {
1754
        return payments;
1755
    }
1756
 
1757
    public void setPayments(List<Payment> payments) {
1758
        this.payments = payments;
1759
    }
1760
 
1761
    public String getTransactionId() {
1762
        return transactionId;
1763
    }
1764
 
1765
    public void setTransactionId(String transactionId) {
1766
        this.transactionId = transactionId;
1767
    }
4438 anupam.sin 1768
 
1769
    public String getPaymentId() {
1770
        return paymentId;
1771
    }
1772
 
1773
    public void setPaymentId(String paymentId) {
1774
        this.paymentId = paymentId;
1775
    }
4490 anupam.sin 1776
 
1777
    public HashMap<String, String> getAllAttachmentsForTicket() {
1778
        return allAttachmentsForTicket;
1779
    }
1780
 
1781
    public void setAllAttachmentsForTicket(HashMap<String, String> allAttachmentsForTicket) {
1782
        this.allAttachmentsForTicket = allAttachmentsForTicket;
1783
    }
5791 anupam.sin 1784
 
1785
    public String getPickupExtension() {
1786
        return pickupExtension;
1787
    }
1788
 
1789
    public void setPickupExtension(String pickupExtension) {
1790
        this.pickupExtension = pickupExtension;
1791
    }
5909 amar.kumar 1792
 
1793
	public Map<String, Long> getTicketCategorycountMap() {
1794
		return ticketCategorycountMap;
1795
	}
1796
 
1797
	public void setTicketCategorycountMap(
1798
			Map<String, Long> ticketCategorycountMap) {
1799
		this.ticketCategorycountMap = ticketCategorycountMap;
1800
	}
7645 anupam.sin 1801
 
1802
    public String getPremises() {
1803
        return premises;
1804
    }
1805
 
1806
    public void setPremises(String premises) {
1807
        this.premises = premises;
1808
    }
1809
 
1810
    public String getClosureType() {
1811
        return closureType;
1812
    }
1813
 
1814
    public void setClosureType(String closureType) {
1815
        this.closureType = closureType;
1816
    }
19072 manish.sha 1817
 
1818
 
1819
	public String getQuantity() {
1820
		return quantity;
1821
	}
1822
 
1823
	public void setQuantity(String quantity) {
1824
		this.quantity = quantity;
1825
	}
1826
 
18341 amit.gupta 1827
 
1828
    public Map<Long, Order> getTransactions() {
1829
		return transactions;
1830
	}
1831
 
1832
	public void setTransactions(Map<Long, Order> transactions) {
1833
		this.transactions = transactions;
1834
	}
1835
 
18342 amit.gupta 1836
	public Map<Long, Long> getTransactionShipping() {
18341 amit.gupta 1837
		return transactionShipping;
1838
	}
1839
 
18342 amit.gupta 1840
	public void setTransactionShipping(Map<Long, Long> transactionShipping) {
18341 amit.gupta 1841
		this.transactionShipping = transactionShipping;
1842
	}
1843
 
18342 amit.gupta 1844
	public Map<Long, Long> getTransactionTotal() {
18341 amit.gupta 1845
		return transactionTotal;
1846
	}
1847
 
18342 amit.gupta 1848
	public void setTransactionTotal(Map<Long, Long> transactionTotal) {
18341 amit.gupta 1849
		this.transactionTotal = transactionTotal;
1850
	}
20152 aman.kumar 1851
 
1852
	public String getDisposition() {
1853
		return disposition;
1854
	}
1855
 
1856
	public void setDisposition(String disposition) {
1857
		this.disposition = disposition;
1858
	}
1859
 
1860
	public List<String> getActionable() {
1861
		return actionable;
1862
	}
1863
 
1864
	public void setActionable(List<String> actionable) {
1865
		this.actionable = actionable;
1866
	}
1867
 
1868
	public void setSuitableActionable(TicketCategory ticketCategory){
1869
		this.actionable = CRMConstants.CATEGORY_ACTION_MAP.get(ticketCategory);
1870
	}
1871
 
3137 mandeep.dh 1872
}