use of org.eevolution.model.RoutingService in project adempiere by adempiere.
the class StandardCostingMethod method createUsageVariances.
public void createUsageVariances(MPPCostCollector usageVariance) {
// Apply only for material Usage Variance
if (!usageVariance.isCostCollectorType(MPPCostCollector.COSTCOLLECTORTYPE_UsegeVariance))
throw new IllegalArgumentException("Cost Collector is not Material Usage Variance");
//
final MProduct product;
final BigDecimal quantity;
if (usageVariance.getPP_Order_BOMLine_ID() > 0) {
product = MProduct.get(usageVariance.getCtx(), usageVariance.getM_Product_ID());
quantity = usageVariance.getMovementQty();
} else {
product = MProduct.forS_Resource_ID(usageVariance.getCtx(), usageVariance.getS_Resource_ID(), null);
final RoutingService routingService = RoutingServiceFactory.get().getRoutingService(usageVariance.getAD_Client_ID());
quantity = routingService.getResourceBaseValue(usageVariance.getS_Resource_ID(), usageVariance);
}
//
for (MAcctSchema accountSchema : CostEngine.getAcctSchema(usageVariance)) {
for (MCostElement element : MCostElement.getCostElement(usageVariance.getCtx(), usageVariance.get_TrxName())) {
final BigDecimal price = getProductActualCostPrice(usageVariance, product, accountSchema, element, usageVariance.get_TrxName());
final BigDecimal amt = CostEngine.roundCost(price.multiply(quantity), accountSchema.getC_AcctSchema_ID());
// Create / Update Cost Detail
if (amt.compareTo(Env.ZERO) != 0) {
List<MCostType> costTypes = MCostType.get(accountSchema.getCtx(), accountSchema.get_TrxName());
for (MCostType costType : costTypes) {
createVarianceCostDetail(usageVariance, amt.abs(), quantity, null, product, accountSchema, costType, element);
}
}
}
// for Elments
}
// Account Schema
}
use of org.eevolution.model.RoutingService 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.RoutingService in project adempiere by adempiere.
the class StandardCostingMethod method createActivityControl.
public void createActivityControl(MPPCostCollector costCollector) {
if (!costCollector.isCostCollectorType(MPPCostCollector.COSTCOLLECTORTYPE_ActivityControl))
return;
//
final MProduct product = MProduct.forS_Resource_ID(costCollector.getCtx(), costCollector.getS_Resource_ID(), null);
final RoutingService routingService = RoutingServiceFactory.get().getRoutingService(costCollector.getAD_Client_ID());
final BigDecimal quantity = routingService.getResourceBaseValue(costCollector.getS_Resource_ID(), costCollector);
for (MAcctSchema accountSchema : CostEngine.getAcctSchema(costCollector)) {
for (MCostElement costElement : MCostElement.getCostElement(costCollector.getCtx(), costCollector.get_TrxName())) {
if (!CostEngine.isActivityControlElement(costElement)) {
continue;
}
final CostDimension dimension = new CostDimension(product, accountSchema, accountSchema.getM_CostType_ID(), costCollector.getAD_Org_ID(), costCollector.getM_Warehouse_ID(), costCollector.getM_AttributeSetInstanceTo_ID(), costElement.getM_CostElement_ID());
final BigDecimal price = getResourceActualCostRate(costCollector.getS_Resource_ID(), dimension, costCollector.get_TrxName());
BigDecimal costs = price.multiply(quantity);
if (costs.scale() > accountSchema.getCostingPrecision())
costs = costs.setScale(accountSchema.getCostingPrecision(), RoundingMode.HALF_UP);
//
List<MCostType> costTypes = MCostType.get(accountSchema.getCtx(), accountSchema.get_TrxName());
for (MCostType costType : costTypes) {
//implementation only for standard cost
if (!MCostType.COSTINGMETHOD_StandardCosting.equals(costType.getCostingMethod()))
continue;
MCostDetail cost = new // AD_Org_ID,
MCostDetail(// AD_Org_ID,
accountSchema, // AD_Org_ID,
costCollector.getAD_Org_ID(), // M_AttributeSetInstance_ID,
dimension.getM_Product_ID(), // M_AttributeSetInstance_ID,
0, costElement.getM_CostElement_ID(), costs.negate(), // Description,
quantity.negate(), // Description,
costElement.getName(), costCollector.get_TrxName(), costType.getM_CostType_ID());
cost.setPP_Cost_Collector_ID(costCollector.getPP_Cost_Collector_ID());
cost.setDateAcct(costCollector.getDateAcct());
cost.setCostAmt(costs.negate());
cost.saveEx();
}
}
}
}
use of org.eevolution.model.RoutingService in project adempiere by adempiere.
the class RollupWorkflow method doIt.
// prepare
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());
routingService = RoutingServiceFactory.get().getRoutingService(getAD_Client_ID());
//Iterate product ids based on parameters
Arrays.stream(getProductIds()).filter(productId -> productId > 0).forEach(productId -> {
MProduct product = MProduct.get(getCtx(), productId);
log.info("Product: " + product);
int workflowId = 0;
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@");
else {
Trx.run(new TrxRunnable() {
MAcctSchema accountSchema;
MCostType costType;
MProduct product;
MPPProductPlanning productPlanning;
int workflowId;
public TrxRunnable setParameters(MAcctSchema accountSchema, MCostType costType, MProduct product, MPPProductPlanning productPlanning, int workflowId) {
this.accountSchema = accountSchema;
this.costType = costType;
this.product = product;
this.productPlanning = productPlanning;
this.workflowId = workflowId;
return this;
}
public void run(String trxName) {
MWorkflow workflow = new MWorkflow(getCtx(), workflowId, trxName);
costElements.stream().filter(costElement -> costElement != null && CostEngine.isActivityControlElement(costElement)).forEach(costElement -> {
rollup(accountSchema, costType, costElement, product, workflow, trxName);
});
if (productPlanning != null) {
productPlanning.load(trxName);
productPlanning.setYield(workflow.getYield());
productPlanning.saveEx();
}
}
}.setParameters(accountSchema, costType, product, productPlanning, workflowId));
}
});
return "@OK@";
}
Aggregations