Subversion Repositories SmartDukaan

Rev

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

Rev 9597 Rev 9725
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
3
import in.shop2020.model.v1.catalog.CatalogService.Client;
4
import in.shop2020.model.v1.catalog.CatalogServiceException;
4
import in.shop2020.model.v1.catalog.CatalogServiceException;
5
import in.shop2020.model.v1.catalog.Item;
5
import in.shop2020.model.v1.catalog.Item;
-
 
6
import in.shop2020.model.v1.catalog.MarketplaceItems;
6
import in.shop2020.model.v1.catalog.SnapdealItem;
7
import in.shop2020.model.v1.catalog.SnapdealItem;
7
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
8
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
-
 
9
import in.shop2020.model.v1.inventory.InventoryServiceException;
-
 
10
import in.shop2020.model.v1.inventory.InventoryType;
-
 
11
import in.shop2020.model.v1.inventory.ItemInventory;
-
 
12
import in.shop2020.model.v1.inventory.Warehouse;
-
 
13
import in.shop2020.model.v1.inventory.WarehouseType;
8
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
14
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
9
import in.shop2020.model.v1.order.SnapdealOrder;
15
import in.shop2020.model.v1.order.SnapdealOrder;
10
import in.shop2020.support.utils.ReportsUtils;
16
import in.shop2020.support.utils.ReportsUtils;
11
import in.shop2020.thrift.clients.CatalogClient;
17
import in.shop2020.thrift.clients.CatalogClient;
12
import in.shop2020.thrift.clients.InventoryClient;
18
import in.shop2020.thrift.clients.InventoryClient;
13
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.TransactionClient;
-
 
20
import in.shop2020.utils.GmailUtils;
-
 
21
import javax.mail.MessagingException;
14
 
22
 
15
import java.io.BufferedInputStream;
23
import java.io.BufferedInputStream;
16
import java.io.File;
24
import java.io.File;
17
import java.io.FileInputStream;
25
import java.io.FileInputStream;
18
import java.io.FileNotFoundException;
26
import java.io.FileNotFoundException;
Line 99... Line 107...
99
	private String isSuppressInventoryFeed;
107
	private String isSuppressInventoryFeed;
100
	private String isSuppressPriceFeed;
108
	private String isSuppressPriceFeed;
101
	private String maxNlc;
109
	private String maxNlc;
102
	private String sdItemCode;
110
	private String sdItemCode;
103
	private String supc;
111
	private String supc;
-
 
112
	private String held;
-
 
113
	private String lastUpdatedInventoryTimestamp;
-
 
114
	private String lastCheckedTimestamp;
-
 
115
	private String otherCost;
-
 
116
	private String isAutoIncrement;
-
 
117
	private String isAutoDecrement;
-
 
118
	private String isManualFavourite;
-
 
119
	private String isAutoFavourite;
-
 
120
	private String currentSp;
-
 
121
	private String currentTp;
-
 
122
	private String minPosSp;
-
 
123
	private String minPosTp;
-
 
124
	private String vat;
104
 
125
 
-
 
126
	public String getVat() {
-
 
127
		return vat;
-
 
128
	}
-
 
129
 
-
 
130
	public void setVat(String vat) {
-
 
131
		this.vat = vat;
-
 
132
	}
-
 
133
 
-
 
134
	public String getOtherCost() {
-
 
135
		return otherCost;
-
 
136
	}
-
 
137
 
-
 
138
	public void setOtherCost(String otherCost) {
-
 
139
		this.otherCost = otherCost;
-
 
140
	}
105
 
141
 
106
 
142
 
-
 
143
	public String getCurrentSp() {
-
 
144
		return currentSp;
-
 
145
	}
-
 
146
 
-
 
147
	public void setCurrentSp(String currentSp) {
-
 
148
		this.currentSp = currentSp;
-
 
149
	}
-
 
150
 
-
 
151
	public String getCurrentTp() {
-
 
152
		return currentTp;
-
 
153
	}
-
 
154
 
-
 
155
	public void setCurrentTp(String currentTp) {
-
 
156
		this.currentTp = currentTp;
-
 
157
	}
-
 
158
 
-
 
159
 
-
 
160
	public String getLastCheckedTimestamp() {
-
 
161
		return lastCheckedTimestamp;
-
 
162
	}
-
 
163
 
-
 
164
	public String getLastUpdatedInventoryTimestamp() {
-
 
165
		return lastUpdatedInventoryTimestamp;
-
 
166
	}
-
 
167
 
-
 
168
	public void setLastUpdatedInventoryTimestamp(
-
 
169
			String lastUpdatedInventoryTimestamp) {
-
 
170
		this.lastUpdatedInventoryTimestamp = lastUpdatedInventoryTimestamp;
-
 
171
	}
-
 
172
 
-
 
173
	public void setLastCheckedTimestamp(
-
 
174
			String lastCheckedTimestamp) {
-
 
175
		this.lastCheckedTimestamp = lastCheckedTimestamp;
-
 
176
	}
-
 
177
 
-
 
178
	public String getIsAutoIncrement() {
-
 
179
		return isAutoIncrement;
-
 
180
	}
-
 
181
 
-
 
182
	public void setIsAutoIncrement(String isAutoIncrement) {
-
 
183
		this.isAutoIncrement = isAutoIncrement;
-
 
184
	}
-
 
185
 
-
 
186
	public String getIsAutoDecrement() {
-
 
187
		return isAutoDecrement;
-
 
188
	}
-
 
189
 
-
 
190
	public void setIsAutoDecrement(String isAutoDecrement) {
-
 
191
		this.isAutoDecrement = isAutoDecrement;
-
 
192
	}
-
 
193
 
-
 
194
	public String getIsManualFavourite() {
-
 
195
		return isManualFavourite;
-
 
196
	}
-
 
197
 
-
 
198
	public void setIsManualFavourite(String isManualFavourite) {
-
 
199
		this.isManualFavourite = isManualFavourite;
-
 
200
	}
-
 
201
 
-
 
202
	public String getIsAutoFavourite() {
-
 
203
		return isAutoFavourite;
-
 
204
	}
-
 
205
 
-
 
206
	public void setIsAutoFavourite(String isAutoFavourite) {
-
 
207
		this.isAutoFavourite = isAutoFavourite;
-
 
208
	}
-
 
209
 
-
 
210
	public String getMinPosSp() {
-
 
211
		return minPosSp;
-
 
212
	}
-
 
213
 
-
 
214
	public void setMinPosSp(String minPosSp) {
-
 
215
		this.minPosSp = minPosSp;
-
 
216
	}
-
 
217
 
-
 
218
	public String getMinPosTp() {
-
 
219
		return minPosTp;
-
 
220
	}
-
 
221
 
-
 
222
	public void setMinPosTp(String minPosTp) {
-
 
223
		this.minPosTp = minPosTp;
-
 
224
	}
-
 
225
 
-
 
226
	public String getHeld() {
-
 
227
		return held;
-
 
228
	}
-
 
229
 
-
 
230
	public void setHeld(String held) {
-
 
231
		this.held = held;
-
 
232
	}
-
 
233
 
107
	public String getSupc() {
234
	public String getSupc() {
108
		return supc;
235
		return supc;
109
	}
236
	}
110
 
237
 
111
	public void setSupc(String supc) {
238
	public void setSupc(String supc) {
Line 149... Line 276...
149
		return "snapdeal-item-table";
276
		return "snapdeal-item-table";
150
	}
277
	}
151
 
278
 
152
	public SnapdealItemDetails fetchItemDetail() throws NumberFormatException, TException {
279
	public SnapdealItemDetails fetchItemDetail() throws NumberFormatException, TException {
153
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
280
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
154
		return CatalogClient.getSnapdealItemDetails(Long.valueOf(id));
281
		SnapdealItemDetails sdItemDetails = CatalogClient.getSnapdealItemDetails(Long.valueOf(id));
-
 
282
		lastUpdatedInventoryTimeStampForItem(sdItemDetails.getLastUpdatedInventoryTimestamp());
-
 
283
		return sdItemDetails;
-
 
284
	}
-
 
285
 
-
 
286
	public MarketplaceItems fetchMarketplaceDetail() throws NumberFormatException, TException {
-
 
287
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
288
		MarketplaceItems mpItemDetails = CatalogClient.getMarketplacedetailsForItem(Long.valueOf(id), 7);
-
 
289
		lastCheckedTimeStampForItem(mpItemDetails.getLastCheckedTimestamp());
-
 
290
		return mpItemDetails;
-
 
291
	}
-
 
292
 
-
 
293
	public void lastUpdatedInventoryTimeStampForItem(long timestamp){
-
 
294
		setLastUpdatedInventoryTimestamp(new java.util.Date(timestamp).toLocaleString());
-
 
295
	}
-
 
296
 
-
 
297
	public void lastCheckedTimeStampForItem(long timestamp){
-
 
298
		setLastCheckedTimestamp(new java.util.Date(timestamp).toLocaleString());
155
	}
299
	}
156
 
300
 
157
	public String uploadBulkSheet(){
301
	public String uploadBulkSheet(){
158
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
302
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0])) {
159
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
303
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1].split("!")[0]);
160
			return "authfail";
304
			return "authfail";
161
		}
305
		}
162
		return "snapdeal-bulk-upload";
306
		return "snapdeal-bulk-upload";
163
	}
307
	}
164
 
308
 
165
	public String update() throws NumberFormatException, TException{
309
	public void update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException{
166
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
310
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
167
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
311
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
-
 
312
		MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
-
 
313
		InventoryClient inventoryServiceClient = new InventoryClient();
-
 
314
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
315
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
-
 
316
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
-
 
317
			throw new InventoryServiceException();
-
 
318
		}
168
		boolean commit = false; 
319
		boolean commit = false; 
169
		if (snapdealItem.getWarehouseId()!=Long.valueOf(warehouseId)){
320
		if (snapdealItem.getWarehouseId()!=Long.valueOf(warehouseId)){
170
			snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
321
			snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
171
			commit = true;
322
			commit = true;
172
		}
323
		}
Line 220... Line 371...
220
		}
371
		}
221
 
372
 
222
		if (commit){
373
		if (commit){
223
			catalogClient.addOrUpdateSnapdealItem(snapdealItem);
374
			catalogClient.addOrUpdateSnapdealItem(snapdealItem);
224
		}
375
		}
-
 
376
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
-
 
377
		boolean result =catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
225
		return "index";
378
		if(!result){
-
 
379
			throw new CatalogServiceException();
-
 
380
		}
-
 
381
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
-
 
382
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
-
 
383
		}
226
	}
384
	}
227
 
385
 
-
 
386
	private MarketplaceItems updateMarketplaceItemDetails(MarketplaceItems mpItem){
-
 
387
		mpItem.setItemId(Long.valueOf(itemId));
-
 
388
		mpItem.setSource(7);
-
 
389
		mpItem.setVat(Double.valueOf(vat));
-
 
390
		mpItem.setCourierCost(Double.valueOf(courierCost));
-
 
391
		mpItem.setOtherCost(Double.valueOf(otherCost));
-
 
392
		mpItem.setCurrentSp(Double.valueOf(sellingPrice));
-
 
393
		mpItem.setCurrentTp(Double.valueOf(transferPrice));
-
 
394
		mpItem.setAutoDecrement(Boolean.valueOf(isAutoDecrement));
-
 
395
		mpItem.setAutoIncrement(Boolean.valueOf(isAutoIncrement));
-
 
396
		mpItem.setManualFavourite(Boolean.valueOf(isManualFavourite));
-
 
397
		mpItem.setMinimumPossibleSp(Double.valueOf(minPosSp));
-
 
398
		mpItem.setMinimumPossibleTp(Double.valueOf(minPosTp));
-
 
399
		return mpItem;
-
 
400
	}
-
 
401
 
-
 
402
	private void sendAlert(long itemId,double sp,double minSp){
-
 
403
		Item item;
-
 
404
		try{
-
 
405
			Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
406
			item= catalogClient.getItem(itemId);
-
 
407
		}
-
 
408
		catch(Exception e){
-
 
409
			e.printStackTrace();
-
 
410
			return;
-
 
411
		}
-
 
412
		String emailSubjectTxt="Snapdeal SP is set below Min Possible SP";
-
 
413
		String[] sendTo=new String[]{ "kshitij.sood@shop2020.in"};
228
	public String addNewItem() throws TException{
414
		String text = "Item Details\nItem Id: "+itemId+"\nProduct Name: "+item.getBrand()+" "+item.getModelName()+" "+item.getModelNumber()+" "+item.getColor()+"\nSellingPrice: "+sp+"\nMinPossibleSp: "+minSp+"\nUpdated By: "+session.getAttribute(ReportsUtils.USER_NAME).toString();
-
 
415
		logger.info(text);
-
 
416
		String emailFromAddress = "build@shop2020.in";
-
 
417
		String password = "cafe@nes";
-
 
418
		GmailUtils mailer = new GmailUtils();
-
 
419
		try {
-
 
420
			mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, "");
-
 
421
		}
-
 
422
		catch (Exception e) {
-
 
423
			e.printStackTrace();
-
 
424
		}
-
 
425
	}
-
 
426
 
-
 
427
	public void addNewItem() throws TException, NumberFormatException, InventoryServiceException, CatalogServiceException{
-
 
428
		InventoryClient inventoryServiceClient = new InventoryClient();
-
 
429
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
430
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
-
 
431
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
-
 
432
			throw new InventoryServiceException();
-
 
433
		}
229
		SnapdealItem snapdealItem = new SnapdealItem();
434
		SnapdealItem snapdealItem = new SnapdealItem();
230
		snapdealItem.setItem_id(Long.valueOf(itemId));
435
		snapdealItem.setItem_id(Long.valueOf(itemId));
231
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
436
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
232
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
437
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
233
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
438
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
Line 239... Line 444...
239
		snapdealItem.setCommission(Double.valueOf(commission));
444
		snapdealItem.setCommission(Double.valueOf(commission));
240
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
445
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
241
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
446
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
242
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
447
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
243
		snapdealItem.setSupc(supc);
448
		snapdealItem.setSupc(supc);
-
 
449
		
-
 
450
		MarketplaceItems mpItem = new MarketplaceItems();
-
 
451
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
244
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
452
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
245
		catalogClient.addOrUpdateSnapdealItem(snapdealItem);
453
		catalogClient.addOrUpdateSnapdealItem(snapdealItem);
-
 
454
		boolean result =catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
246
		return "index";
455
		if(!result){
-
 
456
			throw new CatalogServiceException();
-
 
457
		}
-
 
458
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
-
 
459
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
-
 
460
		}
247
	}
461
	}
248
 
462
 
249
	public String getAddNewItemForm(){
463
	public String getAddNewItemForm(){
250
		return "snapdeal-add-item";
464
		return "snapdeal-add-item";
251
	}
465
	}
252
 
466
 
253
	public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException{
467
	public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException, InventoryServiceException{
254
		Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
468
		Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
255
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
469
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
256
		if (snapdealItem.getItem_id()!=0){
470
		if (snapdealItem.getItem_id()!=0){
257
			throw new CatalogServiceException();
471
			throw new CatalogServiceException();
258
		}
472
		}
Line 260... Line 474...
260
		if (item.getId()==0){
474
		if (item.getId()==0){
261
			throw new CatalogServiceException();
475
			throw new CatalogServiceException();
262
		}
476
		}
263
		InventoryClient inventoryServiceClient = new InventoryClient();
477
		InventoryClient inventoryServiceClient = new InventoryClient();
264
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
478
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
479
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
-
 
480
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
-
 
481
			throw new InventoryServiceException();
-
 
482
		}
265
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
483
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
266
		itemObj = new JSONObject();
484
		itemObj = new JSONObject();
267
		itemObj.put("ItemId", item.getId());
485
		itemObj.put("ItemId", item.getId());
268
		itemObj.put("Brand", item.getBrand());
486
		itemObj.put("Brand", item.getBrand());
269
		itemObj.put("ModelName", item.getModelName());
487
		itemObj.put("ModelName", item.getModelName());
Line 276... Line 494...
276
		itemObj.put("SellingPrice", item.getSellingPrice());
494
		itemObj.put("SellingPrice", item.getSellingPrice());
277
		itemObj.put("MaxNlc", maxNLC);
495
		itemObj.put("MaxNlc", maxNLC);
278
		return "item-details-json";
496
		return "item-details-json";
279
	}
497
	}
280
 
498
 
281
	public String ke$ha() throws NumberFormatException, TException, JSONException{
499
	public String ke$ha() throws NumberFormatException, TException, JSONException, InventoryServiceException{
282
		InventoryClient inventoryServiceClient = new InventoryClient();
500
		InventoryClient inventoryServiceClient = new InventoryClient();
283
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
501
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
502
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
-
 
503
		if (warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD){
284
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
504
			double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
285
		itemObj = new JSONObject();
505
			itemObj = new JSONObject();
286
		itemObj.put("ItemId", itemId);
506
			itemObj.put("ItemId", itemId);
287
		itemObj.put("WarehouseId", warehouseId);
507
			itemObj.put("WarehouseId", warehouseId);
288
		itemObj.put("MaxNlc", maxNLC);
508
			itemObj.put("MaxNlc", maxNLC);
-
 
509
		}
-
 
510
		else{
-
 
511
			itemObj = new JSONObject();
-
 
512
			throw new InventoryServiceException();
-
 
513
		}
289
		return "item-details-json";
514
		return "item-details-json";
290
	}
515
	}
291
 
516
 
-
 
517
	public ItemInventory getItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
-
 
518
		try{
-
 
519
			InventoryClient inventoryServiceClient = new InventoryClient();
-
 
520
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
521
			in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
-
 
522
			return thriftItemInventory;
-
 
523
		}
-
 
524
		catch(Exception e){
-
 
525
			logger.error("Unable to get inventory info for item",e);
-
 
526
			return null;
-
 
527
		}
-
 
528
	}
-
 
529
 
-
 
530
	public Warehouse getWarehouse(String warehouseId) throws NumberFormatException, TException, InventoryServiceException { 
-
 
531
		InventoryClient inventoryServiceClient = new InventoryClient();
-
 
532
		return inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
-
 
533
	}
-
 
534
 
-
 
535
	public void changeHeldForSource() throws NumberFormatException, TException, InventoryServiceException{
-
 
536
		InventoryClient inventoryServiceClient = new InventoryClient();
-
 
537
		Warehouse warehouse = inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
-
 
538
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
-
 
539
			throw new InventoryServiceException();
-
 
540
		}
-
 
541
		inventoryServiceClient.getClient().addUpdateHoldInventory(Long.valueOf(itemId),Long.valueOf(warehouseId),Long.valueOf(held),7);
-
 
542
	}
-
 
543
 
292
	public void downloadSnapdealListings() throws IOException, TException{
544
	public void downloadSnapdealListings() throws IOException, TException{
293
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
545
		File file = new File("/tmp/snapdeal-bulk-upload-template.xls");
294
		HSSFWorkbook hwb=new HSSFWorkbook();
546
		HSSFWorkbook hwb=new HSSFWorkbook();
295
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
547
		HSSFSheet sheet =  hwb.createSheet("Snapdeal-Listings");
296
		HSSFRow rowhead=   sheet.createRow((short)0);
548
		HSSFRow rowhead=   sheet.createRow((short)0);
Line 391... Line 643...
391
		}   
643
		}   
392
 
644
 
393
 
645
 
394
	}
646
	}
395
 
647
 
396
	public void uploadsnapdealBulkSheet() throws IOException, TException{
648
	public void uploadsnapdealBulkSheet() throws IOException, TException, NumberFormatException, InventoryServiceException{
397
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
649
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
398
		FileUtils.copyFile(this.file, fileToCreate);
650
		FileUtils.copyFile(this.file, fileToCreate);
399
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
651
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
400
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
652
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
401
		HSSFSheet sheet = workbook.getSheetAt(0);
653
		HSSFSheet sheet = workbook.getSheetAt(0);
Line 433... Line 685...
433
					new_item = true;
685
					new_item = true;
434
					snapdealItem = new SnapdealItem();
686
					snapdealItem = new SnapdealItem();
435
					snapdealItem.setItem_id(sku); 
687
					snapdealItem.setItem_id(sku); 
436
				}
688
				}
437
			}
689
			}
438
			
690
 
439
			if (checkEmptyString(sheet.getRow(iterator).getCell(1)) && new_item){
691
			if (checkEmptyString(sheet.getRow(iterator).getCell(1)) && new_item){
440
				sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
692
				sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
441
				continue;
693
				continue;
442
			}
694
			}
443
			
695
 
444
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
696
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
-
 
697
				Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
-
 
698
				if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
-
 
699
					sb.append(sku + "Not acceptable warehouse"+"\n");
-
 
700
					continue;
-
 
701
				}
445
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
702
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
446
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
703
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
447
				if (maxNLC==0){
704
				if (maxNLC==0){
448
					sb.append(sku + "Max Nlc can't be 0"+"\n");
705
					sb.append(sku + "Max Nlc can't be 0"+"\n");
449
					continue;
706
					continue;
Line 494... Line 751...
494
				}
751
				}
495
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
752
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
496
					snapdealItem.setSuppressInventoryFeed(false);
753
					snapdealItem.setSuppressInventoryFeed(false);
497
				}
754
				}
498
			}
755
			}
499
			
756
 
500
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
757
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
501
				sheet.getRow(iterator).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
758
				sheet.getRow(iterator).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
502
				String snapdealItemCode = sheet.getRow(iterator).getCell(7).getStringCellValue();
759
				String snapdealItemCode = sheet.getRow(iterator).getCell(7).getStringCellValue();
503
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
760
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
504
			}
761
			}
505
			
762
 
506
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
763
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
507
				sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
764
				sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
508
				String supc = sheet.getRow(iterator).getCell(8).getStringCellValue();
765
				String supc = sheet.getRow(iterator).getCell(8).getStringCellValue();
509
				snapdealItem.setSupc(supc);
766
				snapdealItem.setSupc(supc);
510
			}
767
			}
Line 586... Line 843...
586
 
843
 
587
	public String show() {
844
	public String show() {
588
		logger.info("Before fetching role");
845
		logger.info("Before fetching role");
589
		logger.info(request.getSession().toString());
846
		logger.info(request.getSession().toString());
590
		logger.info(ReportsUtils.ROLE);
847
		logger.info(ReportsUtils.ROLE);
591
		logger.info(session.getAttribute(ReportsUtils.ROLE).toString());
848
		logger.info(session.getAttribute(ReportsUtils.USER_NAME).toString());
592
		logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
849
		logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
593
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
850
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
594
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
851
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
595
			return "authfail";
852
			return "authfail";
596
		}
853
		}
Line 839... Line 1096...
839
 
1096
 
840
	public String getItemDetails(){
1097
	public String getItemDetails(){
841
		return itemObj.toString();
1098
		return itemObj.toString();
842
	}
1099
	}
843
 
1100
 
-
 
1101
	public double getRoundOfValue(String val){
-
 
1102
		return roundTwoDecimals(Double.valueOf(val));
-
 
1103
	}
-
 
1104
 
844
 
1105
 
845
 
1106
 
846
}
1107
}
847
1108