Subversion Repositories SmartDukaan

Rev

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

Rev 19690 Rev 20776
Line 61... Line 61...
61
	private static long GREEN_AND_IN_RED_OR_WHITE = 3L;
61
	private static long GREEN_AND_IN_RED_OR_WHITE = 3L;
62
	private static long ALL_RED = 4L;
62
	private static long ALL_RED = 4L;
63
	private static long ALL_PURPLE = 5L;
63
	private static long ALL_PURPLE = 5L;
64
	private static long PURPLE_AND_IN_RED_OR_WHITE = 6L;
64
	private static long PURPLE_AND_IN_RED_OR_WHITE = 6L;
65
	private static long ALL_OTHERS = 7L;
65
	private static long ALL_OTHERS = 7L;
66
	private static int categoryOrderCount = 0;
66
	private static int categoryOrderCount = 0; 
-
 
67
	private static SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
-
 
68
	private static SimpleDateFormat newSdf = new SimpleDateFormat("yyyy-MM-dd");
-
 
69
	private static NumberFormat formatter = new DecimalFormat("#0.000");
-
 
70
	private static NumberFormat rformatter = new DecimalFormat("#0.00");
-
 
71
	
-
 
72
	private static  Map<Long, in.shop2020.logistics.Provider> getProvidersMap() {
-
 
73
		if(providersMap==null){
-
 
74
			try {
-
 
75
				in.shop2020.logistics.LogisticsService.Client logisticsClient = new LogisticsClient().getClient();
-
 
76
				List<in.shop2020.logistics.Provider> providers = logisticsClient.getAllProviders();
-
 
77
				providersMap = new HashMap<Long, in.shop2020.logistics.Provider>();
-
 
78
			
-
 
79
				for(in.shop2020.logistics.Provider provider : providers){
-
 
80
					providersMap.put(provider.getId(), provider);
-
 
81
				}
-
 
82
			}catch (Exception e) {
-
 
83
				e.printStackTrace();
-
 
84
			}
-
 
85
		}
-
 
86
		return providersMap;
-
 
87
	}
-
 
88
	
-
 
89
	private static Map<Long, in.shop2020.logistics.Provider> providersMap = null;
67
	
90
	
68
	
91
	
69
	private static Map<Long, OrderCategory> categoryStrMap = new HashMap<Long, OrderCategory>();
92
	private static Map<Long, OrderCategory> categoryStrMap = new HashMap<Long, OrderCategory>();
70
	
93
	
71
	private static enum ColorCode {
94
	private static enum ColorCode {
Line 97... Line 120...
97
	 * @param offset
120
	 * @param offset
98
	 *            Offset to start from
121
	 *            Offset to start from
99
	 * @param limit
122
	 * @param limit
100
	 *            No. of orders to return
123
	 *            No. of orders to return
101
	 * @param warehouseId
124
	 * @param warehouseId
102
	 *            The warehouse for which the orders should be queried.
125
	 *            The billing warehouse for which the orders should be queried.
103
	 * @return A list of orders of the given type to be fulfilled from the given
126
	 * @return A list of orders of the given type to be fulfilled from the given
104
	 *         warehouse
127
	 *         warehouse
105
	 */
128
	 */
106
	public static List<Order> getOrders(OrderType type, long offset, long limit, long warehouseId, long source, OrderCategory orderCategory){
129
	public static List<Order> getOrders(OrderType type, long offset, long limit, long warehouseId, long source, OrderCategory orderCategory){
107
		List<OrderStatus> statuses = getStatuses(type);
130
		List<OrderStatus> statuses = getStatuses(type);
Line 122... Line 145...
122
				}else{
145
				}else{
123
					t_orders.addAll(client.getOrdersInBatch(statuses, offset, limit, warehouseId, source));
146
					t_orders.addAll(client.getOrdersInBatch(statuses, offset, limit, warehouseId, source));
124
				}
147
				}
125
			}
148
			}
126
			
149
			
127
			orders = getOrdersFromThirftOrders(t_orders);
150
			orders = getOrdersFromThirftOrders(t_orders, warehouseId);
128
			/*for (in.shop2020.model.v1.order.Order t_order: t_orders){
151
			/*for (in.shop2020.model.v1.order.Order t_order: t_orders){
129
				Order o = getOrderFromThriftOrder(t_order);
152
				Order o = getOrderFromThriftOrder(t_order);
130
				orders.add(o);
153
				orders.add(o);
131
			}*/
154
			}*/
132
			if(type==OrderType.NEW || type==OrderType.ALL_PENDING || type ==OrderType.LOW_INVENTORY || type == OrderType.PO_RAISED
155
			if(type==OrderType.NEW || type==OrderType.ALL_PENDING || type ==OrderType.LOW_INVENTORY || type == OrderType.PO_RAISED
Line 496... Line 519...
496
		}
519
		}
497
		return true;
520
		return true;
498
	}
521
	}
499
	
522
	
500
	
523
	
501
	public static List<Order> getOrdersFromThirftOrders(List<in.shop2020.model.v1.order.Order> orders){
524
	public static List<Order> getOrdersFromThirftOrders(List<in.shop2020.model.v1.order.Order> orders, Long billingWarehouseId){
502
		List<Order> ordersToReturn = new ArrayList<Order>();
525
		List<Order> ordersToReturn = new ArrayList<Order>();
503
		Map<Long, Warehouse> warehousesMap = CatalogUtils.getAllWarehousesForBillingWarehouse(0); 
526
		Map<Long, Warehouse> warehousesMap = CatalogUtils.getAllWarehousesForBillingWarehouse(billingWarehouseId); 
504
		List<Long> itemIds = new ArrayList<Long>();
527
		List<Long> itemIds = new ArrayList<Long>();
505
		Map<Long, List<in.shop2020.model.v1.order.Order>> txnOrdersMap = new HashMap<Long, List<in.shop2020.model.v1.order.Order>>();
528
		Map<Long, List<in.shop2020.model.v1.order.Order>> txnOrdersMap = new HashMap<Long, List<in.shop2020.model.v1.order.Order>>();
506
		SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
-
 
507
		SimpleDateFormat newSdf = new SimpleDateFormat("yyyy-MM-dd");
-
 
508
		NumberFormat formatter = new DecimalFormat("#0.000");
-
 
509
		NumberFormat rformatter = new DecimalFormat("#0.00");
-
 
-
 
529
		
510
		Date date = new Date(System.currentTimeMillis());
530
		Date date = new Date(System.currentTimeMillis());
511
		for(in.shop2020.model.v1.order.Order t_order : orders){
531
		for(in.shop2020.model.v1.order.Order t_order : orders){
512
			if(!itemIds.contains(t_order.getLineitems().get(0).getItem_id())){
532
			if(!itemIds.contains(t_order.getLineitems().get(0).getItem_id())){
513
				itemIds.add(t_order.getLineitems().get(0).getItem_id());
533
				itemIds.add(t_order.getLineitems().get(0).getItem_id());
514
			}
534
			}
Line 522... Line 542...
522
			txnOrdersMap.put(t_order.getTransactionId(), txnOrders);
542
			txnOrdersMap.put(t_order.getTransactionId(), txnOrders);
523
		}
543
		}
524
		try {
544
		try {
525
			in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
545
			in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
526
			Map<Long, Item> itemsMap = client.getItems(itemIds);
546
			Map<Long, Item> itemsMap = client.getItems(itemIds);
527
			in.shop2020.logistics.LogisticsService.Client logisticsClient = new LogisticsClient().getClient();
-
 
528
			List<in.shop2020.logistics.Provider> providers = logisticsClient.getAllProviders();
-
 
529
			Map<Long,in.shop2020.logistics.Provider> providersMap = new HashMap<Long, in.shop2020.logistics.Provider>();
-
 
530
 
-
 
531
			for(in.shop2020.logistics.Provider provider : providers){
-
 
532
				providersMap.put(provider.getId(), provider);
-
 
533
			}
-
 
534
 
547
 
535
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
548
			in.shop2020.model.v1.order.TransactionService.Client tClient = new TransactionClient().getClient();
536
			InventoryClient inventoryServiceClient = new InventoryClient();
549
			InventoryClient inventoryServiceClient = new InventoryClient();
537
			InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
550
			InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
538
			for(in.shop2020.model.v1.order.Order t_order : orders){
551
			for(in.shop2020.model.v1.order.Order t_order : orders){
539
				LineItem lineItem = t_order.getLineitems().get(0);
552
				LineItem lineItem = t_order.getLineitems().get(0);
540
				String pickFromWarehouse = warehousesMap.get(t_order.getFulfilmentWarehouseId()).getDisplayName();
553
				String pickFromWarehouse = warehousesMap.get(t_order.getFulfilmentWarehouseId()).getDisplayName();
541
				Item item = itemsMap.get(lineItem.getItem_id());
554
				Item item = itemsMap.get(lineItem.getItem_id());
542
				in.shop2020.logistics.Provider provider = providersMap.get(t_order.getLogistics_provider_id());
555
				in.shop2020.logistics.Provider provider = getProvidersMap().get(t_order.getLogistics_provider_id());
543
				Warehouse fulfillmentWarehouse = warehousesMap.get(t_order.getFulfilmentWarehouseId());
556
				Warehouse fulfillmentWarehouse = warehousesMap.get(t_order.getFulfilmentWarehouseId());
544
				Map<Long, Map<String, String>> acceptTogetherOrdersMap = null;
557
				Map<Long, Map<String, String>> acceptTogetherOrdersMap = null;
545
				Map<Long, Map<String, String>> billTogetherOrdersMap = null;
558
				Map<Long, Map<String, String>> billTogetherOrdersMap = null;
546
				if(!t_order.isSetAccepted_timestamp()){
559
				if(!t_order.isSetAccepted_timestamp()){
547
					acceptTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
560
					acceptTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
Line 1322... Line 1335...
1322
				"VirtualWarehouses", CacheManager.create());
1335
				"VirtualWarehouses", CacheManager.create());
1323
		
1336
		
1324
		List<Long> virtualWarehouseIds = virtualWhCache.get("virtual_warehouses");
1337
		List<Long> virtualWarehouseIds = virtualWhCache.get("virtual_warehouses");
1325
		
1338
		
1326
		if(virtualWarehouseIds!=null && virtualWarehouseIds.size()>0){
1339
		if(virtualWarehouseIds!=null && virtualWarehouseIds.size()>0){
1327
			System.out.println("Virtual Warehouse Exists");
-
 
1328
			logger.info("Virtual Warehouse Exists");
-
 
1329
			return virtualWarehouseIds;
1340
			return virtualWarehouseIds;
1330
		}else{
1341
		}else{
1331
			System.out.println("Virtual Warehouse Not Exists");
-
 
1332
			logger.info("Virtual Warehouse Not Exists");
1342
			logger.info("Virtual Warehouse Not Exists, creating them");
1333
			virtualWarehouseIds = new ArrayList<Long>();
1343
			virtualWarehouseIds = new ArrayList<Long>();
1334
			try{
1344
			try{
1335
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
1345
				in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
1336
				List<Warehouse> allWarehouses = inventoryClient.getWarehouses(null, null, 0, 0, 0);
1346
				List<Warehouse> allWarehouses = inventoryClient.getWarehouses(null, null, 0, 0, 0);
1337
				for(Warehouse wh:allWarehouses){
1347
				for(Warehouse wh:allWarehouses){