Subversion Repositories SmartDukaan

Rev

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

Rev 2119 Rev 2126
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.shared;
1
package in.shop2020.catalog.dashboard.shared;
2
 
2
 
3
import in.shop2020.catalog.dashboard.client.CatalogService;
3
import in.shop2020.catalog.dashboard.client.CatalogService;
4
import in.shop2020.catalog.dashboard.client.CatalogServiceAsync;
4
import in.shop2020.catalog.dashboard.client.CatalogServiceAsync;
-
 
5
import in.shop2020.model.v1.catalog.status;
5
 
6
 
6
import java.util.Date;
7
import java.util.Date;
7
import java.util.List;
8
import java.util.List;
8
import java.util.Map;
9
import java.util.Map;
9
import java.util.Map.Entry;
10
import java.util.Map.Entry;
10
 
11
 
11
import com.google.gwt.core.client.GWT;
12
import com.google.gwt.core.client.GWT;
-
 
13
import com.google.gwt.user.client.DOM;
12
import com.google.gwt.user.client.Window;
14
import com.google.gwt.user.client.Window;
13
import com.google.gwt.user.client.rpc.AsyncCallback;
15
import com.google.gwt.user.client.rpc.AsyncCallback;
-
 
16
import com.google.gwt.user.client.ui.RootPanel;
14
 
17
 
15
public class Utils {
18
public class Utils {
16
    public static int MODE_ADD = 0, MODE_EDIT = 1;
19
    //public static final int MODE_ADD = 0, MODE_EDIT = 1;
-
 
20
    public static final int PHASED_OUT = 0,
-
 
21
                            DELETED = 1,
-
 
22
                            PAUSED = 2,
-
 
23
                            ACTIVE = 3,
-
 
24
                            IN_PROCESS = 4,
-
 
25
                            CONTENT_COMPLETE = 5;
-
 
26
    
17
    private static Map<Long, String> vendors, warehouses;
27
    private static Map<Long, String> vendors, warehouses;
18
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
28
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
-
 
29
    
19
    private static boolean vendorsLoaded;
30
    
-
 
31
 
20
    static {
32
    static {
21
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
33
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
22
            @Override
34
            @Override
23
            public void onSuccess(Map<Long, String> result) {
35
            public void onSuccess(Map<Long, String> result) {
24
                vendors = result;
36
                vendors = result;
25
                setVendorsLoaded();
-
 
26
            }
37
            }
27
            @Override
38
            @Override
28
            public void onFailure(Throwable caught) {
39
            public void onFailure(Throwable caught) {
29
            }
40
            }
30
        });
41
        });
Line 38... Line 49...
38
            public void onFailure(Throwable caught) {
49
            public void onFailure(Throwable caught) {
39
            }
50
            }
40
        });
51
        });
41
    }
52
    }
42
    
53
    
43
    private static void setVendorsLoaded() {
-
 
44
        vendorsLoaded = true;
-
 
45
    }
-
 
46
        
-
 
47
    public static Map<Long, String> getAllVendors() {
54
    public static Map<Long, String> getAllVendors() {
48
        return vendors;
55
        return vendors;
49
    }
56
    }
50
    
57
    
51
    public static Map<Long, String> getAllWarehouses() {
58
    public static Map<Long, String> getAllWarehouses() {
Line 99... Line 106...
99
        if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {
106
        if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {
100
            Window.alert("Model Number cannot be empty.");
107
            Window.alert("Model Number cannot be empty.");
101
            return false;
108
            return false;
102
        }
109
        }
103
        
110
        
104
        if(item.getSellingPrice() > item.getMrp()) {
111
        if(item.getSellingPrice() != -1 && item.getMrp() != -1 && item.getSellingPrice() > item.getMrp()) {
105
            Window.alert("Selling price cannot be more than MRP");
112
            Window.alert("Selling price cannot be more than MRP");
106
            return false;
113
            return false;
107
        }
114
        }
108
        if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {
115
        if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {
109
            for(VendorPricings v : item.getVendorPricesMap().values()) {
116
            for(VendorPricings v : item.getVendorPricesMap().values()) {
110
                if(item.getMrp() < v.getMop()) {
117
                if(item.getMrp() != -1 && item.getMrp() < v.getMop()) {
111
                    Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
118
                    Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
112
                    return false;
119
                    return false;
113
                }
120
                }
114
                if(v.getTransferPrice() > v.getMop()) {
121
                if(v.getTransferPrice() > v.getMop()) {
115
                    Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
122
                    Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
Line 125... Line 132...
125
                }
132
                }
126
            }
133
            }
127
        }
134
        }
128
        return true;
135
        return true;
129
    }
136
    }
-
 
137
    
-
 
138
    public static boolean validateStatusChange(int fromStatus, int toStatus) {
-
 
139
        switch(toStatus) {
-
 
140
        case PHASED_OUT: 
-
 
141
            switch(fromStatus) {
-
 
142
            case IN_PROCESS: return true;
-
 
143
            case CONTENT_COMPLETE: return true;
-
 
144
            case ACTIVE: return true;
-
 
145
            default: return false;
-
 
146
            }
-
 
147
        case IN_PROCESS:
-
 
148
            switch(fromStatus) {
-
 
149
            case PHASED_OUT: return true;
-
 
150
            default: return false;
-
 
151
            }
-
 
152
        case PAUSED:
-
 
153
            switch(fromStatus) {
-
 
154
            case ACTIVE: return true;
-
 
155
            default: return false;
-
 
156
            }
-
 
157
        case ACTIVE:
-
 
158
            switch(fromStatus) {
-
 
159
            case PAUSED: return true;
-
 
160
            default: return false;
-
 
161
            }
-
 
162
        }
-
 
163
        return true;
-
 
164
    }
-
 
165
    
-
 
166
    public static void showWaitCursor() {
-
 
167
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");
-
 
168
    }
-
 
169
     
-
 
170
    public static void showDefaultCursor() {
-
 
171
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
-
 
172
    }
-
 
173
    
-
 
174
    
130
}
175
}