Search in sources :

Example 6 with IDColumn

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

the class OrderReceiptIssue method saveSelection.

/**
	 * Save Selection & return selecion Query or ""
	 * 
	 * @return where clause like C_Order_ID IN (...)
	 */
public void saveSelection(IMiniTable miniTable) {
    log.info("");
    // Array of Integers
    ArrayList<Integer> results = new ArrayList<Integer>();
    setSelection(null);
    // Get selected entries
    int rows = miniTable.getRowCount();
    for (int i = 0; i < rows; i++) {
        // ID in column
        IDColumn id = (IDColumn) miniTable.getValueAt(i, 0);
        // log.fine( "Row=" + i + " - " + id);
        if (id != null && id.isSelected())
            results.add(id.getRecord_ID());
    }
    if (results.size() == 0)
        return;
    log.config("Selected #" + results.size());
    setSelection(results);
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ArrayList(java.util.ArrayList)

Example 7 with IDColumn

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

the class OrderReceiptIssue method executeQuery.

/**
	 * Query Info
	 */
public void executeQuery(IMiniTable issue) {
    final String sql = "SELECT " + // 1
    "obl.PP_Order_BOMLine_ID," + // 2
    "obl.IsCritical," + // 3
    "p.Value," + // 4,5
    "obl.M_Product_ID,p.Name," + // 6,7
    "p.C_UOM_ID,u.Name," + // 8
    "obl.QtyRequired," + // 9
    "obl.QtyReserved," + // 10
    "bomQtyAvailable(obl.M_Product_ID,obl.M_Warehouse_ID,0 ) AS QtyAvailable," + // 11
    "bomQtyOnHand(obl.M_Product_ID,obl.M_Warehouse_ID,0) AS QtyOnHand," + // 12
    "p.M_Locator_ID," + // 13,14
    "obl.M_Warehouse_ID,w.Name," + // 15
    "obl.QtyBom," + // 16
    "obl.isQtyPercentage," + // 17
    "obl.QtyBatch," + // 18
    "obl.ComponentType," + // 19
    "obl.QtyRequired - QtyDelivered AS QtyOpen," + // 20
    "obl.QtyDelivered" + " FROM PP_Order_BOMLine obl" + " INNER JOIN M_Product p ON (obl.M_Product_ID = p.M_Product_ID) " + " INNER JOIN C_UOM u ON (p.C_UOM_ID = u.C_UOM_ID) " + " INNER JOIN M_Warehouse w ON (w.M_Warehouse_ID = obl.M_Warehouse_ID) " + " WHERE obl.PP_Order_ID = ?" + " ORDER BY obl." + MPPOrderBOMLine.COLUMNNAME_Line;
    // reset table
    int row = 0;
    issue.setRowCount(row);
    // Execute
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, getPP_Order_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            // extend table
            issue.setRowCount(row + 1);
            // set values
            // issue.
            IDColumn id = new IDColumn(rs.getInt(1));
            BigDecimal qtyBom = rs.getBigDecimal(15);
            Boolean isQtyPercentage = rs.getString(16).equals("Y");
            Boolean isCritical = rs.getString(2).equals("Y");
            BigDecimal qtyBatch = rs.getBigDecimal(17);
            BigDecimal qtyRequired = rs.getBigDecimal(8);
            BigDecimal qtyOnHand = rs.getBigDecimal(11);
            BigDecimal qtyOpen = rs.getBigDecimal(19);
            BigDecimal qtyDelivered = rs.getBigDecimal(20);
            String componentType = rs.getString(18);
            BigDecimal toDeliverQty = getToDeliverQty();
            BigDecimal openQty = getOpenQty();
            BigDecimal scrapQty = getScrapQty();
            BigDecimal componentToDeliverQty = Env.ZERO;
            BigDecimal componentScrapQty = Env.ZERO;
            BigDecimal componentQtyReq = Env.ZERO;
            BigDecimal componentQtyToDel = Env.ZERO;
            id.setSelected(isOnlyReceipt());
            // PP_OrderBOMLine_ID
            issue.setValueAt(id, row, 0);
            // IsCritical
            issue.setValueAt(isCritical, row, 1);
            // Product's Search
            issue.setValueAt(rs.getString(3), row, 2);
            // key
            // Product
            issue.setValueAt(new KeyNamePair(rs.getInt(4), rs.getString(5)), row, 3);
            // UOM
            issue.setValueAt(new KeyNamePair(rs.getInt(6), rs.getString(7)), row, 4);
            // ... 5 - ASI
            // QtyRequired
            issue.setValueAt(qtyRequired, row, 6);
            // QtyDelivered
            issue.setValueAt(qtyDelivered, row, 7);
            // ... 8, 9, 10 - QtyToDeliver, QtyScrap, QtyOnHand
            // OnHand
            issue.setValueAt(qtyOnHand, row, 10);
            // QtyReserved
            issue.setValueAt(rs.getBigDecimal(9), row, 11);
            // QtyAvailable
            issue.setValueAt(rs.getBigDecimal(10), row, 12);
            // ... 13 - M_Locator_ID
            // Warehouse
            issue.setValueAt(new KeyNamePair(rs.getInt(13), rs.getString(14)), row, 14);
            // QtyBom
            issue.setValueAt(qtyBom, row, 15);
            // isQtyPercentage
            issue.setValueAt(isQtyPercentage, row, 16);
            // QtyBatch
            issue.setValueAt(qtyBatch, row, 17);
            if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Component) || componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing)) {
                // If the there is product on hand and product is required
                // the product should be selected
                id.setSelected(qtyOnHand.signum() > 0 && qtyRequired.signum() > 0);
                // PP_OrderBOMLine_ID
                issue.setValueAt(id, row, 0);
                if (isQtyPercentage) {
                    // If the quantity of product is calculated as a
                    // percentage
                    BigDecimal qtyBatchPerc = qtyBatch.divide(Env.ONEHUNDRED, 8, RoundingMode.HALF_UP);
                    if (isBackflush()) {
                        // Component from Qty To Deliver
                        if (qtyRequired.signum() == 0 || qtyOpen.signum() == 0) {
                            componentToDeliverQty = Env.ZERO;
                        } else {
                            componentToDeliverQty = toDeliverQty.multiply(qtyBatchPerc);
                            if (qtyRequired.subtract(qtyDelivered).signum() < 0 | componentToDeliverQty.signum() == 0)
                                componentToDeliverQty = qtyRequired.subtract(qtyDelivered);
                        }
                        if (componentToDeliverQty.signum() != 0) {
                            // TODO: arhipac: teo_sarca: is this a bug ?
                            // ...instead of toDeliverQty, qtyRequired
                            // should be used!
                            // componentQtyReq =
                            // toDeliverQty.multiply(qtyBatchPerc); // TODO:
                            // set scale 4
                            componentQtyToDel = componentToDeliverQty.setScale(4, BigDecimal.ROUND_HALF_UP);
                            // issue.setValueAt(toDeliverQty.multiply(qtyBatchPerc),
                            // row, 6); // QtyRequired
                            // QtyToDelivery
                            issue.setValueAt(componentToDeliverQty, row, 8);
                        }
                    } else {
                        // Only Issue - Calculate Component from Open
                        // Qty
                        componentToDeliverQty = qtyOpen;
                        if (componentToDeliverQty.signum() != 0) {
                            // scale 4
                            componentQtyReq = openQty.multiply(qtyBatchPerc);
                            componentQtyToDel = componentToDeliverQty.setScale(4, BigDecimal.ROUND_HALF_UP);
                            // QtyToDelivery
                            issue.setValueAt(componentToDeliverQty.setScale(8, BigDecimal.ROUND_HALF_UP), row, 8);
                            // QtyRequired
                            issue.setValueAt(openQty.multiply(qtyBatchPerc), row, 6);
                        }
                    }
                    if (scrapQty.signum() != 0) {
                        componentScrapQty = scrapQty.multiply(qtyBatchPerc);
                        if (componentScrapQty.signum() != 0) {
                            // QtyScrap
                            issue.setValueAt(componentScrapQty, row, 9);
                        }
                    } else
                        // QtyScrap
                        issue.setValueAt(componentScrapQty, row, 9);
                } else {
                    // Absolute Qtys (not Percentage)
                    if (isBackflush()) {
                        // Component from Qty To Deliver
                        if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing))
                            componentToDeliverQty = qtyRequired.subtract(qtyDelivered);
                        else
                            // TODO: set Number scale
                            componentToDeliverQty = toDeliverQty.multiply(qtyBom);
                        if (componentToDeliverQty.signum() != 0) {
                            if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing))
                                componentQtyReq = qtyRequired.subtract(qtyDelivered);
                            else
                                componentQtyReq = toDeliverQty.multiply(qtyBom);
                            componentQtyToDel = componentToDeliverQty;
                            // QtyRequired
                            issue.setValueAt(componentQtyReq, row, 6);
                            // QtyToDelivery
                            issue.setValueAt(componentToDeliverQty, row, 8);
                        }
                    } else {
                        // Only Issue - Calculate Component from Open
                        // Qty
                        componentToDeliverQty = qtyOpen;
                        if (componentToDeliverQty.signum() != 0) {
                            if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing))
                                componentQtyReq = qtyOpen;
                            else
                                componentQtyReq = openQty.multiply(qtyBom);
                            componentQtyToDel = componentToDeliverQty;
                            // QtyRequired
                            issue.setValueAt(componentQtyReq, row, 6);
                            // QtyToDelivery
                            issue.setValueAt(componentToDeliverQty, row, 8);
                        }
                    }
                    if (scrapQty.signum() != 0) {
                        // TODO:
                        componentScrapQty = scrapQty.multiply(qtyBom);
                        // scale
                        if (componentScrapQty.signum() != 0) {
                            // ScrapQty
                            issue.setValueAt(componentScrapQty, row, 9);
                        }
                    } else
                        // ScrapQty
                        issue.setValueAt(componentScrapQty, row, 9);
                }
            } else if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Tools)) {
                // TODO; set Number scale
                componentToDeliverQty = qtyBom;
                if (componentToDeliverQty.signum() != 0) {
                    componentQtyReq = qtyBom;
                    componentQtyToDel = componentToDeliverQty;
                    // QtyRequired
                    issue.setValueAt(qtyBom, row, 6);
                    // QtyToDelivery
                    issue.setValueAt(componentToDeliverQty, row, 8);
                }
            } else {
                // QtyRequired
                issue.setValueAt(Env.ZERO, row, 6);
            //issue.setValueAt(Env.ZERO, row, 8); // QtyToDelivery
            }
            row++;
            if (isOnlyIssue() || isBackflush()) {
                int warehouse_id = rs.getInt(13);
                int product_id = rs.getInt(4);
                row += lotes(row, id, warehouse_id, product_id, componentQtyReq, componentQtyToDel, issue);
            }
        }
    // while
    } catch (SQLException e) {
        throw new DBException(e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    issue.autoSize();
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) BigDecimal(java.math.BigDecimal)

Example 8 with IDColumn

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

the class OrderDistributionReceipt method saveSelection.

//	dispose
/**
	 *	Save Selection & return selecion Query or ""
	 *  @return where clause like C_Order_ID IN (...)
	 */
public void saveSelection(IMiniTable miniTable) {
    log.info("");
    //  Array of Integers
    ArrayList<Integer> results = new ArrayList<Integer>();
    setSelection(null);
    //	Get selected entries
    int rows = miniTable.getRowCount();
    for (int i = 0; i < rows; i++) {
        //  ID in column 0
        IDColumn id = (IDColumn) miniTable.getValueAt(i, 0);
        //	log.fine( "Row=" + i + " - " + id);
        if (id != null && id.isSelected())
            results.add(id.getRecord_ID());
    }
    if (results.size() == 0)
        return;
    log.config("Selected #" + results.size());
    setSelection(results);
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ArrayList(java.util.ArrayList)

Example 9 with IDColumn

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

the class OrderDistributionReceipt method executeQuery.

/**
	 *  Query Info
	 */
public void executeQuery(IMiniTable miniTable) {
    log.info("");
    String sql = "";
    if (m_DD_Order_ID == null)
        return;
    sql = getOrderSQL();
    log.fine(sql);
    //  reset table
    int row = 0;
    miniTable.setRowCount(row);
    //  Execute
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
        pstmt.setInt(1, Integer.parseInt(m_DD_Order_ID.toString()));
        ResultSet rs = pstmt.executeQuery();
        //
        while (rs.next()) {
            //  extend table
            miniTable.setRowCount(row + 1);
            //  set values
            //  DD_Order_ID
            miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0);
            //  QtyInTransit
            miniTable.setValueAt(rs.getBigDecimal(2), row, 1);
            //  C_UOM_ID
            miniTable.setValueAt(rs.getString(3), row, 2);
            //  Value
            miniTable.setValueAt(rs.getString(4), row, 4);
            //  M_Product_ID
            miniTable.setValueAt(rs.getString(5), row, 3);
            //  WarehouseSource
            miniTable.setValueAt(rs.getString(6), row, 5);
            //  prepare next
            row++;
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql.toString(), e);
    }
    //
    miniTable.autoSize();
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 10 with IDColumn

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

the class WBrowser method selectedRows.

/**
	 * Selected Rows
	 */
private void selectedRows() {
    int topIndex = detail.isShowTotals() ? 2 : 1;
    int rows = detail.getRowCount();
    int[] selectedList = new int[rows];
    if (isAllSelected) {
        for (int row = 0; row <= rows - topIndex; row++) {
            Object data = detail.getModel().getValueAt(row, m_keyColumnIndex);
            if (data instanceof IDColumn) {
                IDColumn dataColumn = (IDColumn) data;
                dataColumn.setSelected(true);
                detail.getModel().setValueAt(dataColumn, row, m_keyColumnIndex);
            }
            selectedList[row] = row;
        }
        detail.setSelectedIndices(selectedList);
    } else {
        for (int row = 0; row <= rows - topIndex; row++) {
            Object data = detail.getModel().getValueAt(row, m_keyColumnIndex);
            if (data instanceof IDColumn) {
                IDColumn dataColumn = (IDColumn) data;
                dataColumn.setSelected(false);
                detail.getModel().setValueAt(dataColumn, row, m_keyColumnIndex);
            }
        }
        detail.clearSelection();
    }
    isAllSelected = !isAllSelected;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn)

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