package bb.gui.sales.so;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import bb.common.BB2Part;
import bb.common.SalesOrderItemVO;
import bb.gui.ClientUtil;
import bb.gui.base.ClientUI;
import bb.gui.sales.SalesUtil;
import bb.gui.swing.ButtonPane;
import bb.gui.swing.ButtonPaneFactory;
import bb.gui.swing.CommentNotePane;
import bb.gui.swing.DisplayTextField;
import bb.gui.swing.JTextAreaLabel;
import bb.gui.swing.MfrTable;
import bb.gui.swing.PartPKPane;
import bb.gui.swing.PermissionPanel;
import bb.gui.swing.StatusTextField;
import bb.gui.swing.TableLayout;
import bb.gui.swing.browserpane.DWGBrowserPane;
import bb.gui.swing.browserpane.RevisionBrowserPane;
import bb.gui.swing.browserpane.TracabelBrowserPane;

public class SalesOrderItemUI extends ClientUI
{
  private static final long serialVersionUID = 1L;
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout3 = new BorderLayout();
  SalesOrderItemVO vo = null;
  ButtonPane windowButtonPane = ButtonPaneFactory.createButtonPane("help|close");
  JTextField txtItemNumber = new DisplayTextField();
  JTextAreaLabel txtPartDescription = new JTextAreaLabel();
  BorderLayout borderLayout7 = new BorderLayout();
  JTextField txtQtyShipped = new DisplayTextField();
  JPanel mainPane = new JPanel();
  JLabel jLabel17 = new JLabel();
  JTextField txtSoNumber = new DisplayTextField();
  RevisionBrowserPane txtPartRevision = new RevisionBrowserPane();
  JLabel jLabel6 = new JLabel();
  DisplayTextField txtQtyOrdered = new DisplayTextField();
  JLabel lbTracabelLevel = new JLabel();
  DisplayTextField txtTracabelLevel = new DisplayTextField();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel8 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JPanel jPanel3 = new JPanel();
  JLabel jLabel2 = new JLabel();
  DWGBrowserPane txtPartDwg = new DWGBrowserPane();
  TableLayout mainPaneLayout = new TableLayout(10, 2);
  JLabel jLabel7 = new JLabel();
  TracabelBrowserPane txtPartTraceable = new TracabelBrowserPane();
  JLabel lbSoNumber = new JLabel();
  MfrTable mfrTable = new MfrTable();
  PartPKPane txtPartNumber = new PartPKPane();
  JPanel bigPane = new JPanel();
  GridLayout bigPaneLayout = new GridLayout();
  JPanel otherPane = new JPanel();
  TableLayout otherPaneLayout = new TableLayout(10, 2);
  JPanel tablePane = new JPanel();
  BorderLayout tablePaneLayout = new BorderLayout();
  JPanel tab = new JPanel();
  JTextField txtExtPrice = new DisplayTextField();
  //modify by hzf on 20140822,销售单项的销售金额小计受“查看销售价格”权限控制
  PermissionPanel extPricePanel=new PermissionPanel(PermissionPanel.PRICE, this.txtExtPrice);
  JTextField txtDeliveryDate = new DisplayTextField();
  JLabel lbRefDoc2 = new JLabel();
  JLabel lbDeliveryDays = new JLabel();
  StatusTextField txtStatus = new StatusTextField();
  JTextField txtRefDoc1 = new DisplayTextField();
  JLabel lbDiscount = new JLabel();
  JLabel lbStatus = new JLabel();
  JTextField txtUnit = new DisplayTextField();
  JLabel lbRefDoc1 = new JLabel();
  JTextField txtRefDoc2 = new DisplayTextField();
  JLabel lbExtPrice = new JLabel();
  JTextField txtPriceUnit = new DisplayTextField();
  //add by hzf on 20140822,单价受“查看销售价格”权限控制
  PermissionPanel priceUnitPanel=new PermissionPanel(PermissionPanel.PRICE, this.txtPriceUnit);
  JTextField txtDeliveryDays = new DisplayTextField();
  JLabel lbDelivery = new JLabel();
  JLabel lbUnit = new JLabel();
  JLabel lbPriceUnit = new JLabel();
  JTextField txtDiscount = new DisplayTextField();
  //add by hzf on 20140822,折扣率受“查看销售价格”权限控制
  PermissionPanel discountPanel=new PermissionPanel(PermissionPanel.PRICE, this.txtDiscount);
  JPanel jPanel5 = new JPanel();
  BorderLayout borderLayout6 = new BorderLayout();
  BorderLayout borderLayout8 = new BorderLayout(0, 5);
  CommentNotePane commentPane = new CommentNotePane();
  JTextField txtAvgCost = new DisplayTextField();
  PermissionPanel avgCostPerPane = new PermissionPanel("VIEW_INVENTORY_COST", this.txtAvgCost);
  JTextField txtStdCost = new DisplayTextField();
  PermissionPanel stdCostPerPane = new PermissionPanel("VIEW_INVENTORY_COST", this.txtStdCost);
  JPanel desPane = new JPanel(new BorderLayout(5, 5));
  JPanel topPane = new JPanel(new BorderLayout());

  public SalesOrderItemUI() {
    init();
    ClientUtil.setupWindow(this);
  }

  public void setVO(SalesOrderItemVO vo) {
    this.vo = vo;
    if (vo != null) {
      BB2Part part = new BB2Part(vo.getPartNumber(), vo.getPartType(), vo.getPartFrom());
      setTitle(vo.getPk().getSalesOrderNumber() + "." + vo.getPk().getSalesOrderItemNumber() + "  " + SalesUtil.getString("QuoteItemUI.Properties"));
      this.txtSoNumber.setText(vo.getPk().getSalesOrderNumber());
      this.txtItemNumber.setText(vo.getPk().getSalesOrderItemNumber());
      this.txtPartNumber.setBB2Part(part);
      this.txtPartRevision.setBB2Part(part, vo.getRevision());
      this.txtPartTraceable.setBB2Part(part, vo.getTraceable());
      if (!ClientUtil.isNullObject(vo.getTraceableLevel())) {
        this.txtTracabelLevel.setText(vo.getTraceableLevel());
      }
      this.txtPartDwg.setBB2Part(part, vo.getDwg());
      this.txtPartDescription.setText(vo.getSalesItemDescription());
      this.txtQtyOrdered.setText(ClientUtil.getNumberString(vo.getQuantityOrdered()));
      this.txtQtyShipped.setText(ClientUtil.getNumberString(vo.getQuantityShipped()));
      this.txtAvgCost.setText(ClientUtil.getNumberStringControlledDecimal(vo.getCost()));
      this.txtStdCost.setText(ClientUtil.getNumberStringControlledDecimal(vo.getStdCost()));
      this.txtUnit.setText(vo.getUnit());
      this.txtPriceUnit.setText(ClientUtil.getNumberStringControlledDecimal(vo.getPricePerUnit()));
      this.txtDiscount.setText(ClientUtil.getNumberString(vo.getDiscount()));
      this.txtExtPrice.setText(ClientUtil.getNumberStringWithTwoDigits(vo.getExtendPrice()));
      this.txtDeliveryDate.setText(ClientUtil.getDateLocalString(vo.getDeliveryDate()));
      this.txtDeliveryDays.setText(new Integer(vo.getDelayDays()).toString());
      this.mfrTable.installTableData(vo.getSalesOrderItemManufacturer());
      this.txtRefDoc1.setText(vo.getReferenceDoc1());
      this.txtRefDoc2.setText(vo.getReferenceDoc2());
      this.txtStatus.setText(vo.getStatus());
      this.commentPane.setComments(vo.getSalesOrderItemComments());
      this.commentPane.setPrivateNote(vo.getSalesOrderItemPrivateNotes());
      this.commentPane.setBP("");
    }
  }

  private void init() {
    this.topPane.setBorder(ClientUtil.createTitleBorder(SalesUtil.getString("SalesOrderUIGeneralPane.GeneralInformation"), new Insets(0, 10, 0, 10)));
    setLayout(this.borderLayout1);
    setTitle(SalesUtil.getString("SalesOrderItemUI.Title"));
    this.txtItemNumber.setEnabled(true);
    this.txtItemNumber.setPreferredSize(new Dimension(400, 22));
    this.mainPane.setLayout(this.mainPaneLayout);
    this.jLabel17.setText(SalesUtil.getString("SalesOrderItemUI.Manufacturers"));
    this.jLabel6.setText(SalesUtil.getString("SalesOrderItemUI.PartDescription"));
    this.jLabel5.setText(SalesUtil.getString("SalesOrderItemUI.DWGDrawing"));
    this.jLabel8.setText(SalesUtil.getString("SalesOrderItemUI.QtyOrdered"));
    this.jLabel4.setText(SalesUtil.getString("SalesOrderItemUI.Revision"));
    this.jScrollPane1.setPreferredSize(new Dimension(453, 60));
    this.jLabel1.setText(SalesUtil.getString("SalesOrderItemUI.Item"));
    this.jLabel3.setText(SalesUtil.getString("SalesOrderItemUI.Traceable"));
    this.jPanel3.setLayout(this.borderLayout7);
    this.jLabel2.setText(SalesUtil.getString("SalesOrderItemUI.Part"));
    this.jLabel7.setText(SalesUtil.getString("SalesOrderItemUI.QtyShipped"));
    this.lbSoNumber.setText(SalesUtil.getString("SalesOrderItemUI.SO"));
    this.bigPane.setLayout(this.bigPaneLayout);
    this.bigPaneLayout.setHgap(10);
    this.bigPaneLayout.setColumns(2);
    this.otherPane.setLayout(this.otherPaneLayout);
    this.tablePane.setLayout(this.tablePaneLayout);
    this.txtExtPrice.setEnabled(true);
    this.lbRefDoc2.setText(SalesUtil.getString("SalesOrderItemUI.RefDoc2"));
    this.lbDeliveryDays.setText(SalesUtil.getString("SalesOrderItemUI.DeliveryDate"));
    this.lbDiscount.setText(SalesUtil.getString("SalesOrderItemUI.Discount"));
    this.lbStatus.setText(SalesUtil.getString("SalesOrderItemUI.Status"));
    this.lbRefDoc1.setText(SalesUtil.getString("SalesOrderItemUI.RefDoc1"));
    this.lbExtPrice.setText(SalesUtil.getString("SalesOrderItemUI.ExtPrice"));
    this.lbDelivery.setText(SalesUtil.getString("SalesOrderItemUI.DeliveryDays"));
    this.lbUnit.setText(SalesUtil.getString("SalesOrderItemUI.Unit"));
    this.lbPriceUnit.setText(SalesUtil.getString("SalesOrderItemUI.PriceUnit"));
    this.lbTracabelLevel.setText(SalesUtil.getString("SalesOrderItemUI.TracableLevel"));
    this.jPanel5.setLayout(this.borderLayout6);
    this.jPanel5.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
    this.tab.setLayout(this.borderLayout8);
    this.tab.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
    add(this.windowButtonPane, "South");
    this.mainPane.add(this.lbSoNumber, null);
    this.mainPane.add(this.txtSoNumber, null);
    this.mainPane.add(this.jLabel1, null);
    this.mainPane.add(this.txtItemNumber, null);
    this.mainPane.add(this.jLabel2, null);
    this.mainPane.add(this.txtPartNumber, null);
    this.mainPane.add(this.jLabel3, null);
    this.mainPane.add(this.txtPartTraceable, null);
    this.mainPane.add(this.lbTracabelLevel, null);
    this.mainPane.add(this.txtTracabelLevel, null);
    this.mainPane.add(this.jLabel4, null);
    this.mainPane.add(this.txtPartRevision, null);
    this.mainPane.add(this.jLabel5, null);
    this.mainPane.add(this.txtPartDwg, null);
    this.mainPane.add(this.jLabel8, null);
    this.mainPane.add(this.txtQtyOrdered, null);
    this.mainPane.add(this.jLabel7, null);
    this.mainPane.add(this.txtQtyShipped, null);
    this.mainPane.add(new JLabel(SalesUtil.getString("UpdateSalesOrderItemGeneralPane.Cost")), null);
    this.mainPane.add(this.avgCostPerPane, null);
    this.bigPane.add(this.mainPane, null);
    this.bigPane.add(this.otherPane, null);
    this.tablePane.add(this.jPanel3, "Center");
    this.jPanel3.add(this.jScrollPane1, "Center");
    this.tablePane.add(this.jLabel17, "North");
    this.jScrollPane1.getViewport().add(this.mfrTable, null);
    add(this.jPanel5, "North");
    this.jPanel5.add(this.topPane, "Center");
    this.topPane.add(this.bigPane);
    this.topPane.add(this.desPane, "South");
    add(this.tab, "Center");
    this.tab.add(this.commentPane, "North");
    this.tab.add(this.tablePane, "Center");
    this.otherPane.add(this.lbStatus, null);
    this.otherPane.add(this.txtStatus, null);
    this.otherPane.add(this.lbExtPrice, null);
    //modify by hzf on 20140822,销售单项的销售金额小计受“查看销售价格”权限控制
    //this.otherPane.add(this.txtExtPrice, null);
    this.otherPane.add(this.extPricePanel, null);
    this.otherPane.add(this.lbDeliveryDays, null);
    this.otherPane.add(this.txtDeliveryDate, null);
    this.otherPane.add(this.lbDelivery, null);
    this.otherPane.add(this.txtDeliveryDays, null);
    this.otherPane.add(this.lbDiscount, null);
    //modify by hzf on 20140822,折扣率受“查看销售价格”权限控制
    //this.otherPane.add(this.txtDiscount, null);
    this.otherPane.add(this.discountPanel, null);
    this.otherPane.add(this.lbUnit, null);
    this.otherPane.add(this.txtUnit, null);
    this.otherPane.add(this.lbPriceUnit, null);
    //add by hzf on 20140822,单价受“查看销售价格”权限控制
    //this.otherPane.add(this.txtPriceUnit, null);
    this.otherPane.add(this.priceUnitPanel, null);
    this.otherPane.add(this.lbRefDoc1, null);
    this.otherPane.add(this.txtRefDoc1, null);
    this.otherPane.add(this.lbRefDoc2, null);
    this.otherPane.add(this.txtRefDoc2, null);
    this.otherPane.add(new JLabel(SalesUtil.getString("UpdateSalesOrderItemGeneralPane.StdCost")), null);
    this.otherPane.add(this.stdCostPerPane, null);
    this.desPane.add(this.jLabel6, "North");
    this.desPane.add(new JScrollPane(this.txtPartDescription));
    this.txtPartDescription.setRows(3);
  }
}