Subversion Repositories SmartDukaan

Rev

Rev 2126 | Rev 2427 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2066 ankur.sing 1
package in.shop2020.catalog.dashboard.shared;
2
 
3
import in.shop2020.catalog.dashboard.client.CatalogService;
4
import in.shop2020.catalog.dashboard.client.CatalogServiceAsync;
2126 ankur.sing 5
import in.shop2020.model.v1.catalog.status;
2066 ankur.sing 6
 
2068 ankur.sing 7
import java.util.Date;
2105 ankur.sing 8
import java.util.List;
2066 ankur.sing 9
import java.util.Map;
2105 ankur.sing 10
import java.util.Map.Entry;
2066 ankur.sing 11
 
12
import com.google.gwt.core.client.GWT;
2126 ankur.sing 13
import com.google.gwt.user.client.DOM;
2119 ankur.sing 14
import com.google.gwt.user.client.Window;
2066 ankur.sing 15
import com.google.gwt.user.client.rpc.AsyncCallback;
2126 ankur.sing 16
import com.google.gwt.user.client.ui.RootPanel;
2066 ankur.sing 17
 
18
public class Utils {
2126 ankur.sing 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;
2359 ankur.sing 26
    public static final int ROLE_STAGING = 0, ROLE_PRODUCTION = 1;
2066 ankur.sing 27
    private static Map<Long, String> vendors, warehouses;
28
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
2126 ankur.sing 29
 
30
 
31
 
2066 ankur.sing 32
    static {
33
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
34
            @Override
35
            public void onSuccess(Map<Long, String> result) {
36
                vendors = result;
37
            }
38
            @Override
39
            public void onFailure(Throwable caught) {
2359 ankur.sing 40
                caught.printStackTrace();
2066 ankur.sing 41
            }
42
        });
43
 
44
        catalogService.getAllWarehouses(new AsyncCallback<Map<Long,String>>() {
45
            @Override
46
            public void onSuccess(Map<Long, String> result) {
47
                warehouses = result;
48
            }
49
            @Override
50
            public void onFailure(Throwable caught) {
2359 ankur.sing 51
                caught.printStackTrace();
2066 ankur.sing 52
            }
53
        });
54
    }
2119 ankur.sing 55
 
2105 ankur.sing 56
    public static Map<Long, String> getAllVendors() {
57
        return vendors;
58
    }
2066 ankur.sing 59
 
2105 ankur.sing 60
    public static Map<Long, String> getAllWarehouses() {
61
        return warehouses;
62
    }
63
 
2066 ankur.sing 64
    public static String getVendorDesc(long id) {
65
        if(vendors == null) {
66
            return null;
67
        }
68
        return vendors.get(id);
69
    }
70
 
71
    public static String getWarehouseDesc(long id) {
72
        if(warehouses == null) {
73
            return null;
74
        }
75
        return warehouses.get(id);
76
    }
2068 ankur.sing 77
 
78
    public static String getDisplayableDate(Long millis){
79
        Date date = new Date();
80
        date.setTime(millis);
81
        String dateString = date.toString();
82
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
83
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
84
        return dateString;      
85
    }
2105 ankur.sing 86
 
87
    public static long getVendorId(String vendorDesc) {
88
        if(vendors == null) {
89
            return 0;
90
        }
91
        for(Entry<Long, String> v : vendors.entrySet()) {
92
            if(v.getValue().equals(vendorDesc)) {
93
                return v.getKey();
94
            }
95
        }
96
        return 0;
97
    }
2119 ankur.sing 98
 
99
    public static boolean validateItem(Item item) {
100
        if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {
101
            Window.alert("Product Group cannot be empty.");
102
            return false;
103
        }
104
        if(item.getBrand() == null || item.getBrand().isEmpty()) {
105
            Window.alert("Brand cannot be empty.");
106
            return false;
107
        }
108
        if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {
109
            Window.alert("Model Number cannot be empty.");
110
            return false;
111
        }
112
 
2126 ankur.sing 113
        if(item.getSellingPrice() != -1 && item.getMrp() != -1 && item.getSellingPrice() > item.getMrp()) {
2119 ankur.sing 114
            Window.alert("Selling price cannot be more than MRP");
115
            return false;
116
        }
117
        if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {
118
            for(VendorPricings v : item.getVendorPricesMap().values()) {
2126 ankur.sing 119
                if(item.getMrp() != -1 && item.getMrp() < v.getMop()) {
2119 ankur.sing 120
                    Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
121
                    return false;
122
                }
123
                if(v.getTransferPrice() > v.getMop()) {
124
                    Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
125
                    return false;
126
                }
127
            }
128
        }
2359 ankur.sing 129
        if(item.getVendorKeysMap() != null && !item.getVendorKeysMap().isEmpty()) {
130
            for(VendorItemMapping v : item.getVendorKeysMap().values()) {
2119 ankur.sing 131
                if(v.getItemKey() == null || v.getItemKey().isEmpty()) {
132
                    Window.alert("Item Key cannot be empty. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
133
                    return false;
134
                }
135
            }
136
        }
137
        return true;
138
    }
2126 ankur.sing 139
 
140
    public static boolean validateStatusChange(int fromStatus, int toStatus) {
141
        switch(toStatus) {
142
        case PHASED_OUT: 
143
            switch(fromStatus) {
144
            case IN_PROCESS: return true;
145
            case CONTENT_COMPLETE: return true;
146
            case ACTIVE: return true;
147
            default: return false;
148
            }
149
        case IN_PROCESS:
150
            switch(fromStatus) {
151
            case PHASED_OUT: return true;
152
            default: return false;
153
            }
154
        case PAUSED:
155
            switch(fromStatus) {
156
            case ACTIVE: return true;
157
            default: return false;
158
            }
159
        case ACTIVE:
160
            switch(fromStatus) {
161
            case PAUSED: return true;
162
            default: return false;
163
            }
164
        }
165
        return true;
166
    }
167
 
168
    public static void showWaitCursor() {
169
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait");
170
    }
171
 
172
    public static void showDefaultCursor() {
173
        DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
174
    }
175
 
176
 
2066 ankur.sing 177
}