Subversion Repositories SmartDukaan

Rev

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

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