Subversion Repositories SmartDukaan

Rev

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

Rev 2066 Rev 2068
Line 19... Line 19...
19
import com.google.gwt.user.client.ui.Button;
19
import com.google.gwt.user.client.ui.Button;
20
import com.google.gwt.user.client.ui.CheckBox;
20
import com.google.gwt.user.client.ui.CheckBox;
21
import com.google.gwt.user.client.ui.FlexTable;
21
import com.google.gwt.user.client.ui.FlexTable;
22
import com.google.gwt.user.client.ui.HTMLTable.Cell;
22
import com.google.gwt.user.client.ui.HTMLTable.Cell;
23
import com.google.gwt.user.client.ui.Label;
23
import com.google.gwt.user.client.ui.Label;
24
import com.google.gwt.user.client.ui.ListBox;
-
 
25
import com.google.gwt.user.client.ui.ResizeComposite;
24
import com.google.gwt.user.client.ui.ResizeComposite;
26
import com.google.gwt.user.client.ui.TextBox;
25
import com.google.gwt.user.client.ui.TextBox;
27
import com.google.gwt.user.client.ui.Widget;
26
import com.google.gwt.user.client.ui.Widget;
-
 
27
import com.google.gwt.user.datepicker.client.DateBox;
28
 
28
 
29
public class ItemDetails extends ResizeComposite {
29
public class ItemDetails extends ResizeComposite {
30
 
30
 
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;
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;
32
    private final int TABLE_INDEX_WAREHOUSE_ID = 0, TABLE_INDEX_WAREHOUSE_DESC = 1, TABLE_INDEX_WAREHOUSE_INV = 2;
32
    private final int TABLE_INDEX_WAREHOUSE_ID = 0, TABLE_INDEX_WAREHOUSE_DESC = 1, TABLE_INDEX_WAREHOUSE_INV = 2;
Line 52... Line 52...
52
    @UiField Label itemId;
52
    @UiField Label itemId;
53
    @UiField TextBox productGroup, brand, modelNumber, modelName, color;
53
    @UiField TextBox productGroup, brand, modelNumber, modelName, color;
54
    @UiField Label category, catalogItemId;
54
    @UiField Label category, catalogItemId;
55
    @UiField TextBox comments;
55
    @UiField TextBox comments;
56
    @UiField TextBox sellingPrice, mrp, /*mop, dealerPrice, transferPrice,*/ weight;
56
    @UiField TextBox sellingPrice, mrp, /*mop, dealerPrice, transferPrice,*/ weight;
57
    @UiField Label addedOn, startDate, retireDate, updatedOn;
57
    @UiField Label addedOn, /*startDate,*/ retireDate, updatedOn;
58
    @UiField Label itemStatus;
58
    @UiField Label itemStatus;
59
    @UiField TextBox bestDealsText, bestDealsValue; 
59
    @UiField TextBox bestDealsText, bestDealsValue; 
60
    @UiField FlexTable headerAvailability, availabilityTable;
60
    @UiField FlexTable headerAvailability, availabilityTable;
61
    @UiField FlexTable headerPricing, pricingTable;
61
    @UiField FlexTable headerPricing, pricingTable;
62
    @UiField TextBox bestSellingRank;
62
    @UiField TextBox bestSellingRank;
63
    @UiField CheckBox defaultForEntity;
63
    @UiField CheckBox defaultForEntity;
64
    @UiField Button submit;
64
    @UiField Button submit;
-
 
65
    @UiField DateBox startDate;
65
 
66
 
66
    public ItemDetails(Item item){
67
    public ItemDetails(Item item){
67
        initWidget(uiBinder.createAndBindUi(this));
68
        initWidget(uiBinder.createAndBindUi(this));
68
        initAvailabilityHeader();
69
        initAvailabilityHeader();
69
        initPricingHeader();
70
        initPricingHeader();
Line 94... Line 95...
94
        sellingPrice.setText(item.getSellingPrice()+"");
95
        sellingPrice.setText(item.getSellingPrice()+"");
95
        /*mop.setText(item.getMop()+"");
96
        /*mop.setText(item.getMop()+"");
96
		dealerPrice.setText(item.getDealerPrice()+"");
97
		dealerPrice.setText(item.getDealerPrice()+"");
97
		transferPrice.setText(item.getTransferPrice()+"");*/
98
		transferPrice.setText(item.getTransferPrice()+"");*/
98
        weight.setText(item.getWeight()+"");
99
        weight.setText(item.getWeight()+"");
-
 
100
        
99
 
101
        
100
        addedOn.setText(getDisplayableDate(item.getAddedOn()));
102
        startDate.setValue(new Date(item.getStartDate()));
-
 
103
        
101
        startDate.setText(getDisplayableDate(item.getStartDate()));
104
        addedOn.setText(Utils.getDisplayableDate(item.getAddedOn()));
102
        retireDate.setText(getDisplayableDate(item.getRetireDate()));
105
        retireDate.setText(Utils.getDisplayableDate(item.getRetireDate()));
103
        updatedOn.setText(getDisplayableDate(item.getUpdatedOn()));
106
        updatedOn.setText(Utils.getDisplayableDate(item.getUpdatedOn()));
104
 
107
 
105
        bestDealsText.setText(item.getBestDealsText());
108
        bestDealsText.setText(item.getBestDealsText());
106
        bestDealsValue.setText(item.getBestDealsValue()+"");
109
        bestDealsValue.setText(item.getBestDealsValue()+"");
107
 
110
 
108
        bestSellingRank.setText(item.getBestSellingRank()+"");
111
        bestSellingRank.setText(item.getBestSellingRank()+"");
Line 194... Line 197...
194
            });
197
            });
195
        }
198
        }
196
    }
199
    }
197
 
200
 
198
 
201
 
199
    //TODO: This code is duplicated between here and OrderList. Move it to a Utility class.
-
 
200
    private String getDisplayableDate(Long millis){
-
 
201
        Date date = new Date();
-
 
202
        date.setTime(millis);
-
 
203
        String dateString = date.toString();
-
 
204
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
-
 
205
        dateString = dateString.substring(0, dateString.lastIndexOf(" "));
-
 
206
        return dateString;		
-
 
207
    }
-
 
208
 
-
 
209
    public void setItemUpdateListener(ItemUpdateListener itemUpdatelistener) {
202
    public void setItemUpdateListener(ItemUpdateListener itemUpdatelistener) {
210
        this.itemUpdateListener = itemUpdatelistener;
203
        this.itemUpdateListener = itemUpdatelistener;
211
    }
204
    }
212
 
205
 
213
    @UiHandler("submit")
206
    @UiHandler("submit")
214
    void onSubmitPressed(ClickEvent clickEvent) {
207
    void onSubmitPressed(ClickEvent clickEvent) {
215
        //long id = Long.parseLong(this.itemId.getText());
208
        //long id = Long.parseLong(this.itemId.getText());
216
        try {
209
        try {
-
 
210
            updateItem();
217
            if(!isItemChanged()) {
211
            if(!isItemChanged()) {
218
                Window.alert("Nothing to update. Please change intended item parameters and try again.");
212
                Window.alert("Nothing to update. Please change intended item parameters and try again.");
219
                return;
213
                return;
220
            }
214
            }
221
            updateItem();
215
            
222
            if(!validatePrices()) {
216
            if(!validatePrices()) {
223
                return;
217
                return;
224
            }
218
            }
225
            //updateItem();
219
            //updateItem();
226
        } catch(NumberFormatException ex) {
220
        } catch(NumberFormatException ex) {
Line 242... Line 236...
242
        newItem.setCategory(Long.parseLong(category.getText()));
236
        newItem.setCategory(Long.parseLong(category.getText()));
243
        newItem.setComments(comments.getText().trim());
237
        newItem.setComments(comments.getText().trim());
244
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
238
        newItem.setCatalogItemId(Long.parseLong(catalogItemId.getText()));
245
        newItem.setFeatureId(item.getFeatureId());
239
        newItem.setFeatureId(item.getFeatureId());
246
        newItem.setFeatureDescription(item.getFeatureDescription());
240
        newItem.setFeatureDescription(item.getFeatureDescription());
-
 
241
        try {
247
        newItem.setMrp(Double.parseDouble(mrp.getText().trim()));
242
            newItem.setMrp(Double.parseDouble(mrp.getText().trim()));
-
 
243
        } catch(NumberFormatException ex) {
-
 
244
            Window.alert("Invalid MRP format");
-
 
245
            throw new NumberFormatException();
-
 
246
        }
-
 
247
        try {
248
        newItem.setSellingPrice(Double.parseDouble(sellingPrice.getText().trim()));
248
            newItem.setSellingPrice(Double.parseDouble(sellingPrice.getText().trim()));
-
 
249
        }
-
 
250
        catch(NumberFormatException ex) {
-
 
251
            Window.alert("Invalid Selling Price format");
-
 
252
            throw new NumberFormatException();
-
 
253
        }
-
 
254
        try {
249
        newItem.setWeight(Double.parseDouble(weight.getText().trim()));
255
            newItem.setWeight(Double.parseDouble(weight.getText().trim()));
-
 
256
        } catch(NumberFormatException ex) {
-
 
257
            Window.alert("Invalid Weight format");
-
 
258
            throw new NumberFormatException();
-
 
259
        }
250
        newItem.setAddedOn(item.getAddedOn());
260
        newItem.setAddedOn(item.getAddedOn());
251
        newItem.setStartDate(item.getStartDate());
261
        newItem.setStartDate(startDate.getValue().getTime());
252
        newItem.setRetireDate(item.getRetireDate());
262
        newItem.setRetireDate(item.getRetireDate());
253
        newItem.setUpdatedOn(item.getUpdatedOn());
263
        newItem.setUpdatedOn(item.getUpdatedOn());
254
        newItem.setItemStatus(item.getItemStatus());
264
        newItem.setItemStatus(item.getItemStatus());
255
        newItem.setOtherInfo(item.getOtherInfo());
265
        newItem.setOtherInfo(item.getOtherInfo());
256
        newItem.setBestDealsText(bestDealsText.getText().trim());
266
        newItem.setBestDealsText(bestDealsText.getText().trim());
-
 
267
        try {
257
        newItem.setBestDealsValue(Double.parseDouble(bestDealsValue.getText().trim()));
268
            newItem.setBestDealsValue(Double.parseDouble(bestDealsValue.getText().trim()));
-
 
269
        } catch(NumberFormatException ex) {
-
 
270
            Window.alert("Invalid Best Deals Value format");
-
 
271
            throw new NumberFormatException();
-
 
272
        }
-
 
273
        try {
258
        newItem.setBestSellingRank(Long.parseLong(bestSellingRank.getText().trim()));
274
            newItem.setBestSellingRank(Long.parseLong(bestSellingRank.getText().trim()));
-
 
275
        } catch (NumberFormatException ex) {
-
 
276
            Window.alert("Invalid Best Selling Rank format");
-
 
277
            throw new NumberFormatException();
-
 
278
        }
-
 
279
 
259
        newItem.setDefaultForEntity(defaultForEntity.getValue());
280
        newItem.setDefaultForEntity(defaultForEntity.getValue());
260
        newItem.setAvailability(item.getAvailability());
281
        newItem.setAvailability(item.getAvailability());
261
        Map<Long, double[]> vendorPrices = new HashMap<Long, double[]>();
282
        Map<Long, double[]> vendorPrices = new HashMap<Long, double[]>();
262
        double[] arr;
283
        double[] arr;
263
        for(int row = 0; row < pricingTable.getRowCount(); row++) {
284
        for(int row = 0; row < pricingTable.getRowCount(); row++) {
Line 384... Line 405...
384
            throw new NumberFormatException();
405
            throw new NumberFormatException();
385
        }
406
        }
386
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
407
        if(item.isDefaultForEntity() != defaultForEntity.getValue()) {
387
            return true;
408
            return true;
388
        }
409
        }
-
 
410
        
-
 
411
        if(newItem.getStartDate() != item.getStartDate()) {
-
 
412
            return true;
-
 
413
        }
389
                
414
                
390
        double[] vendorPrices;
415
        double[] vendorPrices;
391
        long vendorId;
416
        long vendorId;
392
        for(int row = 0; row < pricingTable.getRowCount(); row++) {
417
        for(int row = 0; row < pricingTable.getRowCount(); row++) {
393
            vendorId = Long.parseLong(pricingTable.getText(row, TABLE_INDEX_VENDORID));
418
            vendorId = Long.parseLong(pricingTable.getText(row, TABLE_INDEX_VENDORID));