Subversion Repositories SmartDukaan

Rev

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

Rev 11196 Rev 11406
Line 294... Line 294...
294
								TimeZone zone= TimeZone.getTimeZone("GMT");
294
								TimeZone zone= TimeZone.getTimeZone("GMT");
295
								istFormatter.setTimeZone(zone);
295
								istFormatter.setTimeZone(zone);
296
								Date date = istFormatter.parse(amazonOrder.getPurchaseDate().toString());
296
								Date date = istFormatter.parse(amazonOrder.getPurchaseDate().toString());
297
								SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
297
								SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
298
								Date date_key = dateFormat.parse(dateFormat.format(date));
298
								Date date_key = dateFormat.parse(dateFormat.format(date));
299
								//System.out.println("Order Details " + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
-
 
300
								Long itemid;
299
								Long itemid;
301
								AmazonFCWarehouseLocation fcLocation;
300
								AmazonFCWarehouseLocation fcLocation;
302
								if(amazonOrder.getOrderItem().get(0).getSKU().startsWith("FBA")){
301
								if(amazonOrder.getOrderItem().get(0).getSKU().startsWith("FBA")){
303
									itemid = Long.parseLong(amazonOrder.getOrderItem().get(0).getSKU().replaceAll("FBA",""));
302
									itemid = Long.parseLong(amazonOrder.getOrderItem().get(0).getSKU().replaceAll("FBA",""));
304
									fcLocation = AmazonFCWarehouseLocation.Mumbai;
303
									fcLocation = AmazonFCWarehouseLocation.Mumbai;
Line 306... Line 305...
306
								else if(amazonOrder.getOrderItem().get(0).getSKU().startsWith("FBB")){
305
								else if(amazonOrder.getOrderItem().get(0).getSKU().startsWith("FBB")){
307
									itemid = Long.parseLong(amazonOrder.getOrderItem().get(0).getSKU().replaceAll("FBB",""));
306
									itemid = Long.parseLong(amazonOrder.getOrderItem().get(0).getSKU().replaceAll("FBB",""));
308
									fcLocation = AmazonFCWarehouseLocation.Bangalore;
307
									fcLocation = AmazonFCWarehouseLocation.Bangalore;
309
								}
308
								}
310
								else{
309
								else{
-
 
310
									//System.out.println("Skipping Order not FBB or FBA" + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
311
									continue;
311
									continue;
312
								}
312
								}
313
								Integer qty=0;
313
								Integer qty=0;
314
								if(amazonOrder.getOrderItem().get(0).getQuantity()!=0){
314
								if(amazonOrder.getOrderItem().get(0).getQuantity()!=0){
315
									qty = new Integer(amazonOrder.getOrderItem().get(0).getQuantity());
315
									qty = new Integer(amazonOrder.getOrderItem().get(0).getQuantity());
Line 318... Line 318...
318
								if(amazonOrder.getOrderItem().get(0).getItemPrice()!=null && amazonOrder.getOrderItem().get(0).getItemPrice().getComponent()!=null && amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().size()>0){
318
								if(amazonOrder.getOrderItem().get(0).getItemPrice()!=null && amazonOrder.getOrderItem().get(0).getItemPrice().getComponent()!=null && amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().size()>0){
319
									if(amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().get(0).getAmount().getValue()!=0){
319
									if(amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().get(0).getAmount().getValue()!=0){
320
										itemSale = new Float(amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().get(0).getAmount().getValue());
320
										itemSale = new Float(amazonOrder.getOrderItem().get(0).getItemPrice().getComponent().get(0).getAmount().getValue());
321
									}
321
									}
322
									else{
322
									else{
323
										continue;
323
										itemSale = (float) 0;
324
									}
324
									}
325
								}
325
								}
326
 
326
 
327
								else{
327
								else{
328
									continue;
328
									itemSale = (float) 0;
329
								}
329
								}
330
 
330
 
331
								Float itemDiscount; 
331
								Float itemDiscount; 
332
								if(amazonOrder.getOrderItem().get(0).getPromotion()!=null){
332
								if(amazonOrder.getOrderItem().get(0).getPromotion()!=null){
333
									if(amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount()!=null && amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount().floatValue()!=0.0f){
333
									if(amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount()!=null && amazonOrder.getOrderItem().get(0).getPromotion().getItemPromotionDiscount().floatValue()!=0.0f){
Line 343... Line 343...
343
 
343
 
344
								if(("Cancelled").equalsIgnoreCase(amazonOrder.getOrderStatus()) || ("Cancelled").equalsIgnoreCase(amazonOrder.getOrderItem().get(0).getItemStatus())){
344
								if(("Cancelled").equalsIgnoreCase(amazonOrder.getOrderStatus()) || ("Cancelled").equalsIgnoreCase(amazonOrder.getOrderItem().get(0).getItemStatus())){
345
									itemSale = (float) 0; 
345
									itemSale = (float) 0; 
346
									itemDiscount = (float) 0;
346
									itemDiscount = (float) 0;
347
									qty = 0;
347
									qty = 0;
-
 
348
									//System.out.println("Cancelled Order " + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
348
								}
349
								}
349
								if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
350
								if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
350
									FbaSalesSnapshot fbaSalesSnapshot;
351
									FbaSalesSnapshot fbaSalesSnapshot;
351
									if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(amazonOrder.getOrderItem().get(0).getSKU())){
352
									if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(amazonOrder.getOrderItem().get(0).getSKU())){
352
										fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(amazonOrder.getOrderItem().get(0).getSKU());
353
										fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(amazonOrder.getOrderItem().get(0).getSKU());
Line 355... Line 356...
355
											fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
356
											fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
356
										}
357
										}
357
										fbaSalesSnapshot.setFcLocation(fcLocation);
358
										fbaSalesSnapshot.setFcLocation(fcLocation);
358
										fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
359
										fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
359
										fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
360
										fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
-
 
361
										Map<String,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
362
										ItemIdFbaSaleSnapshotMap.put(amazonOrder.getOrderItem().get(0).getSKU(), fbaSalesSnapshot);
-
 
363
										//System.out.println("Adding Order to list entry exists " + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
-
 
364
										orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
360
									}
365
									}
361
									else{
366
									else{
362
										fbaSalesSnapshot = new FbaSalesSnapshot();
367
										fbaSalesSnapshot = new FbaSalesSnapshot();
363
										fbaSalesSnapshot.setFcLocation(fcLocation);
368
										fbaSalesSnapshot.setFcLocation(fcLocation);
364
										fbaSalesSnapshot.setTotalOrderCount(qty);
369
										fbaSalesSnapshot.setTotalOrderCount(qty);
Line 369... Line 374...
369
										}
374
										}
370
										else{
375
										else{
371
											fbaSalesSnapshot.setPromotionOrderCount(0);
376
											fbaSalesSnapshot.setPromotionOrderCount(0);
372
											fbaSalesSnapshot.setTotalPromotionSale((float) 0);
377
											fbaSalesSnapshot.setTotalPromotionSale((float) 0);
373
										}
378
										}
-
 
379
										Map<String,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
380
										ItemIdFbaSaleSnapshotMap.put(amazonOrder.getOrderItem().get(0).getSKU(), fbaSalesSnapshot);
-
 
381
										//System.out.println("Adding Order to list new entry " + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
-
 
382
										orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
374
									}
383
									}
375
									orderDateItemIdFbaSaleSnapshotMap.get(date_key).put(amazonOrder.getOrderItem().get(0).getSKU(),fbaSalesSnapshot);
-
 
376
								}
384
								}
377
								else{
385
								else{
378
									Map<String,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<String,FbaSalesSnapshot>();
386
									Map<String,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<String,FbaSalesSnapshot>();
379
									FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
387
									FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
380
									fbaSalesSnapshot.setFcLocation(fcLocation);
388
									fbaSalesSnapshot.setFcLocation(fcLocation);
Line 387... Line 395...
387
									else{
395
									else{
388
										fbaSalesSnapshot.setTotalPromotionSale((float) 0);
396
										fbaSalesSnapshot.setTotalPromotionSale((float) 0);
389
										fbaSalesSnapshot.setPromotionOrderCount(0);
397
										fbaSalesSnapshot.setPromotionOrderCount(0);
390
									}
398
									}
391
									ItemIdFbaSaleSnapshotMap.put(amazonOrder.getOrderItem().get(0).getSKU(),fbaSalesSnapshot);
399
									ItemIdFbaSaleSnapshotMap.put(amazonOrder.getOrderItem().get(0).getSKU(),fbaSalesSnapshot);
-
 
400
									//System.out.println("Adding Order to list date doesnt exists " + amazonOrder.getAmazonOrderID()+" "+date_key+" "+ amazonOrder.getOrderItem().get(0).getSKU()  +" " + amazonOrder.getOrderItem().get(0).getItemStatus() + " " + amazonOrder.getOrderItem().get(0).getQuantity());
392
									orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
401
									orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
393
								}
402
								}
394
							}
403
							}
395
						}
404
						}
396
					}
405
					}
Line 482... Line 491...
482
								istFormatter.setTimeZone(zone);
491
								istFormatter.setTimeZone(zone);
483
								Date date = istFormatter.parse(nextLine[0]);
492
								Date date = istFormatter.parse(nextLine[0]);
484
								if(nextLine[1].length()> 0 && (nextLine[1].startsWith("FBA") || nextLine[1].startsWith("FBB"))){
493
								if(nextLine[1].length()> 0 && (nextLine[1].startsWith("FBA") || nextLine[1].startsWith("FBB"))){
485
									nextLine[1] = nextLine[1].replaceAll("FBA",""); 
494
									nextLine[1] = nextLine[1].replaceAll("FBA",""); 
486
									nextLine[1] = nextLine[1].replaceAll("FBB","");
495
									nextLine[1] = nextLine[1].replaceAll("FBB","");
487
									}
496
								}
488
								else{
497
								else{
489
									continue;
498
									continue;
490
								}
499
								}
491
								Long item_id = Long.parseLong(nextLine[1]);
500
								Long item_id = Long.parseLong(nextLine[1]);
492
								Double ourPrice = null;
501
								Double ourPrice = null;
Line 571... Line 580...
571
					boolean oos;
580
					boolean oos;
572
					List<AmazonFbaSalesSnapshot> fbaSalesSnapShotList = new ArrayList<AmazonFbaSalesSnapshot>();
581
					List<AmazonFbaSalesSnapshot> fbaSalesSnapShotList = new ArrayList<AmazonFbaSalesSnapshot>();
573
					for (Entry<Date, Map<String, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
582
					for (Entry<Date, Map<String, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
574
						Date orderDate = entry.getKey();
583
						Date orderDate = entry.getKey();
575
						AmazonFCWarehouseLocation location;
584
						AmazonFCWarehouseLocation location;
576
						Long item_id;
585
						Long item_id = null;
577
						for(Entry<String, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
586
						for(Entry<String, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
578
							if(entry1.getKey().startsWith("FBA")){
587
							if(entry1.getKey().startsWith("FBA")){
579
								location = AmazonFCWarehouseLocation.Mumbai;
588
								location = AmazonFCWarehouseLocation.Mumbai;
580
								item_id = Long.parseLong(entry1.getKey().replaceAll("FBA",""));
589
								item_id = Long.parseLong(entry1.getKey().replaceAll("FBA",""));
581
							}
590
							}
582
							else if(entry1.getKey().startsWith("FBB")){
591
							else if(entry1.getKey().startsWith("FBB")){
583
								location = AmazonFCWarehouseLocation.Bangalore;
592
								location = AmazonFCWarehouseLocation.Bangalore;
584
								item_id = Long.parseLong(entry1.getKey().replaceAll("FBB",""));
593
								item_id = Long.parseLong(entry1.getKey().replaceAll("FBB",""));
585
							}
594
							}
586
							else{
595
							else{
-
 
596
								System.out.println("Skipping Item ID " + entry1.getKey() +" date : "+orderDate);
587
								continue;
597
								continue;
588
							}
598
							}
589
//							System.out.println("Item ID is " + item_id);
-
 
590
							List<AmazonFbaInventorySnapshot> iteminventory;
599
							List<AmazonFbaInventorySnapshot> iteminventory;
591
							Long inventory = 0L;
600
							Long inventory = 0L;
592
							try{
601
							try{
593
								iteminventory = inventoryClient.getAmazonFbaItemInventory(item_id);
602
								iteminventory = inventoryClient.getAmazonFbaItemInventory(item_id);
594
							}
603
							}
Line 605... Line 614...
605
								oos=true;
614
								oos=true;
606
							}
615
							}
607
							else{
616
							else{
608
								oos=false;
617
								oos=false;
609
							}
618
							}
610
							Amazonlisted amazon_item;
-
 
611
							try{
-
 
612
								amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
613
							}
-
 
614
							catch(TTransportException e){
-
 
615
								catalogClient   = catalogServiceClient.getClient();
-
 
616
								amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
617
							}
-
 
618
							if(amazon_item.getItemid()==0){
-
 
619
								continue;
-
 
620
							}
-
 
621
							//System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
619
							//System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
622
							AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
620
							AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
623
							amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
621
							amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
624
							amazonfbasalessnapshot.setItem_id(item_id);
622
							amazonfbasalessnapshot.setItem_id(item_id);
625
							amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
623
							amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
Line 654... Line 652...
654
							if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
652
							if(itemIdOurPriceMap.containsKey(item_id) && itemIdOurPriceMap.get(item_id).getPrice()!=0){
655
								amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
653
								amazonfbasalessnapshot.setOurPrice(itemIdOurPriceMap.get(item_id).getPrice());
656
								amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
654
								amazonfbasalessnapshot.setOurPriceSnapshotDate(itemIdOurPriceMap.get(item_id).getDate().getTime());
657
							}
655
							}
658
							else{
656
							else{
-
 
657
								Amazonlisted amazon_item;
-
 
658
								try{
-
 
659
									amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
660
								}
-
 
661
								catch(TTransportException e){
-
 
662
									catalogClient   = catalogServiceClient.getClient();
-
 
663
									amazon_item=catalogClient.getAmazonItemDetails(item_id);
-
 
664
								}
-
 
665
								if(amazon_item.getItemid()==0){
-
 
666
									System.out.println("Skipping Item ID listing not present" + entry1.getKey() +" date : "+orderDate);
-
 
667
									continue;
-
 
668
								}
659
								amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
669
								amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
660
								amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
670
								amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
661
							}
671
							}
662
							amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
672
							amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
663
							amazonfbasalessnapshot.setFcLocation(location);
673
							amazonfbasalessnapshot.setFcLocation(location);
Line 678... Line 688...
678
					// TODO Auto-generated catch block
688
					// TODO Auto-generated catch block
679
					e.printStackTrace(); 
689
					e.printStackTrace(); 
680
				} catch (TException e) {
690
				} catch (TException e) {
681
					// TODO Auto-generated catch block
691
					// TODO Auto-generated catch block
682
					e.printStackTrace();
692
					e.printStackTrace();
683
 
-
 
684
				}
693
				}
685
				break;
694
				break;
686
 
-
 
687
			}
695
			}
688
			else{ 
696
			else{ 
689
				System.out.println("Report not ready");
697
				System.out.println("Report not ready");
690
				try {
698
				try {
691
					Thread.sleep(5*60*1000);
699
					Thread.sleep(5*60*1000);