Search in sources :

Example 51 with IDColumn

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

the class OrderReceiptIssue method lotes.

/**
	 * Adds Attribute Set Instances Quantities to table. Extension to
	 * {@link #executeQuery()}
	 * 
	 * @return how many lines were added
	 */
private int lotes(int row, IDColumn id, int Warehouse_ID, int M_Product_ID, BigDecimal qtyRequired, BigDecimal qtyToDelivery, IMiniTable issue) {
    int linesNo = 0;
    BigDecimal qtyRequiredActual = qtyRequired;
    final String sql = "SELECT " + "s.M_Product_ID , s.QtyOnHand, s.M_AttributeSetInstance_ID" + ", p.Name, masi.Description, l.M_Locator_ID , l.Value, w.Value, w.M_warehouse_ID,p.Value" + "  FROM M_Storage s " + " INNER JOIN M_Product p ON (s.M_Product_ID = p.M_Product_ID) " + " INNER JOIN C_UOM u ON (u.C_UOM_ID = p.C_UOM_ID) " + " INNER JOIN M_AttributeSetInstance masi ON (masi.M_AttributeSetInstance_ID = s.M_AttributeSetInstance_ID) " + " INNER JOIN M_Warehouse w ON (w.M_Warehouse_ID = ?) " + " INNER JOIN M_Locator l ON(l.M_Warehouse_ID=w.M_Warehouse_ID and s.M_Locator_ID=l.M_Locator_ID) " + " WHERE s.M_Product_ID = ? and s.QtyOnHand > 0 " + " and s.M_AttributeSetInstance_ID <> 0 " + " ORDER BY s.Created ";
    // Execute
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, Warehouse_ID);
        pstmt.setInt(2, M_Product_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            issue.setRowCount(row + 1);
            // Qty On Hand
            final BigDecimal qtyOnHand = rs.getBigDecimal(2);
            // ID/M_AttributeSetInstance_ID
            IDColumn id1 = new IDColumn(rs.getInt(3));
            id1.setSelected(false);
            // issue.setRowSelectionAllowed(true);
            issue.setValueAt(id1, row, 0);
            // Product
            KeyNamePair productkey = new KeyNamePair(rs.getInt(1), rs.getString(4));
            issue.setValueAt(productkey, row, 3);
            // QtyOnHand
            issue.setValueAt(qtyOnHand, row, 10);
            // ASI
            issue.setValueAt(rs.getString(5), row, 5);
            // Locator
            KeyNamePair locatorKey = new KeyNamePair(rs.getInt(6), rs.getString(7));
            issue.setValueAt(locatorKey, row, 13);
            // Warehouse
            KeyNamePair m_warehousekey = new KeyNamePair(rs.getInt(9), rs.getString(8));
            issue.setValueAt(m_warehousekey, row, 14);
            // QtyRequired
            issue.setValueAt(Env.ZERO, row, 6);
            // QtyToDelivery
            issue.setValueAt(Env.ZERO, row, 8);
            // Srcap
            issue.setValueAt(Env.ZERO, row, 9);
            // Qty Required:
            if (qtyRequiredActual.compareTo(qtyOnHand) < 0) {
                issue.setValueAt(qtyRequiredActual.signum() > 0 ? qtyRequiredActual : Env.ZERO, row, 6);
            } else {
                issue.setValueAt(qtyOnHand, row, 6);
            }
            qtyRequiredActual = qtyRequiredActual.subtract(qtyOnHand);
            linesNo++;
            row++;
        }
    } catch (SQLException e) {
        throw new DBException(e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return linesNo;
}
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 52 with IDColumn

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

the class OrderReceiptIssue method createIssue.

/**
	 * Performs what ever task is attached to the combo box
	 * 
	 * @return Whether the process was successful or not
	 */
/*
	 * public boolean cmd_process(final boolean isCloseDocument, final
	 * IMiniTable issue) {
	 * 
	 * if (isOnlyReceipt() || isBackflush()) { if (getM_Locator_ID() <= 0) {
	 * //JOptionPane.showMessageDialog(null,
	 * Msg.getMsg(Env.getCtx(),"NoLocator"), "Info",
	 * JOptionPane.INFORMATION_MESSAGE); showMessage(
	 * Msg.getMsg(Env.getCtx(),"NoLocator"), false); } } if (getPP_Order() ==
	 * null || getMovementDate() == null) { return false; } try { Trx.run(new
	 * TrxRunnable() { public void run(String trxName) { MPPOrder order = new
	 * MPPOrder(Env.getCtx(), getPP_Order_ID(), trxName); if (isBackflush() ||
	 * isOnlyIssue()) { createIssue(order, issue); } if (isOnlyReceipt() ||
	 * isBackflush()) { MPPOrder.createReceipt(order, getMovementDate(),
	 * getDeliveredQty(), getToDeliverQty(), getScrapQty(), getRejectQty(),
	 * getM_Locator_ID(), getM_AttributeSetInstance_ID() ); if (isCloseDocument)
	 * { order.setDateFinish(getMovementDate()); order.closeIt();
	 * order.saveEx(); } } }}); } catch (Exception e) {
	 * showMessage(e.getLocalizedMessage(), true); return false; } finally {
	 * m_PP_order = null; }
	 * 
	 * return true; }
	 */
public void createIssue(MPPOrder order, IMiniTable issue) {
    Timestamp movementDate = getMovementDate();
    Timestamp minGuaranteeDate = movementDate;
    boolean isCompleteQtyDeliver = false;
    ArrayList[][] m_issue = new ArrayList[issue.getRowCount()][1];
    int row = 0;
    // Check Available On Hand Qty
    for (int i = 0; i < issue.getRowCount(); i++) {
        ArrayList<Object> data = new ArrayList<Object>();
        IDColumn id = (IDColumn) issue.getValueAt(i, 0);
        KeyNamePair key = new KeyNamePair(id.getRecord_ID(), id.isSelected() ? "Y" : "N");
        // 0 - ID
        data.add(key);
        // 1 - IsCritical
        data.add(issue.getValueAt(i, 1));
        // 2 - Value
        data.add(issue.getValueAt(i, 2));
        // 3 - KeyNamePair Product
        data.add(issue.getValueAt(i, 3));
        // 4 - QtyToDeliver
        data.add(getValueBigDecimal(issue, i, 8));
        // 5 - QtyScrapComponent
        data.add(getValueBigDecimal(issue, i, 9));
        // 6 - Location Id
        KeyNamePair location = (KeyNamePair) issue.getValueAt(i, 13);
        if (location != null)
            // 7 - Location
            data.add(location.getID());
        else
            data.add(0);
        m_issue[row][0] = data;
        row++;
    }
    isCompleteQtyDeliver = MPPOrder.isQtyAvailable(order, m_issue, minGuaranteeDate);
    for (int i = 0; i < m_issue.length; i++) {
        KeyNamePair key = (KeyNamePair) m_issue[i][0].get(0);
        boolean isSelected = key.getName().equals("Y");
        if (key == null || !isSelected)
            continue;
        Boolean isCritical = (Boolean) m_issue[i][0].get(1);
        String value = (String) m_issue[i][0].get(2);
        KeyNamePair productkey = (KeyNamePair) m_issue[i][0].get(3);
        int productId = productkey.getKey();
        MPPOrderBOMLine orderbomLine = null;
        int orderBOMLineId = 0;
        int attributeSetInstanceId = 0;
        int locatorId = 0;
        BigDecimal qtyToDeliver = (BigDecimal) m_issue[i][0].get(4);
        BigDecimal qtyScrapComponent = (BigDecimal) m_issue[i][0].get(5);
        MProduct product = MProduct.get(order.getCtx(), productId);
        if (product != null && product.get_ID() != 0 && product.isStocked()) {
            if (value == null && isSelected) {
                attributeSetInstanceId = key.getKey();
                locatorId = new Integer((String) m_issue[i][0].get(6));
                if (attributeSetInstanceId == 0)
                    attributeSetInstanceId = (Integer) key.getKey();
                orderbomLine = MPPOrderBOMLine.forM_Product_ID(Env.getCtx(), order.get_ID(), productId, order.get_TrxName());
                if (orderbomLine != null)
                    orderBOMLineId = orderbomLine.get_ID();
            } else if (value != null && isSelected) {
                orderBOMLineId = (Integer) key.getKey();
                if (orderBOMLineId > 0)
                    orderbomLine = new MPPOrderBOMLine(order.getCtx(), orderBOMLineId, order.get_TrxName());
                attributeSetInstanceId = orderbomLine.getM_AttributeSetInstance_ID();
            }
            MStorage[] totalStorages = MPPOrder.getStorages(Env.getCtx(), productId, order.getM_Warehouse_ID(), attributeSetInstanceId, minGuaranteeDate, order.get_TrxName());
            MStorage[] storages;
            if (locatorId > 0) {
                int finalLocatorId = locatorId;
                storages = Arrays.stream(totalStorages).filter(storaage -> storaage.getM_Locator_ID() == finalLocatorId).toArray(MStorage[]::new);
            } else
                storages = totalStorages;
            boolean forceIssue = false;
            BigDecimal toIssue = qtyToDeliver.add(qtyScrapComponent);
            //allow return quantity order line
            if (storages == null || storages.length == 0) {
                if (toIssue.signum() < 0 && toIssue.add(orderbomLine.getQtyDelivered()).signum() >= 0)
                    forceIssue = true;
            }
            MPPOrder.createIssue(order, orderbomLine, movementDate, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
        }
    }
}
Also used : MProduct(org.compiere.model.MProduct) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) IDColumn(org.compiere.minigrid.IDColumn) MPPOrderBOMLine(org.eevolution.model.MPPOrderBOMLine) KeyNamePair(org.compiere.util.KeyNamePair)

Example 53 with IDColumn

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

the class OrderReceiptIssue method generateSummaryTable.

// executeQuery
public String generateSummaryTable(IMiniTable issue, String productField, String uomField, String attribute, String toDeliverQty, String deliveredQtyField, String scrapQtyField, boolean isBackflush, boolean isOnlyIssue, boolean isOnlyReceipt) {
    StringBuffer iText = new StringBuffer();
    iText.append("<b>");
    iText.append(Msg.parseTranslation(Env.getCtx(), "@IsShipConfirm@"));
    iText.append("</b>");
    iText.append("<br />");
    if (isOnlyReceipt || isBackflush) {
        String[][] table = { { Msg.translate(Env.getCtx(), "Name"), Msg.translate(Env.getCtx(), "C_UOM_ID"), Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID"), Msg.translate(Env.getCtx(), "QtyToDeliver"), Msg.translate(Env.getCtx(), "QtyDelivered"), Msg.translate(Env.getCtx(), "QtyScrap") }, { productField, uomField, attribute, toDeliverQty, deliveredQtyField, scrapQtyField } };
        iText.append(createHTMLTable(table));
    }
    if (isBackflush || isOnlyIssue) {
        iText.append("<br /><br />");
        ArrayList<String[]> table = new ArrayList<String[]>();
        table.add(new String[] { // 0
        Msg.translate(Env.getCtx(), "Value"), // 1
        Msg.translate(Env.getCtx(), "Name"), // 2
        Msg.translate(Env.getCtx(), "C_UOM_ID"), // 3
        Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID"), // 4
        Msg.translate(Env.getCtx(), "QtyToDeliver"), // 5
        Msg.translate(Env.getCtx(), "QtyDelivered"), // 6
        Msg.translate(Env.getCtx(), "QtyScrap") });
        // check available on hand
        for (int i = 0; i < issue.getRowCount(); i++) {
            IDColumn id = (IDColumn) issue.getValueAt(i, 0);
            if (id != null && id.isSelected()) {
                KeyNamePair m_productkey = (KeyNamePair) issue.getValueAt(i, 3);
                int m_M_Product_ID = m_productkey.getKey();
                KeyNamePair m_uomkey = (KeyNamePair) issue.getValueAt(i, 4);
                if (// M_AttributeSetInstance_ID
                issue.getValueAt(i, 5) == null) // is null
                {
                    Timestamp m_movementDate = getMovementDate();
                    Timestamp minGuaranteeDate = m_movementDate;
                    MStorage[] storages = MPPOrder.getStorages(Env.getCtx(), m_M_Product_ID, getPP_Order().getM_Warehouse_ID(), 0, minGuaranteeDate, null);
                    // Qty Delivered
                    BigDecimal qtyDelivered = getValueBigDecimal(issue, i, 7);
                    // QtyOpen
                    BigDecimal toDelivery = getValueBigDecimal(issue, i, 8);
                    // QtyScrap
                    BigDecimal scrap = getValueBigDecimal(issue, i, 9);
                    BigDecimal toIssue = toDelivery.add(scrap);
                    //allow return quantity order line
                    if (storages == null || storages.length == 0) {
                        if (toIssue.signum() < 0 && qtyDelivered.signum() > 0 && qtyDelivered.add(toIssue).signum() >= 0) {
                            String[] row = { "", "", "", "", "0.00", "0.00", "0.00" };
                            row[0] = issue.getValueAt(i, 2) != null ? issue.getValueAt(i, 2).toString() : "";
                            row[1] = m_productkey.toString();
                            row[2] = m_uomkey != null ? m_uomkey.toString() : "";
                            String desc = null;
                            row[3] = desc != null ? desc : "";
                            row[4] = toIssue.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                            row[5] = getValueBigDecimal(issue, i, 7).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                            row[6] = getValueBigDecimal(issue, i, 9).toString();
                            table.add(row);
                        }
                        continue;
                    }
                    for (MStorage storage : storages) {
                        if (storage.getQtyOnHand().signum() == 0)
                            continue;
                        BigDecimal issueact = toIssue;
                        if (issueact.compareTo(storage.getQtyOnHand()) > 0)
                            issueact = storage.getQtyOnHand();
                        toIssue = toIssue.subtract(issueact);
                        String desc = new MAttributeSetInstance(Env.getCtx(), storage.getM_AttributeSetInstance_ID(), null).getDescription();
                        String[] row = { "", "", "", "", "0.00", "0.00", "0.00" };
                        row[0] = issue.getValueAt(i, 2) != null ? issue.getValueAt(i, 2).toString() : "";
                        row[1] = m_productkey.toString();
                        row[2] = m_uomkey != null ? m_uomkey.toString() : "";
                        row[3] = desc != null ? desc : "";
                        row[4] = issueact.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                        row[5] = getValueBigDecimal(issue, i, 7).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                        row[6] = getValueBigDecimal(issue, i, 9).toString();
                        table.add(row);
                        if (toIssue.signum() <= 0)
                            break;
                    }
                } else // if M_AttributeSetInstance_ID isn't null
                {
                    String[] row = { "", "", "", "", "0.00", "0.00", "0.00" };
                    row[0] = issue.getValueAt(i, 2) != null ? issue.getValueAt(i, 2).toString() : "";
                    row[1] = m_productkey.toString();
                    row[2] = m_uomkey != null ? m_uomkey.toString() : "";
                    row[3] = issue.getValueAt(i, 5) != null ? issue.getValueAt(i, 5).toString() : "";
                    row[4] = getValueBigDecimal(issue, i, 8).toString();
                    row[5] = getValueBigDecimal(issue, i, 7).toString();
                    row[6] = getValueBigDecimal(issue, i, 9).toString();
                    table.add(row);
                }
            }
        }
        String[][] tableArray = table.toArray(new String[table.size()][]);
        iText.append(createHTMLTable(tableArray));
    }
    return iText.toString();
}
Also used : ArrayList(java.util.ArrayList) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) IDColumn(org.compiere.minigrid.IDColumn) KeyNamePair(org.compiere.util.KeyNamePair)

Example 54 with IDColumn

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

the class OrderDistribution method saveSelection.

//  executeQuery
/**
	 *	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 55 with IDColumn

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

the class OrderDistribution method executeQuery.

/**
	 *  Query Info
	 */
public void executeQuery(IMiniTable miniTable) {
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
    String sql = "";
    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, AD_Client_ID);
        ResultSet rs = pstmt.executeQuery();
        //
        while (rs.next()) {
            //  extend table
            miniTable.setRowCount(row + 1);
            //  set values
            //  C_Order_ID
            miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, 0);
            //  Org
            miniTable.setValueAt(rs.getString(2), row, 1);
            //  DocType
            miniTable.setValueAt(rs.getString(3), row, 2);
            //  Doc No
            miniTable.setValueAt(rs.getString(4), row, 3);
            //  BPartner
            miniTable.setValueAt(rs.getString(5), row, 4);
            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)

Aggregations

IDColumn (org.compiere.minigrid.IDColumn)79 SQLException (java.sql.SQLException)25 BigDecimal (java.math.BigDecimal)20 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)20 ArrayList (java.util.ArrayList)16 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 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)2 ChangeEvent (javax.swing.event.ChangeEvent)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2