Subversion Repositories SmartDukaan

Rev

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

Rev 2105 Rev 2119
Line 1... Line 1...
1
package in.shop2020.catalog.dashboard.client;
1
package in.shop2020.catalog.dashboard.client;
2
 
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
3
import in.shop2020.catalog.dashboard.shared.Item;
4
import in.shop2020.catalog.dashboard.shared.Utils;
4
import in.shop2020.catalog.dashboard.shared.Utils;
-
 
5
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
5
import in.shop2020.catalog.dashboard.shared.VendorDetails;
6
import in.shop2020.catalog.dashboard.shared.VendorPricings;
6
 
7
 
7
import java.util.HashMap;
8
import java.util.HashMap;
8
import java.util.Map;
9
import java.util.Map;
9
 
10
 
10
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.core.client.GWT;
Line 29... Line 30...
29
 
30
 
30
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
31
    interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
31
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
32
    private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
32
    
33
    
33
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
34
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
34
    private final int TABLE_INDEX_VENDORID = 0, TABLE_INDEX_VENDOR_DESC = 1, 
35
    private final int TABLE_INDEX_VENDORID = 0,
35
    TABLE_INDEX_ITEM_KEY = 2, TABLE_INDEX_MOP = 3, TABLE_INDEX_DP = 4, TABLE_INDEX_TP = 5;
36
                      TABLE_INDEX_VENDOR_DESC = 1, 
-
 
37
                      TABLE_INDEX_ITEM_KEY = 2,
-
 
38
                      TABLE_INDEX_MOP = 2,
-
 
39
                      TABLE_INDEX_DP = 3,
-
 
40
                      TABLE_INDEX_TP = 4;
36
 
41
 
37
    @UiField ListBox vendorCategory;
42
    @UiField ListBox vendorCategory;
38
    @UiField TextBox productGroup;
43
    @UiField TextBox productGroup;
39
    @UiField TextBox brand, modelNumber, modelName, color, comments;
44
    @UiField TextBox brand, modelNumber, modelName, color, comments;
40
    @UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank;
45
    @UiField TextBox mrp, sellingPrice, weight, bestDealText, bestDealValue, bestSellingRank;
41
    @UiField DateBox startDate, retireDate;
46
    @UiField DateBox startDate, retireDate;
42
    @UiField Button addButton, cancelButton;
47
    @UiField Button addButton, cancelButton;
43
    @UiField CheckBox defaultForEntity;
48
    @UiField CheckBox defaultForEntity;
44
    @UiField FlexTable headerVendor, vendorTable;
49
    @UiField FlexTable headerVendor, vendorTable;
45
    @UiField Button addVendorPrices;
50
    @UiField FlexTable headerVendorM, vendorTableM;
46
    
51
    
47
    public ItemForm(){
52
    public ItemForm(){
48
        setText("Add New Item");
53
        setText("Add New Item");
49
        setWidget(uiBinder.createAndBindUi(this));
54
        setWidget(uiBinder.createAndBindUi(this));
-
 
55
        initMappingHeader();
50
        initPricingHeader();
56
        initPricingHeader();
51
        vendorCategory.addItem("Handsets");
57
        vendorCategory.addItem("Handsets");
52
        vendorCategory.addItem("Accessories");
58
        vendorCategory.addItem("Accessories");
53
    }
59
    }
54
    
60
    
-
 
61
    private void initMappingHeader(){
-
 
62
        // Initialize the header.
-
 
63
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
-
 
64
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
-
 
65
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
-
 
66
        headerVendorM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
-
 
67
 
-
 
68
        headerVendorM.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
-
 
69
        headerVendorM.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor Desc");
-
 
70
        headerVendorM.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
-
 
71
        
-
 
72
        Button addButton = new Button("Add");
-
 
73
        headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
-
 
74
        addButton.addClickHandler(new ClickHandler() {
-
 
75
            @Override
-
 
76
            public void onClick(ClickEvent event) {
-
 
77
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog();
-
 
78
                vendorMappingDialog.updateButton.setText("Add");
-
 
79
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
-
 
80
                    @Override
-
 
81
                    public boolean onUpdate(String key, long vendorId) {
-
 
82
                        final int row = vendorTableM.getRowCount();
-
 
83
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
-
 
84
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
-
 
85
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
-
 
86
                        vendorTableM.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY + 1, "50px");
-
 
87
                        
-
 
88
                        vendorTableM.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
-
 
89
                        vendorTableM.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
-
 
90
                        vendorTableM.setText(row, TABLE_INDEX_ITEM_KEY, key);
-
 
91
                        Button removeButton = new Button("X");
-
 
92
                        vendorTableM.setWidget(row, TABLE_INDEX_ITEM_KEY + 1, removeButton);
-
 
93
                        removeButton.addClickHandler(new ClickHandler() {
-
 
94
                            @Override
-
 
95
                            public void onClick(ClickEvent event) {
-
 
96
                                vendorTableM.removeRow(row);
-
 
97
                            }
-
 
98
                        });
-
 
99
                        return true;
-
 
100
                    }
-
 
101
                });
-
 
102
                vendorMappingDialog.show();
-
 
103
            }
-
 
104
        });
-
 
105
    }
55
    
106
    
56
    private void initPricingHeader(){
107
    private void initPricingHeader(){
57
        // Initialize the header.
108
        // Initialize the header.
58
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
109
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
59
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
110
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
60
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
111
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
61
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
112
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
62
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
113
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
63
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
114
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
-
 
115
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP + 1, "50px");
64
 
116
 
65
        headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
117
        headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
66
        headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor Desc");
118
        headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor Desc");
67
        headerVendor.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
119
        headerVendor.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
68
        headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
120
        headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
69
        headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
121
        headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
70
        headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
122
        headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
-
 
123
        
-
 
124
        Button addButton = new Button("Add");
-
 
125
        headerVendor.setWidget(0, TABLE_INDEX_TP + 1, addButton);
-
 
126
        addButton.addClickHandler(new ClickHandler() {
-
 
127
            @Override
-
 
128
            public void onClick(ClickEvent event) {
-
 
129
                VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
-
 
130
                vendorPricesDialog.updateButton.setText("Add");
-
 
131
                vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
-
 
132
                    @Override
-
 
133
                    public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
-
 
134
                        if(!vendorExists(vendorId)) {
-
 
135
                            Window.alert("Vendor already exists");
-
 
136
                            return false;
-
 
137
                        }
-
 
138
                        /*if(!validateVendorPrices(mop, dp, tp)) {
-
 
139
                            return false;
-
 
140
                        }*/
-
 
141
                        final int row = vendorTable.getRowCount();
-
 
142
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
-
 
143
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
-
 
144
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
-
 
145
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
-
 
146
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
-
 
147
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP + 1, "50px");
-
 
148
                        
-
 
149
                        vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
-
 
150
                        vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
-
 
151
                        vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
-
 
152
                        vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
-
 
153
                        vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
-
 
154
                        Button removeButton = new Button("X");
-
 
155
                        vendorTable.setWidget(row, TABLE_INDEX_TP + 1, removeButton);
-
 
156
                        removeButton.addClickHandler(new ClickHandler() {
-
 
157
                            @Override
-
 
158
                            public void onClick(ClickEvent event) {
-
 
159
                                vendorTable.removeRow(row);
-
 
160
                            }
-
 
161
                        });
-
 
162
                        return true;
-
 
163
                    }
-
 
164
                });
-
 
165
                vendorPricesDialog.show();
-
 
166
            }
-
 
167
        });
71
    }
168
    }
72
 
169
 
73
    @UiHandler("addButton")
170
    @UiHandler("addButton")
74
    /**
171
    /**
75
     * On add button click a new item instance is created and all the information from UI fields is dumped in this item instance.
172
     * On add button click a new item instance is created and all the information from UI fields is dumped in this item instance.
76
     * This item instance is then passed to service implementation.
173
     * This item instance is then passed to service implementation.
77
     */
174
     */
78
    void addItem(ClickEvent event) {
175
    void addItem(ClickEvent event) {
79
        //TODO: validate UI fields
176
        //TODO: validate UI fields
80
        
177
        
-
 
178
        catalogService.checkSimilarItem(productGroup.getText().trim(), brand.getText().trim(),
-
 
179
                modelNumber.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
-
 
180
            @Override
-
 
181
            public void onFailure(Throwable caught) {
-
 
182
                GWT.log("Error checking similar item");
-
 
183
                Window.alert("Error checking similar item");
-
 
184
                return;
-
 
185
            }
-
 
186
            @Override
-
 
187
            public void onSuccess(Long result) {
-
 
188
                if(result != 0) {
-
 
189
                    Window.alert("Similar product exists with Item Id " + result);
-
 
190
                    return;
-
 
191
                }
-
 
192
                addNewItem();
-
 
193
            }
-
 
194
        });
-
 
195
    }
-
 
196
    
-
 
197
    void addNewItem() {
81
        Item item = new Item();
198
        Item item = new Item();
82
        
199
        
83
        item.setProductGroup(productGroup.getText().trim());
200
        item.setProductGroup(productGroup.getText().trim());
84
        item.setVendorCategory(vendorCategory.getItemText(vendorCategory.getSelectedIndex()));
201
        item.setVendorCategory(vendorCategory.getItemText(vendorCategory.getSelectedIndex()));
85
        
202
        
Line 162... Line 279...
162
            Window.alert("Invalid best selling rank format");
279
            Window.alert("Invalid best selling rank format");
163
            return;
280
            return;
164
        }
281
        }
165
        item.setDefaultForEntity(defaultForEntity.getValue());
282
        item.setDefaultForEntity(defaultForEntity.getValue());
166
        
283
        
167
        /*Create an instance of VendorDetails for each row in vendor table. Set the vendor details to the instance.
284
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
168
          Add the instance to map and set the map to the item instance created above.*/
285
          Add the instance to map and set the map to the item instance created above.*/
169
        Map<Long, VendorDetails> vendorPrices = new HashMap<Long, VendorDetails>();
286
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
170
        VendorDetails v;
287
        VendorPricings v;
171
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
288
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
172
            v = new VendorDetails();
289
            v = new VendorPricings();
173
            v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
290
            v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
174
            v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
291
            v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
175
            v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
292
            v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
176
            v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
293
            v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
177
            vendorPrices.put(v.getVendorId(), v);
294
            vendorPrices.put(v.getVendorId(), v);
178
            item.setMop(v.getMop());
295
            item.setMop(v.getMop());
179
            item.setDealerPrice(v.getDealerPrice());
296
            item.setDealerPrice(v.getDealerPrice());
180
            item.setTransferPrice(v.getTransferPrice());
297
            item.setTransferPrice(v.getTransferPrice());
181
        }
298
        }
182
        item.setVendorDetails(vendorPrices);
299
        item.setVendorPricesMap(vendorPrices);
-
 
300
        
-
 
301
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
-
 
302
        Add the instance to map and set the map to the item instance created above.*/
-
 
303
        Map<Long, VendorItemMapping> vendorMappings = new HashMap<Long, VendorItemMapping>();
-
 
304
        VendorItemMapping vMapping;
-
 
305
        for(int row = 0; row < vendorTableM.getRowCount(); row++) {
-
 
306
            vMapping = new VendorItemMapping();
-
 
307
            vMapping.setItemKey(vendorTableM.getText(row, TABLE_INDEX_ITEM_KEY));
-
 
308
            vMapping.setVendorId(Long.parseLong(vendorTableM.getText(row, TABLE_INDEX_VENDORID)));
-
 
309
            vendorMappings.put(vMapping.getVendorId(), vMapping);
-
 
310
        }
-
 
311
        item.setVendorMappingsMap(vendorMappings);
-
 
312
        
-
 
313
        if(!Utils.validateItem(item)) {
-
 
314
            return;
-
 
315
        }
183
        
316
        
184
        /*Service method to add item to DB. */
317
        /*Service method to add item to DB. */
185
        catalogService.addItem(item, new AsyncCallback<Long>() {
318
        catalogService.addItem(item, new AsyncCallback<Long>() {
186
            @Override
319
            @Override
187
            public void onSuccess(Long result) {
320
            public void onSuccess(Long result) {
Line 207... Line 340...
207
    
340
    
208
    /**
341
    /**
209
     * This will pop up a dialog box for adding vendor details. 
342
     * This will pop up a dialog box for adding vendor details. 
210
     * @param event
343
     * @param event
211
     */
344
     */
212
    @UiHandler("addVendorPrices")
345
    /*@UiHandler("addVendorPrices")
213
    void addVendorPrices(ClickEvent event) {
346
    void addVendorPrices(ClickEvent event) {
214
        VendorPricesDialog pricesDialog = new VendorPricesDialog();
347
        VendorPricesDialog pricesDialog = new VendorPricesDialog();
215
        pricesDialog.updateButton.setText("Add");
348
        pricesDialog.updateButton.setText("Add");
216
        pricesDialog.setVendorDetailsUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
349
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
217
            @Override
350
            @Override
218
            public boolean onUpdate(String itemKey, double mop, double dp, double tp, long vendorId) {
351
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
219
                if(!vendorExists(vendorId)) {
352
                if(!vendorExists(vendorId)) {
220
                    Window.alert("Vendor already exists");
353
                    Window.alert("Vendor already exists");
221
                    return false;
354
                    return false;
222
                }   
355
                }   
223
                if(!validateVendorDetails(itemKey, mop, dp, tp)) {
356
                if(!validateVendorPrices(mop, dp, tp)) {
224
                    return false;
357
                    return false;
225
                }
358
                }
226
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
359
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
227
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
360
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
228
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
-
 
229
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
361
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
230
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
362
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
231
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
363
                vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
232
                
364
                
233
                int row = vendorTable.getRowCount();
365
                int row = vendorTable.getRowCount();
234
                vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId+"");
366
                vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId+"");
235
                vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
367
                vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
236
                vendorTable.setText(row, TABLE_INDEX_ITEM_KEY, itemKey);
-
 
237
                vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
368
                vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
238
                vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
369
                vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
239
                vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
370
                vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
240
                Button removeButton = new Button("Remove");
371
                Button removeButton = new Button("Remove");
241
                vendorTable.setWidget(row, TABLE_INDEX_TP + 1, removeButton);
372
                vendorTable.setWidget(row, TABLE_INDEX_TP + 1, removeButton);
Line 250... Line 381...
250
                return true;
381
                return true;
251
            }
382
            }
252
        });
383
        });
253
        pricesDialog.center();
384
        pricesDialog.center();
254
        pricesDialog.show();
385
        pricesDialog.show();
255
    }
386
    }*/
256
    
387
    
257
    /**
388
    /**
258
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
389
     * Checks if vendor details already exists corresponding to the vendor Id parameter. 
259
     */
390
     */
260
    private boolean vendorExists(long vendorId) {
391
    private boolean vendorExists(long vendorId) {
Line 267... Line 398...
267
        }
398
        }
268
        return true;
399
        return true;
269
    }
400
    }
270
    
401
    
271
    /**
402
    /**
272
     * validate vendor details (Item key, MOP, DealerPrice, TransferPrice)
403
     * validate vendor prices (MOP, DealerPrice, TransferPrice)
273
     */
404
     */
274
    private boolean validateVendorDetails(String key, double mop, double dp, double tp) {
405
    private boolean validateVendorPrices(double mop, double dp, double tp) {
275
        double mrpValue;
406
        double mrpValue;
276
        if(key == null || key.isEmpty()) {
-
 
277
            Window.alert("Item key cannot be empty");
-
 
278
            return false;
-
 
279
        }
-
 
280
        try {
407
        try {
281
            mrpValue = Double.parseDouble(mrp.getText().trim());
408
            mrpValue = Double.parseDouble(mrp.getText().trim());
282
        } catch (NumberFormatException ex) {
409
        } catch (NumberFormatException ex) {
283
            Window.alert("Invalid MRP value.");
410
            Window.alert("Invalid MRP value.");
284
            return false;
411
            return false;