use of org.compiere.model.MCost in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method getProductFutureCostPrice.
public BigDecimal getProductFutureCostPrice(MPPCostCollector costCollector, MProduct product, MAcctSchema acctSchema, MCostElement costElement, String trxName) {
String CostingLevel = product.getCostingLevel(acctSchema);
// Org Element
int orgId = 0;
int warehouseId = 0;
if (product.getS_Resource_ID() != 0) {
orgId = product.getS_Resource().getAD_Org_ID();
warehouseId = product.getS_Resource().getM_Warehouse_ID();
} else {
orgId = (costCollector == null) ? costElement.getAD_Org_ID() : costCollector.getAD_Org_ID();
warehouseId = (costCollector == null) ? 0 : costCollector.getM_Warehouse_ID();
}
int attributeSetInstanceId = (costCollector == null) ? 0 : costCollector.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
orgId = 0;
attributeSetInstanceId = 0;
warehouseId = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
attributeSetInstanceId = 0;
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
orgId = 0;
CostDimension d = new CostDimension(product, acctSchema, acctSchema.getM_CostType_ID(), orgId, attributeSetInstanceId, //warehouse
warehouseId, costElement.getM_CostElement_ID());
MCost cost = d.toQuery(MCost.class, trxName).firstOnly();
if (cost == null)
return Env.ZERO;
BigDecimal price = cost.getFutureCostPrice().add(cost.getFutureCostPriceLL());
return roundCost(price, acctSchema.getC_AcctSchema_ID());
}
use of org.compiere.model.MCost in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method getProductActualCostPrice.
public BigDecimal getProductActualCostPrice(MPPCostCollector costCollector, MProduct product, MAcctSchema acctSchema, MCostElement costElement, String trxName) {
String CostingLevel = product.getCostingLevel(acctSchema);
// Org Element
int orgId = 0;
int warehouseId = 0;
if (product.getS_Resource_ID() != 0) {
orgId = product.getS_Resource().getAD_Org_ID();
warehouseId = product.getS_Resource().getM_Warehouse_ID();
} else {
orgId = (costCollector == null) ? costElement.getAD_Org_ID() : costCollector.getAD_Org_ID();
warehouseId = (costCollector == null) ? 0 : costCollector.getM_Warehouse_ID();
}
int attributeSetInstanceId = (costCollector == null) ? 0 : costCollector.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
orgId = 0;
attributeSetInstanceId = 0;
warehouseId = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
attributeSetInstanceId = 0;
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
orgId = 0;
CostDimension costDimension = new CostDimension(product, acctSchema, acctSchema.getM_CostType_ID(), orgId, attributeSetInstanceId, //warehouse
warehouseId, costElement.getM_CostElement_ID());
MCost cost = costDimension.toQuery(MCost.class, trxName).firstOnly();
if (cost == null)
return Env.ZERO;
BigDecimal price = cost.getCurrentCostPrice().add(cost.getCurrentCostPriceLL());
return roundCost(price, acctSchema.getC_AcctSchema_ID());
}
use of org.compiere.model.MCost in project adempiere by adempiere.
the class MPPOrder method createStandardCosts.
/**
* Save standard costs records into PP_Order_Cost.
* This will be usefull for calculating standard costs variances
*/
public final void createStandardCosts() {
MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema();
log.info("Cost_Group_ID" + as.getM_CostType_ID());
final TreeSet<Integer> productsAdded = new TreeSet<Integer>();
//
// Create Standard Costs for Order Header (resulting product)
{
final MProduct product = getM_Product();
productsAdded.add(product.getM_Product_ID());
final CostDimension d = new CostDimension(product, as, as.getM_CostType_ID(), getAD_Org_ID(), getM_Warehouse_ID(), getM_AttributeSetInstance_ID(), CostDimension.ANY);
Collection<MCost> costs = d.toQuery(MCost.class, get_TrxName()).list();
for (MCost cost : costs) {
//Create or Update the Order Cost dimension
MPPOrderCost.createOrderCostDimension(get_ID(), cost);
}
}
// Create Standard Costs for Order BOM Line
for (MPPOrderBOMLine line : getLines()) {
final MProduct product = line.getM_Product();
// Check if we already added this product
if (productsAdded.contains(product.getM_Product_ID()))
continue;
productsAdded.add(product.getM_Product_ID());
//
CostDimension d = new CostDimension(line.getM_Product(), as, as.getM_CostType_ID(), line.getAD_Org_ID(), getM_Warehouse_ID(), line.getM_AttributeSetInstance_ID(), CostDimension.ANY);
Collection<MCost> costs = d.toQuery(MCost.class, get_TrxName()).list();
for (MCost cost : costs) {
//Create or Update the Order Cost dimension
MPPOrderCost.createOrderCostDimension(get_ID(), cost);
}
}
// Create Standard Costs from Activity Resources
for (MPPOrderNode node : getMPPOrderWorkflow().getNodes(true)) {
final int S_Resource_ID = node.getS_Resource_ID();
if (S_Resource_ID <= 0)
continue;
final MProduct resourceProduct = MProduct.forS_Resource_ID(getCtx(), S_Resource_ID, null);
// Check if we already added this product
if (productsAdded.contains(resourceProduct.getM_Product_ID()))
continue;
productsAdded.add(resourceProduct.getM_Product_ID());
CostDimension d = new CostDimension(resourceProduct, as, as.getM_CostType_ID(), node.getAD_Org_ID(), getM_Warehouse_ID(), // ASI
0, CostDimension.ANY);
Collection<MCost> costs = d.toQuery(MCost.class, get_TrxName()).list();
for (MCost cost : costs) {
//Create or Update the Order Cost dimension
MPPOrderCost.createOrderCostDimension(get_ID(), cost);
}
}
}
use of org.compiere.model.MCost in project adempiere by adempiere.
the class CostResult method assertCostInvoice.
/**
* Assert Cost Invoice
* @param product
* @param receiptLine
* @param as
* @param trxName
*/
private void assertCostInvoice(CostResult costResult, int M_InOutLine_ID, MAcctSchema as, String trxName) {
//Evaluate Result
MCost cost = assertCost(costResult);
String whereClause = "M_Product_ID=? AND M_CostElement_ID=? AND M_CostType_ID=? AND M_InOutLine_ID=?";
ArrayList<Object> parameters = new ArrayList();
parameters.add(costResult.M_Product_ID);
parameters.add(cost.getM_CostElement_ID());
parameters.add(cost.getM_CostType_ID());
parameters.add(M_InOutLine_ID);
assertCostDetail(costResult, whereClause, parameters);
}
use of org.compiere.model.MCost in project adempiere by adempiere.
the class FrozenUnFrozenCost method doIt.
@Override
protected String doIt() throws Exception {
//Get account schema
MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
//Get cost type
MCostType costType = MCostType.get(getCtx(), getCostTypeId());
//Get cost element to process
final List<MCostElement> costElements = getCostElementId() > 0 ? Arrays.asList(MCostElement.get(getCtx(), getCostElementId())) : MCostElement.getCostElement(getCtx(), get_TrxName());
//Iterate cost element
costElements.stream().filter(costElement -> costElement != null).forEach(costElement -> {
AtomicInteger records = new AtomicInteger(0);
Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
MProduct product = MProduct.get(getCtx(), productId);
final CostDimension costDimension = new CostDimension(product, accountSchema, costType.getM_CostType_ID(), getOrganizationId(), getWarehouseId(), 0, costElement.getM_CostElement_ID());
Trx.run(trxName -> {
final List<MCost> costs = costDimension.toQuery(MCost.class, trxName).list();
costs.stream().filter(cost -> cost != null).forEach(cost -> {
cost.setIsCostFrozen(isCostFrozen());
cost.saveEx();
records.updateAndGet(record -> record + 1);
});
});
});
String message = "@M_CostElement_ID@ " + costElement.getName() + " @Records@ " + records.get() + " @IsCostFrozen@ = " + isCostFrozen();
addLog(Msg.parseTranslation(getCtx(), message));
});
return "@OK@";
}
Aggregations