Subversion Repositories SmartDukaan

Rev

Rev 9508 | Rev 9510 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9404 vikram.rag 1
package in.shop2020;
2
 
9456 vikram.rag 3
import in.shop2020.model.v1.catalog.CatalogService;
9404 vikram.rag 4
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.SnapdealItem;
9495 vikram.rag 6
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
9404 vikram.rag 7
import in.shop2020.model.v1.inventory.InventoryService.Client;
8
import in.shop2020.model.v1.inventory.InventoryType;
9
import in.shop2020.model.v1.inventory.ItemInventory;
10
import in.shop2020.model.v1.inventory.SnapdealInventoryItem;
11
import in.shop2020.model.v1.inventory.Warehouse;
12
import in.shop2020.model.v1.inventory.WarehouseType;
13
import in.shop2020.thrift.clients.CatalogClient;
14
import in.shop2020.thrift.clients.InventoryClient;
15
import in.shop2020.thrift.clients.TransactionClient;
9459 vikram.rag 16
import in.shop2020.utils.GmailUtils;
9404 vikram.rag 17
import inventory.Inventory;
9456 vikram.rag 18
import inventory.InventoryHistory;
19
import inventory.InventoryHistoryItems;
9404 vikram.rag 20
import inventory.InventoryItems;
9495 vikram.rag 21
import inventory.PendingOrderInventoryHistory;
9404 vikram.rag 22
import inventory.SnapdealItemForInventory;
23
 
24
import java.io.BufferedReader;
9459 vikram.rag 25
import java.io.File;
9404 vikram.rag 26
import java.io.FileInputStream;
27
import java.io.FileNotFoundException;
28
import java.io.FileOutputStream;
29
import java.io.IOException;
30
import java.io.InputStreamReader;
31
import java.io.UnsupportedEncodingException;
32
import java.util.ArrayList;
9459 vikram.rag 33
import java.util.Calendar;
34
import java.util.GregorianCalendar;
9404 vikram.rag 35
import java.util.HashMap;
36
import java.util.List;
37
import java.util.Map;
9495 vikram.rag 38
import java.util.Map.Entry;
9404 vikram.rag 39
 
9459 vikram.rag 40
import javax.mail.MessagingException;
41
 
9404 vikram.rag 42
import org.apache.http.HttpResponse;
43
import org.apache.http.NameValuePair;
44
import org.apache.http.client.ClientProtocolException;
45
import org.apache.http.client.HttpClient;
46
import org.apache.http.client.entity.UrlEncodedFormEntity;
47
import org.apache.http.client.methods.HttpGet;
48
import org.apache.http.client.methods.HttpPost;
49
import org.apache.http.impl.client.DefaultHttpClient;
50
import org.apache.http.message.BasicNameValuePair;
51
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
52
import org.apache.poi.ss.usermodel.Row;
53
import org.apache.poi.ss.usermodel.Sheet;
54
import org.apache.poi.ss.usermodel.Workbook;
55
import org.apache.thrift.TException;
56
import org.apache.thrift.transport.TTransportException;
9456 vikram.rag 57
 
9404 vikram.rag 58
import com.google.gson.Gson;
59
 
60
public class CreateSnapDealInventoryFeed {
9456 vikram.rag 61
	private static long time = System.currentTimeMillis();
9415 vikram.rag 62
	private static String SNAPDEAL_INVENTORY_SHEET;
9404 vikram.rag 63
	private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap = new HashMap<Long, SnapdealItemForInventory>();
9501 vikram.rag 64
	private static ArrayList<Inventory> currentInventoryItemList;
9404 vikram.rag 65
	static Map<Long,Long> itemIdpendingOrdersMap = new HashMap<Long,Long>();
9456 vikram.rag 66
	private static Map<String,InventoryHistory> inventoryhistoryItemMap;
67
	private static DefaultHttpClient client = new DefaultHttpClient();
9495 vikram.rag 68
	static Map<String,SnapdealItemDetails> snapdealItemMap = new HashMap<String,SnapdealItemDetails>();
69
	static Map<Long,SnapdealItemDetails> itemSnapdealMap = new HashMap<Long,SnapdealItemDetails>();
70
	static Map<String,PendingOrderInventoryHistory> PendingOrdersInventoryHistoryMap = new HashMap<String,PendingOrderInventoryHistory>();
71
	static long lastUpdatedInventoryTime = 0;
72
	static{
73
		CatalogClient catalogServiceClient = null;
74
		try {
75
			catalogServiceClient = new CatalogClient();
76
		} catch (TTransportException e1) {
77
			// TODO Auto-generated catch block
78
			e1.printStackTrace();
79
		}
80
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
81
		List<SnapdealItemDetails> allSnapdealItems = null;
82
		try {
83
			allSnapdealItems = catalogClient.getAllSnapdealItems();
84
		} catch (TException e) {
85
			// TODO Auto-generated catch block
86
			e.printStackTrace();
87
		}
88
		for(SnapdealItemDetails snapdealItem:allSnapdealItems){
89
			snapdealItemMap.put(snapdealItem.getSkuAtSnapdeal(),snapdealItem);
90
			itemSnapdealMap.put(snapdealItem.getItem_id(), snapdealItem);
9502 vikram.rag 91
			System.out.println("Creating Item and Snapdeal Map " + snapdealItem.getItem_id() + " " + snapdealItem.getSkuAtSnapdeal());
9495 vikram.rag 92
		}
93
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
94
		try {
9497 vikram.rag 95
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 96
			lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
9498 vikram.rag 97
			System.out.println("Time is " + lastUpdatedInventoryTime);
9495 vikram.rag 98
		} catch (Exception e) {
99
			try {
9497 vikram.rag 100
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 101
				lastUpdatedInventoryTime = transactionClient.getSourceDetail(7).getLastUpdatedOn();
102
			} catch (Exception ex) {
103
				ex.printStackTrace();
104
			}
105
		}
106
 
107
	}
108
 
9404 vikram.rag 109
	private static void calculateinventory(){
110
		CatalogClient catalogServiceClient = null;
111
		Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
112
		try {
113
			catalogServiceClient = new CatalogClient();
114
		} catch (TTransportException e) {
115
			// TODO Auto-generated catch block
116
			e.printStackTrace();
117
		}
118
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
119
		try {
120
			List<Item> aliveItems = catalogClient.getAllAliveItems();
121
			Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>(); 
122
			for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
123
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
124
 
125
			}
9495 vikram.rag 126
			InventoryClient inventoryServiceClient = new InventoryClient();
9404 vikram.rag 127
			try {
128
				inventoryServiceClient = new InventoryClient();
129
			} catch (TTransportException e) {
130
				e.printStackTrace();
131
			}
132
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
133
			List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
9415 vikram.rag 134
			SNAPDEAL_INVENTORY_SHEET = "/home/snapdeal/snapdeal-inventory-"+time+".xls";
9404 vikram.rag 135
			availability = inventoryClient.getInventorySnapshot(0);
9456 vikram.rag 136
			List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,null,0,0,0);
137
			Map<Long,Warehouse> allWarehousesMap = new HashMap<Long,Warehouse>();
138
			for(Warehouse warehouse:allwarehouses){
139
				allWarehousesMap.put(warehouse.getId(),warehouse);
140
			}
9404 vikram.rag 141
			List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
142
			List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
143
			List<Long> thirdpartywarehouseids = new ArrayList<Long>();
144
			List<Long> oursGoodWarehouse = new ArrayList<Long>();
145
			for(Warehouse warehouse:warehouses){
146
				thirdpartywarehouseids.add(warehouse.getId());
147
			}
148
			for (Warehouse warehouse:ours_warehouses){
149
				oursGoodWarehouse.add(warehouse.getId());
150
			}
151
			long available=0;
152
			long reserve=0;
153
			long total_held=0;
154
			long heldForSource=0;
155
			double nlc=0;
156
			double maxnlc=0;
157
			Item thriftItem;
9456 vikram.rag 158
			long sku = 0;
9501 vikram.rag 159
			for(Inventory inventoryItem:currentInventoryItemList){
9495 vikram.rag 160
				if(snapdealItemMap.containsKey(inventoryItem.getSellerSku())){
161
					sku = snapdealItemMap.get(inventoryItem.getSellerSku()).getItem_id();
9404 vikram.rag 162
				}
9495 vikram.rag 163
				else{
164
					continue;
9456 vikram.rag 165
				}
166
				if(aliveItemsMap.get(sku) != null){
167
					thriftItem = aliveItemsMap.get(sku);	
168
				}
9404 vikram.rag 169
				else{
170
					continue;
171
				}
172
				available=0;
173
				reserve=0;
174
				total_held=0;
175
				heldForSource=0;
176
				nlc=0;
177
				List<Warehouse> vendor_warehouses=null;
178
				SnapdealItemForInventory item;
179
				if(availability.get(thriftItem.getId())!=null){ 
180
					ItemInventory iteminventory = availability.get(thriftItem.getId());
181
					Map<Long,Long> itemavailability = new HashMap<Long,Long>();
182
					itemavailability = iteminventory.getAvailability();
183
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
184
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());						
185
						vendor_warehouses = inventoryClient.getWarehouses(WarehouseType.THIRD_PARTY,InventoryType.GOOD , thriftItem.getPreferredVendor(), 0, 0);
186
						vendor_warehouses.addAll(ours_warehouses);
187
						for (Warehouse warehouse:vendor_warehouses){
9456 vikram.rag 188
							if(warehouse.getBillingWarehouseId()!=7){
189
								continue;
190
							}
9404 vikram.rag 191
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
192
							ignoredItem.setItemId(thriftItem.getId());
193
							ignoredItem.setWarehouseId(warehouse.getId());
194
							if (itemavailability.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(ignoredItem)){
195
								try{
196
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
197
								}
198
								catch(TTransportException e){
199
									inventoryClient = inventoryServiceClient.getClient(); 
200
									nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
201
								}
202
								maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
9413 vikram.rag 203
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
9404 vikram.rag 204
								if(nlc !=0 && (maxnlc >= nlc)){
205
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
206
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 7);
207
									available = available + itemavailability.get(warehouse.getId()) - total_held;
9413 vikram.rag 208
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9404 vikram.rag 209
								}
9413 vikram.rag 210
								else if(maxnlc==0){
211
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
212
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 7);
213
									available = available + itemavailability.get(warehouse.getId()) - total_held;
214
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9404 vikram.rag 215
								}
216
							}
217
						}
218
					}
219
					else{
220
						for (Map.Entry<Long,Long> entry :  itemavailability.entrySet()) {
9456 vikram.rag 221
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
222
								continue;
223
							}
9404 vikram.rag 224
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
225
							ignoredItem.setItemId(thriftItem.getId());
226
							ignoredItem.setWarehouseId(entry.getKey());
227
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
9509 vikram.rag 228
 
9404 vikram.rag 229
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
230
								try{
231
									maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
232
								}
233
								catch(TTransportException e){
234
									catalogClient = catalogServiceClient.getClient();  
235
									maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
236
								}
9509 vikram.rag 237
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
9404 vikram.rag 238
								if(nlc !=0 && (maxnlc >= nlc)){
239
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
240
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 7);
241
									available =  available + entry.getValue() - total_held;
9509 vikram.rag 242
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9404 vikram.rag 243
								}
9413 vikram.rag 244
								else if(maxnlc==0){
245
									total_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
246
									heldForSource = heldForSource + total_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 7);
247
									available = available + itemavailability.get(entry.getKey()) - total_held;
9509 vikram.rag 248
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
9413 vikram.rag 249
								}
250
 
9404 vikram.rag 251
							}
252
						}
253
					}
254
					Map<Long,Long> itemreserve = new HashMap<Long,Long>();
255
					itemreserve = iteminventory.getReserved();
256
					if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
257
						//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
258
						for (Warehouse warehouse:vendor_warehouses){
9456 vikram.rag 259
							if(warehouse.getBillingWarehouseId()!=7){
260
								continue;
261
							}
9404 vikram.rag 262
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
263
							ignoredItem.setItemId(thriftItem.getId());
264
							ignoredItem.setWarehouseId(warehouse.getId());
265
							if (itemreserve.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(warehouse.getId())){
266
								nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
267
								maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
9509 vikram.rag 268
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
9404 vikram.rag 269
								if(nlc !=0 && (maxnlc >= nlc)){
270
									reserve = reserve + itemreserve.get(warehouse.getId());
9413 vikram.rag 271
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
9404 vikram.rag 272
								}
9413 vikram.rag 273
								else if(maxnlc==0){
274
									reserve = reserve + itemreserve.get(warehouse.getId());
275
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
276
								}
277
 
9404 vikram.rag 278
							}
279
						}
280
					}else{
281
						for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
9456 vikram.rag 282
							if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
283
								continue;
284
							}
9404 vikram.rag 285
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
286
							ignoredItem.setItemId(thriftItem.getId());
287
							ignoredItem.setWarehouseId(entry.getKey());
288
							if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
289
								nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
290
								maxnlc = catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
9509 vikram.rag 291
								System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
9404 vikram.rag 292
								if(nlc !=0 && (maxnlc >= nlc)){
293
									reserve =  reserve + entry.getValue();
9413 vikram.rag 294
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
9404 vikram.rag 295
								}
9413 vikram.rag 296
								else if(maxnlc==0){
297
									reserve =  reserve + entry.getValue();
298
									System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
299
								}
300
 
9404 vikram.rag 301
							}
9413 vikram.rag 302
 
9404 vikram.rag 303
							else{
304
								//System.out.println("skipping inventory for warehouse id " + entry.getKey());
305
							}
306
						}
307
					}
308
					item= new SnapdealItemForInventory(thriftItem.getId(),available,reserve,heldForSource,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),thriftItem.isRisky(),thriftItem.getItemStatus());
9413 vikram.rag 309
					System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
9404 vikram.rag 310
				}
311
				else{
312
					item = new SnapdealItemForInventory(thriftItem.getId(),0,0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),thriftItem.isRisky(),thriftItem.getItemStatus());
9413 vikram.rag 313
					System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
9404 vikram.rag 314
				}
315
 
316
				//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
317
				//System.out.println("+++++++++++++++++++++++");
318
				allItemsInventoryMap.put(thriftItem.getId(),item);
319
 
320
			}
321
 
322
		} catch (TException e) {
323
			// TODO Auto-generated catch block
324
			e.printStackTrace();
325
		}
326
 
327
	}
9456 vikram.rag 328
	private static void fetchinventoryhistoryfromsnapdeal() throws UnsupportedEncodingException, TException{
9404 vikram.rag 329
		HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
330
		HttpGet get; 
331
		BufferedReader rd= null;
332
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
333
		nameValuePairs.add(new BasicNameValuePair("j_username",
334
		"khushal.bhatia@saholic.com"));
335
		nameValuePairs.add(new BasicNameValuePair("j_password",
336
		"sonline"));
337
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
338
		HttpResponse response = null;
339
		try {
340
			response = client.execute(post);
341
		} catch (ClientProtocolException e) {
342
			// TODO Auto-generated catch block
343
			e.printStackTrace();
344
		} catch (IOException e) {
345
			// TODO Auto-generated catch block
346
			e.printStackTrace();
347
		}
348
		try {
349
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
350
		} catch (IllegalStateException e1) {
351
			// TODO Auto-generated catch block
352
			e1.printStackTrace();
353
		} catch (IOException e1) {
354
			// TODO Auto-generated catch block
355
			e1.printStackTrace();
356
		}
357
		String line = "";
358
		try {
359
			while ((line = rd.readLine()) != null) {
360
				System.out.println(line);
361
			}
362
		} catch (IOException e) {
363
			// TODO Auto-generated catch block
364
			e.printStackTrace();
365
		}
366
		int i = 1;
367
		Gson gson = new Gson();
9456 vikram.rag 368
		inventoryhistoryItemMap = new HashMap<String,InventoryHistory>();
369
		boolean exitfetchinghistory = true;
370
		while(exitfetchinghistory){
371
			System.out.println("Fetching inventory history page " +i);
372
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=history&_search=false&nd="+time+"&rows=30&page="+i+"&sidx=&sord=dsc");
373
			try {
374
				response = client.execute(get);
375
			} catch (ClientProtocolException e) {
376
				// TODO Auto-generated catch block
377
				e.printStackTrace();
378
			} catch (IOException e) {
379
				// TODO Auto-generated catch block
380
				e.printStackTrace();
381
			}
382
			try {
383
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
384
			} catch (IllegalStateException e) {
385
				// TODO Auto-generated catch block
386
				e.printStackTrace();
387
			} catch (IOException e) {
388
				// TODO Auto-generated catch block
389
				e.printStackTrace();
390
			}
391
			InventoryHistoryItems inventoryhistoryitems = (InventoryHistoryItems) gson.fromJson(rd, InventoryHistoryItems.class);
392
			if(inventoryhistoryitems.getRows().size()!=0){
393
				//System.out.println("Parsing page " + i);
394
				for(InventoryHistory inventoryhistory : inventoryhistoryitems.getRows()){
395
					if(inventoryhistory.getUpdateTime() > lastUpdatedInventoryTime){
396
						if(inventoryhistoryItemMap.containsKey(inventoryhistory.getSellerSku())){
397
							if(inventoryhistoryItemMap.get(inventoryhistory.getSellerSku()).getUpdateTime() < inventoryhistory.getUpdateTime()){  
398
								inventoryhistoryItemMap.put(inventoryhistory.getSellerSku(),inventoryhistory);
399
							}
400
						}
401
						else{
402
							inventoryhistoryItemMap.put(inventoryhistory.getSellerSku(),inventoryhistory);
403
						}
404
					}
405
					else{
406
						exitfetchinghistory = false;
407
					}
408
				}
409
			}
410
			else{
411
				exitfetchinghistory = false;
412
			}
413
			i++;
414
		}
9495 vikram.rag 415
		InventoryClient inventoryServiceClient = new InventoryClient();
416
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
417
		List<SnapdealInventoryItem> snapdealInventoryItemHistoryList = inventoryClient.getSnapdealInventorySnapshot();
418
		if(snapdealInventoryItemHistoryList.size()>0){
419
			for(SnapdealInventoryItem snapdealInventoryItem:snapdealInventoryItemHistoryList){
420
				if(itemSnapdealMap.containsKey(snapdealInventoryItem.getItem_id())){
421
					PendingOrderInventoryHistory pendingOrdersInventoryHistory = new PendingOrderInventoryHistory();
422
					pendingOrdersInventoryHistory.setPendingOrders(snapdealInventoryItem.getPendingOrders());
423
					pendingOrdersInventoryHistory.setInventoryHistory(snapdealInventoryItem.getAvailability());
424
					pendingOrdersInventoryHistory.setLastUpdatedTimestamp(snapdealInventoryItem.getLastUpdatedOnSnapdeal());
425
					PendingOrdersInventoryHistoryMap.put(itemSnapdealMap.get(snapdealInventoryItem.getItem_id()).getSkuAtSnapdeal(), pendingOrdersInventoryHistory);
426
				}
427
			}
428
		}
429
		PendingOrderInventoryHistory  pendingOrdersInventoryHistory;
430
		for(Entry<String, InventoryHistory> inventoryHistoryItem :inventoryhistoryItemMap.entrySet()){
431
			if(PendingOrdersInventoryHistoryMap.containsKey(inventoryHistoryItem.getValue().getSellerSku())){
432
				pendingOrdersInventoryHistory = PendingOrdersInventoryHistoryMap.get(inventoryHistoryItem.getValue().getSellerSku());
433
				pendingOrdersInventoryHistory.setInventoryHistory(Long.parseLong(inventoryHistoryItem.getValue().getNewValue()));
434
				pendingOrdersInventoryHistory.setLastUpdatedTimestamp(inventoryHistoryItem.getValue().getUpdateTime());
435
				PendingOrdersInventoryHistoryMap.put(inventoryHistoryItem.getValue().getSellerSku(),pendingOrdersInventoryHistory);
436
			}
437
			else{
438
				pendingOrdersInventoryHistory = new PendingOrderInventoryHistory();
439
				pendingOrdersInventoryHistory.setInventoryHistory(Long.parseLong(inventoryHistoryItem.getValue().getNewValue()));
440
				pendingOrdersInventoryHistory.setLastUpdatedTimestamp(inventoryHistoryItem.getValue().getUpdateTime());
441
				pendingOrdersInventoryHistory.setPendingOrders(0);
442
				PendingOrdersInventoryHistoryMap.put(inventoryHistoryItem.getValue().getSellerSku(),pendingOrdersInventoryHistory);
443
			}
444
		}
9456 vikram.rag 445
	}
446
 
9495 vikram.rag 447
	private static void fetchcurrentinventoryfromsnapdeal() throws UnsupportedEncodingException, TException{
9456 vikram.rag 448
		/*client = new DefaultHttpClient();
449
		HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
450
		BufferedReader rd= null;
451
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
452
		nameValuePairs.add(new BasicNameValuePair("j_username",
453
		"khushal.bhatia@saholic.com"));
454
		nameValuePairs.add(new BasicNameValuePair("j_password",
455
		"sonline"));
456
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
457
		HttpResponse response = null;
9404 vikram.rag 458
		try {
9456 vikram.rag 459
			response = client.execute(post);
460
		} catch (ClientProtocolException e) {
9404 vikram.rag 461
			// TODO Auto-generated catch block
462
			e.printStackTrace();
9456 vikram.rag 463
		} catch (IOException e) {
464
			// TODO Auto-generated catch block
465
			e.printStackTrace();
9404 vikram.rag 466
		}
9456 vikram.rag 467
		try {
468
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
469
		} catch (IllegalStateException e1) {
470
			// TODO Auto-generated catch block
471
			e1.printStackTrace();
472
		} catch (IOException e1) {
473
			// TODO Auto-generated catch block
474
			e1.printStackTrace();
475
		}
476
		String line = "";
477
		try {
478
			while ((line = rd.readLine()) != null) {
479
				System.out.println(line);
480
			}
481
		} catch (IOException e) {
482
			// TODO Auto-generated catch block
483
			e.printStackTrace();
484
		}*/
485
		int i = 1;
486
		int items=0;
487
		Gson gson = new Gson();
488
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
9501 vikram.rag 489
		currentInventoryItemList = new ArrayList<Inventory>();
9456 vikram.rag 490
		HttpGet get;
491
		HttpResponse response = null;
492
		BufferedReader rd= null;
9404 vikram.rag 493
		while(true){
9456 vikram.rag 494
			System.out.println("Fetching current inventory page " +i);
9404 vikram.rag 495
			get = new HttpGet("http://seller.snapdeal.com/inventory/search?gridType=normal&_search=false&nd="+time+"&rows="+30+"&page="+i+"&sidx=&sord=asc");
496
			try {
497
				response = client.execute(get);
498
			} catch (ClientProtocolException e) {
499
				// TODO Auto-generated catch block
500
				e.printStackTrace();
501
			} catch (IOException e) {
502
				// TODO Auto-generated catch block
503
				e.printStackTrace();
504
			}
505
			try {
506
				rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
507
			} catch (IllegalStateException e) {
508
				// TODO Auto-generated catch block
509
				e.printStackTrace();
510
			} catch (IOException e) {
511
				// TODO Auto-generated catch block
512
				e.printStackTrace();
513
			}
514
			InventoryItems inventoryitems = (InventoryItems) gson.fromJson(rd, InventoryItems.class);
515
			if(inventoryitems.getRows().size()!=0){
516
				for(Inventory inventory : inventoryitems.getRows()){
9508 vikram.rag 517
					System.out.println(inventory.getSellerSku());
518
					currentInventoryItemList.add(inventory);
9456 vikram.rag 519
					items++;
520
				}
521
			}
522
			else{
523
				System.out.println("Fetched  " + items);
524
				break;
525
			}
526
			i++;
527
		}
528
		in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
9495 vikram.rag 529
		SnapdealItemDetails snapdealitem = null;
9456 vikram.rag 530
		long sku = 0;
531
		long created_orders;
532
		long pending_orders;
533
		try {
9467 vikram.rag 534
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9456 vikram.rag 535
		} catch (TTransportException e1) {
536
			// TODO Auto-generated catch block
537
			e1.printStackTrace();
538
		}
539
		try {
540
			catalogServiceClient = new CatalogClient().getClient();
541
		} catch (TTransportException e1) {
542
			// TODO Auto-generated catch block
543
			e1.printStackTrace();
544
		}
545
		List<String> notMappedItems = new ArrayList<String>();
9501 vikram.rag 546
		for(Inventory inventory:currentInventoryItemList){
9456 vikram.rag 547
			created_orders = 0;
548
			pending_orders = 0;
9495 vikram.rag 549
			try {
550
				snapdealitem = snapdealItemMap.get(inventory.getSellerSku());
551
				if(snapdealitem==null){
9501 vikram.rag 552
					notMappedItems.add("inventory.getSellerSku() "+inventory.getProductName());
9495 vikram.rag 553
					continue;
554
				}
555
				if(sku!=0){
9459 vikram.rag 556
					try{
9495 vikram.rag 557
						if(lastUpdatedInventoryTime > 0){
9499 vikram.rag 558
							System.out.println("Fetching created orders for " + sku);
559
							System.out.println("Last Updated on Time is  " + lastUpdatedInventoryTime);
9495 vikram.rag 560
							created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7, sku);
9404 vikram.rag 561
						}
562
					}
9495 vikram.rag 563
					catch(TTransportException e){
9501 vikram.rag 564
						if(lastUpdatedInventoryTime > 0){
565
							transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
566
							created_orders = transactionClient.getOrdersCreatedAfterTimestampForSource(lastUpdatedInventoryTime, 7, sku);
567
						}
9459 vikram.rag 568
					}
569
				}
9495 vikram.rag 570
				else{
571
					continue;
572
				}
573
			} catch (TException e) {
574
				// TODO Auto-generated catch block
575
				e.printStackTrace();
9404 vikram.rag 576
			}
9495 vikram.rag 577
			pending_orders = PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).getPendingOrders()+(inventory.getAvailableInventory() - PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).getInventoryHistory() - created_orders);
9456 vikram.rag 578
			itemIdpendingOrdersMap.put(sku, pending_orders);
9495 vikram.rag 579
			PendingOrdersInventoryHistoryMap.get(inventory.getSellerSku()).setPendingOrders(pending_orders);
9404 vikram.rag 580
		}
9495 vikram.rag 581
		List<SnapdealInventoryItem> snapdealInventoryItemList = new ArrayList<SnapdealInventoryItem>();
582
		SnapdealInventoryItem snapdealInventoryItem;
583
		for(Entry<String, PendingOrderInventoryHistory> pendingOrderInventoryHistory:PendingOrdersInventoryHistoryMap.entrySet()){
584
			snapdealInventoryItem = new SnapdealInventoryItem();
585
			if(snapdealItemMap.containsKey(pendingOrderInventoryHistory.getKey())){
586
				snapdealInventoryItem.setItem_id(snapdealItemMap.get(pendingOrderInventoryHistory.getKey()).getItem_id());
587
				snapdealInventoryItem.setPendingOrders(pendingOrderInventoryHistory.getValue().getPendingOrders());
588
				snapdealInventoryItem.setAvailability(pendingOrderInventoryHistory.getValue().getInventoryHistory());
589
				snapdealInventoryItem.setLastUpdatedOnSnapdeal(pendingOrderInventoryHistory.getValue().getLastUpdatedTimestamp());
590
				snapdealInventoryItemList.add(snapdealInventoryItem);
591
			}
592
		}
593
		InventoryClient inventoryServiceClient = new InventoryClient();
594
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
595
		try {
596
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
597
		} catch (TException e) {
598
			// TODO Auto-generated catch block
599
			e.printStackTrace();
600
			inventoryClient = inventoryServiceClient.getClient();
601
			inventoryClient.addOrUpdateAllSnapdealInventory(snapdealInventoryItemList);
602
		}
603
 
9404 vikram.rag 604
	}
605
 
606
	@SuppressWarnings("deprecation")
607
	public static void main(String[] args) throws NumberFormatException, TException, ClientProtocolException, IOException {
9456 vikram.rag 608
		fetchinventoryhistoryfromsnapdeal();
9495 vikram.rag 609
		fetchcurrentinventoryfromsnapdeal();
9404 vikram.rag 610
		calculateinventory();
611
		in.shop2020.model.v1.catalog.CatalogService.Client catalogServiceClient = null;
612
		try {
613
			catalogServiceClient = new CatalogClient().getClient();
614
		} catch (TTransportException e) {
615
			// TODO Auto-generated catch block
616
			e.printStackTrace();
617
		}
618
		Client inventoryClient = new InventoryClient().getClient();
9420 vikram.rag 619
		FileInputStream fis = new FileInputStream("/root/code/trunk/SnapDealFeeds/SellerInventory.xls");
9413 vikram.rag 620
		Workbook hwb = new HSSFWorkbook(fis);
621
		Sheet sheet = hwb.getSheetAt(0);
622
		Row row;
9404 vikram.rag 623
		int iterator=1;
9456 vikram.rag 624
		long availability,reserve,defaultinventory,holdinventory,actualavailability,heldorders=0,sent_inventory;
9404 vikram.rag 625
		SnapdealItemForInventory  inventoryItem;
9456 vikram.rag 626
		StringBuffer outOfStockItems =new StringBuffer();
627
		StringBuffer backInStockItems =new StringBuffer();
628
		long sku = 0;
9502 vikram.rag 629
		SnapdealItemDetails snapdealitem;
9501 vikram.rag 630
		for(Inventory inventory:currentInventoryItemList){
9456 vikram.rag 631
			//System.out.println(inventory.getSupc()+" "+inventory.getSellerSku()+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+inventory.isLive()+" "+itemIdpendingOrdersMap.get(Long.parseLong(inventory.getSellerSku())));
9508 vikram.rag 632
			if(snapdealItemMap.containsKey(inventory.getSellerSku())){
633
				snapdealitem = snapdealItemMap.get(inventory.getSellerSku()); 
634
				sku =  snapdealitem.getItem_id();
635
			}
636
			else{
637
				continue;
638
			}
9404 vikram.rag 639
			if(snapdealitem.getItem_id()!=0 && snapdealitem.isIsListedOnSnapdeal() && !snapdealitem.isSuppressInventoryFeed()){
9495 vikram.rag 640
				inventoryItem = allItemsInventoryMap.get(sku);
9404 vikram.rag 641
				if(inventoryItem==null){
642
					continue;
643
				}
644
				availability = inventoryItem.getAvailability(); 
645
				reserve = inventoryItem.getReserve();
646
				defaultinventory = inventoryItem.getDefaultInventory();
647
				holdinventory = inventoryItem.getHoldInventory();
648
				actualavailability = availability - reserve;
9495 vikram.rag 649
				if(itemIdpendingOrdersMap.containsKey(sku)){
650
					heldorders = itemIdpendingOrdersMap.get(sku);
9458 vikram.rag 651
					if(heldorders < 0){
652
						heldorders = 0;
653
					}
9456 vikram.rag 654
				}
9413 vikram.rag 655
				System.out.println("itemId:" + inventoryItem.getId() + "\tavailable: " + inventoryItem.getAvailability() + "\treserve" + inventoryItem.getReserve() + "\theldForSource:" + inventoryItem.getHeldForSource() + "\twebsite_hold:" + inventoryItem.getHoldInventory() + "\tdefault_inv:" +inventoryItem.getDefaultInventory() + "\theldorders" + heldorders);
9404 vikram.rag 656
				row =   sheet.getRow((short) iterator);
657
				long inventoryForRiskyItem = actualavailability - holdinventory;
658
				if(inventoryItem.getRisky()){
659
					if(inventoryForRiskyItem > 0){
9413 vikram.rag 660
						if((Math.round(inventoryForRiskyItem*2/3) - heldorders + inventoryItem.getHeldForSource()) > 0){
9415 vikram.rag 661
							sent_inventory = Math.round(inventoryForRiskyItem*2/3) - heldorders + inventoryItem.getHeldForSource();
9404 vikram.rag 662
						}
663
						else{
9415 vikram.rag 664
							sent_inventory = 0;
9404 vikram.rag 665
						}
666
					}
667
					else{
9415 vikram.rag 668
						sent_inventory = 0;
9404 vikram.rag 669
					}
670
				}
671
				else{
672
					if(actualavailability > defaultinventory){
9413 vikram.rag 673
						if((Math.round(actualavailability*2/3) +  inventoryItem.getHeldForSource()) > heldorders){
674
							System.out.println("actual" + actualavailability + "\t2/3actual" + Math.round(actualavailability*2/3) +  "\theld for source" + inventoryItem.getHeldForSource() + "\theldorders" +  heldorders + "\tFinal Value is : " + (Math.round(actualavailability*2/3) +  inventoryItem.getHeldForSource() - heldorders));
9415 vikram.rag 675
							sent_inventory = Math.round(actualavailability*2/3) +  inventoryItem.getHeldForSource() - heldorders;
9404 vikram.rag 676
						}
677
						else{
9415 vikram.rag 678
							sent_inventory = 0;
9404 vikram.rag 679
						}
680
					}
681
					else{
682
						if(defaultinventory > heldorders){
9415 vikram.rag 683
							sent_inventory = defaultinventory - heldorders;
9404 vikram.rag 684
						}
685
						else{
9415 vikram.rag 686
							sent_inventory = 0;
9404 vikram.rag 687
						}
688
					}
689
				}
9456 vikram.rag 690
				if(inventory.getAvailableInventory()!= sent_inventory){
691
					row.getCell((short) 0).setCellValue(inventory.getSupc());
692
					row.getCell((short) 1).setCellValue(inventory.getSellerSku());
693
					row.getCell((short) 2).setCellValue(inventory.getProductName());
694
					row.getCell((short) 3).setCellValue(inventory.getAvailableInventory());
695
					row.getCell((short) 4).setCellValue(sent_inventory);
696
					if(inventory.getAvailableInventory()!=0 && sent_inventory==0){
9459 vikram.rag 697
						outOfStockItems.append(sku+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+sent_inventory+"\n");
9456 vikram.rag 698
					}
699
					if(inventory.getAvailableInventory()==0 && sent_inventory!=0){
9459 vikram.rag 700
						backInStockItems.append(sku+ " " +inventory.getProductName()+" "+inventory.getAvailableInventory()+" "+sent_inventory+"\n");
9456 vikram.rag 701
					}
702
					if(inventory.isLive()){
703
						row.getCell((short) 5).setCellValue("Yes");
704
					}
705
					else{
706
						row.getCell((short) 5).setCellValue("No");
707
					}
708
					iterator++;
9404 vikram.rag 709
				}
710
			}
711
			else{
712
				continue;
713
			}
714
		}
715
		FileOutputStream fileOut = null;
716
		fis.close();
717
		try {
9456 vikram.rag 718
			System.out.println("Before writing file ");
9404 vikram.rag 719
			fileOut = new FileOutputStream(SNAPDEAL_INVENTORY_SHEET);
720
		} catch (FileNotFoundException e) {
721
			// TODO Auto-generated catch block
722
			e.printStackTrace();
723
		}
724
		try {
9459 vikram.rag 725
 
9404 vikram.rag 726
			hwb.write(fileOut);
727
		} catch (IOException e) {
728
			// TODO Auto-generated catch block
729
			e.printStackTrace();
730
		}
9413 vikram.rag 731
		/*		HttpClient client = new DefaultHttpClient();
9404 vikram.rag 732
		HttpPost post = new HttpPost("http://seller.snapdeal.com/login_security_check?spring-security-redirect=http://seller.snapdeal.com/inventory&");
733
		BufferedReader rd= null;
9405 vikram.rag 734
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
9404 vikram.rag 735
		nameValuePairs.add(new BasicNameValuePair("j_username",
736
		"khushal.bhatia@saholic.com"));
737
		nameValuePairs.add(new BasicNameValuePair("j_password",
738
		"sonline"));
9405 vikram.rag 739
		post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
9404 vikram.rag 740
		HttpResponse response = null;
741
		String line;
9405 vikram.rag 742
		try {
9404 vikram.rag 743
			response = client.execute(post);
744
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
745
			while ((line = rd.readLine()) != null) {
746
				System.out.println(line);
747
			}
748
 
749
		} catch (ClientProtocolException e) {
750
			// TODO Auto-generated catch block
751
			e.printStackTrace();
752
		} catch (IOException e) {
753
			// TODO Auto-generated catch block
754
			e.printStackTrace();
755
		}
9405 vikram.rag 756
		post = new HttpPost("http://seller.snapdeal.com/inventory/upload");
9404 vikram.rag 757
		File file = new File("/home/vikram/snapdeal-inventory-1389608325312.xls");
758
		MultipartEntity mpEntity = new MultipartEntity();
759
	    ContentBody cbFile = new FileBody(file,"application/vnd.ms-excel");
760
	    mpEntity.addPart("file", cbFile);
761
	    post.setEntity(mpEntity);
762
		response = client.execute(post);
763
		try {
764
			rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
765
		} catch (IllegalStateException e1) {
766
			// TODO Auto-generated catch block
767
			e1.printStackTrace();
768
		} catch (IOException e1) {
769
			// TODO Auto-generated catch block
770
			e1.printStackTrace();
771
		}
772
		line = "";
773
		try {
774
			while ((line = rd.readLine()) != null) {
775
				System.out.println(line);
776
			}
777
		} catch (IOException e) {
778
			// TODO Auto-generated catch block
779
			e.printStackTrace();
780
		}
9413 vikram.rag 781
		 */
9495 vikram.rag 782
		in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
783
		long lastSentInventoryTime = System.currentTimeMillis();
784
		try {
9497 vikram.rag 785
			transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 786
			transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
787
		} catch (Exception e) {
788
			try {
9497 vikram.rag 789
				transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
9495 vikram.rag 790
				transactionClient.updateSourceDetailTimestamp(7, lastSentInventoryTime);
791
			} catch (Exception ex) {
792
				ex.printStackTrace();
793
			}
794
		}
9459 vikram.rag 795
		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
796
		String emailFromAddress = "build@shop2020.in";
797
		String password = "cafe@nes";
798
		GmailUtils mailer = new GmailUtils();
9495 vikram.rag 799
		String sendTo[] = new String[]{"vikram.raghav@shop2020.in"};
800
		//String sendTo[] = new String[]{"vikram.raghav@shop2020.in","kshitij.sood@shop2020.in"};
9459 vikram.rag 801
		/*String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
802
				"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
803
				"yukti.jain@shop2020.in","manisha.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in"};
804
		 */
9495 vikram.rag 805
		String emailSubjectTxt = "Products back in stock on Snapdeal "+sdf.format(lastSentInventoryTime);
9459 vikram.rag 806
		String text = backInStockItems.toString();
807
		if(text.length() > 0){
808
			try {
809
				mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
810
			} catch (MessagingException e) {
811
				e.printStackTrace();
812
			}
813
		}
9496 vikram.rag 814
		emailSubjectTxt = "Products out of stock on Snapdeal "+sdf.format(lastSentInventoryTime);
9459 vikram.rag 815
		text = outOfStockItems.toString();
816
		if(text.length() > 0){
817
			try {
818
				mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
819
			} catch (MessagingException e) {
820
				e.printStackTrace();
821
			}
822
		}
9460 vikram.rag 823
		List<File> files = new ArrayList<File>();
824
		files.add(new File(SNAPDEAL_INVENTORY_SHEET));
825
		try {
9471 vikram.rag 826
			mailer.sendSSLMessage(sendTo,"Inventory File","Please see attached inventory file", emailFromAddress, password, files);
9460 vikram.rag 827
		} catch (MessagingException e) {
828
			e.printStackTrace();
829
		}
9459 vikram.rag 830
 
9495 vikram.rag 831
 
9404 vikram.rag 832
	}
833
 
834
}