Subversion Repositories SmartDukaan

Rev

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

Rev 9754 Rev 9755
Line 50... Line 50...
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
			while ((nextLine = orderreportreader.readNext()) != null) {
-
 
55
				try{
55
				if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
56
					if(count!=1 && nextLine[5].equalsIgnoreCase("Amazon") && nextLine[6].equalsIgnoreCase("Amazon.in")){
56
					SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
57
						SimpleDateFormat istFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
57
					istFormatter .setLenient(false);
58
						istFormatter .setLenient(false);
58
					TimeZone zone= TimeZone.getTimeZone("GMT");
59
						TimeZone zone= TimeZone.getTimeZone("GMT");
59
					istFormatter.setTimeZone(zone);
60
						istFormatter.setTimeZone(zone);
60
					Date date = istFormatter.parse(nextLine[2]);
61
						Date date = istFormatter.parse(nextLine[2]);
61
					SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
62
						SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
62
					Date date_key = dateFormat.parse(dateFormat.format(date));
63
						Date date_key = dateFormat.parse(dateFormat.format(date));
63
					if(nextLine[11].equals("FBA13465")){
-
 
64
						System.out.println("Order Details " + nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[14] + " " + nextLine[4] + " " + nextLine[13] );
64
						System.out.println("Order Details " + nextLine[0]+" "+date_key+" "+ nextLine[11] +" " + nextLine[13] + " " + nextLine[14]);
65
					}
-
 
66
					Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
65
						Long itemid = Long.parseLong(nextLine[11].replaceAll("FBA",""));
67
					Integer qty=0;
66
						Integer qty=0;
68
					if(nextLine[14].length()!=0){
67
						if(nextLine[14].length()!=0){
69
						qty = new Integer(nextLine[14]);
68
							qty = new Integer(nextLine[14]);
70
					}
69
						}
71
					Float itemSale = null;
70
						Float itemSale = null;
72
					if(nextLine[16].length()!=0){
71
						if(nextLine[16].length()!=0){
73
						itemSale = new Float(nextLine[16]);
72
							itemSale = new Float(nextLine[16]);
74
					}
73
						}
75
					else{
74
						else{
76
						itemSale = (float) 0;
75
							continue;
77
					}
76
						}
78
					Float itemDiscount; 
77
						Float itemDiscount; 
79
					if(nextLine[22].length()!=0){
78
						if(nextLine[22].length()!=0){
80
						itemDiscount = new Float(nextLine[22]);
79
							itemDiscount = new Float(nextLine[22]);
81
					}
80
						}
82
					else{
81
						else{
83
						itemDiscount = new Float(0);
82
							itemDiscount = new Float(0);
84
					}
83
						}
85
					if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[13].equalsIgnoreCase("Cancelled")){
84
						if(nextLine[4].equalsIgnoreCase("Cancelled") || nextLine[13].equalsIgnoreCase("Cancelled")){
86
						itemSale = (float) 0; 
85
							itemSale = (float) 0; 
87
						itemDiscount = (float) 0;
86
							itemDiscount = (float) 0;
88
						qty = 0;
87
							qty = 0;
89
					}
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);
90
					if(itemid==13465){
93
								if(itemDiscount!=0){
-
 
94
									fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
91
						System.out.println("Order Details after parsing " + nextLine[0]+" "+date_key+" "+ itemid +" " + qty);
95
									fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
92
					}
96
								}
-
 
97
								fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
-
 
98
								fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
93
					if(orderDateItemIdFbaSaleSnapshotMap.containsKey(date_key)){
99
								ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
94
						Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap;
100
								ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
95
						if(orderDateItemIdFbaSaleSnapshotMap.get(date_key).containsKey(itemid)){
101
								orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
102
							}
-
 
103
							else{
96
							FbaSalesSnapshot fbaSalesSnapshot = orderDateItemIdFbaSaleSnapshotMap.get(date_key).get(itemid);
104
								FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
105
								fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
106
								fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
97
							if(itemDiscount!=0){
107
								if(itemDiscount!=0){
98
								fbaSalesSnapshot.setPromotionOrderCount(fbaSalesSnapshot.getPromotionOrderCount()+qty);
108
									fbaSalesSnapshot.setPromotionOrderCount(qty);
99
								fbaSalesSnapshot.setTotalPromotionSale(fbaSalesSnapshot.getTotalPromotionSale() + (itemSale - itemDiscount));
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);
100
							}
118
							}
101
							fbaSalesSnapshot.setTotalOrderCount(fbaSalesSnapshot.getTotalOrderCount() + qty);
-
 
102
							fbaSalesSnapshot.setTotalSale(fbaSalesSnapshot.getTotalSale() + itemSale - itemDiscount);
-
 
103
							ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
104
							ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
-
 
105
							orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
106
						}
119
						}
107
						else{
120
						else{
-
 
121
							Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
108
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
122
							FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
109
							fbaSalesSnapshot.setTotalOrderCount(qty);
123
							fbaSalesSnapshot.setTotalOrderCount(qty);
110
							fbaSalesSnapshot.setTotalSale(itemSale - itemDiscount);
124
							fbaSalesSnapshot.setTotalSale(itemSale);
111
							if(itemDiscount!=0){
125
							if(itemDiscount!=0){
112
								fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
113
								fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
126
								fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
127
								fbaSalesSnapshot.setPromotionOrderCount(qty);
114
							}
128
							}
115
							else{
129
							else{
116
								fbaSalesSnapshot.setPromotionOrderCount(0);
-
 
117
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
130
								fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
131
								fbaSalesSnapshot.setPromotionOrderCount(0);
118
							}
132
							}
119
							ItemIdFbaSaleSnapshotMap = orderDateItemIdFbaSaleSnapshotMap.get(date_key);
-
 
120
							ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot); 
133
							ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
121
							orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
134
							orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
122
						}
135
						}
123
					}
136
					}
124
					else{
-
 
125
						Map<Long,FbaSalesSnapshot> ItemIdFbaSaleSnapshotMap = new HashMap<Long,FbaSalesSnapshot>();
-
 
126
						FbaSalesSnapshot fbaSalesSnapshot = new FbaSalesSnapshot();
-
 
127
						fbaSalesSnapshot.setTotalOrderCount(qty);
-
 
128
						fbaSalesSnapshot.setTotalSale(itemSale);
-
 
129
						if(itemDiscount!=0){
-
 
130
							fbaSalesSnapshot.setTotalPromotionSale(itemSale - itemDiscount);
-
 
131
							fbaSalesSnapshot.setPromotionOrderCount(qty);
-
 
132
						}
137
				}
133
						else{
138
				catch(Exception e){
134
							fbaSalesSnapshot.setTotalPromotionSale((float) 0);
-
 
135
							fbaSalesSnapshot.setPromotionOrderCount(0);
139
					e.printStackTrace();
136
						}
-
 
137
						ItemIdFbaSaleSnapshotMap.put(itemid,fbaSalesSnapshot);
-
 
138
						orderDateItemIdFbaSaleSnapshotMap.put(date_key,ItemIdFbaSaleSnapshotMap);
-
 
139
					}
-
 
140
				}
140
				}
141
				count++;
141
				count++;
142
			}
142
			}
143
			InventoryClient inventoryServiceClient = null;
143
			InventoryClient inventoryServiceClient = null;
144
			TransactionClient transactionServiceClient = null;
144
			TransactionClient transactionServiceClient = null;
Line 161... Line 161...
161
			Calendar cal = Calendar.getInstance();
161
			Calendar cal = Calendar.getInstance();
162
			cal.add(Calendar.DATE, -1);
162
			cal.add(Calendar.DATE, -1);
163
			Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
163
			Date date_end = dateFormat.parse(dateFormat.format(cal.getTime()));
164
			cal.add(Calendar.DATE, -5);
164
			cal.add(Calendar.DATE, -5);
165
			Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
165
			Date date_start = dateFormat.parse(dateFormat.format(cal.getTime()));
166
			//System.out.println("Start Date = " + date_start);
166
			System.out.println("Start Date = " + date_start);
167
			//System.out.println("End Date = " + date_end);
167
			System.out.println("End Date = " + date_end);
168
			Date d = date_start;
168
			Date d = date_start;
169
			while(!d.equals(date_end)){
169
			while(!d.equals(date_end)){
170
				cal.setTime(d);
170
				cal.setTime(d);
171
				cal.add(Calendar.DATE,1);
171
				cal.add(Calendar.DATE,1);
172
				d = cal.getTime();
172
				d = cal.getTime();
Line 301... Line 301...
301
			}
301
			}
302
			boolean oos;
302
			boolean oos;
303
			for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
303
			for (Entry<Date, Map<Long, FbaSalesSnapshot>> entry : orderDateItemIdFbaSaleSnapshotMap.entrySet()){
304
				Date orderDate = entry.getKey();
304
				Date orderDate = entry.getKey();
305
				for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
305
				for(Entry<Long, FbaSalesSnapshot> entry1 :entry.getValue().entrySet()){
306
					//System.out.println("Item ID is " + entry1.getKey());
306
					System.out.println("Item ID is " + entry1.getKey());
307
					Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
307
					Long inventory = inventoryClient.getAmazonFbaItemInventory(entry1.getKey());
308
 
308
 
309
					if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
309
					if(inventory==0 && entry1.getValue().getTotalOrderCount()==0){
310
						oos=true;
310
						oos=true;
311
					}
311
					}
Line 315... Line 315...
315
					Long item_id = entry1.getKey();
315
					Long item_id = entry1.getKey();
316
					Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
316
					Amazonlisted amazon_item=catalogClient.getAmazonItemDetails(item_id);
317
					if(amazon_item.getItemid()==0){
317
					if(amazon_item.getItemid()==0){
318
						continue;
318
						continue;
319
					}
319
					}
320
					//System.out.println(orderDate +","+entry1.getKey()+","+entry1.getValue()+","+ inventory +","+ oos+","+itemIdSalePriceMap.get(item_id)+","+itemIdminFBAPriceMap.get(item_id)+","+itemIdminMFNPriceMap.get(item_id));
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();
321
					AmazonFbaSalesSnapshot amazonfbasalessnapshot = new AmazonFbaSalesSnapshot();
322
					amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
322
					amazonfbasalessnapshot.setDateOfSale(orderDate.getTime());
323
					amazonfbasalessnapshot.setItem_id(entry1.getKey());
323
					amazonfbasalessnapshot.setItem_id(entry1.getKey());
324
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
324
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getPromotionOrderCount());
325
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
325
					amazonfbasalessnapshot.setTotalOrderCount(entry1.getValue().getTotalOrderCount());
Line 356... Line 356...
356
					}
356
					}
357
					else{
357
					else{
358
						amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
358
						amazonfbasalessnapshot.setOurPrice(amazon_item.getFbaPrice());
359
						amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
359
						amazonfbasalessnapshot.setOurPriceSnapshotDate(0);
360
					}
360
					}
361
					if(amazonfbasalessnapshot.getTotalOrderCount() > 0){
-
 
362
						Date date =  new Date(amazonfbasalessnapshot.getDateOfSale());
-
 
363
						SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); 
-
 
364
						System.out.println(" Item details are " + sdf.format(date) + " "+ amazonfbasalessnapshot.getItem_id() + " " + amazonfbasalessnapshot.getTotalOrderCount());
-
 
365
					}
-
 
366
					amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
361
					amazonfbasalessnapshot.setAmazonFbaInventory(inventory);
367
					transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
362
					transactionClient.addOrUpdateAmazonFbaSalesSnapshot(amazonfbasalessnapshot);
368
				}
363
				}
369
			}
364
			}
370
		} catch (IOException e) {
365
		} catch (IOException e) {