use of com.qcadoo.mes.operationTimeCalculations.dto.OperationTimes in project mes by qcadoo.
the class OperationsCostCalculationServiceImpl method estimateCostCalculationForHourly.
private Map<String, BigDecimal> estimateCostCalculationForHourly(final EntityTreeNode calculationOperationComponent, final OperationTimesContainer realizationTimes, final boolean hourlyCostFromOperation, Entity costCalculation) {
checkArgument(calculationOperationComponent != null, "given operationComponent is empty");
Map<String, BigDecimal> costs = Maps.newHashMapWithExpectedSize(L_COST_KEYS.size());
MathContext mathContext = numberService.getMathContext();
for (String costKey : L_COST_KEYS) {
costs.put(costKey, BigDecimal.ZERO);
}
for (EntityTreeNode child : calculationOperationComponent.getChildren()) {
Map<String, BigDecimal> unitCosts = estimateCostCalculationForHourly(child, realizationTimes, hourlyCostFromOperation, costCalculation);
for (String costKey : L_COST_KEYS) {
BigDecimal unitCost = costs.get(costKey).add(unitCosts.get(costKey), mathContext);
costs.put(costKey, numberService.setScaleWithDefaultMathContext(unitCost));
}
}
OperationTimes operationTimes = realizationTimes.get(calculationOperationComponent.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT).getId());
Map<String, BigDecimal> costsForSingleOperation = estimateHourlyCostCalculationForSingleOperation(operationTimes, hourlyCostFromOperation, costCalculation);
saveGeneratedValues(costsForSingleOperation, calculationOperationComponent, operationTimes.getTimes());
costs.put(CalculationOperationComponentFields.MACHINE_HOURLY_COST, costs.get(CalculationOperationComponentFields.MACHINE_HOURLY_COST).add(costsForSingleOperation.get(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST), mathContext));
costs.put(CalculationOperationComponentFields.LABOR_HOURLY_COST, costs.get(CalculationOperationComponentFields.LABOR_HOURLY_COST).add(costsForSingleOperation.get(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST), mathContext));
return costs;
}
use of com.qcadoo.mes.operationTimeCalculations.dto.OperationTimes in project mes by qcadoo.
the class OperationsCostCalculationServiceImpl method calculateOperationsCost.
@Override
public BigDecimal calculateOperationsCost(final Entity costCalculation, final Entity technology) {
DataDefinition costCalculationDataDefinition = costCalculation.getDataDefinition();
BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);
ProductQuantitiesHolder productQuantitiesAndOperationRuns = getProductQuantitiesAndOperationRuns(technology, quantity, costCalculation);
Entity copyCostCalculation = operationCostCalculationTreeBuilder.copyTechnologyTree(costCalculation, technology);
Entity yetAnotherCostCalculation = costCalculationDataDefinition.save(copyCostCalculation);
Entity newCostCalculation = costCalculationDataDefinition.get(yetAnotherCostCalculation.getId());
EntityTree calculationOperationComponents = newCostCalculation.getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS);
checkArgument(calculationOperationComponents != null, "given operation components is null");
List<Entity> tocs = calculationOperationComponents.stream().map(e -> e.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT)).collect(Collectors.toList());
OperationTimesContainer operationTimes = operationWorkTimeService.estimateOperationsWorkTimes(tocs, productQuantitiesAndOperationRuns.getOperationRuns(), costCalculation.getBooleanField(CostCalculationFields.INCLUDE_TPZ), costCalculation.getBooleanField(CostCalculationFields.INCLUDE_ADDITIONAL_TIME), true);
boolean hourlyCostFromOperation = !SourceOfOperationCosts.PARAMETERS.getStringValue().equals(costCalculation.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS));
Map<String, BigDecimal> resultsMap = estimateCostCalculationForHourly(calculationOperationComponents.getRoot(), operationTimes, hourlyCostFromOperation, costCalculation);
costCalculation.setField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS, calculationOperationComponents);
return BigDecimalUtils.convertNullToZero(numberService.setScaleWithDefaultMathContext(resultsMap.get(CalculationOperationComponentFields.MACHINE_HOURLY_COST))).add(BigDecimalUtils.convertNullToZero(numberService.setScaleWithDefaultMathContext(resultsMap.get(CalculationOperationComponentFields.LABOR_HOURLY_COST))), numberService.getMathContext());
}
Aggregations