Subversion Repositories SmartDukaan

Rev

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

Rev 2105 Rev 2119
Line 7... Line 7...
7
import java.util.List;
7
import java.util.List;
8
import java.util.Map;
8
import java.util.Map;
9
import java.util.Map.Entry;
9
import java.util.Map.Entry;
10
 
10
 
11
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.core.client.GWT;
-
 
12
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.rpc.AsyncCallback;
13
import com.google.gwt.user.client.rpc.AsyncCallback;
13
 
14
 
14
public class Utils {
15
public class Utils {
15
    public static int MODE_ADD = 0, MODE_EDIT = 1;
16
    public static int MODE_ADD = 0, MODE_EDIT = 1;
16
    private static Map<Long, String> vendors, warehouses;
17
    private static Map<Long, String> vendors, warehouses;
17
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
18
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
-
 
19
    private static boolean vendorsLoaded;
18
    static {
20
    static {
19
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
21
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
20
            @Override
22
            @Override
21
            public void onSuccess(Map<Long, String> result) {
23
            public void onSuccess(Map<Long, String> result) {
22
                vendors = result;
24
                vendors = result;
-
 
25
                setVendorsLoaded();
23
            }
26
            }
24
            @Override
27
            @Override
25
            public void onFailure(Throwable caught) {
28
            public void onFailure(Throwable caught) {
26
            }
29
            }
27
        });
30
        });
Line 34... Line 37...
34
            @Override
37
            @Override
35
            public void onFailure(Throwable caught) {
38
            public void onFailure(Throwable caught) {
36
            }
39
            }
37
        });
40
        });
38
    }
41
    }
-
 
42
    
-
 
43
    private static void setVendorsLoaded() {
-
 
44
        vendorsLoaded = true;
-
 
45
    }
39
        
46
        
40
    public static Map<Long, String> getAllVendors() {
47
    public static Map<Long, String> getAllVendors() {
41
        return vendors;
48
        return vendors;
42
    }
49
    }
43
    
50
    
Line 77... Line 84...
77
                return v.getKey();
84
                return v.getKey();
78
            }
85
            }
79
        }
86
        }
80
        return 0;
87
        return 0;
81
    }
88
    }
-
 
89
    
-
 
90
    public static boolean validateItem(Item item) {
-
 
91
        if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {
-
 
92
            Window.alert("Product Group cannot be empty.");
-
 
93
            return false;
-
 
94
        }
-
 
95
        if(item.getBrand() == null || item.getBrand().isEmpty()) {
-
 
96
            Window.alert("Brand cannot be empty.");
-
 
97
            return false;
-
 
98
        }
-
 
99
        if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {
-
 
100
            Window.alert("Model Number cannot be empty.");
-
 
101
            return false;
-
 
102
        }
-
 
103
        
-
 
104
        if(item.getSellingPrice() > item.getMrp()) {
-
 
105
            Window.alert("Selling price cannot be more than MRP");
-
 
106
            return false;
-
 
107
        }
-
 
108
        if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {
-
 
109
            for(VendorPricings v : item.getVendorPricesMap().values()) {
-
 
110
                if(item.getMrp() < v.getMop()) {
-
 
111
                    Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
-
 
112
                    return false;
-
 
113
                }
-
 
114
                if(v.getTransferPrice() > v.getMop()) {
-
 
115
                    Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
-
 
116
                    return false;
-
 
117
                }
-
 
118
            }
-
 
119
        }
-
 
120
        if(item.getVendorMappingsMap() != null && !item.getVendorMappingsMap().isEmpty()) {
-
 
121
            for(VendorItemMapping v : item.getVendorMappingsMap().values()) {
-
 
122
                if(v.getItemKey() == null || v.getItemKey().isEmpty()) {
-
 
123
                    Window.alert("Item Key cannot be empty. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
-
 
124
                    return false;
-
 
125
                }
-
 
126
            }
-
 
127
        }
-
 
128
        return true;
-
 
129
    }
82
}
130
}