Subversion Repositories SmartDukaan

Rev

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