Subversion Repositories SmartDukaan

Rev

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