Subversion Repositories SmartDukaan

Rev

Rev 18457 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18457 Rev 21864
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;
-
 
4
import in.shop2020.catalog.dashboard.shared.Utils;
-
 
5
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
-
 
6
import in.shop2020.catalog.dashboard.shared.VendorPricings;
-
 
7
import java.util.Date;
3
import java.util.Date;
8
import java.util.HashMap;
4
import java.util.HashMap;
-
 
5
import java.util.List;
9
import java.util.Map;
6
import java.util.Map;
10
import java.util.Map.Entry;
7
import java.util.Map.Entry;
-
 
8
 
-
 
9
import org.apache.log4j.Logger;
-
 
10
 
11
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.core.client.GWT;
-
 
12
import com.google.gwt.event.dom.client.ChangeEvent;
-
 
13
import com.google.gwt.event.dom.client.ChangeHandler;
12
import com.google.gwt.event.dom.client.ClickEvent;
14
import com.google.gwt.event.dom.client.ClickEvent;
13
import com.google.gwt.event.dom.client.ClickHandler;
15
import com.google.gwt.event.dom.client.ClickHandler;
14
import com.google.gwt.uibinder.client.UiBinder;
16
import com.google.gwt.uibinder.client.UiBinder;
15
import com.google.gwt.uibinder.client.UiField;
17
import com.google.gwt.uibinder.client.UiField;
16
import com.google.gwt.uibinder.client.UiHandler;
18
import com.google.gwt.uibinder.client.UiHandler;
Line 23... Line 25...
23
import com.google.gwt.user.client.ui.ListBox;
25
import com.google.gwt.user.client.ui.ListBox;
24
import com.google.gwt.user.client.ui.TextBox;
26
import com.google.gwt.user.client.ui.TextBox;
25
import com.google.gwt.user.client.ui.Widget;
27
import com.google.gwt.user.client.ui.Widget;
26
import com.google.gwt.user.datepicker.client.DateBox;
28
import com.google.gwt.user.datepicker.client.DateBox;
27
 
29
 
-
 
30
import in.shop2020.catalog.dashboard.server.CatalogServiceImpl;
-
 
31
import in.shop2020.catalog.dashboard.shared.CategoryHsnCode;
-
 
32
import in.shop2020.catalog.dashboard.shared.Item;
-
 
33
import in.shop2020.catalog.dashboard.shared.Utils;
-
 
34
import in.shop2020.catalog.dashboard.shared.VendorItemMapping;
-
 
35
import in.shop2020.catalog.dashboard.shared.VendorPricings;
-
 
36
 
28
/**
37
/**
29
 * ItemForm is a DialogBox which is created on the click of Add Item button in ItemActions.
38
 * ItemForm is a DialogBox which is created on the click of Add Item button in ItemActions.
30
 * This contains UI fields to fill up item attributes. It also contains tables for adding
39
 * This contains UI fields to fill up item attributes. It also contains tables for adding
31
 * vendor prices and vendor mapping keys.
40
 * vendor prices and vendor mapping keys.
32
 *
41
 *
Line 34... Line 43...
34
public class ItemForm extends DialogBox implements ComingSoon{
43
public class ItemForm extends DialogBox implements ComingSoon{
35
 
44
 
36
	interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
45
	interface ItemFormUiBinder extends UiBinder<Widget, ItemForm> {}
37
	private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
46
	private static ItemFormUiBinder uiBinder = GWT.create(ItemFormUiBinder.class);
38
	
47
	
39
 
-
 
40
	private final static CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
48
	private final static CatalogServiceAsync catalogService = GWT.create(CatalogService.class);
41
	private final int TABLE_INDEX_VENDORID = 0,
49
	private final int TABLE_INDEX_VENDORID = 0,
42
	TABLE_INDEX_VENDOR_DESC = 1, 
50
	TABLE_INDEX_VENDOR_DESC = 1, 
43
	TABLE_INDEX_ITEM_KEY = 2,
51
	TABLE_INDEX_ITEM_KEY = 2,
44
	TABLE_INDEX_MOP = 2,
52
	TABLE_INDEX_MOP = 2,
Line 54... Line 62...
54
	@UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
62
	@UiField DateBox startDate, retireDate, comingSoonStartDate, expectedArrivalDate;
55
	@UiField Button addButton, cancelButton, comingSoonButton,searchButton;
63
	@UiField Button addButton, cancelButton, comingSoonButton,searchButton;
56
	@UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance, showSellingPrice;
64
	@UiField CheckBox defaultForEntity, risky, itemType, hasItemNo, clearance, showSellingPrice;
57
	@UiField FlexTable headerVendor, vendorTable;
65
	@UiField FlexTable headerVendor, vendorTable;
58
	@UiField FlexTable headerVendorM, vendorTableM;
66
	@UiField FlexTable headerVendorM, vendorTableM;
59
	@UiField ListBox preferredVendor,preferredInsurer;
67
	@UiField ListBox preferredVendor,preferredInsurer, categories, hsnCode;
60
 
68
 
61
	public ItemForm(){
69
	public ItemForm(){
62
		setText("Add New Item");
70
		setText("Add New Item");
63
		setWidget(uiBinder.createAndBindUi(this));
71
		setWidget(uiBinder.createAndBindUi(this));
64
		initVendorKeysHeader();
72
		initVendorKeysHeader();
Line 72... Line 80...
72
		}
80
		}
73
		preferredInsurer.addItem("select", "0");
81
		preferredInsurer.addItem("select", "0");
74
		for(Entry<Long, String> e : Utils.getAllInsurers().entrySet()){
82
		for(Entry<Long, String> e : Utils.getAllInsurers().entrySet()){
75
			preferredInsurer.addItem(e.getValue(),e.getKey().toString());
83
			preferredInsurer.addItem(e.getValue(),e.getKey().toString());
76
		}
84
		}
-
 
85
		
-
 
86
		categories.addItem("select", "0");
-
 
87
		for(Entry<Long, String> e : Utils.getAllCategoriesMap().entrySet()){
-
 
88
			categories.addItem(e.getValue(),e.getKey().toString());
-
 
89
		}
-
 
90
		
-
 
91
		//System.out.println("\n\n\nInitial ui ..... \n\n\n");
-
 
92
		//hsnCode.addItem("select");
-
 
93
		categories.addChangeHandler(new ChangeHandler() {
-
 
94
    		public void onChange(ChangeEvent arg0) {
-
 
95
    			hsnCode.clear();
-
 
96
    			int categoryId = Integer.parseInt(categories.getValue(categories.getSelectedIndex()));
-
 
97
    			System.out.println("fired onChangeEvent categoryId : "+categoryId);
-
 
98
    			catalogService.getHsnCodesByCategoryId(categoryId, new AsyncCallback<List<CategoryHsnCode>>() {
-
 
99
    				
-
 
100
					public void onFailure(Throwable arg0) {
-
 
101
						arg0.printStackTrace();
-
 
102
					}
-
 
103
 
-
 
104
					public void onSuccess(List<CategoryHsnCode> arg0) {
-
 
105
						for(CategoryHsnCode categoryHsnCode : arg0){
-
 
106
		    				hsnCode.addItem(categoryHsnCode.getDescription() + " ("+ categoryHsnCode.getHsnCode() + ")", categoryHsnCode.getHsnCode());
-
 
107
		    			}
-
 
108
					}
-
 
109
    				
-
 
110
				});
-
 
111
    			
-
 
112
    		}
-
 
113
			
-
 
114
		});
77
 
115
 
78
	}
116
	}
79
 
117
 
80
	/**
118
	/**
81
	 * initialises vendor item key table header. Creates an Add button and
119
	 * initialises vendor item key table header. Creates an Add button and
Line 209... Line 247...
209
	/**
247
	/**
210
	 * On search button click the item id is searched if it exists then the attributes of the item id are filled into the item form.
248
	 * On search button click the item id is searched if it exists then the attributes of the item id are filled into the item form.
211
	 * Else an alert is displayed showing item id does not exists.
249
	 * Else an alert is displayed showing item id does not exists.
212
	 */
250
	 */
213
	void searchItem(ClickEvent event){
251
	void searchItem(ClickEvent event){
-
 
252
		hsnCode.clear();
214
		preferredVendor.clear();
253
		preferredVendor.clear();
215
		preferredInsurer.clear();  
254
		preferredInsurer.clear(); 
-
 
255
		categories.clear();
216
		catalogItemId.setText(null);
256
		catalogItemId.setText(null);
217
		productGroup.setText(null);
257
		productGroup.setText(null);
218
		brand.setText(null);
258
		brand.setText(null);
219
		modelNumber.setText(null);
259
		modelNumber.setText(null);
220
		modelName.setText(null);
260
		modelName.setText(null);
Line 316... Line 356...
316
    		preferredInsurer.addItem(entry.getValue(),entry.getKey().toString());
356
    		preferredInsurer.addItem(entry.getValue(),entry.getKey().toString());
317
    		if(item.getPreferredInsurer()==entry.getKey()){
357
    		if(item.getPreferredInsurer()==entry.getKey()){
318
    			preferredInsurer.setSelectedIndex(index);  
358
    			preferredInsurer.setSelectedIndex(index);  
319
    		}
359
    		}
320
    	}
360
    	}
-
 
361
    	index = 0;
-
 
362
    	categories.addItem("select", "0");
-
 
363
    	categories.setSelectedIndex(0);
-
 
364
    	for(Map.Entry<Long, String> entry : Utils.getAllCategoriesMap().entrySet()){
-
 
365
    		index ++;
-
 
366
    		categories.addItem(entry.getValue(), entry.getKey().toString());
-
 
367
    		if(item.getCategoryItemId() == entry.getKey()){
-
 
368
    			categories.setSelectedIndex(index);
-
 
369
    		}
-
 
370
    	}
-
 
371
    	
-
 
372
    	
321
		catalogItemId.setText(Long.toString(item.getCatalogItemId()));
373
		catalogItemId.setText(Long.toString(item.getCatalogItemId()));
322
		productGroup.setText(item.getProductGroup());
374
		productGroup.setText(item.getProductGroup());
323
		brand.setText(item.getBrand());
375
		brand.setText(item.getBrand());
324
		modelNumber.setText(item.getModelNumber());
376
		modelNumber.setText(item.getModelNumber());
325
		modelName.setText(item.getModelName());
377
		modelName.setText(item.getModelName());
Line 661... Line 713...
661
		}
713
		}
662
		else {
714
		else {
663
			item.setPreferredVendor(Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex())));
715
			item.setPreferredVendor(Utils.getVendorId(preferredVendor.getItemText(preferredVendor.getSelectedIndex())));
664
		}
716
		}
665
		item.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
717
		item.setPreferredInsurer(Long.parseLong(preferredInsurer.getValue(preferredInsurer.getSelectedIndex())));
-
 
718
		//item.setCategoryItemId(Integer.parseInt(categories.getValue(categories.getSelectedIndex())));
-
 
719
		item.setHsnCode(hsnCode.getValue(hsnCode.getSelectedIndex()));
666
		/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
720
		/*Create an instance of VendorPricings for each row in vendor pricing table. Set the vendor prices to the instance.
667
          Add the instance to map and set the map to the item instance created above.*/
721
          Add the instance to map and set the map to the item instance created above.*/
668
		Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
722
		Map<Long, VendorPricings> vendorPrices = new HashMap<Long, VendorPricings>();
669
		VendorPricings v;
723
		VendorPricings v;
670
		for(int row = 0; row < vendorTable.getRowCount(); row++) {
724
		for(int row = 0; row < vendorTable.getRowCount(); row++) {