Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
1961 ankur.sing 1
package in.shop2020.catalog.dashboard.client;
2
 
3
import in.shop2020.catalog.dashboard.shared.Item;
2066 ankur.sing 4
import in.shop2020.catalog.dashboard.shared.Utils;
2105 ankur.sing 5
import in.shop2020.catalog.dashboard.shared.VendorDetails;
1961 ankur.sing 6
 
7
import java.util.Date;
2066 ankur.sing 8
import java.util.HashMap;
1992 ankur.sing 9
import java.util.Map;
10
import java.util.Map.Entry;
1961 ankur.sing 11
 
12
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.event.dom.client.ClickEvent;
1992 ankur.sing 14
import com.google.gwt.event.dom.client.ClickHandler;
15
import com.google.gwt.resources.client.CssResource;
1961 ankur.sing 16
import com.google.gwt.uibinder.client.UiBinder;
17
import com.google.gwt.uibinder.client.UiField;
18
import com.google.gwt.uibinder.client.UiHandler;
19
import com.google.gwt.user.client.Window;
20
import com.google.gwt.user.client.ui.Button;
2066 ankur.sing 21
import com.google.gwt.user.client.ui.CheckBox;
1992 ankur.sing 22
import com.google.gwt.user.client.ui.FlexTable;
23
import com.google.gwt.user.client.ui.HTMLTable.Cell;
1961 ankur.sing 24
import com.google.gwt.user.client.ui.Label;
25
import com.google.gwt.user.client.ui.ResizeComposite;
26
import com.google.gwt.user.client.ui.TextBox;
27
import com.google.gwt.user.client.ui.Widget;
2068 ankur.sing 28
import com.google.gwt.user.datepicker.client.DateBox;
1961 ankur.sing 29
 
30
public class ItemDetails extends ResizeComposite {
31
 
2105 ankur.sing 32
    private final int TABLE_INDEX_VENDORID = 0, TABLE_INDEX_VENDOR_DESC = 1, 
33
        TABLE_INDEX_ITEM_KEY = 2, TABLE_INDEX_MOP = 3, TABLE_INDEX_DP = 4, TABLE_INDEX_TP = 5;
2066 ankur.sing 34
    private final int TABLE_INDEX_WAREHOUSE_ID = 0, TABLE_INDEX_WAREHOUSE_DESC = 1, TABLE_INDEX_WAREHOUSE_INV = 2;
35
 
36
    interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
37
    private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
38
 
39
    public interface ItemUpdateListener {
1992 ankur.sing 40
        void onItemUpdate(Item item);
2066 ankur.sing 41
    }
1961 ankur.sing 42
 
2066 ankur.sing 43
    interface ItemDetailStyle extends CssResource{
44
        String greenLabel();
45
        String fieldChanged();
46
    }
1961 ankur.sing 47
 
2066 ankur.sing 48
    private ItemUpdateListener itemUpdateListener;
49
 
2105 ankur.sing 50
    private Item item, newItem;
2066 ankur.sing 51
 
52
    @UiField ItemDetailStyle style;
53
    @UiField Label itemId;
54
    @UiField TextBox productGroup, brand, modelNumber, modelName, color;
2105 ankur.sing 55
    @UiField Label contentCategory, catalogItemId;
2066 ankur.sing 56
    @UiField TextBox comments;
2105 ankur.sing 57
    @UiField TextBox sellingPrice, mrp, weight;
58
    @UiField Label addedOn, retireDate, updatedOn;
2066 ankur.sing 59
    @UiField Label itemStatus;
60
    @UiField TextBox bestDealsText, bestDealsValue; 
61
    @UiField FlexTable headerAvailability, availabilityTable;
2105 ankur.sing 62
    @UiField FlexTable headerVendorM, vendorTableM;
63
    @UiField FlexTable headerVendor, vendorTable;
2066 ankur.sing 64
    @UiField TextBox bestSellingRank;
65
    @UiField CheckBox defaultForEntity;
66
    @UiField Button submit;
2068 ankur.sing 67
    @UiField DateBox startDate;
2066 ankur.sing 68
 
69
    public ItemDetails(Item item){
2105 ankur.sing 70
        this();
2066 ankur.sing 71
        setItemDetails(item);
72
    }
73
 
74
    public ItemDetails() {
75
        initWidget(uiBinder.createAndBindUi(this));
76
        initAvailabilityHeader();
77
        initPricingHeader();
2105 ankur.sing 78
        headerAvailability.setVisible(false);
79
        availabilityTable.setVisible(false);
2066 ankur.sing 80
    }
81
 
82
    public void setItemDetails(Item item){
83
        this.item = item;
84
        itemId.setText(item.getId()+"");
85
        productGroup.setText(item.getProductGroup());
86
        brand.setText(item.getBrand());
87
        modelNumber.setText(item.getModelNumber());
88
        modelName.setText(item.getModelName());
89
        color.setText(item.getColor());
90
 
2105 ankur.sing 91
        contentCategory.setText(item.getContentCategory()+"");
2066 ankur.sing 92
        comments.setText(item.getComments());
93
        catalogItemId.setText(item.getCatalogItemId() + "");
94
 
95
        mrp.setText(item.getMrp()+"");
96
        sellingPrice.setText(item.getSellingPrice()+"");
97
        weight.setText(item.getWeight()+"");
2068 ankur.sing 98
 
99
        startDate.setValue(new Date(item.getStartDate()));
100
 
101
        addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
102
        retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
103
        updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
1992 ankur.sing 104
 
2066 ankur.sing 105
        bestDealsText.setText(item.getBestDealsText());
106
        bestDealsValue.setText(item.getBestDealsValue()+"");
107
 
108
        bestSellingRank.setText(item.getBestSellingRank()+"");
109
        defaultForEntity.setValue(item.isDefaultForEntity());
1992 ankur.sing 110
 
2066 ankur.sing 111
        itemStatus.setText(item.getItemStatus());
112
 
113
        updateAvailabilityTable(item.getAvailability());
114
 
2105 ankur.sing 115
        updatePricingTable(item.getVendorDetails());
1992 ankur.sing 116
    }
2066 ankur.sing 117
 
118
    private void initAvailabilityHeader(){
1992 ankur.sing 119
        // Initialize the header.
2066 ankur.sing 120
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
2105 ankur.sing 121
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
2066 ankur.sing 122
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
123
 
124
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
125
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
126
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INV, "Availability");
1992 ankur.sing 127
 
128
    }
2066 ankur.sing 129
 
130
    private void initPricingHeader(){
131
        // Initialize the header.
2105 ankur.sing 132
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
133
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
134
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
135
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
136
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
137
        headerVendor.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
2066 ankur.sing 138
 
2105 ankur.sing 139
        headerVendor.setText(0, TABLE_INDEX_VENDORID, "Vendor Id");
140
        headerVendor.setText(0, TABLE_INDEX_VENDOR_DESC, "Vendor Desc");
141
        headerVendor.setText(0, TABLE_INDEX_ITEM_KEY, "Item Key");
142
        headerVendor.setText(0, TABLE_INDEX_MOP, "MOP");
143
        headerVendor.setText(0, TABLE_INDEX_DP, "Dealer Price");
144
        headerVendor.setText(0, TABLE_INDEX_TP, "Transfer Price");
145
 
146
        Button addButton = new Button("Add");
147
        headerVendor.setWidget(0, TABLE_INDEX_TP + 1, addButton);
148
        addButton.addClickHandler(new ClickHandler() {
149
            @Override
150
            public void onClick(ClickEvent event) {
151
                VendorPricesDialog vendorDialog = new VendorPricesDialog();
152
                vendorDialog.updateButton.setText("Add");
153
                vendorDialog.setVendorDetailsUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
154
                    @Override
155
                    public boolean onUpdate(String key, double mop, double dp, double tp, long vendorId) {
156
                        if(!vendorExists(vendorId)) {
157
                            Window.alert("Vendor already exists");
158
                            return false;
159
                        }
160
                        if(!validateVendorDetails(key, mop, dp, tp)) {
161
                            return false;
162
                        }
163
                        int row = vendorTable.getRowCount();
164
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
165
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
166
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
167
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
168
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
169
                        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
170
 
171
                        vendorTable.setText(row, TABLE_INDEX_VENDORID, vendorId + "");
172
                        vendorTable.setText(row, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorId));
173
                        vendorTable.setText(row, TABLE_INDEX_ITEM_KEY, key);
174
                        vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
175
                        vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
176
                        vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
177
                        return true;
178
                    }
179
                });
180
                vendorDialog.show();
181
            }
182
        });
2066 ankur.sing 183
    }
184
 
2105 ankur.sing 185
 
1992 ankur.sing 186
    private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
187
        availabilityTable.removeAllRows();
188
        if(availabilityMap == null) {
189
            return;
190
        }
2066 ankur.sing 191
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
2105 ankur.sing 192
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
2066 ankur.sing 193
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
194
 
195
 
1992 ankur.sing 196
        int i=0;
197
        for(Entry<Long, Long> availability : availabilityMap.entrySet()){
2066 ankur.sing 198
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, availability.getKey() + "");
199
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(availability.getKey()));
200
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INV, availability.getValue() + "");
1992 ankur.sing 201
            i++;
202
        }
203
    }
2066 ankur.sing 204
 
2105 ankur.sing 205
    private void updatePricingTable(Map<Long, VendorDetails> vendorDetailsMap){
206
        vendorTable.removeAllRows();
207
 
208
        if(vendorDetailsMap == null || vendorDetailsMap.isEmpty()) {
1992 ankur.sing 209
            return;
210
        }
2105 ankur.sing 211
        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDORID, "128px");
212
        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_VENDOR_DESC, "128px");
213
        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_ITEM_KEY, "250px");
214
        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_MOP, "128px");
215
        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_DP, "128px");
216
        vendorTable.getColumnFormatter().setWidth(TABLE_INDEX_TP, "128px");
2066 ankur.sing 217
 
218
 
1992 ankur.sing 219
        int i=0;
2105 ankur.sing 220
        for(VendorDetails vendorDetail : vendorDetailsMap.values()){
221
            vendorTable.setText(i, TABLE_INDEX_VENDORID, vendorDetail.getVendorId() + "");
222
            vendorTable.setText(i, TABLE_INDEX_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
223
            vendorTable.setText(i, TABLE_INDEX_ITEM_KEY, vendorDetail.getItemKey());
224
            vendorTable.setText(i, TABLE_INDEX_MOP, vendorDetail.getMop() + "");
225
            vendorTable.setText(i, TABLE_INDEX_DP, vendorDetail.getDealerPrice() + "");
226
            vendorTable.setText(i, TABLE_INDEX_TP, vendorDetail.getTransferPrice() + "");
1992 ankur.sing 227
            Button editButton = new Button("Edit");
2105 ankur.sing 228
            vendorTable.setWidget(i, TABLE_INDEX_TP + 1, editButton);
1992 ankur.sing 229
            i++;
230
            editButton.addClickHandler(new ClickHandler() {
231
                @Override
232
                public void onClick(ClickEvent event) {
2105 ankur.sing 233
                    Cell cell = vendorTable.getCellForEvent(event);
1992 ankur.sing 234
                    int row = cell.getRowIndex();
2105 ankur.sing 235
                    long vendorId = Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID));
1992 ankur.sing 236
                    updateVendorPrices(vendorId, row);
237
                }
238
            });
239
        }
240
    }
2066 ankur.sing 241
 
242
    public void setItemUpdateListener(ItemUpdateListener itemUpdatelistener) {
243
        this.itemUpdateListener = itemUpdatelistener;
244
    }
245
 
246
    @UiHandler("submit")
247
    void onSubmitPressed(ClickEvent clickEvent) {
248
        try {
2068 ankur.sing 249
            updateItem();
2066 ankur.sing 250
            if(!isItemChanged()) {
251
                Window.alert("Nothing to update. Please change intended item parameters and try again.");
252
                return;
253
            }
2068 ankur.sing 254
 
2066 ankur.sing 255
            if(!validatePrices()) {
256
                return;
257
            }
2105 ankur.sing 258
            //updateItem();  -- Calling this method above. A new item is created with updated data.
2066 ankur.sing 259
        } catch(NumberFormatException ex) {
260
            return;
261
        }
262
        itemUpdateListener.onItemUpdate(newItem);
2027 ankur.sing 263
        GWT.log("Item updated. Id = " + item.getId());
2066 ankur.sing 264
        item = newItem;
265
    }
266
 
267
    private void updateItem() throws NumberFormatException {
268
        newItem = new Item();
269
        newItem.setId(Long.parseLong(itemId.getText()));
270
        newItem.setProductGroup(productGroup.getText().trim());
271
        newItem.setBrand(brand.getText().trim());
272
        newItem.setModelNumber(modelNumber.getText().trim());
273
        newItem.setModelName(modelName.getText().trim());
274
        newItem.setColor(color.getText().trim());
2105 ankur.sing 275
        newItem.setContentCategory(Long.parseLong(contentCategory.getText()));
2066 ankur.sing 276
        newItem.setComments(comments.getText().trim());
277
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
278
        newItem.setFeatureId(item.getFeatureId());
279
        newItem.setFeatureDescription(item.getFeatureDescription());
2068 ankur.sing 280
        try {
281
            newItem.setMrp(Double.parseDouble(mrp.getText().trim()));
282
        } catch(NumberFormatException ex) {
283
            Window.alert("Invalid MRP format");
284
            throw new NumberFormatException();
285
        }
286
        try {
287
            newItem.setSellingPrice(Double.parseDouble(sellingPrice.getText().trim()));
288
        }
289
        catch(NumberFormatException ex) {
290
            Window.alert("Invalid Selling Price format");
291
            throw new NumberFormatException();
292
        }
293
        try {
294
            newItem.setWeight(Double.parseDouble(weight.getText().trim()));
295
        } catch(NumberFormatException ex) {
296
            Window.alert("Invalid Weight format");
297
            throw new NumberFormatException();
298
        }
2066 ankur.sing 299
        newItem.setAddedOn(item.getAddedOn());
2068 ankur.sing 300
        newItem.setStartDate(startDate.getValue().getTime());
2066 ankur.sing 301
        newItem.setRetireDate(item.getRetireDate());
302
        newItem.setUpdatedOn(item.getUpdatedOn());
303
        newItem.setItemStatus(item.getItemStatus());
304
        newItem.setOtherInfo(item.getOtherInfo());
305
        newItem.setBestDealsText(bestDealsText.getText().trim());
2068 ankur.sing 306
        try {
307
            newItem.setBestDealsValue(Double.parseDouble(bestDealsValue.getText().trim()));
308
        } catch(NumberFormatException ex) {
309
            Window.alert("Invalid Best Deals Value format");
310
            throw new NumberFormatException();
311
        }
312
        try {
313
            newItem.setBestSellingRank(Long.parseLong(bestSellingRank.getText().trim()));
314
        } catch (NumberFormatException ex) {
315
            Window.alert("Invalid Best Selling Rank format");
316
            throw new NumberFormatException();
317
        }
318
 
2066 ankur.sing 319
        newItem.setDefaultForEntity(defaultForEntity.getValue());
320
        newItem.setAvailability(item.getAvailability());
2105 ankur.sing 321
        Map<Long, VendorDetails> vendorDetails = new HashMap<Long, VendorDetails>();
322
        VendorDetails v;
323
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
324
            v = new VendorDetails();
325
            v.setItemKey(vendorTable.getText(row, TABLE_INDEX_ITEM_KEY));
326
            v.setMop(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP)));
327
            v.setDealerPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP)));
328
            v.setTransferPrice(Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP)));
329
            v.setVendorId(Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID)));
330
            vendorDetails.put(v.getVendorId(), v);
331
            newItem.setMop(v.getMop());
332
            newItem.setDealerPrice(v.getDealerPrice());
333
            newItem.setTransferPrice(v.getTransferPrice());
2066 ankur.sing 334
        }
2105 ankur.sing 335
        newItem.setVendorDetails(vendorDetails);
2027 ankur.sing 336
 
2066 ankur.sing 337
        /*item.setProductGroup(productGroup.getText().trim());
338
        item.setBrand(brand.getText().trim());
339
        item.setModelName(modelName.getText().trim());
340
        item.setModelNumber(modelNumber.getText().trim());
341
        item.setColor(color.getText().trim());
342
        item.setComments(comments.getText().trim());
343
        item.setMrp(Double.parseDouble(this.mrp.getText()));
344
        item.setSellingPrice(Double.parseDouble(this.sellingPrice.getText()));
345
        item.setWeight(Double.parseDouble(this.weight.getText()));
346
        item.setBestDealsText(bestDealsText.getText().trim());
347
        item.setBestDealsValue(Double.parseDouble(bestDealsValue.getText().trim()));
348
        item.setBestSellingRank(Long.parseLong(bestSellingRank.getText().trim()));
349
        item.setDefaultForEntity(defaultForEntity.getValue());
350
        for(int row = 0; row < pricingTable.getRowCount(); row++) {
351
            long vendorId = Long.parseLong(pricingTable.getText(row, TABLE_INDEX_VENDORID));
352
            double mop = Double.parseDouble(pricingTable.getText(row, TABLE_INDEX_MOP));
353
            double dp = Double.parseDouble(pricingTable.getText(row, TABLE_INDEX_DP));
354
            double tp = Double.parseDouble(pricingTable.getText(row, TABLE_INDEX_TP));
355
            item.getVendorPricings().get(vendorId)[Item.INDEX_MOP] = mop;
356
            item.getVendorPricings().get(vendorId)[Item.INDEX_DP] = dp;
357
            item.getVendorPricings().get(vendorId)[Item.INDEX_TP] = tp;
358
            item.setMop(mop);
359
            item.setDealerPrice(dp);
360
            item.setTransferPrice(tp);
361
        }*/
362
    }
363
 
364
    private void updateVendorPrices(final long vendorId, final int row) {
2105 ankur.sing 365
        String mop = vendorTable.getText(row, TABLE_INDEX_MOP);
366
        String dp = vendorTable.getText(row, TABLE_INDEX_DP);
367
        String tp = vendorTable.getText(row, TABLE_INDEX_TP);
368
        String key = vendorTable.getText(row, TABLE_INDEX_ITEM_KEY);
369
        VendorPricesDialog pricesDialog = new VendorPricesDialog(key, mop, dp, tp);
370
        pricesDialog.updateButton.setText("Update");
371
        pricesDialog.setVendorDetailsUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 372
            @Override
2105 ankur.sing 373
            public boolean onUpdate(String itemKey, double mop, double dp, double tp, long vendorId) {
374
                if(!validateVendorDetails(itemKey, mop, dp, tp)) {
375
                    return false;
376
                }
377
                vendorTable.setText(row, TABLE_INDEX_ITEM_KEY, itemKey);
378
                vendorTable.setText(row, TABLE_INDEX_MOP, mop + "");
379
                vendorTable.setText(row, TABLE_INDEX_DP, dp + "");
380
                vendorTable.setText(row, TABLE_INDEX_TP, tp + "");
381
                return true;
2066 ankur.sing 382
            }
383
        });
384
        pricesDialog.show();
385
    }
386
 
387
    private boolean isItemChanged() {
388
        if(!productGroup.getText().trim().equals(item.getProductGroup())) {
389
            return true;
390
        }
391
        if(!brand.getText().trim().equals(item.getBrand())) {
392
            return true;
393
        }
394
        if(!modelNumber.getText().trim().equals(item.getModelNumber())) {
395
            return true;
396
        }
397
        if(!modelName.getText().trim().equals(item.getModelName())) {
398
            return true;
399
        }
400
        if(!color.getText().trim().equals(item.getColor())) {
401
            return true;
402
        }
403
        if(!comments.getText().trim().equals(item.getComments())) {
404
            return true;
405
        }
406
        try {
407
            if(item.getMrp() != Double.parseDouble(mrp.getText().trim())) {
408
                return true;
409
            }
410
        } catch(NumberFormatException ex) {
411
            Window.alert("Invalid MRP format");
412
            throw new NumberFormatException();
413
        }
414
        try {
415
            if(item.getSellingPrice() != Double.parseDouble(sellingPrice.getText().trim())) {
416
                return true;
417
            }
418
        } catch(NumberFormatException ex) {
2027 ankur.sing 419
            Window.alert("Invalid Selling Price format");
420
            throw new NumberFormatException();
421
        }
2066 ankur.sing 422
        try {
423
            if(item.getWeight() != Double.parseDouble(weight.getText().trim())) {
424
                return true;
425
            }
426
        } catch(NumberFormatException ex) {
2027 ankur.sing 427
            Window.alert("Invalid Weight format");
428
            throw new NumberFormatException();
429
        }
2066 ankur.sing 430
        if(!bestDealsText.getText().trim().equals(item.getBestDealsText())) {
431
            return true;
432
        }
433
        try {
434
            if(item.getBestDealsValue() != Double.parseDouble(bestDealsValue.getText().trim())) {
435
                return true;
436
            }
437
        } catch(NumberFormatException ex) {
2027 ankur.sing 438
            Window.alert("Invalid Best Deals Value format");
439
            throw new NumberFormatException();
440
        }
2066 ankur.sing 441
        try{
442
            if(item.getBestSellingRank() != Long.parseLong(bestSellingRank.getText().trim())) {
443
                return true;
1992 ankur.sing 444
            }
2066 ankur.sing 445
        } catch (NumberFormatException ex) {
446
            Window.alert("Invalid Best Selling Rank format");
447
            throw new NumberFormatException();
448
        }
449
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
450
            return true;
451
        }
2068 ankur.sing 452
 
453
        if(newItem.getStartDate() != item.getStartDate()) {
454
            return true;
455
        }
2066 ankur.sing 456
 
2105 ankur.sing 457
        VendorDetails vendorDetails;
2066 ankur.sing 458
        long vendorId;
2105 ankur.sing 459
        for(int row = 0; row < vendorTable.getRowCount(); row++) {
460
            vendorId = Long.parseLong(vendorTable.getText(row, TABLE_INDEX_VENDORID));
461
            vendorDetails = item.getVendorDetails().get(vendorId);
462
            if(vendorDetails.getMop() != Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_MOP))) {
2066 ankur.sing 463
                return true;
464
            }
2105 ankur.sing 465
            if(vendorDetails.getDealerPrice() != Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_DP))) {
2066 ankur.sing 466
                return true;
467
            }
2105 ankur.sing 468
            if(vendorDetails.getTransferPrice() != Double.parseDouble(vendorTable.getText(row, TABLE_INDEX_TP))) {
2066 ankur.sing 469
                return true;
470
            }
471
        }
472
        return false;
473
    }
474
 
475
    private boolean validatePrices() {
476
        if(newItem.getSellingPrice() > newItem.getMrp()) {
477
            Window.alert("Selling price cannot be more than MRP");
478
            return false;
479
        }
2105 ankur.sing 480
        for(VendorDetails v : newItem.getVendorDetails().values()) {
481
            if(newItem.getMrp() < v.getMop()) {
482
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 483
                return false;
484
            }
2105 ankur.sing 485
            if(v.getTransferPrice() > v.getMop()) {
486
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 487
                return false;
488
            }
489
        }
490
        return true;
491
    }
2105 ankur.sing 492
 
493
    private boolean validateVendorDetails(String key, double mop, double dp, double tp) {
494
        if(key == null || key.isEmpty()) {
495
            Window.alert("Item key cannot be empty");
496
            return false;
1992 ankur.sing 497
        }
2105 ankur.sing 498
        if(item.getMrp() < mop) {
499
            Window.alert("MOP cannot be more than MRP.");
500
            return false;
1992 ankur.sing 501
        }
2105 ankur.sing 502
        if(tp > mop) {
503
            Window.alert("Transfer Price cannot be more than MOP.");
504
            return false;
1992 ankur.sing 505
        }
2105 ankur.sing 506
        return true;
1992 ankur.sing 507
    }
2105 ankur.sing 508
 
509
    public long getItemId() {
510
        return item == null ? 0 : item.getId();
511
    }
512
 
513
    public Item getItem() {
514
        return item;
515
    }
516
 
517
    private boolean vendorExists(long vendorId) {
518
        long id;
519
        for(int i = 0; i < vendorTable.getRowCount(); i++) {
520
            id = Long.parseLong(vendorTable.getText(i, TABLE_INDEX_VENDORID));
521
            if(vendorId == id) {
522
                return false;
523
            }
1992 ankur.sing 524
        }
2105 ankur.sing 525
        return true;
1992 ankur.sing 526
    }
1961 ankur.sing 527
}