Subversion Repositories SmartDukaan

Rev

Rev 3362 | Rev 3524 | 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;
2119 ankur.sing 5
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
6
import in.shop2020.catalog.dashboard.shared.VendorPricings;
1961 ankur.sing 7
 
8
import java.util.Date;
2066 ankur.sing 9
import java.util.HashMap;
1992 ankur.sing 10
import java.util.Map;
11
import java.util.Map.Entry;
1961 ankur.sing 12
 
13
import com.google.gwt.core.client.GWT;
14
import com.google.gwt.event.dom.client.ClickEvent;
1992 ankur.sing 15
import com.google.gwt.event.dom.client.ClickHandler;
16
import com.google.gwt.resources.client.CssResource;
1961 ankur.sing 17
import com.google.gwt.uibinder.client.UiBinder;
18
import com.google.gwt.uibinder.client.UiField;
19
import com.google.gwt.user.client.Window;
2126 ankur.sing 20
import com.google.gwt.user.client.rpc.AsyncCallback;
1961 ankur.sing 21
import com.google.gwt.user.client.ui.Button;
2066 ankur.sing 22
import com.google.gwt.user.client.ui.CheckBox;
1992 ankur.sing 23
import com.google.gwt.user.client.ui.FlexTable;
24
import com.google.gwt.user.client.ui.HTMLTable.Cell;
1961 ankur.sing 25
import com.google.gwt.user.client.ui.Label;
26
import com.google.gwt.user.client.ui.ResizeComposite;
27
import com.google.gwt.user.client.ui.TextBox;
28
import com.google.gwt.user.client.ui.Widget;
2068 ankur.sing 29
import com.google.gwt.user.datepicker.client.DateBox;
1961 ankur.sing 30
 
2427 ankur.sing 31
/**
32
 * Panel contains fields for item details. Some of these fields are editable.
33
 * It also contains vendor item pricings, vendor item keys, and item availability in tabular format.
34
 * Item availability is made invisible for time being 
35
 */
1961 ankur.sing 36
public class ItemDetails extends ResizeComposite {
37
 
2359 ankur.sing 38
    private final int TABLE_INDEX_MAPPING_VENDOR_DESC = 0, 
39
                      TABLE_INDEX_MAPPING_ITEM_KEY = 1,
40
                      TABLE_INDEX_MAPPING_BUTTON = 2,
41
                      TABLE_INDEX_MAPPING_VENDORID = 3, 
42
                      TABLE_INDEX_MAPPING_ITEM_KEY_OLD = 4;
43
 
44
    private final int TABLE_INDEX_PRICING_VENDOR_DESC = 0, 
45
                      TABLE_INDEX_PRICING_MOP = 1,
46
                      TABLE_INDEX_PRICING_DP = 2,
47
                      TABLE_INDEX_PRICING_TP = 3,
48
                      TABLE_INDEX_PRICING_BUTTON = 4,
49
                      TABLE_INDEX_PRICING_VENDORID = 5;
50
 
2119 ankur.sing 51
    private final int TABLE_INDEX_WAREHOUSE_ID = 0,
52
                      TABLE_INDEX_WAREHOUSE_DESC = 1,
53
                      TABLE_INDEX_WAREHOUSE_INV = 2;
2359 ankur.sing 54
 
55
    private final String PRICE_WIDTH = "100px", VENDOR_DESC_WIDTH = "130px",
56
                         VENDOR_ID_WIDTH = "100px", ITEM_KEY_WIDTH = "200px",
57
                         BUTTON_WIDTH = "50px";
2066 ankur.sing 58
 
59
    interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
60
    private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
2126 ankur.sing 61
    private final CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
2066 ankur.sing 62
 
1961 ankur.sing 63
 
2066 ankur.sing 64
    interface ItemDetailStyle extends CssResource{
65
        String greenLabel();
66
        String fieldChanged();
67
    }
1961 ankur.sing 68
 
2105 ankur.sing 69
    private Item item, newItem;
2489 ankur.sing 70
    private CatalogDashboard catalogDashboardPanel;
2066 ankur.sing 71
 
72
    @UiField ItemDetailStyle style;
73
    @UiField Label itemId;
74
    @UiField TextBox productGroup, brand, modelNumber, modelName, color;
2105 ankur.sing 75
    @UiField Label contentCategory, catalogItemId;
2359 ankur.sing 76
    @UiField TextBox statusDesc, comments;
2105 ankur.sing 77
    @UiField TextBox sellingPrice, mrp, weight;
78
    @UiField Label addedOn, retireDate, updatedOn;
2066 ankur.sing 79
    @UiField Label itemStatus;
80
    @UiField TextBox bestDealsText, bestDealsValue; 
81
    @UiField FlexTable headerAvailability, availabilityTable;
2427 ankur.sing 82
    @UiField FlexTable headerVendorItemKey, tableVendorItemKey;
83
    @UiField FlexTable headerVendorPrices, tableVendorPrices;
2066 ankur.sing 84
    @UiField TextBox bestSellingRank;
3359 chandransh 85
    @UiField TextBox expectedDelay;
86
    @UiField TextBox preferredWarehouse;
2252 ankur.sing 87
    @UiField CheckBox defaultForEntity, risky;
2068 ankur.sing 88
    @UiField DateBox startDate;
2066 ankur.sing 89
 
90
    public ItemDetails(Item item){
2105 ankur.sing 91
        this();
2066 ankur.sing 92
        setItemDetails(item);
93
    }
94
 
95
    public ItemDetails() {
96
        initWidget(uiBinder.createAndBindUi(this));
97
        initAvailabilityHeader();
2427 ankur.sing 98
        initVendorKeysHeader();
99
        initVendorPricingHeader();
2119 ankur.sing 100
 
2105 ankur.sing 101
        headerAvailability.setVisible(false);
102
        availabilityTable.setVisible(false);
2066 ankur.sing 103
    }
104
 
2427 ankur.sing 105
    /**
106
     * Sets the UI fields with item object attributes
107
     * Also populates tables for vendor prices, keys and item availability
108
     * @param item
109
     */
2066 ankur.sing 110
    public void setItemDetails(Item item){
111
        this.item = item;
112
        itemId.setText(item.getId()+"");
113
        productGroup.setText(item.getProductGroup());
114
        brand.setText(item.getBrand());
115
        modelNumber.setText(item.getModelNumber());
116
        modelName.setText(item.getModelName());
117
        color.setText(item.getColor());
118
 
2359 ankur.sing 119
        statusDesc.setText(item.getItemStatusDesc());
2105 ankur.sing 120
        contentCategory.setText(item.getContentCategory()+"");
2066 ankur.sing 121
        comments.setText(item.getComments());
122
        catalogItemId.setText(item.getCatalogItemId() + "");
123
 
2489 ankur.sing 124
        mrp.setText(item.getMrp() != null ? item.getMrp()+"" : "");
125
        sellingPrice.setText(item.getSellingPrice() != null ? item.getSellingPrice()+"" : "");
126
        weight.setText(item.getWeight() != null ? item.getWeight()+"" : "");
3359 chandransh 127
        expectedDelay.setValue(item.getExpectedDelay()+"");
128
        preferredWarehouse.setValue(item.getPreferredWarehouse()+"");
2068 ankur.sing 129
 
130
        startDate.setValue(new Date(item.getStartDate()));
131
        addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
132
        retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
133
        updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
1992 ankur.sing 134
 
2066 ankur.sing 135
        bestDealsText.setText(item.getBestDealsText());
2489 ankur.sing 136
        bestDealsValue.setText(item.getBestDealsValue() != null ? item.getBestDealsValue()+"" : "");
137
        bestSellingRank.setText(item.getBestSellingRank() != null ? item.getBestSellingRank()+"" : "");
2066 ankur.sing 138
        defaultForEntity.setValue(item.isDefaultForEntity());
2252 ankur.sing 139
        risky.setValue(item.isRisky());
1992 ankur.sing 140
 
2066 ankur.sing 141
        itemStatus.setText(item.getItemStatus());
142
 
143
        updateAvailabilityTable(item.getAvailability());
2427 ankur.sing 144
        updateVendorKeysTable(item.getVendorKeysMap());
145
        updateVendorPricingTable(item.getVendorPricesMap());
1992 ankur.sing 146
    }
2066 ankur.sing 147
 
2427 ankur.sing 148
    /**
149
     * initialise item availability table header.
150
     */
2066 ankur.sing 151
    private void initAvailabilityHeader(){
152
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
2105 ankur.sing 153
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
2066 ankur.sing 154
        headerAvailability.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
155
 
156
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_ID, "Warehouse Id");
157
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_DESC, "Warehouse Desc");
158
        headerAvailability.setText(0, TABLE_INDEX_WAREHOUSE_INV, "Availability");
1992 ankur.sing 159
 
160
    }
2066 ankur.sing 161
 
2427 ankur.sing 162
    /**
163
     * initialises vendor item key table header. Creates an Add button and
164
     * adds click event listener to it to create and pop up a dialog for adding 
165
     * a new vendor item key. 
166
     */
167
    private void initVendorKeysHeader(){
168
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
169
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
170
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
171
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
172
        headerVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2119 ankur.sing 173
 
2427 ankur.sing 174
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDORID, "Vendor Id");
175
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_VENDOR_DESC, "Vendor");
176
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY, "Item Key");
177
        headerVendorItemKey.setText(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, "Prev Item Key");
2119 ankur.sing 178
 
2427 ankur.sing 179
        headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_VENDORID, false);
180
        headerVendorItemKey.getCellFormatter().setVisible(0, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 181
 
2119 ankur.sing 182
        Button addButton = new Button("Add");
2427 ankur.sing 183
        headerVendorItemKey.setWidget(0, TABLE_INDEX_MAPPING_BUTTON, addButton);
2119 ankur.sing 184
        addButton.addClickHandler(new ClickHandler() {
185
            @Override
186
            public void onClick(ClickEvent event) {
2126 ankur.sing 187
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
188
                        modelNumber.getText().trim(), color.getText().trim());
2119 ankur.sing 189
                vendorMappingDialog.updateButton.setText("Add");
190
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
191
                    @Override
192
                    public boolean onUpdate(String key, long vendorId) {
2427 ankur.sing 193
                        int row = tableVendorItemKey.getRowCount();
194
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
195
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
196
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
197
                        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
2119 ankur.sing 198
 
2427 ankur.sing 199
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDORID, vendorId + "");
200
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
201
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, key);
202
                        tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, key);
2359 ankur.sing 203
 
2427 ankur.sing 204
                        tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_VENDORID, false);
205
                        tableVendorItemKey.getCellFormatter().setVisible(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2119 ankur.sing 206
                        return true;
207
                    }
208
                });
209
                vendorMappingDialog.show();
210
            }
211
        });
212
    }
213
 
2427 ankur.sing 214
    /**
215
     * initialises vendor prices table header. Creates an Add button and
216
     * adds click event listener to it to create and pop up a dialog for adding 
217
     * a prices for a new vendor 
218
     */
219
    private void initVendorPricingHeader(){
220
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
221
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
222
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
223
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
224
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
225
        headerVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 226
 
2427 ankur.sing 227
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDORID, "Vendor Id");
228
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_VENDOR_DESC, "Vendor");
229
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_MOP, "MOP");
230
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_DP, "Dealer Price");
231
        headerVendorPrices.setText(0, TABLE_INDEX_PRICING_TP, "Transfer Price");
2105 ankur.sing 232
 
2427 ankur.sing 233
        headerVendorPrices.getCellFormatter().setVisible(0, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 234
 
2105 ankur.sing 235
        Button addButton = new Button("Add");
2427 ankur.sing 236
        headerVendorPrices.setWidget(0, TABLE_INDEX_PRICING_BUTTON, addButton);
2105 ankur.sing 237
        addButton.addClickHandler(new ClickHandler() {
238
            @Override
239
            public void onClick(ClickEvent event) {
2119 ankur.sing 240
                VendorPricesDialog vendorPricesDialog = new VendorPricesDialog();
241
                vendorPricesDialog.updateButton.setText("Add");
242
                vendorPricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2105 ankur.sing 243
                    @Override
2119 ankur.sing 244
                    public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
2105 ankur.sing 245
                        if(!vendorExists(vendorId)) {
246
                            Window.alert("Vendor already exists");
247
                            return false;
248
                        }
2119 ankur.sing 249
                        /*if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 250
                            return false;
2119 ankur.sing 251
                        }*/
2427 ankur.sing 252
                        int row = tableVendorPrices.getRowCount();
253
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
254
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
255
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
256
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
257
                        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
2105 ankur.sing 258
 
2427 ankur.sing 259
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDORID, vendorId + "");
260
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorId));
261
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
262
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
263
                        tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2359 ankur.sing 264
 
2427 ankur.sing 265
                        tableVendorPrices.getCellFormatter().setVisible(row, TABLE_INDEX_PRICING_VENDORID, false);
2105 ankur.sing 266
                        return true;
267
                    }
268
                });
2119 ankur.sing 269
                vendorPricesDialog.show();
2105 ankur.sing 270
            }
271
        });
2066 ankur.sing 272
    }
2105 ankur.sing 273
 
2427 ankur.sing 274
    /**
275
     * Clear and populate item availability table.
276
     * @param availabilityMap
277
     */
1992 ankur.sing 278
    private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
279
        availabilityTable.removeAllRows();
280
        if(availabilityMap == null) {
281
            return;
282
        }
2066 ankur.sing 283
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_ID, "128px");
2105 ankur.sing 284
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_DESC, "300px");
2066 ankur.sing 285
        availabilityTable.getColumnFormatter().setWidth(TABLE_INDEX_WAREHOUSE_INV, "128px");
286
 
1992 ankur.sing 287
        int i=0;
288
        for(Entry<Long, Long> availability : availabilityMap.entrySet()){
2066 ankur.sing 289
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_ID, availability.getKey() + "");
290
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_DESC, Utils.getWarehouseDesc(availability.getKey()));
291
            availabilityTable.setText(i, TABLE_INDEX_WAREHOUSE_INV, availability.getValue() + "");
1992 ankur.sing 292
            i++;
293
        }
294
    }
2119 ankur.sing 295
 
2427 ankur.sing 296
    /**
297
     * Clear and populate vendor item key table with keys in the passed argument.
298
     * With each row in the table, an edit button is created and click event listener 
299
     * is added to it to edit that vendor item key row.
300
     * @param vendorKeysMap
301
     */
302
    private void updateVendorKeysTable(Map<String, VendorItemMapping> vendorKeysMap){
303
        tableVendorItemKey.removeAllRows();
2119 ankur.sing 304
 
2427 ankur.sing 305
        if(vendorKeysMap == null || vendorKeysMap.isEmpty()) {
2119 ankur.sing 306
            return;
307
        }
2427 ankur.sing 308
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDORID, VENDOR_ID_WIDTH);
309
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_VENDOR_DESC, VENDOR_DESC_WIDTH);
310
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY, ITEM_KEY_WIDTH);
311
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_ITEM_KEY_OLD, ITEM_KEY_WIDTH);
312
        tableVendorItemKey.getColumnFormatter().setWidth(TABLE_INDEX_MAPPING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 313
 
2119 ankur.sing 314
        int i=0;
2427 ankur.sing 315
        for(Entry<String, VendorItemMapping> e : vendorKeysMap.entrySet()){
2359 ankur.sing 316
            VendorItemMapping vendorMapping = e.getValue();
2427 ankur.sing 317
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDORID, vendorMapping.getVendorId() + "");
318
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_VENDOR_DESC, Utils.getVendorDesc(vendorMapping.getVendorId()));
319
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY, vendorMapping.getItemKey());
320
            tableVendorItemKey.setText(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, e.getKey().substring(e.getKey().indexOf(Item.KEY_SEPARATOR)+1));
2119 ankur.sing 321
            Button editButton = new Button("Edit");
2427 ankur.sing 322
            tableVendorItemKey.setWidget(i, TABLE_INDEX_MAPPING_BUTTON, editButton);
2119 ankur.sing 323
            editButton.addClickHandler(new ClickHandler() {
324
                @Override
325
                public void onClick(ClickEvent event) {
2427 ankur.sing 326
                    Cell cell = tableVendorItemKey.getCellForEvent(event);
2119 ankur.sing 327
                    int row = cell.getRowIndex();
2427 ankur.sing 328
                    long vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
329
                    editVendorKey(vendorId, row);
2119 ankur.sing 330
                }
331
            });
2427 ankur.sing 332
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_VENDORID, false);
333
            tableVendorItemKey.getCellFormatter().setVisible(i, TABLE_INDEX_MAPPING_ITEM_KEY_OLD, false);
2359 ankur.sing 334
            i++;
2119 ankur.sing 335
        }
336
    }
337
 
2427 ankur.sing 338
    /**
339
     * Clear and populate vendor prices table with prices in the passed argument.
340
     * With each row in the table, an edit button is created and click event listener 
341
     * is added to it to edit that vendor prices row.
342
     * @param vendorPricingMap
343
     */
344
    private void updateVendorPricingTable(Map<Long, VendorPricings> vendorPricingMap){
345
        tableVendorPrices.removeAllRows();
2105 ankur.sing 346
 
2119 ankur.sing 347
        if(vendorPricingMap == null || vendorPricingMap.isEmpty()) {
1992 ankur.sing 348
            return;
349
        }
2427 ankur.sing 350
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDORID, VENDOR_ID_WIDTH);
351
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_VENDOR_DESC, VENDOR_DESC_WIDTH);
352
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_MOP, PRICE_WIDTH);
353
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_DP, PRICE_WIDTH);
354
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_TP, PRICE_WIDTH);
355
        tableVendorPrices.getColumnFormatter().setWidth(TABLE_INDEX_PRICING_BUTTON, BUTTON_WIDTH);
2066 ankur.sing 356
 
357
 
1992 ankur.sing 358
        int i=0;
2119 ankur.sing 359
        for(VendorPricings vendorDetail : vendorPricingMap.values()){
2427 ankur.sing 360
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDORID, vendorDetail.getVendorId() + "");
361
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_VENDOR_DESC, Utils.getVendorDesc(vendorDetail.getVendorId()));
362
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_MOP, vendorDetail.getMop() + "");
363
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_DP, vendorDetail.getDealerPrice() + "");
364
            tableVendorPrices.setText(i, TABLE_INDEX_PRICING_TP, vendorDetail.getTransferPrice() + "");
1992 ankur.sing 365
            Button editButton = new Button("Edit");
2427 ankur.sing 366
            tableVendorPrices.setWidget(i, TABLE_INDEX_PRICING_BUTTON, editButton);
1992 ankur.sing 367
            editButton.addClickHandler(new ClickHandler() {
368
                @Override
369
                public void onClick(ClickEvent event) {
2427 ankur.sing 370
                    Cell cell = tableVendorPrices.getCellForEvent(event);
1992 ankur.sing 371
                    int row = cell.getRowIndex();
2427 ankur.sing 372
                    long vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
373
                    editVendorPrices(vendorId, row);
1992 ankur.sing 374
                }
375
            });
2427 ankur.sing 376
            tableVendorPrices.getCellFormatter().setVisible(i, TABLE_INDEX_PRICING_VENDORID, false);
2359 ankur.sing 377
            i++;
1992 ankur.sing 378
        }
379
    }
2066 ankur.sing 380
 
2427 ankur.sing 381
    /**
382
     * called on the click event of update item button in ItemActions
383
     */
2126 ankur.sing 384
    void updateItem() {
385
        if(item == null) {
386
            Window.alert("Please select an item to update.");
387
            return;
388
        }
2066 ankur.sing 389
        try {
2126 ankur.sing 390
            if(!createNewItem()) {
391
                return;
392
            }
2252 ankur.sing 393
            String paramsChanged = isItemChanged();
394
            if(paramsChanged.equals("")) {
2066 ankur.sing 395
                Window.alert("Nothing to update. Please change intended item parameters and try again.");
396
                return;
2252 ankur.sing 397
            } else {
398
                paramsChanged = "You have changed following items.\n" + paramsChanged;
399
                Window.alert(paramsChanged);
2066 ankur.sing 400
            }
401
        } catch(NumberFormatException ex) {
2126 ankur.sing 402
            ex.printStackTrace();
403
            GWT.log("Number format exception");
404
        }
405
        if(!Utils.validateItem(newItem)) {
2066 ankur.sing 406
            return;
407
        }
2126 ankur.sing 408
 
409
        /*if(!validatePrices()) {
410
            return;
411
        }*/
412
        catalogService.updateItem(newItem, new AsyncCallback<Boolean>() {
413
            @Override
414
            public void onSuccess(Boolean result) {
415
                if(result) {
416
                    item = newItem;
417
                    GWT.log("Item updated. Id = " + item.getId());
2489 ankur.sing 418
                    catalogDashboardPanel.getItemListWidget().updateItem(item);
419
                    getFreshItemFromDB(item.getId());
2126 ankur.sing 420
                    Window.alert("Item updated successfully.");
421
                }
422
                else {
423
                    GWT.log("Error updating item");
424
                    Window.alert("Error updating item");
425
                }
426
            }
427
            @Override
428
            public void onFailure(Throwable caught) {
429
                caught.printStackTrace();
430
                Window.alert("Error while updating item");
431
            }
432
        });
2066 ankur.sing 433
    }
2126 ankur.sing 434
 
2489 ankur.sing 435
    private void getFreshItemFromDB(long id) {
436
        catalogService.getItem(id, new AsyncCallback<Item>() {
437
            @Override
438
            public void onSuccess(Item result) {
439
                setItemDetails(result);
440
            }
441
            @Override
442
            public void onFailure(Throwable caught) {
443
                caught.printStackTrace();
444
                Window.alert("Unable to fetch item details.");
445
            }
446
        });
447
    }
448
 
2427 ankur.sing 449
    /**
450
     * This method is called while updating item.<br> It will create a new Item object and set 
451
     * its editable attributes with UI fields values and non-editable attributes with old Item
452
     * object attributes. This new Item object is then passed to the service to update item in the database.
453
     * <br>If update is successful, the old Item object is replaced with the new Item object. 
454
     * @return true if new Item object is created successfully
455
     *     <br>false if some error occurs due to NumberFormatException
456
     */
2126 ankur.sing 457
    private boolean createNewItem() {
2066 ankur.sing 458
        newItem = new Item();
2489 ankur.sing 459
        newItem.setId(item.getId());
460
        newItem.setVendorCategory(item.getVendorCategory());
2066 ankur.sing 461
        newItem.setProductGroup(productGroup.getText().trim());
462
        newItem.setBrand(brand.getText().trim());
463
        newItem.setModelNumber(modelNumber.getText().trim());
464
        newItem.setModelName(modelName.getText().trim());
465
        newItem.setColor(color.getText().trim());
2119 ankur.sing 466
        newItem.setContentCategory(contentCategory.getText());
2066 ankur.sing 467
        newItem.setComments(comments.getText().trim());
468
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
2126 ankur.sing 469
 
2068 ankur.sing 470
        try {
2126 ankur.sing 471
            if(!mrp.getText().trim().isEmpty()) {
472
                double mrpValue = Double.parseDouble(mrp.getText().trim());
473
                if(mrpValue <= 0) {
474
                    throw new NumberFormatException("Negative value of MRP");
475
                }
476
                newItem.setMrp(mrpValue);
477
            }
2068 ankur.sing 478
        } catch(NumberFormatException ex) {
2126 ankur.sing 479
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
480
            return false;
2068 ankur.sing 481
        }
482
        try {
2126 ankur.sing 483
            if(!sellingPrice.getText().trim().isEmpty()) {
484
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
485
            if(spValue <= 0) {
486
                throw new NumberFormatException("Negative value of Selling price");
487
            }
488
            newItem.setSellingPrice(spValue);
489
            }
490
        } catch(NumberFormatException ex) {
491
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
492
            return false;
2068 ankur.sing 493
        }
494
        try {
2126 ankur.sing 495
            if(!weight.getText().trim().isEmpty()) {
496
                double wtValue = Double.parseDouble(weight.getText().trim());
497
                if(wtValue <= 0) {
498
                    throw new NumberFormatException("Negative value of Weight");
499
                }
500
                newItem.setWeight(wtValue);
501
            }
2068 ankur.sing 502
        } catch(NumberFormatException ex) {
2126 ankur.sing 503
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
504
            return false;
2068 ankur.sing 505
        }
2126 ankur.sing 506
        try {
507
            if(!startDate.getTextBox().getText().trim().equals("")) {
508
                newItem.setStartDate(startDate.getValue().getTime());
509
            }
510
        } catch(Exception ex) {
511
            Window.alert("Invalid start date format");
512
            return false;
513
        }
2066 ankur.sing 514
        newItem.setBestDealsText(bestDealsText.getText().trim());
2068 ankur.sing 515
        try {
2126 ankur.sing 516
            if(!bestDealsValue.getText().trim().equals("")) {
517
                double bdValue = Double.parseDouble(bestDealsValue.getText().trim());
518
                if(bdValue < 0) {
519
                    throw new NumberFormatException("Negative value of BestDealValue");
520
                }
521
                newItem.setBestDealsValue(bdValue);
522
            }
2068 ankur.sing 523
        } catch(NumberFormatException ex) {
2126 ankur.sing 524
            Window.alert("Invalid best deal value format");
525
            return false;
2068 ankur.sing 526
        }
3363 chandransh 527
 
2068 ankur.sing 528
        try {
2126 ankur.sing 529
            if(!bestSellingRank.getText().trim().equals("")) {
530
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
531
                if(bsrValue < 0) {
532
                    throw new NumberFormatException("Negative value of Best Selling Rank");
533
                }
534
                newItem.setBestSellingRank(bsrValue);
535
            }
536
        } catch(NumberFormatException ex) {
537
            Window.alert("Invalid best selling rank format");
538
            return false;
2068 ankur.sing 539
        }
2066 ankur.sing 540
        newItem.setDefaultForEntity(defaultForEntity.getValue());
2252 ankur.sing 541
        newItem.setRisky(risky.getValue());
2119 ankur.sing 542
 
3363 chandransh 543
        try {
544
            String expectedDelayText = expectedDelay.getText().trim();
545
            if(!expectedDelayText.equals("")){
546
                newItem.setExpectedDelay(Integer.parseInt(expectedDelayText));
547
            }
548
        } catch(NumberFormatException nfe) {
549
            Window.alert("Invalid expected delay");
550
            return false;
551
        }
552
 
553
        try {
554
            String preferredWarehouseText = preferredWarehouse.getText().trim();
555
            if(!preferredWarehouseText.equals("")){
556
                newItem.setPreferredWarehouse(Long.parseLong(preferredWarehouseText) + "");
557
            }
558
        }catch(NumberFormatException nfe){
559
            Window.alert("Invalid Preferred Warehouse");
560
            return false;
561
        }
562
 
2126 ankur.sing 563
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
564
          Add the instance to map and set the map to the item instance created above.*/
565
        Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
2119 ankur.sing 566
        VendorPricings v;
2427 ankur.sing 567
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
2119 ankur.sing 568
            v = new VendorPricings();
2427 ankur.sing 569
            v.setMop(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP)));
570
            v.setDealerPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP)));
571
            v.setTransferPrice(Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP)));
572
            v.setVendorId(Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID)));
2126 ankur.sing 573
            vendorPrices.put(v.getVendorId(), v);
2066 ankur.sing 574
        }
2126 ankur.sing 575
        newItem.setVendorPricesMap(vendorPrices);
2359 ankur.sing 576
        newItem.setItemStatusDesc(statusDesc.getText().trim());
2427 ankur.sing 577
 
2126 ankur.sing 578
        /*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
579
        Add the instance to map and set the map to the item instance created above.*/
2359 ankur.sing 580
        Map<String, VendorItemMapping> vendorMappings = new HashMap<String, VendorItemMapping>();
2126 ankur.sing 581
        VendorItemMapping vMapping;
2427 ankur.sing 582
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
2126 ankur.sing 583
            vMapping = new VendorItemMapping();
2427 ankur.sing 584
            vMapping.setItemKey(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY));
585
            vMapping.setVendorId(Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID)));
586
            vendorMappings.put(vMapping.getVendorId() + Item.KEY_SEPARATOR + tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD), vMapping);
2119 ankur.sing 587
        }
2359 ankur.sing 588
        newItem.setVendorKeysMap(vendorMappings);
2119 ankur.sing 589
 
2126 ankur.sing 590
        newItem.setContentCategoryId(item.getContentCategoryId());
591
        newItem.setFeatureId(item.getFeatureId());
592
        newItem.setFeatureDescription(item.getFeatureDescription());
593
        newItem.setAddedOn(item.getAddedOn());
594
        newItem.setRetireDate(item.getRetireDate());
595
        newItem.setUpdatedOn(item.getUpdatedOn());
596
        newItem.setItemStatus(item.getItemStatus());
597
        newItem.setOtherInfo(item.getOtherInfo());
598
        newItem.setAvailability(item.getAvailability());
2119 ankur.sing 599
 
2126 ankur.sing 600
        return true;
2066 ankur.sing 601
    }
602
 
2427 ankur.sing 603
    /**
604
     * This method is called when Edit button is clicked corresponding to a row in 
605
     * vendor prices table. It will pop up a form to edit the vendor prices.
606
     * @param vendorId
607
     * @param row
608
     */
609
    private void editVendorPrices(final long vendorId, final int row) {
610
        String mop = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP);
611
        String dp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP);
612
        String tp = tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP);
2119 ankur.sing 613
        VendorPricesDialog pricesDialog = new VendorPricesDialog(mop, dp, tp);
2105 ankur.sing 614
        pricesDialog.updateButton.setText("Update");
2119 ankur.sing 615
        pricesDialog.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
2066 ankur.sing 616
            @Override
2119 ankur.sing 617
            public boolean onUpdate(double mop, double dp, double tp, long vendorId) {
618
                if(!validateVendorPrices(mop, dp, tp)) {
2105 ankur.sing 619
                    return false;
620
                }
2427 ankur.sing 621
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_MOP, mop + "");
622
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_DP, dp + "");
623
                tableVendorPrices.setText(row, TABLE_INDEX_PRICING_TP, tp + "");
2105 ankur.sing 624
                return true;
2066 ankur.sing 625
            }
626
        });
627
        pricesDialog.show();
628
    }
2119 ankur.sing 629
 
2427 ankur.sing 630
    /**
631
     * This method is called when Edit button is clicked corresponding to a row in 
632
     * vendor item key table. It will pop up a form to edit the item key.
633
     * @param vendorId
634
     * @param row
635
     */
636
    private void editVendorKey(final long vendorId, final int row) {
637
        String key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2126 ankur.sing 638
        VendorMappingDialog mappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
639
                modelNumber.getText().trim(), color.getText().trim(), key);
2119 ankur.sing 640
        mappingDialog.updateButton.setText("Update");
641
        mappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
642
            @Override
643
            public boolean onUpdate(String itemKey, long vendorId) {
644
                if(itemKey == null || itemKey.equals("")) {
645
                    Window.alert("Item key cannot be empty.");
646
                    return false;
647
                }
2427 ankur.sing 648
                tableVendorItemKey.setText(row, TABLE_INDEX_MAPPING_ITEM_KEY, itemKey);
2119 ankur.sing 649
                return true;
650
            }
651
        });
652
        mappingDialog.show();
653
    }
2066 ankur.sing 654
 
2427 ankur.sing 655
    /**
656
     * This method compares all the editable UI fields values with attributes in the item object.
657
     * If they differ, the attribute name is appended to a string.
658
     * @return String showing attributes which are changed by the user for confirmation.
659
     *      <br>Empty string if nothing is changed.
660
     */
2252 ankur.sing 661
    private String isItemChanged() {
662
        StringBuilder sb = new StringBuilder("");
2489 ankur.sing 663
        if(!checkParameterIfEqual(productGroup.getText().trim(), item.getProductGroup())) {
2387 ankur.sing 664
            sb.append("\n-Product Group");
2066 ankur.sing 665
        }
2489 ankur.sing 666
        if(!checkParameterIfEqual(brand.getText().trim(), item.getBrand())) {
2387 ankur.sing 667
            sb.append("\n-Brand");
2066 ankur.sing 668
        }
2489 ankur.sing 669
        if(!checkParameterIfEqual(modelNumber.getText().trim(), item.getModelNumber())) {
2387 ankur.sing 670
            sb.append("\n-Model Number");
2066 ankur.sing 671
        }
2489 ankur.sing 672
        if(!checkParameterIfEqual(modelName.getText().trim(), item.getModelName())) {
2387 ankur.sing 673
            sb.append("\n-Model Name");
2066 ankur.sing 674
        }
2489 ankur.sing 675
        if(!checkParameterIfEqual(color.getText().trim(), item.getColor())) {
2387 ankur.sing 676
            sb.append("\n-Color");
2066 ankur.sing 677
        }
2489 ankur.sing 678
        if(!checkParameterIfEqual(statusDesc.getText().trim(), item.getItemStatusDesc())) {
2387 ankur.sing 679
            sb.append("\n-Status Description");
2359 ankur.sing 680
        }
2489 ankur.sing 681
        if(!checkParameterIfEqual(comments.getText().trim(), item.getComments())) {
2387 ankur.sing 682
            sb.append("\n-Comments");
2066 ankur.sing 683
        }
2489 ankur.sing 684
        if(!checkParameterIfEqual(newItem.getMrp(), item.getMrp())) {
2387 ankur.sing 685
            sb.append("\n-MRP");
2066 ankur.sing 686
        }
2489 ankur.sing 687
        if(!checkParameterIfEqual(newItem.getSellingPrice(), item.getSellingPrice())) {
2387 ankur.sing 688
            sb.append("\n-Selling Price");
2027 ankur.sing 689
        }
2489 ankur.sing 690
        if(!checkParameterIfEqual(newItem.getWeight(), item.getWeight())) {
2387 ankur.sing 691
            sb.append("\n-Weight");
2027 ankur.sing 692
        }
2489 ankur.sing 693
        if(!checkParameterIfEqual(bestDealsText.getText().trim(), item.getBestDealsText())) {
2387 ankur.sing 694
            sb.append("\n-Best Deal Text");
2066 ankur.sing 695
        }
2489 ankur.sing 696
        if(!checkParameterIfEqual(newItem.getBestDealsValue(), item.getBestDealsValue())) {
2387 ankur.sing 697
            sb.append("\n-Best Deal Value");
2027 ankur.sing 698
        }
2489 ankur.sing 699
        if(!checkParameterIfEqual(newItem.getBestSellingRank(), item.getBestSellingRank())) {
2387 ankur.sing 700
            sb.append("\n-Best Selling Rank");
2066 ankur.sing 701
        }
702
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
2387 ankur.sing 703
            sb.append("\n-Default For Entity Flag");
2066 ankur.sing 704
        }
2252 ankur.sing 705
        if(item.isRisky() != risky.getValue()) {
2387 ankur.sing 706
            sb.append("\n-Risky Flag");
2252 ankur.sing 707
        }
2489 ankur.sing 708
        if(!checkParameterIfEqual(newItem.getStartDate(), item.getStartDate())) {
2387 ankur.sing 709
            sb.append("\n-Start Date");
2068 ankur.sing 710
        }
3362 chandransh 711
        if(item.getExpectedDelay() != newItem.getExpectedDelay()) {
712
            sb.append("\n-Expected Delay");
713
        }
714
        if(item.getPreferredWarehouse() != newItem.getPreferredWarehouse()) {
715
            sb.append("\n-Preferred Warehouse");
716
        }
717
 
2126 ankur.sing 718
        VendorPricings vendorPricings;
2066 ankur.sing 719
        long vendorId;
2427 ankur.sing 720
        for(int row = 0; row < tableVendorPrices.getRowCount(); row++) {
721
            vendorId = Long.parseLong(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_VENDORID));
2126 ankur.sing 722
            vendorPricings = item.getVendorPricesMap().get(vendorId);
2359 ankur.sing 723
            if(vendorPricings == null) {
2387 ankur.sing 724
                sb.append("\n-Vendor Prices (Vendor:" + vendorId + ")");
2359 ankur.sing 725
                continue;
726
            }
2427 ankur.sing 727
            if(vendorPricings.getMop() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_MOP))) {
2387 ankur.sing 728
                sb.append("\n-MOP (Vendor:" + vendorId + ")");
2066 ankur.sing 729
            }
2427 ankur.sing 730
            if(vendorPricings.getDealerPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_DP))) {
2387 ankur.sing 731
                sb.append("\n-Dealer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 732
            }
2427 ankur.sing 733
            if(vendorPricings.getTransferPrice() != Double.parseDouble(tableVendorPrices.getText(row, TABLE_INDEX_PRICING_TP))) {
2387 ankur.sing 734
                sb.append("\n-Transfer Price (Vendor:" + vendorId + ")");
2066 ankur.sing 735
            }
736
        }
2387 ankur.sing 737
 
738
        VendorItemMapping mapping;
739
        String old_key, new_key;
2427 ankur.sing 740
        for(int row = 0; row < tableVendorItemKey.getRowCount(); row++) {
741
            vendorId = Long.parseLong(tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_VENDORID));
742
            old_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY_OLD);
743
            new_key = tableVendorItemKey.getText(row, TABLE_INDEX_MAPPING_ITEM_KEY);
2387 ankur.sing 744
            mapping = item.getVendorKeysMap().get(vendorId + Item.KEY_SEPARATOR + old_key);
745
            if(mapping == null || !old_key.equals(new_key)) {
746
                sb.append("\n-Vendor Key (Vendor:" + vendorId + ",Key: = " + old_key + ")");
747
                continue;
748
            }
749
        }
2252 ankur.sing 750
        return sb.toString();
2066 ankur.sing 751
    }
752
 
2566 chandransh 753
    @SuppressWarnings("unused")
754
	private boolean validatePrices() {
2066 ankur.sing 755
        if(newItem.getSellingPrice() > newItem.getMrp()) {
756
            Window.alert("Selling price cannot be more than MRP");
757
            return false;
758
        }
2119 ankur.sing 759
        for(VendorPricings v : newItem.getVendorPricesMap().values()) {
2105 ankur.sing 760
            if(newItem.getMrp() < v.getMop()) {
761
                Window.alert("MRP cannot be less than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 762
                return false;
763
            }
2105 ankur.sing 764
            if(v.getTransferPrice() > v.getMop()) {
765
                Window.alert("Transfer Price cannot be more than MOP. Vendor: " + v.getVendorId());
2066 ankur.sing 766
                return false;
767
            }
768
        }
769
        return true;
770
    }
2105 ankur.sing 771
 
2119 ankur.sing 772
    private boolean validateVendorPrices(double mop, double dp, double tp) {
2489 ankur.sing 773
        if(item.getMrp() != null && item.getMrp() < mop) {
2105 ankur.sing 774
            Window.alert("MOP cannot be more than MRP.");
775
            return false;
1992 ankur.sing 776
        }
2105 ankur.sing 777
        if(tp > mop) {
778
            Window.alert("Transfer Price cannot be more than MOP.");
779
            return false;
1992 ankur.sing 780
        }
2105 ankur.sing 781
        return true;
1992 ankur.sing 782
    }
2105 ankur.sing 783
 
784
    public long getItemId() {
785
        return item == null ? 0 : item.getId();
786
    }
787
 
788
    public Item getItem() {
789
        return item;
790
    }
791
 
2427 ankur.sing 792
    /**
793
     * This method is used while adding vendor prices to ensure that there is only one row in the table for a vendor.
794
     * @param vendorId
795
     * @return true if parameter vendor Id is already added to vendor prices table.
796
     *      <br>else false
797
     */
2105 ankur.sing 798
    private boolean vendorExists(long vendorId) {
799
        long id;
2427 ankur.sing 800
        for(int i = 0; i < tableVendorPrices.getRowCount(); i++) {
801
            id = Long.parseLong(tableVendorPrices.getText(i, TABLE_INDEX_PRICING_VENDORID));
2105 ankur.sing 802
            if(vendorId == id) {
803
                return false;
804
            }
1992 ankur.sing 805
        }
2105 ankur.sing 806
        return true;
1992 ankur.sing 807
    }
2387 ankur.sing 808
 
2427 ankur.sing 809
    /**
810
     * This method is used to check if any of the string item attributes is changed by the user.
2489 ankur.sing 811
     * @param o1
812
     * @param o2
2427 ankur.sing 813
     * @return true if two strings are equal
814
     *      <br>true if one of them is null and another is empty.
815
     *      <br>false otherwise
816
     */
2489 ankur.sing 817
    private boolean checkParameterIfEqual(Object o1, Object o2) {
818
        if(o1 == o2) {
2387 ankur.sing 819
            return true;
820
        }
2489 ankur.sing 821
        if(o1 != null && o2 != null && o1.equals(o2)) {
2387 ankur.sing 822
            return true;
823
        }
2489 ankur.sing 824
        if((o1 == null && o2.equals("")) || (o2 == null && o1.equals(""))) {
2387 ankur.sing 825
            return true;
826
        }
827
        return false;
828
    }
2489 ankur.sing 829
 
830
    public void setCatalogDashboardPanel(CatalogDashboard catalogDashboardPanel) {
831
        this.catalogDashboardPanel = catalogDashboardPanel;
832
    }
1961 ankur.sing 833
}