Subversion Repositories SmartDukaan

Rev

Rev 2105 | Rev 2126 | 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;
5
 
2068 ankur.sing 6
import java.util.Date;
2105 ankur.sing 7
import java.util.List;
2066 ankur.sing 8
import java.util.Map;
2105 ankur.sing 9
import java.util.Map.Entry;
2066 ankur.sing 10
 
11
import com.google.gwt.core.client.GWT;
2119 ankur.sing 12
import com.google.gwt.user.client.Window;
2066 ankur.sing 13
import com.google.gwt.user.client.rpc.AsyncCallback;
14
 
15
public class Utils {
2105 ankur.sing 16
    public static int MODE_ADD = 0, MODE_EDIT = 1;
2066 ankur.sing 17
    private static Map<Long, String> vendors, warehouses;
18
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
2119 ankur.sing 19
    private static boolean vendorsLoaded;
2066 ankur.sing 20
    static {
21
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
22
            @Override
23
            public void onSuccess(Map<Long, String> result) {
24
                vendors = result;
2119 ankur.sing 25
                setVendorsLoaded();
2066 ankur.sing 26
            }
27
            @Override
28
            public void onFailure(Throwable caught) {
29
            }
30
        });
31
 
32
        catalogService.getAllWarehouses(new AsyncCallback<Map<Long,String>>() {
33
            @Override
34
            public void onSuccess(Map<Long, String> result) {
35
                warehouses = result;
36
            }
37
            @Override
38
            public void onFailure(Throwable caught) {
39
            }
40
        });
41
    }
2119 ankur.sing 42
 
43
    private static void setVendorsLoaded() {
44
        vendorsLoaded = true;
45
    }
2105 ankur.sing 46
 
47
    public static Map<Long, String> getAllVendors() {
48
        return vendors;
49
    }
2066 ankur.sing 50
 
2105 ankur.sing 51
    public static Map<Long, String> getAllWarehouses() {
52
        return warehouses;
53
    }
54
 
2066 ankur.sing 55
    public static String getVendorDesc(long id) {
56
        if(vendors == null) {
57
            return null;
58
        }
59
        return vendors.get(id);
60
    }
61
 
62
    public static String getWarehouseDesc(long id) {
63
        if(warehouses == null) {
64
            return null;
65
        }
66
        return warehouses.get(id);
67
    }
2068 ankur.sing 68
 
69
    public static String getDisplayableDate(Long millis){
70
        Date date = new Date();
71
        date.setTime(millis);
72
        String dateString = date.toString();
73
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
74
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
75
        return dateString;      
76
    }
2105 ankur.sing 77
 
78
    public static long getVendorId(String vendorDesc) {
79
        if(vendors == null) {
80
            return 0;
81
        }
82
        for(Entry<Long, String> v : vendors.entrySet()) {
83
            if(v.getValue().equals(vendorDesc)) {
84
                return v.getKey();
85
            }
86
        }
87
        return 0;
88
    }
2119 ankur.sing 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
    }
2066 ankur.sing 130
}