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();
}
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;
}
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());
}
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;
}
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());
}
Aggregations