Search in sources :

Example 26 with KeyNamePair

use of org.compiere.util.KeyNamePair 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 27 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VMRPDetailed method setMRP.

/**
	 * Fill header MRP information
	 */
private void setMRP() {
    int M_Product_ID = getM_Product_ID();
    int M_AttributeSetInstance_ID = getM_AttributeSetInstance_ID();
    int M_Warehouse_ID = getM_Warehouse_ID();
    // Check Product (mandatory):
    if (M_Product_ID <= 0)
        return;
    // Set Quantities
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        StringBuffer sql = new StringBuffer("SELECT ").append("BOMQtyOnHandASI(M_Product_ID,?,?,?) as qtyonhand, ").append("BOMQtyReservedASI(M_Product_ID,?,?,?) as qtyreserved, ").append("BOMQtyAvailableASI(M_Product_ID,?,?,?) as qtyavailable, ").append("BOMQtyOrderedASI(M_Product_ID,?,?,?) as qtyordered").append(" FROM M_Product WHERE M_Product_ID=?");
        pstmt = DB.prepareStatement(sql.toString(), null);
        DB.setParameters(pstmt, new Object[] { getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_Product_ID() });
        rs = pstmt.executeQuery();
        while (rs.next()) {
            fOnhand.setValue(rs.getBigDecimal(1));
            fReserved.setValue(rs.getBigDecimal(2));
            fAvailable.setValue(rs.getBigDecimal(3));
            fOrdered.setValue(rs.getBigDecimal(4));
        }
    } catch (SQLException ex) {
        throw new DBException(ex);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    // Set UOM:
    int uom_id = MProduct.get(getCtx(), M_Product_ID).getC_UOM_ID();
    MUOM um = MUOM.get(getCtx(), uom_id);
    KeyNamePair kum = new KeyNamePair(um.getC_UOM_ID(), um.get_Translation(MUOM.COLUMNNAME_Name));
    fUOM.setText(kum.toString());
    //
    // Set Replenish Min Level:
    BigDecimal replenishLevelMin = Env.ZERO;
    if (getM_Warehouse_ID() > 0) {
        String sql = "SELECT Level_Min FROM M_Replenish" + " WHERE AD_Client_ID=? AND M_Product_ID=? AND M_Warehouse_ID=?";
        replenishLevelMin = DB.getSQLValueBD(null, sql, AD_Client_ID, M_Product_ID, M_Warehouse_ID);
    }
    fReplenishMin.setValue(replenishLevelMin);
}
Also used : DBException(org.adempiere.exceptions.DBException) MUOM(org.compiere.model.MUOM) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) BigDecimal(java.math.BigDecimal)

Example 28 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WAcctViewerData method fillOrg.

// fillTable
/**
	 *  Fill Org
	 *
	 *  @param cb Listbox to be filled
	 */
protected void fillOrg(Listbox cb) {
    KeyNamePair pp = new KeyNamePair(0, "");
    cb.appendItem(pp.getName(), pp);
    String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Client_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            KeyNamePair key = new KeyNamePair(rs.getInt(1), rs.getString(2));
            cb.appendItem(key.getName(), key);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair)

Example 29 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WAcctViewerData method fillAcctSchema.

// dispose
/**************************************************************************
	 *  Fill Accounting Schema
	 *  @param cb Listbox to be filled
	 */
protected void fillAcctSchema(Listbox cb) {
    for (int i = 0; i < ASchemas.length; i++) {
        KeyNamePair key = new KeyNamePair(ASchemas[i].getC_AcctSchema_ID(), ASchemas[i].getName());
        cb.appendItem(key.getName(), key);
    }
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 30 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class ZkReportViewer method fillComboReport.

//	dynInit
/**
	 * 	Fill ComboBox comboReport (report options)
	 *  @param AD_PrintFormat_ID item to be selected
	 */
private void fillComboReport(int AD_PrintFormat_ID) {
    comboReport.removeEventListener(Events.ON_SELECT, this);
    comboReport.getItems().clear();
    Listitem selectValue = null;
    //	fill Report Options
    String sql = MRole.getDefault().addAccessSQL("SELECT AD_PrintFormat_ID, Name, Description " + "FROM AD_PrintFormat " + "WHERE AD_Table_ID=? " + //Added Lines by Armen
    "AND IsActive='Y' " + //End of Added Lines
    "ORDER BY Name", "AD_PrintFormat", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Table_ID);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            Listitem li = comboReport.appendItem(pp.getName(), pp.getKey());
            if (rs.getInt(1) == AD_PrintFormat_ID) {
                selectValue = li;
                comboReport.setSelectedItem(li);
            }
        }
        //	Select Default
        if (selectValue != null) {
            comboReport.setSelectedItem(selectValue);
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    StringBuffer sb = new StringBuffer("** ").append(Msg.getMsg(Env.getCtx(), "NewReport")).append(" **");
    KeyNamePair pp = new KeyNamePair(-1, sb.toString());
    comboReport.appendItem(pp.getName(), pp.getKey());
    sb = new StringBuffer("** ").append(Msg.getMsg(m_ctx, "CopyReport")).append(" **");
    pp = new KeyNamePair(-2, sb.toString());
    comboReport.addItem(pp);
    comboReport.addEventListener(Events.ON_SELECT, this);
    //	FR [ 237 ]
    fillComboReportView();
}
Also used : SQLException(java.sql.SQLException) Listitem(org.zkoss.zul.Listitem) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7