Search in sources :

Example 21 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoProduct method enableButtons.

/**
	 *  Enable PAttribute if row selected/changed
	 */
protected void enableButtons() {
    if (m_PAttributeButton != null) {
        if (p_table == null)
            return;
        int row = p_table.getSelectionModel().getLeadSelectionIndex();
        int rows = p_table.getRowCount();
        if (p_table.getShowTotals())
            rows = rows - 1;
        if (row < 0 || row > rows) {
            super.enableButtons();
            return;
        }
        boolean enabled = false;
        // Check the lead row - if it has no attribute instances, no button
        try {
            Object value = p_table.getValueAt(row, INDEX_PATTRIBUTE);
            enabled = Boolean.TRUE.equals(value);
        } catch (Exception e) {
            enabled = false;
        }
        if (enabled && p_table.isMultiSelection()) {
            //  Only enable if a single row is selected.  Disable for multiple selections.
            //  Multiple selections can be checked or just high-lighted.
            int checkedRows = p_table.getSelectedKeys().size();
            int selectedRows = p_table.getSelectedRowCount();
            log.fine("Checked Rows: " + checkedRows + " SelectedRows: " + selectedRows);
            if (checkedRows > 1 || selectedRows > 1)
                enabled = false;
            else if (// SelectedRows could be zero so don't care
            checkedRows == 1) {
                //Check that the lead selection is checked
                Object data = p_table.getValueAt(row, p_table.getKeyColumnIndex());
                if (data instanceof IDColumn) {
                    IDColumn record = (IDColumn) data;
                    if (!record.isSelected()) {
                        enabled = false;
                        log.fine("Lead selection is not checked!");
                    }
                }
            }
        }
        m_PAttributeButton.setEnabled(enabled);
    }
    super.enableButtons();
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) SQLException(java.sql.SQLException)

Example 22 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoProduct method refreshAtpTab.

//	initAtpTab
/**
	 *	Refresh ATP
	 */
private void refreshAtpTab() {
    boolean showDetail = checkShowDetail.isSelected();
    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    int M_Warehouse_ID = 0;
    // row to prevent array index out of bounds. BF 3051361
    if (warehouseTbl.getRowCount() > 0) {
        int selectedRow = warehouseTbl.getSelectedRow();
        if (selectedRow < 0)
            selectedRow = 0;
        Object wh_data = warehouseTbl.getValueAt(selectedRow, warehouseTbl.getKeyColumnIndex());
        if (wh_data != null && wh_data instanceof IDColumn) {
            IDColumn dataColumn = (IDColumn) wh_data;
            M_Warehouse_ID = dataColumn.getRecord_ID();
        }
    } else {
        M_Warehouse_ID = m_M_Warehouse_ID;
    }
    if (M_Warehouse_ID == 0) {
        // Can't find a warehouse to load.  Clear the table
        clearAtpTab();
        return;
    } else // Update the table
    {
        //	Create the SELECT ..UNION. clause
        //  This is done in-line rather than using prepareTable() so we can add a running sum to the data.
        String sql;
        if (!showDetail)
            sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, 0 as ID, null as Date," + " sum(s.QtyOnHand) as AvailQty, null as DeltaQty, sum(s.QtyOrdered) as QtyOrdered, sum(s.QtyReserved) as QtyReserved," + // " s.PASI," 
            " null as sumPASI," + " 0 as ASI," + " null as BP_Name, null as DocumentNo, 10 as SeqNo";
        else
            sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, s.M_AttributeSetInstance_ID as ID, now() as Date," + " s.QtyOnHand as AvailQty, null as DeltaQty, s.QtyOrdered as QtyOrdered, s.QtyReserved as QtyReserved," + " CASE WHEN s.PASI  = '' THEN '{' || COALESCE(s.M_AttributeSetInstance_ID,0) || '}' ELSE s.PASI END as sumPASI," + " COALESCE(M_AttributeSetInstance_ID,0) as ASI," + " null as BP_Name, null as DocumentNo,  10 as SeqNo";
        sql += " FROM (SELECT M_Product_ID, M_Locator_ID, QtyOnHand, QtyReserved, QtyOrdered," + " COALESCE(productAttribute(M_AttributeSetInstance_ID)::varchar, '') as PASI," + " COALESCE(M_AttributeSetInstance_ID,0) as M_AttributeSetInstance_ID FROM M_Storage) s " + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " AND s.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND l.M_Warehouse_ID=" + M_Warehouse_ID;
        //	sql += " AND s.M_AttributeSetInstance_ID=?";
        if (!showDetail) {
            //sql += " AND (s.QtyOnHand<>0)";
            sql += " GROUP BY s.M_Product_ID, w.Name, l.value, s.M_Locator_ID, sumPASI, ASI, BP_Name, DocumentNo, SeqNo ";
        } else
            //sql += " AND (s.QtyOnHand<>0) ";
            ;
        sql += " UNION ALL ";
        //	Orders
        sql += "SELECT ol.M_Product_ID, w.Name as warehouse, null as locator, ol.M_AttributeSetInstance_ID as ID, o.DatePromised as date," + " null as AvailQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE -ol.QtyReserved END as DeltaQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE null END as QtyOrdered," + " CASE WHEN dt.DocBaseType = 'POO' THEN 0 ELSE 0 END as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM C_Order o" + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp  ON (o.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO')" + " AND ol.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
        //if (m_M_AttributeSetInstance_ID > 0)
        //	sql += " AND ol.M_AttributeSetInstance_ID=?";
        //sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator";
        sql += " UNION ALL ";
        //	Distribution Orders out bound
        sql += "SELECT ol.M_Product_ID, wf.Name as warehouse, lf.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " -ol.QtyOrdered+ol.QtyInTransit+ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null  as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp  ON (o.C_BPartner_ID = bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered = 'N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND wf.M_Warehouse_ID=" + M_Warehouse_ID;
        //if (m_M_AttributeSetInstance_ID > 0)
        //	sql += " AND ol.M_AttributeSetInstance_ID=?";
        sql += " UNION ALL ";
        //	Distribution Orders in bound
        sql += "SELECT ol.M_Product_ID, w.Name as warehouse, l.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " ol.QtyOrdered-ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null  as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp  ON (wf.AD_Org_ID=bp.AD_OrgBP_ID) " + "WHERE ol.QtyOrdered - ol.Qtydelivered > 0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered='N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
        //if (m_M_AttributeSetInstance_ID > 0)
        //	sql += " AND ol.M_AttributeSetInstance_ID=?";
        sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator)";
        double qty = 0;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            int index = 1;
            pstmt = DB.prepareStatement(sql, null);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                //  The order of data matches the layout, not the query
                //  M_Product_ID, warehouse, locator, ID, Date, AvailQty, DeltaQty, (1..7) 
                //  QtyOrdered, QtyReserved, (8..9)
                //  sumPASI, ASI, (10..11)
                //  BP_Name, DocumentNo,  SeqNo (12..14)
                Vector<Object> line = new Vector<Object>(10);
                //  M_Product_ID
                line.add(rs.getInt(1));
                //  warehouse
                line.add(rs.getString(2));
                //  Locator
                line.add(rs.getString(3));
                //  Date
                line.add(rs.getTimestamp(5));
                double deltaQty = rs.getDouble(7);
                qty += +rs.getDouble(6) + deltaQty;
                //  Qty Available (running sum)
                line.add(new Double(qty) - rs.getDouble(9));
                //  Qty on hand (this line)
                line.add(new Double(rs.getDouble(6)));
                //  Delta Qty
                line.add(new Double(rs.getDouble(7)));
                //  BPartner
                line.add(rs.getString(12));
                //  QtyOrdered
                line.add(new Double(rs.getDouble(8)));
                //  QtyReserved
                line.add(new Double(rs.getDouble(9)));
                //  ASI
                line.add(rs.getString(10));
                //  DocumentNo
                line.add(rs.getString(13));
                data.add(line);
            }
        } catch (SQLException e) {
            log.log(Level.SEVERE, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    }
    //  Update the table
    //	Header
    Vector<String> columnNames = new Vector<String>();
    for (int i = 0; i < m_layoutATP.length; i++) {
        columnNames.add(m_layoutATP[i].getColHeader());
    }
    m_modelAtp = new DefaultTableModel();
    m_modelAtp.setDataVector(data, columnNames);
    //  Avoid an exception
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            m_tableAtp.setModel(m_modelAtp);
            //  set editors (two steps)
            for (int i = 0; i < m_layoutATP.length; i++) {
                m_tableAtp.setColumnClass(i, m_layoutATP[i].getColClass(), m_layoutATP[i].isReadOnly(), m_layoutATP[i].getColHeader());
                if (m_layoutATP[i].isColorColumn()) {
                    // QtyAvailable.
                    m_tableAtp.setColorColumn(i);
                }
            }
            m_tableAtp.autoSize();
        }
    });
}
Also used : SQLException(java.sql.SQLException) DefaultTableModel(javax.swing.table.DefaultTableModel) PreparedStatement(java.sql.PreparedStatement) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) IDColumn(org.compiere.minigrid.IDColumn) ResultSet(java.sql.ResultSet) Vector(java.util.Vector)

Example 23 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoPanel method readData.

private void readData(ResultSet rs) throws SQLException {
    //  columns start with 1
    int colOffset = 1;
    List<Object> data = new ArrayList<Object>();
    for (int col = 0; col < p_layout.length; col++) {
        Object value = null;
        Class<?> c = p_layout[col].getColClass();
        int colIndex = col + colOffset;
        if (c == IDColumn.class) {
            value = new IDColumn(rs.getInt(colIndex));
        } else if (c == Boolean.class)
            value = new Boolean("Y".equals(rs.getString(colIndex)));
        else if (c == Timestamp.class)
            value = rs.getTimestamp(colIndex);
        else if (c == BigDecimal.class)
            value = rs.getBigDecimal(colIndex);
        else if (c == Double.class)
            value = new Double(rs.getDouble(colIndex));
        else if (c == Integer.class)
            value = new Integer(rs.getInt(colIndex));
        else if (c == KeyNamePair.class) {
            String display = rs.getString(colIndex);
            int key = rs.getInt(colIndex + 1);
            value = new KeyNamePair(key, display);
            colOffset++;
        } else {
            value = rs.getString(colIndex);
        }
        data.add(value);
    }
    line.add(data);
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ArrayList(java.util.ArrayList) KeyNamePair(org.compiere.util.KeyNamePair) BigDecimal(java.math.BigDecimal)

Example 24 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoPanel method getSelectedRowKeys.

//  getSelectedRowKey
/**
     *  Get the keys of selected row/s based on layout defined in prepareTable
     *  @return IDs if selection present
     *  @author ashley
     */
protected ArrayList<Integer> getSelectedRowKeys() {
    ArrayList<Integer> selectedDataList = new ArrayList<Integer>();
    if (p_table.getKeyColumnIndex() == -1) {
        return selectedDataList;
    }
    if (p_multipleSelection) {
        int[] rows = p_table.getSelectedIndices();
        for (int row = 0; row < rows.length; row++) {
            Object data = p_table.getModel().getValueAt(rows[row], p_table.getKeyColumnIndex());
            if (data instanceof IDColumn) {
                IDColumn dataColumn = (IDColumn) data;
                selectedDataList.add(dataColumn.getRecord_ID());
            } else {
                log.severe("For multiple selection, IDColumn should be key column for selection");
            }
        }
    }
    if (selectedDataList.size() == 0) {
        int row = p_table.getSelectedRow();
        if (row != -1 && p_table.getKeyColumnIndex() != -1) {
            Object data = p_table.getModel().getValueAt(row, p_table.getKeyColumnIndex());
            if (data instanceof IDColumn)
                selectedDataList.add(((IDColumn) data).getRecord_ID());
            if (data instanceof Integer)
                selectedDataList.add((Integer) data);
        }
    }
    return selectedDataList;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ArrayList(java.util.ArrayList)

Example 25 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoProductPanel method refreshAtpTab.

//	initAtpTab	
/**
	 *	Refresh ATP
	 */
private void refreshAtpTab() {
    boolean showDetail = checkShowDetail.isSelected();
    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    int M_Warehouse_ID = 0;
    // row to prevent array index out of bounds. BF 3051361
    if (m_ATP_M_Warehouse_ID > 0) {
        M_Warehouse_ID = m_ATP_M_Warehouse_ID;
    } else
        M_Warehouse_ID = m_M_Warehouse_ID;
    if (M_Warehouse_ID == 0) {
    // Do nothing and pass blank data to the table
    } else // Update the table
    {
        //	Create the SELECT ..UNION. clause
        //  This is done in-line rather than using prepareTable() so we can add a running sum to the data.
        String sql;
        if (!showDetail)
            sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, 0 as ID, null as Date," + " sum(s.QtyOnHand) as AvailQty, null as DeltaQty, sum(s.QtyOrdered) as QtyOrdered, sum(s.QtyReserved) as QtyReserved," + // " s.PASI," 
            " null as sumPASI," + " 0 as ASI," + " null as BP_Name, null as DocumentNo, 10 as SeqNo";
        else
            sql = "(SELECT s.M_Product_ID, w.Name as warehouse, l.value as locator, s.M_AttributeSetInstance_ID as ID, now() as Date," + " s.QtyOnHand as AvailQty, null as DeltaQty, s.QtyOrdered as QtyOrdered, s.QtyReserved as QtyReserved," + " CASE WHEN s.PASI  = '' THEN '{' || COALESCE(s.M_AttributeSetInstance_ID,0) || '}' ELSE s.PASI END as sumPASI," + " COALESCE(M_AttributeSetInstance_ID,0) as ASI," + " null as BP_Name, null as DocumentNo,  10 as SeqNo";
        sql += " FROM (SELECT M_Product_ID, M_Locator_ID, QtyOnHand, QtyReserved, QtyOrdered," + " COALESCE(productAttribute(M_AttributeSetInstance_ID)::varchar, '') as PASI," + " COALESCE(M_AttributeSetInstance_ID,0) as M_AttributeSetInstance_ID FROM M_Storage) s " + " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " AND s.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND l.M_Warehouse_ID=" + M_Warehouse_ID;
        //	sql += " AND s.M_AttributeSetInstance_ID=?";
        if (!showDetail) {
            //sql += " AND (s.QtyOnHand<>0)";
            sql += " GROUP BY s.M_Product_ID, w.Name, l.value, s.M_Locator_ID, sumPASI, ASI, BP_Name, DocumentNo, SeqNo ";
        } else
            //sql += " AND (s.QtyOnHand<>0) ";
            ;
        sql += " UNION ALL ";
        //	Orders
        sql += "SELECT ol.M_Product_ID, w.Name as warehouse, null as locator, ol.M_AttributeSetInstance_ID as ID, o.DatePromised as date," + " null as AvailQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE -ol.QtyReserved END as DeltaQty," + " CASE WHEN dt.DocBaseType = 'POO' THEN ol.QtyOrdered ELSE null END as QtyOrdered," + " CASE WHEN dt.DocBaseType = 'POO' THEN 0 ELSE 0 END as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM C_Order o" + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp  ON (o.C_BPartner_ID=bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO')" + " AND ol.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
        //if (m_M_AttributeSetInstance_ID > 0)
        //	sql += " AND ol.M_AttributeSetInstance_ID=?";
        //sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator";
        sql += " UNION ALL ";
        //	Distribution Orders out bound
        sql += "SELECT ol.M_Product_ID, wf.Name as warehouse, lf.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " -ol.QtyOrdered+ol.QtyInTransit+ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null  as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp  ON (o.C_BPartner_ID = bp.C_BPartner_ID) " + "WHERE ol.QtyReserved<>0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered = 'N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND wf.M_Warehouse_ID=" + M_Warehouse_ID;
        //if (m_M_AttributeSetInstance_ID > 0)
        //	sql += " AND ol.M_AttributeSetInstance_ID=?";
        sql += " UNION ALL ";
        //	Distribution Orders in bound
        sql += "SELECT ol.M_Product_ID, w.Name as warehouse, l.value as locator, ol.M_AttributeSetInstance_ID as ID, ol.DatePromised as date," + " null as AvailQty," + " ol.QtyOrdered-ol.QtyDelivered as DeltaQty," + " null as QtyOrdered," + " null  as QtyReserved," + " productAttribute(ol.M_AttributeSetInstance_ID) as sumPASI," + " ol.M_AttributeSetInstance_ID as ASI," + " bp.Name as BP_Name, dt.PrintName || ' ' || o.DocumentNo As DocumentNo, 20 as SeqNo " + "FROM DD_Order o" + " INNER JOIN DD_OrderLine ol ON (o.DD_Order_ID=ol.DD_Order_ID)" + " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)" + " INNER JOIN M_Locator l ON (l.M_Locator_ID = ol.M_LocatorTo_ID)" + " INNER JOIN M_Locator lf on (lf.M_Locator_ID = ol.M_Locator_ID)" + " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID)" + " INNER JOIN M_Warehouse wf ON (lf.M_Warehouse_ID=wf.M_Warehouse_ID)" + " INNER JOIN C_BPartner bp  ON (wf.AD_Org_ID=bp.AD_OrgBP_ID) " + "WHERE ol.QtyOrdered - ol.Qtydelivered > 0 AND o.DocStatus in ('IP','CO') AND o.IsDelivered='N'" + " AND ol.M_Product_ID=" + m_M_Product_ID;
        if (M_Warehouse_ID != 0)
            sql += " AND w.M_Warehouse_ID=" + M_Warehouse_ID;
        //if (m_M_AttributeSetInstance_ID > 0)
        //	sql += " AND ol.M_AttributeSetInstance_ID=?";
        sql += " ORDER BY M_Product_ID, SeqNo, ID, date, locator)";
        double qty = 0;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            int index = 1;
            pstmt = DB.prepareStatement(sql, null);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                //  The order of data matches the layout, not the query
                //  M_Product_ID, warehouse, locator, ID, Date, AvailQty, DelataQty, (1..7) 
                //  QtyOrdered, QtyReserved, (8..9)
                //  PASI, ASI, (10..11)
                //  BP_Name, DocumentNo,  SeqNo (12..14)
                IDColumn mpid = new IDColumn(rs.getInt(1));
                Vector<Object> line = new Vector<Object>(9);
                //  M_Product_ID
                line.add(mpid);
                //  warehouse
                line.add(rs.getString(2));
                //  Locator
                line.add(rs.getString(3));
                //  Date
                line.add(rs.getTimestamp(5));
                double deltaQty = rs.getDouble(7);
                qty += +rs.getDouble(6) + deltaQty;
                //  Qty Available (running sum)
                line.add(new Double(qty) - rs.getDouble(9));
                //  Qty on hand (this line)
                line.add(new Double(rs.getDouble(6)));
                //  Delta Qty
                line.add(new Double(rs.getDouble(7)));
                //  BPartner
                line.add(rs.getString(12));
                //  QtyOrdered
                line.add(new Double(rs.getDouble(8)));
                //  QtyReserved
                line.add(new Double(rs.getDouble(9)));
                //  ASI
                line.add(rs.getString(10));
                //  DocumentNo
                line.add(rs.getString(13));
                data.add(line);
            }
        } catch (SQLException e) {
            log.log(Level.SEVERE, sql, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    }
    //	Header
    for (int i = 0; i < m_layoutATP.length; i++) {
        m_tableAtp.addColumn(m_layoutATP[i].getColHeader());
    }
    m_modelAtp = new ListModelTable(data);
    //  Avoid an exception
    //SwingUtilities.invokeLater(new Runnable(){public void run(){
    m_tableAtp.setModel(m_modelAtp);
    //  set editors (two steps)
    for (int i = 0; i < m_layoutATP.length; i++) {
        m_tableAtp.setColumnClass(i, m_layoutATP[i].getColClass(), m_layoutATP[i].isReadOnly(), m_layoutATP[i].getColHeader());
        if (m_layoutATP[i].isColorColumn()) {
            // QtyAvailable.
            m_tableAtp.setColorColumn(i);
        }
    }
    m_tableAtp.autoSize();
    m_tableAtp.repaint();
//}});
}
Also used : SQLException(java.sql.SQLException) ListModelTable(org.adempiere.webui.component.ListModelTable) PreparedStatement(java.sql.PreparedStatement) IDColumn(org.compiere.minigrid.IDColumn) ResultSet(java.sql.ResultSet) Vector(java.util.Vector)

Aggregations

IDColumn (org.compiere.minigrid.IDColumn)74 SQLException (java.sql.SQLException)23 BigDecimal (java.math.BigDecimal)19 PreparedStatement (java.sql.PreparedStatement)18 ResultSet (java.sql.ResultSet)18 ArrayList (java.util.ArrayList)15 KeyNamePair (org.compiere.util.KeyNamePair)13 Timestamp (java.sql.Timestamp)8 Vector (java.util.Vector)5 GridField (org.compiere.model.GridField)5 MBrowseField (org.adempiere.model.MBrowseField)4 ApplicationException (org.adempiere.webui.exception.ApplicationException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 PO (org.compiere.model.PO)3 Component (org.zkoss.zk.ui.Component)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)2 ChangeEvent (javax.swing.event.ChangeEvent)2