Search in sources :

Example 26 with MProduct

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

the class MPPOrder method isQtyAvailable.

public static boolean isQtyAvailable(MPPOrder order, I_PP_Order_BOMLine line) {
    MProduct product = MProduct.get(order.getCtx(), line.getM_Product_ID());
    if (product == null || !product.isStocked())
        return true;
    BigDecimal qtyToDeliver = line.getQtyRequired();
    BigDecimal qtyScrap = line.getQtyScrap();
    BigDecimal qtyRequired = qtyToDeliver.add(qtyScrap);
    BigDecimal qtyAvailable = MStorage.getQtyAvailable(order.getM_Warehouse_ID(), 0, line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), order.get_TrxName());
    return qtyAvailable.compareTo(qtyRequired) >= 0;
}
Also used : MProduct(org.compiere.model.MProduct) BigDecimal(java.math.BigDecimal)

Example 27 with MProduct

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

the class MPPOrder method updateMakeToKit.

/**
	 * Create Auto Receipt and Issue based on Quantity
	 * @param qtyShipment
	 */
public void updateMakeToKit(BigDecimal qtyShipment) {
    MPPOrderBOM orderBOM = (MPPOrderBOM) getMPPOrderBOM();
    getLines(true);
    // Auto receipt and issue for kit
    if (MPPOrderBOM.BOMTYPE_Make_To_Kit.equals(orderBOM.getBOMType()) && MPPOrderBOM.BOMUSE_Manufacturing.equals(orderBOM.getBOMUse())) {
        Timestamp today = new Timestamp(System.currentTimeMillis());
        ArrayList[][] issue = new ArrayList[m_lines.length][1];
        for (int i = 0; i < getLines().length; i++) {
            MPPOrderBOMLine line = m_lines[i];
            KeyNamePair id = null;
            if (MPPOrderBOMLine.ISSUEMETHOD_Backflush.equals(line.getIssueMethod())) {
                id = new KeyNamePair(line.get_ID(), "Y");
            } else
                id = new KeyNamePair(line.get_ID(), "N");
            ArrayList<Object> data = new ArrayList<Object>();
            BigDecimal qtyToDeliver = qtyShipment.multiply(line.getQtyMultiplier());
            //0 - MPPOrderBOMLine ID
            data.add(id);
            //1 - Critical
            data.add(line.isCritical());
            MProduct product = (MProduct) line.getM_Product();
            //2 - Value
            data.add(product.getValue());
            KeyNamePair productKey = new KeyNamePair(product.get_ID(), product.getName());
            //3 - KeyNamePair Product
            data.add(productKey);
            //4 - QtyToDeliver			
            data.add(qtyToDeliver);
            //5 - QtyScrapComponent
            data.add(Env.ZERO);
            issue[i][0] = data;
        }
        boolean forceIssue = false;
        MOrderLine orderLine = (MOrderLine) getC_OrderLine();
        if (MOrder.DELIVERYRULE_CompleteLine.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_CompleteOrder.equals(orderLine.getParent().getDeliveryRule())) {
            boolean isCompleteQtyDeliver = MPPOrder.isQtyAvailable(this, issue, today);
            if (!isCompleteQtyDeliver) {
                throw new AdempiereException("@NoQtyAvailable@");
            }
        } else if (MOrder.DELIVERYRULE_Availability.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_AfterReceipt.equals(orderLine.getParent().getDeliveryRule()) || MOrder.DELIVERYRULE_Manual.equals(orderLine.getParent().getDeliveryRule())) {
            throw new AdempiereException("@DeliveryRule@ " + orderLine.getParent().getDeliveryRule() + "@ActionNotSupported@");
        } else if (MOrder.DELIVERYRULE_Force.equals(orderLine.getParent().getDeliveryRule())) {
            forceIssue = true;
        }
        for (int i = 0; i < issue.length; i++) {
            int attributeSetInstanceId = 0;
            KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
            Boolean isCritical = (Boolean) issue[i][0].get(1);
            String value = (String) issue[i][0].get(2);
            KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
            int productId = productkey.getKey();
            MProduct product = MProduct.get(getCtx(), productId);
            BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
            BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
            MPPOrderBOMLine orderBOMLine = null;
            int orderBOMLineId = (Integer) key.getKey();
            if (orderBOMLineId > 0) {
                orderBOMLine = new MPPOrderBOMLine(getCtx(), orderBOMLineId, get_TrxName());
                //Validate if AttributeSet generate instance
                attributeSetInstanceId = orderBOMLine.getM_AttributeSetInstance_ID();
            }
            MStorage[] storages = MPPOrder.getStorages(getCtx(), productId, getM_Warehouse_ID(), attributeSetInstanceId, today, get_TrxName());
            MPPOrder.createIssue(this, orderBOMLine, today, qtyToDeliver, qtyScrapComponent, Env.ZERO, storages, forceIssue);
        }
        MPPOrder.createReceipt(this, today, getQtyDelivered(), qtyShipment, getQtyScrap(), getQtyReject(), getM_Locator_ID(), getM_AttributeSetInstance_ID());
    }
}
Also used : MProduct(org.compiere.model.MProduct) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) KeyNamePair(org.compiere.util.KeyNamePair) MOrderLine(org.compiere.model.MOrderLine)

Example 28 with MProduct

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

the class CalloutBOM method parent.

/**
	 *	Parent cycle check and BOM Line defaults.
	 *  @param ctx      Context
	 *  @param WindowNo current Window No
	 *  @param mTab     Model Tab
	 *  @param mField   Model Field
	 *  @param value    The new value
	 */
public String parent(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    if (isCalloutActive() || value == null)
        return "";
    final int M_Product_ID = (Integer) value;
    if (M_Product_ID <= 0)
        return "";
    I_PP_Product_BOMLine bomLine = GridTabWrapper.create(mTab, I_PP_Product_BOMLine.class);
    I_PP_Product_BOM bom = bomLine.getPP_Product_BOM();
    if (//Adempiere-272 changes
    bom == null) {
        throw new AdempiereException("Please save header record first.");
    }
    if (bom.getM_Product_ID() == bomLine.getM_Product_ID()) {
        throw new AdempiereException("@ValidComponent@ - Error Parent not be Component");
    }
    // Set BOM Line defaults
    // May be the parent;
    MProduct product = MProduct.get(ctx, M_Product_ID);
    bomLine.setDescription(product.getDescription());
    bomLine.setHelp(product.getHelp());
    bomLine.setC_UOM_ID(product.getC_UOM_ID());
    bomLine.setM_AttributeSetInstance_ID(product.getEnvAttributeSetInstance(ctx, WindowNo) == null ? 0 : product.getEnvAttributeSetInstance(ctx, WindowNo));
    return "";
}
Also used : MProduct(org.compiere.model.MProduct) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 29 with MProduct

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

the class MPPOrder method isQtyAvailable.

/**
	 * get if Component is Available
	 * @param MPPOrdrt Manufacturing order
	 * @param ArrayList Issues
	 * @param minGuaranteeDate Guarantee Date
	 * @return true when the qty available is enough
	 */
public static boolean isQtyAvailable(MPPOrder order, ArrayList[][] issue, Timestamp minGuaranteeDate) {
    boolean isCompleteQtyDeliver = false;
    for (int i = 0; i < issue.length; i++) {
        KeyNamePair key = (KeyNamePair) issue[i][0].get(0);
        boolean isSelected = key.getName().equals("Y");
        if (key == null || !isSelected) {
            continue;
        }
        String value = (String) issue[i][0].get(2);
        KeyNamePair productkey = (KeyNamePair) issue[i][0].get(3);
        int M_Product_ID = productkey.getKey();
        BigDecimal qtyToDeliver = (BigDecimal) issue[i][0].get(4);
        BigDecimal qtyScrapComponent = (BigDecimal) issue[i][0].get(5);
        MProduct product = MProduct.get(order.getCtx(), M_Product_ID);
        if (product != null && product.isStocked()) {
            int M_AttributeSetInstance_ID = 0;
            if (value == null && isSelected) {
                M_AttributeSetInstance_ID = (Integer) key.getKey();
            } else if (value != null && isSelected) {
                int PP_Order_BOMLine_ID = (Integer) key.getKey();
                if (PP_Order_BOMLine_ID > 0) {
                    MPPOrderBOMLine orderBOMLine = new MPPOrderBOMLine(order.getCtx(), PP_Order_BOMLine_ID, order.get_TrxName());
                    //Validate if AttributeSet generate instance
                    M_AttributeSetInstance_ID = orderBOMLine.getM_AttributeSetInstance_ID();
                }
            }
            MStorage[] storages = MPPOrder.getStorages(order.getCtx(), M_Product_ID, order.getM_Warehouse_ID(), M_AttributeSetInstance_ID, minGuaranteeDate, order.get_TrxName());
            if (M_AttributeSetInstance_ID == 0) {
                BigDecimal toIssue = qtyToDeliver.add(qtyScrapComponent);
                for (MStorage storage : storages) {
                    //	TODO Selection of ASI
                    if (storage.getQtyOnHand().signum() == 0)
                        continue;
                    BigDecimal issueActual = toIssue.min(storage.getQtyOnHand());
                    toIssue = toIssue.subtract(issueActual);
                    if (toIssue.signum() <= 0)
                        break;
                }
            } else {
                BigDecimal qtydelivered = qtyToDeliver;
                qtydelivered.setScale(4, BigDecimal.ROUND_HALF_UP);
                qtydelivered = Env.ZERO;
            }
            BigDecimal onHand = Env.ZERO;
            for (MStorage storage : storages) {
                onHand = onHand.add(storage.getQtyOnHand());
            }
            isCompleteQtyDeliver = onHand.compareTo(qtyToDeliver.add(qtyScrapComponent)) >= 0;
            if (!isCompleteQtyDeliver)
                break;
        }
    }
    return isCompleteQtyDeliver;
}
Also used : MProduct(org.compiere.model.MProduct) KeyNamePair(org.compiere.util.KeyNamePair) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal)

Example 30 with MProduct

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

the class MPPOrderBOMLine method explodePhantom.

/**
	 * Explode Phantom Items
	 * TODO: check if BOM and BOM Lines are valid
	 */
private void explodePhantom() {
    if (m_isExplodePhantom && m_qtyRequiredPhantom != null) {
        MProduct parent = MProduct.get(getCtx(), getM_Product_ID());
        int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(parent);
        if (PP_Product_BOM_ID <= 0) {
            return;
        }
        MPPProductBOM bom = MPPProductBOM.get(getCtx(), PP_Product_BOM_ID);
        if (bom != null) {
            for (MPPProductBOMLine PP_Product_BOMline : bom.getLines()) {
                MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), getPP_Order_BOM_ID(), getM_Warehouse_ID(), get_TrxName());
                PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
                PP_Order_BOMLine.setQtyOrdered(m_qtyRequiredPhantom);
                PP_Order_BOMLine.saveEx();
            }
        }
        m_isExplodePhantom = false;
    }
}
Also used : MProduct(org.compiere.model.MProduct)

Aggregations

MProduct (org.compiere.model.MProduct)180 BigDecimal (java.math.BigDecimal)70 AdempiereException (org.adempiere.exceptions.AdempiereException)30 ArrayList (java.util.ArrayList)29 Query (org.compiere.model.Query)29 ResultSet (java.sql.ResultSet)19 MLocator (org.compiere.model.MLocator)18 PreparedStatement (java.sql.PreparedStatement)17 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)17 KeyNamePair (org.compiere.util.KeyNamePair)17 MCostElement (org.compiere.model.MCostElement)16 MStorage (org.compiere.model.MStorage)16 MAcctSchema (org.compiere.model.MAcctSchema)14 MCost (org.compiere.model.MCost)14 MPPProductBOM (org.eevolution.model.MPPProductBOM)14 MPPProductBOMLine (org.eevolution.model.MPPProductBOMLine)14 SQLException (java.sql.SQLException)13 Timestamp (java.sql.Timestamp)13 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)13 Vector (java.util.Vector)12