Subversion Repositories SmartDukaan

Rev

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

Rev 19164 Rev 19196
Line 52... Line 52...
52
 * 
52
 * 
53
 */
53
 */
54
public class TransactionUtils {
54
public class TransactionUtils {
55
	private static String courierDetailsPath = "/CourierDetailReports";
55
	private static String courierDetailsPath = "/CourierDetailReports";
56
	private static Logger logger = LoggerFactory.getLogger(TransactionUtils.class);
56
	private static Logger logger = LoggerFactory.getLogger(TransactionUtils.class);
-
 
57
	private static long ALL_GREEN = 1L;
-
 
58
	private static long GREEN_AND_PURPULE = 2L;
-
 
59
	private static long GREEN_AND_IN_RED_OR_WHITE = 3L;
-
 
60
	private static long ALL_RED = 4L;
-
 
61
	private static long ALL_PURPLE = 5L;
-
 
62
	private static long PURPLE_AND_IN_RED_OR_WHITE = 6L;
-
 
63
	private static long ALL_OTHERS = 7L;
-
 
64
	
-
 
65
	private static enum ColorCode {
-
 
66
		GREEN,
-
 
67
		PURPLE,
-
 
68
		RED,
-
 
69
		OTHER
-
 
70
	}
-
 
71
	
57
	
72
	
58
	/**
73
	/**
59
	 * The human user is concerned only with a consolidated view of actionable
74
	 * The human user is concerned only with a consolidated view of actionable
60
	 * orders. Orders with different statuses in the database can be part of the
75
	 * orders. Orders with different statuses in the database can be part of the
61
	 * same consolidated view. This method uses a mapping of <i>type</i> to
76
	 * same consolidated view. This method uses a mapping of <i>type</i> to
Line 93... Line 108...
93
				orders.add(o);
108
				orders.add(o);
94
			}
109
			}
95
			if(type==OrderType.NEW || type==OrderType.ALL_PENDING || type ==OrderType.LOW_INVENTORY || type == OrderType.PO_RAISED
110
			if(type==OrderType.NEW || type==OrderType.ALL_PENDING || type ==OrderType.LOW_INVENTORY || type == OrderType.PO_RAISED
96
					|| type == OrderType.REVERSAL_INITIATED || type == OrderType.NOT_AVAILABLE){
111
					|| type == OrderType.REVERSAL_INITIATED || type == OrderType.NOT_AVAILABLE){
97
				Map<Long, List<Order>> transactionOrdersMap = new HashMap<Long, List<Order>>();
112
				Map<Long, List<Order>> transactionOrdersMap = new HashMap<Long, List<Order>>();
-
 
113
				Map<Long, Map<String, Long>> transactionsColorMap = new HashMap<Long, Map<String, Long>>();
98
				for(Order order : orders){
114
				for(Order order : orders){
99
					if(transactionOrdersMap.containsKey(order.getTransactionId())){
115
					if(transactionOrdersMap.containsKey(order.getTransactionId())){
100
						List<Order> txnOrders = transactionOrdersMap.get(order.getTransactionId());
116
						List<Order> txnOrders = transactionOrdersMap.get(order.getTransactionId());
101
						txnOrders.add(order);
117
						txnOrders.add(order);
102
						transactionOrdersMap.put(order.getTransactionId(), txnOrders);
118
						transactionOrdersMap.put(order.getTransactionId(), txnOrders);
103
					}else{
119
					}else{
104
						List<Order> txnOrders = new ArrayList<Order>();
120
						List<Order> txnOrders = new ArrayList<Order>();
105
						txnOrders.add(order);
121
						txnOrders.add(order);
106
						transactionOrdersMap.put(order.getTransactionId(), txnOrders);
122
						transactionOrdersMap.put(order.getTransactionId(), txnOrders);
107
					}
123
					}
108
				}
124
					
-
 
125
					if(transactionsColorMap.containsKey(order.getTransactionId())){
-
 
126
						Map<String, Long> colorMap = transactionsColorMap.get(order.getTransactionId());
-
 
127
						//SHIPPING_TIME_EXCEEDED, DELIVERY_TIME_EXCEEDED, ORDER_NOT_CONNECTED_FOR_TOO_LONG, ORDER_NOT_CONNECTED
-
 
128
						if(order.getAlert()==OrderAlert.TODAY_SHIPPING_IN_STOCK){
-
 
129
							if(colorMap.containsKey(ColorCode.GREEN.toString())){
-
 
130
								colorMap.put(ColorCode.GREEN.toString(),colorMap.get(ColorCode.GREEN.toString())+1);
-
 
131
							}else{
-
 
132
								colorMap.put(ColorCode.GREEN.toString(),1L);
109
 
133
							}
-
 
134
						}else if(order.getAlert()==OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK){
-
 
135
							if(colorMap.containsKey(ColorCode.RED.toString())){
-
 
136
								colorMap.put(ColorCode.RED.toString(),colorMap.get(ColorCode.RED.toString())+1);
-
 
137
							}else{
110
				orders = new ArrayList<Order>();
138
								colorMap.put(ColorCode.RED.toString(),1L);
-
 
139
							}
-
 
140
						}else if(order.getAlert()==OrderAlert.LATER_SHIPPING_IN_STOCK){
-
 
141
							if(colorMap.containsKey(ColorCode.PURPLE.toString())){
-
 
142
								colorMap.put(ColorCode.PURPLE.toString(),colorMap.get(ColorCode.PURPLE.toString())+1);
-
 
143
							}else{
-
 
144
								colorMap.put(ColorCode.PURPLE.toString(),1L);
-
 
145
							}
-
 
146
						}else{
-
 
147
							if(colorMap.containsKey(ColorCode.OTHER.toString())){
-
 
148
								colorMap.put(ColorCode.OTHER.toString(),colorMap.get(ColorCode.OTHER.toString())+1);
-
 
149
							}else{
-
 
150
								colorMap.put(ColorCode.OTHER.toString(),1L);
-
 
151
							}
-
 
152
						}
111
				for(Entry<Long, List<Order>> entry : transactionOrdersMap.entrySet()){
153
						transactionsColorMap.put(order.getTransactionId(), colorMap);
-
 
154
					}else{
-
 
155
						Map<String, Long> colorMap = new HashMap<String, Long>();
-
 
156
						if(order.getAlert()==OrderAlert.TODAY_SHIPPING_IN_STOCK){
-
 
157
							colorMap.put(ColorCode.GREEN.toString(),1L);
-
 
158
						}else if(order.getAlert()==OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK){
112
					List<Order> txnOrders = entry.getValue();
159
							colorMap.put(ColorCode.RED.toString(),1L);
113
					Collections.sort(txnOrders,new OrderPromisedShippingComparator());
160
						}else if(order.getAlert()==OrderAlert.LATER_SHIPPING_IN_STOCK){
-
 
161
							colorMap.put(ColorCode.PURPLE.toString(),1L);
-
 
162
						}else{
-
 
163
							colorMap.put(ColorCode.OTHER.toString(),1L);
-
 
164
						}
114
					transactionOrdersMap.put(entry.getKey(), txnOrders);
165
						transactionsColorMap.put(order.getTransactionId(), colorMap);
-
 
166
					}
-
 
167
					
115
				}
168
				}
116
				
169
				
117
				Set<Long> transactionIds = transactionOrdersMap.keySet();
170
				Map<Long, List<Long>> orderCategoryMap = new HashMap<Long, List<Long>>();
118
				
171
				
-
 
172
				for(Entry<Long, Map<String, Long>> colorMapEntry : transactionsColorMap.entrySet()){
-
 
173
					Map<String, Long> colorMap = colorMapEntry.getValue();
-
 
174
					List<String> colorSet = new ArrayList<String>(colorMap.keySet());
-
 
175
					long colorMapSize = colorSet.size();
-
 
176
					if(colorMapSize==1){
-
 
177
						if(ColorCode.GREEN.toString().equalsIgnoreCase(colorSet.get(0))){
-
 
178
							if(orderCategoryMap.containsKey(ALL_GREEN)){
-
 
179
								List<Long> transactions = orderCategoryMap.get(ALL_GREEN);
-
 
180
								transactions.add(colorMapEntry.getKey());
-
 
181
								orderCategoryMap.put(ALL_GREEN, transactions);
-
 
182
							}else{
-
 
183
								List<Long> transactions = new ArrayList<Long>();
-
 
184
								transactions.add(colorMapEntry.getKey());
-
 
185
								orderCategoryMap.put(ALL_GREEN, transactions);
-
 
186
							}
-
 
187
						}else if(ColorCode.RED.toString().equalsIgnoreCase(colorSet.get(0))){
-
 
188
							if(orderCategoryMap.containsKey(ALL_RED)){
-
 
189
								List<Long> transactions = orderCategoryMap.get(ALL_RED);
-
 
190
								transactions.add(colorMapEntry.getKey());
-
 
191
								orderCategoryMap.put(ALL_RED, transactions);
-
 
192
							}else{
-
 
193
								List<Long> transactions = new ArrayList<Long>();
-
 
194
								transactions.add(colorMapEntry.getKey());
-
 
195
								orderCategoryMap.put(ALL_RED, transactions);
-
 
196
							}
-
 
197
						}else if(ColorCode.PURPLE.toString().equalsIgnoreCase(colorSet.get(0))){
-
 
198
							if(orderCategoryMap.containsKey(ALL_PURPLE)){
-
 
199
								List<Long> transactions = orderCategoryMap.get(ALL_PURPLE);
-
 
200
								transactions.add(colorMapEntry.getKey());
-
 
201
								orderCategoryMap.put(ALL_PURPLE, transactions);
-
 
202
							}else{
-
 
203
								List<Long> transactions = new ArrayList<Long>();
-
 
204
								transactions.add(colorMapEntry.getKey());
-
 
205
								orderCategoryMap.put(ALL_PURPLE, transactions);
-
 
206
							}
-
 
207
						}else{
-
 
208
							if(orderCategoryMap.containsKey(ALL_OTHERS)){
-
 
209
								List<Long> transactions = orderCategoryMap.get(ALL_OTHERS);
-
 
210
								transactions.add(colorMapEntry.getKey());
-
 
211
								orderCategoryMap.put(ALL_OTHERS, transactions);
-
 
212
							}else{
-
 
213
								List<Long> transactions = new ArrayList<Long>();
-
 
214
								transactions.add(colorMapEntry.getKey());
-
 
215
								orderCategoryMap.put(ALL_OTHERS, transactions);
-
 
216
							}
-
 
217
						}
-
 
218
					}else if(colorMapSize>1){
-
 
219
						if(colorSet.contains(ColorCode.GREEN.toString())){
-
 
220
							if(colorSet.contains(ColorCode.PURPLE.toString())){
-
 
221
								if(orderCategoryMap.containsKey(GREEN_AND_PURPULE)){
-
 
222
									List<Long> transactions = orderCategoryMap.get(GREEN_AND_PURPULE);
-
 
223
									transactions.add(colorMapEntry.getKey());
-
 
224
									orderCategoryMap.put(GREEN_AND_PURPULE, transactions);
-
 
225
								}else{
-
 
226
									List<Long> transactions = new ArrayList<Long>();
-
 
227
									transactions.add(colorMapEntry.getKey());
-
 
228
									orderCategoryMap.put(GREEN_AND_PURPULE, transactions);
-
 
229
								}
-
 
230
							}else{
-
 
231
								if(orderCategoryMap.containsKey(GREEN_AND_IN_RED_OR_WHITE)){
-
 
232
									List<Long> transactions = orderCategoryMap.get(GREEN_AND_IN_RED_OR_WHITE);
-
 
233
									transactions.add(colorMapEntry.getKey());
-
 
234
									orderCategoryMap.put(GREEN_AND_IN_RED_OR_WHITE, transactions);
-
 
235
								}else{
-
 
236
									List<Long> transactions = new ArrayList<Long>();
-
 
237
									transactions.add(colorMapEntry.getKey());
-
 
238
									orderCategoryMap.put(GREEN_AND_IN_RED_OR_WHITE, transactions);
-
 
239
								}
-
 
240
							}
-
 
241
						}else if(colorSet.contains(ColorCode.PURPLE.toString())){
-
 
242
							if(orderCategoryMap.containsKey(PURPLE_AND_IN_RED_OR_WHITE)){
-
 
243
								List<Long> transactions = orderCategoryMap.get(PURPLE_AND_IN_RED_OR_WHITE);
-
 
244
								transactions.add(colorMapEntry.getKey());
-
 
245
								orderCategoryMap.put(PURPLE_AND_IN_RED_OR_WHITE, transactions);
-
 
246
							}else{
-
 
247
								List<Long> transactions = new ArrayList<Long>();
-
 
248
								transactions.add(colorMapEntry.getKey());
-
 
249
								orderCategoryMap.put(PURPLE_AND_IN_RED_OR_WHITE, transactions);
-
 
250
							}
-
 
251
						}else{
-
 
252
							if(orderCategoryMap.containsKey(ALL_OTHERS)){
-
 
253
								List<Long> transactions = orderCategoryMap.get(ALL_OTHERS);
-
 
254
								transactions.add(colorMapEntry.getKey());
-
 
255
								orderCategoryMap.put(ALL_OTHERS, transactions);
-
 
256
							}else{
119
				List<Long> transactionIdList = new ArrayList<Long>(transactionIds);
257
								List<Long> transactions = new ArrayList<Long>();
-
 
258
								transactions.add(colorMapEntry.getKey());
-
 
259
								orderCategoryMap.put(ALL_OTHERS, transactions);
-
 
260
							}
-
 
261
						}
-
 
262
					}
-
 
263
				}
120
				
264
				
-
 
265
				List<Long> categoryList = new ArrayList<Long>(orderCategoryMap.keySet());
121
				Collections.sort(transactionIdList);
266
				Collections.sort(categoryList);
122
 
267
				
-
 
268
				orders = new ArrayList<Order>();
-
 
269
				for(Long category:categoryList){
-
 
270
					List<Long> transactions = orderCategoryMap.get(category);
123
				for(Long transactionId : transactionIdList){
271
					for(Long transactionId: transactions){
124
					orders.addAll(transactionOrdersMap.get(transactionId));
272
						List<Order> txnOrders = transactionOrdersMap.get(transactionId);
-
 
273
						Collections.sort(txnOrders,new OrderPromisedShippingComparator());
-
 
274
						orders.addAll(txnOrders);
-
 
275
					}
125
				}
276
				}
126
			}
277
			}
127
			
278
			
128
		}catch(Exception e){
279
		}catch(Exception e){
129
			e.printStackTrace();
280
			e.printStackTrace();
Line 480... Line 631...
480
			order.setLogisticsTransactionId(t_order.getLogisticsTransactionId());
631
			order.setLogisticsTransactionId(t_order.getLogisticsTransactionId());
481
		}
632
		}
482
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
633
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
483
		Date date = new Date(System.currentTimeMillis());
634
		Date date = new Date(System.currentTimeMillis());
484
		long currentDateTime = 0;
635
		long currentDateTime = 0;
485
		long expectedDateShippingTime =0 ;
636
		long promisedShippingTime =0 ;
486
		long currentTime = date.getTime();
637
		long currentTime = date.getTime();
487
		try{
638
		try{
488
			currentDateTime = sdf.parse(sdf.format(date)).getTime();
639
			currentDateTime = sdf.parse(sdf.format(date)).getTime();
489
			expectedDateShippingTime = sdf.parse(sdf.format(new Date(order.getExpectedShippingTime()))).getTime();
640
			promisedShippingTime = sdf.parse(sdf.format(new Date(order.getPromisedShippingTime()))).getTime();
490
		}catch(Exception e){
641
		}catch(Exception e){
491
			e.printStackTrace();
642
			e.printStackTrace();
492
		}
643
		}
493
		if(expectedDateShippingTime >0 && (order.getStatus()==3 || order.getStatus()==5 || order.getStatus()==41 ||
644
		if(promisedShippingTime >0 && (order.getStatus()==3 || order.getStatus()==5 || order.getStatus()==41 ||
494
				order.getStatus()==35 || order.getStatus()==36 || order.getStatus()==37)){
645
				order.getStatus()==35 || order.getStatus()==36 || order.getStatus()==37)){
495
			if(expectedDateShippingTime <= currentDateTime){
646
			if(promisedShippingTime <= currentDateTime){
496
				if(loadVirtualWarehouseDetails().contains(order.getFulfilmentWarehouseId())){
647
				if(loadVirtualWarehouseDetails().contains(order.getFulfilmentWarehouseId())){
497
					order.setAlert(OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK);
648
					order.setAlert(OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK);
498
				}else{
649
				}else{
499
					order.setAlert(OrderAlert.TODAY_SHIPPING_IN_STOCK);
650
					order.setAlert(OrderAlert.TODAY_SHIPPING_IN_STOCK);
500
				}
651
				}