Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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) {
164
				if(!addBillingInfo.isEnabled()) return;
165
				BillingInfoBox box = new BillingInfoBox(eventbus, order, user);
166
				//box.clear();
167
				box.center();				
168
			}
169
		});
487 rajveer 170
 
306 ashish 171
		printLabel.addClickHandler(new ClickHandler() {
172
 
173
			@Override
174
			public void onClick(ClickEvent event) {
892 chandransh 175
				String invoiceGenerationUrl = "http://" + Window.Location.getHost() + "/Support/invoice/";
493 rajveer 176
				invoiceGenerationUrl = invoiceGenerationUrl + order.getOrderId();
177
				Window.open(invoiceGenerationUrl, "newWindowName", "window features.");
306 ashish 178
			}
179
		});
487 rajveer 180
 
677 chandransh 181
		printManifest.addClickHandler(new ClickHandler() {
182
 
183
			@Override
184
			public void onClick(ClickEvent event) {
185
				ProviderInfoBox box = new ProviderInfoBox(eventbus, user, warehouseID);
186
				//box.clear();
760 chandransh 187
				box.center();
677 chandransh 188
			}
189
		});
190
 
306 ashish 191
		addShippingInfo.addClickHandler(new ClickHandler() {
192
 
193
			@Override
194
			public void onClick(ClickEvent event) {
195
				if(!addShippingInfo.isEnabled()) return;
196
				ShipmentInfoBox box = new ShipmentInfoBox(eventbus, order);
197
				//box.clear();
198
				box.center();			
199
			}
200
		});
201
		markShipped.addClickHandler(new ClickHandler() {
202
 
203
			@Override
204
			public void onClick(ClickEvent event) {			
205
				if(!markShipped.isEnabled()) return;
206
				eventbus.fireEvent(new ShippedOrderEvent(order, "", "", "", false));
207
			}
208
		});
209
 
210
	}
211
	/*
167 ashish 212
	private void registerhandlers(){
213
		header.addClickHandler(new ClickHandler() {
214
 
215
			@Override
216
			public void onClick(ClickEvent event) {
217
 
218
				Cell cell = header.getCellForEvent(event);
219
 
220
				int columnIndex = cell.getCellIndex();
221
 
222
				if(columnIndex == 0){
223
					//accept orders
224
					eventbus.fireEvent(new AcceptOrderEvent(order));
225
				}
226
 
227
				if(columnIndex == 1){
228
					//generate billing information
192 ashish 229
					BillingInfoBox box = new BillingInfoBox(eventbus, order);
167 ashish 230
					box.clear();
231
					box.center();
232
				}
233
 
234
				if(columnIndex == 2){
235
					eventbus.fireEvent(new AddressLabelEvent(order));
236
				}
237
 
238
				if(columnIndex == 3){
192 ashish 239
					ShipmentInfoBox box = new ShipmentInfoBox(eventbus, order);
167 ashish 240
					box.clear();
241
					box.center();
242
				}
243
 
244
				if(columnIndex == 4){
192 ashish 245
 
246
					eventbus.fireEvent(new ShippedOrderEvent(order, "", "", "", false));
247
 
167 ashish 248
				}
249
			}
250
		});
251
	}
306 ashish 252
*/
253
	private void implementMask(){
254
		switch(mask){
255
		case NEW:
677 chandransh 256
			maskButtons(true, true, true, false, false, false, false, true);
306 ashish 257
			break;
258
		case ACCEPT:
677 chandransh 259
			maskButtons(false, false, false, false, true, false, false, true);
306 ashish 260
			break;
486 rajveer 261
		case REJECT:
677 chandransh 262
			maskButtons(false, false, false, false, false, false, false, true);
486 rajveer 263
			break;
306 ashish 264
		case BILL:
677 chandransh 265
			maskButtons(false, false, false, true, false, true, true, true);
306 ashish 266
			break;
267
		case SHIP:
677 chandransh 268
			maskButtons(false, false, false, false, false, false, false, true);
306 ashish 269
			break;
487 rajveer 270
		case NO_STOCK:
677 chandransh 271
			maskButtons(true, true, false, false, false, false, false, true);
487 rajveer 272
			break;
273
 
306 ashish 274
		}
275
	}
276
 
677 chandransh 277
	private void maskButtons(boolean accept, boolean reject, boolean notavailable, boolean print, boolean billing, boolean shipping, boolean mark, boolean manifest){
306 ashish 278
		acceptOrder.setEnabled(accept);
279
		rejectOrder.setEnabled(reject);
280
		notAvailable.setEnabled(notavailable);
281
		printLabel.setEnabled(print);
677 chandransh 282
		printManifest.setEnabled(manifest);
306 ashish 283
		addBillingInfo.setEnabled(billing);
284
		addShippingInfo.setEnabled(shipping);
285
		markShipped.setEnabled(mark);		
286
	}
287
 
288
	private void loadOrderDetails(){
966 chandransh 289
		orderDetails1.add(getHorizontalPanel("PRODUCT GROUP: ", transaction.getProductGroup()));
290
		orderDetails1.add(getHorizontalPanel("BRAND:   	     ", transaction.getBrand()));
291
		orderDetails1.add(getHorizontalPanel("MODEL:         ", getModelDisplayName(transaction)));
292
		orderDetails1.add(getHorizontalPanel("Item ID:       ", transaction.getItemId()+""));
293
		orderDetails1.add(getHorizontalPanel("EXTRA INFO:    ", transaction.getExtraInfo()));
306 ashish 294
 
966 chandransh 295
		orderDetails2.add(getHorizontalPanel("NAME:          ", transaction.getCustomerName()));
296
		orderDetails2.add(getHorizontalPanel("ADDRESS:       ", getDisplayAddress(transaction)));
297
		orderDetails2.add(getHorizontalPanel("MOBILE NUMBER: ", transaction.getCustomerMobileNumber()));
306 ashish 298
 
966 chandransh 299
		orderDetails3.add(getHorizontalPanel("TOTAL WEIGHT:      ", transaction.getTotalWeight()+""));
300
		orderDetails3.add(getHorizontalPanel("TOTAL AMOUNT(Rs):  ", transaction.getTotalAmount()+""));
306 ashish 301
 
966 chandransh 302
		orderDetails4.add(getHorizontalPanel("AIRWAY BILL NO:  ", transaction.getAirwayBillNo()));
303
		orderDetails4.add(getHorizontalPanel("INVOICE NUMBER:  ", transaction.getInvoiceNumber()));
304
		orderDetails4.add(getHorizontalPanel("JACKET NUMBER:   ", transaction.getJacketNumber() + ""));
305
		orderDetails4.add(getHorizontalPanel("BILLED BY:       ", transaction.getBilledBy()));		
306
	}
639 chandransh 307
 
966 chandransh 308
	private HorizontalPanel getHorizontalPanel(String labelText, String valueText) {
309
		HorizontalPanel hpanel = new HorizontalPanel();
639 chandransh 310
		hpanel.setSpacing(5);
966 chandransh 311
		hpanel.add(new Label(labelText));
312
		hpanel.add(new Label(valueText));
639 chandransh 313
		hpanel.setCellWidth(hpanel.getWidget(0), "128px");
314
		hpanel.setCellWidth(hpanel.getWidget(1), "128px");
315
		hpanel.getWidget(0).setStyleName(selectionStyle.blueLabel());
316
		hpanel.getWidget(1).setStyleName(selectionStyle.greenLabel());
966 chandransh 317
		return hpanel;
318
	}
306 ashish 319
 
966 chandransh 320
	private String getModelDisplayName(Order order){
321
		String modelName = "";
322
		if(order.getModelName()!=null)
323
			modelName = order.getModelName() + " ";
324
		if(order.getModelNumber()!=null)
325
			modelName = modelName + order.getModelNumber();
326
		if(order.getColor()!=null)
327
			modelName = modelName + " (" + order.getColor() + ")";
328
		return modelName;
306 ashish 329
	}
966 chandransh 330
 
331
	private String getDisplayAddress(Order order){
332
		StringBuilder displayAddress = new StringBuilder();
333
		displayAddress.append(order.getCustomerAddress1() + "\n");
334
		displayAddress.append(order.getCustomerAddress2() + "\n");
335
		displayAddress.append(order.getCustomerCity() + "\n");
336
		displayAddress.append(order.getCustomerState() + "   PIN - " +  order.getCustomerPincode());
337
		return displayAddress.toString();
338
	}
167 ashish 339
}