Subversion Repositories SmartDukaan

Rev

Rev 10531 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9787 manish.sha 1
package com.amazonaws.mws.samples;
2
 
3
import in.shop2020.model.v1.catalog.Amazonlisted;
4
import in.shop2020.model.v1.catalog.CatalogServiceException;
5
import in.shop2020.model.v1.catalog.Item;
6
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
7
import in.shop2020.model.v1.inventory.InventoryServiceException;
8
import in.shop2020.model.v1.inventory.Vendor;
9
import in.shop2020.model.v1.inventory.VendorItemPricing;
10
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
11
import in.shop2020.model.v1.order.TransactionService.Client;
12
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.InventoryClient;
14
import in.shop2020.thrift.clients.TransactionClient;
15
 
16
import java.io.File;
17
import java.io.FileInputStream;
18
import java.io.FileNotFoundException;
19
import java.io.FileOutputStream;
20
import java.io.FileReader;
21
import java.io.IOException;
22
import java.io.OutputStream;
23
import java.text.ParseException;
24
import java.text.SimpleDateFormat;
25
import java.util.ArrayList;
26
import java.util.Calendar;
27
import java.util.Date;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.Map.Entry;
32
import java.util.TimeZone;
33
 
34
import javax.xml.bind.JAXBContext;
35
import javax.xml.bind.JAXBException;
36
import javax.xml.bind.Unmarshaller;
37
 
38
import org.apache.commons.io.IOUtils;
39
import org.apache.poi.hssf.usermodel.HSSFRow;
40
import org.apache.poi.hssf.usermodel.HSSFSheet;
41
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
42
import org.apache.thrift.TException;
43
 
44
import com.amazonaws.mws.model.AmazonEnvelope;
45
import com.amazonaws.mws.model.FulfillmentData;
46
import com.amazonaws.mws.model.Message;
47
import com.amazonaws.mws.model.Order;
48
 
49
import au.com.bytecode.opencsv.CSVReader;
50
 
51
public class XMLFileParser {
52
	public static void main(String... args){
53
		String toFind = "<AmazonEnvelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"amzn-envelope.xsd\">";
54
		String toReplace = "<AmazonEnvelope xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\">";
55
		File orderReportFile = new File("/home/amazonorderreport.xml");
56
		String content = "";
57
		try {
58
			content = IOUtils.toString(new FileInputStream(orderReportFile));
59
		} catch (FileNotFoundException e1) {
60
			// TODO Auto-generated catch block
61
			e1.printStackTrace();
62
		} catch (IOException e1) {
63
			// TODO Auto-generated catch block
64
			e1.printStackTrace();
65
		}
66
		content = content.replaceAll(toFind, toReplace);
67
		try {
68
			IOUtils.write(content, new FileOutputStream(orderReportFile));
69
		} catch (FileNotFoundException e1) {
70
			e1.printStackTrace();
71
		} catch (IOException e1) {
72
			e1.printStackTrace();
73
		}
74
 
75
		JAXBContext jc = null;
76
		Unmarshaller unmarshaller = null;
77
		AmazonEnvelope amazonOrderData = null;
78
		try {
79
			jc = JAXBContext.newInstance(AmazonEnvelope.class);
80
			unmarshaller = jc.createUnmarshaller();
81
			amazonOrderData = (AmazonEnvelope)unmarshaller.unmarshal(orderReportFile);
82
		} catch (JAXBException e1) {
83
			e1.printStackTrace();
84
		}
85
 
86
		/*CSVReader orderreportreader = null;*/
87
		CSVReader inventoryhealthreportreader = null;
88
		try {
89
			/*orderreportreader = new CSVReader(new FileReader("/home/amazonorderreport.csv"),'\t');*/
90
			inventoryhealthreportreader = new CSVReader(new FileReader("/home/inventoryhealthreport.csv"),'\t');
91
		} catch (FileNotFoundException e) {
92
			// TODO Auto-generated catch block
93
			e.printStackTrace();
94
		}
95
		String [] nextLine;
96
		try {
97
			int count =1;
98
			Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
99
 
100
			if(amazonOrderData!=null){
101
				List<Message> orderMessageList = amazonOrderData.getMessage();
102
				for(Message orderMessage : orderMessageList){
103
					Order amazonOrder = orderMessage.getOrder();
104
					FulfillmentData orderFullfillmentData = amazonOrder.getFulfillmentData();
105
					if("Amazon.in".equalsIgnoreCase(amazonOrder.getSalesChannel()) && "Amazon".equalsIgnoreCase(orderFullfillmentData.getFulfillmentChannel())){
106
						SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
107
						istFormatter .setLenient(false);
108
						TimeZone zone= TimeZone.getTimeZone("GMT");
109
						istFormatter.setTimeZone(zone);
110
						Date date = istFormatter.parse(amazonOrder.getPurchaseDate().toString());
111
						SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
112
						Date date_key = dateFormat.parse(dateFormat.format(date));
113
						System.out.println("Order Details " + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
114
						Long itemid = Long.parseLong(amazonOrder.getOrderItem().get(0).getSKU().replaceAll("FBA",""));
115
						Integer qty=0;
116
						if(amazonOrder.getOrderItem().get(0).getQuantity()!=0){
117
							qty = new Integer(amazonOrder.getOrderItem().get(0).getQuantity());
118
						}
119
						Float itemSale = null;
120
						if(amazonOrder.getOrderItem().get(0).getItemPrice()!=null && amazonOrder.getOrderItem().get(0).getItemPrice().getComponent()!=null && amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().size()>0){
121
							if(amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().get(0).getAmount().getValue()!=0){
122
								itemSale = new Float(amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().get(0).getAmount().getValue());
123
							}
124
							else{
125
								continue;
126
							}
127
						}
128
 
129
						else{
130
							continue;
131
						}
132
 
133
						Float itemDiscount; 
134
						if(amazonOrder.getOrderItem().get(0).getPromotion()!=null){
135
							if(amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount()!=null && amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount().floatValue()!=0.0f){
136
								itemDiscount = amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount();
137
							}
138
							else{
139
								itemDiscount = new Float(0);
140
							}
141
						}
142
						else{
143
							itemDiscount = new Float(0);
144
						}
145
 
146
						if(("Cancelled").equalsIgnoreCase(amazonOrder.getOrderStatus()) || ("Cancelled").equalsIgnoreCase(amazonOrder.getOrderItem().get(0).getItemStatus())){
147
							itemSale = (float) 0; 
148
							itemDiscount = (float) 0;
149
							qty = 0;
150
						}
151
						if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
152
							if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
153
								FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
154
								if(itemDiscount!=0){
155
									fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
156
									fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
157
								}
158
								else{
159
									fbaSalesSnapshot.setPromotionOrderCount(0);
160
									fbaSalesSnapshot.setTotalPromotionSale((float) 0);
161
								}
162
								fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
163
								fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
164
								orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
165
							}
166
							else{
167
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
168
								fbaSalesSnapshot.setTotalOrderCount(qty);
169
								fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
170
								if(itemDiscount!=0){
171
									fbaSalesSnapshot.setPromotionOrderCount(qty);
172
									fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
173
								}
174
								else{
175
									fbaSalesSnapshot.setPromotionOrderCount(0);
176
									fbaSalesSnapshot.setTotalPromotionSale((float) 0);
177
								}
178
								orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
179
							}
180
						}
181
						else{
182
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
183
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
184
							fbaSalesSnapshot.setTotalOrderCount(qty);
185
							fbaSalesSnapshot.setTotalSale(itemSale);
186
							if(itemDiscount!=0){
187
								fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
188
								fbaSalesSnapshot.setPromotionOrderCount(qty);
189
							}
190
							else{
191
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
192
								fbaSalesSnapshot.setPromotionOrderCount(0);
193
							}
194
							ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
195
							orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
196
						}
197
					}
198
				}
199
			}
200
			InventoryClient inventoryServiceClient = null;
201
			TransactionClient transactionServiceClient = null;
202
			CatalogClient catalogServiceClient = null;
203
			try {
204
				inventoryServiceClient = new InventoryClient();
205
				transactionServiceClient = new TransactionClient();
10531 vikram.rag 206
				//catalogServiceClient = new CatalogClient();
10530 vikram.rag 207
				catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
9787 manish.sha 208
			} catch (Exception e) {
209
				// TODO Auto-generated catch block
210
				e.printStackTrace();
211
			}	
212
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
213
			in.shop2020.model.v1.order.TransactionService.Client transactionClient   = transactionServiceClient.getClient();
214
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
215
			SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
216
			//Date date_today = dateFormat.parse(dateFormat.format(new Date()));
217
			List<Date> dates = new ArrayList<Date>();
218
			Calendar cal = Calendar.getInstance();
219
			cal.add(Calendar.DATE, -1);
220
			Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
221
			cal.add(Calendar.DATE, -5);
222
			Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
223
			//System.out.println("Start Date = " + date_start);
224
			//System.out.println("End Date = " + date_end);
225
			Date d = date_start;
226
			while(!d.equals(date_end)){
227
				cal.setTime(d);
228
				cal.add(Calendar.DATE,1);
229
				d = cal.getTime();
230
				dates.add(d);
231
			}
232
			List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
233
			for(Date date:dates){
234
				if(nonzeroFbaInventorySnapshotlist!=null){
235
					for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
236
						if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date) ){ 
237
							if(!orderDateItemIdFbaSaleSnapshotMap.get(date).containsKey(amazonFbaInventory.getItem_id())){
238
								Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
239
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
240
								fbaSalesSnapshot.setTotalOrderCount(0);
241
								fbaSalesSnapshot.setPromotionOrderCount(0);
242
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
243
								fbaSalesSnapshot.setTotalSale((float) 0);
244
								ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
245
								orderDateItemIdFbaSaleSnapshotMap.get(date).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
246
							}
247
 
248
						}
249
						else{
250
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
251
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
252
							fbaSalesSnapshot.setTotalOrderCount(0);
253
							fbaSalesSnapshot.setPromotionOrderCount(0);
254
							fbaSalesSnapshot.setTotalPromotionSale((float) 0);
255
							fbaSalesSnapshot.setTotalSale((float) 0);
256
							ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
257
							orderDateItemIdFbaSaleSnapshotMap.put(date,ItemIdFbaSaleSnapshotMap);
258
						}
259
					}
260
				}
261
				else{
262
					System.out.println("No inventory in FBA");
263
				}
264
			}
265
			Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
266
			Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
267
			Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
268
			Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
269
			count=1;
270
			while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
271
				try{
272
					if(count!=1){
273
						//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
274
						SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
275
						istFormatter .setLenient(false);
276
						TimeZone zone= TimeZone.getTimeZone("GMT");
277
						istFormatter.setTimeZone(zone);
278
						Date date = istFormatter.parse(nextLine[0]);
279
						Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
280
						Double ourPrice = null;
281
						Double minFBAPrice= null;
282
						Double minMFNPrice= null;
283
						Double salePrice= null; 
284
						if(nextLine[30].length() >0){
285
							ourPrice = Double.parseDouble(nextLine[30]);
286
							if(itemIdOurPriceMap.containsKey(item_id)){
287
								if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
288
									PriceAtDate priceAtDate= new PriceAtDate();
289
									priceAtDate.setDate(date);
290
									priceAtDate.setPrice(ourPrice);
291
									itemIdOurPriceMap.put(item_id,priceAtDate);
292
								}
293
							}
294
							else{	
295
								PriceAtDate priceAtDate= new PriceAtDate();
296
								priceAtDate.setDate(date);
297
								priceAtDate.setPrice(ourPrice);
298
								itemIdOurPriceMap.put(item_id,priceAtDate);
299
							}
300
						}
301
						if(nextLine[31].length() >0){
302
							salePrice = Double.parseDouble(nextLine[31]);
303
							if(itemIdSalePriceMap.containsKey(item_id) ){
304
								if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
305
									PriceAtDate priceAtDate= new PriceAtDate();
306
									priceAtDate.setDate(date);
307
									priceAtDate.setPrice(salePrice);
308
									itemIdSalePriceMap.put(item_id,priceAtDate);
309
								}
310
							}
311
							else{	
312
								PriceAtDate priceAtDate= new PriceAtDate();
313
								priceAtDate.setDate(date);
314
								priceAtDate.setPrice(salePrice);
315
								itemIdSalePriceMap.put(item_id,priceAtDate);
316
							}
317
						}
318
						if(nextLine[32].length() >0){
319
							minFBAPrice = Double.parseDouble(nextLine[32]);
320
							if(itemIdminFBAPriceMap.containsKey(item_id)){
321
								if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
322
									PriceAtDate priceAtDate= new PriceAtDate();
323
									priceAtDate.setDate(date);
324
									priceAtDate.setPrice(minFBAPrice);
325
									itemIdminFBAPriceMap.put(item_id,priceAtDate);
326
								}
327
							}
328
							else{	
329
								PriceAtDate priceAtDate= new PriceAtDate();
330
								priceAtDate.setDate(date);
331
								priceAtDate.setPrice(minFBAPrice);
332
								itemIdminFBAPriceMap.put(item_id,priceAtDate);
333
							}
334
						}
335
						if(nextLine[34].length() >0){
336
							minMFNPrice = Double.parseDouble(nextLine[34]);
337
							if(itemIdminMFNPriceMap.containsKey(item_id)){
338
								if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
339
									PriceAtDate priceAtDate= new PriceAtDate();
340
									priceAtDate.setDate(date);
341
									priceAtDate.setPrice(minMFNPrice);
342
									itemIdminMFNPriceMap.put(item_id,priceAtDate);
343
								}
344
							}
345
							else{	
346
								PriceAtDate priceAtDate= new PriceAtDate();
347
								priceAtDate.setDate(date);
348
								priceAtDate.setPrice(minMFNPrice);
349
								itemIdminMFNPriceMap.put(item_id,priceAtDate);
350
							}
351
						}
352
					}
353
				}
354
				catch(Exception e){
355
					e.printStackTrace();
356
				}
357
				count++;
358
			}
359
			boolean oos;
9802 manish.sha 360
			List<AmazonFbaSalesSnapshot> fbaSalesSnapShotList = new ArrayList<AmazonFbaSalesSnapshot>();
9787 manish.sha 361
			for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
362
				Date orderDate = entry.getKey();
363
				for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
364
					//System.out.println("Item ID is " + entry1.getKey());
12619 kshitij.so 365
				    Long inventory = 0l;
366
					//Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
9787 manish.sha 367
 
368
					if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
369
						oos=true;
370
					}
371
					else{
372
						oos=false;
373
					}
374
					Long item_id = entry1.getKey();
375
					Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
376
					if(amazon_item.getItemid()==0){
377
						continue;
378
					}
379
					//System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
380
					AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
381
					amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
382
					amazonfbasalessnapshot.setItem_id(entry1.getKey());
383
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
384
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
385
					amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
386
					amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
387
					amazonfbasalessnapshot.setIsOutOfStock(oos);
388
					if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
389
						amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
390
						amazonfbasalessnapshot.setSalePriceSnapshotDate(itemIdSalePriceMap.get(item_id).getDate().getTime());
391
					}
392
					else{
393
						amazonfbasalessnapshot.setSalePrice(0.0);
394
						amazonfbasalessnapshot.setSalePriceSnapshotDate(0);
395
					}
396
					if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
397
						amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
398
						amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(itemIdminMFNPriceMap.get(item_id).getDate().getTime());
399
					}
400
					else{
401
						amazonfbasalessnapshot.setMinMfnPrice(0.0);
402
						amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(0);
403
					}
404
					if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
405
						amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
406
						amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(itemIdminFBAPriceMap.get(item_id).getDate().getTime());
407
					}
408
					else{
409
						amazonfbasalessnapshot.setMinFbaPrice(0.0);
410
						amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(0);
411
					}
412
					if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
413
						amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
414
						amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
415
					}
416
					else{
417
						amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
418
						amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
419
					}
420
					if(amazonfbasalessnapshot.getTotalOrderCount() > 0){
421
						Date date =  new Date(amazonfbasalessnapshot.getDateOfSale());
422
						SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); 
423
						System.out.println(" Item details are " + sdf.format(date) + " "+ amazonfbasalessnapshot.getItem_id() + " " + amazonfbasalessnapshot.getTotalOrderCount());
424
					}
425
					amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
9802 manish.sha 426
					fbaSalesSnapShotList.add(amazonfbasalessnapshot);
9787 manish.sha 427
				}
428
			}
10529 vikram.rag 429
			try{
9802 manish.sha 430
			transactionServiceClient.getClient().bulkAddOrUpdateAmazonFbaSalesSnapshot(fbaSalesSnapShotList);
10529 vikram.rag 431
			}
432
			catch(Exception e){
433
				new TransactionClient().getClient().bulkAddOrUpdateAmazonFbaSalesSnapshot(fbaSalesSnapShotList);
434
			}
9787 manish.sha 435
		} catch (IOException e) {
436
			// TODO Auto-generated catch block
437
			e.printStackTrace();
438
		} catch (ParseException e) {
439
			// TODO Auto-generated catch block
440
			e.printStackTrace();
441
		} catch (TException e) {
442
			// TODO Auto-generated catch block
443
			e.printStackTrace();
444
		}
445
		catch (Exception e) {
446
			// TODO Auto-generated catch block
447
			e.printStackTrace();
448
		}
449
 
450
	}
451
 
452
	public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
453
		Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
454
		return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
455
 
456
	}
457
 
458
	public static Double getMinimumSalePriceOnAmazonFBA(AmazonFbaSalesSnapshot snapshot){
459
		if(snapshot.getMinFbaPrice() > snapshot.getMinMfnPrice()){
460
			return snapshot.getMinMfnPrice();
461
		}
462
		else{
463
			return snapshot.getMinFbaPrice();
464
		}
465
	}
466
 
467
}