Subversion Repositories SmartDukaan

Rev

Rev 11949 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11874 manish.sha 1
package in.shop2020;
2
 
3
import in.shop2020.model.v1.catalog.FlipkartItem;
4
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
6
import in.shop2020.model.v1.inventory.InventoryType;
7
import in.shop2020.model.v1.inventory.ItemInventory;
8
import in.shop2020.model.v1.inventory.Vendor;
9
import in.shop2020.model.v1.inventory.Warehouse;
10
import in.shop2020.model.v1.inventory.WarehouseLocation;
11
import in.shop2020.model.v1.inventory.WarehouseType;
12
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.InventoryClient;
14
import in.shop2020.thrift.clients.TransactionClient;
15
import in.shop2020.utils.GmailUtils;
16
//import inventory.Inventory;
17
import inventory.FlipkartInventoryItem;
18
import inventory.NlcLeftOutInventory;
19
//import inventory.SnapdealItemForInventory;
20
 
21
import java.io.BufferedReader;
22
import java.io.BufferedWriter;
23
import java.io.File;
11944 manish.sha 24
import java.io.FileReader;
11874 manish.sha 25
import java.io.FileWriter;
26
import java.io.IOException;
27
import java.io.InputStreamReader;
28
import java.util.ArrayList;
11940 manish.sha 29
import java.util.Collections;
11874 manish.sha 30
import java.util.HashMap;
11882 manish.sha 31
import java.util.HashSet;
32
import java.util.Iterator;
11874 manish.sha 33
import java.util.List;
34
import java.util.Map;
11882 manish.sha 35
import java.util.Set;
11874 manish.sha 36
 
37
import javax.mail.MessagingException;
38
 
39
import org.apache.commons.lang.StringUtils;
40
import org.apache.http.Header;
41
import org.apache.http.HttpResponse;
42
import org.apache.http.NameValuePair;
43
import org.apache.http.client.ClientProtocolException;
44
import org.apache.http.client.HttpClient;
45
import org.apache.http.client.entity.UrlEncodedFormEntity;
46
import org.apache.http.client.methods.HttpGet;
47
import org.apache.http.client.methods.HttpPost;
48
import org.apache.http.impl.client.DefaultHttpClient;
49
import org.apache.http.message.BasicNameValuePair;
50
import org.apache.http.params.HttpParams;
51
import org.apache.thrift.TException;
52
import org.apache.thrift.transport.TTransportException;
53
 
11940 manish.sha 54
public class NlcLeftOutInventoryDetailScript {
11874 manish.sha 55
 
11940 manish.sha 56
	// private static ArrayList<Inventory> currentInventoryItemList;
11874 manish.sha 57
	private static List<SnapdealItemDetails> snapdealItems;
58
	private static List<FlipkartItem> flipkartItems;
59
	private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
11940 manish.sha 60
	static Map<Long, SnapdealItemDetails> snapdealItemMap = new HashMap<Long, SnapdealItemDetails>();
61
	static Map<Long, FlipkartItem> flipkartItemMap = new HashMap<Long, FlipkartItem>();
62
	// private static Map<Long, SnapdealItemForInventory> allItemsInventoryMap =
63
	// new HashMap<Long, SnapdealItemForInventory>();
11874 manish.sha 64
	private static Map<Long, String> vendorDataMap = new HashMap<Long, String>();
11940 manish.sha 65
	// static java.text.SimpleDateFormat sdf;
11874 manish.sha 66
	static String emailFromAddress;
67
	static String password;
68
	static GmailUtils mailer;
69
	static String sendTo[];
11889 manish.sha 70
	private static Map<String, Map<Long, NlcLeftOutInventory>> nlcLoiItemsMapSD = new HashMap<String, Map<Long, NlcLeftOutInventory>>();
71
	private static Map<String, Map<Long, NlcLeftOutInventory>> nlcLoiItemsMapFK = new HashMap<String, Map<Long, NlcLeftOutInventory>>();
11874 manish.sha 72
 
11940 manish.sha 73
	private static List<NlcLeftOutInventory> mainNlcLoiItemsListSD = new ArrayList<NlcLeftOutInventory>();
74
	private static List<NlcLeftOutInventory> mainNlcLoiItemsListFK = new ArrayList<NlcLeftOutInventory>();
75
 
76
	static {
11891 manish.sha 77
		emailFromAddress = "build-staging@shop2020.in";
78
		password = "shop2020";
11874 manish.sha 79
		mailer = new GmailUtils();
11949 manish.sha 80
		//sendTo = new String[] { "vikram.raghav@shop2020.in", "manish.sharma@shop2020.in" };
81
 
82
		sendTo = new String[]{ "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
83
		  "khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
84
		  "chandan.kumar@shop2020.in" , "manish.sharma@shop2020.in"};
85
 
11874 manish.sha 86
		CatalogClient catalogServiceClient = null;
87
		try {
88
			catalogServiceClient = new CatalogClient();
89
		} catch (TTransportException e1) {
90
			// TODO Auto-generated catch block
91
			e1.printStackTrace();
92
		}
11940 manish.sha 93
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient
11944 manish.sha 94
		.getClient();
11874 manish.sha 95
 
96
		try {
97
			snapdealItems = catalogClient.getAllSnapdealItems();
98
			flipkartItems = catalogClient.getAllFlipkartItems();
99
		} catch (TException e) {
100
			// TODO Auto-generated catch block
101
			e.printStackTrace();
102
		}
11940 manish.sha 103
		for (FlipkartItem flipkartItem : flipkartItems) {
104
			if (flipkartItem.isIsListedOnFlipkart()
105
					&& !flipkartItem.isSuppressInventoryFeed())
11874 manish.sha 106
				flipkartInventoryItems.add(flipkartItem);
107
		}
108
 
11940 manish.sha 109
		for (FlipkartItem flipkartItem : flipkartItems) {
110
			if (flipkartItem.isIsListedOnFlipkart()
111
					&& !flipkartItem.isSuppressInventoryFeed()) {
11874 manish.sha 112
				flipkartItemMap.put(flipkartItem.getItem_id(), flipkartItem);
113
			}
114
		}
115
 
11940 manish.sha 116
		for (SnapdealItemDetails snapdealItem : snapdealItems) {
117
			snapdealItemMap.put(snapdealItem.getItem_id(), snapdealItem);
11874 manish.sha 118
		}
119
 
11940 manish.sha 120
		if (flipkartItemMap.size() == 0) {
11874 manish.sha 121
			String text = "";
122
			try {
11940 manish.sha 123
				mailer.sendSSLMessage(sendTo,
124
						"No items to check not sent Inventory Data ",
125
						emailFromAddress, password, text);
11874 manish.sha 126
				System.exit(0);
127
			} catch (MessagingException e) {
128
				e.printStackTrace();
129
			}
130
		}
131
 
11940 manish.sha 132
		if (snapdealItemMap.size() == 0) {
11874 manish.sha 133
			String text = "";
134
			try {
11940 manish.sha 135
				mailer.sendSSLMessage(sendTo,
136
						"No items to check not sent Inventory Data ",
137
						emailFromAddress, password, text);
11874 manish.sha 138
				System.exit(0);
139
			} catch (MessagingException e) {
140
				e.printStackTrace();
141
			}
142
		}
143
	}
144
 
11940 manish.sha 145
	private static void calculateinventory() {
11874 manish.sha 146
		CatalogClient catalogServiceClient = null;
11940 manish.sha 147
		Map<Long, ItemInventory> availability = new HashMap<Long, ItemInventory>();
11874 manish.sha 148
		try {
149
			catalogServiceClient = new CatalogClient();
150
		} catch (TTransportException e) {
151
			e.printStackTrace();
152
		}
11940 manish.sha 153
		in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient
11944 manish.sha 154
		.getClient();
11874 manish.sha 155
		try {
156
			List<Item> aliveItems = catalogClient.getAllAliveItems();
11940 manish.sha 157
			Map<Long, Item> aliveItemsMap = new HashMap<Long, Item>();
158
			for (in.shop2020.model.v1.catalog.Item thriftItem : aliveItems) {
11874 manish.sha 159
				aliveItemsMap.put(thriftItem.getId(), thriftItem);
160
 
161
			}
162
			InventoryClient inventoryServiceClient = new InventoryClient();
163
			try {
164
				inventoryServiceClient = new InventoryClient();
165
			} catch (TTransportException e) {
166
				e.printStackTrace();
167
			}
11940 manish.sha 168
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient
11944 manish.sha 169
			.getClient();
11874 manish.sha 170
			List<Vendor> allVendors = inventoryClient.getAllVendors();
11940 manish.sha 171
			for (Vendor v : allVendors) {
11874 manish.sha 172
				vendorDataMap.put(v.getId(), v.getName());
173
			}
11940 manish.sha 174
			List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient
11944 manish.sha 175
			.getIgnoredWarehouseidsAndItemids();
11889 manish.sha 176
 
11874 manish.sha 177
			availability = inventoryClient.getInventorySnapshot(0);
11940 manish.sha 178
			List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,
179
					null, 0, 0, 0);
180
			Map<Long, Warehouse> allWarehousesMap = new HashMap<Long, Warehouse>();
181
			for (Warehouse warehouse : allwarehouses) {
182
				allWarehousesMap.put(warehouse.getId(), warehouse);
11874 manish.sha 183
			}
11940 manish.sha 184
			List<Warehouse> warehouses = inventoryClient.getWarehouses(
185
					WarehouseType.OURS_THIRDPARTY, null, 0, 0, 0);
186
			List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(
187
					WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
11874 manish.sha 188
			List<Long> thirdpartywarehouseids = new ArrayList<Long>();
189
			List<Long> oursGoodWarehouse = new ArrayList<Long>();
11940 manish.sha 190
			for (Warehouse warehouse : warehouses) {
11874 manish.sha 191
				thirdpartywarehouseids.add(warehouse.getId());
192
			}
11940 manish.sha 193
			for (Warehouse warehouse : ours_warehouses) {
11874 manish.sha 194
				oursGoodWarehouse.add(warehouse.getId());
195
			}
11940 manish.sha 196
			/*
197
			 * long available=0; long reserve=0; long total_warehouse_held=0;
198
			 * long heldForSource=0; long total_held=0;
199
			 */
200
			double nlc = 0;
201
			double maxnlcSD = 0;
202
			double maxnlcFK = 0;
11874 manish.sha 203
 
11886 manish.sha 204
			Map<String, Map<Long, NlcLeftOutInventory>> snapdealLeftInvDataMap = new HashMap<String, Map<Long, NlcLeftOutInventory>>();
205
			Map<String, Map<Long, NlcLeftOutInventory>> flipkartLeftInvDataMap = new HashMap<String, Map<Long, NlcLeftOutInventory>>();
11874 manish.sha 206
 
11940 manish.sha 207
			for (Item thriftItem : aliveItems) {
11874 manish.sha 208
				SnapdealItemDetails snapdealItem = null;
209
				FlipkartItem flipkartItem = null;
210
				NlcLeftOutInventory nlcLOISD;
211
				NlcLeftOutInventory nlcLOIFK;
11940 manish.sha 212
				maxnlcSD = 0;
213
				maxnlcFK = 0;
11886 manish.sha 214
				Map<Long, NlcLeftOutInventory> nlcLoiMapSD = new HashMap<Long, NlcLeftOutInventory>();
215
				Map<Long, NlcLeftOutInventory> nlcLoiMapFK = new HashMap<Long, NlcLeftOutInventory>();
11882 manish.sha 216
				Set<NlcLeftOutInventory> nlcLoiSetSD = new HashSet<NlcLeftOutInventory>();
217
				Set<NlcLeftOutInventory> nlcLoiSetFK = new HashSet<NlcLeftOutInventory>();
11940 manish.sha 218
				if (snapdealItemMap.containsKey(thriftItem.getId())) {
11874 manish.sha 219
					snapdealItem = snapdealItemMap.get(thriftItem.getId());
220
					maxnlcSD = snapdealItem.getMaxNlc();
221
				}
11940 manish.sha 222
				if (flipkartItemMap.containsKey(thriftItem.getId())) {
11874 manish.sha 223
					flipkartItem = flipkartItemMap.get(thriftItem.getId());
224
					maxnlcFK = flipkartItem.getMaxNlc();
225
				}
11940 manish.sha 226
				nlc = 0;
227
				List<Warehouse> vendor_warehouses = null;
228
				if (availability.get(thriftItem.getId()) != null) {
229
					ItemInventory iteminventory = availability.get(thriftItem
230
							.getId());
231
					Map<Long, Long> itemavailability = new HashMap<Long, Long>();
11874 manish.sha 232
					itemavailability = iteminventory.getAvailability();
11940 manish.sha 233
					if (thriftItem.isIsWarehousePreferenceSticky()
234
							&& thriftItem.getPreferredVendor() != 0) {
235
						// System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());
236
						vendor_warehouses = inventoryClient.getWarehouses(
237
								WarehouseType.THIRD_PARTY, InventoryType.GOOD,
238
								thriftItem.getPreferredVendor(), 0, 0);
11874 manish.sha 239
						vendor_warehouses.addAll(ours_warehouses);
11940 manish.sha 240
						for (Warehouse warehouse : vendor_warehouses) {
241
							if (warehouse.getBillingWarehouseId() != 7) {
242
								if (warehouse.getLogisticsLocation().equals(
243
										WarehouseLocation.Delhi)
244
										&& warehouse.getWarehouseType().equals(
245
												WarehouseType.THIRD_PARTY)
11944 manish.sha 246
												&& warehouse.getVendor().getId() != 1) {
11874 manish.sha 247
 
11940 manish.sha 248
								} else {
11874 manish.sha 249
									continue;
250
								}
251
							}
252
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
253
							ignoredItem.setItemId(thriftItem.getId());
254
							ignoredItem.setWarehouseId(warehouse.getId());
11940 manish.sha 255
							if (itemavailability.get(warehouse.getId()) != null
256
									&& !thirdpartywarehouseids
11944 manish.sha 257
									.contains(warehouse.getId())
11940 manish.sha 258
									&& !ignoreItems.contains(ignoredItem)) {
259
								try {
260
									nlc = inventoryClient.getNlcForWarehouse(
261
											warehouse.getId(),
262
											thriftItem.getId());
11874 manish.sha 263
 
11940 manish.sha 264
								} catch (TTransportException e) {
265
									inventoryClient = inventoryServiceClient
11944 manish.sha 266
									.getClient();
11940 manish.sha 267
									nlc = inventoryClient.getNlcForWarehouse(
268
											warehouse.getId(),
269
											thriftItem.getId());
11874 manish.sha 270
								}
271
 
11940 manish.sha 272
								// maxnlc =
273
								// catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
11874 manish.sha 274
 
11940 manish.sha 275
								if (snapdealItem != null) {
276
									if (nlc != 0 && (maxnlcSD >= nlc)) {
277
										/*
278
										 * total_warehouse_held =
279
										 * inventoryClient.
280
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
281
										 * (thriftItem.getId(),
282
										 * warehouse.getId(), 0); heldForSource
283
										 * = heldForSource +
284
										 * total_warehouse_held -
285
										 * inventoryClient.
286
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
287
										 * (thriftItem.getId(),
288
										 * warehouse.getId(), 7); available =
289
										 * available +
290
										 * itemavailability.get(warehouse
291
										 * .getId()); total_held = total_held +
292
										 * total_warehouse_held;
293
										 */
294
										// continue;
295
										// System.out.println("itemId:" +
296
										// thriftItem.getId() + "\ttotal_held: "
297
										// + total_held + "\theldForSource:" +
298
										// heldForSource + "\tavailable:" +
299
										// available);
300
									} else if (maxnlcSD == 0) {
301
										/*
302
										 * total_warehouse_held =
303
										 * inventoryClient.
304
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
305
										 * (thriftItem.getId(),
306
										 * warehouse.getId(), 0); heldForSource
307
										 * = heldForSource +
308
										 * total_warehouse_held -
309
										 * inventoryClient.
310
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
311
										 * (thriftItem.getId(),
312
										 * warehouse.getId(), 7); available =
313
										 * available +
314
										 * itemavailability.get(warehouse
315
										 * .getId()); total_held = total_held +
316
										 * total_warehouse_held;
317
										 */
318
										// continue;
319
										// System.out.println("itemId:" +
320
										// thriftItem.getId() + "\ttotal_held: "
321
										// + total_held + "\theldForSource:" +
322
										// heldForSource + "\tavailable:" +
323
										// available);
324
									} else {
325
										long available = itemavailability
11944 manish.sha 326
										.get(warehouse.getId());
11940 manish.sha 327
										if (available > 0) {
328
											nlcLOISD = new NlcLeftOutInventory();
329
											nlcLOISD.setItemId(snapdealItem
330
													.getItem_id());
331
											nlcLOISD.setProductName(snapdealItem
332
													.getBrand()
333
													+ " "
334
													+ snapdealItem
11944 manish.sha 335
													.getModel_name()
11940 manish.sha 336
													+ " "
337
													+ snapdealItem
11944 manish.sha 338
													.getModel_number()
11940 manish.sha 339
													+ " "
340
													+ snapdealItem.getColor());
11875 manish.sha 341
											nlcLOISD.setOurNlc(maxnlcSD);
11940 manish.sha 342
											nlcLOISD.setSkuAtSource(snapdealItem
343
													.getSkuAtSnapdeal());
344
											nlcLOISD.setVendorName(warehouse
345
													.getVendor().getName());
11875 manish.sha 346
											nlcLOISD.setVendorAvailability(available);
347
											nlcLOISD.setVendorNlc(nlc);
11940 manish.sha 348
											nlcLOISD.setVendorWarehouseId(warehouse
349
													.getId());
350
											nlcLOISD.setWarehouseType(warehouse
351
													.getWarehouseType()
352
													.toString());
353
											if (!nlcLoiMapSD
354
													.containsKey(warehouse
355
															.getId()))
356
												nlcLoiMapSD.put(
357
														warehouse.getId(),
358
														nlcLOISD);
11889 manish.sha 359
 
11875 manish.sha 360
										}
11874 manish.sha 361
									}
362
								}
363
 
11940 manish.sha 364
								if (flipkartItem != null) {
365
									if (nlc != 0 && (maxnlcFK >= nlc)) {
366
										/*
367
										 * total_warehouse_held =
368
										 * inventoryClient.
369
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
370
										 * (thriftItem.getId(),
371
										 * warehouse.getId(), 0); heldForSource
372
										 * = heldForSource +
373
										 * total_warehouse_held -
374
										 * inventoryClient.
375
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
376
										 * (thriftItem.getId(),
377
										 * warehouse.getId(), 8); available =
378
										 * available +
379
										 * itemavailability.get(warehouse
380
										 * .getId()); total_held = total_held +
381
										 * total_warehouse_held;
382
										 */
383
										// continue;
384
										// System.out.println("itemId:" +
385
										// thriftItem.getId() + "\ttotal_held: "
386
										// + total_held + "\theldForSource:" +
387
										// heldForSource + "\tavailable:" +
388
										// available);
389
									} else if (maxnlcFK == 0) {
390
										/*
391
										 * total_warehouse_held =
392
										 * inventoryClient.
393
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
394
										 * (thriftItem.getId(),
395
										 * warehouse.getId(), 0); heldForSource
396
										 * = heldForSource +
397
										 * total_warehouse_held -
398
										 * inventoryClient.
399
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
400
										 * (thriftItem.getId(),
401
										 * warehouse.getId(), 8); available =
402
										 * available +
403
										 * itemavailability.get(warehouse
404
										 * .getId()); total_held = total_held +
405
										 * total_warehouse_held;
406
										 */
407
										// continue;
408
										// System.out.println("itemId:" +
409
										// thriftItem.getId() + "\ttotal_held: "
410
										// + total_held + "\theldForSource:" +
411
										// heldForSource + "\tavailable:" +
412
										// available);
413
									} else {
414
										long available = itemavailability
11944 manish.sha 415
										.get(warehouse.getId());
11940 manish.sha 416
										if (available > 0) {
11875 manish.sha 417
											nlcLOIFK = new NlcLeftOutInventory();
11940 manish.sha 418
											nlcLOIFK.setItemId(flipkartItem
419
													.getItem_id());
420
											nlcLOIFK.setProductName(thriftItem
421
													.getBrand()
422
													+ " "
423
													+ thriftItem.getModelName()
424
													+ " "
425
													+ thriftItem
11944 manish.sha 426
													.getModelNumber()
11940 manish.sha 427
													+ " "
428
													+ thriftItem.getColor());
11875 manish.sha 429
											nlcLOIFK.setOurNlc(maxnlcFK);
11940 manish.sha 430
											nlcLOIFK.setSkuAtSource(flipkartItem
431
													.getSkuAtFlipkart());
432
											nlcLOIFK.setVendorName(warehouse
433
													.getVendor().getName());
11875 manish.sha 434
											nlcLOIFK.setVendorAvailability(available);
435
											nlcLOIFK.setVendorNlc(nlc);
11940 manish.sha 436
											nlcLOIFK.setVendorWarehouseId(warehouse
437
													.getId());
438
											nlcLOIFK.setWarehouseType(warehouse
439
													.getWarehouseType()
440
													.toString());
441
											if (!nlcLoiMapFK
442
													.containsKey(warehouse
443
															.getId()))
444
												nlcLoiMapFK.put(
445
														warehouse.getId(),
446
														nlcLOIFK);
11875 manish.sha 447
										}
11874 manish.sha 448
									}
449
								}
11940 manish.sha 450
								// System.out.println("itemId:" +
451
								// thriftItem.getId() + "\tmaxnlc: " + maxnlc +
452
								// "\tnlc:" + nlc + "\twid:" + warehouse.getId()
453
								// );
11874 manish.sha 454
 
455
							}
456
						}
11940 manish.sha 457
						if (nlcLoiMapSD != null && nlcLoiMapSD.size() > 0) {
458
							snapdealLeftInvDataMap.put(
459
									snapdealItem.getSkuAtSnapdeal(),
460
									nlcLoiMapSD);
11884 manish.sha 461
						}
11940 manish.sha 462
						if (nlcLoiMapFK != null && nlcLoiMapFK.size() > 0) {
463
							flipkartLeftInvDataMap.put(
464
									flipkartItem.getSkuAtFlipkart(),
465
									nlcLoiMapFK);
11884 manish.sha 466
						}
11940 manish.sha 467
					} else {
468
						for (Map.Entry<Long, Long> entry : itemavailability
469
								.entrySet()) {
470
							if (allWarehousesMap.get(entry.getKey())
471
									.getBillingWarehouseId() != 7) {
472
								if (allWarehousesMap.get(entry.getKey())
473
										.getLogisticsLocation()
474
										.equals(WarehouseLocation.Delhi)
475
										&& allWarehousesMap
11944 manish.sha 476
										.get(entry.getKey())
477
										.getWarehouseType()
478
										.equals(WarehouseType.THIRD_PARTY)
11940 manish.sha 479
										&& allWarehousesMap.get(entry.getKey())
11944 manish.sha 480
										.getVendor().getId() != 1) {
11874 manish.sha 481
 
11940 manish.sha 482
								} else {
11874 manish.sha 483
									continue;
484
								}
485
							}
486
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
487
							ignoredItem.setItemId(thriftItem.getId());
488
							ignoredItem.setWarehouseId(entry.getKey());
11940 manish.sha 489
							if (!thirdpartywarehouseids
490
									.contains(entry.getKey())
491
									&& !ignoreItems.contains(ignoredItem)) {
11874 manish.sha 492
 
11940 manish.sha 493
								nlc = inventoryClient.getNlcForWarehouse(
494
										entry.getKey(), thriftItem.getId());
11874 manish.sha 495
 
11940 manish.sha 496
								// System.out.println("itemId:" +
497
								// thriftItem.getId() + "\tmaxnlc: " + maxnlc +
498
								// "\tnlc:" + nlc + "\twid:" + entry.getKey() );
499
								if (snapdealItem != null) {
500
									if (nlc != 0 && (maxnlcSD >= nlc)) {
501
										/*
502
										 * total_warehouse_held =
503
										 * inventoryClient.
504
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
505
										 * (thriftItem.getId(), entry.getKey(),
506
										 * 0); heldForSource = heldForSource +
507
										 * total_warehouse_held -
508
										 * inventoryClient.
509
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
510
										 * (thriftItem.getId(), entry.getKey(),
511
										 * 7); available = available +
512
										 * entry.getValue(); total_held =
513
										 * total_held + total_warehouse_held;
514
										 */
515
										// continue;
516
										// System.out.println("itemId:" +
517
										// thriftItem.getId() + "\ttotal_held: "
518
										// + total_held + "\theldForSource:" +
519
										// heldForSource + "\tavailable:" +
520
										// available);
521
									} else if (maxnlcSD == 0) {
522
										/*
523
										 * total_warehouse_held =
524
										 * inventoryClient.
525
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
526
										 * (thriftItem.getId(), entry.getKey(),
527
										 * 0); heldForSource = heldForSource +
528
										 * total_warehouse_held -
529
										 * inventoryClient.
530
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
531
										 * (thriftItem.getId(), entry.getKey(),
532
										 * 7); available = available +
533
										 * itemavailability.get(entry.getKey());
534
										 * total_held = total_held +
535
										 * total_warehouse_held;
536
										 */
11874 manish.sha 537
 
11940 manish.sha 538
										// continue;
539
										// System.out.println("itemId:" +
540
										// thriftItem.getId() + "\ttotal_held: "
541
										// + total_held + "\theldForSource:" +
542
										// heldForSource + "\tavailable:" +
543
										// available);
544
									} else {
545
										long available = itemavailability
11944 manish.sha 546
										.get(entry.getKey());
11940 manish.sha 547
										if (available > 0) {
11875 manish.sha 548
											nlcLOISD = new NlcLeftOutInventory();
11940 manish.sha 549
											nlcLOISD.setItemId(snapdealItem
550
													.getItem_id());
551
											nlcLOISD.setProductName(snapdealItem
552
													.getBrand()
553
													+ " "
554
													+ snapdealItem
11944 manish.sha 555
													.getModel_name()
11940 manish.sha 556
													+ " "
557
													+ snapdealItem
11944 manish.sha 558
													.getModel_number()
11940 manish.sha 559
													+ " "
560
													+ snapdealItem.getColor());
11875 manish.sha 561
											nlcLOISD.setOurNlc(maxnlcSD);
11940 manish.sha 562
											nlcLOISD.setSkuAtSource(snapdealItem
563
													.getSkuAtSnapdeal());
564
											nlcLOISD.setVendorName(vendorDataMap
565
													.get(allWarehousesMap
566
															.get(entry.getKey())
567
															.getVendor()
568
															.getId()));
11875 manish.sha 569
											nlcLOISD.setVendorAvailability(available);
570
											nlcLOISD.setVendorNlc(nlc);
11940 manish.sha 571
											nlcLOISD.setVendorWarehouseId(entry
572
													.getKey());
573
											nlcLOISD.setWarehouseType(allWarehousesMap
574
													.get(entry.getKey())
575
													.getWarehouseType()
576
													.toString());
577
											if (!nlcLoiMapSD.containsKey(entry
578
													.getKey()))
579
												nlcLoiMapSD.put(entry.getKey(),
580
														nlcLOISD);
11875 manish.sha 581
										}
11874 manish.sha 582
									}
583
								}
584
 
11940 manish.sha 585
								if (flipkartItem != null) {
586
									if (nlc != 0 && (maxnlcFK >= nlc)) {
587
										/*
588
										 * total_warehouse_held =
589
										 * inventoryClient.
590
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
591
										 * (thriftItem.getId(), entry.getKey(),
592
										 * 0); heldForSource = heldForSource +
593
										 * total_warehouse_held -
594
										 * inventoryClient.
595
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
596
										 * (thriftItem.getId(), entry.getKey(),
597
										 * 8); available = available +
598
										 * entry.getValue(); total_held =
599
										 * total_held + total_warehouse_held;
600
										 */
601
										// continue;
602
										// System.out.println("itemId:" +
603
										// thriftItem.getId() + "\ttotal_held: "
604
										// + total_held + "\theldForSource:" +
605
										// heldForSource + "\tavailable:" +
606
										// available);
607
									} else if (maxnlcFK == 0) {
608
										/*
609
										 * total_warehouse_held =
610
										 * inventoryClient.
611
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
612
										 * (thriftItem.getId(), entry.getKey(),
613
										 * 0); heldForSource = heldForSource +
614
										 * total_warehouse_held -
615
										 * inventoryClient.
616
										 * getHoldInventoryDetailForItemForWarehouseIdExceptSource
617
										 * (thriftItem.getId(), entry.getKey(),
618
										 * 8); available = available +
619
										 * itemavailability.get(entry.getKey());
620
										 * total_held = total_held +
621
										 * total_warehouse_held;
622
										 */
623
										// continue;
624
										// System.out.println("itemId:" +
625
										// thriftItem.getId() + "\ttotal_held: "
626
										// + total_held + "\theldForSource:" +
627
										// heldForSource + "\tavailable:" +
628
										// available);
629
									} else {
630
										long available = itemavailability
11944 manish.sha 631
										.get(entry.getKey());
11940 manish.sha 632
										if (available > 0) {
11875 manish.sha 633
											nlcLOIFK = new NlcLeftOutInventory();
11940 manish.sha 634
											nlcLOIFK.setItemId(flipkartItem
635
													.getItem_id());
636
											nlcLOIFK.setProductName(thriftItem
637
													.getBrand()
638
													+ " "
639
													+ thriftItem.getModelName()
640
													+ " "
641
													+ thriftItem
11944 manish.sha 642
													.getModelNumber()
11940 manish.sha 643
													+ " "
644
													+ thriftItem.getColor());
11875 manish.sha 645
											nlcLOIFK.setOurNlc(maxnlcFK);
11940 manish.sha 646
											nlcLOIFK.setSkuAtSource(flipkartItem
647
													.getSkuAtFlipkart());
648
											nlcLOIFK.setVendorName(vendorDataMap
649
													.get(allWarehousesMap
650
															.get(entry.getKey())
651
															.getVendor()
652
															.getId()));
11875 manish.sha 653
											nlcLOIFK.setVendorAvailability(available);
654
											nlcLOIFK.setVendorNlc(nlc);
11940 manish.sha 655
											nlcLOIFK.setVendorWarehouseId(entry
656
													.getKey());
657
											nlcLOIFK.setWarehouseType(allWarehousesMap
658
													.get(entry.getKey())
659
													.getWarehouseType()
660
													.toString());
661
											if (!nlcLoiMapFK.containsKey(entry
662
													.getKey()))
663
												nlcLoiMapFK.put(entry.getKey(),
664
														nlcLOIFK);
11875 manish.sha 665
										}
11874 manish.sha 666
									}
667
								}
668
 
669
							}
670
						}
11940 manish.sha 671
						if (nlcLoiMapSD != null && nlcLoiMapSD.size() > 0) {
672
							snapdealLeftInvDataMap.put(
673
									snapdealItem.getSkuAtSnapdeal(),
674
									nlcLoiMapSD);
11884 manish.sha 675
						}
11940 manish.sha 676
						if (nlcLoiMapFK != null && nlcLoiMapFK.size() > 0) {
677
							flipkartLeftInvDataMap.put(
678
									flipkartItem.getSkuAtFlipkart(),
679
									nlcLoiMapFK);
11884 manish.sha 680
						}
11874 manish.sha 681
					}
682
 
11940 manish.sha 683
					Map<Long, Long> itemreserve = new HashMap<Long, Long>();
11874 manish.sha 684
					itemreserve = iteminventory.getReserved();
11940 manish.sha 685
					if (thriftItem.isIsWarehousePreferenceSticky()
686
							&& thriftItem.getPreferredVendor() != 0) {
687
						// System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
688
						for (Warehouse warehouse : vendor_warehouses) {
689
							if (warehouse.getBillingWarehouseId() != 7) {
690
								if (warehouse.getLogisticsLocation().equals(
691
										WarehouseLocation.Delhi)
692
										&& warehouse.getWarehouseType().equals(
693
												WarehouseType.THIRD_PARTY)
11944 manish.sha 694
												&& warehouse.getVendor().getId() != 1) {
11874 manish.sha 695
 
11940 manish.sha 696
								} else {
11874 manish.sha 697
									continue;
698
								}
699
							}
700
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
701
							ignoredItem.setItemId(thriftItem.getId());
702
							ignoredItem.setWarehouseId(warehouse.getId());
11940 manish.sha 703
							if (itemreserve.get(warehouse.getId()) != null
704
									&& !thirdpartywarehouseids
11944 manish.sha 705
									.contains(warehouse.getId())
11940 manish.sha 706
									&& !ignoreItems.contains(warehouse.getId())) {
707
								nlc = inventoryClient.getNlcForWarehouse(
708
										warehouse.getId(), thriftItem.getId());
709
								// maxnlc =
710
								// catalogClient.getSnapdealItem(thriftItem.getId()).getMaxNlc();
711
								// System.out.println("itemId:" +
712
								// thriftItem.getId() + "\tmaxnlc: " + maxnlc +
713
								// "\tnlc:" + nlc + "\twid:" + warehouse.getId()
714
								// );
715
								if (snapdealItem != null) {
716
									if (nlc != 0 && (maxnlcSD >= nlc)) {
717
										// reserve = reserve +
718
										// itemreserve.get(warehouse.getId());
719
										// System.out.println("itemId:" +
720
										// thriftItem.getId() + "\ttotal_held: "
721
										// + total_held + "\theldForSource:" +
722
										// heldForSource + "\treserve:" +
723
										// reserve);
724
										// continue;
725
									} else if (maxnlcSD == 0) {
726
										// reserve = reserve +
727
										// itemreserve.get(warehouse.getId());
728
										// System.out.println("itemId:" +
729
										// thriftItem.getId() + "\ttotal_held: "
730
										// + total_held + "\theldForSource:" +
731
										// heldForSource + "\treserve:" +
732
										// reserve);
733
										// continue;
734
									} else {
735
										if (snapdealLeftInvDataMap
736
												.containsKey(snapdealItem
737
														.getSkuAtSnapdeal())) {
738
											Map<Long, NlcLeftOutInventory> newNlcObjMap = snapdealLeftInvDataMap
11944 manish.sha 739
											.get(snapdealItem
740
													.getSkuAtSnapdeal());
11940 manish.sha 741
											if (newNlcObjMap
742
													.containsKey(warehouse
743
															.getId())) {
744
												NlcLeftOutInventory newObj = newNlcObjMap
11944 manish.sha 745
												.get(warehouse.getId());
11940 manish.sha 746
												newObj.setReserved(itemreserve
747
														.get(warehouse.getId()));
748
												newObj.setTotalAvailability(newObj
749
														.getVendorAvailability()
750
														- itemreserve.get(warehouse
751
																.getId()));
752
												newNlcObjMap.remove(warehouse
753
														.getId());
754
												newNlcObjMap.put(
755
														warehouse.getId(),
756
														newObj);
11889 manish.sha 757
 
758
											}
759
											nlcLoiMapSD = newNlcObjMap;
11874 manish.sha 760
										}
761
									}
762
								}
763
 
11940 manish.sha 764
								if (flipkartItem != null) {
765
									if (nlc != 0 && (maxnlcFK >= nlc)) {
766
										// reserve = reserve +
767
										// itemreserve.get(warehouse.getId());
768
										// System.out.println("itemId:" +
769
										// thriftItem.getId() + "\ttotal_held: "
770
										// + total_held + "\theldForSource:" +
771
										// heldForSource + "\treserve:" +
772
										// reserve);
773
										// continue;
774
									} else if (maxnlcFK == 0) {
775
										// reserve = reserve +
776
										// itemreserve.get(warehouse.getId());
777
										// System.out.println("itemId:" +
778
										// thriftItem.getId() + "\ttotal_held: "
779
										// + total_held + "\theldForSource:" +
780
										// heldForSource + "\treserve:" +
781
										// reserve);
782
										// continue;
783
									} else {
784
										if (flipkartLeftInvDataMap
785
												.containsKey(flipkartItem
786
														.getSkuAtFlipkart())) {
787
											Map<Long, NlcLeftOutInventory> newNlcObjMap = flipkartLeftInvDataMap
11944 manish.sha 788
											.get(flipkartItem
789
													.getSkuAtFlipkart());
11940 manish.sha 790
											if (newNlcObjMap
791
													.containsKey(warehouse
792
															.getId())) {
793
												NlcLeftOutInventory newObj = newNlcObjMap
11944 manish.sha 794
												.get(warehouse.getId());
11940 manish.sha 795
												newObj.setReserved(itemreserve
796
														.get(warehouse.getId()));
797
												newObj.setTotalAvailability(newObj
798
														.getVendorAvailability()
799
														- itemreserve.get(warehouse
800
																.getId()));
801
												newNlcObjMap.remove(warehouse
802
														.getId());
803
												newNlcObjMap.put(
804
														warehouse.getId(),
805
														newObj);
11889 manish.sha 806
 
807
											}
808
											nlcLoiMapFK = newNlcObjMap;
11874 manish.sha 809
										}
810
									}
811
								}
812
 
813
							}
814
						}
11889 manish.sha 815
 
11940 manish.sha 816
						if (nlcLoiMapSD != null && nlcLoiMapSD.size() > 0) {
817
							snapdealLeftInvDataMap.put(
818
									snapdealItem.getSkuAtSnapdeal(),
819
									nlcLoiMapSD);
11884 manish.sha 820
						}
11940 manish.sha 821
						if (nlcLoiMapFK != null && nlcLoiMapFK.size() > 0) {
822
							flipkartLeftInvDataMap.put(
823
									flipkartItem.getSkuAtFlipkart(),
824
									nlcLoiMapFK);
11884 manish.sha 825
						}
11889 manish.sha 826
 
11940 manish.sha 827
					} else {
828
						for (Map.Entry<Long, Long> entry : itemreserve
829
								.entrySet()) {
830
							if (allWarehousesMap.get(entry.getKey())
831
									.getBillingWarehouseId() != 7) {
832
								if (allWarehousesMap.get(entry.getKey())
833
										.getLogisticsLocation()
834
										.equals(WarehouseLocation.Delhi)
835
										&& allWarehousesMap
11944 manish.sha 836
										.get(entry.getKey())
837
										.getWarehouseType()
838
										.equals(WarehouseType.THIRD_PARTY)
11940 manish.sha 839
										&& allWarehousesMap.get(entry.getKey())
11944 manish.sha 840
										.getVendor().getId() != 1) {
11874 manish.sha 841
 
11940 manish.sha 842
								} else {
11874 manish.sha 843
									continue;
844
								}
845
							}
846
							in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
847
							ignoredItem.setItemId(thriftItem.getId());
848
							ignoredItem.setWarehouseId(entry.getKey());
11940 manish.sha 849
							if (!thirdpartywarehouseids
850
									.contains(entry.getKey())
851
									&& !ignoreItems.contains(ignoredItem)) {
852
								nlc = inventoryClient.getNlcForWarehouse(
853
										entry.getKey(), thriftItem.getId());
854
								// System.out.println("itemId:" +
855
								// thriftItem.getId() + "\tmaxnlc: " + maxnlc +
856
								// "\tnlc:" + nlc + "\twid:" + entry.getKey() );
857
								if (snapdealItem != null) {
858
									if (nlc != 0 && (maxnlcSD >= nlc)) {
859
										// reserve = reserve + entry.getValue();
860
										// System.out.println("itemId:" +
861
										// thriftItem.getId() + "\ttotal_held: "
862
										// + total_held + "\theldForSource:" +
863
										// heldForSource + "\treserve:" +
864
										// reserve);
865
										// continue;
866
									} else if (maxnlcSD == 0) {
867
										// reserve = reserve + entry.getValue();
868
										// System.out.println("itemId:" +
869
										// thriftItem.getId() + "\ttotal_held: "
870
										// + total_held + "\theldForSource:" +
871
										// heldForSource + "\treserve:" +
872
										// reserve);
873
										// continue;
874
									} else {
875
										if (snapdealLeftInvDataMap
876
												.containsKey(snapdealItem
877
														.getSkuAtSnapdeal())) {
878
											Map<Long, NlcLeftOutInventory> newNlcObjMap = snapdealLeftInvDataMap
11944 manish.sha 879
											.get(snapdealItem
880
													.getSkuAtSnapdeal());
11940 manish.sha 881
											if (newNlcObjMap.containsKey(entry
882
													.getKey())) {
883
												NlcLeftOutInventory newObj = newNlcObjMap
11944 manish.sha 884
												.get(entry.getKey());
11940 manish.sha 885
												newObj.setReserved(itemreserve
886
														.get(entry.getKey()));
887
												newObj.setTotalAvailability(newObj
888
														.getVendorAvailability()
889
														- itemreserve.get(entry
890
																.getKey()));
891
												newNlcObjMap.remove(entry
892
														.getKey());
893
												newNlcObjMap.put(
894
														entry.getKey(), newObj);
11889 manish.sha 895
 
896
											}
897
											nlcLoiMapSD = newNlcObjMap;
11874 manish.sha 898
										}
899
									}
900
								}
11940 manish.sha 901
								if (flipkartItem != null) {
902
									if (nlc != 0 && (maxnlcFK >= nlc)) {
903
										// reserve = reserve + entry.getValue();
904
										// System.out.println("itemId:" +
905
										// thriftItem.getId() + "\ttotal_held: "
906
										// + total_held + "\theldForSource:" +
907
										// heldForSource + "\treserve:" +
908
										// reserve);
909
										// continue;
910
									} else if (maxnlcFK == 0) {
911
										// reserve = reserve + entry.getValue();
912
										// System.out.println("itemId:" +
913
										// thriftItem.getId() + "\ttotal_held: "
914
										// + total_held + "\theldForSource:" +
915
										// heldForSource + "\treserve:" +
916
										// reserve);
917
										// continue;
918
									} else {
919
										if (flipkartLeftInvDataMap
920
												.containsKey(flipkartItem
921
														.getSkuAtFlipkart())) {
922
											Map<Long, NlcLeftOutInventory> newNlcObjMap = flipkartLeftInvDataMap
11944 manish.sha 923
											.get(flipkartItem
924
													.getSkuAtFlipkart());
11940 manish.sha 925
											if (newNlcObjMap.containsKey(entry
926
													.getKey())) {
927
												NlcLeftOutInventory newObj = newNlcObjMap
11944 manish.sha 928
												.get(entry.getKey());
11940 manish.sha 929
												newObj.setReserved(itemreserve
930
														.get(entry.getKey()));
931
												newObj.setTotalAvailability(newObj
932
														.getVendorAvailability()
933
														- itemreserve.get(entry
934
																.getKey()));
935
												newNlcObjMap.remove(entry
936
														.getKey());
937
												newNlcObjMap.put(
938
														entry.getKey(), newObj);
11889 manish.sha 939
 
940
											}
941
											nlcLoiMapFK = newNlcObjMap;
11874 manish.sha 942
										}
943
									}
944
								}
945
 
946
							}
947
 
11940 manish.sha 948
							else {
949
								// System.out.println("skipping inventory for warehouse id "
950
								// + entry.getKey());
11874 manish.sha 951
							}
952
						}
11889 manish.sha 953
 
11940 manish.sha 954
						if (nlcLoiMapSD != null && nlcLoiMapSD.size() > 0) {
955
							snapdealLeftInvDataMap.put(
956
									snapdealItem.getSkuAtSnapdeal(),
957
									nlcLoiMapSD);
11884 manish.sha 958
						}
11940 manish.sha 959
						if (nlcLoiMapFK != null && nlcLoiMapFK.size() > 0) {
960
							flipkartLeftInvDataMap.put(
961
									flipkartItem.getSkuAtFlipkart(),
962
									nlcLoiMapFK);
11884 manish.sha 963
						}
11874 manish.sha 964
					}
965
 
966
				}
967
 
11889 manish.sha 968
				nlcLoiItemsMapSD = snapdealLeftInvDataMap;
969
				nlcLoiItemsMapFK = flipkartLeftInvDataMap;
11940 manish.sha 970
 
11874 manish.sha 971
			}
972
		} catch (TException e) {
973
			// TODO Auto-generated catch block
974
			e.printStackTrace();
975
		}
976
 
977
	}
978
 
11940 manish.sha 979
	private static void createAndSendLeftOutInventoryFile(
980
			Map<String, Map<Long, NlcLeftOutInventory>> nlcLeftoutInventoryItems,
981
			String fileName) {
11874 manish.sha 982
		try {
983
 
11944 manish.sha 984
			File file = new File("/tmp/" + fileName + "-leftOutInv.xls");
985
			BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(
986
					file));
987
			bufferedWriter.write(StringUtils.join(new String[] { "ItemId",
988
					"Product Name", "SkuAtSource", "Vendor Name",
989
					"Vendor Warehouse Id", "Warehouse Type", "Max Our NLC",
990
					"Vendor NLC", "Availability Count", "Reserved Count",
991
			"Net Availabilty" }, '\t'));
992
             //id -0, name -1, sku - 2, vname 3, wh 4, wt 5, mnlc 6, vnlc 7, av8, r9, na 10
993
			// System.out.println(fileName+
994
			// " Main Map Size "+nlcLeftoutInventoryItems.size());
995
 
996
			for (Map<Long, NlcLeftOutInventory> nlcLOImap : nlcLeftoutInventoryItems
997
					.values()) {
998
				// System.out.println("Inner Map Size "+nlcLOImap.size());
999
				for (NlcLeftOutInventory nlcLOI : nlcLOImap.values()) {
1000
					bufferedWriter.newLine();
1001
 
1002
					bufferedWriter.write(StringUtils.join(
1003
							new String[] {
1004
									String.valueOf(nlcLOI.getItemId()),
1005
									nlcLOI.getProductName(),
1006
									nlcLOI.getSkuAtSource(),
1007
									nlcLOI.getVendorName(),
1008
									String.valueOf(nlcLOI
1009
											.getVendorWarehouseId()),
1010
											nlcLOI.getWarehouseType(),
1011
											String.valueOf(nlcLOI.getOurNlc()),
1012
											String.valueOf(nlcLOI.getVendorNlc()),
1013
											String.valueOf(nlcLOI
1014
													.getVendorAvailability()),
1015
													String.valueOf(nlcLOI.getReserved()),
1016
													String.valueOf(nlcLOI
1017
															.getTotalAvailability()) }, '\t'));
1018
 
1019
				}
1020
			}
1021
			bufferedWriter.close();
1022
 
1023
			List<NlcLeftOutInventory> subNlcLoiItemsListSD1 = new ArrayList<NlcLeftOutInventory>();
1024
			List<NlcLeftOutInventory> subNlcLoiItemsListSD2 = new ArrayList<NlcLeftOutInventory>();
1025
			List<NlcLeftOutInventory> subNlcLoiItemsListFK1 = new ArrayList<NlcLeftOutInventory>();
1026
			List<NlcLeftOutInventory> subNlcLoiItemsListFK2 = new ArrayList<NlcLeftOutInventory>();
1027
 
1028
 
1029
			BufferedReader reader = null;
1030
			File readfile = new File("/tmp/" + fileName + "-leftOutInv.xls");
1031
		    reader = new BufferedReader(new FileReader(readfile));
1032
		    String line;
1033
		    String values[];
11945 manish.sha 1034
		    int i=1;
11944 manish.sha 1035
		  //id -0, name -1, sku - 2, vname 3, wh 4, wt 5, mnlc 6, vnlc 7, av8, r9, na 10
1036
		    while ((line = reader.readLine()) != null) {
11945 manish.sha 1037
		    	if(i==1){
11947 manish.sha 1038
		    		i++;
11945 manish.sha 1039
		    		continue;
1040
		    	}
11944 manish.sha 1041
		        values = line.split("\t");
1042
		        NlcLeftOutInventory nlcLoI = new NlcLeftOutInventory();
1043
		        nlcLoI.setItemId(Long.parseLong(values[0]));
1044
		        nlcLoI.setProductName(values[1]);
1045
		        nlcLoI.setOurNlc(Double.parseDouble(values[6]));
1046
		        nlcLoI.setSkuAtSource(values[2]);
1047
		        nlcLoI.setVendorName(values[3]);
1048
		        nlcLoI.setVendorAvailability(Long.parseLong(values[8]));
1049
		        nlcLoI.setVendorNlc(Double.parseDouble(values[7]));
1050
		        nlcLoI.setVendorWarehouseId(Long.parseLong(values[4]));
1051
		        nlcLoI.setWarehouseType(values[5]);
1052
		        nlcLoI.setReserved(Long.parseLong(values[9]));
1053
		        nlcLoI.setTotalAvailability(Long.parseLong(values[10]));
1054
 
1055
		        if(fileName.equalsIgnoreCase("SNAPDEAL")){
11946 manish.sha 1056
		        	if (values[5].equalsIgnoreCase("OURS")) {
11944 manish.sha 1057
						subNlcLoiItemsListSD1.add(nlcLoI);
1058
					}
11946 manish.sha 1059
					if (values[5].equalsIgnoreCase("THIRD_PARTY")) {
11944 manish.sha 1060
						subNlcLoiItemsListSD2.add(nlcLoI);
1061
					}
1062
		        }
1063
		        if(fileName.equalsIgnoreCase("FLIPKART")){
11946 manish.sha 1064
		        	if (values[5].equalsIgnoreCase("OURS")) {
11944 manish.sha 1065
						subNlcLoiItemsListFK1.add(nlcLoI);
1066
					}
11946 manish.sha 1067
					if (values[5].equalsIgnoreCase("THIRD_PARTY")) {
11944 manish.sha 1068
						subNlcLoiItemsListFK2.add(nlcLoI);
1069
					}
1070
		        }
11945 manish.sha 1071
		        i++;
11944 manish.sha 1072
		    }
1073
		    StringBuffer sb = new StringBuffer();
11940 manish.sha 1074
			sb.append("<html><table border=\"1\" align=\"center\">"
1075
					+ "<caption><b>" + "LEFT OUT INVENTORY DETAIL" + "</b></caption>"
1076
					+ "<tr>" + "<td><b>" + "ITEM-ID" + "</b></td>" + "<td><b>"
1077
					+ "PRODUCT-NAME" + "</b></td>" + "<td><b>" + "SKU-AT-SOURCE"
1078
					+ "</b></td>" + "<td><b>" + "VENDOR-NAME" + "</b></td>"
1079
					+ "<td><b>" + "VENDOR-WAREHOUSE" + "</b></td>" + "<td><b>"
1080
					+ "WAREHOUSE-TYPE" + "</b></td>" + "<td><b>" + "MAX-OUR-NLC"
1081
					+ "</b></td>" + "</b></td>" + "<td><b>" + "VENDOR-NLC"
1082
					+ "</b></td>" + "<td><b>" + "AVAILABILITY-COUNT" + "</b></td>"
1083
					+ "<td><b>" + "RESERVED-COUNT" + "</b></td>"
1084
					+ "<td><b>" + "NET-AVAILABILITY" + "</b></td>"
1085
					+ "</tr>");
11944 manish.sha 1086
 
1087
		    if(fileName.equalsIgnoreCase("SNAPDEAL")){
1088
			    if (subNlcLoiItemsListSD1 != null
1089
						&& subNlcLoiItemsListSD1.size() >= 2) {
1090
					Collections.sort(subNlcLoiItemsListSD1,
1091
							new NlcLeftOutInventoryComparator());
1092
				}
1093
				if (subNlcLoiItemsListSD2 != null
1094
						&& subNlcLoiItemsListSD2.size() >= 2) {
1095
					Collections.sort(subNlcLoiItemsListSD2,
1096
							new NlcLeftOutInventoryComparator());
1097
				}
1098
				mainNlcLoiItemsListSD.addAll(subNlcLoiItemsListSD1);
1099
				mainNlcLoiItemsListSD.addAll(subNlcLoiItemsListSD2);
1100
 
11940 manish.sha 1101
				for(NlcLeftOutInventory obj: mainNlcLoiItemsListSD){
1102
					sb.append("<tr>"+"<td>"+obj.getItemId()+"</td>"
1103
							+"<td>"+obj.getProductName()+"</td>"
1104
							+"<td>"+obj.getSkuAtSource()+"</td>"
1105
							+"<td>"+obj.getVendorName()+"</td>"
1106
							+"<td>"+obj.getVendorWarehouseId()+"</td>"
1107
							+"<td>"+obj.getWarehouseType()+"</td>"
1108
							+"<td>"+obj.getOurNlc()+"</td>"
1109
							+"<td>"+obj.getVendorNlc()+"</td>"
1110
							+"<td>"+obj.getVendorAvailability()+"</td>"
1111
							+"<td>"+obj.getReserved()+"</td>"
1112
							+"<td>"+obj.getTotalAvailability()+"</td>"+"</tr>"
11944 manish.sha 1113
					);
11940 manish.sha 1114
				}
11944 manish.sha 1115
		    }
11940 manish.sha 1116
 
11944 manish.sha 1117
		    if(fileName.equalsIgnoreCase("FLIPKART")){
1118
				if (subNlcLoiItemsListFK1 != null
1119
						&& subNlcLoiItemsListFK1.size() >= 2) {
1120
					Collections.sort(subNlcLoiItemsListFK1,
1121
							new NlcLeftOutInventoryComparator());
1122
				}
1123
				if (subNlcLoiItemsListFK2 != null
1124
						&& subNlcLoiItemsListFK2.size() >= 2) {
1125
					Collections.sort(subNlcLoiItemsListFK2,
1126
							new NlcLeftOutInventoryComparator());
1127
				}
1128
				mainNlcLoiItemsListFK.addAll(subNlcLoiItemsListFK1);
1129
				mainNlcLoiItemsListFK.addAll(subNlcLoiItemsListFK2);
1130
 
11940 manish.sha 1131
				for(NlcLeftOutInventory obj: mainNlcLoiItemsListFK){
1132
					sb.append("<tr>"+"<td>"+obj.getItemId()+"</td>"
1133
							+"<td>"+obj.getProductName()+"</td>"
1134
							+"<td>"+obj.getSkuAtSource()+"</td>"
1135
							+"<td>"+obj.getVendorName()+"</td>"
1136
							+"<td>"+obj.getVendorWarehouseId()+"</td>"
1137
							+"<td>"+obj.getWarehouseType()+"</td>"
1138
							+"<td>"+obj.getOurNlc()+"</td>"
1139
							+"<td>"+obj.getVendorNlc()+"</td>"
1140
							+"<td>"+obj.getVendorAvailability()+"</td>"
1141
							+"<td>"+obj.getReserved()+"</td>"
1142
							+"<td>"+obj.getTotalAvailability()+"</td>"+"</tr>"
11944 manish.sha 1143
					);
11940 manish.sha 1144
				}
11944 manish.sha 1145
		    }
1146
 
11940 manish.sha 1147
			sb.append("</table></html>");
11944 manish.sha 1148
 
11940 manish.sha 1149
			BufferedWriter out = new BufferedWriter(new FileWriter("/tmp/"+fileName+"-leftOutInv-file.htm"));
1150
			out.write(sb.toString());
1151
			out.flush();
1152
			out.close();
1153
 
11944 manish.sha 1154
 
11874 manish.sha 1155
			List<File> files = new ArrayList<File>();
1156
			files.add(file);
1157
 
12409 manish.sha 1158
			mailer.sendSSLMessage(sendTo,"Inventory not Sent due to NLC Limitaion in case of - "+ fileName, "Please find attached file.",emailFromAddress, password, "/tmp/" + fileName + "-leftOutInv.xls", "/tmp/"+fileName+"-leftOutInv-file.htm");
11940 manish.sha 1159
			/*mailer.sendSSLMessage(sendTo,
1160
					"Inventory not Sent due to NLC Limitaion in case of - "
1161
							+ fileName, "Please find attached file.",
1162
					emailFromAddress, password, files);*/
11874 manish.sha 1163
		} catch (Exception e) {
1164
			e.printStackTrace();
11891 manish.sha 1165
			try {
11940 manish.sha 1166
				mailer.sendSSLMessage(sendTo,
1167
						"Error while creating file from data ",
1168
						emailFromAddress, password, "");
11874 manish.sha 1169
			} catch (MessagingException e1) {
1170
				e1.printStackTrace();
11891 manish.sha 1171
			}
11874 manish.sha 1172
		}
1173
	}
1174
 
11940 manish.sha 1175
	// private static DefaultHttpClient client = new DefaultHttpClient();
11874 manish.sha 1176
 
1177
	public static void main(String[] args) throws Exception {
1178
		calculateinventory();
11889 manish.sha 1179
		createAndSendLeftOutInventoryFile(nlcLoiItemsMapSD, "SNAPDEAL");
1180
		createAndSendLeftOutInventoryFile(nlcLoiItemsMapFK, "FLIPKART");
11874 manish.sha 1181
 
1182
	}
1183
}