Subversion Repositories SmartDukaan

Rev

Rev 1146 | Rev 2449 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
167 ashish 1
package in.shop2020.hotspot.dashbaord.client.inbox;
2
 
3
import in.shop2020.hotspot.dashbaord.client.event.AcceptOrderEvent;
487 rajveer 4
import in.shop2020.hotspot.dashbaord.client.event.NostockOrderEvent;
192 ashish 5
import in.shop2020.hotspot.dashbaord.client.event.ShippedOrderEvent;
306 ashish 6
import in.shop2020.hotspot.dashbaord.shared.actions.DetailsMask;
167 ashish 7
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
8
 
9
import org.enunes.gwt.mvp.client.EventBus;
10
 
11
import com.google.gwt.core.client.GWT;
12
import com.google.gwt.event.dom.client.ClickEvent;
13
import com.google.gwt.event.dom.client.ClickHandler;
14
import com.google.gwt.resources.client.CssResource;
15
import com.google.gwt.uibinder.client.UiBinder;
16
import com.google.gwt.uibinder.client.UiField;
487 rajveer 17
import com.google.gwt.user.client.Window;
306 ashish 18
import com.google.gwt.user.client.ui.Button;
167 ashish 19
import com.google.gwt.user.client.ui.FlexTable;
306 ashish 20
import com.google.gwt.user.client.ui.HorizontalPanel;
21
import com.google.gwt.user.client.ui.Label;
167 ashish 22
import com.google.gwt.user.client.ui.ResizeComposite;
306 ashish 23
import com.google.gwt.user.client.ui.VerticalPanel;
167 ashish 24
import com.google.gwt.user.client.ui.Widget;
25
 
26
public class OrderDetails extends ResizeComposite{
27
 
28
	public interface Listener{
29
		void onClick();
30
	}
31
 
585 chandransh 32
	interface OrderDetailsUiBinder extends UiBinder<Widget, OrderDetails>{ }
167 ashish 33
 
34
	interface SelectionStyle extends CssResource{
306 ashish 35
		String blueLabel();
36
		String greenLabel();
167 ashish 37
	}
38
 
585 chandransh 39
	private static final OrderDetailsUiBinder binder = GWT.create(OrderDetailsUiBinder.class);
167 ashish 40
 
41
	@UiField FlexTable header;
42
	@UiField FlexTable table;
306 ashish 43
	@UiField HorizontalPanel orderDetails;
44
	@UiField VerticalPanel orderDetails1;
45
	@UiField VerticalPanel orderDetails2;
46
	@UiField VerticalPanel orderDetails3;
47
	@UiField VerticalPanel orderDetails4;
48
	@UiField VerticalPanel orderDetails5;
49
	@UiField SelectionStyle selectionStyle;
167 ashish 50
 
51
 
52
	private final EventBus eventbus;
53
	private Order order;
54
	private Order transaction;
306 ashish 55
	private Button acceptOrder = new Button();
56
	private Button rejectOrder = new Button();
57
	private Button notAvailable= new Button();
58
	private Button addBillingInfo= new Button();
59
	private Button addShippingInfo= new Button();
60
	private Button markShipped= new Button();
61
	private Button printLabel = new Button();
677 chandransh 62
	private Button printManifest = new Button();
63
 
306 ashish 64
	private String user;
65
	private DetailsMask mask;
677 chandransh 66
	private long warehouseID;
167 ashish 67
 
677 chandransh 68
	public OrderDetails(EventBus eventbus, Order order, Order order2, DetailsMask mask, String user, long warehouseID){
167 ashish 69
		this.eventbus = eventbus;
70
		this.order = order;
71
		this.transaction = order2;
306 ashish 72
		this.mask = mask;
73
		this.user = user;
677 chandransh 74
		this.warehouseID = warehouseID;
167 ashish 75
		initWidget(binder.createAndBindUi(this));
76
		initTable();
306 ashish 77
		registerButtonHandlers();
78
		implementMask();
79
		loadOrderDetails();
167 ashish 80
	}
81
 
82
	private void initTable() {
83
		header.getColumnFormatter().setWidth(0, "128px");
306 ashish 84
	    header.getColumnFormatter().setWidth(1, "128px");
85
	    header.getColumnFormatter().setWidth(2, "128px");
86
	    header.getColumnFormatter().setWidth(3, "128px");
87
	    header.getColumnFormatter().setWidth(4, "128px");
677 chandransh 88
	    header.getColumnFormatter().setWidth(5, "128px");
89
	    header.getColumnFormatter().setWidth(6, "256px");
306 ashish 90
 
91
	    acceptOrder.setText("Accept");
92
	    rejectOrder.setText("Reject");
93
	    notAvailable.setText("Out Of Stock");
94
	    addBillingInfo.setText("Bill");
487 rajveer 95
	    printLabel.setText("Print Invoice");
677 chandransh 96
	    printManifest.setText("Print Manifest");
849 chandransh 97
	    printManifest.setVisible(false);
306 ashish 98
	    addShippingInfo.setText("Ship");
959 chandransh 99
	    addShippingInfo.setVisible(false);
306 ashish 100
	    markShipped.setText("Shipped");
486 rajveer 101
	    markShipped.setVisible(false);
102
 
306 ashish 103
	    header.setWidget(0, 0, acceptOrder);
487 rajveer 104
	    header.setWidget(0, 1, notAvailable);
105
	    header.setWidget(0, 2, printLabel);
106
	    header.setWidget(0, 3, addBillingInfo);
107
	    header.setWidget(0, 4, addShippingInfo);
677 chandransh 108
	    header.setWidget(0, 5, printManifest);
849 chandransh 109
	    header.setWidget(0, 5, markShipped);
110
	    header.setWidget(0, 6, rejectOrder);
677 chandransh 111
 
306 ashish 112
	    //addShippingInfo.setVisible(false);
113
	    //markShipped.setVisible(false);
114
	    /*
115
	    header.setText(0, 1, "Add Billing Details");
116
	    header.setText(0, 2, "Print shipping label");
117
	    header.setText(0, 3, "Prepare for Shipping ");
118
	    header.setText(0, 4, "Mark Shipped");
119
	    header.setText(0, 5, "View Order Details");
120
 
167 ashish 121
	    header.setText(0, 0, "Accept Order");
122
	    header.setText(0, 1, "Add Billing Details");
123
	    header.setText(0, 2, "Print shipping label");
124
	    header.setText(0, 3, "Prepare for Shipping ");
125
	    header.setText(0, 4, "Mark Shipped");
126
	    header.setText(0, 5, "View Order Details");
306 ashish 127
	    */ 
167 ashish 128
	}
129
 
306 ashish 130
	private void registerButtonHandlers(){
131
		acceptOrder.addClickHandler(new ClickHandler() {
132
 
133
			@Override
134
			public void onClick(ClickEvent event) {
135
				if(acceptOrder.isEnabled()){
136
					eventbus.fireEvent(new AcceptOrderEvent(order));
137
				}
138
			}
139
		});
140
 
486 rajveer 141
		rejectOrder.addClickHandler(new ClickHandler() {
142
 
143
			@Override
144
			public void onClick(ClickEvent event) {
145
				if(!notAvailable.isEnabled()) return;
146
				RejectReasonBox box = new RejectReasonBox(eventbus, order);
147
				//box.clear();
148
				box.center();			
149
			}
150
		});
151
 
487 rajveer 152
		notAvailable.addClickHandler(new ClickHandler() {
153
 
154
			@Override
155
			public void onClick(ClickEvent event) {
156
				eventbus.fireEvent(new NostockOrderEvent(order));
157
			}
158
		});
159
 
306 ashish 160
		addBillingInfo.addClickHandler(new ClickHandler() {
161
 
162
			@Override
163
			public void onClick(ClickEvent event) {
1146 chandransh 164
				if(!addBillingInfo.isEnabled())
165
					return;
306 ashish 166
				BillingInfoBox box = new BillingInfoBox(eventbus, order, user);
167
				box.center();				
168
			}
169
		});
487 rajveer 170
 
306 ashish 171
		printLabel.addClickHandler(new ClickHandler() {
172
 
173
			@Override
174
			public void onClick(ClickEvent event) {
1146 chandransh 175
				if(!printLabel.isEnabled())
176
					return;
177
				if(order.getJacketNumber()==0){
178
					JacketInfoBox box = new JacketInfoBox(eventbus, order);
179
					//box.clean();
180
					box.center();
181
				}else{
182
					String invoiceGenerationUrl = "http://" + Window.Location.getHost() + "/Support/invoice/";
183
					invoiceGenerationUrl = invoiceGenerationUrl + order.getOrderId();
184
					Window.open(invoiceGenerationUrl, "newWindowName", "window features.");
185
				}
306 ashish 186
			}
187
		});
487 rajveer 188
 
677 chandransh 189
		printManifest.addClickHandler(new ClickHandler() {
190
 
191
			@Override
192
			public void onClick(ClickEvent event) {
193
				ProviderInfoBox box = new ProviderInfoBox(eventbus, user, warehouseID);
194
				//box.clear();
760 chandransh 195
				box.center();
677 chandransh 196
			}
197
		});
198
 
306 ashish 199
		addShippingInfo.addClickHandler(new ClickHandler() {
200
 
201
			@Override
202
			public void onClick(ClickEvent event) {
203
				if(!addShippingInfo.isEnabled()) return;
204
				ShipmentInfoBox box = new ShipmentInfoBox(eventbus, order);
205
				//box.clear();
206
				box.center();			
207
			}
208
		});
209
		markShipped.addClickHandler(new ClickHandler() {
210
 
211
			@Override
212
			public void onClick(ClickEvent event) {			
213
				if(!markShipped.isEnabled()) return;
214
				eventbus.fireEvent(new ShippedOrderEvent(order, "", "", "", false));
215
			}
216
		});
217
 
218
	}
219
	/*
167 ashish 220
	private void registerhandlers(){
221
		header.addClickHandler(new ClickHandler() {
222
 
223
			@Override
224
			public void onClick(ClickEvent event) {
225
 
226
				Cell cell = header.getCellForEvent(event);
227
 
228
				int columnIndex = cell.getCellIndex();
229
 
230
				if(columnIndex == 0){
231
					//accept orders
232
					eventbus.fireEvent(new AcceptOrderEvent(order));
233
				}
234
 
235
				if(columnIndex == 1){
236
					//generate billing information
192 ashish 237
					BillingInfoBox box = new BillingInfoBox(eventbus, order);
167 ashish 238
					box.clear();
239
					box.center();
240
				}
241
 
242
				if(columnIndex == 2){
243
					eventbus.fireEvent(new AddressLabelEvent(order));
244
				}
245
 
246
				if(columnIndex == 3){
192 ashish 247
					ShipmentInfoBox box = new ShipmentInfoBox(eventbus, order);
167 ashish 248
					box.clear();
249
					box.center();
250
				}
251
 
252
				if(columnIndex == 4){
192 ashish 253
 
254
					eventbus.fireEvent(new ShippedOrderEvent(order, "", "", "", false));
255
 
167 ashish 256
				}
257
			}
258
		});
259
	}
306 ashish 260
*/
261
	private void implementMask(){
262
		switch(mask){
263
		case NEW:
677 chandransh 264
			maskButtons(true, true, true, false, false, false, false, true);
306 ashish 265
			break;
266
		case ACCEPT:
677 chandransh 267
			maskButtons(false, false, false, false, true, false, false, true);
306 ashish 268
			break;
486 rajveer 269
		case REJECT:
677 chandransh 270
			maskButtons(false, false, false, false, false, false, false, true);
486 rajveer 271
			break;
306 ashish 272
		case BILL:
677 chandransh 273
			maskButtons(false, false, false, true, false, true, true, true);
306 ashish 274
			break;
275
		case SHIP:
677 chandransh 276
			maskButtons(false, false, false, false, false, false, false, true);
306 ashish 277
			break;
487 rajveer 278
		case NO_STOCK:
677 chandransh 279
			maskButtons(true, true, false, false, false, false, false, true);
487 rajveer 280
			break;
281
 
306 ashish 282
		}
283
	}
284
 
677 chandransh 285
	private void maskButtons(boolean accept, boolean reject, boolean notavailable, boolean print, boolean billing, boolean shipping, boolean mark, boolean manifest){
306 ashish 286
		acceptOrder.setEnabled(accept);
287
		rejectOrder.setEnabled(reject);
288
		notAvailable.setEnabled(notavailable);
289
		printLabel.setEnabled(print);
677 chandransh 290
		printManifest.setEnabled(manifest);
306 ashish 291
		addBillingInfo.setEnabled(billing);
292
		addShippingInfo.setEnabled(shipping);
293
		markShipped.setEnabled(mark);		
294
	}
295
 
296
	private void loadOrderDetails(){
966 chandransh 297
		orderDetails1.add(getHorizontalPanel("PRODUCT GROUP: ", transaction.getProductGroup()));
298
		orderDetails1.add(getHorizontalPanel("BRAND:   	     ", transaction.getBrand()));
299
		orderDetails1.add(getHorizontalPanel("MODEL:         ", getModelDisplayName(transaction)));
300
		orderDetails1.add(getHorizontalPanel("Item ID:       ", transaction.getItemId()+""));
301
		orderDetails1.add(getHorizontalPanel("EXTRA INFO:    ", transaction.getExtraInfo()));
306 ashish 302
 
966 chandransh 303
		orderDetails2.add(getHorizontalPanel("NAME:          ", transaction.getCustomerName()));
304
		orderDetails2.add(getHorizontalPanel("ADDRESS:       ", getDisplayAddress(transaction)));
305
		orderDetails2.add(getHorizontalPanel("MOBILE NUMBER: ", transaction.getCustomerMobileNumber()));
306 ashish 306
 
966 chandransh 307
		orderDetails3.add(getHorizontalPanel("TOTAL WEIGHT:      ", transaction.getTotalWeight()+""));
308
		orderDetails3.add(getHorizontalPanel("TOTAL AMOUNT(Rs):  ", transaction.getTotalAmount()+""));
306 ashish 309
 
966 chandransh 310
		orderDetails4.add(getHorizontalPanel("AIRWAY BILL NO:  ", transaction.getAirwayBillNo()));
311
		orderDetails4.add(getHorizontalPanel("INVOICE NUMBER:  ", transaction.getInvoiceNumber()));
312
		orderDetails4.add(getHorizontalPanel("JACKET NUMBER:   ", transaction.getJacketNumber() + ""));
313
		orderDetails4.add(getHorizontalPanel("BILLED BY:       ", transaction.getBilledBy()));		
314
	}
639 chandransh 315
 
966 chandransh 316
	private HorizontalPanel getHorizontalPanel(String labelText, String valueText) {
317
		HorizontalPanel hpanel = new HorizontalPanel();
639 chandransh 318
		hpanel.setSpacing(5);
966 chandransh 319
		hpanel.add(new Label(labelText));
320
		hpanel.add(new Label(valueText));
639 chandransh 321
		hpanel.setCellWidth(hpanel.getWidget(0), "128px");
322
		hpanel.setCellWidth(hpanel.getWidget(1), "128px");
323
		hpanel.getWidget(0).setStyleName(selectionStyle.blueLabel());
324
		hpanel.getWidget(1).setStyleName(selectionStyle.greenLabel());
966 chandransh 325
		return hpanel;
326
	}
306 ashish 327
 
966 chandransh 328
	private String getModelDisplayName(Order order){
329
		String modelName = "";
330
		if(order.getModelName()!=null)
331
			modelName = order.getModelName() + " ";
332
		if(order.getModelNumber()!=null)
333
			modelName = modelName + order.getModelNumber();
334
		if(order.getColor()!=null)
335
			modelName = modelName + " (" + order.getColor() + ")";
336
		return modelName;
306 ashish 337
	}
966 chandransh 338
 
339
	private String getDisplayAddress(Order order){
340
		StringBuilder displayAddress = new StringBuilder();
341
		displayAddress.append(order.getCustomerAddress1() + "\n");
342
		displayAddress.append(order.getCustomerAddress2() + "\n");
343
		displayAddress.append(order.getCustomerCity() + "\n");
344
		displayAddress.append(order.getCustomerState() + "   PIN - " +  order.getCustomerPincode());
345
		return displayAddress.toString();
346
	}
167 ashish 347
}