Subversion Repositories SmartDukaan

Rev

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