Rev 4603 | Rev 4666 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.hotspot.dashbaord.client.inbox;import in.shop2020.hotspot.dashbaord.client.event.AcceptOrderEvent;import in.shop2020.hotspot.dashbaord.client.event.FlagOrderEvent;import in.shop2020.hotspot.dashbaord.client.event.NostockOrderEvent;import in.shop2020.hotspot.dashbaord.client.event.ProvisionalCaptureEvent;import in.shop2020.hotspot.dashbaord.client.event.ReshipOrderEvent;import in.shop2020.hotspot.dashbaord.shared.actions.BillingType;import in.shop2020.hotspot.dashbaord.shared.actions.DetailsMask;import in.shop2020.hotspot.dashbaord.shared.actions.Order;import in.shop2020.hotspot.dashbaord.shared.actions.UserType;import java.util.Map;import org.enunes.gwt.mvp.client.EventBus;import com.google.gwt.core.client.GWT;import com.google.gwt.event.dom.client.ClickEvent;import com.google.gwt.event.dom.client.ClickHandler;import com.google.gwt.resources.client.CssResource;import com.google.gwt.uibinder.client.UiBinder;import com.google.gwt.uibinder.client.UiField;import com.google.gwt.user.client.Window;import com.google.gwt.user.client.ui.Button;import com.google.gwt.user.client.ui.FlexTable;import com.google.gwt.user.client.ui.HorizontalPanel;import com.google.gwt.user.client.ui.Label;import com.google.gwt.user.client.ui.ResizeComposite;import com.google.gwt.user.client.ui.VerticalPanel;import com.google.gwt.user.client.ui.Widget;public class OrderDetails extends ResizeComposite{public interface Listener{void onClick();}interface OrderDetailsUiBinder extends UiBinder<Widget, OrderDetails>{ }interface SelectionStyle extends CssResource{String blueLabel();String greenLabel();}private static final OrderDetailsUiBinder binder = GWT.create(OrderDetailsUiBinder.class);@UiField FlexTable header;@UiField FlexTable table;@UiField HorizontalPanel orderDetails;@UiField VerticalPanel orderDetails1;@UiField VerticalPanel orderDetails2;@UiField VerticalPanel orderDetails3;@UiField VerticalPanel orderDetails4;@UiField VerticalPanel orderDetails5;@UiField SelectionStyle selectionStyle;private final EventBus eventbus;private Order order;private Order transaction;//Buttons for the Warehouse Executive//private Button verifyOrder = new Button();private Button acceptOrder = new Button();private Button rejectOrder = new Button();private Button printAllInvoices = new Button();private Button notAvailable= new Button();private Button addBillingInfo= new Button();private Button printInvoice = new Button();private Button receiveReturn = new Button();private Button validateDOA = new Button();private Button validateReturnProduct = new Button();//Buttons for the Admin to track orderprivate Button flagOrder = new Button();private Button requestPickup = new Button();private Button authorizePickup = new Button();private Button refundOrder = new Button();private Button reshipOrder = new Button();private Button provisionallyCapturePaymentForOrder = new Button();//Buttons for the Admin to edit order detailsprivate Button addWeight = new Button();private Button changeColor = new Button();private Button addDelayReason = new Button();private Button shiftWarehouse = new Button();private String user;private DetailsMask mask;private long warehouseID;private UserType userType;private BillingType billingType;private Map<Long, String> vendors;private Map<Long, String> providers;public OrderDetails(EventBus eventbus, Order order, Order order2, DetailsMask mask, String user, long warehouseID, UserType userType, BillingType billingType, Map<Long, String> vendors, Map<Long, String> providers){this.eventbus = eventbus;this.order = order;this.transaction = order2;this.mask = mask;this.user = user;this.warehouseID = warehouseID;this.userType = userType;this.billingType = billingType;this.vendors = vendors;this.providers = providers;initWidget(binder.createAndBindUi(this));initTableForWE();if(this.userType == UserType.ADMIN){initTableForAdmin();}loadOrderDetails();}private void initTableForWE() {header.getColumnFormatter().setWidth(0, "120px");header.getColumnFormatter().setWidth(1, "120px");header.getColumnFormatter().setWidth(2, "120px");header.getColumnFormatter().setWidth(3, "120px");header.getColumnFormatter().setWidth(4, "120px");header.getColumnFormatter().setWidth(5, "120px");header.getColumnFormatter().setWidth(6, "120px");header.getColumnFormatter().setWidth(7, "120px");header.getColumnFormatter().setWidth(8, "120px");//verifyOrder.setText("Verify");acceptOrder.setText("Accept");notAvailable.setText("Out Of Stock");addBillingInfo.setText("Bill");if(billingType == BillingType.OURS)addBillingInfo.setVisible(false);printInvoice.setText("Print Invoice");receiveReturn.setText("Receive Return");validateDOA.setText("Validate DOA");validateReturnProduct.setText("Product Usable?");rejectOrder.setText("Cancel Order");printAllInvoices.setText("Print All Invoices");//header.setWidget(0, 0, verifyOrder);header.setWidget(0, 0, acceptOrder);header.setWidget(0, 1, notAvailable);header.setWidget(0, 2, addBillingInfo);header.setWidget(0, 3, printInvoice);header.setWidget(0, 4, receiveReturn);header.setWidget(0, 5, validateDOA);header.setWidget(0, 6, rejectOrder);header.setWidget(0, 7, printAllInvoices);header.setWidget(0, 8, validateReturnProduct);registerButtonHandlersForWE();if(this.userType == UserType.WAREHOUSE_EXECUTIVE || this.userType == UserType.ADMIN){implementMaskForWE();}if(this.userType == UserType.WAREHOUSE_MONITOR){implementMaskForWM();}}private void registerButtonHandlersForWE(){/*verifyOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(verifyOrder.isEnabled()){GWT.log("Verify order event fired");eventbus.fireEvent(new VerifyOrderEvent(order));}}});*/acceptOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(acceptOrder.isEnabled())eventbus.fireEvent(new AcceptOrderEvent(order));}});notAvailable.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(notAvailable.isEnabled())eventbus.fireEvent(new NostockOrderEvent(order));}});rejectOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(rejectOrder.isEnabled()){RejectReasonBox box = new RejectReasonBox(eventbus, order, user);box.center();}}});addBillingInfo.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!addBillingInfo.isEnabled())return;BillingInfoBox box = new BillingInfoBox(eventbus, order, user);box.center();}});printInvoice.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!printInvoice.isEnabled())return;if(order.getJacketNumber()==0 && billingType == BillingType.OURS){JacketInfoBox box = new JacketInfoBox(eventbus, order, user, billingType, vendors);//box.clean();box.center();}else{String invoiceGenerationUrl = GWT.getHostPageBaseURL() + "invoice/?id=" + order.getOrderId() + "&warehouse=" + warehouseID;if(billingType == BillingType.OURS)invoiceGenerationUrl += "&withBill=true";elseinvoiceGenerationUrl += "&withBill=false";Window.open(invoiceGenerationUrl, "newWindowName", "window features.");}}});printAllInvoices.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!printAllInvoices.isEnabled()){return;}else{String invoiceGenerationUrl = GWT.getHostPageBaseURL() + "invoice/?id=" + order.getOrderId() + "&printAll=true&warehouse=" + warehouseID;if(billingType == BillingType.OURS)invoiceGenerationUrl += "&withBill=true";elseinvoiceGenerationUrl += "&withBill=false";Window.open(invoiceGenerationUrl, "newWindowName", "window features.");}}});receiveReturn.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!receiveReturn.isEnabled())return;ReceiveReturnBox box = new ReceiveReturnBox(eventbus, order);box.center();}});validateDOA.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!validateDOA.isEnabled())return;DoaValidationBox box = new DoaValidationBox(eventbus, order);box.center();}});validateReturnProduct.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!validateReturnProduct.isEnabled())return;ProductValidationBox box = new ProductValidationBox(eventbus, order);box.center();}});}private void implementMaskForWM(){maskButtonsForWE(false, false, false, false, false, false, false, false, false); //Unknown state, let's disallow any untoward actions.}private void implementMaskForWE(){switch(mask){case VERIFICATION_PENDING:maskButtonsForWE(false, false, false, false, false, false, false, false, false); //Do not allow the WE to verify the order.break;case CAPTURE_IN_PROCESS:case NEW:maskButtonsForWE(true, false, true, false, false, false, false, false, false); //Allow the WE to either accept the order or mark it as out of stock.break;case ACCEPT://TODO: Mask buttons based on the billingTypeif(billingType == BillingType.OURS)maskButtonsForWE(false, false, false, true, true, false, false, true, false); // For our billing, allow the WE to directly print the invoive.elsemaskButtonsForWE(false, false, false, true, true, false, false, true, false); //For external billing, allow the WE to feed the invoice info.break;case REJECT:maskButtonsForWE(false, false, false, false, false, false, false, false, false); //Can't do anything once the order has been rejected.break;case BILL:maskButtonsForWE(false, false, false, true, false, false, false, false, false); //Allow WE to print the invoice for a billed order.break;case SHIP:maskButtonsForWE(false, false, false, false, false, false, false, false, false);break;case NO_STOCK:maskButtonsForWE(true, false, false, false, false, false, false, false, false); //Allow WE to accept a low inventory item.break;case CANCEL_CONFIRMED:maskButtonsForWE(false, true, false, false, false, false, false, false, false); //Allow WE to Cancel a order which is in cancellation pending state.break;case DOA_AWAITED:case SALES_RETURN_AWAITED:maskButtonsForWE(false, false, false, false, false, true, false, false, false); //Allow WE to accept the packet.break;case DOA_RECEIVED:maskButtonsForWE(false, false, false, false, false, false, true, false, false); //Allow WE to validate the DOA certificate.break;case RET_RECEIVED:maskButtonsForWE(false, false, false, false, false, false, false, false, true); //Allow WE to validate the DOA certificate.break;default:maskButtonsForWE(false, false, false, false, false, false, false, false, false); //Unknown state, let's disallow any untoward actions.break;}}private void maskButtonsForWE(boolean accept, boolean reject, boolean notavailable, boolean printInv, boolean billing, boolean acceptdoa, boolean validatedoa, boolean printAllInvoice, boolean validatereturnproduct){//verifyOrder.setEnabled(verify);acceptOrder.setEnabled(accept);notAvailable.setEnabled(notavailable);printInvoice.setEnabled(printInv);addBillingInfo.setEnabled(billing);receiveReturn.setEnabled(acceptdoa);validateDOA.setEnabled(validatedoa);rejectOrder.setEnabled(reject);printAllInvoices.setEnabled(printAllInvoice);validateReturnProduct.setEnabled(validatereturnproduct);}private void initTableForAdmin() {if(transaction.isDoaFlag()){flagOrder.setText("Unflag");} else {flagOrder.setText("Flag");}requestPickup.setText("Request Pick-up No");authorizePickup.setText("Confirm Pick-up");reshipOrder.setText("Reship");refundOrder.setText("Refund");provisionallyCapturePaymentForOrder.setText("Capture provisionally");header.setWidget(1, 0, flagOrder);header.setWidget(1, 1, requestPickup);header.setWidget(1, 2, authorizePickup);header.setWidget(1, 3, reshipOrder);header.setWidget(1, 5, provisionallyCapturePaymentForOrder);header.setWidget(1, 6, refundOrder);addWeight.setText("Add weight");changeColor.setText("Change Color");addDelayReason.setText("Add Delay Reason");shiftWarehouse.setText("Shift Warehouse");header.setWidget(2, 0, addWeight);header.setWidget(2, 1, changeColor);header.setWidget(2, 2, addDelayReason);header.setWidget(2, 6, shiftWarehouse);if(order.getTotalWeight() != 0)addWeight.setEnabled(false);registerButtonHandlersForAdmin();implementMaskForAdmin();}private void registerButtonHandlersForAdmin(){flagOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(flagOrder.isEnabled()){eventbus.fireEvent(new FlagOrderEvent(order));}}});requestPickup.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(requestPickup.isEnabled()){GWT.log("Raising a pickup request for: " + order.getOrderId());ChoosePickupProviderBox box = new ChoosePickupProviderBox(eventbus, order, providers);box.center();}}});authorizePickup.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(!authorizePickup.isEnabled())return;PickupAuthorizationInfoBox box = new PickupAuthorizationInfoBox(eventbus, order, providers);box.center();}});reshipOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(reshipOrder.isEnabled()){GWT.log("Reshipping the order: " + order.getOrderId());eventbus.fireEvent(new ReshipOrderEvent(order));}}});provisionallyCapturePaymentForOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(provisionallyCapturePaymentForOrder.isEnabled()) {GWT.log("Provisionally capturing payment for order: " + order.getOrderId());eventbus.fireEvent(new ProvisionalCaptureEvent(order));}}});refundOrder.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(refundOrder.isEnabled()){RejectReasonBox box = new RejectReasonBox(eventbus, order, user);//box.clear();box.center();}}});addWeight.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(addWeight.isEnabled()){AddWeightBox box = new AddWeightBox(eventbus, order);box.center();}}});changeColor.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(changeColor.isEnabled()){ChooseColorBox box = new ChooseColorBox(eventbus, order);box.center();}}});addDelayReason.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {AddDelayReasonBox box = new AddDelayReasonBox(eventbus, order);box.center();}});shiftWarehouse.addClickHandler(new ClickHandler() {@Overridepublic void onClick(ClickEvent event) {if(shiftWarehouse.isEnabled()){ChooseWarehouseBox box = new ChooseWarehouseBox(eventbus, order);box.center();}}});}private void implementMaskForAdmin(){switch(mask){case CAPTURE_IN_PROCESS:maskButtonsForAdmin(false, false, false, false, true, true, true); //Allow the OM to refund a COD order or an order with low inventory or when a customer calls or writes to cancel an order.break;case VERIFICATION_PENDING:case NEW:case NO_STOCK:case ACCEPT:case BILL:maskButtonsForAdmin(false, false, false, false, true, true, false); //Allow the OM to refund a COD order or an order with low inventory or when a customer calls or writes to cancel an order.break;case DELIVERED:maskButtonsForAdmin(false, false, false, false, false, true, false); //Allow the OM to flag and request pickup.break;case DOA_REQUEST_AUTHORIZED:maskButtonsForAdmin(true, true, false, false, false, true, false); //Allow the OM to flag and request pickup.break;case DOA_PICKUP_REQUESTED:maskButtonsForAdmin(true, true, true, false, false, true, false); //Allow the OM to either re-request a pickup no. or authorize pickup by entering onebreak;case DOA_RETURNED:case SALES_RETURNED:maskButtonsForAdmin(false, false, false, true, true, true, false); //Allow the OM to either reship the order or refund itbreak;default:maskButtonsForAdmin(false, false, false, false, false, true, false); //Unknown state. Let's not allow any untoward actions.break;}}private void maskButtonsForAdmin(boolean flag, boolean reqPickup, boolean authPickup, boolean reship,boolean refund, boolean printInv, boolean provisionallyCapturePayment){flagOrder.setEnabled(flag);requestPickup.setEnabled(reqPickup);authorizePickup.setEnabled(authPickup);reshipOrder.setEnabled(reship);provisionallyCapturePaymentForOrder.setEnabled(provisionallyCapturePayment);refundOrder.setEnabled(refund);printInvoice.setEnabled(printInv);}private void loadOrderDetails(){orderDetails1.add(getHorizontalPanel("FREE ITEM: ", transaction.getDealText()));orderDetails1.add(getHorizontalPanel("PRODUCT GROUP: ", transaction.getProductGroup()));orderDetails1.add(getHorizontalPanel("BRAND: ", transaction.getBrand()));orderDetails1.add(getHorizontalPanel("MODEL: ", getModelDisplayName(transaction)));orderDetails1.add(getHorizontalPanel("Item ID: ", transaction.getItemId()+""));orderDetails1.add(getHorizontalPanel("DELAY REASON: ", transaction.getDelayReason()));orderDetails1.add(getHorizontalPanel("ALERT: ", transaction.getAlert().toString()));orderDetails2.add(getHorizontalPanel("NAME: ", transaction.getCustomerName()));orderDetails2.add(getHorizontalPanel("ADDRESS: ", getDisplayAddress(transaction)));orderDetails2.add(getHorizontalPanel("MOBILE NUMBER: ", transaction.getCustomerMobileNumber()));orderDetails3.add(getHorizontalPanel("TOTAL WEIGHT: ", transaction.getTotalWeight()+""));orderDetails3.add(getHorizontalPanel("TOTAL AMOUNT(Rs): ", transaction.getTotalAmount()+""));orderDetails4.add(getHorizontalPanel("AIRWAY BILL NO: ", transaction.getAirwayBillNo()));orderDetails4.add(getHorizontalPanel("INVOICE NUMBER: ", transaction.getInvoiceNumber()));orderDetails4.add(getHorizontalPanel("JACKET NUMBER: ", transaction.getJacketNumber() + ""));orderDetails4.add(getHorizontalPanel("ITEM NO: ", getDisplayNameForNullableString(transaction.getItemNumber())));orderDetails4.add(getHorizontalPanel("IMEI NO: ", transaction.getImeiNumber() + ""));orderDetails4.add(getHorizontalPanel("BILLED BY: ", transaction.getBilledBy()));}private HorizontalPanel getHorizontalPanel(String labelText, String valueText) {HorizontalPanel hpanel = new HorizontalPanel();hpanel.setSpacing(5);hpanel.add(new Label(labelText));hpanel.add(new Label(valueText));hpanel.setCellWidth(hpanel.getWidget(0), "128px");hpanel.setCellWidth(hpanel.getWidget(1), "128px");hpanel.getWidget(0).setStyleName(selectionStyle.blueLabel());hpanel.getWidget(1).setStyleName(selectionStyle.greenLabel());return hpanel;}private String getModelDisplayName(Order order){String modelName = "";if(order.getModelName()!=null)modelName = order.getModelName() + " ";if(order.getModelNumber()!=null)modelName = modelName + order.getModelNumber();if(order.getColor()!=null)modelName = modelName + " (" + order.getColor() + ")";return modelName;}private String getDisplayAddress(Order order){StringBuilder displayAddress = new StringBuilder();displayAddress.append(order.getCustomerAddress1() + "\n");displayAddress.append(order.getCustomerAddress2() + "\n");displayAddress.append(order.getCustomerCity() + "\n");displayAddress.append(order.getCustomerState() + " PIN - " + order.getCustomerPincode());return displayAddress.toString();}private String getDisplayNameForNullableString(String s) {if (s == null)return "";return s;}}