Subversion Repositories SmartDukaan

Rev

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

Rev 8825 Rev 8826
Line 236... Line 236...
236
				String [] nextLine;
236
				String [] nextLine;
237
				try {
237
				try {
238
					int count =1;
238
					int count =1;
239
					Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
239
					Map<Date,Map<Long,FbaSalesSnapshot>> orderDateItemIdFbaSaleSnapshotMap = new HashMap<Date,Map<Long,FbaSalesSnapshot>>();
240
					while ((nextLine = orderreportreader.readNext()) != null) {
240
					while ((nextLine = orderreportreader.readNext()) != null) {
-
 
241
						try{
241
						if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
242
							if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
242
							SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
243
								SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
243
							istFormatter .setLenient(false);
244
								istFormatter .setLenient(false);
244
							TimeZone zone= TimeZone.getTimeZone("GMT");
245
								TimeZone zone= TimeZone.getTimeZone("GMT");
245
							istFormatter.setTimeZone(zone);
246
								istFormatter.setTimeZone(zone);
246
							Date date = istFormatter.parse(nextLine[2]);
247
								Date date = istFormatter.parse(nextLine[2]);
247
							SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
248
								SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
248
							Date date_key = dateFormat.parse(dateFormat.format(date));
249
								Date date_key = dateFormat.parse(dateFormat.format(date));
249
							System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
250
								System.out.println(nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
250
							Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
251
								Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
251
							Integer qty=0;
252
								Integer qty=0;
252
							if(nextLine[14].length()!=0){
253
								if(nextLine[14].length()!=0){
253
								qty = new Integer(nextLine[14]);
254
									qty = new Integer(nextLine[14]);
254
							}
255
								}
255
							Float itemSale = null;
256
								Float itemSale = null;
256
							if(nextLine[16].length()!=0){
257
								if(nextLine[16].length()!=0){
257
								itemSale = new Float(nextLine[16]);
258
									itemSale = new Float(nextLine[16]);
258
							}
259
								}
259
							else{
260
								else{
260
								continue;
261
									continue;
261
							}
262
								}
262
							Float itemDiscount; 
263
								Float itemDiscount; 
263
							if(nextLine[22].length()!=0){
264
								if(nextLine[22].length()!=0){
264
								itemDiscount = new Float(nextLine[22]);
265
									itemDiscount = new Float(nextLine[22]);
265
							}
266
								}
266
							else{
267
								else{
267
								itemDiscount = new Float(0);
268
									itemDiscount = new Float(0);
268
							}
269
								}
269
							if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[4].equalsIgnoreCase("Cancelled")){
270
								if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[4].equalsIgnoreCase("Cancelled")){
270
								itemSale = (float) 0; 
271
									itemSale = (float) 0; 
271
								itemDiscount = (float) 0;
272
									itemDiscount = (float) 0;
272
								qty = 0;
273
									qty = 0;
273
							}
274
								}
274
							if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
275
								if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
275
								if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
276
									if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
276
									FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
277
										FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
277
									if(itemDiscount!=0){
278
										if(itemDiscount!=0){
278
										fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
279
											fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
279
										fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
280
											fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
-
 
281
										}
-
 
282
										fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
-
 
283
										fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
-
 
284
										orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
-
 
285
									}
-
 
286
									else{
-
 
287
										FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
288
										fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
289
										fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
-
 
290
										if(itemDiscount!=0){
-
 
291
											fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
292
											fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
293
										}
-
 
294
										else{
-
 
295
											fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
296
											fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
297
										}
-
 
298
										orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
280
									}
299
									}
281
									fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
-
 
282
									fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
-
 
283
									orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
-
 
284
								}
300
								}
285
								else{
301
								else{
-
 
302
									Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
286
									FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
303
									FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
287
									fbaSalesSnapshot.setTotalOrderCount(qty);
304
									fbaSalesSnapshot.setTotalOrderCount(qty);
288
									fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
305
									fbaSalesSnapshot.setTotalSale(itemSale);
289
									if(itemDiscount!=0){
306
									if(itemDiscount!=0){
290
										fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
291
										fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
307
										fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
308
										fbaSalesSnapshot.setPromotionOrderCount(qty);
292
									}
309
									}
293
									else{
310
									else{
294
										fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
295
										fbaSalesSnapshot.setTotalPromotionSale((float) 0);
311
										fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
312
										fbaSalesSnapshot.setPromotionOrderCount(0);
296
									}
313
									}
-
 
314
									ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
297
									orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(itemid,fbaSalesSnapshot);
315
									orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
298
								}
316
								}
299
							}
317
							}
300
							else{
-
 
301
								Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
302
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
303
								fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
304
								fbaSalesSnapshot.setTotalSale(itemSale);
-
 
305
								if(itemDiscount!=0){
-
 
306
									fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
307
									fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
308
								}
318
						}
309
								else{
319
						catch(Exception e){
310
									fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
311
									fbaSalesSnapshot.setPromotionOrderCount(0);
320
							e.printStackTrace();
312
								}
-
 
313
								ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
-
 
314
								orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
315
							}
-
 
316
						} 
321
						}
317
						count++;
322
						count++;
318
					}
323
					}
319
					InventoryClient inventoryServiceClient = null;
324
					InventoryClient inventoryServiceClient = null;
320
					TransactionClient transactionServiceClient = null;
325
					TransactionClient transactionServiceClient = null;
321
					CatalogClient catalogServiceClient = null;
326
					CatalogClient catalogServiceClient = null;
Line 341... Line 346...
341
					Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
346
					Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
342
					System.out.println("Start Date = " + date_start);
347
					System.out.println("Start Date = " + date_start);
343
					System.out.println("End Date = " + date_end);
348
					System.out.println("End Date = " + date_end);
344
					Date d = date_start;
349
					Date d = date_start;
345
					while(!d.equals(date_end)){
350
					while(!d.equals(date_end)){
346
				        cal.setTime(d);
351
						cal.setTime(d);
347
				        cal.add(Calendar.DATE,1);
352
						cal.add(Calendar.DATE,1);
348
						d = cal.getTime();
353
						d = cal.getTime();
349
						dates.add(d);
354
						dates.add(d);
350
					}
355
					}
351
					List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
356
					List<AmazonFbaInventorySnapshot> nonzeroFbaInventorySnapshotlist =  inventoryClient.getAllAmazonFbaItemInventory();
352
					for(Date date:dates){
357
					for(Date date:dates){
Line 385... Line 390...
385
					Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
390
					Map<Long,PriceAtDate> itemIdSalePriceMap = new HashMap<Long,PriceAtDate>();
386
					Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
391
					Map<Long,PriceAtDate> itemIdminFBAPriceMap = new HashMap<Long,PriceAtDate>();
387
					Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
392
					Map<Long,PriceAtDate> itemIdminMFNPriceMap = new HashMap<Long,PriceAtDate>();
388
					count=1;
393
					count=1;
389
					while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
394
					while ((nextLine = inventoryhealthreportreader.readNext()) != null ) {
-
 
395
						try{
390
						if(count!=1){
396
							if(count!=1){
391
							//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
397
								//System.out.println(nextLine[1] +" "+ nextLine[31] +" " + nextLine[32] + " " + nextLine[34]);
392
							SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
398
								SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
393
							istFormatter .setLenient(false);
399
								istFormatter .setLenient(false);
394
							TimeZone zone= TimeZone.getTimeZone("GMT");
400
								TimeZone zone= TimeZone.getTimeZone("GMT");
395
							istFormatter.setTimeZone(zone);
401
								istFormatter.setTimeZone(zone);
396
							Date date = istFormatter.parse(nextLine[0]);
402
								Date date = istFormatter.parse(nextLine[0]);
397
							Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
403
								Long item_id = Long.parseLong(nextLine[1].replaceAll("FBA",""));
398
							Double ourPrice = null;
404
								Double ourPrice = null;
399
							Double minFBAPrice= null;
405
								Double minFBAPrice= null;
400
							Double minMFNPrice= null;
406
								Double minMFNPrice= null;
401
							Double salePrice= null; 
407
								Double salePrice= null; 
402
							if(nextLine[30].length() >0){
408
								if(nextLine[30].length() >0){
403
								ourPrice = Double.parseDouble(nextLine[30]);
409
									ourPrice = Double.parseDouble(nextLine[30]);
404
								if(itemIdOurPriceMap.containsKey(item_id)){
410
									if(itemIdOurPriceMap.containsKey(item_id)){
405
									if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
411
										if(itemIdOurPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
412
											PriceAtDate priceAtDate= new PriceAtDate();
-
 
413
											priceAtDate.setDate(date);
-
 
414
											priceAtDate.setPrice(ourPrice);
-
 
415
											itemIdOurPriceMap.put(item_id,priceAtDate);
-
 
416
										}
-
 
417
									}
-
 
418
									else{	
406
										PriceAtDate priceAtDate= new PriceAtDate();
419
										PriceAtDate priceAtDate= new PriceAtDate();
407
										priceAtDate.setDate(date);
420
										priceAtDate.setDate(date);
408
										priceAtDate.setPrice(ourPrice);
421
										priceAtDate.setPrice(ourPrice);
409
										itemIdOurPriceMap.put(item_id,priceAtDate);
422
										itemIdOurPriceMap.put(item_id,priceAtDate);
410
									}
423
									}
411
								}
424
								}
412
								else{	
425
								if(nextLine[31].length() >0){
-
 
426
									salePrice = Double.parseDouble(nextLine[31]);
-
 
427
									if(itemIdSalePriceMap.containsKey(item_id) ){
-
 
428
										if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
413
									PriceAtDate priceAtDate= new PriceAtDate();
429
											PriceAtDate priceAtDate= new PriceAtDate();
414
									priceAtDate.setDate(date);
430
											priceAtDate.setDate(date);
415
									priceAtDate.setPrice(ourPrice);
431
											priceAtDate.setPrice(salePrice);
416
									itemIdOurPriceMap.put(item_id,priceAtDate);
432
											itemIdSalePriceMap.put(item_id,priceAtDate);
417
								}
433
										}
418
							}
434
									}
419
							if(nextLine[31].length() >0){
435
									else{	
420
								salePrice = Double.parseDouble(nextLine[31]);
-
 
421
								if(itemIdSalePriceMap.containsKey(item_id) ){
-
 
422
									if(itemIdSalePriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
423
										PriceAtDate priceAtDate= new PriceAtDate();
436
										PriceAtDate priceAtDate= new PriceAtDate();
424
										priceAtDate.setDate(date);
437
										priceAtDate.setDate(date);
425
										priceAtDate.setPrice(salePrice);
438
										priceAtDate.setPrice(salePrice);
426
										itemIdSalePriceMap.put(item_id,priceAtDate);
439
										itemIdSalePriceMap.put(item_id,priceAtDate);
427
									}
440
									}
428
								}
441
								}
429
								else{	
442
								if(nextLine[32].length() >0){
-
 
443
									minFBAPrice = Double.parseDouble(nextLine[32]);
-
 
444
									if(itemIdminFBAPriceMap.containsKey(item_id)){
-
 
445
										if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
430
									PriceAtDate priceAtDate= new PriceAtDate();
446
											PriceAtDate priceAtDate= new PriceAtDate();
431
									priceAtDate.setDate(date);
447
											priceAtDate.setDate(date);
432
									priceAtDate.setPrice(salePrice);
448
											priceAtDate.setPrice(minFBAPrice);
433
									itemIdSalePriceMap.put(item_id,priceAtDate);
449
											itemIdminFBAPriceMap.put(item_id,priceAtDate);
434
								}
450
										}
435
							}
451
									}
436
							if(nextLine[32].length() >0){
452
									else{	
437
								minFBAPrice = Double.parseDouble(nextLine[32]);
-
 
438
								if(itemIdminFBAPriceMap.containsKey(item_id)){
-
 
439
									if(itemIdminFBAPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
440
										PriceAtDate priceAtDate= new PriceAtDate();
453
										PriceAtDate priceAtDate= new PriceAtDate();
441
										priceAtDate.setDate(date);
454
										priceAtDate.setDate(date);
442
										priceAtDate.setPrice(minFBAPrice);
455
										priceAtDate.setPrice(minFBAPrice);
443
										itemIdminFBAPriceMap.put(item_id,priceAtDate);
456
										itemIdminFBAPriceMap.put(item_id,priceAtDate);
444
									}
457
									}
445
								}
458
								}
446
								else{	
459
								if(nextLine[34].length() >0){
-
 
460
									minMFNPrice = Double.parseDouble(nextLine[34]);
-
 
461
									if(itemIdminMFNPriceMap.containsKey(item_id)){
-
 
462
										if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
447
									PriceAtDate priceAtDate= new PriceAtDate();
463
											PriceAtDate priceAtDate= new PriceAtDate();
448
									priceAtDate.setDate(date);
464
											priceAtDate.setDate(date);
449
									priceAtDate.setPrice(minFBAPrice);
465
											priceAtDate.setPrice(minMFNPrice);
450
									itemIdminFBAPriceMap.put(item_id,priceAtDate);
466
											itemIdminMFNPriceMap.put(item_id,priceAtDate);
451
								}
467
										}
452
							}
468
									}
453
							if(nextLine[34].length() >0){
469
									else{	
454
								minMFNPrice = Double.parseDouble(nextLine[34]);
-
 
455
								if(itemIdminMFNPriceMap.containsKey(item_id)){
-
 
456
									if(itemIdminMFNPriceMap.get(item_id).getDate().getTime() < date.getTime()){
-
 
457
										PriceAtDate priceAtDate= new PriceAtDate();
470
										PriceAtDate priceAtDate= new PriceAtDate();
458
										priceAtDate.setDate(date);
471
										priceAtDate.setDate(date);
459
										priceAtDate.setPrice(minMFNPrice);
472
										priceAtDate.setPrice(minMFNPrice);
460
										itemIdminMFNPriceMap.put(item_id,priceAtDate);
473
										itemIdminMFNPriceMap.put(item_id,priceAtDate);
461
									}
474
									}
462
								}
475
								}
463
								else{	
-
 
464
									PriceAtDate priceAtDate= new PriceAtDate();
-
 
465
									priceAtDate.setDate(date);
-
 
466
									priceAtDate.setPrice(minMFNPrice);
-
 
467
									itemIdminMFNPriceMap.put(item_id,priceAtDate);
-
 
468
								}
-
 
469
							}
476
							}
470
						}
477
						}
-
 
478
						catch(Exception e){
-
 
479
							e.printStackTrace();
-
 
480
						}
471
						count++;
481
						count++;
472
					}
482
					}
473
					boolean oos;
483
					boolean oos;
474
					for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
484
					for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
475
						Date orderDate = entry.getKey();
485
						Date orderDate = entry.getKey();