Subversion Repositories SmartDukaan

Rev

Rev 2119 | Rev 2359 | 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;
26
 
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) {
40
            }
41
        });
42
 
43
        catalogService.getAllWarehouses(new AsyncCallback<Map<Long,String>>() {
44
            @Override
45
            public void onSuccess(Map<Long, String> result) {
46
                warehouses = result;
47
            }
48
            @Override
49
            public void onFailure(Throwable caught) {
50
            }
51
        });
52
    }
2119 ankur.sing 53
 
2105 ankur.sing 54
    public static Map<Long, String> getAllVendors() {
55
        return vendors;
56
    }
2066 ankur.sing 57
 
2105 ankur.sing 58
    public static Map<Long, String> getAllWarehouses() {
59
        return warehouses;
60
    }
61
 
2066 ankur.sing 62
    public static String getVendorDesc(long id) {
63
        if(vendors == null) {
64
            return null;
65
        }
66
        return vendors.get(id);
67
    }
68
 
69
    public static String getWarehouseDesc(long id) {
70
        if(warehouses == null) {
71
            return null;
72
        }
73
        return warehouses.get(id);
74
    }
2068 ankur.sing 75
 
76
    public static String getDisplayableDate(Long millis){
77
        Date date = new Date();
78
        date.setTime(millis);
79
        String dateString = date.toString();
80
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
81
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
82
        return dateString;      
83
    }
2105 ankur.sing 84
 
85
    public static long getVendorId(String vendorDesc) {
86
        if(vendors == null) {
87
            return 0;
88
        }
89
        for(Entry<Long, String> v : vendors.entrySet()) {
90
            if(v.getValue().equals(vendorDesc)) {
91
                return v.getKey();
92
            }
93
        }
94
        return 0;
95
    }
2119 ankur.sing 96
 
97
    public static boolean validateItem(Item item) {
98
        if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {
99
            Window.alert("Product Group cannot be empty.");
100
            return false;
101
        }
102
        if(item.getBrand() == null || item.getBrand().isEmpty()) {
103
            Window.alert("Brand cannot be empty.");
104
            return false;
105
        }
106
        if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {
107
            Window.alert("Model Number cannot be empty.");
108
            return false;
109
        }
110
 
2126 ankur.sing 111
        if(item.getSellingPrice() != -1 && item.getMrp() != -1 && item.getSellingPrice() > item.getMrp()) {
2119 ankur.sing 112
            Window.alert("Selling price cannot be more than MRP");
113
            return false;
114
        }
115
        if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {
116
            for(VendorPricings v : item.getVendorPricesMap().values()) {
2126 ankur.sing 117
                if(item.getMrp() != -1 && item.getMrp() < v.getMop()) {
2119 ankur.sing 118
                    Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
119
                    return false;
120
                }
121
                if(v.getTransferPrice() > v.getMop()) {
122
                    Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
123
                    return false;
124
                }
125
            }
126
        }
127
        if(item.getVendorMappingsMap() != null && !item.getVendorMappingsMap().isEmpty()) {
128
            for(VendorItemMapping v : item.getVendorMappingsMap().values()) {
129
                if(v.getItemKey() == null || v.getItemKey().isEmpty()) {
130
                    Window.alert("Item Key cannot be empty. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
131
                    return false;
132
                }
133
            }
134
        }
135
        return true;
136
    }
2126 ankur.sing 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
 
2066 ankur.sing 175
}