Search in sources :

Example 26 with MStorage

use of org.compiere.model.MStorage in project adempiere by adempiere.

the class InventoryTestException method dumpStatus.

private void dumpStatus(MMDocument doc, String trxName) {
    MProduct product = InventoryUtil.getCreateProduct(doc);
    MStorage[] storage = MStorage.getOfProduct(getCtx(), product.get_ID(), trxName);
    System.err.println("" + product.toString());
    System.err.println("STORAGE____________________________________________________");
    System.err.println("   " + doc);
    for (MStorage s : storage) {
        System.err.println("" + s);
    }
    //
    //
    System.err.println("COST QUEUE ________________________________________________");
    List<MCostQueue> queue = new Query(getCtx(), MCostQueue.Table_Name, "M_Product_ID=?", trxName).setParameters(new Object[] { product.get_ID() }).setOrderBy(MCostQueue.COLUMNNAME_M_CostQueue_ID).list();
    for (MCostQueue q : queue) {
        System.err.println("" + q);
    }
    //
    //
    System.err.println("COST Detail ________________________________________________");
    List<MCostDetail> details = new Query(getCtx(), MCostDetail.Table_Name, "M_Product_ID=?", trxName).setParameters(new Object[] { product.get_ID() }).setOrderBy(MCostDetail.COLUMNNAME_M_CostDetail_ID).list();
    for (MCostDetail cd : details) {
        System.err.println("" + cd.toString());
    }
    //
    //
    System.err.println(doc.scenario.toString());
    //	
    System.err.println("___________________________________________________________");
    System.err.flush();
    System.err.flush();
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MCostQueue(org.compiere.model.MCostQueue) MCostDetail(org.compiere.model.MCostDetail) MStorage(org.compiere.model.MStorage)

Example 27 with MStorage

use of org.compiere.model.MStorage 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 28 with MStorage

use of org.compiere.model.MStorage 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 29 with MStorage

use of org.compiere.model.MStorage in project adempiere by adempiere.

the class WMRuleFIFO method getWarehouse.

/**
	 * Get Storage
	 * @param ctx
	 * @param warehouseId
	 * @param productId
	 * @param attributeSetInstanceId
	 * @param FiFo
	 * @param positiveOnly
	 * @param locatorId
     * @param trxName
     * @return
     */
public List<MStorage> getWarehouse(Properties ctx, int warehouseId, int productId, int attributeSetInstanceId, boolean FiFo, boolean positiveOnly, int locatorId, String trxName) {
    Timestamp minGuaranteeDate = new Timestamp(System.currentTimeMillis());
    ArrayList<MStorage> list = new ArrayList<MStorage>();
    if ((warehouseId == 0 && locatorId == 0) || productId == 0)
        return list;
    boolean allAttributeInstances = false;
    if (attributeSetInstanceId == 0)
        allAttributeInstances = true;
    // Specific Attribute Set Instance
    String sql = "SELECT s.M_Product_ID,s.M_Locator_ID,s.M_AttributeSetInstance_ID," + "s.AD_Client_ID,s.AD_Org_ID,s.IsActive,s.Created,s.CreatedBy,s.Updated,s.UpdatedBy," + "s.QtyOnHand,s.QtyReserved,s.QtyOrdered,s.DateLastInventory " + "FROM M_Storage s" + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) ";
    if (locatorId > 0)
        sql += "WHERE l.M_Locator_ID = ?";
    else
        sql += "WHERE l.M_Warehouse_ID=?";
    sql += " AND s.M_Product_ID=?" + " AND COALESCE(s.M_AttributeSetInstance_ID,0)=? ";
    if (positiveOnly) {
        sql += " AND s.QtyOnHand > 0 ";
    } else {
        sql += " AND s.QtyOnHand <> 0 ";
    }
    sql += "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
    if (!FiFo)
        sql += " DESC";
    // All Attribute Set Instances
    if (allAttributeInstances) {
        sql = "SELECT s.M_Product_ID,s.M_Locator_ID,s.M_AttributeSetInstance_ID," + "s.AD_Client_ID,s.AD_Org_ID,s.IsActive,s.Created,s.CreatedBy,s.Updated,s.UpdatedBy," + "s.QtyOnHand,s.QtyReserved,s.QtyOrdered,s.DateLastInventory " + "FROM M_Storage s" + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID)" + " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) ";
        if (locatorId > 0)
            sql += "WHERE l.M_Locator_ID = ?";
        else
            sql += "WHERE l.M_Warehouse_ID=?";
        sql += " AND s.M_Product_ID=? ";
        if (positiveOnly) {
            sql += " AND s.QtyOnHand > 0 ";
        } else {
            sql += " AND s.QtyOnHand <> 0 ";
        }
        if (minGuaranteeDate != null) {
            sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) ";
            sql += "ORDER BY l.PriorityNo DESC, " + "asi.GuaranteeDate, M_AttributeSetInstance_ID";
            if (!FiFo)
                sql += " DESC";
            sql += ", s.QtyOnHand DESC";
        } else {
            sql += "ORDER BY l.PriorityNo DESC, l.M_Locator_ID, s.M_AttributeSetInstance_ID";
            if (!FiFo)
                sql += " DESC";
            sql += ", s.QtyOnHand DESC";
        }
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, trxName);
        pstmt.setInt(1, locatorId > 0 ? locatorId : warehouseId);
        pstmt.setInt(2, productId);
        if (!allAttributeInstances) {
            pstmt.setInt(3, attributeSetInstanceId);
        } else if (minGuaranteeDate != null) {
            pstmt.setTimestamp(3, minGuaranteeDate);
        }
        rs = pstmt.executeQuery();
        while (rs.next()) {
            if (rs.getBigDecimal(11).signum() != 0)
                list.add(new MStorage(ctx, rs, trxName));
        }
    } catch (Exception e) {
    // s_log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage)

Example 30 with MStorage

use of org.compiere.model.MStorage in project adempiere by adempiere.

the class StorageCleanup method getSources.

//	eliminateReservation
/**
	 * 	Get Storage Sources
	 *	@param M_Product_ID product
	 *	@param M_Locator_ID locator
	 *	@return sources
	 */
private MStorage[] getSources(int M_Product_ID, int M_Locator_ID) {
    ArrayList<MStorage> list = new ArrayList<MStorage>();
    String sql = "SELECT * " + "FROM M_Storage s " + "WHERE QtyOnHand > 0" + " AND M_Product_ID=?" + //	Empty ASI or ASI with no attribute set
    " AND (M_AttributeSetInstance_ID=0" + "  OR EXISTS (SELECT * FROM M_AttributeSetInstance asi" + " 	RIGHT OUTER JOIN M_AttributeSet mas ON (asi.M_AttributeSet_ID = mas.M_AttributeSet_ID)" + " 	WHERE s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID" + " 	AND (mas.M_AttributeSet_ID IS NULL OR mas.isinstanceattribute = 'N')))" + //	Stock in same Warehouse
    " AND EXISTS (SELECT * FROM M_Locator sl, M_Locator x " + "WHERE s.M_Locator_ID=sl.M_Locator_ID" + " AND x.M_Locator_ID=?" + " AND sl.M_Warehouse_ID=x.M_Warehouse_ID) " + "ORDER BY M_AttributeSetInstance_ID";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setInt(1, M_Product_ID);
        pstmt.setInt(2, M_Locator_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            list.add(new MStorage(getCtx(), rs, get_TrxName()));
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    MStorage[] retValue = new MStorage[list.size()];
    list.toArray(retValue);
    return retValue;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MStorage(org.compiere.model.MStorage)

Aggregations

MStorage (org.compiere.model.MStorage)33 BigDecimal (java.math.BigDecimal)27 MProduct (org.compiere.model.MProduct)16 ArrayList (java.util.ArrayList)11 Timestamp (java.sql.Timestamp)9 MLocator (org.compiere.model.MLocator)8 MMovementLine (org.compiere.model.MMovementLine)7 ResultSet (java.sql.ResultSet)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MInOutLine (org.compiere.model.MInOutLine)5 PreparedStatement (java.sql.PreparedStatement)4 MClient (org.compiere.model.MClient)4 MMovement (org.compiere.model.MMovement)4 MOrderLine (org.compiere.model.MOrderLine)4 MWarehouse (org.compiere.model.MWarehouse)4 KeyNamePair (org.compiere.util.KeyNamePair)4 MDDOrderLine (org.eevolution.model.MDDOrderLine)4 MAttributeSet (org.compiere.model.MAttributeSet)3 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)3 MInOut (org.compiere.model.MInOut)3