gt:                     if (encoded != NewProduct.NOTENCODE) {
context: /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  /*
   * StockByValue.java
   *
   * Created on 06-Sep-2009, 13:44:50
   */
  package proffittcenter;
  
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.text.NumberFormat;
  import java.util.ResourceBundle;
  import java.util.Vector;
  import java.util.logging.Level;
  import java.util.prefs.Preferences;
  import javax.swing.SwingConstants;
  import javax.swing.table.AbstractTableModel;
  import javax.swing.table.TableColumnModel;
  
  /**
   *
   * @author HP_Owner
   */
  public class StockByValue extends EscapeDialog {
  
      private ResourceBundle bundle = ResourceBundle.getBundle("proffittcenter/resource/StockByValue");
      private Vector tableHeader = new Vector();
      private String product;
      private String department;
      private Double retailPrice;
      private Double wholesalePrice;
      private Integer number;
      private Integer lineTotal;
      private Double stockTotal;
      private Double departmentTotal;
      private Double overalTotal;
      private String supplier;
      private Integer value;
      private int stockValue;
      private int departmentValue;
      private boolean newDepartment = false;
      private boolean nextDepartment = false;
      private int theType;
      private int theDepartment;
      private String aDepartment = "";
      private int skuType = SkuType.INCLUDED.value();
      private NumberFormat nf = NumberFormat.getInstance();
      private String stocks = "SELECT Products.Description,Products.ID,"
              + "Products.Encoded,Departments.ID AS SD,"
              + "FORMAT((10*PackSuppliers.Price/Packs.Size+5)/10,0),"
              + "PackSuppliers.Price AS PackPrice ,"
              + "Packs.Size,Skus.ID,"
              + "Departments.Margin AS Margin,"
              + "Taxes.Rate AS Rate,"
              + "Departments.Description AS Department,"
              + "Products.Price AS RetailPrice,Skus.Quantity AS StockQuantity,"
              + "Products.Description,PackSuppliers.WhenCreated "
              + "FROM Products "
              + "LEFT JOIN Packs ON Packs.Product = Products.ID "
              + "LEFT JOIN PackSuppliers ON Packs.ID=PackSuppliers.Pack "
              + "JOIN Skus ON Products.Sku=Skus.ID "
              + "JOIN Departments ON Departments.ID=Skus.Department "
              + "JOIN Taxes ON Taxes.ID=Skus.Tax "
              + "WHERE Skus.StockType=? AND Skus.ID>2 " + //exclude A and B
              "ORDER BY Departments.Description ,Skus.ID, PackSuppliers.WhenCreated DESC";
      private boolean b0 = tableHeader.add(bundle.getString("Department"));
      private boolean b1 = tableHeader.add(bundle.getString("Department") + " (" + Main.shop.poundSymbol + ")");
      private int align[] = {SwingConstants.LEFT, SwingConstants.RIGHT};
      private Object[] line = {department, departmentTotal};
      private Vector<Object[]> rowData = new Vector<Object[]>();
      private Vector<Object[]> rowDataOld = new Vector<Object[]>();
      private AbstractTableModel model = new AbstractTableModel() {
  
          @Override
          public String getColumnName(int col) {
              return (String) tableHeader.get(col);
          }
  
          @Override
          public int getColumnCount() {
              return tableHeader.size();
          }
  
          @Override
          public int getRowCount() {
              return rowData.size();
          }
  
          @Override
          public Object getValueAt(int rowIndex, int columnIndex) {
              line = rowData.get(rowIndex);
              if (columnIndex == 0) {//department
                  return line[0];
              } else if (columnIndex == 1) {//departmentTotal
                  NumberFormat nf = NumberFormat.getInstance();
                  nf.setMaximumFractionDigits(2);
                  nf.setMinimumFractionDigits(2);
                  return nf.format(((Double) line[1]) / 100);
              } else {
                  return null;
              }
          }
  
          @Override
          public Class getColumnClass(int c) {
              return getValueAt(0, c).getClass();
          }
  
          @Override
          public boolean isCellEditable(int row, int col) {
              //Note that the data/cell address is constant,
              //no matter where the cell appears onscreen.
              return col == 2;
          }
  
          @Override
          public void setValueAt(Object value, int row, int col) {
          }
      };
      private MyHeaderRenderer mhr = null;
      private MyTableCellRenderer mtcr = null;
      private Preferences root = Preferences.userNodeForPackage(getClass());
      private String s;
      private int lastDepartmentID;
      private int departmentID;
      private boolean isByDepartment = true;//get this working first
      private Double margin;
      private Double packSupplierPrice;
      private Integer packSize;
      private int stockQuantity;
      private int lastSku;
      private int sku;
      private int encoded;
      private String productDescription;
  
      /** Creates new form StockByValue */
      public StockByValue(java.awt.Frame parent, boolean modal) {
          super(parent, modal);
          initComponents();
          jTable1.setModel(model);
          TableColumnModel tc = jTable1.getTableHeader().getColumnModel();
          tc.getColumn(0).setPreferredWidth(400);
          tc.getColumn(1).setPreferredWidth(180);
          mhr = new MyHeaderRenderer(align);
          for (int i = 0; i < tc.getColumnCount(); i++) {
              tc.getColumn(i).setHeaderRenderer(mhr);
          }
          mtcr = new MyTableCellRenderer(align);
          jTable1.setDefaultRenderer(Integer.class, mtcr);
          jTable1.setDefaultRenderer(String.class, mtcr);
      }
  
      public void execute(SkuType skuType) {
              int op = Main.operator.getOperator();//needed to clear temporary operator
              Audio.play("Tada");
              jStockValue.setText("");
              rowData.clear();
              newDepartment = false;
              stockQuantity = 0;
              //set all values initially
              departmentTotal = 0.;
              overalTotal = 0.;
              try {
                  PreparedStatement ps = Main.getConnection().prepareStatement(stocks);
                  int jj = skuType.value();//ours or theirs
                  ps.setInt(1, skuType.value());
                  ResultSet rs = ps.executeQuery();
                  //get first set of values
                  if (!rs.next()) {//no point if empty
                      ps.close();
                      setVisible(true);
                      return;
                  }
                  lastSku = rs.getInt("Skus.ID");
                  sku = rs.getInt("Skus.ID");
                  lastDepartmentID = rs.getInt("SD");
                  packSupplierPrice = rs.getDouble("PackPrice");
                  packSize = rs.getInt("Packs.Size");
                  stockQuantity = rs.getInt("StockQuantity");
                  if (stockQuantity < 0) {//ignore negatiive stock levels
                      stockQuantity = 0;
                  }
                  product = rs.getString("Products.ID");
                  encoded = rs.getInt("Encoded");
                  retailPrice = rs.getDouble("RetailPrice");//* 100
                  productDescription = rs.getString("Products.Description");
                  margin = rs.getDouble("Margin");
                  wholesalePrice = retailPrice * (1 - margin / 10000);//default * 100
                  if (packSupplierPrice == null || packSupplierPrice == 0 || packSize == null || packSize == 0) {
                      Regime rr = Main.shop.regimeIs();
                      if (rr == Regime.NONE || rr == Regime.REGISTERED || rr == Regime.UNREGISTERED) {
                          wholesalePrice = retailPrice * (1 - margin / 100);
                      } else if (rr == Regime.WHOLESALE || rr == Regime.SALESTAX) {
                          double taxRate = rs.getInt("Rate");
                          wholesalePrice = retailPrice * (1 - taxRate / 10000) * (1 - margin / 10000);
                      }
                  } else {
  