Subversion Repositories SmartDukaan

Rev

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