| 1961 |
ankur.sing |
1 |
package in.shop2020.catalog.dashboard.client;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.catalog.dashboard.shared.Item;
|
|
|
4 |
|
|
|
5 |
import java.util.Date;
|
| 1992 |
ankur.sing |
6 |
import java.util.Map;
|
|
|
7 |
import java.util.Map.Entry;
|
| 1961 |
ankur.sing |
8 |
|
|
|
9 |
import com.google.gwt.core.client.GWT;
|
|
|
10 |
import com.google.gwt.event.dom.client.ClickEvent;
|
| 1992 |
ankur.sing |
11 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
12 |
import com.google.gwt.resources.client.CssResource;
|
| 1961 |
ankur.sing |
13 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
14 |
import com.google.gwt.uibinder.client.UiField;
|
|
|
15 |
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
16 |
import com.google.gwt.user.client.Window;
|
|
|
17 |
import com.google.gwt.user.client.ui.Button;
|
| 1992 |
ankur.sing |
18 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
19 |
import com.google.gwt.user.client.ui.HTMLTable.Cell;
|
| 1961 |
ankur.sing |
20 |
import com.google.gwt.user.client.ui.Label;
|
|
|
21 |
import com.google.gwt.user.client.ui.ResizeComposite;
|
|
|
22 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
23 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
24 |
|
|
|
25 |
public class ItemDetails extends ResizeComposite {
|
|
|
26 |
|
|
|
27 |
interface ItemDetailsUiBinder extends UiBinder<Widget, ItemDetails> {}
|
|
|
28 |
private static ItemDetailsUiBinder uiBinder = GWT.create(ItemDetailsUiBinder.class);
|
|
|
29 |
|
| 1992 |
ankur.sing |
30 |
public interface ItemUpdateListener {
|
|
|
31 |
void onItemUpdate(Item item);
|
| 1961 |
ankur.sing |
32 |
}
|
|
|
33 |
|
| 1992 |
ankur.sing |
34 |
interface ItemDetailStyle extends CssResource{
|
|
|
35 |
String greenLabel();
|
|
|
36 |
String fieldChanged();
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private ItemUpdateListener itemUpdateListener;
|
|
|
40 |
|
|
|
41 |
private Item item;
|
| 1961 |
ankur.sing |
42 |
|
| 1992 |
ankur.sing |
43 |
@UiField ItemDetailStyle style;
|
| 1961 |
ankur.sing |
44 |
@UiField Label itemId, productGroup, brand, modelNumber, modelName, color;
|
|
|
45 |
@UiField Label category, comments;
|
|
|
46 |
@UiField Label catalogItemId;
|
| 1992 |
ankur.sing |
47 |
@UiField TextBox sellingPrice, mrp, /*mop, dealerPrice, transferPrice,*/ weight;
|
| 1961 |
ankur.sing |
48 |
@UiField Label addedOn, startDate, retireDate, updatedOn;
|
| 1992 |
ankur.sing |
49 |
@UiField Label bestDealsText, bestDealsValue, itemStatus;
|
|
|
50 |
@UiField FlexTable headerAvailability, availabilityTable;
|
|
|
51 |
@UiField FlexTable headerPricing, pricingTable;
|
| 1961 |
ankur.sing |
52 |
@UiField Button submit;
|
|
|
53 |
|
|
|
54 |
public ItemDetails(Item item){
|
|
|
55 |
initWidget(uiBinder.createAndBindUi(this));
|
| 1992 |
ankur.sing |
56 |
initAvailabilityHeader();
|
|
|
57 |
initPricingHeader();
|
|
|
58 |
setItemDetails(item);
|
| 1961 |
ankur.sing |
59 |
}
|
|
|
60 |
|
|
|
61 |
public ItemDetails() {
|
|
|
62 |
this.item = null;
|
|
|
63 |
initWidget(uiBinder.createAndBindUi(this));
|
| 1992 |
ankur.sing |
64 |
|
|
|
65 |
initAvailabilityHeader();
|
|
|
66 |
initPricingHeader();
|
| 1961 |
ankur.sing |
67 |
}
|
|
|
68 |
|
|
|
69 |
public void setItemDetails(Item item){
|
| 1992 |
ankur.sing |
70 |
this.item = item;
|
| 1961 |
ankur.sing |
71 |
itemId.setText(item.getId()+"");
|
|
|
72 |
productGroup.setText(item.getProductGroup());
|
|
|
73 |
brand.setText(item.getBrand());
|
|
|
74 |
modelNumber.setText(item.getModelNumber());
|
|
|
75 |
modelName.setText(item.getModelName());
|
|
|
76 |
color.setText(item.getColor());
|
|
|
77 |
|
|
|
78 |
category.setText(item.getCategory()+"");
|
|
|
79 |
comments.setText(item.getComments());
|
|
|
80 |
catalogItemId.setText(item.getCatalogItemId() + "");
|
|
|
81 |
|
|
|
82 |
mrp.setText(item.getMrp()+"");
|
|
|
83 |
sellingPrice.setText(item.getSellingPrice()+"");
|
| 1992 |
ankur.sing |
84 |
/*mop.setText(item.getMop()+"");
|
| 1961 |
ankur.sing |
85 |
dealerPrice.setText(item.getDealerPrice()+"");
|
| 1992 |
ankur.sing |
86 |
transferPrice.setText(item.getTransferPrice()+"");*/
|
| 1961 |
ankur.sing |
87 |
weight.setText(item.getWeight()+"");
|
|
|
88 |
|
|
|
89 |
addedOn.setText(getDisplayableDate(item.getAddedOn()));
|
|
|
90 |
startDate.setText(getDisplayableDate(item.getStartDate()));
|
|
|
91 |
retireDate.setText(getDisplayableDate(item.getRetireDate()));
|
|
|
92 |
updatedOn.setText(getDisplayableDate(item.getUpdatedOn()));
|
|
|
93 |
|
|
|
94 |
bestDealsText.setText(item.getBestDealsText());
|
|
|
95 |
bestDealsValue.setText(item.getBestDealsValue()+"");
|
| 1992 |
ankur.sing |
96 |
|
|
|
97 |
itemStatus.setText(item.getItemStatus());
|
|
|
98 |
|
|
|
99 |
updateAvailabilityTable(item.getAvailability());
|
|
|
100 |
|
|
|
101 |
updatePricingTable(item.getVendorPricings());
|
| 1961 |
ankur.sing |
102 |
}
|
|
|
103 |
|
| 1992 |
ankur.sing |
104 |
private void initAvailabilityHeader(){
|
|
|
105 |
// Initialize the header.
|
|
|
106 |
headerAvailability.getColumnFormatter().setWidth(0, "128px");
|
|
|
107 |
headerAvailability.getColumnFormatter().setWidth(1, "128px");
|
|
|
108 |
|
|
|
109 |
headerAvailability.setText(0, 0, "Warehouse Id");
|
|
|
110 |
headerAvailability.setText(0, 1, "Availability");
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
private void initPricingHeader(){
|
|
|
115 |
// Initialize the header.
|
|
|
116 |
headerPricing.getColumnFormatter().setWidth(0, "128px");
|
|
|
117 |
headerPricing.getColumnFormatter().setWidth(1, "128px");
|
|
|
118 |
headerPricing.getColumnFormatter().setWidth(2, "128px");
|
|
|
119 |
headerPricing.getColumnFormatter().setWidth(3, "128px");
|
|
|
120 |
|
|
|
121 |
headerPricing.setText(0, 0, "Vendor Id");
|
|
|
122 |
headerPricing.setText(0, 1, "MOP");
|
|
|
123 |
headerPricing.setText(0, 2, "Dealer Price");
|
|
|
124 |
headerPricing.setText(0, 3, "Transfer Price");
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
private void updateAvailabilityTable(Map<Long, Long> availabilityMap){
|
|
|
128 |
availabilityTable.removeAllRows();
|
|
|
129 |
if(availabilityMap == null) {
|
|
|
130 |
return;
|
|
|
131 |
}
|
|
|
132 |
availabilityTable.getColumnFormatter().setWidth(0, "128px");
|
|
|
133 |
availabilityTable.getColumnFormatter().setWidth(1, "128px");
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
int i=0;
|
|
|
137 |
for(Entry<Long, Long> availability : availabilityMap.entrySet()){
|
|
|
138 |
int col = 0;
|
|
|
139 |
availabilityTable.setText(i, col++, availability.getKey() + "");
|
|
|
140 |
availabilityTable.setText(i, col++, availability.getValue() + "");
|
|
|
141 |
i++;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
private void updatePricingTable(Map<Long, double[]> pricings){
|
|
|
146 |
pricingTable.removeAllRows();
|
|
|
147 |
if(pricings == null || pricings.isEmpty()) {
|
|
|
148 |
return;
|
|
|
149 |
}
|
|
|
150 |
pricingTable.getColumnFormatter().setWidth(0, "128px");
|
|
|
151 |
pricingTable.getColumnFormatter().setWidth(1, "128px");
|
|
|
152 |
pricingTable.getColumnFormatter().setWidth(2, "128px");
|
|
|
153 |
pricingTable.getColumnFormatter().setWidth(3, "128px");
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
int i=0;
|
|
|
157 |
for(Entry<Long, double[]> pricing : pricings.entrySet()){
|
|
|
158 |
int col = 0;
|
|
|
159 |
pricingTable.setText(i, col++, pricing.getKey() + "");
|
|
|
160 |
pricingTable.setText(i, col++, pricing.getValue()[Item.INDEX_MOP] + "");
|
|
|
161 |
pricingTable.setText(i, col++, pricing.getValue()[Item.INDEX_DP] + "");
|
|
|
162 |
pricingTable.setText(i, col++, pricing.getValue()[Item.INDEX_TP] + "");
|
|
|
163 |
Button editButton = new Button("Edit");
|
|
|
164 |
pricingTable.setWidget(i, col++, editButton);
|
|
|
165 |
i++;
|
|
|
166 |
editButton.addClickHandler(new ClickHandler() {
|
|
|
167 |
@Override
|
|
|
168 |
public void onClick(ClickEvent event) {
|
|
|
169 |
Cell cell = pricingTable.getCellForEvent(event);
|
|
|
170 |
int row = cell.getRowIndex();
|
|
|
171 |
long vendorId = Long.parseLong(pricingTable.getText(row, 0));
|
|
|
172 |
updateVendorPrices(vendorId, row);
|
|
|
173 |
}
|
|
|
174 |
});
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
|
| 1961 |
ankur.sing |
179 |
//TODO: This code is duplicated between here and OrderList. Move it to a Utility class.
|
|
|
180 |
private String getDisplayableDate(Long millis){
|
|
|
181 |
Date date = new Date();
|
|
|
182 |
date.setTime(millis);
|
|
|
183 |
String dateString = date.toString();
|
|
|
184 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
185 |
dateString = dateString.substring(0, dateString.lastIndexOf(" "));
|
|
|
186 |
return dateString;
|
|
|
187 |
}
|
|
|
188 |
|
| 1992 |
ankur.sing |
189 |
public void setItemUpdateListener(ItemUpdateListener itemUpdatelistener) {
|
|
|
190 |
this.itemUpdateListener = itemUpdatelistener;
|
| 1961 |
ankur.sing |
191 |
}
|
|
|
192 |
|
|
|
193 |
@UiHandler("submit")
|
|
|
194 |
void onSubmitPressed(ClickEvent clickEvent) {
|
| 1992 |
ankur.sing |
195 |
//long id = Long.parseLong(this.itemId.getText());
|
| 1961 |
ankur.sing |
196 |
try {
|
| 1992 |
ankur.sing |
197 |
updateItem();
|
| 1961 |
ankur.sing |
198 |
} catch(NumberFormatException ex) {
|
|
|
199 |
Window.alert("Price format is not correct.");
|
| 1992 |
ankur.sing |
200 |
return;
|
| 1961 |
ankur.sing |
201 |
}
|
| 1992 |
ankur.sing |
202 |
itemUpdateListener.onItemUpdate(item);
|
| 1961 |
ankur.sing |
203 |
}
|
|
|
204 |
|
| 1992 |
ankur.sing |
205 |
void updateItem() throws NumberFormatException {
|
|
|
206 |
item.setSellingPrice(Double.parseDouble(this.sellingPrice.getText()));
|
|
|
207 |
/*item.setTransferPrice(Double.parseDouble(this.transferPrice.getText()));
|
|
|
208 |
item.setDealerPrice(Double.parseDouble(this.dealerPrice.getText()));
|
|
|
209 |
item.setMop(Double.parseDouble(this.mop.getText()));*/
|
|
|
210 |
item.setWeight(Double.parseDouble(this.weight.getText()));
|
|
|
211 |
item.setMrp(Double.parseDouble(this.mrp.getText()));
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
private void updateVendorPrices(final long vendorId, final int row) {
|
|
|
215 |
String mop = pricingTable.getText(row, 1);
|
|
|
216 |
String dp = pricingTable.getText(row, 2);
|
|
|
217 |
String tp = pricingTable.getText(row, 3);
|
|
|
218 |
VendorPricesDialog vpd = new VendorPricesDialog(mop, dp, tp);
|
|
|
219 |
vpd.setVendorPriceUpdateListener(new VendorPricesDialog.VendorPriceUpdateListener() {
|
|
|
220 |
@Override
|
|
|
221 |
public void onPriceUpdate(double mop, double dp, double tp) {
|
|
|
222 |
pricingTable.setText(row, 1, mop + "");
|
|
|
223 |
pricingTable.setText(row, 2, dp + "");
|
|
|
224 |
pricingTable.setText(row, 3, tp + "");
|
|
|
225 |
item.getVendorPricings().get(vendorId)[Item.INDEX_MOP] = mop;
|
|
|
226 |
item.getVendorPricings().get(vendorId)[Item.INDEX_DP] = dp;
|
|
|
227 |
item.getVendorPricings().get(vendorId)[Item.INDEX_TP] = tp;
|
|
|
228 |
item.setMop(mop);
|
|
|
229 |
item.setDealerPrice(dp);
|
|
|
230 |
item.setTransferPrice(tp);
|
|
|
231 |
}
|
|
|
232 |
});
|
|
|
233 |
vpd.show();
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/*
|
|
|
237 |
@UiHandler("sellingPrice")
|
|
|
238 |
void onSPUpdate(KeyPressEvent keyPressEvent) {
|
|
|
239 |
if(Double.parseDouble(sellingPrice.getText()) != item.getSellingPrice()) {
|
|
|
240 |
sellingPrice.getElement().addClassName(style.fieldChanged());
|
|
|
241 |
} else {
|
|
|
242 |
sellingPrice.getElement().addClassName(style.greenLabel());
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
@UiHandler("mop")
|
|
|
247 |
void onMOPUpdate(KeyPressEvent keyPressEvent) {
|
|
|
248 |
if(Double.parseDouble(mop.getText()) != item.getMop()) {
|
|
|
249 |
mop.getElement().addClassName(style.fieldChanged());
|
|
|
250 |
} else {
|
|
|
251 |
mop.getElement().addClassName(style.greenLabel());
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
@UiHandler("dealerPrice")
|
|
|
256 |
void onDPUpdate(KeyPressEvent keyPressEvent) {
|
|
|
257 |
if(Double.parseDouble(dealerPrice.getText()) != item.getDealerPrice()) {
|
|
|
258 |
dealerPrice.getElement().addClassName(style.fieldChanged());
|
|
|
259 |
} else {
|
|
|
260 |
dealerPrice.getElement().addClassName(style.greenLabel());
|
|
|
261 |
}
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
@UiHandler("transferPrice")
|
|
|
265 |
void onTPUpdate(KeyPressEvent keyPressEvent) {
|
|
|
266 |
if(Double.parseDouble(transferPrice.getText()) != item.getTransferPrice()) {
|
|
|
267 |
transferPrice.getElement().addClassName(style.fieldChanged());
|
|
|
268 |
} else {
|
|
|
269 |
transferPrice.getElement().addClassName(style.greenLabel());
|
|
|
270 |
}
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
@UiHandler("weight")
|
|
|
274 |
void onWeightUpdate(KeyPressEvent keyPressEvent) {
|
|
|
275 |
if(Double.parseDouble(weight.getText()) != item.getWeight()) {
|
|
|
276 |
weight.getElement().addClassName(style.fieldChanged());
|
|
|
277 |
} else {
|
|
|
278 |
weight.getElement().addClassName(style.greenLabel());
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
void applyDefaultStyles() {
|
|
|
283 |
sellingPrice.getElement().addClassName(style.greenLabel());
|
|
|
284 |
mop.getElement().addClassName(style.greenLabel());
|
|
|
285 |
dealerPrice.getElement().addClassName(style.greenLabel());
|
|
|
286 |
transferPrice.getElement().addClassName(style.greenLabel());
|
|
|
287 |
weight.getElement().addClassName(style.greenLabel());
|
|
|
288 |
}*/
|
|
|
289 |
|
| 1961 |
ankur.sing |
290 |
}
|