Rev 2105 | Rev 2126 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.catalog.dashboard.shared;import in.shop2020.catalog.dashboard.client.CatalogService;import in.shop2020.catalog.dashboard.client.CatalogServiceAsync;import java.util.Date;import java.util.List;import java.util.Map;import java.util.Map.Entry;import com.google.gwt.core.client.GWT;import com.google.gwt.user.client.Window;import com.google.gwt.user.client.rpc.AsyncCallback;public class Utils {public static int MODE_ADD = 0, MODE_EDIT = 1;private static Map<Long, String> vendors, warehouses;private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);private static boolean vendorsLoaded;static {catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {@Overridepublic void onSuccess(Map<Long, String> result) {vendors = result;setVendorsLoaded();}@Overridepublic void onFailure(Throwable caught) {}});catalogService.getAllWarehouses(new AsyncCallback<Map<Long,String>>() {@Overridepublic void onSuccess(Map<Long, String> result) {warehouses = result;}@Overridepublic void onFailure(Throwable caught) {}});}private static void setVendorsLoaded() {vendorsLoaded = true;}public static Map<Long, String> getAllVendors() {return vendors;}public static Map<Long, String> getAllWarehouses() {return warehouses;}public static String getVendorDesc(long id) {if(vendors == null) {return null;}return vendors.get(id);}public static String getWarehouseDesc(long id) {if(warehouses == null) {return null;}return warehouses.get(id);}public static String getDisplayableDate(Long millis){Date date = new Date();date.setTime(millis);String dateString = date.toString();dateString = dateString.substring(0, dateString.lastIndexOf(" "));dateString = dateString.substring(0, dateString.lastIndexOf(" "));return dateString;}public static long getVendorId(String vendorDesc) {if(vendors == null) {return 0;}for(Entry<Long, String> v : vendors.entrySet()) {if(v.getValue().equals(vendorDesc)) {return v.getKey();}}return 0;}public static boolean validateItem(Item item) {if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {Window.alert("Product Group cannot be empty.");return false;}if(item.getBrand() == null || item.getBrand().isEmpty()) {Window.alert("Brand cannot be empty.");return false;}if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {Window.alert("Model Number cannot be empty.");return false;}if(item.getSellingPrice() > item.getMrp()) {Window.alert("Selling price cannot be more than MRP");return false;}if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {for(VendorPricings v : item.getVendorPricesMap().values()) {if(item.getMrp() < v.getMop()) {Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));return false;}if(v.getTransferPrice() > v.getMop()) {Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));return false;}}}if(item.getVendorMappingsMap() != null && !item.getVendorMappingsMap().isEmpty()) {for(VendorItemMapping v : item.getVendorMappingsMap().values()) {if(v.getItemKey() == null || v.getItemKey().isEmpty()) {Window.alert("Item Key cannot be empty. Vendor: " + Utils.getVendorDesc(v.getVendorId()));return false;}}}return true;}}