Subversion Repositories SmartDukaan

Rev

Rev 3065 | Rev 3196 | 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);
59
				//check if it has an associated alert
60
				List<Alert> alerts = c.getAlerts(t_order.getId(), true);
2449 chandransh 61
				if(alerts != null && alerts.size() != 0){
62
					o.setAlert(true);
63
					o.setStatusMessage(alerts.iterator().next().getComment());
64
				} else {
493 rajveer 65
					o.setAlert(false);
66
				}
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);
966 chandransh 109
		Order order = new Order(t_order.getId(),
110
				t_order.getCustomer_id(),
111
				t_order.getCustomer_name(),
112
				t_order.getCustomer_mobilenumber(),
113
				t_order.getCustomer_pincode(),
114
				t_order.getCustomer_address1(),
115
				t_order.getCustomer_address2(),
116
				t_order.getCustomer_city(),
117
				t_order.getCustomer_state(),
118
				t_order.getCustomer_email(),
119
				t_order.getCreated_timestamp(),
120
				t_order.getExpected_delivery_time(),
121
				t_order.getStatus().getValue(),
122
				t_order.getStatusDescription(),
123
				lineItem.getItem_id(),
124
				lineItem.getProductGroup(),
125
				lineItem.getBrand(),
126
				lineItem.getModel_name(),
127
				lineItem.getModel_number(),
128
				lineItem.getColor(),
129
				lineItem.getExtra_info(),
2782 chandransh 130
				t_order.getTotal_amount(),
131
				t_order.getTotal_weight(),
132
				t_order.getAirwaybill_no(),
133
				t_order.getBilled_by(),
134
				t_order.getInvoice_number(),
135
				t_order.getJacket_number(),
136
				lineItem.getItem_number(),
137
				lineItem.getImei_number(),
3065 chandransh 138
				t_order.getBatchNo(),
139
				t_order.getSerialNo(),
2509 chandransh 140
				false,
141
				t_order.isDoaFlag(),
3065 chandransh 142
				t_order.getPickupRequestNo(),
143
				t_order.isCod());
966 chandransh 144
		return order;
671 chandransh 145
	}
146
 
2449 chandransh 147
	/**
2697 chandransh 148
	 * Queries the transction server to get the list of all return orders that
149
	 * have to be processed.
150
	 * 
151
	 * @return A list of all return orders to be processed.
152
	 */
153
	public static List<ReturnOrder> getReturnOrders(long warehouseId){
154
		List<ReturnOrder> retOrders = new ArrayList<ReturnOrder>();
155
		try{
3132 rajveer 156
			TransactionClient client = new TransactionClient();
2697 chandransh 157
			Client c = client.getClient();
158
			List<in.shop2020.model.v1.order.ReturnOrder> tRetOrders =  c.getReturnOrders(warehouseId, 0L, new Date().getTime());
159
			for(in.shop2020.model.v1.order.ReturnOrder retOrder : tRetOrders){
160
				retOrders.add(getReturnOrderFromThriftRO(retOrder));
161
			}
162
		}catch(Exception e){
163
			e.printStackTrace();
164
		}
165
		return retOrders;
166
	}
167
 
2700 chandransh 168
	public static ReturnOrder getReturnOrderFromThriftRO(in.shop2020.model.v1.order.ReturnOrder tRetOrder){
169
		ReturnOrder retOrder = new ReturnOrder(tRetOrder.getOrderId(),
170
				tRetOrder.getWarehouseId(),
171
				tRetOrder.getItemId(),
172
				tRetOrder.getProductGroup(),
173
				tRetOrder.getBrand(),
174
				tRetOrder.getModelName(),
175
				tRetOrder.getModelNumber(),
176
				tRetOrder.getColor(),
177
				tRetOrder.getInvoiceNumber(),
178
				tRetOrder.getJacketNumber(),
179
				tRetOrder.getTotalPrice(),
180
				tRetOrder.getTransferPrice(),
181
				false,
182
				tRetOrder.getCreatedAt());
2697 chandransh 183
		return retOrder;
184
	}
185
 
186
	/**
2449 chandransh 187
	 * This method maps a given type to a list of statuses.
188
	 * 
189
	 * @param type
190
	 *            The type of orders to fetch.
191
	 * @return The list of Thrift statuses associated with a particular order
192
	 *         type.
193
	 */
194
	private static List<OrderStatus> getStatuses(OrderType type) {
195
		List<OrderStatus> statuses = new ArrayList<OrderStatus>();
196
 
197
		switch (type) {
198
		case ACCEPTED:
199
			statuses.add(OrderStatus.ACCEPTED);
200
			break;
201
 
202
		case ALL:
203
			break;
204
 
205
		case NEW:
206
			statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
207
			statuses.add(OrderStatus.INVENTORY_LOW);
208
			break;
209
 
210
		case BILLED:
211
			statuses.add(OrderStatus.BILLED);
212
			break;
213
 
214
		case NO_STOCK:
215
			statuses.add(OrderStatus.INVENTORY_LOW);
216
			break;
217
 
218
		case REJECTED:
219
			statuses.add(OrderStatus.REJECTED);
220
			break;
221
 
222
		case SHIPPED:
223
			statuses.add(OrderStatus.SHIPPED_FROM_WH);
224
			statuses.add(OrderStatus.SHIPPED_TO_LOGST);
225
			break;
226
 
227
		case DELIVERED:
228
			statuses.add(OrderStatus.DELIVERY_SUCCESS);
2509 chandransh 229
			statuses.add(OrderStatus.DOA_PICKUP_REQUESTED);
2449 chandransh 230
			break;
2610 chandransh 231
 
232
		case DOA_AWAITED:
233
			statuses.add(OrderStatus.DOA_RETURN_AUTHORIZED);
234
			statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
235
			statuses.add(OrderStatus.DOA_RECEIVED);
236
			break;
2449 chandransh 237
 
2509 chandransh 238
		case SALES_RETURN_AWAITED:
239
			statuses.add(OrderStatus.SALES_RETURN_IN_TRANSIT);
240
			break;
241
 
2610 chandransh 242
		case DOA_RETURNED:
243
			statuses.add(OrderStatus.DOA_CERT_VALID);
244
			break;
245
 
2509 chandransh 246
		case SALES_RETURNED:
2610 chandransh 247
			statuses.add(OrderStatus.SALES_RET_RECEIVED);
248
			statuses.add(OrderStatus.DOA_CERT_INVALID);
2509 chandransh 249
			break;
250
 
2628 chandransh 251
		case RESHIPPED:
252
			statuses.add(OrderStatus.SALES_RET_RESHIPPED);
253
			statuses.add(OrderStatus.DOA_INVALID_RESHIPPED);
254
			statuses.add(OrderStatus.DOA_RESHIPPED);
255
			break;
256
 
257
		case REFUNDED:
258
			statuses.add(OrderStatus.SALES_RET_REFUNDED);
259
			statuses.add(OrderStatus.DOA_INVALID_REFUNDED);
260
			statuses.add(OrderStatus.DOA_VALID_REFUNDED);
261
			statuses.add(OrderStatus.REFUNDED);
262
			break;
2509 chandransh 263
 
3065 chandransh 264
		case VERIFICATION_PENDING:
265
		    statuses.add(OrderStatus.INIT);
266
		    break;
2449 chandransh 267
		default:
268
			break;
269
		}
270
		return statuses;
271
	}
493 rajveer 272
}