Subversion Repositories SmartDukaan

Rev

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