Subversion Repositories SmartDukaan

Rev

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

Rev 9734 Rev 9780
Line 2... Line 2...
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.MarketplaceItems;
-
 
7
import in.shop2020.model.v1.catalog.MarketplacePercentage;
7
import in.shop2020.model.v1.catalog.SnapdealItem;
8
import in.shop2020.model.v1.catalog.SnapdealItem;
8
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
9
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
9
import in.shop2020.model.v1.inventory.InventoryServiceException;
10
import in.shop2020.model.v1.inventory.InventoryServiceException;
10
import in.shop2020.model.v1.inventory.InventoryType;
11
import in.shop2020.model.v1.inventory.InventoryType;
11
import in.shop2020.model.v1.inventory.ItemInventory;
12
import in.shop2020.model.v1.inventory.ItemInventory;
12
import in.shop2020.model.v1.inventory.Warehouse;
13
import in.shop2020.model.v1.inventory.Warehouse;
13
import in.shop2020.model.v1.inventory.WarehouseType;
14
import in.shop2020.model.v1.inventory.WarehouseType;
14
import in.shop2020.model.v1.order.AmazonFbaSalesSnapshot;
-
 
15
import in.shop2020.model.v1.order.SnapdealOrder;
15
import in.shop2020.model.v1.order.SnapdealOrder;
16
import in.shop2020.support.utils.ReportsUtils;
16
import in.shop2020.support.utils.ReportsUtils;
17
import in.shop2020.thrift.clients.CatalogClient;
17
import in.shop2020.thrift.clients.CatalogClient;
18
import in.shop2020.thrift.clients.InventoryClient;
18
import in.shop2020.thrift.clients.InventoryClient;
19
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.TransactionClient;
Line 317... Line 317...
317
	}
317
	}
318
 
318
 
319
	public String update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException, JSONException{
319
	public String update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException, JSONException{
320
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
320
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
321
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
321
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
-
 
322
		MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
-
 
323
		if (mpCosting.getSource()==0){
-
 
324
			throw new CatalogServiceException();
-
 
325
		}
322
		MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
326
		MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
-
 
327
		mpItem.setEmiFee(mpCosting.getEmiFee());
-
 
328
		mpItem.setReturnProvision(mpCosting.getReturnProvision());
-
 
329
		mpItem.setClosingFee(mpCosting.getClosingFee());
-
 
330
		mpItem.setServiceTax(mpCosting.getServiceTax());
-
 
331
		mpItem.setCommission(mpCosting.getCommission());
323
		InventoryClient inventoryServiceClient = new InventoryClient();
332
		InventoryClient inventoryServiceClient = new InventoryClient();
324
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
333
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
325
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
334
		/*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
326
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
335
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
327
			throw new InventoryServiceException();
336
			throw new InventoryServiceException();
328
		}
337
		}*/
329
		boolean commit = false; 
-
 
330
		if (snapdealItem.getWarehouseId()!=Long.valueOf(warehouseId)){
-
 
331
			snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
338
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
332
			commit = true;
-
 
333
		}
-
 
334
		if (snapdealItem.isIsListedOnSnapdeal()!=Boolean.valueOf(isListedOnSnapdeal)){
-
 
335
			snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
339
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
336
			commit = true;
-
 
337
		}
-
 
338
		if (snapdealItem.isSuppressInventoryFeed()!=Boolean.valueOf(isSuppressInventoryFeed)){
-
 
339
			snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
340
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
340
			commit = true;
-
 
341
		}
-
 
342
		if (snapdealItem.isSuppressPriceFeed()!=Boolean.valueOf(isSuppressPriceFeed)){
-
 
343
			snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
341
		snapdealItem.setSuppressPriceFeed(Boolean.valueOf(isSuppressPriceFeed));
344
			commit = true;
-
 
345
		}
-
 
346
		if (snapdealItem.getTransferPrice()!=Double.valueOf(transferPrice)){
-
 
347
			snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
342
		snapdealItem.setTransferPrice(Double.valueOf(transferPrice));
348
			commit = true;
-
 
349
		}
-
 
350
		if (snapdealItem.getExceptionPrice()!=Double.valueOf(exceptionPrice)){
-
 
351
			snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
343
		snapdealItem.setExceptionPrice(Double.valueOf(exceptionPrice));
352
			commit = true;
-
 
353
		}
-
 
354
		if (snapdealItem.getSellingPrice()!=Double.valueOf(sellingPrice)){
-
 
355
			snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
344
		snapdealItem.setSellingPrice(Double.valueOf(sellingPrice));
356
			commit = true;
-
 
357
		}
-
 
358
		if (snapdealItem.getCourierCost()!=Double.valueOf(courierCost)){
-
 
359
			snapdealItem.setCourierCost(Double.valueOf(courierCost));
345
		snapdealItem.setCourierCost(Double.valueOf(courierCost));
360
			commit = true;
-
 
361
		}
-
 
362
		if (snapdealItem.getCommission()!=Double.valueOf(commission)){
-
 
363
			snapdealItem.setCommission(Double.valueOf(commission));
346
		snapdealItem.setCommission(Double.valueOf(commission));
364
			commit = true;
-
 
365
		}
-
 
366
		if (snapdealItem.getServiceTax()!=Double.valueOf(serviceTax)){
-
 
367
			snapdealItem.setServiceTax(Double.valueOf(serviceTax));
347
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
368
			commit = true;
-
 
369
		}
-
 
370
		if (snapdealItem.getMaxNlc()!=Double.valueOf(maxNlc)){
-
 
371
			snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
348
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
372
			commit = true;
-
 
373
		}
-
 
374
		if (!StringUtils.equalsIgnoreCase(snapdealItem.getSkuAtSnapdeal(), sdItemCode)){
-
 
375
			snapdealItem.setSkuAtSnapdeal(sdItemCode);
349
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
376
			commit=true;
-
 
377
		}
-
 
378
		if (!StringUtils.equalsIgnoreCase(snapdealItem.getSupc(), supc)){
-
 
379
			snapdealItem.setSupc(supc);
350
		snapdealItem.setSupc(supc);
380
			commit=true;
-
 
381
		}
-
 
382
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
351
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
-
 
352
		snapdealItem.setUpdatedBy(getUserName());
-
 
353
		snapdealItem.setMarketplaceItems(t_mpItem);
383
		
354
 
384
		if(!compareParameters(t_mpItem,snapdealItem)){
355
		if(!compareParameters(t_mpItem,snapdealItem)){
385
			setComparsionResult("0");
356
			setComparsionResult("0");
386
			return "snapdeal-update-result";
357
			return "snapdeal-update-result";
387
		}
358
		}
388
		else{
359
		else{
389
			setComparsionResult("1");
360
			setComparsionResult("1");
390
		}
361
		}
391
 
362
 
392
		if (commit){
-
 
393
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
363
		if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
394
				throw new CatalogServiceException();
-
 
395
			}
-
 
396
		}
-
 
397
		boolean result = catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
-
 
398
		if(!result){
-
 
399
			throw new CatalogServiceException();
364
			throw new CatalogServiceException();
400
		}
365
		}
-
 
366
 
401
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
367
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
402
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
368
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
403
		}
369
		}
404
		return "snapdeal-update-result";
370
		return "snapdeal-update-result";
405
	}
371
	}
Line 407... Line 373...
407
 
373
 
408
	public boolean compareParameters(MarketplaceItems mpItem, SnapdealItem snapdealItem) throws TException, JSONException{
374
	public boolean compareParameters(MarketplaceItems mpItem, SnapdealItem snapdealItem) throws TException, JSONException{
409
		double nlc =getNlcForWarehouse(snapdealItem.getWarehouseId(),snapdealItem.getItem_id());
375
		double nlc =getNlcForWarehouse(snapdealItem.getWarehouseId(),snapdealItem.getItem_id());
410
		double vat = (snapdealItem.getSellingPrice()/(1+(mpItem.getVat()/100))-(nlc/(1+(mpItem.getVat()/100))))*(mpItem.getVat()/100);
376
		double vat = (snapdealItem.getSellingPrice()/(1+(mpItem.getVat()/100))-(nlc/(1+(mpItem.getVat()/100))))*(mpItem.getVat()/100);
411
		double inHouseCost = 15+vat+(mpItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+mpItem.getOtherCost();
377
		double inHouseCost = 15+vat+(mpItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+mpItem.getOtherCost();
412
	    double lowest_possible_tp = nlc+inHouseCost;
378
		double lowest_possible_tp = nlc+inHouseCost;
413
	    double our_tp =  snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*(mpItem.getCommission()/100)*(1+(mpItem.getServiceTax()/100))-snapdealItem.getCourierCost()*(1+(mpItem.getServiceTax()/100));
379
		double our_tp =  snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*(mpItem.getCommission()/100+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))-(snapdealItem.getCourierCost()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100));
414
	    double commission =  ((mpItem.getCommission()/100)*snapdealItem.getSellingPrice());
380
		double commission =  ((mpItem.getCommission()/100)*snapdealItem.getSellingPrice());
415
	    double service_tax = (mpItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCost());
381
		double service_tax = (mpItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCost());
416
	    double lowest_possible_sp = (nlc+(snapdealItem.getCourierCost()+0)*1.1236*(1+(mpItem.getVat()/100))+(15+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-(mpItem.getCommission()/100+0)*1.1236*(1+(mpItem.getVat())/100)-.005*(1+(mpItem.getVat())/100));
382
		double lowest_possible_sp = (nlc+(snapdealItem.getCourierCost()+mpItem.getClosingFee())*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat()/100))+(15+mpItem.getOtherCost())*(1+(mpItem.getVat())/100))/(1-(mpItem.getCommission()/100+mpItem.getEmiFee()/100)*(1+(mpItem.getServiceTax()/100))*(1+(mpItem.getVat())/100)-(mpItem.getReturnProvision()/100)*(1+(mpItem.getVat())/100));
417
	    JSONObject x = new JSONObject();
383
		JSONObject x = new JSONObject();
418
	    x.put("NLC", nlc);
384
		x.put("NLC", nlc);
419
	    x.put("VAT", vat);
385
		x.put("VAT", vat);
420
	    x.put("LOWEST POS TP", lowest_possible_tp);
386
		x.put("LOWEST POS TP", lowest_possible_tp);
421
	    x.put("TP", our_tp);
387
		x.put("TP", our_tp);
422
	    x.put("COMMISSION", commission);
388
		x.put("COMMISSION", commission);
423
	    x.put("SERVICE TAX", service_tax);
389
		x.put("SERVICE TAX", service_tax);
424
	    x.put("LOWEST POS SP", lowest_possible_sp);
390
		x.put("LOWEST POS SP", lowest_possible_sp);
425
	    logger.info("Snapdeal Backend validation "+x.toString());
391
		logger.info("Snapdeal Backend validation "+x.toString());
426
	    boolean compare_result=true;
392
		boolean compare_result=true;
427
	    if(!(nlc==snapdealItem.getMaxNlc())){
393
		if(!(nlc==snapdealItem.getMaxNlc())){
428
	    	compare_result=false;
394
			compare_result=false;
429
	    }
395
		}
430
	    if(!(lowest_possible_tp-mpItem.getMinimumPossibleTp()>-1 && lowest_possible_tp-mpItem.getMinimumPossibleTp()<1)){
396
		if(!(lowest_possible_tp-mpItem.getMinimumPossibleTp()>-1 && lowest_possible_tp-mpItem.getMinimumPossibleTp()<1)){
431
	    	compare_result=false;
397
			compare_result=false;
432
	    }
398
		}
433
	    if(!(our_tp-snapdealItem.getTransferPrice()>-1 && our_tp-snapdealItem.getTransferPrice()<1)){
399
		if(!(our_tp-snapdealItem.getTransferPrice()>-1 && our_tp-snapdealItem.getTransferPrice()<1)){
434
	    	compare_result=false;
400
			compare_result=false;
435
	    }
401
		}
436
	    if(!(commission-snapdealItem.getCommission()>-1 && commission-snapdealItem.getCommission()<1)){
402
		if(!(commission-snapdealItem.getCommission()>-1 && commission-snapdealItem.getCommission()<1)){
437
	    	compare_result=false;
403
			compare_result=false;
438
	    }
404
		}
439
	    if(!(service_tax-snapdealItem.getServiceTax()>-1 && service_tax-snapdealItem.getServiceTax()<1)){
405
		if(!(service_tax-snapdealItem.getServiceTax()>-1 && service_tax-snapdealItem.getServiceTax()<1)){
440
	    	compare_result=false;
406
			compare_result=false;
441
	    }
407
		}
442
	    if(!(lowest_possible_sp-mpItem.getMinimumPossibleSp()>-1 && lowest_possible_sp-mpItem.getMinimumPossibleSp()<1)){
408
		if(!(lowest_possible_sp-mpItem.getMinimumPossibleSp()>-1 && lowest_possible_sp-mpItem.getMinimumPossibleSp()<1)){
443
	    	compare_result=false;
409
			compare_result=false;
444
	    }
410
		}
445
	    return compare_result;
411
		return compare_result;
446
	  
412
 
447
	}
413
	}
448
	
414
 
449
	public double getNlcForWarehouse(long warehouseId,long item_id) throws TException{
415
	public double getNlcForWarehouse(long warehouseId,long item_id) throws TException{
450
		InventoryClient inventoryServiceClient = new InventoryClient();
416
		InventoryClient inventoryServiceClient = new InventoryClient();
451
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
417
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
452
		return inventoryClient.getNlcForWarehouse(warehouseId, item_id);
418
		return inventoryClient.getNlcForWarehouse(warehouseId, item_id);
453
	}
419
	}
454
	
420
 
455
	public double getCourierCost(double weight){
421
	public double getCourierCost(double weight){
456
		double cCost = 45;
422
		double cCost = 45;
457
		int slabs = (int) ((weight - .001)/(.5));
423
		int slabs = (int) ((weight - .001)/(.5));
458
		for(int i=0;i<slabs;i++){
424
		for(int i=0;i<slabs;i++){
459
			cCost = cCost + 35;
425
			cCost = cCost + 35;
Line 488... Line 454...
488
			e.printStackTrace();
454
			e.printStackTrace();
489
			return;
455
			return;
490
		}
456
		}
491
		String emailSubjectTxt="Snapdeal SP is set below Min Possible SP";
457
		String emailSubjectTxt="Snapdeal SP is set below Min Possible SP";
492
		String[] sendTo=new String[]{ "kshitij.sood@saholic.com","rajneesh.arora@saholic.com","rajveer.singh@saholic.com","vikram.raghav@saholic.com"};
458
		String[] sendTo=new String[]{ "kshitij.sood@saholic.com","rajneesh.arora@saholic.com","rajveer.singh@saholic.com","vikram.raghav@saholic.com"};
493
		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();
459
		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();
494
		logger.info(text);
460
		logger.info(text);
495
		String emailFromAddress = "build@shop2020.in";
461
		String emailFromAddress = "build@shop2020.in";
496
		String password = "cafe@nes";
462
		String password = "cafe@nes";
497
		GmailUtils mailer = new GmailUtils();
463
		GmailUtils mailer = new GmailUtils();
498
		try {
464
		try {
499
			//mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
465
			mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
500
		}
466
		}
501
		catch (Exception e) {
467
		catch (Exception e) {
502
			logger.info(e.toString());
468
			logger.info(e.toString());
503
		}
469
		}
504
	}
470
	}
505
 
471
 
506
	public void addNewItem() throws TException, NumberFormatException, InventoryServiceException, CatalogServiceException{
472
	public String addNewItem() throws TException, NumberFormatException, InventoryServiceException, CatalogServiceException, JSONException{
507
		InventoryClient inventoryServiceClient = new InventoryClient();
473
		InventoryClient inventoryServiceClient = new InventoryClient();
508
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
474
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
475
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
476
		MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
-
 
477
		if (mpCosting.getSource()==0){
-
 
478
			throw new CatalogServiceException();
-
 
479
		}
509
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
480
		/*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
510
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
481
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
511
			throw new InventoryServiceException();
482
			throw new InventoryServiceException();
512
		}
483
		}*/
513
		SnapdealItem snapdealItem = new SnapdealItem();
484
		SnapdealItem snapdealItem = new SnapdealItem();
514
		snapdealItem.setItem_id(Long.valueOf(itemId));
485
		snapdealItem.setItem_id(Long.valueOf(itemId));
515
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
486
		snapdealItem.setWarehouseId(Long.valueOf(warehouseId));
516
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
487
		snapdealItem.setIsListedOnSnapdeal(Boolean.valueOf(isListedOnSnapdeal));
517
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
488
		snapdealItem.setSuppressInventoryFeed(Boolean.valueOf(isSuppressInventoryFeed));
Line 523... Line 494...
523
		snapdealItem.setCommission(Double.valueOf(commission));
494
		snapdealItem.setCommission(Double.valueOf(commission));
524
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
495
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
525
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
496
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
526
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
497
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
527
		snapdealItem.setSupc(supc);
498
		snapdealItem.setSupc(supc);
-
 
499
		snapdealItem.setUpdatedBy(getUserName());
528
 
500
 
529
		MarketplaceItems mpItem = new MarketplaceItems();
501
		MarketplaceItems mpItem = new MarketplaceItems();
530
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
502
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
-
 
503
		t_mpItem.setCommission(mpCosting.getCommission());
-
 
504
		t_mpItem.setServiceTax(mpCosting.getServiceTax());
531
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
505
		t_mpItem.setReturnProvision(mpCosting.getReturnProvision());
-
 
506
		t_mpItem.setEmiFee(mpCosting.getEmiFee());
-
 
507
		t_mpItem.setClosingFee(mpCosting.getClosingFee());
532
		catalogClient.addOrUpdateSnapdealItem(snapdealItem);
508
		if(!compareParameters(t_mpItem,snapdealItem)){
-
 
509
			setComparsionResult("0");
-
 
510
			return "snapdeal-update-result";
-
 
511
		}
-
 
512
		else{
-
 
513
			setComparsionResult("1");
-
 
514
		}
-
 
515
		snapdealItem.setMarketplaceItems(t_mpItem);
533
		boolean result =catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
516
		boolean result = catalogClient.addOrUpdateSnapdealItem(snapdealItem);
534
		if(!result){
517
		if(!result){
535
			throw new CatalogServiceException();
518
			throw new CatalogServiceException();
536
		}
519
		}
537
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
520
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
538
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
521
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
539
		}
522
		}
-
 
523
		return "snapdeal-update-result";
540
	}
524
	}
541
 
525
 
-
 
526
 
542
	public String getAddNewItemForm(){
527
	public String getAddNewItemForm(){
543
		return "snapdeal-add-item";
528
		return "snapdeal-add-item";
544
	}
529
	}
545
 
530
 
546
	public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException, InventoryServiceException{
531
	public String getItemDetailsInJson() throws NumberFormatException, CatalogServiceException, TException, JSONException, InventoryServiceException{
547
		Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
532
		Client catalogClient =new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
548
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
533
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
-
 
534
		MarketplacePercentage mpCosting = catalogClient.getCostingForMarketplace(7, Long.valueOf(itemId));
549
		if (snapdealItem.getItem_id()!=0){
535
		if (snapdealItem.getItem_id()!=0){
550
			throw new CatalogServiceException();
536
			throw new CatalogServiceException();
551
		}
537
		}
552
		Item item = catalogClient.getItem(Long.valueOf(itemId));
538
		Item item = catalogClient.getItem(Long.valueOf(itemId));
553
		if (item.getId()==0){
539
		if (item.getId()==0){
554
			throw new CatalogServiceException();
540
			throw new CatalogServiceException();
555
		}
541
		}
556
		InventoryClient inventoryServiceClient = new InventoryClient();
542
		InventoryClient inventoryServiceClient = new InventoryClient();
557
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
543
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
558
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
544
		/*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
559
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
545
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
560
			throw new InventoryServiceException();
546
			throw new InventoryServiceException();
561
		}
547
		}*/
562
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
548
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
-
 
549
		if (maxNLC==0){
-
 
550
			throw new InventoryServiceException();
-
 
551
		}
563
		itemObj = new JSONObject();
552
		itemObj = new JSONObject();
564
		itemObj.put("ItemId", item.getId());
553
		itemObj.put("ItemId", item.getId());
565
		itemObj.put("Brand", item.getBrand());
554
		itemObj.put("Brand", item.getBrand());
566
		itemObj.put("ModelName", item.getModelName());
555
		itemObj.put("ModelName", item.getModelName());
567
		itemObj.put("ModelNumber", item.getModelNumber());
556
		itemObj.put("ModelNumber", item.getModelNumber());
Line 570... Line 559...
570
		itemObj.put("Risky", item.isRisky());
559
		itemObj.put("Risky", item.isRisky());
571
		itemObj.put("Status", item.getItemStatus());
560
		itemObj.put("Status", item.getItemStatus());
572
		itemObj.put("MRP", item.getMrp());
561
		itemObj.put("MRP", item.getMrp());
573
		itemObj.put("SellingPrice", item.getSellingPrice());
562
		itemObj.put("SellingPrice", item.getSellingPrice());
574
		itemObj.put("MaxNlc", maxNLC);
563
		itemObj.put("MaxNlc", maxNLC);
-
 
564
		itemObj.put("CommissionRate", mpCosting.getCommission());
-
 
565
		itemObj.put("ServiceTaxRate", mpCosting.getServiceTax());
-
 
566
		itemObj.put("ReturnProvision", mpCosting.getReturnProvision());
-
 
567
		itemObj.put("EmiFee", mpCosting.getEmiFee());
-
 
568
		itemObj.put("ClosingFee", mpCosting.getClosingFee());
575
		return "item-details-json";
569
		return "item-details-json";
576
	}
570
	}
577
 
571
 
578
	public String ke$ha() throws NumberFormatException, TException, JSONException, InventoryServiceException{
572
	public String ke$ha() throws NumberFormatException, TException, JSONException, InventoryServiceException{
579
		InventoryClient inventoryServiceClient = new InventoryClient();
573
		InventoryClient inventoryServiceClient = new InventoryClient();
580
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
574
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
581
		Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
575
		//Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
582
		if (warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD){
576
		//if (warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD){
583
			double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
577
		double maxNLC = inventoryClient.getNlcForWarehouse(Long.valueOf(warehouseId), Long.valueOf(itemId));
584
			itemObj = new JSONObject();
578
		itemObj = new JSONObject();
585
			itemObj.put("ItemId", itemId);
579
		itemObj.put("ItemId", itemId);
586
			itemObj.put("WarehouseId", warehouseId);
580
		itemObj.put("WarehouseId", warehouseId);
587
			itemObj.put("MaxNlc", maxNLC);
581
		itemObj.put("MaxNlc", maxNLC);
588
		}
582
		/*}
589
		else{
583
		else{
590
			itemObj = new JSONObject();
584
			itemObj = new JSONObject();
591
			throw new InventoryServiceException();
585
			throw new InventoryServiceException();
592
		}
586
		}*/
593
		return "item-details-json";
587
		return "item-details-json";
594
	}
588
	}
595
 
589
 
596
	public ItemInventory getItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
590
	public ItemInventory getItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
597
		try{
591
		try{
Line 636... Line 630...
636
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
630
		rowhead.createCell((short) 1).setCellValue("WAREHOUSE-ID");
637
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
631
		rowhead.createCell((short) 2).setCellValue("EXCEPTIONAL-PRICE");
638
		rowhead.createCell((short) 3).setCellValue("SNAPDEAL-LISTED");
632
		rowhead.createCell((short) 3).setCellValue("SNAPDEAL-LISTED");
639
		rowhead.createCell((short) 4).setCellValue("TRANSFER-PRICE");
633
		rowhead.createCell((short) 4).setCellValue("TRANSFER-PRICE");
640
		rowhead.createCell((short) 5).setCellValue("SELLING-PRICE");
634
		rowhead.createCell((short) 5).setCellValue("SELLING-PRICE");
-
 
635
		rowhead.createCell((short) 6).setCellValue("LOWEST POSSIBLE SP");
-
 
636
		rowhead.createCell((short) 7).setCellValue("LOWEST POSSIBLE TP");
-
 
637
		rowhead.createCell((short) 8).setCellValue("OTHER COST");
641
		rowhead.createCell((short) 6).setCellValue("COURIER-COST");
638
		rowhead.createCell((short) 9).setCellValue("COURIER-COST");
642
		rowhead.createCell((short) 7).setCellValue("COMMISION");
639
		rowhead.createCell((short) 10).setCellValue("COMMISION");
643
		rowhead.createCell((short) 8).setCellValue("SERVICE-TAX");
640
		rowhead.createCell((short) 11).setCellValue("SERVICE-TAX");
644
		rowhead.createCell((short) 9).setCellValue("Suppress Inventory Feed");
641
		rowhead.createCell((short) 12).setCellValue("Suppress Inventory Feed");
645
		rowhead.createCell((short) 10).setCellValue("Suppress Price Feed");
642
		rowhead.createCell((short) 13).setCellValue("Suppress Price Feed");
-
 
643
		rowhead.createCell((short) 14).setCellValue("AUTO FAVOURITE");
-
 
644
		rowhead.createCell((short) 15).setCellValue("MANUAL FAVOURITE");
-
 
645
		rowhead.createCell((short) 16).setCellValue("AUTO INCREMENT");
-
 
646
		rowhead.createCell((short) 17).setCellValue("AUTO DECREMENT");
646
		rowhead.createCell((short) 11).setCellValue("Max NLC");
647
		rowhead.createCell((short) 18).setCellValue("Max NLC");
647
		rowhead.createCell((short) 12).setCellValue("SKU @ Snapdeal");
648
		rowhead.createCell((short) 19).setCellValue("SKU @ Snapdeal");
648
		rowhead.createCell((short) 13).setCellValue("SUPC");
649
		rowhead.createCell((short) 20).setCellValue("SUPC");
649
		CatalogClient catalogServiceClient = null;
650
		Client catalogClient = null;
650
		List<SnapdealItemDetails> snapdealItems = null;
651
		List<SnapdealItemDetails> snapdealItems = null;
651
		try {
652
		try {
652
			catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
653
			catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
653
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= catalogServiceClient.getClient();
-
 
654
			snapdealItems = catalogClient.getAllSnapdealItems();
654
			snapdealItems = catalogClient.getAllSnapdealItems();
655
		} catch (Exception e) {
655
		} catch (Exception e) {
656
			e.printStackTrace();
656
			e.printStackTrace();
657
		}
657
		}
658
		int iterator=1;
658
		int iterator=1;
659
		for(SnapdealItemDetails snapdealItem:snapdealItems){
659
		for(SnapdealItemDetails snapdealItem:snapdealItems){
-
 
660
			MarketplaceItems marketplaceItem = catalogClient.getMarketplacedetailsForItem(snapdealItem.getItem_id(), 7);
660
			HSSFRow row = sheet.createRow((short)iterator);
661
			HSSFRow row = sheet.createRow((short)iterator);
661
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
662
			row.createCell((short) 0).setCellValue(snapdealItem.getItem_id());
662
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
663
			row.createCell((short) 1).setCellValue(snapdealItem.getWarehouseId());
663
			row.createCell((short) 2).setCellValue(snapdealItem.getExceptionPrice());
664
			row.createCell((short) 2).setCellValue(roundTwoDecimals(snapdealItem.getExceptionPrice()));
664
			if(snapdealItem.isIsListedOnSnapdeal()){
665
			if(snapdealItem.isIsListedOnSnapdeal()){
665
				row.createCell((short) 3).setCellValue(1);
666
				row.createCell((short) 3).setCellValue(1);
666
			}
667
			}
667
			else{
668
			else{
668
				row.createCell((short) 3).setCellValue(0);
669
				row.createCell((short) 3).setCellValue(0);
669
			}
670
			}
670
			row.createCell((short) 4).setCellValue(snapdealItem.getTransferPrice());
671
			row.createCell((short) 4).setCellValue(roundTwoDecimals(snapdealItem.getTransferPrice()));
671
			row.createCell((short) 5).setCellValue(snapdealItem.getSellingPrice());
672
			row.createCell((short) 5).setCellValue(roundTwoDecimals(snapdealItem.getSellingPrice()));
-
 
673
			row.createCell((short) 6).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleSp()));
-
 
674
			row.createCell((short) 7).setCellValue(roundTwoDecimals(marketplaceItem.getMinimumPossibleTp()));
-
 
675
			row.createCell((short) 8).setCellValue(roundTwoDecimals(marketplaceItem.getOtherCost()));
672
			row.createCell((short) 6).setCellValue(snapdealItem.getCourierCost());
676
			row.createCell((short) 9).setCellValue(snapdealItem.getCourierCost());
673
			row.createCell((short) 7).setCellValue(snapdealItem.getCommission());
677
			row.createCell((short) 10).setCellValue(roundTwoDecimals(snapdealItem.getCommission()));
674
			row.createCell((short) 8).setCellValue(snapdealItem.getServiceTax());
678
			row.createCell((short) 11).setCellValue(roundTwoDecimals(snapdealItem.getServiceTax()));
675
			row.createCell((short) 9).setCellValue(snapdealItem.isSuppressInventoryFeed());
679
			if(snapdealItem.isSuppressInventoryFeed()){
-
 
680
				row.createCell((short) 12).setCellValue(1);
-
 
681
			}
-
 
682
			else{
-
 
683
				row.createCell((short) 12).setCellValue(0);
-
 
684
			}
-
 
685
			if(snapdealItem.isSuppressPriceFeed()){
-
 
686
				row.createCell((short) 13).setCellValue(1);
-
 
687
			}
-
 
688
			else{
-
 
689
				row.createCell((short) 13).setCellValue(0);
-
 
690
			}
-
 
691
			if(marketplaceItem.isAutoFavourite()){
-
 
692
				row.createCell((short) 14).setCellValue(1);
-
 
693
			}
-
 
694
			else{
676
			row.createCell((short) 10).setCellValue(snapdealItem.isSuppressPriceFeed());
695
				row.createCell((short) 14).setCellValue(0);
-
 
696
			}
-
 
697
			if(marketplaceItem.isManualFavourite()){
-
 
698
				row.createCell((short) 15).setCellValue(1);
-
 
699
			}
-
 
700
			else{
-
 
701
				row.createCell((short) 15).setCellValue(0);
-
 
702
			}
-
 
703
			if(marketplaceItem.isAutoIncrement()){
-
 
704
				row.createCell((short) 16).setCellValue(1);
-
 
705
			}
-
 
706
			else{
-
 
707
				row.createCell((short) 16).setCellValue(0);
-
 
708
			}
-
 
709
			if(marketplaceItem.isAutoDecrement()){
-
 
710
				row.createCell((short) 17).setCellValue(1);
-
 
711
			}
-
 
712
			else{
-
 
713
				row.createCell((short) 17).setCellValue(0);
-
 
714
			}
677
			row.createCell((short) 11).setCellValue(snapdealItem.getMaxNlc());
715
			row.createCell((short) 18).setCellValue(snapdealItem.getMaxNlc());
678
			row.createCell((short) 12).setCellValue(snapdealItem.getSkuAtSnapdeal());
716
			row.createCell((short) 19).setCellValue(snapdealItem.getSkuAtSnapdeal());
679
			row.createCell((short) 13).setCellValue(snapdealItem.getSupc());
717
			row.createCell((short) 20).setCellValue(snapdealItem.getSupc());
680
			iterator++;
718
			iterator++;
681
		}
719
		}
682
 
720
 
683
		FileOutputStream fileOut = null;
721
		FileOutputStream fileOut = null;
684
		try {
722
		try {
Line 729... Line 767...
729
		}   
767
		}   
730
 
768
 
731
 
769
 
732
	}
770
	}
733
 
771
 
734
	public void uploadsnapdealBulkSheet() throws IOException, TException, NumberFormatException, InventoryServiceException{
772
	public void uploadsnapdealBulkSheet() throws IOException, TException, NumberFormatException, InventoryServiceException, CatalogServiceException{
735
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
773
		File fileToCreate = new File("/tmp/", "Snapdeal-bulk-upload.xls");
736
		FileUtils.copyFile(this.file, fileToCreate);
774
		FileUtils.copyFile(this.file, fileToCreate);
737
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
775
		FileInputStream iFile = new FileInputStream(new File(file.getAbsolutePath()));
738
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
776
		HSSFWorkbook workbook = new HSSFWorkbook(iFile);
739
		HSSFSheet sheet = workbook.getSheetAt(0);
777
		HSSFSheet sheet = workbook.getSheetAt(0);
-
 
778
		String updatedBy = getUserName();
740
		Client catalogClient=null;
779
		Client catalogClient=null;
-
 
780
		Client catalogClientProd=null;
741
		StringBuilder sb = new StringBuilder();
781
		StringBuilder sb = new StringBuilder();
742
		try {
782
		try {
743
			catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
783
			catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
-
 
784
			catalogClientProd = new CatalogClient().getClient();
744
		} catch (TTransportException e) {
785
		} catch (TTransportException e) {
745
			e.printStackTrace();
786
			e.printStackTrace();
746
		}
787
		}
747
		InventoryClient inventoryServiceClient = new InventoryClient();
788
		InventoryClient inventoryServiceClient = new InventoryClient();
748
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
789
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
790
		
749
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
791
		for (int iterator=(sheet.getFirstRowNum()+1);iterator<=sheet.getLastRowNum();iterator++){
-
 
792
			if (sheet.getLastRowNum()-1>100){
-
 
793
				sb.append("Number of items to update can't be greater than 100");
-
 
794
				break;
-
 
795
			}
750
			SnapdealItem snapdealItem =null;
796
			SnapdealItem snapdealItem = null;
-
 
797
			MarketplaceItems marketplaceItem = null;
-
 
798
			MarketplacePercentage mpCosting = null;
751
			Item item = null;
799
			Item item = null;
752
			Long sku;
800
			Long sku;
753
			boolean new_item = false;
801
			boolean new_item = false;
754
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
802
			if (checkEmptyString(sheet.getRow(iterator).getCell(0))){
755
				continue;
803
				continue;
756
			}
804
			}
757
			else {
805
			else {
758
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
806
				sku=(long) sheet.getRow(iterator).getCell(0).getNumericCellValue();
759
				snapdealItem = catalogClient.getSnapdealItem(sku);
807
				snapdealItem = catalogClient.getSnapdealItem(sku);
-
 
808
				mpCosting = catalogClient.getCostingForMarketplace(7, sku);
-
 
809
				marketplaceItem  = catalogClient.getMarketplacedetailsForItem(sku, 7);
-
 
810
				marketplaceItem.setItemId(sku);
-
 
811
				marketplaceItem.setSource(7);
-
 
812
				marketplaceItem.setCommission(mpCosting.getCommission());
-
 
813
				marketplaceItem.setServiceTax(mpCosting.getServiceTax());
-
 
814
				marketplaceItem.setReturnProvision(mpCosting.getReturnProvision());
-
 
815
				marketplaceItem.setEmiFee(mpCosting.getEmiFee());
-
 
816
				marketplaceItem.setClosingFee(mpCosting.getClosingFee());
-
 
817
				
760
				try {
818
				try {
761
					item = catalogClient.getItem(sku);
819
					item = catalogClient.getItem(sku);
762
					if (item.getId()==0){
820
					if (item.getId()==0){
763
						sb.append(sku + " Item not Present"+"\n");
821
						sb.append(sku + " Item not valid"+"\n");
764
						continue;
822
						continue;
765
					}
823
					}
766
				} catch (CatalogServiceException e) {
824
				} catch (CatalogServiceException e) {
767
					sb.append(sku + " Item not Present"+"\n");
825
					sb.append(sku + " Item not valid"+"\n");
768
					continue;
826
					continue;
769
				}
827
				}
770
				if(snapdealItem.getItem_id()==0){
828
				if(snapdealItem.getItem_id()==0){
771
					new_item = true;
829
					new_item = true;
772
					snapdealItem = new SnapdealItem();
830
					snapdealItem = new SnapdealItem();
Line 778... Line 836...
778
				sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
836
				sb.append(sku + " New Listing - Warehouse Id not Present"+"\n");
779
				continue;
837
				continue;
780
			}
838
			}
781
 
839
 
782
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
840
			if (!checkEmptyString(sheet.getRow(iterator).getCell(1))){
783
				Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
841
				/*Warehouse warehouse = inventoryClient.getWarehouse(Long.valueOf(warehouseId));
784
				if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
842
				if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
785
					sb.append(sku + "Not acceptable warehouse"+"\n");
843
					sb.append(sku + "Not acceptable warehouse"+"\n");
786
					continue;
844
					continue;
787
				}
845
				}*/
788
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
846
				long warehouseId = (long) sheet.getRow(iterator).getCell(1).getNumericCellValue();
789
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
847
				double maxNLC = inventoryClient.getNlcForWarehouse(warehouseId, item.getId());
790
				if (maxNLC==0){
848
				if (maxNLC==0){
791
					sb.append(sku + "Max Nlc can't be 0"+"\n");
849
					sb.append(sku + "Max Nlc can't be 0"+"\n");
792
					continue;
850
					continue;
Line 806... Line 864...
806
				}
864
				}
807
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
865
				if ((long)sheet.getRow(iterator).getCell(3).getNumericCellValue()==0){
808
					snapdealItem.setIsListedOnSnapdeal(false);
866
					snapdealItem.setIsListedOnSnapdeal(false);
809
				}
867
				}
810
			}
868
			}
-
 
869
			
811
			double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax;
870
			double transferPrice = 0,sellingPrice,commission,courierCost =45,serviceTax,otherCost;
812
			if (checkEmptyString(sheet.getRow(iterator).getCell(4))){
871
			if (checkEmptyString(sheet.getRow(iterator).getCell(4))&& new_item){
813
				sb.append(sku + " Transfer Price cannot be empty"+"\n");
872
				sb.append(sku + "New Item -  Selling Price cannot be empty"+"\n");
814
				continue;
873
				continue;
815
			}
874
			}
816
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
875
			if (!checkEmptyString(sheet.getRow(iterator).getCell(4))){
817
				transferPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
876
				sellingPrice = sheet.getRow(iterator).getCell(4).getNumericCellValue();
818
				if(transferPrice==0){
877
				if(sellingPrice==0){
819
					sb.append(sku + " Transfer Price cannot be zero"+"\n");
878
					sb.append(sku + " Selling Price cannot be zero"+"\n");
820
					continue;
879
					continue;
821
				}
880
				}
822
				snapdealItem.setTransferPrice(transferPrice);
881
				snapdealItem.setSellingPrice(sellingPrice);
-
 
882
				marketplaceItem.setCurrentSp(sellingPrice);
823
			}
883
			}
824
 
884
			
825
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
885
			if (!checkEmptyString(sheet.getRow(iterator).getCell(5))){
-
 
886
				otherCost = sheet.getRow(iterator).getCell(5).getNumericCellValue();
-
 
887
				marketplaceItem.setOtherCost(otherCost);
-
 
888
			}
-
 
889
 
-
 
890
 
-
 
891
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
826
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==1){
892
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
827
					snapdealItem.setSuppressPriceFeed(true);
893
					snapdealItem.setSuppressPriceFeed(true);
828
				}
894
				}
829
				if ((long)sheet.getRow(iterator).getCell(5).getNumericCellValue()==0){
895
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
830
					snapdealItem.setSuppressPriceFeed(false);
896
					snapdealItem.setSuppressPriceFeed(false);
831
				}
897
				}
832
			}
898
			}
833
 
899
 
834
			if (!checkEmptyString(sheet.getRow(iterator).getCell(6))){
900
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
835
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==1){
901
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==1){
836
					snapdealItem.setSuppressInventoryFeed(true);
902
					snapdealItem.setSuppressInventoryFeed(true);
837
				}
903
				}
838
				if ((long)sheet.getRow(iterator).getCell(6).getNumericCellValue()==0){
904
				if ((long)sheet.getRow(iterator).getCell(7).getNumericCellValue()==0){
839
					snapdealItem.setSuppressInventoryFeed(false);
905
					snapdealItem.setSuppressInventoryFeed(false);
840
				}
906
				}
841
			}
907
			}
842
 
908
 
843
			if (!checkEmptyString(sheet.getRow(iterator).getCell(7))){
909
			if (checkEmptyString(sheet.getRow(iterator).getCell(8)) && new_item){
844
				sheet.getRow(iterator).getCell(7).setCellType(Cell.CELL_TYPE_STRING);
910
				sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
845
				String snapdealItemCode = sheet.getRow(iterator).getCell(7).getStringCellValue();
-
 
846
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
911
				continue;
847
			}
912
			}
848
 
913
 
849
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
914
			if (!checkEmptyString(sheet.getRow(iterator).getCell(8))){
850
				sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
915
				sheet.getRow(iterator).getCell(8).setCellType(Cell.CELL_TYPE_STRING);
-
 
916
				String snapdealItemCode = sheet.getRow(iterator).getCell(8).getStringCellValue();
-
 
917
				if (snapdealItemCode.length()==0 && new_item){
-
 
918
					sb.append(sku + " New Item -  SKU@Snapdeal cannot be empty"+"\n");
-
 
919
					continue;
-
 
920
				}
-
 
921
				snapdealItem.setSkuAtSnapdeal(snapdealItemCode);
-
 
922
			}
-
 
923
			
-
 
924
			if (checkEmptyString(sheet.getRow(iterator).getCell(9)) && new_item){
-
 
925
				sb.append(sku + " New Item -  SUPC code cannot be empty"+"\n");
-
 
926
				continue;
-
 
927
			}
-
 
928
 
-
 
929
			if (!checkEmptyString(sheet.getRow(iterator).getCell(9))){
-
 
930
				sheet.getRow(iterator).getCell(9).setCellType(Cell.CELL_TYPE_STRING);
851
				String supc = sheet.getRow(iterator).getCell(8).getStringCellValue();
931
				String supc = sheet.getRow(iterator).getCell(9).getStringCellValue();
-
 
932
				if (supc.length()==0 && new_item){
-
 
933
					sb.append(sku + "  New Item -  SUPC code cannot be empty"+"\n");
-
 
934
					continue;
-
 
935
				}
852
				snapdealItem.setSupc(supc);
936
				snapdealItem.setSupc(supc);
853
			}
937
			}
854
			double weight = item.getWeight();
938
			double weight = item.getWeight();
855
 
939
 
856
			/*
940
			
857
			 *TODO Uncomment this for pricing feed. 
-
 
858
			 * if(weight==0){
941
			if(weight==0){
859
				sb.append(sku + " Please add weight"+"\n");
942
				sb.append(sku + " Please add weight"+"\n");
860
				continue;
943
				continue;
861
			}*/
944
			}
862
			if (weight!=0){
945
			if (weight!=0){
-
 
946
				weight = weight+.05;
863
				int slabs = (int) ((weight - .001)/(.5));
947
				int slabs = (int) ((weight - .001)/(.5));
864
 
948
 
865
				for(int i=0;i<slabs;i++){
949
				for(int i=0;i<slabs;i++){
866
					courierCost = courierCost + 35;
950
					courierCost = courierCost + 35;
867
				}
951
				}
868
			}
952
			}
869
 
953
 
870
			snapdealItem.setCourierCost(courierCost);
954
			snapdealItem.setCourierCost(courierCost);
-
 
955
			marketplaceItem.setCourierCost(courierCost);
871
			sellingPrice = roundTwoDecimals(((transferPrice + courierCost*1.1236)/(100 - 3.59*1.1236))*100);
956
			transferPrice = roundTwoDecimals(snapdealItem.getSellingPrice()- snapdealItem.getSellingPrice()*(marketplaceItem.getCommission()/100+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))-(snapdealItem.getCourierCost()+marketplaceItem.getClosingFee())*(1+(marketplaceItem.getServiceTax()/100)));
872
			snapdealItem.setSellingPrice(sellingPrice);
957
			snapdealItem.setTransferPrice(transferPrice);
873
			double commision_value = roundTwoDecimals(.0359*sellingPrice + courierCost);
958
			marketplaceItem.setCurrentTp(transferPrice);
874
			commission = roundTwoDecimals(((.0359*sellingPrice + courierCost)/sellingPrice)*100);
959
			commission = roundTwoDecimals(((marketplaceItem.getCommission()/100)*snapdealItem.getSellingPrice()));
875
			snapdealItem.setCommission(commission);
960
			snapdealItem.setCommission(commission);
876
			serviceTax = roundTwoDecimals((commision_value * .1236)); 
961
			serviceTax = roundTwoDecimals((marketplaceItem.getServiceTax()/100)*(snapdealItem.getCommission()+snapdealItem.getCourierCost())); 
877
			snapdealItem.setServiceTax(serviceTax);
962
			snapdealItem.setServiceTax(serviceTax);
-
 
963
			double vatRate = catalogClientProd.getVatPercentageForItem(snapdealItem.getItem_id(),0,snapdealItem.getSellingPrice());
-
 
964
			marketplaceItem.setVat(vatRate);
-
 
965
			double vat = roundTwoDecimals((snapdealItem.getSellingPrice()/(1+(marketplaceItem.getVat()/100))-(snapdealItem.getMaxNlc()/(1+(marketplaceItem.getVat()/100))))*(marketplaceItem.getVat()/100));
-
 
966
			double inHouseCost = roundTwoDecimals(15+vat+(marketplaceItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+marketplaceItem.getOtherCost());
-
 
967
			double lowest_possible_tp = roundTwoDecimals(snapdealItem.getMaxNlc()+inHouseCost);
-
 
968
			marketplaceItem.setMinimumPossibleTp(lowest_possible_tp);
-
 
969
			double lowest_possible_sp = roundTwoDecimals((snapdealItem.getMaxNlc()+(snapdealItem.getCourierCost()+marketplaceItem.getClosingFee())*(1+marketplaceItem.getServiceTax()/100)*(1+(marketplaceItem.getVat()/100))+(15+marketplaceItem.getOtherCost())*(1+(marketplaceItem.getVat())/100))/(1-(marketplaceItem.getCommission()/100+marketplaceItem.getEmiFee()/100)*(1+(marketplaceItem.getServiceTax()/100))*(1+(marketplaceItem.getVat())/100)-(marketplaceItem.getReturnProvision()/100)*(1+(marketplaceItem.getVat())/100)));
-
 
970
			marketplaceItem.setMinimumPossibleSp(lowest_possible_sp);
-
 
971
			snapdealItem.setUpdatedBy(updatedBy);
-
 
972
			snapdealItem.setMarketplaceItems(marketplaceItem);
878
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
973
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
879
				sb.append(sku + "\n");
974
				sb.append(sku + " Service Error\n");
880
			}	
975
			}	
881
		}
976
		}
882
		//logger.info("Amazon Bulk Map "+amazonBulkUpdate.toString());
-
 
883
		File file = new File("/tmp/amazonbulk");
977
		File file = new File("/tmp/snapdealbulk");
884
		FileWriter writer = new FileWriter(file);
978
		FileWriter writer = new FileWriter(file);
885
		writer.append(sb.toString());
979
		writer.append(sb.toString());
886
		writer.close();
980
		writer.close();
887
		byte[] buffer = new byte[(int)file.length()];
981
		byte[] buffer = new byte[(int)file.length()];
888
		InputStream input = null;
982
		InputStream input = null;
Line 926... Line 1020...
926
		return Double.valueOf(twoPlaces.format(d));
1020
		return Double.valueOf(twoPlaces.format(d));
927
	}
1021
	}
928
 
1022
 
929
 
1023
 
930
	public String show() {
1024
	public String show() {
931
		logger.info("Before fetching role");
-
 
932
		logger.info(request.getSession().toString());
-
 
933
		logger.info(ReportsUtils.ROLE);
-
 
934
		logger.info(session.getAttribute(ReportsUtils.USER_NAME).toString());
-
 
935
		logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
-
 
936
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
1025
		if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getRequestURI().substring(request.getContextPath().length()).split("/")[1])) {
937
			logger.info(request.getRequestURI().substring(request.getContextPath().length()).split("/")[1]);
-
 
938
			return "authfail";
1026
			return "authfail";
939
		}
1027
		}
940
 
1028
 
941
		if (StringUtils.equals(id, "snapdeal-options")){
1029
		if (StringUtils.equals(id, "snapdeal-options")){
942
			return "snapdeal-options";
1030
			return "snapdeal-options";
Line 950... Line 1038...
950
 
1038
 
951
	public void setId(String id) {
1039
	public void setId(String id) {
952
		this.id = id;
1040
		this.id = id;
953
	}
1041
	}
954
 
1042
 
-
 
1043
	public String getUserName(){
-
 
1044
		return session.getAttribute(ReportsUtils.USER_NAME).toString();
-
 
1045
	}
-
 
1046
 
955
	public HttpServletRequest getRequest() {
1047
	public HttpServletRequest getRequest() {
956
		logger.info("set request"+request.toString());
1048
		logger.info("set request"+request.toString());
957
		return request;
1049
		return request;
958
	}
1050
	}
959
 
1051
 
Line 972... Line 1064...
972
	public HttpSession getSession() {
1064
	public HttpSession getSession() {
973
		return session;
1065
		return session;
974
	}
1066
	}
975
 
1067
 
976
	public void setSession(HttpSession session) {
1068
	public void setSession(HttpSession session) {
977
		logger.info("set session"+session.toString());
-
 
978
		this.session = session;
1069
		this.session = session;
979
	}
1070
	}
980
 
1071
 
981
	public ServletContext getContext() {
1072
	public ServletContext getContext() {
982
		return context;
1073
		return context;