use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method addChildCost.
private void addChildCost(ComponentsCalculationHolder component, ComponentsCalculationHolder child, List<ComponentsCalculationHolder> allOperations, Map<Long, Entity> entitiesById, MathContext mathContext) {
ComponentsCalculationHolder _component = component;
if (child != null) {
BigDecimal materialCost = BigDecimalUtils.convertNullToZero(component.getMaterialCost()).add(BigDecimalUtils.convertNullToZero(child.getMaterialCost()), mathContext);
BigDecimal laborCost = BigDecimalUtils.convertNullToZero(component.getLaborCost()).add(BigDecimalUtils.convertNullToZero(child.getLaborCost()), mathContext);
component.setLaborCost(numberService.setScaleWithDefaultMathContext(laborCost, 2));
component.setMaterialCost(numberService.setScaleWithDefaultMathContext(materialCost, 2));
_component = child;
}
for (Entity toc : entitiesById.get(_component.getToc().getId()).getHasManyField(TechnologyOperationComponentFields.CHILDREN)) {
ComponentsCalculationHolder nextChild = allOperations.stream().filter(op -> op.getToc().getId().equals(toc.getId())).findFirst().orElse(null);
addChildCost(component, nextChild, allOperations, entitiesById, mathContext);
}
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method addMaterialCost.
private void addMaterialCost(final Entity costCalculation, final List<ComponentsCalculationHolder> allOperationComponents, final Entity technology, final BigDecimal quantity) {
MathContext mathContext = numberService.getMathContext();
Map<OperationProductComponentHolder, BigDecimal> materialQuantitiesByOPC = productQuantitiesWithComponentsService.getNeededProductQuantitiesByOPC(technology, quantity, MrpAlgorithm.ONLY_MATERIALS);
DataDefinition operationProductComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
for (Map.Entry<OperationProductComponentHolder, BigDecimal> neededProductQuantity : materialQuantitiesByOPC.entrySet()) {
Entity product = neededProductQuantity.getKey().getProduct();
Entity operationProductComponent = operationProductComponentDD.get(neededProductQuantity.getKey().getOperationProductComponentId());
BigDecimal costPerUnit = productsCostCalculationService.calculateOperationProductCostPerUnit(costCalculation, product, operationProductComponent);
BigDecimal productQuantity = neededProductQuantity.getValue();
BigDecimal costForGivenQuantity = costPerUnit.multiply(BigDecimalUtils.convertNullToZero(productQuantity), numberService.getMathContext());
if (operationProductComponent.getBooleanField(OperationProductInComponentFields.DIFFERENT_PRODUCTS_IN_DIFFERENT_SIZES)) {
List<Entity> productsBySize = operationProductComponent.getHasManyField(OperationProductInComponentFields.PRODUCT_BY_SIZE_GROUPS);
BigDecimal sumOfCosts = BigDecimal.ZERO;
for (Entity pbs : productsBySize) {
Entity p = pbs.getBelongsToField(ProductBySizeGroupFields.PRODUCT);
BigDecimal costPerUnitPBS = productsCostCalculationService.calculateProductCostPerUnit(p, costCalculation.getStringField(CostCalculationFields.MATERIAL_COSTS_USED), costCalculation.getBooleanField(CostCalculationFields.USE_NOMINAL_COST_PRICE_NOT_SPECIFIED));
BigDecimal q = costCalculation.getDecimalField(CostCalculationFields.QUANTITY).multiply(pbs.getDecimalField(ProductBySizeGroupFields.QUANTITY), numberService.getMathContext());
BigDecimal costPBS = numberService.setScaleWithDefaultMathContext(costPerUnitPBS.multiply(q));
sumOfCosts = sumOfCosts.add(costPBS, numberService.getMathContext());
}
costForGivenQuantity = sumOfCosts.divide(new BigDecimal(productsBySize.size()), numberService.getMathContext());
}
ComponentsCalculationHolder cc = allOperationComponents.stream().filter(bc -> bc.getToc().getId().equals(neededProductQuantity.getKey().getTechnologyOperationComponentId())).findFirst().orElse(null);
if (Objects.nonNull(cc)) {
BigDecimal materialCost = BigDecimalUtils.convertNullToZero(cc.getMaterialCost()).add(BigDecimalUtils.convertNullToZero(costForGivenQuantity), mathContext);
cc.setMaterialCost(numberService.setScaleWithDefaultMathContext(materialCost, 2));
}
}
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method groupComponentCosts.
private Collection<ComponentsCalculationHolder> groupComponentCosts(List<ComponentsCalculationHolder> components) {
Map<ComponentCostKey, ComponentsCalculationHolder> groupedComponentCosts = new HashMap<>();
for (ComponentsCalculationHolder componentsCalculationHolder : components) {
ComponentCostKey componentCostKey = new ComponentCostKey(componentsCalculationHolder.getProduct().getId(), componentsCalculationHolder.getTechnologyInputProductType());
if (groupedComponentCosts.containsKey(componentCostKey)) {
ComponentsCalculationHolder groupedComponentCost = groupedComponentCosts.get(componentCostKey);
groupedComponentCost.setMaterialCost(groupedComponentCost.getMaterialCost().add(componentsCalculationHolder.getMaterialCost(), numberService.getMathContext()));
if (!Objects.isNull(groupedComponentCost.getLaborCost())) {
groupedComponentCost.setLaborCost(groupedComponentCost.getLaborCost().add(componentsCalculationHolder.getLaborCost(), numberService.getMathContext()));
}
groupedComponentCost.setSumOfCost(groupedComponentCost.getSumOfCost().add(componentsCalculationHolder.getSumOfCost(), numberService.getMathContext()));
groupedComponentCost.setQuantity(groupedComponentCost.getQuantity().add(componentsCalculationHolder.getQuantity(), numberService.getMathContext()));
groupedComponentCost.setCostPerUnit(groupedComponentCost.getCostPerUnit().add(componentsCalculationHolder.getCostPerUnit(), numberService.getMathContext()));
groupedComponentCosts.put(componentCostKey, groupedComponentCost);
} else {
groupedComponentCosts.put(componentCostKey, componentsCalculationHolder);
}
}
return groupedComponentCosts.values();
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method addLaborCost.
private void addLaborCost(final Entity costCalculation, List<ComponentsCalculationHolder> allOperationComponents, List<Entity> calculationOperationComponents) {
if (!SourceOfOperationCosts.STANDARD_LABOR_COSTS.equals(SourceOfOperationCosts.parseString(costCalculation.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS)))) {
for (Entity calculationOperationComponent : calculationOperationComponents) {
BigDecimal totalMachineOperationCost = calculationOperationComponent.getDecimalField(CalculationOperationComponentFields.TOTAL_MACHINE_OPERATION_COST);
BigDecimal totalLaborOperationCost = calculationOperationComponent.getDecimalField(CalculationOperationComponentFields.TOTAL_LABOR_OPERATION_COST);
ComponentsCalculationHolder holder = allOperationComponents.stream().filter(bc -> bc.getToc().getId().equals(calculationOperationComponent.getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT).getId())).findFirst().orElse(null);
if (Objects.nonNull(holder)) {
BigDecimal cost = BigDecimalUtils.convertNullToZero(totalMachineOperationCost).add(BigDecimalUtils.convertNullToZero(totalLaborOperationCost), numberService.getMathContext());
holder.setLaborCost(numberService.setScaleWithDefaultMathContext(cost, 2));
}
}
}
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method fillComponentsCosts.
private void fillComponentsCosts(final EntityTree operationComponents, final List<ComponentsCalculationHolder> components, final List<ComponentsCalculationHolder> allOperationComponents, final BigDecimal quantity) {
Map<Long, Entity> entitiesById = new LinkedHashMap<>();
for (Entity entity : operationComponents) {
entitiesById.put(entity.getId(), entity);
}
for (ComponentsCalculationHolder component : components) {
ComponentsCalculationHolder holder = allOperationComponents.stream().filter(op -> op.getToc().getId().equals(component.getToc().getId())).findFirst().get();
component.setMaterialCost(holder.getMaterialCost());
component.setLaborCost(holder.getLaborCost());
addChildCost(component, null, allOperationComponents, entitiesById, numberService.getMathContext());
BigDecimal sumOfCost = BigDecimalUtils.convertNullToZero(component.getLaborCost()).add(BigDecimalUtils.convertNullToZero(component.getMaterialCost()), numberService.getMathContext());
BigDecimal costPerUnit = sumOfCost.divide(quantity, numberService.getMathContext());
component.setSumOfCost(numberService.setScaleWithDefaultMathContext(sumOfCost, 2));
component.setCostPerUnit(numberService.setScaleWithDefaultMathContext(costPerUnit, 2));
}
}
Aggregations