use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.
the class GenerateShipmentOutBound method createShipment.
/**
* Create Shipment to Out Bound Order
* @param outBoundLine
*/
public void createShipment(MWMInOutBoundLine outBoundLine) {
// Generate Shipment based on Outbound Order
if (outBoundLine.getC_OrderLine_ID() > 0) {
MOrderLine orderLine = outBoundLine.getOrderLine();
if (outBoundLine.getPickedQty().subtract(orderLine.getQtyDelivered()).signum() <= 0 && !isIncludeNotAvailable())
return;
MLocator standing = getStandingLocator(outBoundLine);
BigDecimal qtyDelivered = getQtyDelivered(outBoundLine, orderLine.getQtyDelivered());
MInOut shipment = getShipment(orderLine);
MInOutLine shipmentLine = new MInOutLine(outBoundLine.getCtx(), 0, outBoundLine.get_TrxName());
shipmentLine.setM_InOut_ID(shipment.getM_InOut_ID());
shipmentLine.setM_Locator_ID(standing.getM_Locator_ID());
shipmentLine.setM_Product_ID(outBoundLine.getM_Product_ID());
shipmentLine.setQtyEntered(qtyDelivered);
shipmentLine.setMovementQty(qtyDelivered);
shipmentLine.setC_OrderLine_ID(orderLine.getC_OrderLine_ID());
shipmentLine.saveEx();
}
// Generate Delivery Movement
if (outBoundLine.getDD_OrderLine_ID() > 0) {
MDDOrderLine distributionOrderLine = (MDDOrderLine) outBoundLine.getDD_OrderLine();
if (distributionOrders.get(distributionOrderLine.getDD_Order_ID()) == null)
distributionOrders.put(distributionOrderLine.getDD_Order_ID(), distributionOrderLine.getDD_Order());
distributionOrderLine.setConfirmedQty(outBoundLine.getPickedQty());
distributionOrderLine.saveEx();
}
// Generate Delivery Manufacturing Order
if (outBoundLine.getPP_Order_BOMLine_ID() > 0) {
MPPOrderBOMLine orderBOMLine = (MPPOrderBOMLine) outBoundLine.getPP_Order_BOMLine();
if (outBoundLine.getPickedQty().subtract(orderBOMLine.getQtyDelivered()).signum() <= 0 && !isIncludeNotAvailable())
return;
MLocator standing = getStandingLocator(outBoundLine);
MStorage[] storage = MStorage.getAll(getCtx(), orderBOMLine.getM_Product_ID(), standing.getM_Locator_ID(), get_TrxName());
BigDecimal qtyDelivered = getQtyDelivered(outBoundLine, orderBOMLine.getQtyDelivered());
List<MPPCostCollector> issues = MPPOrder.createIssue(orderBOMLine.getParent(), orderBOMLine, getMovementDate(), qtyDelivered, BigDecimal.ZERO, BigDecimal.ZERO, storage, true);
issues.stream().forEach(costCollector -> {
if (manufacturingIssues.get(costCollector.getPP_Cost_Collector_ID()) == null)
manufacturingIssues.put(costCollector.getPP_Cost_Collector_ID(), costCollector);
});
}
}
use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.
the class GenerateShipmentOutBound method processingIssues.
public void processingIssues() {
manufacturingIssues.entrySet().stream().forEach(entry -> {
MPPCostCollector issue = entry.getValue();
issue.setDocAction(getDocumentAction());
issue.processIt(getDocumentAction());
if (!issue.processIt(getDocumentAction())) {
addLog("@ProcessFailed@ : " + issue.getDocumentInfo());
log.warning("@ProcessFailed@ :" + issue.getDocumentInfo());
}
issue.saveEx();
});
}
use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.
the class CostEngine method createCostDetail.
/**
* Create Cost Detail
* @param accountSchema Account Schema
* @param transaction Material Transaction
* @param model IDocumentLine
* @param costType Cost Type
* @param costElement Cost Element
*/
public void createCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction, IDocumentLine model, boolean force) {
if (!force)
return;
BigDecimal costThisLevel = Env.ZERO;
BigDecimal costLowLevel = Env.ZERO;
String costingLevel = MProduct.get(transaction.getCtx(), transaction.getM_Product_ID()).getCostingLevel(accountSchema, transaction.getAD_Org_ID());
// adjustment for Average PO Costing method
if (model instanceof MMatchInv && MCostType.COSTINGMETHOD_AveragePO.equals(costType.getCostingMethod()))
return;
// adjustment for Average PO Costing method
if (model instanceof MMatchPO && MCostType.COSTINGMETHOD_AverageInvoice.equals(costType.getCostingMethod()))
return;
if (model instanceof MLandedCostAllocation) {
MLandedCostAllocation allocation = (MLandedCostAllocation) model;
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
MCost cost = MCost.validateCostForCostType(accountSchema, costType, costElement, transaction.getM_Product_ID(), transaction.getAD_Org_ID(), transaction.getM_Warehouse_ID(), transaction.getM_AttributeSetInstance_ID(), transaction.get_TrxName());
// get the cost for positive transaction
if ((MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()) || MCostElement.COSTELEMENTTYPE_LandedCost.equals(costElement.getCostElementType())) && transaction.getMovementType().contains("+") && !MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
if (model instanceof MMovementLine || model instanceof MInventoryLine || (model instanceof MInOutLine && MTransaction.MOVEMENTTYPE_CustomerReturns.equals(transaction.getMovementType()))) {
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
if (model instanceof MInventoryLine) {
MInventoryLine inventoryLine = (MInventoryLine) model;
// try get cost from physical inventory
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the current cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
if (costThisLevel.signum() == 0)
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
// try get cost low level from physical inventory
if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the current cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
}
if (costLowLevel.signum() == 0)
costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
}
//Get cost from movement from if it > that zero replace cost This Level
if (model instanceof MMovementLine) {
MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costMovementFrom.signum() > 0)
costThisLevel = costMovementFrom;
BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costMovementFromLL.signum() > 0)
costLowLevel = costMovementFromLL;
}
} else if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
}
if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
if (model instanceof MPPCostCollector) {
MPPCostCollector costCollector = (MPPCostCollector) model;
if (MPPCostCollector.COSTCOLLECTORTYPE_MaterialReceipt.equals(costCollector.getCostCollectorType())) {
// get Actual Cost for Cost Type and Cost Element
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
costLowLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType.getM_CostType_ID(), costElement.getM_CostElement_ID(), costCollector);
}
}
if (model instanceof MProductionLine) {
MProductionLine productionLine = (MProductionLine) model;
if (productionLine.isParent())
costThisLevel = CostEngine.getParentActualCostByCostType(accountSchema, costType, costElement, productionLine.getM_Production());
if (costThisLevel.signum() == 0)
costThisLevel = cost.getCurrentCostPrice();
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()))
costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
// Material Receipt for Production light
if (productionLine.isParent()) {
// if the product is purchase then no use low level
if (!productionLine.getM_Product().isPurchased()) {
costLowLevel = costThisLevel;
costThisLevel = Env.ZERO;
}
} else if (productionLine.getMovementQty().signum() < 0)
costLowLevel = Env.ZERO;
}
} else if (MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod())) {
costThisLevel = cost.getCurrentCostPrice();
costLowLevel = cost.getCurrentCostPriceLL();
//Define Cost Inventory Line
if (model instanceof MInventoryLine) {
MInventoryLine inventoryLine = (MInventoryLine) model;
//Define Current Cost Level
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the current cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPrice() != null && inventoryLine.getCurrentCostPrice().signum() > 0) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
cost.setCurrentCostPrice(costThisLevel);
cost.saveEx();
}
if (costThisLevel.signum() == 0)
costThisLevel = getCostThisLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
//Define Current Cost Low Level
if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
// Use the cost only for Physical Inventory
if (inventoryLine.getQtyInternalUse().signum() == 0 && inventoryLine.getCurrentCostPriceLL() != null && inventoryLine.getCurrentCostPriceLL().signum() > 0) {
costLowLevel = convertCostToSchemaCurrency(accountSchema, model, inventoryLine.getCurrentCostPriceLL());
cost.setCurrentCostPriceLL(costLowLevel);
cost.saveEx();
}
if (costLowLevel.signum() == 0)
costLowLevel = getCostLowLevel(accountSchema, costType, costElement, transaction, model, costingLevel);
}
}
if (model instanceof MMovementLine) {
MTransaction transactionFrom = MTransaction.getByDocumentLine(model, MTransaction.MOVEMENTTYPE_MovementFrom);
BigDecimal costMovementFrom = getCostThisLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (costMovementFrom.signum() > 0)
costThisLevel = costMovementFrom;
}
if (costLowLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
BigDecimal costMovementFromLL = getCostLowLevel(accountSchema, costType, costElement, transactionFrom == null ? transaction : transactionFrom, model, costingLevel);
if (costMovementFromLL.signum() > 0)
costLowLevel = costMovementFromLL;
}
}
if (costThisLevel.signum() == 0 && MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
costThisLevel = getSeedCost(transaction.getCtx(), transaction.getM_Product_ID(), transaction.get_TrxName());
if (costThisLevel.signum() == 0)
if (model instanceof MInOutLine && !model.isSOTrx()) {
costThisLevel = convertCostToSchemaCurrency(accountSchema, model, model.getPriceActualCurrency());
}
if (costThisLevel.signum() != 0) {
cost.setCurrentCostPrice(costThisLevel);
cost.saveEx();
}
}
if (costLowLevel.signum() != 0) {
cost.setCurrentCostPriceLL(costLowLevel);
cost.saveEx();
}
}
final ICostingMethod method = CostingMethodFactory.get().getCostingMethod(costType.getCostingMethod());
method.setCostingMethod(accountSchema, transaction, model, cost, costThisLevel, costLowLevel, model.isSOTrx());
method.process();
}
use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.
the class StandardCostingMethod method createMethodVariances.
public void createMethodVariances(MPPCostCollector costCollector) {
if (!costCollector.isCostCollectorType(MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl))
return;
//
final int std_resource_id = costCollector.getPP_Order_Node().getAD_WF_Node().getS_Resource_ID();
final int actual_resource_id = costCollector.getS_Resource_ID();
if (std_resource_id == actual_resource_id) {
return;
}
//
// Cost Collector - Method Change Variance
MPPCostCollector methodChangeVariance = null;
final RoutingService routingService = RoutingServiceFactory.get().getRoutingService(costCollector.getAD_Client_ID());
for (MAcctSchema as : CostEngine.getAcctSchema(costCollector)) {
for (MCostElement element : MCostElement.getCostElement(costCollector.getCtx(), costCollector.get_TrxName())) {
final MProduct resourcePStd = MProduct.forS_Resource_ID(costCollector.getCtx(), std_resource_id, null);
final MProduct resourcePActual = MProduct.forS_Resource_ID(costCollector.getCtx(), actual_resource_id, null);
final BigDecimal priceStd = getProductActualCostPrice(costCollector, resourcePStd, as, element, costCollector.get_TrxName());
final BigDecimal priceActual = getProductActualCostPrice(costCollector, resourcePActual, as, element, costCollector.get_TrxName());
if (priceStd.compareTo(priceActual) == 0) {
continue;
}
//
if (methodChangeVariance == null) {
methodChangeVariance = MPPCostCollector.createVarianceCostCollector(costCollector, MPPCostCollector.COSTCOLLECTORTYPE_MethodChangeVariance);
}
//
final BigDecimal qty = routingService.getResourceBaseValue(costCollector.getS_Resource_ID(), costCollector);
final BigDecimal amtStd = priceStd.multiply(qty);
final BigDecimal amtActual = priceActual.multiply(qty);
//
List<MCostType> costtypes = MCostType.get(as.getCtx(), as.get_TrxName());
for (MCostType costType : costtypes) {
//implementation only for standard cost
if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod()))
continue;
createVarianceCostDetail(methodChangeVariance, amtActual.abs(), qty, null, resourcePActual, as, costType, element);
createVarianceCostDetail(methodChangeVariance, amtStd.negate(), qty.negate(), null, resourcePStd, as, costType, element);
}
}
}
//
if (methodChangeVariance != null) {
boolean ok = methodChangeVariance.processIt(MPPCostCollector.ACTION_Complete);
methodChangeVariance.saveEx();
if (!ok)
throw new AdempiereException(methodChangeVariance.getProcessMsg());
}
}
use of org.eevolution.model.MPPCostCollector in project adempiere by adempiere.
the class CostEngine method clearAccounting.
/**
* clear Accounting
* @param accountSchema
* @param transaction
*/
public void clearAccounting(MAcctSchema accountSchema, MTransaction transaction) {
if (transaction.getM_InOutLine_ID() > 0) {
MInOutLine line = (MInOutLine) transaction.getM_InOutLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
// get Purchase matches
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
return;
}
// get invoice matches
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
return;
}
} else if (transaction.getC_ProjectIssue_ID() > 0) {
MProjectIssue line = (MProjectIssue) transaction.getC_ProjectIssue();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getMovementDate()))
return;
} else if (transaction.getM_InventoryLine_ID() > 0) {
MInventoryLine line = (MInventoryLine) transaction.getM_InventoryLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
} else if (transaction.getM_MovementLine_ID() > 0) {
MMovementLine line = (MMovementLine) transaction.getM_MovementLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
} else if (transaction.getM_ProductionLine_ID() > 0) {
MProductionLine line = (MProductionLine) transaction.getM_ProductionLine();
MProduction production = (MProduction) line.getM_ProductionPlan().getM_Production();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), production, transaction.getM_Product_ID(), production.getMovementDate()))
return;
} else if (transaction.getPP_Cost_Collector_ID() > 0) {
MPPCostCollector costCollector = (MPPCostCollector) transaction.getPP_Cost_Collector();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), costCollector, costCollector.getM_Product_ID(), costCollector.getDateAcct()))
;
return;
} else {
log.info("Document does not exist :" + transaction);
}
}
Aggregations