Search in sources :

Example 6 with MPPProductPlanning

use of org.eevolution.model.MPPProductPlanning in project adempiere by adempiere.

the class RollupBillOfMaterial method getFutureCostPriceLowLevel.

/**
	 * Get the sum Current Cost Price Level Low for this Cost Element
	 * @param acctSchema
	 * @param bom MPPProductBOM
	 * @param costElement MCostElement
	 * @param trxName
	 * @return Cost Price Lower Level
	 */
private BigDecimal getFutureCostPriceLowLevel(MAcctSchema acctSchema, MPPProductBOM bom, MCostElement costElement, String trxName) {
    log.info("Element: " + costElement);
    AtomicReference<BigDecimal> costPriceLowLevel = new AtomicReference<>(Env.ZERO);
    if (bom == null)
        return costPriceLowLevel.get();
    //Iterate bom lines
    Arrays.stream(bom.getLines()).filter(bomLine -> bomLine != null && !bomLine.isCoProduct()).forEach(bomLine -> {
        MProduct component = MProduct.get(getCtx(), bomLine.getM_Product_ID());
        MCost cost = MCost.getOrCreate(component, 0, acctSchema, getOrganizationId(), getWarehouseId(), getCostTypeId(), costElement.getM_CostElement_ID());
        Boolean includingScrapQty = true;
        BigDecimal qty = bomLine.getQty(includingScrapQty);
        if (bomLine.isByProduct())
            cost.setFutureCostPriceLL(Env.ZERO);
        BigDecimal costPrice = cost.getFutureCostPrice().add(cost.getFutureCostPriceLL());
        if (costPrice.equals(BigDecimal.ZERO))
            costPrice = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
        if (bomLine.getM_Product().getC_UOM_ID() != bomLine.getC_UOM_ID()) {
            BigDecimal rate = MUOMConversion.getProductRateFrom(getCtx(), component.getM_Product_ID(), bomLine.getC_UOM_ID());
            if (rate == null)
                costPrice = costPrice.multiply(BigDecimal.ONE);
            else
                costPrice = costPrice.multiply(rate);
        }
        if (bomLine.isPacking()) {
            int workflowId = 0;
            MProduct product = MProduct.get(getCtx(), bom.getM_Product_ID());
            MPPProductPlanning productPlanning = null;
            if (workflowId <= 0)
                workflowId = MWorkflow.getWorkflowSearchKey(product);
            if (workflowId <= 0) {
                productPlanning = MPPProductPlanning.find(getCtx(), getOrganizationId(), getWarehouseId(), getResourcePlantId(), product.get_ID(), get_TrxName());
                if (productPlanning != null)
                    workflowId = productPlanning.getAD_Workflow_ID();
                else
                    createNotice(product, "@NotFound@ @PP_Product_Planning_ID@");
            }
            if (workflowId <= 0)
                createNotice(product, "@NotFound@ @AD_Workflow_ID@");
            BigDecimal qtyBatchSize = DB.getSQLValueBD(trxName, "SELECT QtyBatchSize FROM AD_Workflow WHERE AD_Workflow_ID=?", workflowId);
            if (qtyBatchSize != null && qtyBatchSize.signum() != 0)
                qty = qty.divide(qtyBatchSize, acctSchema.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
        }
        BigDecimal componentCost = costPrice.multiply(qty);
        costPriceLowLevel.updateAndGet(costAmt -> costAmt.add(componentCost));
        log.info("CostElement: " + costElement.getName() + ", Component: " + component.getValue() + ", CostPrice: " + costPrice + ", Qty: " + qty + ", Cost: " + componentCost + " => Total Cost Element: " + costPriceLowLevel.get());
    });
    // BOM line
    return costPriceLowLevel.get();
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Arrays(java.util.Arrays) I_PP_Product_Planning(org.eevolution.model.I_PP_Product_Planning) MWorkflow(org.compiere.wf.MWorkflow) Env(org.compiere.util.Env) MCostType(org.compiere.model.MCostType) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) MPPProductBOM(org.eevolution.model.MPPProductBOM) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) List(java.util.List) Query(org.compiere.model.Query) DB(org.compiere.util.DB) Msg(org.compiere.util.Msg) MCostElement(org.compiere.model.MCostElement) TrxRunnable(org.compiere.util.TrxRunnable) MPPMRP(org.eevolution.model.MPPMRP) Trx(org.compiere.util.Trx) MProduct(org.compiere.model.MProduct) MProduct(org.compiere.model.MProduct) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MCost(org.compiere.model.MCost) AtomicReference(java.util.concurrent.atomic.AtomicReference) BigDecimal(java.math.BigDecimal)

Example 7 with MPPProductPlanning

use of org.eevolution.model.MPPProductPlanning in project adempiere by adempiere.

the class MRP method getProductPlanning.

protected MPPProductPlanning getProductPlanning(int AD_Client_ID, int AD_Org_ID, int S_Resource_ID, int M_Warehouse_ID, MProduct product, String trxName) throws SQLException {
    // Find data product planning demand 
    MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), AD_Org_ID, M_Warehouse_ID, S_Resource_ID, product.getM_Product_ID(), trxName);
    if (pp == null) {
        return null;
    }
    MPPProductPlanning pp2 = new MPPProductPlanning(getCtx(), 0, null);
    MPPProductPlanning.copyValues(pp, pp2);
    pp2.setAD_Org_ID(pp.getAD_Org_ID());
    pp2.setIsRequiredDRP(isSynchronize());
    //
    if (pp2.getPP_Product_BOM_ID() <= 0 && product.isBOM()) {
        pp2.setPP_Product_BOM_ID(MPPProductBOM.getBOMSearchKey(product));
    }
    if (pp2.getAD_Workflow_ID() <= 0 && product.isBOM()) {
        pp2.setAD_Workflow_ID(MWorkflow.getWorkflowSearchKey(product));
    }
    if (pp2.getPlanner_ID() <= 0) {
        pp2.setPlanner_ID(getPlanner_ID() == null || getPlanner_ID() == 0 ? Env.getAD_User_ID(getCtx()) : getPlanner_ID());
    }
    if (pp2.getM_Warehouse_ID() <= 0) {
        pp2.setM_Warehouse_ID(M_Warehouse_ID);
    }
    if (pp2.getS_Resource_ID() <= 0) {
        pp2.setS_Resource_ID(S_Resource_ID);
    }
    if (pp2.getOrder_Policy() == null) {
        pp2.setOrder_Policy(X_PP_Product_Planning.ORDER_POLICY_Lot_For_Lot);
    }
    //Find Vendor
    if (!isSynchronize()) {
        if (product.isPurchased()) {
            int C_BPartner_ID = 0;
            MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), trxName);
            for (int i = 0; i < ppos.length; i++) {
                if (ppos[i].isCurrentVendor() && ppos[i].getC_BPartner_ID() != 0) {
                    C_BPartner_ID = ppos[i].getC_BPartner_ID();
                    pp2.setDeliveryTime_Promised(BigDecimal.valueOf(ppos[i].getDeliveryTime_Promised()));
                    pp2.setOrder_Min(ppos[i].getOrder_Min());
                    pp2.setOrder_Max(Env.ZERO);
                    pp2.setOrder_Pack(ppos[i].getOrder_Pack());
                    pp2.setC_BPartner_ID(C_BPartner_ID);
                    break;
                }
            }
            if (C_BPartner_ID <= 0) {
                createMRPNote("MRP-130", AD_Org_ID, 0, product, (String) null, null, null, trxName);
                pp2.setIsCreatePlan(false);
            }
        }
        if (product.isBOM()) {
            if (pp2.getAD_Workflow_ID() <= 0)
                log.info("Error: Do not exist workflow (" + product.getValue() + ")");
        }
    }
    //
    return pp2;
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MProductPO(org.compiere.model.MProductPO)

Example 8 with MPPProductPlanning

use of org.eevolution.model.MPPProductPlanning in project adempiere by adempiere.

the class WMRPDetailed method fillHead.

private void fillHead() {
    MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), getAD_Org_ID(), getM_Warehouse_ID(), getS_Resource_ID(), getM_Product_ID(), null);
    if (pp == null)
        pp = new MPPProductPlanning(getCtx(), 0, null);
    fMaster.setSelected(pp.isMPS());
    fMRPReq.setSelected(pp.isRequiredMRP());
    fCreatePlan.setSelected(pp.isCreatePlan());
    fOrderPeriod.setValue(pp.getOrder_Period());
    fLeadtime.setValue(pp.getDeliveryTime_Promised());
    fTimefence.setValue(pp.getTimeFence());
    fMinOrd.setValue(pp.getOrder_Min());
    fMaxOrd.setValue(pp.getOrder_Max());
    fOrdMult.setValue(pp.getOrder_Pack());
    fOrderQty.setValue(pp.getOrder_Qty());
    fYield.setValue(pp.getYield());
    fType.setText(MRefList.getListName(getCtx(), MPPProductPlanning.ORDER_POLICY_AD_Reference_ID, pp.getOrder_Policy()));
    fSafetyStock.setValue(pp.getSafetyStock());
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning)

Example 9 with MPPProductPlanning

use of org.eevolution.model.MPPProductPlanning in project adempiere by adempiere.

the class MRPUtil method getPlanning.

/**
	 * Helper Method : Create Product Planning
	 */
public static I_PP_Product_Planning getPlanning(String productValue, String Order_Policy, int Order_Min, int Order_Max, int Order_Pack, int SafetyStock, int Order_Period, int LeadTime) {
    boolean isPurchased = true;
    int PlanningHorizon = 365;
    //
    Properties ctx = Env.getCtx();
    //		int AD_Client_ID = Env.getAD_Client_ID(ctx);
    int AD_Org_ID = MRPUtil.getFirst_Org_ID();
    I_M_Warehouse wh = MRPUtil.getCreateWarehouse(AD_Org_ID, productValue);
    I_S_Resource plant = MRPUtil.getCreatePlant(productValue, wh.getM_Warehouse_ID(), PlanningHorizon);
    I_M_Product product = MRPUtil.getCreateProduct(ctx, productValue, isPurchased);
    //
    MPPProductPlanning pp = new MPPProductPlanning(ctx, 0, null);
    pp.setIsCreatePlan(true);
    pp.setIsRequiredMRP(true);
    pp.setIsRequiredDRP(false);
    pp.setM_Product_ID(product.getM_Product_ID());
    pp.setAD_Org_ID(AD_Org_ID);
    pp.setM_Warehouse_ID(wh.getM_Warehouse_ID());
    pp.setS_Resource_ID(plant.getS_Resource_ID());
    //
    pp.setOrder_Policy(Order_Policy);
    pp.setOrder_Min(BigDecimal.valueOf(Order_Min));
    pp.setOrder_Max(BigDecimal.valueOf(Order_Max));
    pp.setOrder_Pack(BigDecimal.valueOf(Order_Pack));
    pp.setSafetyStock(BigDecimal.valueOf(SafetyStock));
    pp.setOrder_Period(BigDecimal.valueOf(Order_Period));
    pp.setDeliveryTime_Promised(BigDecimal.valueOf(LeadTime));
    //
    return pp;
}
Also used : I_S_Resource(org.compiere.model.I_S_Resource) I_M_Product(org.compiere.model.I_M_Product) MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Properties(java.util.Properties) I_M_Warehouse(org.compiere.model.I_M_Warehouse)

Example 10 with MPPProductPlanning

use of org.eevolution.model.MPPProductPlanning in project adempiere by adempiere.

the class VMRPDetailed method fillHead.

// executeQuery
/**
	 * Fill the head value
	 */
private void fillHead() {
    MPPProductPlanning pp = MPPProductPlanning.find(getCtx(), getAD_Org_ID(), getM_Warehouse_ID(), getS_Resource_ID(), getM_Product_ID(), null);
    if (pp == null)
        pp = new MPPProductPlanning(getCtx(), 0, null);
    fMaster.setSelected(pp.isMPS());
    fMRPReq.setSelected(pp.isRequiredMRP());
    fCreatePlan.setSelected(pp.isCreatePlan());
    fOrderPeriod.setValue(pp.getOrder_Period());
    fLeadtime.setValue(pp.getDeliveryTime_Promised());
    fTimefence.setValue(pp.getTimeFence());
    fMinOrd.setValue(pp.getOrder_Min());
    fMaxOrd.setValue(pp.getOrder_Max());
    fOrdMult.setValue(pp.getOrder_Pack());
    fOrderQty.setValue(pp.getOrder_Qty());
    fYield.setValue(pp.getYield());
    fType.setText(MRefList.getListName(getCtx(), X_PP_Product_Planning.ORDER_POLICY_AD_Reference_ID, pp.getOrder_Policy()));
    fSafetyStock.setValue(pp.getSafetyStock());
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning)

Aggregations

MPPProductPlanning (org.eevolution.model.MPPProductPlanning)10 MWorkflow (org.compiere.wf.MWorkflow)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MCost (org.compiere.model.MCost)2 MCostElement (org.compiere.model.MCostElement)2 MCostType (org.compiere.model.MCostType)2 MProduct (org.compiere.model.MProduct)2 Query (org.compiere.model.Query)2 Env (org.compiere.util.Env)2 Msg (org.compiere.util.Msg)2 Trx (org.compiere.util.Trx)2 TrxRunnable (org.compiere.util.TrxRunnable)2 MPPProductBOM (org.eevolution.model.MPPProductBOM)2 RoundingMode (java.math.RoundingMode)1 Properties (java.util.Properties)1