use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method fillComponentsQuantity.
private void fillComponentsQuantity(List<ComponentsCalculationHolder> components, Entity technology, BigDecimal quantity) {
Map<OperationProductComponentHolder, BigDecimal> componentQuantitiesByOPC = productQuantitiesWithComponentsService.getNeededProductQuantitiesByOPC(technology, quantity, MrpAlgorithm.ALL_PRODUCTS_IN);
DataDefinition operationProductComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
for (ComponentsCalculationHolder component : components) {
for (Map.Entry<OperationProductComponentHolder, BigDecimal> cq : componentQuantitiesByOPC.entrySet()) {
if (cq.getKey().getTechnologyOperationComponentId().equals(component.getToc().getBelongsToField(TechnologyOperationComponentFields.PARENT).getId()) && cq.getKey().getProductId().equals(component.getProduct().getId())) {
component.setQuantity(cq.getValue());
String technologyInputProductTypeName = "";
Entity technologyInputProductType = operationProductComponentDD.get(cq.getKey().getOperationProductComponentId()).getBelongsToField(OperationProductInComponentFields.TECHNOLOGY_INPUT_PRODUCT_TYPE);
if (technologyInputProductType != null) {
technologyInputProductTypeName = technologyInputProductType.getStringField(TechnologyInputProductTypeFields.NAME);
}
component.setTechnologyInputProductType(technologyInputProductTypeName);
break;
}
}
}
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationComponentsService method getComponentCosts.
public Collection<ComponentsCalculationHolder> getComponentCosts(final Entity costCalculation, final Entity technology, List<Entity> calculationOperationComponents) {
EntityTree operationComponents = productStructureTreeService.getOperationComponentsFromTechnology(technology);
List<ComponentsCalculationHolder> components = operationComponents.stream().filter(pc -> ProductStructureTreeService.L_COMPONENT.equals(pc.getStringField(TechnologyOperationComponentFields.TYPE_FROM_STRUCTURE_TREE))).map(toc -> new ComponentsCalculationHolder(toc, toc.getBelongsToField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE), technology)).collect(Collectors.toList());
List<ComponentsCalculationHolder> allOperationComponents = operationComponents.stream().map(toc -> new ComponentsCalculationHolder(toc, toc.getBelongsToField(TechnologyOperationComponentFields.PRODUCT_FROM_STRUCTURE_TREE), technology)).collect(Collectors.toList());
BigDecimal quantity = costCalculation.getDecimalField(CostCalculationFields.QUANTITY);
addMaterialCost(costCalculation, allOperationComponents, technology, quantity);
addLaborCost(costCalculation, allOperationComponents, calculationOperationComponents);
fillComponentsQuantity(components, technology, quantity);
fillComponentsCosts(operationComponents, components, allOperationComponents, quantity);
return groupComponentCosts(components);
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationXlsService method addExtraSheets.
@Override
protected void addExtraSheets(final HSSFWorkbook workbook, Entity entity, Locale locale) {
List<CostCalculationMaterial> materialCosts = Lists.newArrayList();
List<ComponentsCalculationHolder> componentCosts = Lists.newArrayList();
List<Entity> calculationOperationComponents = Lists.newArrayList();
List<Entity> calculationResults = Lists.newArrayList();
Map<Long, Boolean> hasComponents = Maps.newHashMap();
boolean includeComponents = entity.getBooleanField(CostCalculationFields.INCLUDE_COMPONENTS);
HSSFSheet sheet = workbook.getSheetAt(0);
final FontsContainer fontsContainer = new FontsContainer(sheet.getWorkbook());
final StylesContainer stylesContainer = new StylesContainer(sheet.getWorkbook(), fontsContainer);
for (Entity technology : entity.getHasManyField(CostCalculationFields.TECHNOLOGIES)) {
List<CostCalculationMaterial> technologyMaterialCosts = costCalculationMaterialsService.getSortedMaterialsFromProductQuantities(entity, technology);
materialCosts.addAll(technologyMaterialCosts);
BigDecimal technologyMaterialsCostsSum = BigDecimal.ZERO;
boolean noMaterialPrice = false;
for (CostCalculationMaterial technologyMaterialCost : technologyMaterialCosts) {
BigDecimal costForGivenQuantity = technologyMaterialCost.getCostForGivenQuantity();
if (BigDecimalUtils.valueEquals(costForGivenQuantity, BigDecimal.ZERO)) {
noMaterialPrice = true;
}
technologyMaterialsCostsSum = technologyMaterialsCostsSum.add(costForGivenQuantity, numberService.getMathContext());
}
BigDecimal labourCost;
if (SourceOfOperationCosts.STANDARD_LABOR_COSTS.equals(SourceOfOperationCosts.parseString(entity.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS)))) {
labourCost = entity.getBelongsToField(CostCalculationFields.STANDARD_LABOR_COST).getDecimalField(StandardLaborCostFields.LABOR_COST);
} else {
labourCost = operationsCostCalculationService.calculateOperationsCost(entity, technology);
List<Entity> technologyCalculationOperationComponents = entity.getHasManyField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS);
technologyCalculationOperationComponents.forEach(e -> e.setField(CalculationOperationComponentFields.TECHNOLOGY, technology));
calculationOperationComponents.addAll(technologyCalculationOperationComponents);
}
calculationResults.add(costCalculationService.createCalculationResults(entity, technology, technologyMaterialsCostsSum, labourCost, noMaterialPrice));
}
if (includeComponents) {
for (Entity technology : entity.getHasManyField(CostCalculationFields.TECHNOLOGIES)) {
Collection<ComponentsCalculationHolder> technologyComponentCosts = costCalculationComponentsService.getComponentCosts(entity, technology, calculationOperationComponents);
componentCosts.addAll(technologyComponentCosts);
hasComponents.put(technology.getId(), !technologyComponentCosts.isEmpty());
}
createComponentCosts(entity, componentCosts);
}
createCalculationResultsSheet(sheet, entity, calculationResults, hasComponents, stylesContainer, locale);
createMaterialCostsSheet(materialCosts, createSheet(workbook, translationService.translate("costCalculation.costCalculation.report.xls.sheet.materialCosts", locale)), locale);
createMaterialsBySizeSheet(entity, createSheet(workbook, translationService.translate("costCalculation.costCalculation.report.xls.sheet.materialsBySize", locale)), locale);
if (!SourceOfOperationCosts.STANDARD_LABOR_COSTS.equals(SourceOfOperationCosts.parseString(entity.getStringField(CostCalculationFields.SOURCE_OF_OPERATION_COSTS)))) {
createLabourCostSheet(calculationOperationComponents, createSheet(workbook, translationService.translate("costCalculation.costCalculation.report.xls.sheet.labourCost", locale)), locale);
}
if (includeComponents) {
createComponentCostsSheet(componentCosts, createSheet(workbook, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts", locale)), locale);
}
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationXlsService method createComponentCostsSheet.
private void createComponentCostsSheet(List<ComponentsCalculationHolder> componentCosts, HSSFSheet sheet, Locale locale) {
final FontsContainer fontsContainer = new FontsContainer(sheet.getWorkbook());
final StylesContainer stylesContainer = new StylesContainer(sheet.getWorkbook(), fontsContainer);
final int rowOffset = 1;
HSSFRow row = sheet.createRow(0);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.technologyNumber", locale), 0);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.technologyInputProductType", locale), 1);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.componentNumber", locale), 2);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.componentName", locale), 3);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.quantity", locale), 4);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.unit", locale), 5);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.materialCost", locale), 6);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.labourCost", locale), 7);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.sumOfCosts", locale), 8);
createHeaderCell(stylesContainer, row, translationService.translate("costCalculation.costCalculation.report.xls.sheet.componentCosts.costPerUnit", locale), 9);
int rowCounter = 0;
for (ComponentsCalculationHolder componentCost : componentCosts) {
row = sheet.createRow(rowOffset + rowCounter);
createRegularCell(stylesContainer, row, 0, componentCost.getTechnology().getStringField(TechnologyFields.NUMBER));
createRegularCell(stylesContainer, row, 1, componentCost.getTechnologyInputProductType());
createRegularCell(stylesContainer, row, 2, componentCost.getProduct().getStringField(ProductFields.NUMBER));
createRegularCell(stylesContainer, row, 3, componentCost.getProduct().getStringField(ProductFields.NAME));
createNumericCell(stylesContainer, row, 4, componentCost.getQuantity());
createRegularCell(stylesContainer, row, 5, componentCost.getProduct().getStringField(ProductFields.UNIT));
createNumericCell(stylesContainer, row, 6, componentCost.getMaterialCost());
createNumericCell(stylesContainer, row, 7, componentCost.getLaborCost());
createNumericCell(stylesContainer, row, 8, componentCost.getSumOfCost());
createNumericCell(stylesContainer, row, 9, componentCost.getCostPerUnit());
rowCounter++;
}
for (int i = 0; i <= 9; i++) {
sheet.autoSizeColumn(i, false);
}
}
use of com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder in project mes by qcadoo.
the class CostCalculationXlsService method createComponentCosts.
private void createComponentCosts(Entity entity, List<ComponentsCalculationHolder> componentCosts) {
DataDefinition ccDD = dataDefinitionService.get(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COMPONENT_COST);
for (ComponentsCalculationHolder component : componentCosts) {
Entity cc = ccDD.create();
cc.setField("product", component.getProduct());
cc.setField("pricePerUnit", component.getCostPerUnit());
cc.setField("costCalculation", entity);
ccDD.save(cc);
}
}
Aggregations