Subversion Repositories SmartDukaan

Rev

Rev 9755 | Rev 9757 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9755 Rev 9756
Line 49... Line 49...
49
		}
49
		}
50
		String [] nextLine;
50
		String [] nextLine;
51
		try {
51
		try {
52
			int count =1;
52
			int count =1;
53
			Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
53
			Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
54
			while ((nextLine = orderreportreader.readNext()) != null) {
-
 
55
				try{
-
 
56
					if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
54
			if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
57
						SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
55
				SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
58
						istFormatter .setLenient(false);
56
				istFormatter .setLenient(false);
59
						TimeZone zone= TimeZone.getTimeZone("GMT");
57
				TimeZone zone= TimeZone.getTimeZone("GMT");
60
						istFormatter.setTimeZone(zone);
58
				istFormatter.setTimeZone(zone);
61
						Date date = istFormatter.parse(nextLine[2]);
59
				Date date = istFormatter.parse(nextLine[2]);
62
						SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
60
				SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
63
						Date date_key = dateFormat.parse(dateFormat.format(date));
61
				Date date_key = dateFormat.parse(dateFormat.format(date));
64
						System.out.println("Order Details " + nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
62
				System.out.println("Order Details " + nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
65
						Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
63
				Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
66
						Integer qty=0;
64
				Integer qty=0;
67
						if(nextLine[14].length()!=0){
65
				if(nextLine[14].length()!=0){
68
							qty = new Integer(nextLine[14]);
66
					qty = new Integer(nextLine[14]);
69
						}
-
 
70
						Float itemSale = null;
-
 
71
						if(nextLine[16].length()!=0){
-
 
72
							itemSale = new Float(nextLine[16]);
-
 
73
						}
-
 
74
						else{
-
 
75
							continue;
-
 
76
						}
-
 
77
						Float itemDiscount; 
-
 
78
						if(nextLine[22].length()!=0){
-
 
79
							itemDiscount = new Float(nextLine[22]);
-
 
80
						}
-
 
81
						else{
-
 
82
							itemDiscount = new Float(0);
-
 
83
						}
-
 
84
						if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[13].equalsIgnoreCase("Cancelled")){
-
 
85
							itemSale = (float) 0; 
-
 
86
							itemDiscount = (float) 0;
-
 
87
							qty = 0;
-
 
88
						}
-
 
89
						if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
-
 
90
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap;
-
 
91
							if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
-
 
92
								FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
-
 
93
								if(itemDiscount!=0){
-
 
94
									fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
-
 
95
									fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
-
 
96
								}
-
 
97
								fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
-
 
98
								fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
-
 
99
								ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
100
								ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
-
 
101
								orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
102
							}
-
 
103
							else{
-
 
104
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
105
								fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
106
								fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
-
 
107
								if(itemDiscount!=0){
-
 
108
									fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
109
									fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
110
								}
-
 
111
								else{
-
 
112
									fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
113
									fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
114
								}
-
 
115
								ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
116
								ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
-
 
117
								orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
118
							}
-
 
119
						}
-
 
120
						else{
-
 
121
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
122
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
123
							fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
124
							fbaSalesSnapshot.setTotalSale(itemSale);
-
 
125
							if(itemDiscount!=0){
-
 
126
								fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
127
								fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
128
							}
-
 
129
							else{
-
 
130
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
131
								fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
132
							}
-
 
133
							ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
-
 
134
							orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
135
						}
-
 
136
					}
-
 
137
				}
67
				}
138
				catch(Exception e){
68
				Float itemSale = null;
139
					e.printStackTrace();
69
				if(nextLine[16].length()!=0){
-
 
70
					itemSale = new Float(nextLine[16]);
140
				}
71
				}
-
 
72
				else{
141
				count++;
73
					continue;
142
			}
74
				}
143
			InventoryClient inventoryServiceClient = null;
75
				Float itemDiscount; 
144
			TransactionClient transactionServiceClient = null;
76
				if(nextLine[22].length()!=0){
145
			CatalogClient catalogServiceClient = null;
77
					itemDiscount = new Float(nextLine[22]);
146
			try {
78
				}
147
				inventoryServiceClient = new InventoryClient();
79
				else{
148
				transactionServiceClient = new TransactionClient();
-
 
149
				catalogServiceClient = new CatalogClient();
80
					itemDiscount = new Float(0);
-
 
81
				}
150
				//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
82
				if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[13].equalsIgnoreCase("Cancelled")){
151
			} catch (Exception e) {
83
					itemSale = (float) 0; 
152
				// TODO Auto-generated catch block
84
					itemDiscount = (float) 0;
153
				e.printStackTrace();
85
					qty = 0;
154
			}	
86
				}
155
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
156
			in.shop2020.model.v1.order.TransactionService.Client transactionClient   = transactionServiceClient.getClient();
-
 
157
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
87
				if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
158
			SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
88
					Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap;
159
			//Date date_today = dateFormat.parse(dateFormat.format(new Date()));
89
					if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
160
			List<Date> dates = new ArrayList<Date>();
-
 
161
			Calendar cal = Calendar.getInstance();
-
 
162
			cal.add(Calendar.DATE, -1);
-
 
163
			Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
90
						FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
164
			cal.add(Calendar.DATE, -5);
91
						if(itemDiscount!=0){
165
			Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
92
							fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
166
			System.out.println("Start Date = " + date_start);
93
							fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
167
			System.out.println("End Date = " + date_end);
-
 
168
			Date d = date_start;
-
 
169
			while(!d.equals(date_end)){
-
 
170
				cal.setTime(d);
-
 
171
				cal.add(Calendar.DATE,1);
-
 
172
				d = cal.getTime();
-
 
173
				dates.add(d);
-
 
174
			}
94
						}
175
			List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
95
						fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
176
			for(Date date:dates){
-
 
177
				if(nonzeroFbaInventorySnapshotlist!=null){
-
 
178
					for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
96
						fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
179
						if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date) ){ 
97
						ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
180
							if(!orderDateItemIdFbaSaleSnapshotMap.get(date).containsKey(amazonFbaInventory.getItem_id())){
98
						ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
181
								Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
99
						orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
100
					}
-
 
101
					else{
182
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
102
						FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
183
								fbaSalesSnapshot.setTotalOrderCount(0);
103
						fbaSalesSnapshot.setTotalOrderCount(qty);
184
								fbaSalesSnapshot.setPromotionOrderCount(0);
104
						fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
185
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
105
						if(itemDiscount!=0){
186
								fbaSalesSnapshot.setTotalSale((float) 0);
106
							fbaSalesSnapshot.setPromotionOrderCount(qty);
187
								ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
107
							fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
188
								orderDateItemIdFbaSaleSnapshotMap.get(date).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
-
 
189
							}
-
 
190
 
-
 
191
						}
108
						}
192
						else{
109
						else{
193
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
194
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
195
							fbaSalesSnapshot.setTotalOrderCount(0);
-
 
196
							fbaSalesSnapshot.setPromotionOrderCount(0);
110
							fbaSalesSnapshot.setPromotionOrderCount(0);
197
							fbaSalesSnapshot.setTotalPromotionSale((float) 0);
111
							fbaSalesSnapshot.setTotalPromotionSale((float) 0);
198
							fbaSalesSnapshot.setTotalSale((float) 0);
-
 
199
							ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
-
 
200
							orderDateItemIdFbaSaleSnapshotMap.put(date,ItemIdFbaSaleSnapshotMap);
-
 
201
						}
112
						}
-
 
113
						ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
114
						ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
-
 
115
						orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
202
					}
116
					}
203
				}
117
				}
204
				else{
118
				else{
-
 
119
					Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
120
					FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
205
					System.out.println("No inventory in FBA");
121
					fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
122
					fbaSalesSnapshot.setTotalSale(itemSale);
-
 
123
					if(itemDiscount!=0){
-
 
124
						fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
125
						fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
126
					}
-
 
127
					else{
-
 
128
						fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
129
						fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
130
					}
-
 
131
					ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
-
 
132
					orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
206
				}
133
				}
207
			}
134
			}
208
			Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
-
 
209
			Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
-
 
210
			Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
-
 
211
			Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
-
 
-
 
135
		}
212
			count=1;
136
		count++;
213
			while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
-
 
214
				try{
137
	}
215
					if(count!=1){
-
 
216
						//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
-
 
217
						SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
-
 
218
						istFormatter .setLenient(false);
-
 
219
						TimeZone zone= TimeZone.getTimeZone("GMT");
-
 
220
						istFormatter.setTimeZone(zone);
-
 
221
						Date date = istFormatter.parse(nextLine[0]);
-
 
222
						Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
-
 
223
						Double ourPrice = null;
138
	InventoryClient inventoryServiceClient = null;
224
						Double minFBAPrice= null;
139
	TransactionClient transactionServiceClient = null;
225
						Double minMFNPrice= null;
140
	CatalogClient catalogServiceClient = null;
226
						Double salePrice= null; 
141
	try {
227
						if(nextLine[30].length() >0){
-
 
228
							ourPrice = Double.parseDouble(nextLine[30]);
142
		inventoryServiceClient = new InventoryClient();
229
							if(itemIdOurPriceMap.containsKey(item_id)){
-
 
230
								if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
231
									PriceAtDate priceAtDate= new PriceAtDate();
143
		transactionServiceClient = new TransactionClient();
232
									priceAtDate.setDate(date);
144
		catalogServiceClient = new CatalogClient();
233
									priceAtDate.setPrice(ourPrice);
-
 
234
									itemIdOurPriceMap.put(item_id,priceAtDate);
145
		//catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
235
								}
-
 
236
							}
-
 
237
							else{	
146
	} catch (Exception e) {
238
								PriceAtDate priceAtDate= new PriceAtDate();
-
 
239
								priceAtDate.setDate(date);
147
		// TODO Auto-generated catch block
240
								priceAtDate.setPrice(ourPrice);
148
		e.printStackTrace();
241
								itemIdOurPriceMap.put(item_id,priceAtDate);
-
 
242
							}
-
 
243
						}
149
	}	
244
						if(nextLine[31].length() >0){
-
 
245
							salePrice = Double.parseDouble(nextLine[31]);
150
	in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
246
							if(itemIdSalePriceMap.containsKey(item_id) ){
151
	in.shop2020.model.v1.order.TransactionService.Client transactionClient   = transactionServiceClient.getClient();
247
								if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
152
	in.shop2020.model.v1.catalog.CatalogService.Client catalogClient   = catalogServiceClient.getClient();
248
									PriceAtDate priceAtDate= new PriceAtDate();
153
	SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
249
									priceAtDate.setDate(date);
-
 
250
									priceAtDate.setPrice(salePrice);
-
 
251
									itemIdSalePriceMap.put(item_id,priceAtDate);
154
	//Date date_today = dateFormat.parse(dateFormat.format(new Date()));
252
								}
-
 
253
							}
-
 
254
							else{	
-
 
255
								PriceAtDate priceAtDate= new PriceAtDate();
155
	List<Date> dates = new ArrayList<Date>();
256
								priceAtDate.setDate(date);
156
	Calendar cal = Calendar.getInstance();
257
								priceAtDate.setPrice(salePrice);
157
	cal.add(Calendar.DATE, -1);
258
								itemIdSalePriceMap.put(item_id,priceAtDate);
158
	Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
259
							}
-
 
260
						}
-
 
261
						if(nextLine[32].length() >0){
159
	cal.add(Calendar.DATE, -5);
262
							minFBAPrice = Double.parseDouble(nextLine[32]);
160
	Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
263
							if(itemIdminFBAPriceMap.containsKey(item_id)){
161
	System.out.println("Start Date = " + date_start);
264
								if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
162
	System.out.println("End Date = " + date_end);
265
									PriceAtDate priceAtDate= new PriceAtDate();
163
	Date d = date_start;
266
									priceAtDate.setDate(date);
164
	while(!d.equals(date_end)){
267
									priceAtDate.setPrice(minFBAPrice);
165
		cal.setTime(d);
268
									itemIdminFBAPriceMap.put(item_id,priceAtDate);
166
		cal.add(Calendar.DATE,1);
269
								}
167
		d = cal.getTime();
270
							}
168
		dates.add(d);
271
							else{	
169
	}
272
								PriceAtDate priceAtDate= new PriceAtDate();
170
	List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
273
								priceAtDate.setDate(date);
171
	for(Date date:dates){
274
								priceAtDate.setPrice(minFBAPrice);
172
		if(nonzeroFbaInventorySnapshotlist!=null){
275
								itemIdminFBAPriceMap.put(item_id,priceAtDate);
173
			for(AmazonFbaInventorySnapshot amazonFbaInventory:nonzeroFbaInventorySnapshotlist){
276
							}
-
 
277
						}
-
 
278
						if(nextLine[34].length() >0){
-
 
279
							minMFNPrice = Double.parseDouble(nextLine[34]);
174
				if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date) ){ 
280
							if(itemIdminMFNPriceMap.containsKey(item_id)){
175
					if(!orderDateItemIdFbaSaleSnapshotMap.get(date).containsKey(amazonFbaInventory.getItem_id())){
281
								if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
176
						Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
282
									PriceAtDate priceAtDate= new PriceAtDate();
177
						FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
283
									priceAtDate.setDate(date);
178
						fbaSalesSnapshot.setTotalOrderCount(0);
284
									priceAtDate.setPrice(minMFNPrice);
179
						fbaSalesSnapshot.setPromotionOrderCount(0);
285
									itemIdminMFNPriceMap.put(item_id,priceAtDate);
-
 
286
								}
-
 
287
							}
-
 
288
							else{	
-
 
289
								PriceAtDate priceAtDate= new PriceAtDate();
180
						fbaSalesSnapshot.setTotalPromotionSale((float) 0);
290
								priceAtDate.setDate(date);
181
						fbaSalesSnapshot.setTotalSale((float) 0);
291
								priceAtDate.setPrice(minMFNPrice);
182
						ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
292
								itemIdminMFNPriceMap.put(item_id,priceAtDate);
183
						orderDateItemIdFbaSaleSnapshotMap.get(date).put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
293
							}
-
 
294
						}
-
 
295
					}
184
					}
-
 
185
 
296
				}
186
				}
297
				catch(Exception e){
187
				else{
-
 
188
					Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
189
					FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
298
					e.printStackTrace();
190
					fbaSalesSnapshot.setTotalOrderCount(0);
-
 
191
					fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
192
					fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
193
					fbaSalesSnapshot.setTotalSale((float) 0);
-
 
194
					ItemIdFbaSaleSnapshotMap.put(amazonFbaInventory.getItem_id(),fbaSalesSnapshot);
-
 
195
					orderDateItemIdFbaSaleSnapshotMap.put(date,ItemIdFbaSaleSnapshotMap);
299
				}
196
				}
300
				count++;
-
 
301
			}
197
			}
-
 
198
		}
302
			boolean oos;
199
		else{
303
			for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
-
 
304
				Date orderDate = entry.getKey();
200
			System.out.println("No inventory in FBA");
-
 
201
		}
-
 
202
	}
305
				for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
203
	Map<Long,PriceAtDate> itemIdOurPriceMap = new HashMap<Long,PriceAtDate>();
306
					System.out.println("Item ID is " + entry1.getKey());
204
	Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
307
					Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
205
	Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
308
 
-
 
309
					if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
206
	Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
310
						oos=true;
207
	count=1;
-
 
208
	while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
311
					}
209
		try{
312
					else{
210
			if(count!=1){
-
 
211
				//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
-
 
212
				SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
313
						oos=false;
213
				istFormatter .setLenient(false);
314
					}
214
				TimeZone zone= TimeZone.getTimeZone("GMT");
315
					Long item_id = entry1.getKey();
215
				istFormatter.setTimeZone(zone);
316
					Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
216
				Date date = istFormatter.parse(nextLine[0]);
317
					if(amazon_item.getItemid()==0){
217
				Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
318
						continue;
218
				Double ourPrice = null;
319
					}
219
				Double minFBAPrice= null;
320
					System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
-
 
321
					AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
220
				Double minMFNPrice= null;
322
					amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
221
				Double salePrice= null; 
323
					amazonfbasalessnapshot.setItem_id(entry1.getKey());
222
				if(nextLine[30].length() >0){
324
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
223
					ourPrice = Double.parseDouble(nextLine[30]);
325
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
224
					if(itemIdOurPriceMap.containsKey(item_id)){
326
					amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
225
						if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
327
					amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
226
							PriceAtDate priceAtDate= new PriceAtDate();
328
					amazonfbasalessnapshot.setIsOutOfStock(oos);
227
							priceAtDate.setDate(date);
329
					if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
228
							priceAtDate.setPrice(ourPrice);
330
						amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
229
							itemIdOurPriceMap.put(item_id,priceAtDate);
331
						amazonfbasalessnapshot.setSalePriceSnapshotDate(itemIdSalePriceMap.get(item_id).getDate().getTime());
-
 
-
 
230
						}
332
					}
231
					}
333
					else{
232
					else{	
-
 
233
						PriceAtDate priceAtDate= new PriceAtDate();
-
 
234
						priceAtDate.setDate(date);
334
						amazonfbasalessnapshot.setSalePrice(0.0);
235
						priceAtDate.setPrice(ourPrice);
335
						amazonfbasalessnapshot.setSalePriceSnapshotDate(0);
236
						itemIdOurPriceMap.put(item_id,priceAtDate);
336
					}
237
					}
-
 
238
				}
-
 
239
				if(nextLine[31].length() >0){
-
 
240
					salePrice = Double.parseDouble(nextLine[31]);
337
					if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
241
					if(itemIdSalePriceMap.containsKey(item_id) ){
338
						amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
242
						if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
243
							PriceAtDate priceAtDate= new PriceAtDate();
-
 
244
							priceAtDate.setDate(date);
-
 
245
							priceAtDate.setPrice(salePrice);
339
						amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(itemIdminMFNPriceMap.get(item_id).getDate().getTime());
246
							itemIdSalePriceMap.put(item_id,priceAtDate);
-
 
247
						}
340
					}
248
					}
341
					else{
249
					else{	
342
						amazonfbasalessnapshot.setMinMfnPrice(0.0);
250
						PriceAtDate priceAtDate= new PriceAtDate();
-
 
251
						priceAtDate.setDate(date);
-
 
252
						priceAtDate.setPrice(salePrice);
343
						amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(0);
253
						itemIdSalePriceMap.put(item_id,priceAtDate);
344
					}
254
					}
-
 
255
				}
-
 
256
				if(nextLine[32].length() >0){
-
 
257
					minFBAPrice = Double.parseDouble(nextLine[32]);
345
					if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
258
					if(itemIdminFBAPriceMap.containsKey(item_id)){
346
						amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
259
						if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
260
							PriceAtDate priceAtDate= new PriceAtDate();
-
 
261
							priceAtDate.setDate(date);
-
 
262
							priceAtDate.setPrice(minFBAPrice);
347
						amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(itemIdminFBAPriceMap.get(item_id).getDate().getTime());
263
							itemIdminFBAPriceMap.put(item_id,priceAtDate);
-
 
264
						}
348
					}
265
					}
349
					else{
266
					else{	
-
 
267
						PriceAtDate priceAtDate= new PriceAtDate();
-
 
268
						priceAtDate.setDate(date);
350
						amazonfbasalessnapshot.setMinFbaPrice(0.0);
269
						priceAtDate.setPrice(minFBAPrice);
351
						amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(0);
270
						itemIdminFBAPriceMap.put(item_id,priceAtDate);
352
					}
271
					}
-
 
272
				}
-
 
273
				if(nextLine[34].length() >0){
-
 
274
					minMFNPrice = Double.parseDouble(nextLine[34]);
353
					if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
275
					if(itemIdminMFNPriceMap.containsKey(item_id)){
354
						amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
276
						if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
277
							PriceAtDate priceAtDate= new PriceAtDate();
-
 
278
							priceAtDate.setDate(date);
-
 
279
							priceAtDate.setPrice(minMFNPrice);
355
						amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
280
							itemIdminMFNPriceMap.put(item_id,priceAtDate);
-
 
281
						}
356
					}
282
					}
357
					else{
283
					else{	
-
 
284
						PriceAtDate priceAtDate= new PriceAtDate();
-
 
285
						priceAtDate.setDate(date);
358
						amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
286
						priceAtDate.setPrice(minMFNPrice);
359
						amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
287
						itemIdminMFNPriceMap.put(item_id,priceAtDate);
360
					}
288
					}
361
					amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
-
 
362
					transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
-
 
363
				}
289
				}
364
			}
290
			}
365
		} catch (IOException e) {
-
 
366
			// TODO Auto-generated catch block
-
 
367
			e.printStackTrace();
-
 
368
		} catch (ParseException e) {
-
 
369
			// TODO Auto-generated catch block
-
 
370
			e.printStackTrace();
-
 
371
		} catch (TException e) {
-
 
372
			// TODO Auto-generated catch block
-
 
373
			e.printStackTrace();
-
 
374
		}
291
		}
375
		catch (Exception e) {
292
		catch(Exception e){
376
			// TODO Auto-generated catch block
-
 
377
			e.printStackTrace();
293
			e.printStackTrace();
378
		}
294
		}
-
 
295
		count++;
-
 
296
	}
-
 
297
	boolean oos;
-
 
298
	for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
-
 
299
		Date orderDate = entry.getKey();
-
 
300
		for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
-
 
301
			System.out.println("Item ID is " + entry1.getKey());
-
 
302
			Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
379
 
303
 
-
 
304
			if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
-
 
305
				oos=true;
-
 
306
			}
-
 
307
			else{
-
 
308
				oos=false;
-
 
309
			}
-
 
310
			Long item_id = entry1.getKey();
-
 
311
			Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
312
			if(amazon_item.getItemid()==0){
-
 
313
				continue;
-
 
314
			}
-
 
315
			System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
-
 
316
			AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
-
 
317
			amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
-
 
318
			amazonfbasalessnapshot.setItem_id(entry1.getKey());
-
 
319
			amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
-
 
320
			amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
-
 
321
			amazonfbasalessnapshot.setTotalSale(entry1.getValue().getTotalSale());
-
 
322
			amazonfbasalessnapshot.setPromotionSale(entry1.getValue().getTotalPromotionSale());
-
 
323
			amazonfbasalessnapshot.setIsOutOfStock(oos);
-
 
324
			if(itemIdSalePriceMap.containsKey(item_id) && itemIdSalePriceMap.get(item_id).getPrice()!=0){
-
 
325
				amazonfbasalessnapshot.setSalePrice(itemIdSalePriceMap.get(item_id).getPrice());
-
 
326
				amazonfbasalessnapshot.setSalePriceSnapshotDate(itemIdSalePriceMap.get(item_id).getDate().getTime());
-
 
327
			}
-
 
328
			else{
-
 
329
				amazonfbasalessnapshot.setSalePrice(0.0);
-
 
330
				amazonfbasalessnapshot.setSalePriceSnapshotDate(0);
-
 
331
			}
-
 
332
			if(itemIdminMFNPriceMap.containsKey(item_id) && itemIdminMFNPriceMap.get(item_id).getPrice()!=0){
-
 
333
				amazonfbasalessnapshot.setMinMfnPrice(itemIdminMFNPriceMap.get(item_id).getPrice());
-
 
334
				amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(itemIdminMFNPriceMap.get(item_id).getDate().getTime());
-
 
335
			}
-
 
336
			else{
-
 
337
				amazonfbasalessnapshot.setMinMfnPrice(0.0);
-
 
338
				amazonfbasalessnapshot.setMinMfnPriceSnapshotDate(0);
-
 
339
			}
-
 
340
			if(itemIdminFBAPriceMap.containsKey(item_id) && itemIdminFBAPriceMap.get(item_id).getPrice()!=0){
-
 
341
				amazonfbasalessnapshot.setMinFbaPrice(itemIdminFBAPriceMap.get(item_id).getPrice());
-
 
342
				amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(itemIdminFBAPriceMap.get(item_id).getDate().getTime());
-
 
343
			}
-
 
344
			else{
-
 
345
				amazonfbasalessnapshot.setMinFbaPrice(0.0);
-
 
346
				amazonfbasalessnapshot.setMinFbaPriceSnapshotDate(0);
-
 
347
			}
-
 
348
			if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
-
 
349
				amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
-
 
350
				amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
-
 
351
			}
-
 
352
			else{
-
 
353
				amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
-
 
354
				amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
-
 
355
			}
-
 
356
			amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
-
 
357
			transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
-
 
358
		}
380
	}
359
	}
-
 
360
} catch (IOException e) {
-
 
361
	// TODO Auto-generated catch block
-
 
362
	e.printStackTrace();
-
 
363
} catch (ParseException e) {
-
 
364
	// TODO Auto-generated catch block
-
 
365
	e.printStackTrace();
-
 
366
} catch (TException e) {
-
 
367
	// TODO Auto-generated catch block
-
 
368
	e.printStackTrace();
-
 
369
}
-
 
370
catch (Exception e) {
-
 
371
	// TODO Auto-generated catch block
-
 
372
	e.printStackTrace();
-
 
373
}
381
 
374
 
382
	public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
-
 
383
		Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
-
 
384
		return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
-
 
-
 
375
}
385
 
376
 
386
	}
-
 
-
 
377
public static Double getPercentageDifferenceFromMinimumPrice(AmazonFbaSalesSnapshot snapshot){
-
 
378
	Double minPrice = getMinimumSalePriceOnAmazonFBA(snapshot);
-
 
379
	return (((minPrice - snapshot.getOurPrice())/snapshot.getOurPrice())*100);
387
 
380
 
-
 
381
}
-
 
382
 
388
	public static Double getMinimumSalePriceOnAmazonFBA(AmazonFbaSalesSnapshot snapshot){
383
public static Double getMinimumSalePriceOnAmazonFBA(AmazonFbaSalesSnapshot snapshot){
389
		if(snapshot.getMinFbaPrice() > snapshot.getMinMfnPrice()){
384
	if(snapshot.getMinFbaPrice() > snapshot.getMinMfnPrice()){
390
			return snapshot.getMinMfnPrice();
385
		return snapshot.getMinMfnPrice();
391
		}
-
 
392
		else{
-
 
393
			return snapshot.getMinFbaPrice();
-
 
394
		}
-
 
395
	}
386
	}
-
 
387
	else{
-
 
388
		return snapshot.getMinFbaPrice();
-
 
389
	}
-
 
390
}
396
 
391
 
397
}
392
}