Search in sources :

Example 1 with ComponentsCalculationHolder

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;
            }
        }
    }
}
Also used : OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) Entity(com.qcadoo.model.api.Entity) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) DataDefinition(com.qcadoo.model.api.DataDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 2 with ComponentsCalculationHolder

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);
}
Also used : DataDefinitionService(com.qcadoo.model.api.DataDefinitionService) Autowired(org.springframework.beans.factory.annotation.Autowired) BigDecimalUtils(com.qcadoo.model.api.BigDecimalUtils) HashMap(java.util.HashMap) ProductStructureTreeService(com.qcadoo.mes.technologies.tree.ProductStructureTreeService) ProductQuantitiesWithComponentsService(com.qcadoo.mes.technologies.ProductQuantitiesWithComponentsService) TechnologyOperationComponentFields(com.qcadoo.mes.technologies.constants.TechnologyOperationComponentFields) LinkedHashMap(java.util.LinkedHashMap) CostCalculationFields(com.qcadoo.mes.costCalculation.constants.CostCalculationFields) BigDecimal(java.math.BigDecimal) MrpAlgorithm(com.qcadoo.mes.technologies.constants.MrpAlgorithm) Service(org.springframework.stereotype.Service) Map(java.util.Map) ComponentCostKey(com.qcadoo.mes.costCalculation.print.dto.ComponentCostKey) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) OperationProductInComponentFields(com.qcadoo.mes.technologies.constants.OperationProductInComponentFields) MathContext(java.math.MathContext) Collection(java.util.Collection) CalculationOperationComponentFields(com.qcadoo.mes.costNormsForOperation.constants.CalculationOperationComponentFields) SourceOfOperationCosts(com.qcadoo.mes.costCalculation.constants.SourceOfOperationCosts) OperationProductComponentHolder(com.qcadoo.mes.technologies.dto.OperationProductComponentHolder) DataDefinition(com.qcadoo.model.api.DataDefinition) EntityTree(com.qcadoo.model.api.EntityTree) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ProductBySizeGroupFields(com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields) Entity(com.qcadoo.model.api.Entity) List(java.util.List) TechnologyInputProductTypeFields(com.qcadoo.mes.technologies.constants.TechnologyInputProductTypeFields) NumberService(com.qcadoo.model.api.NumberService) TechnologiesConstants(com.qcadoo.mes.technologies.constants.TechnologiesConstants) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) EntityTree(com.qcadoo.model.api.EntityTree) BigDecimal(java.math.BigDecimal)

Example 3 with ComponentsCalculationHolder

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);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) CostCalculationMaterial(com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial) BigDecimal(java.math.BigDecimal) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet)

Example 4 with ComponentsCalculationHolder

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);
    }
}
Also used : ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow)

Example 5 with ComponentsCalculationHolder

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);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ComponentsCalculationHolder(com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder) DataDefinition(com.qcadoo.model.api.DataDefinition)

Aggregations

ComponentsCalculationHolder (com.qcadoo.mes.costCalculation.print.dto.ComponentsCalculationHolder)10 Entity (com.qcadoo.model.api.Entity)8 BigDecimal (java.math.BigDecimal)7 LinkedHashMap (java.util.LinkedHashMap)5 DataDefinition (com.qcadoo.model.api.DataDefinition)4 HashMap (java.util.HashMap)4 OperationProductComponentHolder (com.qcadoo.mes.technologies.dto.OperationProductComponentHolder)3 Map (java.util.Map)3 ComponentCostKey (com.qcadoo.mes.costCalculation.print.dto.ComponentCostKey)2 MathContext (java.math.MathContext)2 CostCalculationFields (com.qcadoo.mes.costCalculation.constants.CostCalculationFields)1 SourceOfOperationCosts (com.qcadoo.mes.costCalculation.constants.SourceOfOperationCosts)1 CostCalculationMaterial (com.qcadoo.mes.costCalculation.print.dto.CostCalculationMaterial)1 CalculationOperationComponentFields (com.qcadoo.mes.costNormsForOperation.constants.CalculationOperationComponentFields)1 ProductQuantitiesWithComponentsService (com.qcadoo.mes.technologies.ProductQuantitiesWithComponentsService)1 MrpAlgorithm (com.qcadoo.mes.technologies.constants.MrpAlgorithm)1 OperationProductInComponentFields (com.qcadoo.mes.technologies.constants.OperationProductInComponentFields)1 ProductBySizeGroupFields (com.qcadoo.mes.technologies.constants.ProductBySizeGroupFields)1 TechnologiesConstants (com.qcadoo.mes.technologies.constants.TechnologiesConstants)1 TechnologyInputProductTypeFields (com.qcadoo.mes.technologies.constants.TechnologyInputProductTypeFields)1