Subversion Repositories SmartDukaan

Rev

Rev 5407 | Rev 5865 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5407 Rev 5791
Line 9... Line 9...
9
import in.shop2020.crm.SearchFilter;
9
import in.shop2020.crm.SearchFilter;
10
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.Ticket;
11
import in.shop2020.crm.TicketCategory;
11
import in.shop2020.crm.TicketCategory;
12
import in.shop2020.crm.TicketPriority;
12
import in.shop2020.crm.TicketPriority;
13
import in.shop2020.crm.TicketStatus;
13
import in.shop2020.crm.TicketStatus;
-
 
14
import in.shop2020.model.v1.order.Attribute;
14
import in.shop2020.model.v1.order.LineItem;
15
import in.shop2020.model.v1.order.LineItem;
15
import in.shop2020.model.v1.order.Order;
16
import in.shop2020.model.v1.order.Order;
16
import in.shop2020.model.v1.order.OrderStatus;
17
import in.shop2020.model.v1.order.OrderStatus;
17
import in.shop2020.model.v1.order.Transaction;
18
import in.shop2020.model.v1.order.Transaction;
18
import in.shop2020.model.v1.order.TransactionServiceException;
19
import in.shop2020.model.v1.order.TransactionServiceException;
Line 32... Line 33...
32
import in.shop2020.util.CRMConstants.EscalationMatrix;
33
import in.shop2020.util.CRMConstants.EscalationMatrix;
33
import in.shop2020.utils.HelperService.Client;
34
import in.shop2020.utils.HelperService.Client;
34
import in.shop2020.utils.HelperServiceException;
35
import in.shop2020.utils.HelperServiceException;
35
import in.shop2020.utils.ModelUtils;
36
import in.shop2020.utils.ModelUtils;
36
 
37
 
-
 
38
import java.text.DateFormat;
37
import java.text.ParseException;
39
import java.text.ParseException;
-
 
40
import java.text.SimpleDateFormat;
38
import java.util.ArrayList;
41
import java.util.ArrayList;
-
 
42
import java.util.Arrays;
39
import java.util.Calendar;
43
import java.util.Calendar;
40
import java.util.Collections;
44
import java.util.Collections;
41
import java.util.Date;
45
import java.util.Date;
42
import java.util.HashMap;
46
import java.util.HashMap;
43
import java.util.List;
47
import java.util.List;
-
 
48
import java.util.TimeZone;
44
 
49
 
45
import net.htmlparser.jericho.Source;
50
import net.htmlparser.jericho.Source;
46
 
51
 
47
import org.apache.shiro.SecurityUtils;
52
import org.apache.shiro.SecurityUtils;
48
import org.apache.thrift.TException;
53
import org.apache.thrift.TException;
Line 86... Line 91...
86
    private List<Order>       orders;
91
    private List<Order>       orders;
87
    private List<Payment>     payments;
92
    private List<Payment>     payments;
88
    private String            escalate;
93
    private String            escalate;
89
    private String            cancelReason;
94
    private String            cancelReason;
90
    private String            transactionId;
95
    private String            transactionId;
-
 
96
    private String            pickupExtension;
91
 
97
 
92
    private String paymentId;
98
    private String paymentId;
93
 
99
 
94
    private HashMap<String, String> allAttachmentsForTicket;
100
    private HashMap<String, String> allAttachmentsForTicket;
95
 
101
 
Line 230... Line 236...
230
                    if (order.getExpected_delivery_time() > order.getPromised_delivery_time() && order.getExpected_delivery_time() > new Date().getTime()) {
236
                    if (order.getExpected_delivery_time() > order.getPromised_delivery_time() && order.getExpected_delivery_time() > new Date().getTime()) {
231
                        orders.add(order);
237
                        orders.add(order);
232
                    }
238
                    }
233
                }
239
                }
234
            }
240
            }
-
 
241
            
-
 
242
            if (TicketCategory.STORE_PICKUP.equals(ticket.getCategory())) {
-
 
243
                log.info("Fetching orders for " + ticket.getCustomerId());
-
 
244
                orders = new ArrayList<Order>();
-
 
245
                transactionServiceClient = new TransactionClient().getClient();
-
 
246
                for (Order order : transactionServiceClient
-
 
247
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
-
 
248
                                Collections.singletonList(OrderStatus.RECEIVED_AT_STORE))) {
-
 
249
                    log.info("Processing Order: " + order.getId());
-
 
250
                    orders.add(order);
-
 
251
                }
-
 
252
            }
-
 
253
            
235
        } catch (TException e) {
254
        } catch (TException e) {
236
            log.error("Error loading edit page", e);
255
            log.error("Error loading edit page", e);
237
        } catch (NumberFormatException e) {
256
        } catch (NumberFormatException e) {
238
            log.error("Error parsing orderId", e);
257
            log.error("Error parsing orderId", e);
239
        } catch (TransactionServiceException e) {
258
        } catch (TransactionServiceException e) {
Line 261... Line 280...
261
                }
280
                }
262
            }
281
            }
263
        }
282
        }
264
    }
283
    }
265
    
284
    
266
    public static void main(String[] args) {
285
    public static void main(String[] args) throws TException {
267
        TicketsController tc = new TicketsController();
286
        SearchFilter s = new SearchFilter();
268
        Integer i = new Integer(14215);
287
//      s.setTicketId(200l);
269
        tc.id = i.toString();
288
//      s.setTicketAssigneeIds(null);
-
 
289
//      s.setTicketAssigneeIds(new ArrayList<Long>());
-
 
290
//      s.setActivityCreatorIds(Collections.singletonList(2l));
270
        tc.populateAttachments();
291
//      s.setEndTimestamp(new Date());
-
 
292
      //s.setTicketCategory(TicketCategory.STORE_PICKUP);
-
 
293
      s.setTicketId((long) 51345);
-
 
294
      in.shop2020.crm.CRMService.Client crmServiceClient = new CRMClient().getClient();
-
 
295
      Ticket ticket = crmServiceClient.getTickets(s).get(0);
-
 
296
      System.out.println(ticket.getCategory().name());
271
    }
297
    }
272
 
298
 
273
    private String createSubjectString(Ticket ticket) {
299
    private String createSubjectString(Ticket ticket) {
274
        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
300
        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
275
                + " " + ticket.getCategory().name();
301
                + " " + ticket.getCategory().name();
Line 663... Line 689...
663
        }
689
        }
664
 
690
 
665
        log.info("Returning false from pendingCODOrders() for " + customerId);
691
        log.info("Returning false from pendingCODOrders() for " + customerId);
666
        return false;
692
        return false;
667
    }
693
    }
-
 
694
    
-
 
695
    public String extendExpiry() {
-
 
696
        try {
-
 
697
            log.info("order Id = " + orderId);
-
 
698
            log.info("pickup : " + pickupExtension);
-
 
699
            Attribute newAttribute = new Attribute();
-
 
700
            List<Attribute> attributes = new ArrayList<Attribute>();
-
 
701
            String extendedBy = "0";
-
 
702
            transactionServiceClient = new TransactionClient().getClient();
-
 
703
            attributes = transactionServiceClient.getAllAttributesForOrderId(Long.parseLong(orderId));
-
 
704
            for (Attribute attribute : attributes) {
-
 
705
                if (attribute.getName().equals("pickupExtension")) {
-
 
706
                    extendedBy = attribute.getValue();
-
 
707
                    break;
-
 
708
                }
-
 
709
            }
-
 
710
            log.info("ATTR = " + attributes);
-
 
711
            log.info("1");
-
 
712
            if (extendedBy.equals("0")) {
-
 
713
                newAttribute.setName("pickupExtension");
-
 
714
                newAttribute.setValue(pickupExtension);
-
 
715
                attributes.add(newAttribute);
-
 
716
                log.info("2");
-
 
717
            } else {
-
 
718
                Long totalExtension = Long.parseLong(extendedBy) + Long.parseLong(pickupExtension);
-
 
719
                for (Attribute attribute : attributes) {
-
 
720
                    if (attribute.getName().equals("pickupExtension")) {
-
 
721
                        attribute.setValue(totalExtension.toString());
-
 
722
                        log.info("3");
-
 
723
                    }
-
 
724
                }
-
 
725
            }
-
 
726
            transactionServiceClient = new TransactionClient().getClient();
-
 
727
            transactionServiceClient.setOrderAttributes(Long.parseLong(orderId), attributes);
-
 
728
        } catch (NumberFormatException e) {
-
 
729
            e.printStackTrace();
-
 
730
        } catch (TException e) {
-
 
731
            e.printStackTrace();
-
 
732
        }
-
 
733
        return EDIT;
-
 
734
    }
-
 
735
    
-
 
736
    public String getPickupExpiryDate(long id, long deliveryTimestamp) {
-
 
737
        try {
-
 
738
            log.info("orderID" + id);
-
 
739
            log.info("Delivery Time : " + deliveryTimestamp);
-
 
740
            Date deliveryDate = new Date(deliveryTimestamp);
-
 
741
            Calendar cal = Calendar.getInstance();
-
 
742
            cal.setTime(deliveryDate);
-
 
743
            
-
 
744
            log.info("Orig Del Date :" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));
-
 
745
            
-
 
746
            cal.add(Calendar.DATE, 5);
-
 
747
            
-
 
748
            log.info("After adding 5 days" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));
-
 
749
            
-
 
750
            transactionServiceClient = new TransactionClient().getClient();
-
 
751
            List<Attribute> attributes = new ArrayList<Attribute>();
-
 
752
            String extendedBy = "0";
-
 
753
            attributes = transactionServiceClient.getAllAttributesForOrderId(id);
-
 
754
            for (Attribute attribute : attributes) {
-
 
755
                if (attribute.getName().equals("pickupExtension")) {
-
 
756
                    extendedBy = attribute.getValue();
-
 
757
                }
-
 
758
            }
-
 
759
            cal.add(Calendar.DATE, Integer.parseInt(extendedBy));
-
 
760
            
-
 
761
            log.info("Extended by" + extendedBy);
-
 
762
            
-
 
763
            log.info("Final : " + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));
-
 
764
            
-
 
765
            SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy");
-
 
766
            return SDF.format(cal.getTime());
-
 
767
            
-
 
768
        } catch (NumberFormatException e) {
-
 
769
            e.printStackTrace();
-
 
770
        } catch (TException e) {
-
 
771
            e.printStackTrace();
-
 
772
        }
-
 
773
        return "N/A";
-
 
774
    }
668
 
775
 
669
    public String updateOrderStatus() {
776
    public String updateOrderStatus() {
670
        long creatorId;
777
        long creatorId;
671
        OrderStatus orderStatusEnum = null;
778
        OrderStatus orderStatusEnum = null;
672
        try {
779
        try {
Line 1279... Line 1386...
1279
    }
1386
    }
1280
 
1387
 
1281
    public void setAllAttachmentsForTicket(HashMap<String, String> allAttachmentsForTicket) {
1388
    public void setAllAttachmentsForTicket(HashMap<String, String> allAttachmentsForTicket) {
1282
        this.allAttachmentsForTicket = allAttachmentsForTicket;
1389
        this.allAttachmentsForTicket = allAttachmentsForTicket;
1283
    }
1390
    }
-
 
1391
 
-
 
1392
    public String getPickupExtension() {
-
 
1393
        return pickupExtension;
-
 
1394
    }
-
 
1395
 
-
 
1396
    public void setPickupExtension(String pickupExtension) {
-
 
1397
        this.pickupExtension = pickupExtension;
-
 
1398
    }
1284
}
1399
}