Subversion Repositories SmartDukaan

Rev

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

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