Subversion Repositories SmartDukaan

Rev

Rev 3366 | Rev 3473 | 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
 
2610 chandransh 3
import in.shop2020.hotspot.dashbaord.client.event.ReceiveReturnEvent;
167 ashish 4
import in.shop2020.hotspot.dashbaord.client.event.AcceptOrderEvent;
487 rajveer 5
import in.shop2020.hotspot.dashbaord.client.event.NostockOrderEvent;
2509 chandransh 6
import in.shop2020.hotspot.dashbaord.client.event.FlagOrderEvent;
2513 chandransh 7
import in.shop2020.hotspot.dashbaord.client.event.RequestPickupEvent;
2628 chandransh 8
import in.shop2020.hotspot.dashbaord.client.event.ReshipOrderEvent;
3065 chandransh 9
import in.shop2020.hotspot.dashbaord.client.event.VerifyOrderEvent;
2843 chandransh 10
import in.shop2020.hotspot.dashbaord.shared.actions.BillingType;
306 ashish 11
import in.shop2020.hotspot.dashbaord.shared.actions.DetailsMask;
167 ashish 12
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
2835 chandransh 13
import in.shop2020.hotspot.dashbaord.shared.actions.UserType;
167 ashish 14
 
15
import org.enunes.gwt.mvp.client.EventBus;
16
 
17
import com.google.gwt.core.client.GWT;
18
import com.google.gwt.event.dom.client.ClickEvent;
19
import com.google.gwt.event.dom.client.ClickHandler;
20
import com.google.gwt.resources.client.CssResource;
21
import com.google.gwt.uibinder.client.UiBinder;
22
import com.google.gwt.uibinder.client.UiField;
487 rajveer 23
import com.google.gwt.user.client.Window;
306 ashish 24
import com.google.gwt.user.client.ui.Button;
167 ashish 25
import com.google.gwt.user.client.ui.FlexTable;
306 ashish 26
import com.google.gwt.user.client.ui.HorizontalPanel;
27
import com.google.gwt.user.client.ui.Label;
167 ashish 28
import com.google.gwt.user.client.ui.ResizeComposite;
306 ashish 29
import com.google.gwt.user.client.ui.VerticalPanel;
167 ashish 30
import com.google.gwt.user.client.ui.Widget;
31
 
32
public class OrderDetails extends ResizeComposite{
33
 
34
	public interface Listener{
35
		void onClick();
36
	}
37
 
585 chandransh 38
	interface OrderDetailsUiBinder extends UiBinder<Widget, OrderDetails>{ }
167 ashish 39
 
40
	interface SelectionStyle extends CssResource{
306 ashish 41
		String blueLabel();
42
		String greenLabel();
167 ashish 43
	}
44
 
585 chandransh 45
	private static final OrderDetailsUiBinder binder = GWT.create(OrderDetailsUiBinder.class);
167 ashish 46
 
47
	@UiField FlexTable header;
48
	@UiField FlexTable table;
306 ashish 49
	@UiField HorizontalPanel orderDetails;
50
	@UiField VerticalPanel orderDetails1;
51
	@UiField VerticalPanel orderDetails2;
52
	@UiField VerticalPanel orderDetails3;
53
	@UiField VerticalPanel orderDetails4;
54
	@UiField VerticalPanel orderDetails5;
55
	@UiField SelectionStyle selectionStyle;
167 ashish 56
 
57
 
58
	private final EventBus eventbus;
59
	private Order order;
60
	private Order transaction;
2509 chandransh 61
 
3065 chandransh 62
	//Buttons for the Warehouse Executive
63
	private Button verifyOrder = new Button();
306 ashish 64
	private Button acceptOrder = new Button();
65
	private Button rejectOrder = new Button();
66
	private Button notAvailable= new Button();
67
	private Button addBillingInfo= new Button();
2449 chandransh 68
	private Button printInvoice = new Button();
2610 chandransh 69
	private Button receiveReturn = new Button();
2509 chandransh 70
	private Button validateDOA = new Button();
677 chandransh 71
 
3463 chandransh 72
	//Buttons for the Admin to track order
2509 chandransh 73
	private Button flagOrder = new Button();
74
	private Button requestPickup = new Button();
75
	private Button authorizePickup = new Button();
76
	private Button refundOrder = new Button();
77
	private Button reshipOrder = new Button();	
78
 
3463 chandransh 79
	//Buttons for the Admin to edit order details
80
	private Button addWeight = new Button();
81
	private Button changeColor = new Button();
82
	private Button shiftWarehouse = new Button();
83
 
306 ashish 84
	private String user;
85
	private DetailsMask mask;
677 chandransh 86
	private long warehouseID;
2835 chandransh 87
	private UserType userType;
2843 chandransh 88
	private BillingType billingType;
167 ashish 89
 
2843 chandransh 90
	public OrderDetails(EventBus eventbus, Order order, Order order2, DetailsMask mask, String user, long warehouseID, UserType userType, BillingType billingType){
167 ashish 91
		this.eventbus = eventbus;
92
		this.order = order;
93
		this.transaction = order2;
306 ashish 94
		this.mask = mask;
95
		this.user = user;
677 chandransh 96
		this.warehouseID = warehouseID;
2835 chandransh 97
		this.userType = userType;
2843 chandransh 98
		this.billingType = billingType;
2449 chandransh 99
 
167 ashish 100
		initWidget(binder.createAndBindUi(this));
2558 chandransh 101
		initTableForWE();
2835 chandransh 102
		if(this.userType == UserType.ADMIN){
2509 chandransh 103
			initTableForAdmin();
104
		}
306 ashish 105
		loadOrderDetails();
167 ashish 106
	}
107
 
2509 chandransh 108
	private void initTableForWE() {
167 ashish 109
		header.getColumnFormatter().setWidth(0, "128px");
306 ashish 110
	    header.getColumnFormatter().setWidth(1, "128px");
111
	    header.getColumnFormatter().setWidth(2, "128px");
112
	    header.getColumnFormatter().setWidth(3, "128px");
113
	    header.getColumnFormatter().setWidth(4, "128px");
677 chandransh 114
	    header.getColumnFormatter().setWidth(5, "128px");
115
	    header.getColumnFormatter().setWidth(6, "256px");
306 ashish 116
 
3065 chandransh 117
	    verifyOrder.setText("Verify");
306 ashish 118
	    acceptOrder.setText("Accept");
119
	    notAvailable.setText("Out Of Stock");
120
	    addBillingInfo.setText("Bill");
2843 chandransh 121
	    if(billingType == BillingType.OURS)
122
	        addBillingInfo.setVisible(false);
2449 chandransh 123
	    printInvoice.setText("Print Invoice");
2610 chandransh 124
	    receiveReturn.setText("Receive Return");
2509 chandransh 125
	    validateDOA.setText("Validate DOA");
486 rajveer 126
 
3065 chandransh 127
	    header.setWidget(0, 0, verifyOrder);
128
	    header.setWidget(0, 1, acceptOrder);
129
	    header.setWidget(0, 2, notAvailable);
130
	    header.setWidget(0, 3, addBillingInfo);
131
	    header.setWidget(0, 4, printInvoice);
132
	    header.setWidget(0, 5, receiveReturn);
133
	    header.setWidget(0, 6, validateDOA);
2509 chandransh 134
 
135
	    registerButtonHandlersForWE();
136
		implementMaskForWE();
167 ashish 137
	}
138
 
2509 chandransh 139
	private void registerButtonHandlersForWE(){
3065 chandransh 140
	    verifyOrder.addClickHandler(new ClickHandler() {
141
 
142
            @Override
143
            public void onClick(ClickEvent event) {
144
                if(verifyOrder.isEnabled()){
145
                    GWT.log("Verify order event fired");
146
                    eventbus.fireEvent(new VerifyOrderEvent(order));
147
                }
148
            }
149
        });
150
 
306 ashish 151
		acceptOrder.addClickHandler(new ClickHandler() {
152
 
153
			@Override
154
			public void onClick(ClickEvent event) {
2558 chandransh 155
				if(acceptOrder.isEnabled())
306 ashish 156
					eventbus.fireEvent(new AcceptOrderEvent(order));
157
			}
158
		});
486 rajveer 159
 
487 rajveer 160
		notAvailable.addClickHandler(new ClickHandler() {
161
 
162
			@Override
163
			public void onClick(ClickEvent event) {
2558 chandransh 164
				if(notAvailable.isEnabled())
165
					eventbus.fireEvent(new NostockOrderEvent(order));
487 rajveer 166
			}
167
		});
168
 
306 ashish 169
		addBillingInfo.addClickHandler(new ClickHandler() {
170
 
171
			@Override
172
			public void onClick(ClickEvent event) {
1146 chandransh 173
				if(!addBillingInfo.isEnabled())
174
					return;
306 ashish 175
				BillingInfoBox box = new BillingInfoBox(eventbus, order, user);
176
				box.center();				
177
			}
178
		});
487 rajveer 179
 
2449 chandransh 180
		printInvoice.addClickHandler(new ClickHandler() {
306 ashish 181
 
182
			@Override
183
			public void onClick(ClickEvent event) {
2449 chandransh 184
				if(!printInvoice.isEnabled())
1146 chandransh 185
					return;
186
				if(order.getJacketNumber()==0){
2843 chandransh 187
					JacketInfoBox box = new JacketInfoBox(eventbus, order, user, billingType);
1146 chandransh 188
					//box.clean();
189
					box.center();
190
				}else{
2908 chandransh 191
					String invoiceGenerationUrl = "http://" + Window.Location.getHost() + Window.Location.getPath() + "invoice/";
2843 chandransh 192
					invoiceGenerationUrl += "?id=" +order.getOrderId();
193
					if(billingType == BillingType.OURS)
194
					    invoiceGenerationUrl += "&withBill=true";
195
					else
196
					    invoiceGenerationUrl += "&withBill=false";
1146 chandransh 197
					Window.open(invoiceGenerationUrl, "newWindowName", "window features.");
198
				}
306 ashish 199
			}
200
		});
2588 chandransh 201
 
2610 chandransh 202
		receiveReturn.addClickHandler(new ClickHandler() {
2588 chandransh 203
 
204
			@Override
205
			public void onClick(ClickEvent event) {
2610 chandransh 206
				if(receiveReturn.isEnabled())
207
					eventbus.fireEvent(new ReceiveReturnEvent(order));
2588 chandransh 208
			}
209
		});
210
 
211
		validateDOA.addClickHandler(new ClickHandler() {
212
 
213
			@Override
214
			public void onClick(ClickEvent event) {
215
				if(!validateDOA.isEnabled())
216
					return;
217
				DoaValidationBox box = new DoaValidationBox(eventbus, order);
218
				box.center();
219
			}
220
		});
2449 chandransh 221
	}
487 rajveer 222
 
2509 chandransh 223
	private void implementMaskForWE(){
306 ashish 224
		switch(mask){
3065 chandransh 225
		case VERIFICATION_PENDING:
226
		    maskButtonsForWE(true, false, false, false, false, false, false, false); //Allow the WE to verify the order.
227
		    break;
306 ashish 228
		case NEW:
3065 chandransh 229
			maskButtonsForWE(false, true, true, true, false, false, false, false);  //Allow the WE to either accept the order or mark it as out of stock.
306 ashish 230
			break;
231
		case ACCEPT:
2843 chandransh 232
		    //TODO: Mask buttons based on the billingType
233
		    if(billingType == BillingType.OURS)
3065 chandransh 234
		        maskButtonsForWE(false, false, false, false, true, true, false, false); // For our billing, allow the WE to directly print the invoive.
2843 chandransh 235
		    else
3065 chandransh 236
		        maskButtonsForWE(false, false, false, false, false, true, false, false); //For external billing, allow the WE to feed the invoice info.
306 ashish 237
			break;
486 rajveer 238
		case REJECT:
3065 chandransh 239
			maskButtonsForWE(false, false, false, false, false, false, false, false); //Can't do anything once the order has been rejected.
486 rajveer 240
			break;
306 ashish 241
		case BILL:
3065 chandransh 242
			maskButtonsForWE(false, false, false, false, true, false, false, false); //Allow WE to print the invoice for a billed order.
306 ashish 243
			break;
244
		case SHIP:
3065 chandransh 245
			maskButtonsForWE(false, false, false, false, false, false, false, false);
306 ashish 246
			break;
487 rajveer 247
		case NO_STOCK:
3065 chandransh 248
			maskButtonsForWE(false, true, true, false, false, false, false, false); //Allow WE to accept a low inventory item. Reject has been allowed but this button is no longer visible.
487 rajveer 249
			break;
2509 chandransh 250
		case DOA_AWAITED:
2610 chandransh 251
		case SALES_RETURN_AWAITED:
3065 chandransh 252
			maskButtonsForWE(false, false, false, false, false, false, true, false); //Allow WE to accept the packet.
2509 chandransh 253
			break;
2610 chandransh 254
		case DOA_RECEIVED:
3065 chandransh 255
			maskButtonsForWE(false, false, false, false, false, false, false, true); //Allow WE to validate the DOA certificate.
2509 chandransh 256
			break;
2558 chandransh 257
		default:
3065 chandransh 258
			maskButtonsForWE(false, false, false, false, false, false, false, false); //Unknown state, let's disallow any untoward actions.
2558 chandransh 259
			break;
306 ashish 260
		}
261
	}
262
 
3065 chandransh 263
	private void maskButtonsForWE(boolean verify, boolean accept, boolean reject, boolean notavailable, boolean printInv, boolean billing, boolean acceptdoa, boolean validatedoa){
264
	    verifyOrder.setEnabled(verify);
265
	    acceptOrder.setEnabled(accept);
306 ashish 266
		notAvailable.setEnabled(notavailable);
2449 chandransh 267
		printInvoice.setEnabled(printInv);
306 ashish 268
		addBillingInfo.setEnabled(billing);
2610 chandransh 269
		receiveReturn.setEnabled(acceptdoa);
2509 chandransh 270
		validateDOA.setEnabled(validatedoa);
271
		rejectOrder.setEnabled(reject);
306 ashish 272
	}
2509 chandransh 273
 
274
	private void initTableForAdmin() {
275
	    if(transaction.isDoaFlag()){
276
	    	flagOrder.setText("Unflag");
277
	    } else {
278
	    	flagOrder.setText("Flag");
279
	    }
280
 
281
	    requestPickup.setText("Request Pick-up No");
282
	    authorizePickup.setText("Authorize Pick-up");
283
	    reshipOrder.setText("Reship");
284
	    refundOrder.setText("Refund");
285
 
2558 chandransh 286
	    header.setWidget(1, 0, flagOrder);
287
	    header.setWidget(1, 1, requestPickup);
288
	    header.setWidget(1, 2, authorizePickup);
289
	    header.setWidget(1, 3, reshipOrder);
290
	    header.setWidget(1, 6, refundOrder);
2509 chandransh 291
 
3463 chandransh 292
	    addWeight.setText("Add weight");
293
	    changeColor.setText("Change Color");
294
	    shiftWarehouse.setText("Shift Warehouse");
295
 
296
	    header.setWidget(2, 0, addWeight);
297
	    header.setWidget(2, 1, changeColor);
298
	    header.setWidget(2, 6, shiftWarehouse);
299
 
300
	    if(order.getTotalWeight() != 0)
301
	        addWeight.setEnabled(false);
302
 
2509 chandransh 303
	    registerButtonHandlersForAdmin();
3366 chandransh 304
		if(transaction.isCod())
305
		    implementCodMaskForAdmin();
306
		else
307
		    implementMaskForAdmin();
2509 chandransh 308
	}
306 ashish 309
 
2509 chandransh 310
	private void registerButtonHandlersForAdmin(){
311
		flagOrder.addClickHandler(new ClickHandler() {
312
 
313
			@Override
314
			public void onClick(ClickEvent event) {
315
				if(flagOrder.isEnabled()){
316
					eventbus.fireEvent(new FlagOrderEvent(order));
317
				}
318
			}
319
		});
320
 
321
		requestPickup.addClickHandler(new ClickHandler() {
322
 
323
			@Override
324
			public void onClick(ClickEvent event) {
2513 chandransh 325
				if(requestPickup.isEnabled()){
326
					GWT.log("Raising a pickup request for: " + order.getOrderId());
327
					eventbus.fireEvent(new RequestPickupEvent(order));
328
				}
2509 chandransh 329
			}
330
		});
331
 
332
		authorizePickup.addClickHandler(new ClickHandler() {
333
 
334
			@Override
335
			public void onClick(ClickEvent event) {
2526 chandransh 336
				if(!authorizePickup.isEnabled())
337
					return;
338
				PickupAuthorizationInfoBox box = new PickupAuthorizationInfoBox(eventbus, order);
339
				box.center();
2509 chandransh 340
			}
341
		});
342
 
2628 chandransh 343
		reshipOrder.addClickHandler(new ClickHandler() {
344
 
345
			@Override
346
			public void onClick(ClickEvent event) {
347
				if(reshipOrder.isEnabled()){
348
					GWT.log("Reshipping the order: " + order.getOrderId());
349
					eventbus.fireEvent(new ReshipOrderEvent(order));
350
				}
351
			}
352
		});
353
 
2509 chandransh 354
		refundOrder.addClickHandler(new ClickHandler() {
355
 
356
			@Override
357
			public void onClick(ClickEvent event) {
2747 chandransh 358
				if(refundOrder.isEnabled()){
359
					RejectReasonBox box = new RejectReasonBox(eventbus, order, user);
2558 chandransh 360
					//box.clear();
361
					box.center();	
362
				}
2509 chandransh 363
			}
364
		});
3463 chandransh 365
 
366
		addWeight.addClickHandler(new ClickHandler() {
367
 
368
            @Override
369
            public void onClick(ClickEvent event) {
370
                if(addWeight.isEnabled()){
371
                    AddWeightBox box = new AddWeightBox(eventbus, order);
372
                    box.center();
373
                }
374
            }
375
        });
376
 
377
		changeColor.addClickHandler(new ClickHandler() {
378
 
379
            @Override
380
            public void onClick(ClickEvent event) {
381
 
382
            }
383
        });
384
 
385
		shiftWarehouse.addClickHandler(new ClickHandler() {
386
 
387
            @Override
388
            public void onClick(ClickEvent event) {
389
 
390
            }
391
        });
2509 chandransh 392
	}
393
 
394
	private void implementMaskForAdmin(){
395
		switch(mask){
3186 chandransh 396
		case VERIFICATION_PENDING:
2558 chandransh 397
		case NO_STOCK:
3186 chandransh 398
			maskButtonsForAdmin(false, false, false, false, true); //Allow the OM to refund a COD order or an order with low inventory.
2558 chandransh 399
			break;
2509 chandransh 400
		case DELIVERED:
401
			maskButtonsForAdmin(true, true, false, false, false);	//Allow the OM to flag and request pickup.
402
			break;
403
		case DOA_PICKUP_REQUESTED:
404
			maskButtonsForAdmin(true, true, true, false, false);	//Allow the OM to either re-request a pickup no. or authorize pickup by entering one
405
			break;
2610 chandransh 406
		case DOA_RETURNED:
2509 chandransh 407
		case SALES_RETURNED:
408
			maskButtonsForAdmin(false, false, false, true, true);	//Allow the OM to either reship the order or refund it
409
			break;
2558 chandransh 410
		default:
411
			maskButtonsForAdmin(false, false, false, false, false);	//Unknown state. Let's not allow any untoward actions.
412
			break;
2509 chandransh 413
		}
414
	}
415
 
3366 chandransh 416
	private void implementCodMaskForAdmin(){
417
        switch(mask){
418
        case VERIFICATION_PENDING:
419
        case NEW:
420
        case NO_STOCK:
421
        case ACCEPT:
422
        case BILL:
423
            maskButtonsForAdmin(false, false, false, false, true); //Allow the OM to refund a COD order or an order with low inventory.
424
            break;
425
        default:
426
            implementMaskForAdmin();
427
        }
428
    }
429
 
2509 chandransh 430
	private void maskButtonsForAdmin(boolean flag, boolean reqPickup, boolean authPickup, boolean reship, boolean refund){
431
		flagOrder.setEnabled(flag);
432
		requestPickup.setEnabled(reqPickup);
433
		authorizePickup.setEnabled(authPickup);
434
		reshipOrder.setEnabled(reship);
435
		refundOrder.setEnabled(refund);
436
	}
437
 
306 ashish 438
	private void loadOrderDetails(){
966 chandransh 439
		orderDetails1.add(getHorizontalPanel("PRODUCT GROUP: ", transaction.getProductGroup()));
440
		orderDetails1.add(getHorizontalPanel("BRAND:   	     ", transaction.getBrand()));
441
		orderDetails1.add(getHorizontalPanel("MODEL:         ", getModelDisplayName(transaction)));
442
		orderDetails1.add(getHorizontalPanel("Item ID:       ", transaction.getItemId()+""));
443
		orderDetails1.add(getHorizontalPanel("EXTRA INFO:    ", transaction.getExtraInfo()));
306 ashish 444
 
966 chandransh 445
		orderDetails2.add(getHorizontalPanel("NAME:          ", transaction.getCustomerName()));
446
		orderDetails2.add(getHorizontalPanel("ADDRESS:       ", getDisplayAddress(transaction)));
447
		orderDetails2.add(getHorizontalPanel("MOBILE NUMBER: ", transaction.getCustomerMobileNumber()));
306 ashish 448
 
966 chandransh 449
		orderDetails3.add(getHorizontalPanel("TOTAL WEIGHT:      ", transaction.getTotalWeight()+""));
450
		orderDetails3.add(getHorizontalPanel("TOTAL AMOUNT(Rs):  ", transaction.getTotalAmount()+""));
306 ashish 451
 
966 chandransh 452
		orderDetails4.add(getHorizontalPanel("AIRWAY BILL NO:  ", transaction.getAirwayBillNo()));
453
		orderDetails4.add(getHorizontalPanel("INVOICE NUMBER:  ", transaction.getInvoiceNumber()));
454
		orderDetails4.add(getHorizontalPanel("JACKET NUMBER:   ", transaction.getJacketNumber() + ""));
2781 chandransh 455
        orderDetails4.add(getHorizontalPanel("ITEM NO:         ", getDisplayNameForNullableString(transaction.getItemNumber())));
456
        orderDetails4.add(getHorizontalPanel("IMEI NO:         ", transaction.getImeiNumber() + ""));
457
 
966 chandransh 458
		orderDetails4.add(getHorizontalPanel("BILLED BY:       ", transaction.getBilledBy()));		
459
	}
639 chandransh 460
 
966 chandransh 461
	private HorizontalPanel getHorizontalPanel(String labelText, String valueText) {
462
		HorizontalPanel hpanel = new HorizontalPanel();
639 chandransh 463
		hpanel.setSpacing(5);
966 chandransh 464
		hpanel.add(new Label(labelText));
465
		hpanel.add(new Label(valueText));
639 chandransh 466
		hpanel.setCellWidth(hpanel.getWidget(0), "128px");
467
		hpanel.setCellWidth(hpanel.getWidget(1), "128px");
468
		hpanel.getWidget(0).setStyleName(selectionStyle.blueLabel());
469
		hpanel.getWidget(1).setStyleName(selectionStyle.greenLabel());
966 chandransh 470
		return hpanel;
471
	}
306 ashish 472
 
966 chandransh 473
	private String getModelDisplayName(Order order){
474
		String modelName = "";
475
		if(order.getModelName()!=null)
476
			modelName = order.getModelName() + " ";
477
		if(order.getModelNumber()!=null)
478
			modelName = modelName + order.getModelNumber();
479
		if(order.getColor()!=null)
480
			modelName = modelName + " (" + order.getColor() + ")";
481
		return modelName;
306 ashish 482
	}
966 chandransh 483
 
484
	private String getDisplayAddress(Order order){
485
		StringBuilder displayAddress = new StringBuilder();
486
		displayAddress.append(order.getCustomerAddress1() + "\n");
487
		displayAddress.append(order.getCustomerAddress2() + "\n");
488
		displayAddress.append(order.getCustomerCity() + "\n");
489
		displayAddress.append(order.getCustomerState() + "   PIN - " +  order.getCustomerPincode());
490
		return displayAddress.toString();
491
	}
2781 chandransh 492
 
493
    private String getDisplayNameForNullableString(String s) {
494
        if (s == null)
495
            return "";
496
        return s;
497
    }
167 ashish 498
}