Subversion Repositories SmartDukaan

Rev

Rev 12523 | 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;
4957 phani.kuma 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
 
2427 ankur.sing 15
/**
16
 * Utility methods goes here
17
 *
18
 */
2066 ankur.sing 19
public class Utils {
2427 ankur.sing 20
    // item status values. These should be analogous to status enum in status.java
21
    // These values are used in the client side to check if transition from one status to another is 
22
    // valid. Also see validateStatusChange method
23
    // FIXME: These should be read from the ThriftConfig file and not hard-coded here.
2126 ankur.sing 24
    public static final int PHASED_OUT = 0,
25
                            DELETED = 1,
26
                            PAUSED = 2,
27
                            ACTIVE = 3,
28
                            IN_PROCESS = 4,
29
                            CONTENT_COMPLETE = 5;
2427 ankur.sing 30
 
31
    // role column in helper.catalogdashboarduser table. role specifies 
32
    // the username-pwd pair for staging or for production.
33
    // production password is needed while updating item on production server.
6788 rajveer 34
    public static final int ROLE_STAGING = 0, ROLE_READONLY = 1, ROLE_PRODUCTION = 2;
5586 phani.kuma 35
    private static boolean entityIdMandatory = false;
2427 ankur.sing 36
 
12523 amit.gupta 37
    private static Map<Long, String> vendors, warehouses, sources, voucherType, categoriesMap, stateMap;
4957 phani.kuma 38
    private static List<String> categories, brands;
2427 ankur.sing 39
 
2066 ankur.sing 40
    private static final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
2126 ankur.sing 41
 
6530 vikram.rag 42
    private static List<ItemWarehouse> ignoredInventoryUpdateItemsIdsWarehouseIds;
6838 vikram.rag 43
    private static Map<Long,String> allInsurers;
6530 vikram.rag 44
 
2066 ankur.sing 45
    static {
6838 vikram.rag 46
    	catalogService.getAllInsurers(new AsyncCallback<Map<Long,String>>() {
47
            @Override
48
            public void onSuccess(Map<Long, String> result) {
49
            	allInsurers = result;
50
            }
51
            @Override
52
            public void onFailure(Throwable caught) {
53
                caught.printStackTrace();
54
            }
55
        });
5586 phani.kuma 56
    	catalogService.getConfigforentityIdMandatory(new AsyncCallback<Boolean>() {
57
	        @Override
58
	        public void onSuccess(Boolean result) {
59
	        	setEntityIdMandatory(result);
60
	        }
61
	        @Override
62
	        public void onFailure(Throwable caught) {
63
	            caught.printStackTrace();
64
	        }
65
	    });
6530 vikram.rag 66
    	catalogService.getignoredInventoryUpdateItemsIdsWarehouseIds(new AsyncCallback<List<ItemWarehouse>>() {
67
	        @Override
68
	        public void onSuccess(List<ItemWarehouse> result) {
69
	        	ignoredInventoryUpdateItemsIdsWarehouseIds=result;
70
	        }
71
	        @Override
72
	        public void onFailure(Throwable caught) {
73
	            caught.printStackTrace();
74
	        }
75
	    });
76
 
5586 phani.kuma 77
 
2066 ankur.sing 78
        catalogService.getAllVendors(new AsyncCallback<Map<Long,String>>() {
79
            @Override
80
            public void onSuccess(Map<Long, String> result) {
81
                vendors = result;
82
            }
83
            @Override
84
            public void onFailure(Throwable caught) {
2359 ankur.sing 85
                caught.printStackTrace();
2066 ankur.sing 86
            }
87
        });
12523 amit.gupta 88
 
5118 mandeep.dh 89
 
12523 amit.gupta 90
 
91
        catalogService.getAllStatesMap(new AsyncCallback<Map<Long,String>>() {
92
            @Override
93
            public void onSuccess(Map<Long, String> result) {
94
                stateMap = result;
95
            }
96
            @Override
97
            public void onFailure(Throwable caught) {
98
                caught.printStackTrace();
99
            }
100
        });
101
 
102
 
2066 ankur.sing 103
        catalogService.getAllWarehouses(new AsyncCallback<Map<Long,String>>() {
104
            @Override
105
            public void onSuccess(Map<Long, String> result) {
106
                warehouses = result;
107
            }
108
            @Override
109
            public void onFailure(Throwable caught) {
2359 ankur.sing 110
                caught.printStackTrace();
2066 ankur.sing 111
            }
112
        });
3558 rajveer 113
 
114
        catalogService.getAllSources(new AsyncCallback<Map<Long,String>>() {
115
            @Override
116
            public void onSuccess(Map<Long, String> result) {
117
                sources = result;
118
            }
119
            @Override
120
            public void onFailure(Throwable caught) {
121
                caught.printStackTrace();
122
            }
123
        });
4957 phani.kuma 124
 
125
        catalogService.getAllCategories(new AsyncCallback<List<String>>() {
126
            @Override
127
            public void onSuccess(List<String> result) {
12523 amit.gupta 128
            	categories = result; 
4957 phani.kuma 129
            }
130
            @Override
131
            public void onFailure(Throwable caught) {
132
                caught.printStackTrace();
133
            }
134
        });
135
 
12523 amit.gupta 136
 
137
        catalogService.getAllCategoriesMap(new AsyncCallback<Map<Long, String>>() {
138
            @Override
139
            public void onSuccess(Map<Long, String> result) {
140
            	categoriesMap = result;
141
            }
142
            @Override
143
            public void onFailure(Throwable caught) {
144
                caught.printStackTrace();
145
            }
146
        });
147
 
4957 phani.kuma 148
        catalogService.getAllBrands(new AsyncCallback<List<String>>() {
149
            @Override
150
            public void onSuccess(List<String> result) {
151
            	brands = result;
152
            }
153
            @Override
154
            public void onFailure(Throwable caught) {
155
                caught.printStackTrace();
156
            }
157
        });
5504 phani.kuma 158
 
5516 phani.kuma 159
        catalogService.getvoucherTypes(new AsyncCallback<Map<Long,String>>() {
5504 phani.kuma 160
            @Override
5516 phani.kuma 161
            public void onSuccess(Map<Long,String> result) {
162
            	setVoucherType(result);
5504 phani.kuma 163
            }
164
            @Override
165
            public void onFailure(Throwable caught) {
166
                caught.printStackTrace();
167
            }
168
        });
3558 rajveer 169
 
2066 ankur.sing 170
    }
2119 ankur.sing 171
 
5586 phani.kuma 172
    public static void setEntityIdMandatory(boolean entityIdMandatory) {
173
		Utils.entityIdMandatory = entityIdMandatory;
174
	}
175
 
176
	public static boolean isEntityIdMandatory() {
177
		return entityIdMandatory;
178
	}
179
 
180
	public static Map<Long, String> getAllVendors() {
2105 ankur.sing 181
        return vendors;
182
    }
6838 vikram.rag 183
	public static Map<Long, String> getAllInsurers() {
184
        return allInsurers;
185
    }
3558 rajveer 186
 
187
    public static Map<Long, String> getAllSources() {
188
        return sources;
189
    }
2066 ankur.sing 190
 
2105 ankur.sing 191
    public static Map<Long, String> getAllWarehouses() {
192
        return warehouses;
193
    }
5118 mandeep.dh 194
 
4957 phani.kuma 195
    public static List<String> getAllCategories() {
196
        return categories;
197
    }
198
 
12523 amit.gupta 199
 
200
    public static Map<Long, String> getAllCategoriesMap() {
201
        return categoriesMap;
202
    }
203
 
4957 phani.kuma 204
    public static List<String> getAllBrands() {
205
        return brands;
206
    }
207
 
2066 ankur.sing 208
    public static String getVendorDesc(long id) {
209
        if(vendors == null) {
210
            return null;
211
        }
212
        return vendors.get(id);
213
    }
214
 
6530 vikram.rag 215
    public static List<ItemWarehouse> getignoredInventoryUpdateItemsIdsWarehouseIds(){
216
    	return ignoredInventoryUpdateItemsIdsWarehouseIds;
217
    }
218
 
3558 rajveer 219
    public static String getSourceDesc(long id) {
220
        if(sources == null) {
221
            return null;
222
        }
223
        return sources.get(id);
224
    }
225
 
2066 ankur.sing 226
    public static String getWarehouseDesc(long id) {
227
        if(warehouses == null) {
228
            return null;
229
        }
230
        return warehouses.get(id);
231
    }
5516 phani.kuma 232
 
233
    public static long getVoucherTypeId(String voucherDesc) {
234
        if(voucherType == null) {
235
            return 0;
236
        }
237
        for(Entry<Long, String> v : voucherType.entrySet()) {
238
            if(v.getValue().equals(voucherDesc)) {
239
                return v.getKey();
240
            }
241
        }
242
        return 0;
243
    }
244
 
2068 ankur.sing 245
    public static String getDisplayableDate(Long millis){
246
        Date date = new Date();
247
        date.setTime(millis);
248
        String dateString = date.toString();
249
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
250
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
251
        return dateString;      
252
    }
2105 ankur.sing 253
 
2427 ankur.sing 254
    /**
255
     * Since in vendor combo box, vendor name is populated, this method is used to get Id from name
256
     * @param vendor name
257
     * @return vendor Id corresponding to the name
258
     */
2105 ankur.sing 259
    public static long getVendorId(String vendorDesc) {
260
        if(vendors == null) {
261
            return 0;
262
        }
263
        for(Entry<Long, String> v : vendors.entrySet()) {
264
            if(v.getValue().equals(vendorDesc)) {
265
                return v.getKey();
266
            }
267
        }
268
        return 0;
269
    }
2119 ankur.sing 270
 
2427 ankur.sing 271
    /**
4725 phani.kuma 272
     * Since in warehouse combo box, warehouse name is populated, this method is used to get Id from name
273
     * @param warehouse name
274
     * @return warehouse Id corresponding to the name
275
     */
276
    public static long getWarehouseId(String warehouseDesc) {
277
        if(warehouses == null) {
278
            return 0;
279
        }
280
        for(Entry<Long, String> w : warehouses.entrySet()) {
281
            if(w.getValue().equals(warehouseDesc)) {
282
                return w.getKey();
283
            }
284
        }
285
        return 0;
286
    }
287
 
288
    /**
3558 rajveer 289
     * Since in source combo box, source name is populated, this method is used to get Id from name
290
     * @param source name
291
     * @return source Id corresponding to the name
292
     */
293
    public static long getSourceId(String sourceDesc) {
294
        if(sources == null) {
295
            return 0;
296
        }
297
        for(Entry<Long, String> s : sources.entrySet()) {
298
            if(s.getValue().equals(sourceDesc)) {
299
                return s.getKey();
300
            }
301
        }
302
        return 0;
303
    }
304
 
305
    /**
2427 ankur.sing 306
     * validates item object. ProductGroup, brand, modelNumber, modelName should not be empty or null.
307
     * Also does item and vendor prices validations (MRP >= SP, MRP >= MOP, TP <= MOP)
308
     * Vendor Item Key should not be empty or null
309
     * @param item
2431 ankur.sing 310
     * @return true if validation is successful, false otherwise
2427 ankur.sing 311
     */
2119 ankur.sing 312
    public static boolean validateItem(Item item) {
313
        if(item.getProductGroup() == null || item.getProductGroup().isEmpty()) {
314
            Window.alert("Product Group cannot be empty.");
315
            return false;
316
        }
317
        if(item.getBrand() == null || item.getBrand().isEmpty()) {
318
            Window.alert("Brand cannot be empty.");
319
            return false;
320
        }
321
        if(item.getModelNumber() == null || item.getModelNumber().isEmpty()) {
322
            Window.alert("Model Number cannot be empty.");
323
            return false;
324
        }
325
 
2489 ankur.sing 326
        if(item.getSellingPrice() != null && item.getMrp() != null && item.getSellingPrice() > item.getMrp()) {
2119 ankur.sing 327
            Window.alert("Selling price cannot be more than MRP");
328
            return false;
329
        }
330
        if(item.getVendorPricesMap() != null && !item.getVendorPricesMap().isEmpty()) {
331
            for(VendorPricings v : item.getVendorPricesMap().values()) {
2489 ankur.sing 332
                if(item.getMrp() != null && item.getMrp() < v.getMop()) {
2119 ankur.sing 333
                    Window.alert("MRP cannot be less than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
334
                    return false;
335
                }
18457 kshitij.so 336
//                if(v.getTransferPrice() > v.getMop()) {
337
//                    Window.alert("Transfer Price cannot be more than MOP. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
338
//                    return false;
339
//                }
2119 ankur.sing 340
            }
341
        }
2359 ankur.sing 342
        if(item.getVendorKeysMap() != null && !item.getVendorKeysMap().isEmpty()) {
343
            for(VendorItemMapping v : item.getVendorKeysMap().values()) {
2119 ankur.sing 344
                if(v.getItemKey() == null || v.getItemKey().isEmpty()) {
345
                    Window.alert("Item Key cannot be empty. Vendor: " + Utils.getVendorDesc(v.getVendorId()));
346
                    return false;
347
                }
348
            }
349
        }
350
        return true;
351
    }
2126 ankur.sing 352
 
2427 ankur.sing 353
 
2126 ankur.sing 354
    public static boolean validateStatusChange(int fromStatus, int toStatus) {
355
        switch(toStatus) {
356
        case PHASED_OUT: 
357
            switch(fromStatus) {
358
            case IN_PROCESS: return true;
359
            case CONTENT_COMPLETE: return true;
360
            case ACTIVE: return true;
361
            default: return false;
362
            }
363
        case IN_PROCESS:
364
            switch(fromStatus) {
365
            case PHASED_OUT: return true;
366
            default: return false;
367
            }
368
        case PAUSED:
369
            switch(fromStatus) {
370
            case ACTIVE: return true;
371
            default: return false;
372
            }
373
        case ACTIVE:
374
            switch(fromStatus) {
375
            case PAUSED: return true;
376
            default: return false;
377
            }
378
        }
379
        return true;
380
    }
5516 phani.kuma 381
 
382
	public static void setVoucherType(Map<Long, String> voucherType) {
383
		Utils.voucherType = voucherType;
384
	}
385
 
386
	public static Map<Long, String> getVoucherType() {
387
		return voucherType;
388
	}
12523 amit.gupta 389
 
390
	public static Map<Long, String> getStateMap() {
391
		return stateMap;
392
	}
2066 ankur.sing 393
}