Subversion Repositories SmartDukaan

Rev

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

Rev 9729 Rev 9734
Line 120... Line 120...
120
	private String currentSp;
120
	private String currentSp;
121
	private String currentTp;
121
	private String currentTp;
122
	private String minPosSp;
122
	private String minPosSp;
123
	private String minPosTp;
123
	private String minPosTp;
124
	private String vat;
124
	private String vat;
-
 
125
	private String comparsionResult;
-
 
126
	public String getComparsionResult() {
-
 
127
		return comparsionResult;
-
 
128
	}
-
 
129
 
-
 
130
	public void setComparsionResult(String comparsionResult) {
-
 
131
		this.comparsionResult = comparsionResult;
-
 
132
	}
-
 
133
 
-
 
134
	private Map<Integer, Long> holdInventoryMap;
125
 
135
 
126
	public String getVat() {
136
	public String getVat() {
127
		return vat;
137
		return vat;
128
	}
138
	}
129
 
139
 
Line 304... Line 314...
304
			return "authfail";
314
			return "authfail";
305
		}
315
		}
306
		return "snapdeal-bulk-upload";
316
		return "snapdeal-bulk-upload";
307
	}
317
	}
308
 
318
 
309
	public void update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException{
319
	public String update() throws NumberFormatException, TException, InventoryServiceException, CatalogServiceException, JSONException{
310
		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();
311
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
321
		SnapdealItem snapdealItem = catalogClient.getSnapdealItem(Long.valueOf(itemId));
312
		MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
322
		MarketplaceItems mpItem = catalogClient.getMarketplacedetailsForItem(Long.valueOf(itemId),7);
313
		InventoryClient inventoryServiceClient = new InventoryClient();
323
		InventoryClient inventoryServiceClient = new InventoryClient();
314
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
324
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
Line 367... Line 377...
367
		}
377
		}
368
		if (!StringUtils.equalsIgnoreCase(snapdealItem.getSupc(), supc)){
378
		if (!StringUtils.equalsIgnoreCase(snapdealItem.getSupc(), supc)){
369
			snapdealItem.setSupc(supc);
379
			snapdealItem.setSupc(supc);
370
			commit=true;
380
			commit=true;
371
		}
381
		}
-
 
382
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
-
 
383
		
-
 
384
		if(!compareParameters(t_mpItem,snapdealItem)){
-
 
385
			setComparsionResult("0");
-
 
386
			return "snapdeal-update-result";
-
 
387
		}
-
 
388
		else{
-
 
389
			setComparsionResult("1");
-
 
390
		}
372
 
391
 
373
		if (commit){
392
		if (commit){
374
			catalogClient.addOrUpdateSnapdealItem(snapdealItem);
393
			if(!catalogClient.addOrUpdateSnapdealItem(snapdealItem)){
-
 
394
				throw new CatalogServiceException();
-
 
395
			}
375
		}
396
		}
376
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
-
 
377
		boolean result =catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
397
		boolean result = catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
378
		if(!result){
398
		if(!result){
379
			throw new CatalogServiceException();
399
			throw new CatalogServiceException();
380
		}
400
		}
381
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
401
		if (t_mpItem.getCurrentSp()< t_mpItem.getMinimumPossibleSp()){
382
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
402
			sendAlert(t_mpItem.getItemId(),t_mpItem.getCurrentSp(),t_mpItem.getMinimumPossibleSp());
383
		}
403
		}
-
 
404
		return "snapdeal-update-result";
-
 
405
	}
-
 
406
 
-
 
407
 
-
 
408
	public boolean compareParameters(MarketplaceItems mpItem, SnapdealItem snapdealItem) throws TException, JSONException{
-
 
409
		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);
-
 
411
		double inHouseCost = 15+vat+(mpItem.getReturnProvision()/100)*snapdealItem.getSellingPrice()+mpItem.getOtherCost();
-
 
412
	    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));
-
 
414
	    double commission =  ((mpItem.getCommission()/100)*snapdealItem.getSellingPrice());
-
 
415
	    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));
-
 
417
	    JSONObject x = new JSONObject();
-
 
418
	    x.put("NLC", nlc);
-
 
419
	    x.put("VAT", vat);
-
 
420
	    x.put("LOWEST POS TP", lowest_possible_tp);
-
 
421
	    x.put("TP", our_tp);
-
 
422
	    x.put("COMMISSION", commission);
-
 
423
	    x.put("SERVICE TAX", service_tax);
-
 
424
	    x.put("LOWEST POS SP", lowest_possible_sp);
-
 
425
	    logger.info("Snapdeal Backend validation "+x.toString());
-
 
426
	    boolean compare_result=true;
-
 
427
	    if(!(nlc==snapdealItem.getMaxNlc())){
-
 
428
	    	compare_result=false;
-
 
429
	    }
-
 
430
	    if(!(lowest_possible_tp-mpItem.getMinimumPossibleTp()>-1 && lowest_possible_tp-mpItem.getMinimumPossibleTp()<1)){
-
 
431
	    	compare_result=false;
-
 
432
	    }
-
 
433
	    if(!(our_tp-snapdealItem.getTransferPrice()>-1 && our_tp-snapdealItem.getTransferPrice()<1)){
-
 
434
	    	compare_result=false;
-
 
435
	    }
-
 
436
	    if(!(commission-snapdealItem.getCommission()>-1 && commission-snapdealItem.getCommission()<1)){
-
 
437
	    	compare_result=false;
-
 
438
	    }
-
 
439
	    if(!(service_tax-snapdealItem.getServiceTax()>-1 && service_tax-snapdealItem.getServiceTax()<1)){
-
 
440
	    	compare_result=false;
-
 
441
	    }
-
 
442
	    if(!(lowest_possible_sp-mpItem.getMinimumPossibleSp()>-1 && lowest_possible_sp-mpItem.getMinimumPossibleSp()<1)){
-
 
443
	    	compare_result=false;
-
 
444
	    }
-
 
445
	    return compare_result;
-
 
446
	  
-
 
447
	}
-
 
448
	
-
 
449
	public double getNlcForWarehouse(long warehouseId,long item_id) throws TException{
-
 
450
		InventoryClient inventoryServiceClient = new InventoryClient();
-
 
451
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
-
 
452
		return inventoryClient.getNlcForWarehouse(warehouseId, item_id);
-
 
453
	}
-
 
454
	
-
 
455
	public double getCourierCost(double weight){
-
 
456
		double cCost = 45;
-
 
457
		int slabs = (int) ((weight - .001)/(.5));
-
 
458
		for(int i=0;i<slabs;i++){
-
 
459
			cCost = cCost + 35;
-
 
460
		}
-
 
461
		return cCost;
384
	}
462
	}
385
 
463
 
-
 
464
 
386
	private MarketplaceItems updateMarketplaceItemDetails(MarketplaceItems mpItem){
465
	private MarketplaceItems updateMarketplaceItemDetails(MarketplaceItems mpItem){
387
		mpItem.setItemId(Long.valueOf(itemId));
466
		mpItem.setItemId(Long.valueOf(itemId));
388
		mpItem.setSource(7);
467
		mpItem.setSource(7);
389
		mpItem.setVat(Double.valueOf(vat));
468
		mpItem.setVat(Double.valueOf(vat));
390
		mpItem.setCourierCost(Double.valueOf(courierCost));
469
		mpItem.setCourierCost(Double.valueOf(courierCost));
Line 415... Line 494...
415
		logger.info(text);
494
		logger.info(text);
416
		String emailFromAddress = "build@shop2020.in";
495
		String emailFromAddress = "build@shop2020.in";
417
		String password = "cafe@nes";
496
		String password = "cafe@nes";
418
		GmailUtils mailer = new GmailUtils();
497
		GmailUtils mailer = new GmailUtils();
419
		try {
498
		try {
420
			mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
499
			//mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
421
		}
500
		}
422
		catch (Exception e) {
501
		catch (Exception e) {
423
			logger.info(e.toString());
502
			logger.info(e.toString());
424
		}
503
		}
425
	}
504
	}
Line 444... Line 523...
444
		snapdealItem.setCommission(Double.valueOf(commission));
523
		snapdealItem.setCommission(Double.valueOf(commission));
445
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
524
		snapdealItem.setServiceTax(Double.valueOf(serviceTax));
446
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
525
		snapdealItem.setMaxNlc(Double.valueOf(maxNlc));
447
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
526
		snapdealItem.setSkuAtSnapdeal(sdItemCode);
448
		snapdealItem.setSupc(supc);
527
		snapdealItem.setSupc(supc);
449
		
528
 
450
		MarketplaceItems mpItem = new MarketplaceItems();
529
		MarketplaceItems mpItem = new MarketplaceItems();
451
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
530
		MarketplaceItems t_mpItem = updateMarketplaceItemDetails(mpItem);
452
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
531
		Client catalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
453
		catalogClient.addOrUpdateSnapdealItem(snapdealItem);
532
		catalogClient.addOrUpdateSnapdealItem(snapdealItem);
454
		boolean result =catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
533
		boolean result =catalogClient.updateMarketplaceAttributesForItem(t_mpItem);
Line 525... Line 604...
525
			logger.error("Unable to get inventory info for item",e);
604
			logger.error("Unable to get inventory info for item",e);
526
			return null;
605
			return null;
527
		}
606
		}
528
	}
607
	}
529
 
608
 
-
 
609
 
-
 
610
 
530
	public Warehouse getWarehouse(String warehouseId) throws NumberFormatException, TException, InventoryServiceException { 
611
	public Warehouse getWarehouse(String warehouseId,String itemId) throws NumberFormatException, TException, InventoryServiceException { 
531
		InventoryClient inventoryServiceClient = new InventoryClient();
612
		InventoryClient inventoryServiceClient = new InventoryClient();
-
 
613
		holdInventoryMap =inventoryServiceClient.getClient().getHeldInventoryMapForItem(Long.valueOf(itemId), Long.valueOf(warehouseId));
532
		return inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
614
		return inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
533
	}
615
	}
534
 
616
 
-
 
617
	public Map<Integer, Long> getHoldInventoryMapForItem(){
-
 
618
		return holdInventoryMap;
-
 
619
	}
-
 
620
 
535
	public void changeHeldForSource() throws NumberFormatException, TException, InventoryServiceException{
621
	public void changeHeldForSource() throws NumberFormatException, TException, InventoryServiceException{
536
		InventoryClient inventoryServiceClient = new InventoryClient();
622
		InventoryClient inventoryServiceClient = new InventoryClient();
537
		Warehouse warehouse = inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
623
		Warehouse warehouse = inventoryServiceClient.getClient().getWarehouse(Long.valueOf(warehouseId));
538
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
624
		if (!(warehouse.getWarehouseType()==WarehouseType.OURS && warehouse.getInventoryType() == InventoryType.GOOD)){
539
			throw new InventoryServiceException();
625
			throw new InventoryServiceException();