use of org.compiere.model.MCostElement 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.compiere.model.MCostElement in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param cost
*/
public void adjustCostDetail(MCostDetail cost) {
Properties ctx = cost.getCtx();
String trxName = cost.get_TrxName();
int transactionId = cost.getM_Transaction_ID();
int clientId = cost.getAD_Client_ID();
MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
MCostType costType = (MCostType) cost.getM_CostType();
MCostElement costElement = (MCostElement) cost.getM_CostElement();
MAcctSchema accountSchema = (MAcctSchema) cost.getC_AcctSchema();
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0 && cost.getC_OrderLine_ID() > 0) {
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (match.getM_InOutLine_ID() == line.getM_InOutLine_ID() && match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() == 0 && cost.getC_InvoiceLine_ID() > 0 && cost.getC_LandedCostAllocation_ID() == 0) {
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
}
}
// only own allocation
if (cost.getC_LandedCostAllocation_ID() != 0) {
MLandedCostAllocation allocation = (MLandedCostAllocation) cost.getC_LandedCostAllocation();
{
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
}
}
} else
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class AbstractCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param cost
*/
public void adjustCostDetail(MCostDetail cost) {
MCostType costType = (MCostType) cost.getM_CostType();
MCostElement costElement = (MCostElement) cost.getM_CostElement();
MTransaction transaction = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
IDocumentLine docLine = transaction.getDocumentLine();
CostEngineFactory.getCostEngine(cost.getAD_Client_ID()).createCostDetail((MAcctSchema) cost.getC_AcctSchema(), costType, costElement, transaction, docLine, true);
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class Doc_PPCostCollector method createMaterialReceipt.
/**
* The Receipt Finish good product created the next account fact
* Debit Product Asset Account for each Cost Element using Current Cost
* Create a fact line for each cost element type
* Material
* Labor(Resources)
* Burden
* Overhead
* Outsite Processing
* Debit Scrap Account for each Cost Element using Current Cost
* Create a fact line for each cost element type
* Material
* Labor(Resources)
* Burden
* Overhead
* Outsite Processing
* Credit Work in Process Account for each Cost Element using Current Cost
* Create a fact line for each cost element type
* Material
* Labor(Resources)
* Burden
* Overhead
* Outsite Processing
*/
protected Fact createMaterialReceipt(MAcctSchema acctSchema) {
final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
FactLine debitLine = null;
FactLine creditLine = null;
final MAccount workInProcessAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
final MAccount burdenAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Burden, acctSchema);
MAccount inventoryAccount = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_Asset, acctSchema);
BigDecimal totalcosts = BigDecimal.ZERO;
BigDecimal totalcostsScrapped = BigDecimal.ZERO;
for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, true)) {
MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
String description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName();
if (MCostElement.COSTELEMENTTYPE_BurdenMOverhead.equals(costElement.getCostElementType())) {
BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
if (cost.scale() > acctSchema.getStdPrecision())
cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
if (cost.compareTo(Env.ZERO) == 0)
continue;
creditLine = fact.createLine(docLineCostCollector, burdenAccount, acctSchema.getC_Currency_ID(), null, cost);
creditLine.setQty(costCollector.getMovementQty());
creditLine.setDescription(description);
totalcosts = totalcosts.add(cost);
continue;
}
if (costCollector.getMovementQty().signum() != 0) {
BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
if (cost.scale() > acctSchema.getStdPrecision())
cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
if (cost.compareTo(Env.ZERO) == 0)
continue;
creditLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), cost.negate());
creditLine.setQty(costCollector.getMovementQty());
creditLine.setDescription(description);
totalcosts = totalcosts.add(cost);
}
if (costCollector.getScrappedQty().signum() != 0) {
BigDecimal absoluteCost = costDetail.getPrice().multiply(costCollector.getScrappedQty()).add(costDetail.getTotalCost(costDetail, acctSchema));
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
if (cost.scale() > acctSchema.getStdPrecision())
cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
creditLine = fact.createLine(docLineCostCollector, workInProcessAccount, acctSchema.getC_Currency_ID(), null, cost.negate());
creditLine.setQty(costCollector.getMovementQty());
description = manufacturingOrder.getDocumentNo() + " - " + costDetail.getM_CostType().getName() + " - " + costElement.getName() + " - " + Msg.parseTranslation(getCtx(), "@Scrap@");
;
creditLine.setDescription(description);
totalcostsScrapped = totalcostsScrapped.add(cost);
}
}
String description = manufacturingOrder.getDocumentNo();
// Debit Amount based on sign of total costs
debitLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalcosts);
debitLine.setQty(costCollector.getMovementQty());
debitLine.setDescription(description);
if (totalcostsScrapped.compareTo(Env.ZERO) != 0) {
debitLine = fact.createLine(docLineCostCollector, inventoryAccount, acctSchema.getC_Currency_ID(), totalcostsScrapped);
debitLine.setQty(costCollector.getScrappedQty());
description = Msg.parseTranslation(getCtx(), "@Scrap@");
debitLine.setDescription(description);
}
return fact;
}
use of org.compiere.model.MCostElement in project adempiere by adempiere.
the class Doc_PPCostCollector method createVariance.
protected Fact createVariance(MAcctSchema acctSchema, int varianceAcctType) {
final Fact fact = new Fact(this, acctSchema, Fact.POST_Actual);
final MProduct product = costCollector.getM_Product();
MAccount varianceAccount = docLineCostCollector.getAccount(varianceAcctType, acctSchema);
MAccount workInProcess = docLineCostCollector.getAccount(ProductCost.ACCTTYPE_P_WorkInProcess, acctSchema);
for (MCostDetail costDetail : docLineCostCollector.getCostDetail(acctSchema, false)) {
MCostElement costElement = MCostElement.get(getCtx(), costDetail.getM_CostElement_ID());
BigDecimal absoluteCost = costDetail.getTotalCost(costDetail, acctSchema);
if (absoluteCost.signum() == 0)
continue;
BigDecimal cost = costDetail.getQty().signum() < 0 ? absoluteCost.negate() : absoluteCost;
if (cost == null)
cost = BigDecimal.ZERO;
if (cost.scale() > acctSchema.getStdPrecision())
cost = cost.setScale(acctSchema.getStdPrecision(), RoundingMode.HALF_UP);
BigDecimal qty = costDetail.getQty();
createLines(costElement, acctSchema, fact, product, varianceAccount, workInProcess, cost, qty);
}
return fact;
}
Aggregations