Subversion Repositories SmartDukaan

Rev

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

Rev 4583 Rev 4649
Line 74... Line 74...
74
    
74
    
75
    private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
75
    private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
76
                         VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
76
                         VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
77
                         BUTTON_WIDTH = "50px";
77
                         BUTTON_WIDTH = "50px";
78
 
78
 
-
 
79
    private Map<String, String> ConfigMap;
79
    interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
80
    interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
80
    private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
81
    private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
81
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
82
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
82
 
83
 
83
 
84
 
Line 121... Line 122...
121
        initVendorKeysHeader();
122
        initVendorKeysHeader();
122
        initVendorPricingHeader();
123
        initVendorPricingHeader();
123
        initSourcePricingHeader();
124
        initSourcePricingHeader();
124
        initSimilarItemList();
125
        initSimilarItemList();
125
        preferredVendor.addItem("null");
126
        preferredVendor.addItem("null");
-
 
127
        getConfigdataforPriceCompare();
-
 
128
    }
-
 
129
 
-
 
130
    public void getConfigdataforPriceCompare(){
-
 
131
    	catalogService.getConfigdataforPriceCompare(new AsyncCallback<Map<String,String>>() {
-
 
132
            @Override
-
 
133
            public void onSuccess(Map<String, String> result) {
-
 
134
            	ConfigMap = result;
-
 
135
            }
-
 
136
            @Override
-
 
137
            public void onFailure(Throwable caught) {
-
 
138
                caught.printStackTrace();
-
 
139
            }
-
 
140
        });
126
    }
141
    }
127
 
142
 
128
    /**
143
    /**
129
     * Sets the UI fields with item object attributes
144
     * Sets the UI fields with item object attributes
130
     * Also populates tables for vendor prices, keys and item availability
145
     * Also populates tables for vendor prices, keys and item availability
Line 754... Line 769...
754
        }
769
        }
755
        if(!Utils.validateItem(newItem)) {
770
        if(!Utils.validateItem(newItem)) {
756
            return;
771
            return;
757
        }
772
        }
758
        
773
        
-
 
774
        final String[] messageList = new String[2];
-
 
775
        
-
 
776
    	String sellingpricemessage = compareSellingPricewithBreakEven();
-
 
777
    	if(sellingpricemessage.equals("false")) {
-
 
778
    		return;
-
 
779
    	}
-
 
780
    	else if(!sellingpricemessage.equals("true")) {
-
 
781
    		messageList[0] = sellingpricemessage;
-
 
782
    	}
-
 
783
        
-
 
784
        String preferredvendormessage = checkTransferPriceforPreferredVendor();
-
 
785
        if(preferredvendormessage.equals("false")) {
-
 
786
        	return;
-
 
787
        }
-
 
788
        else if(!preferredvendormessage.equals("true")) {
-
 
789
        	messageList[1] = preferredvendormessage;
-
 
790
        }
-
 
791
        
759
        /*if(!validatePrices()) {
792
        /*if(!validatePrices()) {
760
            return;
793
            return;
761
        }*/
794
        }*/
762
        catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
795
        catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
763
            @Override
796
            @Override
764
            public void onSuccess(Boolean result) {
797
            public void onSuccess(Boolean result) {
765
                if(result) {
798
                if(result) {
-
 
799
                	for(int i = 0; i < messageList.length; i++) {
-
 
800
                		if(messageList[i] != null) {
-
 
801
                			logAuthorization(messageList[i]);
-
 
802
                		}
-
 
803
                	}
766
                    item = newItem;
804
                    item = newItem;
767
                    GWT.log("Item updated. Id = " + item.getId());
805
                    GWT.log("Item updated. Id = " + item.getId());
768
                    catalogDashboardPanel.getItemListWidget().updateItem(item);
806
                    catalogDashboardPanel.getItemListWidget().updateItem(item);
769
                    getFreshItemFromDB(item.getId());
807
                    getFreshItemFromDB(item.getId());
770
                    Window.alert("Item updated successfully.");
808
                    Window.alert("Item updated successfully.");
Line 1290... Line 1328...
1290
    }
1328
    }
1291
    
1329
    
1292
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1330
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
1293
        this.catalogDashboardPanel = catalogDashboardPanel;
1331
        this.catalogDashboardPanel = catalogDashboardPanel;
1294
    }
1332
    }
-
 
1333
    
-
 
1334
    private String compareSellingPricewithBreakEven() {
-
 
1335
    	String message = "false";
-
 
1336
    	if(newItem.getWeight() == null) {
-
 
1337
    		Window.alert("Weight is empty.");
-
 
1338
            return message;
-
 
1339
    	}
-
 
1340
    	if(newItem.getSellingPrice() == null) {
-
 
1341
    		Window.alert("Selling Price is empty.");
-
 
1342
            return message;
-
 
1343
    	}
-
 
1344
    	
-
 
1345
    	double transferPrice;
-
 
1346
    	if(newItem.getPreferredVendor() == null && !newItem.getVendorPricesMap().isEmpty()) {
-
 
1347
    		transferPrice = -1;
-
 
1348
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
-
 
1349
				if(transferPrice > vendorDetail.getTransferPrice() || transferPrice == -1){
-
 
1350
					transferPrice = vendorDetail.getTransferPrice();
-
 
1351
				}
-
 
1352
			}
-
 
1353
    	}
-
 
1354
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
-
 
1355
    		transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();    		
-
 
1356
    	}
-
 
1357
    	else{
-
 
1358
    		Window.alert("Add vendor to Vendor Prices and then change the Selling Price.");
-
 
1359
            return message;
-
 
1360
    	}
-
 
1361
 
-
 
1362
    	double weightfactor = Math.ceil((newItem.getWeight() * 1000)/Double.parseDouble(ConfigMap.get("courier_weight_factor")));
-
 
1363
		double couriercost = Double.parseDouble(ConfigMap.get("courier_cost_factor")) * weightfactor;
-
 
1364
		double costfactor = (Double.parseDouble(ConfigMap.get("transfer_price_percentage")) * transferPrice)/100;
-
 
1365
		double breakeven;
-
 
1366
		if(costfactor < Double.parseDouble(ConfigMap.get("transfer_price_factor"))){
-
 
1367
			breakeven = transferPrice + couriercost + Double.parseDouble(ConfigMap.get("breakeven_additon_factor"));
-
 
1368
		}
-
 
1369
		else{
-
 
1370
			breakeven = (transferPrice + couriercost)/Double.parseDouble(ConfigMap.get("breakeven_divisor"));
-
 
1371
		}
-
 
1372
		
-
 
1373
		if(breakeven > newItem.getSellingPrice()) {
-
 
1374
			message = "Selling Price("+newItem.getSellingPrice()+") is less than Breakeven Price("+breakeven+").";
-
 
1375
			if(Window.confirm(message)){
-
 
1376
				return message;
-
 
1377
			}
-
 
1378
			else{
-
 
1379
				message = "false";
-
 
1380
				Window.alert("Updation of Item is canceled.");
-
 
1381
				return message;
-
 
1382
			}
-
 
1383
		}
-
 
1384
		else {
-
 
1385
			message = "true";
-
 
1386
	        return message;
-
 
1387
		}
-
 
1388
    }
-
 
1389
    
-
 
1390
    private String checkTransferPriceforPreferredVendor() {
-
 
1391
    	String message = "false";
-
 
1392
    	if(newItem.getPreferredVendor() == null) {
-
 
1393
    		message = "true";
-
 
1394
    		return message;
-
 
1395
    	}
-
 
1396
    	else if(!newItem.getVendorPricesMap().isEmpty() && newItem.getVendorPricesMap().containsKey(newItem.getPreferredVendor())){
-
 
1397
    		double transferPrice = newItem.getVendorPricesMap().get(newItem.getPreferredVendor()).getTransferPrice();
-
 
1398
        	double mintransferPrice = -1;
-
 
1399
        	String minvendor = "";
-
 
1400
        	boolean compareTransferPrices = false;
-
 
1401
			for(VendorPricings vendorDetail : newItem.getVendorPricesMap().values()){
-
 
1402
				if(mintransferPrice > vendorDetail.getTransferPrice() || mintransferPrice == -1){
-
 
1403
					mintransferPrice = vendorDetail.getTransferPrice();
-
 
1404
					minvendor = Utils.getVendorDesc(vendorDetail.getVendorId());
-
 
1405
				}
-
 
1406
			}
-
 
1407
			if(!checkParameterIfEqual(newItem.getPreferredVendor(), item.getPreferredVendor()) || item.getVendorPricesMap().isEmpty()) {
-
 
1408
				compareTransferPrices = true;
-
 
1409
			}
-
 
1410
			else {
-
 
1411
				double oldmintransferPrice = -1;
-
 
1412
				for(VendorPricings vendorDetail : item.getVendorPricesMap().values()){
-
 
1413
					if(oldmintransferPrice > vendorDetail.getTransferPrice() || oldmintransferPrice == -1){
-
 
1414
						oldmintransferPrice = vendorDetail.getTransferPrice();
-
 
1415
					}
-
 
1416
				}
-
 
1417
				if(mintransferPrice < oldmintransferPrice){
-
 
1418
					compareTransferPrices = true;
-
 
1419
				}
-
 
1420
			}
-
 
1421
			if(compareTransferPrices && transferPrice > mintransferPrice){
-
 
1422
				message = "Transfer Price("+transferPrice+") of Preferred Vendor("+Utils.getVendorDesc(newItem.getPreferredVendor())+") is more than Transfer Price("+mintransferPrice+") of "+minvendor+".";
-
 
1423
				if(Window.confirm(message)){
-
 
1424
					return message;
-
 
1425
				}
-
 
1426
				else{
-
 
1427
					message = "false";
-
 
1428
					Window.alert("Updation of Item is canceled.");
-
 
1429
					return message;
-
 
1430
				}
-
 
1431
			}
-
 
1432
			else {
-
 
1433
				message = "true";
-
 
1434
		        return message;
-
 
1435
			}
-
 
1436
    	}
-
 
1437
    	else{
-
 
1438
    		Window.alert("Add vendor to Vendor Prices and then change the Preferred Vendor.");
-
 
1439
            return message;
-
 
1440
    	}
-
 
1441
    }
-
 
1442
    
-
 
1443
    public void logAuthorization(String message) {
-
 
1444
    	String username = catalogDashboardPanel.uname;
-
 
1445
    	catalogService.addAuthorizationLog(newItem.getId(), username, message, new AsyncCallback<Boolean>() {
-
 
1446
            @Override
-
 
1447
            public void onSuccess(Boolean result) {
-
 
1448
                if(result) {
-
 
1449
                    GWT.log("Event is added");
-
 
1450
                }
-
 
1451
                else {
-
 
1452
                    GWT.log("Error adding the event");
-
 
1453
                    Window.alert("Error adding the event");
-
 
1454
                }
-
 
1455
            }
-
 
1456
            @Override
-
 
1457
            public void onFailure(Throwable caught) {
-
 
1458
                caught.printStackTrace();
-
 
1459
                Window.alert("Error while adding the event");
-
 
1460
            }
-
 
1461
        });
-
 
1462
    }
1295
}
1463
}