Subversion Repositories SmartDukaan

Rev

Rev 3196 | Rev 3461 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
493 rajveer 1
package in.shop2020.hotspot.dashbaord.server;
2
 
3
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
4
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
2697 chandransh 5
import in.shop2020.hotspot.dashbaord.shared.actions.ReturnOrder;
493 rajveer 6
import in.shop2020.model.v1.order.Alert;
914 chandransh 7
import in.shop2020.model.v1.order.LineItem;
493 rajveer 8
import in.shop2020.model.v1.order.OrderStatus;
9
import in.shop2020.model.v1.order.TransactionService.Client;
3132 rajveer 10
import in.shop2020.thrift.clients.TransactionClient;
493 rajveer 11
 
12
import java.util.ArrayList;
13
import java.util.Date;
14
import java.util.List;
15
 
2449 chandransh 16
/**
17
 * This class is a facade to the Transaction service and should be used to
18
 * access all order specific data.
19
 * 
20
 * @author Chandranshu
21
 * 
22
 */
493 rajveer 23
public class TransactionUtils {
2449 chandransh 24
	/**
25
	 * The human user is concerned only with a consolidated view of actionable
26
	 * orders. Orders with different statuses in the database can be part of the
27
	 * same consolidated view. This method uses a mapping of <i>type</i> to
28
	 * <i>status</i> to get all such orders and return them as order beans.
29
	 * 
30
	 * @param type
31
	 *            The type of orders to return.
32
	 * @param warehouseId
33
	 *            The warehouse for which the orders should be queried.
34
	 * @return A list of orders of the given type to be fulfilled from the given
35
	 *         warehouse
36
	 */
493 rajveer 37
	public static List<Order> getOrders(OrderType type, long warehouseId){
2449 chandransh 38
		List<OrderStatus> statuses = getStatuses(type);
493 rajveer 39
 
40
		List<Order> orders = new ArrayList<Order>();
41
		try{
3132 rajveer 42
			TransactionClient client = new TransactionClient();
493 rajveer 43
			Client c = client.getClient();
44
 
45
			List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();
46
			if(statuses.isEmpty()){
47
				t_orders.addAll(c.getAllOrders(null, 0L, new Date().getTime(), warehouseId));
48
			}
49
			else {
50
				for(OrderStatus status: statuses){
51
					t_orders.addAll(c.getAllOrders(status, 0L, new Date().getTime(), warehouseId));
52
				}
53
			}
54
 
55
			for (in.shop2020.model.v1.order.Order t_order: t_orders){
671 chandransh 56
				Order o = getOrderFromThriftOrder(t_order);
493 rajveer 57
 
58
				orders.add(o);
3205 chandransh 59
				//TODO: We'll figure out how to show an alert. I don't think we need another thrift call for that.
493 rajveer 60
				//check if it has an associated alert
3205 chandransh 61
//				List<Alert> alerts = c.getAlerts(t_order.getId(), true);
62
//				if(alerts != null && alerts.size() != 0){
63
//					o.setAlert(true);
64
//					o.setStatusMessage(alerts.iterator().next().getComment());
65
//				} else {
66
//					o.setAlert(false);
67
//				}
493 rajveer 68
			}
69
		}catch(Exception e){
2449 chandransh 70
			e.printStackTrace();
493 rajveer 71
		}
72
		return orders;
73
	}
74
 
2449 chandransh 75
	/**
76
	 * Calls the same method of the transaction service and returns the status
77
	 * returned. Catches all exceptions that are raised and returns false in
78
	 * that case.
79
	 * 
80
	 * @param warehouseId
81
	 *            The warehouse for which the orders should be marked as
82
	 *            manifested.
83
	 * @param providerId
84
	 *            The provider for which the orders should be marked as
85
	 *            manifested.
3065 chandransh 86
	 * @param cod
87
	 *             Whether cod orders have to be marked as manifested
2449 chandransh 88
	 * @return True if everything goes fine, false otherwise.
89
	 */
3065 chandransh 90
	public static boolean markOrdersAsManifested(long warehouseId, String providerId, boolean cod){
760 chandransh 91
		try {
92
			long provider_id = Long.parseLong(providerId);
3132 rajveer 93
			TransactionClient client = new TransactionClient();
760 chandransh 94
			Client c = client.getClient();
3065 chandransh 95
			return c.markOrdersAsManifested(warehouseId, provider_id, cod);
760 chandransh 96
		}catch(Exception e){
97
			e.printStackTrace();
98
			return false;
99
		}
100
	}
2449 chandransh 101
 
671 chandransh 102
	/**
2449 chandransh 103
	 * 
671 chandransh 104
	 * @param t_order
2449 chandransh 105
	 *            A thrift order object with line items.
106
	 * @return an Order bean which can be used for rendering on the client side.
671 chandransh 107
	 */
108
	public static Order getOrderFromThriftOrder(in.shop2020.model.v1.order.Order t_order) {
914 chandransh 109
		LineItem lineItem = t_order.getLineitems().get(0);
966 chandransh 110
		Order order = new Order(t_order.getId(),
111
				t_order.getCustomer_id(),
112
				t_order.getCustomer_name(),
113
				t_order.getCustomer_mobilenumber(),
114
				t_order.getCustomer_pincode(),
115
				t_order.getCustomer_address1(),
116
				t_order.getCustomer_address2(),
117
				t_order.getCustomer_city(),
118
				t_order.getCustomer_state(),
119
				t_order.getCustomer_email(),
120
				t_order.getCreated_timestamp(),
121
				t_order.getExpected_delivery_time(),
122
				t_order.getStatus().getValue(),
123
				t_order.getStatusDescription(),
124
				lineItem.getItem_id(),
125
				lineItem.getProductGroup(),
126
				lineItem.getBrand(),
127
				lineItem.getModel_name(),
128
				lineItem.getModel_number(),
129
				lineItem.getColor(),
130
				lineItem.getExtra_info(),
2782 chandransh 131
				t_order.getTotal_amount(),
132
				t_order.getTotal_weight(),
133
				t_order.getAirwaybill_no(),
134
				t_order.getBilled_by(),
135
				t_order.getInvoice_number(),
136
				t_order.getJacket_number(),
137
				lineItem.getItem_number(),
138
				lineItem.getImei_number(),
3065 chandransh 139
				t_order.getBatchNo(),
140
				t_order.getSerialNo(),
2509 chandransh 141
				false,
142
				t_order.isDoaFlag(),
3065 chandransh 143
				t_order.getPickupRequestNo(),
144
				t_order.isCod());
966 chandransh 145
		return order;
671 chandransh 146
	}
147
 
2449 chandransh 148
	/**
2697 chandransh 149
	 * Queries the transction server to get the list of all return orders that
150
	 * have to be processed.
151
	 * 
152
	 * @return A list of all return orders to be processed.
153
	 */
154
	public static List<ReturnOrder> getReturnOrders(long warehouseId){
155
		List<ReturnOrder> retOrders = new ArrayList<ReturnOrder>();
156
		try{
3132 rajveer 157
			TransactionClient client = new TransactionClient();
2697 chandransh 158
			Client c = client.getClient();
159
			List<in.shop2020.model.v1.order.ReturnOrder> tRetOrders =  c.getReturnOrders(warehouseId, 0L, new Date().getTime());
160
			for(in.shop2020.model.v1.order.ReturnOrder retOrder : tRetOrders){
161
				retOrders.add(getReturnOrderFromThriftRO(retOrder));
162
			}
163
		}catch(Exception e){
164
			e.printStackTrace();
165
		}
166
		return retOrders;
167
	}
168
 
2700 chandransh 169
	public static ReturnOrder getReturnOrderFromThriftRO(in.shop2020.model.v1.order.ReturnOrder tRetOrder){
170
		ReturnOrder retOrder = new ReturnOrder(tRetOrder.getOrderId(),
171
				tRetOrder.getWarehouseId(),
172
				tRetOrder.getItemId(),
173
				tRetOrder.getProductGroup(),
174
				tRetOrder.getBrand(),
175
				tRetOrder.getModelName(),
176
				tRetOrder.getModelNumber(),
177
				tRetOrder.getColor(),
178
				tRetOrder.getInvoiceNumber(),
179
				tRetOrder.getJacketNumber(),
180
				tRetOrder.getTotalPrice(),
181
				tRetOrder.getTransferPrice(),
182
				false,
183
				tRetOrder.getCreatedAt());
2697 chandransh 184
		return retOrder;
185
	}
186
 
187
	/**
2449 chandransh 188
	 * This method maps a given type to a list of statuses.
189
	 * 
190
	 * @param type
191
	 *            The type of orders to fetch.
192
	 * @return The list of Thrift statuses associated with a particular order
193
	 *         type.
194
	 */
195
	private static List<OrderStatus> getStatuses(OrderType type) {
196
		List<OrderStatus> statuses = new ArrayList<OrderStatus>();
197
 
198
		switch (type) {
199
		case ACCEPTED:
200
			statuses.add(OrderStatus.ACCEPTED);
201
			break;
202
 
203
		case ALL:
204
			break;
205
 
206
		case NEW:
207
			statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
208
			statuses.add(OrderStatus.INVENTORY_LOW);
209
			break;
210
 
211
		case BILLED:
212
			statuses.add(OrderStatus.BILLED);
213
			break;
214
 
215
		case NO_STOCK:
216
			statuses.add(OrderStatus.INVENTORY_LOW);
217
			break;
218
 
219
		case REJECTED:
220
			statuses.add(OrderStatus.REJECTED);
221
			break;
222
 
223
		case SHIPPED:
224
			statuses.add(OrderStatus.SHIPPED_FROM_WH);
225
			statuses.add(OrderStatus.SHIPPED_TO_LOGST);
226
			break;
227
 
228
		case DELIVERED:
229
			statuses.add(OrderStatus.DELIVERY_SUCCESS);
2509 chandransh 230
			statuses.add(OrderStatus.DOA_PICKUP_REQUESTED);
2449 chandransh 231
			break;
2610 chandransh 232
 
233
		case DOA_AWAITED:
234
			statuses.add(OrderStatus.DOA_RETURN_AUTHORIZED);
235
			statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
236
			statuses.add(OrderStatus.DOA_RECEIVED);
237
			break;
2449 chandransh 238
 
2509 chandransh 239
		case SALES_RETURN_AWAITED:
240
			statuses.add(OrderStatus.SALES_RETURN_IN_TRANSIT);
241
			break;
242
 
2610 chandransh 243
		case DOA_RETURNED:
244
			statuses.add(OrderStatus.DOA_CERT_VALID);
245
			break;
246
 
2509 chandransh 247
		case SALES_RETURNED:
2610 chandransh 248
			statuses.add(OrderStatus.SALES_RET_RECEIVED);
249
			statuses.add(OrderStatus.DOA_CERT_INVALID);
2509 chandransh 250
			break;
251
 
2628 chandransh 252
		case RESHIPPED:
253
			statuses.add(OrderStatus.SALES_RET_RESHIPPED);
254
			statuses.add(OrderStatus.DOA_INVALID_RESHIPPED);
255
			statuses.add(OrderStatus.DOA_RESHIPPED);
256
			break;
257
 
258
		case REFUNDED:
3196 chandransh 259
		    statuses.add(OrderStatus.CANCELED);
2628 chandransh 260
			statuses.add(OrderStatus.SALES_RET_REFUNDED);
261
			statuses.add(OrderStatus.DOA_INVALID_REFUNDED);
262
			statuses.add(OrderStatus.DOA_VALID_REFUNDED);
263
			statuses.add(OrderStatus.REFUNDED);
264
			break;
2509 chandransh 265
 
3065 chandransh 266
		case VERIFICATION_PENDING:
267
		    statuses.add(OrderStatus.INIT);
268
		    break;
2449 chandransh 269
		default:
270
			break;
271
		}
272
		return statuses;
273
	}
493 rajveer 274
}