Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
68 ashish 1
namespace java in.shop2020.model.v1.order
95 ashish 2
namespace py shop2020.thriftpy.model.v1.order
3374 rajveer 3
 
4
include "GenericService.thrift"
5
 
68 ashish 6
/***
7
	Order objects.
8
*/
483 rajveer 9
enum OrderStatus{
845 chandransh 10
	PAYMENT_PENDING,
11
	PAYMENT_FAILED,
483 rajveer 12
	INIT,
13
	SUBMITTED_FOR_PROCESSING,
14
	ACCEPTED,
15
	INVENTORY_LOW,
495 rajveer 16
	REJECTED,
483 rajveer 17
	BILLED,
18
	READY_FOR_SHIPPING,
19
	SHIPPED_FROM_WH,
20
	SHIPPED_TO_LOGST,
21
	IN_TRANSIT,
22
	DELIVERY_SUCCESS,
23
	DELIVERY_FAILED_FIRST_ATTEMPT,
24
	DELIVERY_FAILED_SECOND_ATTEMPT,
25
	DELIVERY_FAILED_THIRD_ATTEMPT,
26
	DELIVERY_FAILED_WORNG_ADDRESS
27
	COMPLETED,
28
	CANCELED,
2537 chandransh 29
	FAILED,
30
	SALES_RETURN_IN_TRANSIT,
2611 chandransh 31
	SALES_RET_RECEIVED,
2537 chandransh 32
	DOA_PICKUP_REQUESTED,
33
	DOA_RETURN_AUTHORIZED,
34
	DOA_RETURN_IN_TRANSIT,
2600 chandransh 35
	DOA_RECEIVED,
2537 chandransh 36
	DOA_CERT_INVALID,
2614 chandransh 37
	DOA_CERT_VALID,
38
	SALES_RET_RESHIPPED,
39
	DOA_INVALID_RESHIPPED,
40
	DOA_RESHIPPED,
41
	SALES_RET_REFUNDED,
42
	DOA_VALID_REFUNDED,
43
	DOA_INVALID_REFUNDED,
44
	REFUNDED
483 rajveer 45
}
46
 
47
enum TransactionStatus{
48
	INIT,
49
	IN_PROCESS,
50
	COMPLETED,
2964 chandransh 51
	FAILED,
3060 chandransh 52
	AUTHORIZED,
53
	COD_IN_PROCESS
483 rajveer 54
}
55
 
56
struct LineItem{
57
	1:i64 id,
698 chandransh 58
	2:i64 item_id,
956 chandransh 59
	3:string productGroup
60
	4:string brand,
61
	5:string model_number,
62
	6:string color
63
	7:string model_name,
64
	8:string extra_info,
65
	9:double quantity,
66
	10:double unit_price,
67
	11:double unit_weight,
68
	12:double total_price,
1000 varun.gupt 69
	13:double transfer_price,
2780 chandransh 70
	14:double total_weight,
71
	15:optional i64 imei_number,
72
	16:optional string item_number
483 rajveer 73
}
74
 
75
 
76
struct Order{
77
	1:i64 id,
78
	2:i64 warehouse_id,
79
	/**
80
		item info
81
	**/
82
	3:list<LineItem> lineitems,
83
	/**
84
	  logistics info
85
	**/
86
	4:i64 logistics_provider_id,
87
	5:string airwaybill_no,
88
	6:string tracking_id,
89
	7:i64 expected_delivery_time,
90
	/**
91
	  customer info
92
	**/
93
	8:i64 customer_id,
94
	9:string customer_name,
95
	10:string customer_mobilenumber,
96
	11:string customer_pincode,
735 chandransh 97
	12:string customer_address1,
98
	13:string customer_address2,
99
	14:string customer_email,
100
	15:string customer_city,
101
	16:string customer_state,
483 rajveer 102
 
103
	/**
104
		status and misc info
105
	**/
735 chandransh 106
	17:OrderStatus status,
107
	18:string statusDescription,
108
	19:double total_amount,
109
	20:double total_weight,
483 rajveer 110
	/**
111
		billing info
112
	**/
735 chandransh 113
	21:string invoice_number,
114
	22:string billed_by,
483 rajveer 115
	/**
116
		timestamps
117
	**/
735 chandransh 118
	23:i64 created_timestamp,
119
	24:i64 accepted_timestamp,
120
	25:i64 billing_timestamp,
121
	26:i64 shipping_timestamp,
1115 chandransh 122
	27:i64 pickup_timestamp,
123
	28:i64 delivery_timestamp,
1210 chandransh 124
	29:i64 outofstock_timestamp,
125
	30:i64 jacket_number,
1223 chandransh 126
	31:string receiver,
127
	32:i64 batchNo,
2537 chandransh 128
	33:i64 serialNo,
129
	34:bool doaFlag,
2675 vikas 130
	35:string pickupRequestNo,
2819 chandransh 131
	36:i64 transactionId,
3060 chandransh 132
	37:string purchaseOrderNo,
133
	38:bool cod
483 rajveer 134
}
135
 
136
struct Transaction{
137
	1:i64 id,
138
	2:list<Order> orders,
680 rajveer 139
	3:i64 createdOn,
140
	4:TransactionStatus transactionStatus,
141
	5:string statusDescription,
142
	6:i64 shoppingCartid,
2219 varun.gupt 143
	7:i64 customer_id,
2814 vikas 144
	8:string coupon_code,
145
	9:string sessionSource,
146
	10:i64 sessionStartTime
483 rajveer 147
}
148
 
149
struct Alert{
150
	1:i64 id,
151
	2:i64 order_id,
152
	3:i64 type,
153
	4:i64 time_set,
154
	5:string comment,
155
	6:i64 time_unset
156
}
157
 
2688 chandransh 158
struct ReturnOrder{
159
	1:i64 orderId,
2697 chandransh 160
	2:i64 warehouseId,
161
    3:i64 jacketNumber,
162
    4:string invoiceNumber,
163
    5:i64 itemId,
164
    6:string productGroup,
165
    7:string brand,
166
    8:string modelNumber,
167
    9:string modelName,
168
    10:string color,
169
    11:double totalPrice,
170
    12:double transferPrice,
171
    13:bool processedStatus,
172
    14:i64 createdAt,
173
    15:i64 processedAt
2688 chandransh 174
}
175
 
483 rajveer 176
exception TransactionServiceException{
177
	1:i32 errorCode,
178
	2:string message
179
}
180
 
3374 rajveer 181
service TransactionService extends GenericService.GenericService{
483 rajveer 182
 
183
	i64 createTransaction(1:Transaction transaction) throws (1:TransactionServiceException ex),
184
 
185
	//	Get transaction methods.
186
	Transaction getTransaction(1:i64 id) throws (1:TransactionServiceException ex),
187
	list<Transaction> getTransactionsForCustomer(1:i64 customerId, 2:i64 from_date, 3:i64 to_date, 4:TransactionStatus status) throws (1:TransactionServiceException ex),
188
	list<Transaction> getTransactionsForShoppingCartId(1:i64 shoppingCartId) throws (1:TransactionServiceException ex),
189
	TransactionStatus getTransactionStatus(1:i64 transactionId) throws (1:TransactionServiceException ex),
190
	bool changeTransactionStatus(1:i64 transactionId, 2:TransactionStatus status, 3:string description) throws (1:TransactionServiceException ex),
1382 varun.gupt 191
 
1398 varun.gupt 192
	bool enqueueTransactionInfoEmail(1:i64 transactionId) throws (1:TransactionServiceException ex),
1382 varun.gupt 193
 
483 rajveer 194
	list<Order> getAllOrders(1:OrderStatus status, 2:i64 from_date, 3:i64 to_date, 4:i64 warehouse_id) throws (1:TransactionServiceException ex),
1111 varun.gupt 195
 
1115 chandransh 196
	/**
197
	Returns orders within a range of their billing dates
198
	*/
1000 varun.gupt 199
	list<Order> getOrdersByBillingDate(1:OrderStatus status, 2:i64 start_billing_date, 3:i64 end_billing_date, 4:i64 warehouse_id) throws (1:TransactionServiceException ex),
1111 varun.gupt 200
 
1382 varun.gupt 201
	/**
3427 chandransh 202
	Returns orders for a particular provider and warehouse which were shipped between the given dates.
203
	Pass providerId and warehouseId as -1 to ignore both the parameters.
204
	*/
205
	list<Order> getOrdersByShippingDate(1:i64 fromShippingDate, 2:i64 toShippingDate, 3:i64 providerId, 4:i64 warehouseId) throws (1:TransactionServiceException ex),
206
 
207
	/**
1382 varun.gupt 208
	Returns order ids for orders which can be returned
209
	*/
210
	list<i64> getReturnableOrdersForCustomer(1:i64 customer_id, 2:i64 limit) throws (1:TransactionServiceException ex),
211
 
212
	/**
213
	Returns order ids for orders which can be cancelled
214
	*/
215
	list<i64> getCancellableOrdersForCustomer(1:i64 customer_id, 2:i64 limit) throws (1:TransactionServiceException ex),
216
 
483 rajveer 217
	bool changeOrderStatus(1:i64 orderId, 2:OrderStatus status, 3:string description) throws (1:TransactionServiceException ex),
1147 chandransh 218
 
219
	/**
1529 ankur.sing 220
	Returns list of orders for given transaction Id. Also filters based on customer Id so that
221
	only user who owns the transaction can view its order details.
222
	*/
223
	list<Order> getOrdersForTransaction(1:i64 transactionId 2:i64 customerId)  throws (1:TransactionServiceException ex),
3014 chandransh 224
 
225
	/**
226
	Returns list of orders for the given customer created between the given dates and having the given statuses.
227
	Pass and empty list to ignore filtering on statuses.
228
	*/	
229
	list<Order> getOrdersForCustomer(1:i64 customerId, 2:i64 from_date, 3:i64 to_date, 4:list<OrderStatus> statuses) throws (1:TransactionServiceException ex),
1529 ankur.sing 230
 
483 rajveer 231
	i64 createOrder(1:Order order) throws (1:TransactionServiceException ex),
232
	Order getOrder(1:i64 id) throws (1:TransactionServiceException ex),
233
	list<LineItem> getLineItemsForOrder(1:i64 orderId) throws (1:TransactionServiceException ex),
234
 
1529 ankur.sing 235
 
757 chandransh 236
	/**
1529 ankur.sing 237
	Returns an order for the order Id. Also checks if the order belongs to the customer whose Id is passed.
238
	Throws exception if either order Id is invalid or order does not below to the customer whose Id is passed.
239
	*/
240
	Order getOrderForCustomer(1:i64 orderId, 2:i64 customerId) throws (1:TransactionServiceException ex),
241
 
3060 chandransh 242
	//Alerts apis 
243
	list<Alert> getAlerts(1:i64 orderId, 2:bool valid),
244
	void setAlert(1:i64 orderId, 2:bool unset, 3:i64 type, 4: string comment),
245
 
1529 ankur.sing 246
	/**
3060 chandransh 247
	Return the number of valid orders. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
248
	*/
249
	i64 getValidOrderCount(),
250
 
251
	/**
252
	Returns the number of distinct customers who have done successful transactions
253
	*/
254
	i64 getNoOfCustomersWithSuccessfulTransaction(),
255
 
256
	/**
257
	Returns the minimum and maximum amounts of a valid order. (OrderStatus >= OrderStatus.SUBMITTED_FOR_PROCESSING)
258
	List contains two values, first minimum amount and second maximum amount.	
259
	*/
260
	list<double> getValidOrdersAmountRange(),
261
 
262
	/**
263
	Returns list of Orders in descending order by Order creation date. List is restricted to limit Orders.
264
	If limit is passed as 0, then all valid Orders are returned. 
265
	*/
266
	list<Order> getValidOrders(1:i64 limit),
267
 
268
	/**
269
	Create a batch of all the pending orders for the given warehouse.
270
	The returned list is orderd by created_timestamp.
271
	If there are no pending orders, an empty list is returned.
272
	*/
1223 chandransh 273
	list<Order> batchOrders(1:i64 warehouseId) throws (1:TransactionServiceException ex),
274
 
275
	/**
276
	Mark the given order as out of stock. Throws an exception if the order with the given Id couldn't be found. 
1244 chandransh 277
	*/
1210 chandransh 278
	bool markOrderAsOutOfStock(1:i64 orderId) throws (1:TransactionServiceException ex),
279
 
280
	/**
3060 chandransh 281
	Marks the given order as SUBMITTED_FOR_PROCESSING and updates the verified
282
	timestamp. It is intended to be used for COD orders but can be harmlessly 
283
	used for all other orders as well.
284
	Throws an exception if no such order exists.
757 chandransh 285
	*/
3060 chandransh 286
	bool verifyOrder(1:i64 orderId) throws (1:TransactionServiceException ex),
1115 chandransh 287
 
288
	/**
3060 chandransh 289
	Marks the given order as ACCEPTED and updates the accepted timestamp. If the
290
	given order is not a COD order, it also captures the payment if the same has
291
	not been captured.
292
	Throws an exception if no such order exists.
293
	*/
294
	bool acceptOrder(1:i64 orderId) throws (1:TransactionServiceException ex),
295
 
296
	bool billOrder(1:i64 orderId) throws (1:TransactionServiceException ex),
297
 
298
	/**
299
	Add billing details such as the bill number and the biller to the Order.
300
	Should be used when the bill is issued by a 3rd party and we've to feed
301
	the information into our system.
302
	*/
303
	bool addBillingDetails(1:i64 orderId, 2:string invoice_number, 3:string billed_by) throws (1:TransactionServiceException ex),
304
 
305
	/**
306
	Adds jacket number, item number and IMEI no. to the order. Doesn't update
307
	the IMEI no. if a -1 is supplied.
308
	Also, it generates an invoice number for the order, marks the order as
309
	BILLED and sets the billing timestamp.
310
	It should be used when we are billing the orders ourselves.
311
 
312
	Returns false if it doesn't find the order with the given ID.
313
	*/
314
	bool addJacketNumber(1:i64 orderId, 2:i64 jacketNumber, 3:i64 imeiNumber, 4:string itemNumber, 5:string billedBy, 6:i64 billingType) throws (1:TransactionServiceException ex),
315
 
316
	/**
317
	Depending on the third parameter, marks either all prepaid or all cod orders BILLED by the
318
	given warehouse and were picked up by the given provider as SHIPPED_FROM_WH.
319
	*/
320
	bool markOrdersAsManifested(1:i64 warehouseId, 2:i64 providerId, 3:bool cod) throws (1:TransactionServiceException ex),
321
 
322
	/**
1115 chandransh 323
	Marks all SHIPPED_FROM_WH orders of the previous day for a provider as SHIPPED_TO_LOGISTICS.
324
	Returns a list of orders that were shipped from warehouse but did not appear in the pick-up report.
325
	Raises an exception if we encounter report for an AWB number that we did not ship.
326
	*/
1244 chandransh 327
	list<Order> markOrdersAsPickedUp(1:i64 providerId, 2:map<string, string> pickupDetails) throws (1:TransactionServiceException ex),
1134 chandransh 328
 
329
	/**
330
	Marks all orders with AWBs in the given map as delivered. Also sets the delivery timestamp and
331
	the name of the receiver.
332
	Raises an exception if we encounter report for an AWB number that we did not ship.
333
	*/
334
	void markOrdersAsDelivered(1:i64 providerId, 2:map<string, string> deliveredOrders) throws (1:TransactionServiceException ex),
335
 
336
	/**
337
	Mark all orders with AWBs in the given map as failed. Also sets the delivery timestamp.
338
	Raises an exception if we encounter report for an AWB number that we did not ship.
339
	*/
340
	void markOrdersAsFailed(1:i64 providerId, 2:map<string, string> returnedOrders) throws (1:TransactionServiceException ex),
341
 
1244 chandransh 342
	/**
343
	Update the status description of orders whose AWB numbers are keys of the Map.
344
	*/
345
	void updateNonDeliveryReason(1:i64 providerId, 2:map<string, string> undeliveredOrders) throws (1:TransactionServiceException ex),
346
 
1407 ankur.sing 347
	/**
348
	Returns the list of orders whose delivery time has passed but have not been
349
	delivered yet for the given provider and warehouse. To get a complete list of
350
	undelivered orders, pass them as -1. 
351
	Returns an empty list if no such orders exist.
352
	*/
353
	list<Order> getUndeliveredOrders(1:i64 providerId, 2:i64 warehouseId),
354
 
1599 ankur.sing 355
	/**
2537 chandransh 356
	Toggle the DOA flag of an order. This should be used to flag an order for follow-up and unflag it when the follow-up is complete.
357
	Returns the final flag status.
358
	Throws an exception if the order with the given id couldn't be found or if the order status is not DELVIERY_SUCCESS. 
359
	*/
360
	bool toggleDOAFlag(1:i64 orderId) throws (1:TransactionServiceException ex),
361
 
362
	/**
363
	Sends out an email to the account manager of the original courier provider used to ship the order.
364
	If the order status was DELIVERY_SUCCESS, it is changed to be DOA_PICKUP_REQUESTED.
365
	If the order status was DOA_PICKUP_REQUESTED, it is left unchanged.
366
	For any other status, it returns false.
367
	Throws an exception if the order with the given id couldn't be found.
368
	*/
369
	bool requestPickupNumber(1:i64 orderId) throws (1:TransactionServiceException ex),
370
 
371
	/**
372
	If the order status is DOA_PICKUP_REQUESTED, it does the following
373
		1. Sends out an email to the customer with the dispatch advice that he has to print as an attachment.
374
		2. Changes order status to be DOA_PICKUP_AUTHORIZED.
375
		3. Returns true
2589 chandransh 376
	If the order is in any other status, it returns false.
2537 chandransh 377
	Throws an exception if the order with the given id couldn't be found.
378
	*/
379
	bool authorizePickup(1:i64 orderId, 2:string pickupNumber) throws (1:TransactionServiceException ex),
2589 chandransh 380
 
381
	/**
2765 chandransh 382
	Marks all DOA_PICKUP_AUTHORIZED orders of the previous day for a provider as DOA_RETURN_IN_TRANSIT.
383
	Returns a list of orders that were authorized for pickup but did not appear in the pick-up report.
384
	*/
385
	list<Order> markDoasAsPickedUp(1:i64 providerId, 2:map<string, string> pickupDetails),
386
 
387
	/**
2600 chandransh 388
	If the order status is DOA_RETURN_AUTHORIZED or DOA_RETURN_IN_TRANSIT, marks the order status as DOA_RECEIVED and returns true.
2614 chandransh 389
	If the order status is SALES_RETURN_IN_TRANSIT, marks the order status as SALES_RET_RECEIVED and returns true.
2589 chandransh 390
	If the order is in any other state, it returns false.
391
	Throws an exception if the order with the given id couldn't be found.
392
	*/
2614 chandransh 393
	bool receiveReturn(1:i64 orderId) throws (1:TransactionServiceException ex),
2589 chandransh 394
 
395
	/**
2600 chandransh 396
	Used to validate the DOA certificate for an order in the DOA_RECEIVED state. If the certificate is valid,
2614 chandransh 397
	the order state is changed to DOA_CERT_VALID. If the certificate is invalid, the order state is changed to DOA_CERT_INVALID.
2589 chandransh 398
	If the order is in any other state, it returns false.
399
	Throws an exception if the order with the given id couldn't be found.
400
	*/
401
	bool validateDoa(1:i64 orderId, 2:bool isValid) throws (1:TransactionServiceException ex),
2614 chandransh 402
 
403
	/**
404
	If the order is in SALES_RET_RECEIVED or DOA_CERT_INVALID state, it does the following:
405
		1. Creates a new order for processing in the BILLED state. All billing information is saved.
406
		2. Marks the current order as one of the final states SALES_RET_RESHIPPED and DOA_INVALID_RESHIPPED depending on what state the order started in.
407
 
408
	If the order is in DOA_CERT_VALID state, it does the following:
409
		1. Creates a new order for processing in the SUBMITTED_FOR_PROCESSING state.
410
		2. Creates a return order for the warehouse executive to return the DOA material.
411
		3. Marks the current order as the final DOA_RESHIPPED state.
412
 
413
	Returns the id of the newly created order.
414
 
415
	Throws an exception if the order with the given id couldn't be found.
416
	*/
417
	i64 reshipOrder(1:i64 orderId) throws (1:TransactionServiceException ex),
418
 
419
	/**
420
	If the order is in SALES_RET_RECEIVED, DOA_CERT_VALID or DOA_CERT_INVALID state, it does the following:
421
		1. Creates a refund request for batch processing.
422
		2. Creates a return order for the warehouse executive to return the shipped material.
423
		3. Marks the current order as SALES_RET_REFUNDED, DOA_VALID_REFUNDED or DOA_INVALID_REFUNDED final states.
424
 
425
	If the order is in SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
426
		1. Creates a refund request for batch processing.
3226 chandransh 427
		2. Cancels the reservation of the item in the warehouse.
428
		3. Marks the current order as the REFUNDED final state.
2614 chandransh 429
 
3226 chandransh 430
	For all COD orders, if the order is in INIT, SUBMITTED_FOR_PROCESSING or INVENTORY_LOW state, it does the following:
431
		1. Cancels the reservation of the item in the warehouse.
432
		2. Marks the current order as CANCELED.	
433
 
434
	In all cases, it updates the reason for cancellation or refund and the person who performed the action.
435
 
2614 chandransh 436
	Returns True if it is successful, False otherwise.
437
 
438
	Throws an exception if the order with the given id couldn't be found.
439
	*/
3226 chandransh 440
	bool refundOrder(1:i64 orderId, 2:string refundedBy, 3:string reason) throws (1:TransactionServiceException ex),
2688 chandransh 441
 
442
	/**
443
	Get all return orders created between the from and to dates for the given warehouse.
444
	Ignores the warehouse if it is passed as -1.
445
	*/
446
	list<ReturnOrder> getReturnOrders(1:i64 warehouseId, 2:i64 fromDate, 3:i64 toDate),
447
 
448
	/**
2700 chandransh 449
	Returns the ReturnOrder corresponding to the given id.
450
	Throws an exception if the return order with the given id couldn't be found.
451
	*/
452
	ReturnOrder getReturnOrder(1:i64 id) throws (1:TransactionServiceException ex),
453
 
454
	/**
2688 chandransh 455
	Marks the return order with the given id as processed. Raises an exception if no such return order exists. 
456
	*/
2819 chandransh 457
	void processReturn(1:i64 returnOrderId) throws (1:TransactionServiceException ex),
458
 
459
	/**
460
	Creates a purchase order corresponding to all the pending orders of the given warehouse.
461
	Returns the PO no. of the newly created purchase order. Returns -1 no new purchase order had to be created.
462
	*/
463
	i64 createPurchaseOrder(1:i64 warehouseId) throws (1:TransactionServiceException ex)
1115 chandransh 464
}