Search in sources :

Example 36 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class ProductionTrackingListenerServicePFTD method createWarehouseDocuments.

public void createWarehouseDocuments(final Entity productionTracking) {
    Entity order = productionTracking.getBelongsToField(ProductionTrackingFields.ORDER);
    Entity technologyOperationComponent = productionTracking.getBelongsToField(ProductionTrackingFields.TECHNOLOGY_OPERATION_COMPONENT);
    List<Entity> trackingOperationProductOutComponents = productionTracking.getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS);
    Multimap<Long, Entity> groupedRecordOutProducts = productionTrackingDocumentsHelper.fillFromBPCProductOut(trackingOperationProductOutComponents, order, true);
    List<Entity> trackingOperationProductInComponents = productionTracking.getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENTS);
    Multimap<Long, Entity> groupedRecordInProducts = productionTrackingDocumentsHelper.fillFromBPCProductIn(trackingOperationProductInComponents, order, technologyOperationComponent, true);
    boolean releaseMaterials = ReleaseOfMaterials.ON_ACCEPTANCE_REGISTRATION_RECORD.getStringValue().equals(parameterService.getParameter().getStringField(ParameterFieldsPC.RELEASE_OF_MATERIALS));
    if (!groupedRecordInProducts.isEmpty() && releaseMaterials && !checkIfProductsAvailableInStock(productionTracking, groupedRecordInProducts)) {
        return;
    }
    String receiptOfProducts = parameterService.getParameter().getStringField(ParameterFieldsPC.RECEIPT_OF_PRODUCTS);
    if (ReceiptOfProducts.ON_ACCEPTANCE_REGISTRATION_RECORD.getStringValue().equals(receiptOfProducts) || ReceiptOfProducts.END_OF_THE_ORDER.getStringValue().equals(receiptOfProducts)) {
        for (Long warehouseId : groupedRecordOutProducts.keySet()) {
            Entity locationTo = getLocationDD().get(warehouseId);
            Entity inboundDocument = createOrUpdateInternalInboundDocumentForFinalProducts(locationTo, order, groupedRecordOutProducts.get(warehouseId), productionTracking.getBelongsToField(L_USER));
            if (Objects.nonNull(inboundDocument) && !inboundDocument.isValid()) {
                for (ErrorMessage error : inboundDocument.getGlobalErrors()) {
                    productionTracking.addGlobalError(error.getMessage(), error.getVars());
                }
                productionTracking.addGlobalError("productFlowThruDivision.productionTracking.productionTrackingError.createInternalInboundDocument");
                return;
            }
        }
        TransactionAspectSupport.currentTransactionStatus().flush();
    }
    String releaseOfMaterials = parameterService.getParameter().getStringField(ParameterFieldsPC.RELEASE_OF_MATERIALS);
    if (ReleaseOfMaterials.ON_ACCEPTANCE_REGISTRATION_RECORD.getStringValue().equals(releaseOfMaterials)) {
        boolean errorsDisplayed = false;
        for (Long warehouseId : groupedRecordInProducts.keySet()) {
            Entity locationFrom = getLocationDD().get(warehouseId);
            Entity outboundDocument = createInternalOutboundDocumentForComponents(locationFrom, order, groupedRecordInProducts.get(warehouseId), productionTracking.getBelongsToField(L_USER));
            if (Objects.nonNull(outboundDocument) && !outboundDocument.isValid()) {
                for (ErrorMessage error : outboundDocument.getGlobalErrors()) {
                    if (error.getMessage().equalsIgnoreCase(L_ERROR_NOT_ENOUGH_RESOURCES)) {
                        productionTracking.addGlobalError(error.getMessage(), false, error.getVars());
                    } else if (!errorsDisplayed) {
                        productionTracking.addGlobalError(error.getMessage(), error.getVars());
                    }
                }
                if (!errorsDisplayed) {
                    productionTracking.addGlobalError("productFlowThruDivision.productionTracking.productionTrackingError.createInternalOutboundDocument");
                    errorsDisplayed = true;
                }
            }
        }
        if (errorsDisplayed) {
            return;
        }
        updateCostsForOrder(order);
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage)

Example 37 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class ProgressPerShiftViewSaver method saveProgressesAndForm.

@Transactional
private boolean saveProgressesAndForm(final ViewDefinitionState view) {
    AwesomeDynamicListComponent progressForDaysADL = (AwesomeDynamicListComponent) view.getComponentByReference(PROGRESS_ADL_REF);
    FormComponent form = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
    Entity pps = form.getEntity();
    Long ppsId = pps.getId();
    List<Entity> progressForDays = progressForDaysADL.getEntities();
    ProgressType progressType = extractProgressType(view);
    boolean hasCorrections = progressType == ProgressType.CORRECTED;
    List<Entity> savedProgresses = validateAndSaveProgresses(progressForDays, pps, hasCorrections);
    if (Iterables.all(savedProgresses, IS_VALID)) {
        return tryUpdatePPS(view, pps, hasCorrections, savedProgresses);
    } else {
        progressForDaysADL.setFieldValue(savedProgresses);
        showValidationErrors(view, FluentIterable.from(savedProgresses).transformAndConcat(new Function<Entity, Iterable<ErrorMessage>>() {

            @Override
            public Iterable<ErrorMessage> apply(final Entity input) {
                return input.getGlobalErrors();
            }
        }));
        rollbackCurrentTransaction();
        return false;
    }
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) Entity(com.qcadoo.model.api.Entity) Function(com.google.common.base.Function) ProgressType(com.qcadoo.mes.productionPerShift.constants.ProgressType) AwesomeDynamicListComponent(com.qcadoo.view.api.components.AwesomeDynamicListComponent) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class PpsBaseAlgorithmService method generateProgressForDays.

public void generateProgressForDays(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift) {
    Entity order = productionPerShift.getBelongsToField(ProductionPerShiftFields.ORDER);
    if (progressForDaysContainer.getOrder() != null) {
        order = progressForDaysContainer.getOrder();
    }
    Date orderStartDate = order.getDateField(OrderFields.START_DATE);
    if (orderStartDate == null) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.order.startDateRequired", false));
        throw new IllegalStateException("No start date in order");
    }
    Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE);
    if (productionLine == null) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.order.productionLineRequired", false));
        throw new IllegalStateException("No production line in order");
    }
    List<Shift> shifts = shiftsService.findAll(productionLine);
    if (shifts.isEmpty()) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.productionLine.shiftsRequired", false, productionLine.getStringField(ProductionLineFields.NUMBER)));
        throw new IllegalStateException("No shifts assigned to production line");
    }
    boolean allowIncompleteUnits = parameterService.getParameter().getBooleanField(ParameterFieldsPPS.ALLOW_INCOMPLITE_UNITS);
    BigDecimal plannedQuantity = order.getDecimalField(OrderFields.PLANNED_QUANTITY);
    if (order.getBooleanField(OrderFields.FINAL_PRODUCTION_TRACKING)) {
        plannedQuantity = basicProductionCountingService.getProducedQuantityFromBasicProductionCountings(order);
    }
    calculateRegisteredQuantity(progressForDaysContainer, order, productionPerShift, plannedQuantity);
    BigDecimal alreadyPlannedQuantity = BigDecimal.ZERO;
    List<Entity> progressForDays = Lists.newLinkedList();
    DateTime currentDate = new DateTime(orderStartDate);
    currentDate = currentDate.minusDays(1);
    currentDate = currentDate.toLocalDate().toDateTimeAtStartOfDay();
    boolean shouldBeCorrected = progressForDaysContainer.isShouldBeCorrected();
    int realizationDayNumber = 0;
    while (progressForDaysContainer.getPlannedQuantity().compareTo(BigDecimal.ZERO) > 0 || progressForDaysContainer.getAlreadyRegisteredQuantity().compareTo(BigDecimal.ZERO) > 0) {
        DailyProgressContainer dailyProgressContainer = fillDailyProgressWithShifts(progressForDaysContainer, productionPerShift, order, shifts, currentDate, orderStartDate, shouldBeCorrected, progressForDays.size(), alreadyPlannedQuantity, allowIncompleteUnits);
        if (dailyProgressContainer.isCalculationError()) {
            progressForDaysContainer.setCalculationError(true);
            return;
        }
        List<Entity> dailyProgress = dailyProgressContainer.getDailyProgress();
        if (!dailyProgress.isEmpty()) {
            progressForDays.add(createComponent(realizationDayNumber, currentDate.toDate(), dailyProgress, shouldBeCorrected));
        }
        currentDate = currentDate.plusDays(1);
        ++realizationDayNumber;
    }
    progressForDaysContainer.setProgressForDays(progressForDays);
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) DailyProgressContainer(com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Example 39 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class PpsTechNormAlgorithmService method getStandardPerformanceNorm.

protected BigDecimal getStandardPerformanceNorm(ProgressForDaysContainer progressForDaysContainer, Entity order) {
    Optional<BigDecimal> norm = Optional.empty();
    Entity productionLine = order.getBelongsToField(OrderFields.PRODUCTION_LINE);
    if (productionLine != null) {
        norm = technologyService.getStandardPerformance(order.getBelongsToField(OrderFields.TECHNOLOGY), productionLine);
    }
    if (!norm.isPresent()) {
        progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.technology.standardPerformanceTechnologyRequired", false));
        throw new IllegalStateException("No standard performance norm in technology");
    }
    return norm.get();
}
Also used : Entity(com.qcadoo.model.api.Entity) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal)

Example 40 with ErrorMessage

use of com.qcadoo.model.api.validators.ErrorMessage in project mes by qcadoo.

the class TechnologyApiController method saveOperation.

@ResponseBody
@RequestMapping(value = "/operation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public OperationResponse saveOperation(@RequestBody OperationRequest operation) {
    Entity operationEntity = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION).create();
    operationEntity.setField(OperationFields.NUMBER, operation.getNumber());
    operationEntity.setField(OperationFields.NAME, operation.getName());
    operationEntity.setField(OperationFields.QUANTITY_OF_WORKSTATIONS, 1);
    operationEntity.setField(OperationFields.ASSIGNED_TO_OPERATION, "01workstations");
    operationEntity.setField(OperationFields.CREATE_OPERATION_OUTPUT, true);
    operationEntity.setField("tpz", 0);
    operationEntity.setField("tj", 0);
    operationEntity.setField("timeNextOperation", 0);
    operationEntity.setField("productionInOneCycle", BigDecimal.ONE);
    operationEntity.setField("machineUtilization", BigDecimal.ONE);
    operationEntity.setField("laborUtilization", BigDecimal.valueOf(1L));
    operationEntity.setField("nextOperationAfterProducedType", "01all");
    operationEntity.setField("nextOperationAfterProducedQuantity", BigDecimal.ZERO);
    operationEntity.setField("minStaff", 1);
    operationEntity.setField("tjDecreasesForEnlargedStaff", false);
    operationEntity.setField("optimalStaff", 1);
    operationEntity = operationEntity.getDataDefinition().save(operationEntity);
    if (operationEntity.isValid()) {
        OperationResponse operationResponse = new OperationResponse(OperationResponse.StatusCode.OK);
        operationResponse.setId(operationEntity.getId());
        operationResponse.setNumber(operation.getNumber());
        return operationResponse;
    } else {
        // 
        ErrorMessage numberError = operationEntity.getError(ProductionLineFields.NUMBER);
        if (Objects.nonNull(numberError) && numberError.getMessage().equals("qcadooView.validate.field.error.duplicated")) {
            OperationResponse response = new OperationResponse(OperationResponse.StatusCode.ERROR);
            response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.operationDuplicated", LocaleContextHolder.getLocale()));
            return response;
        }
    }
    OperationResponse response = new OperationResponse(OperationResponse.StatusCode.ERROR);
    response.setMessage(translationService.translate("basic.dashboard.orderDefinitionWizard.error.validationError.operationErrors", LocaleContextHolder.getLocale()));
    return response;
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationResponse(com.qcadoo.mes.technologies.controller.dataProvider.OperationResponse) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)50 Entity (com.qcadoo.model.api.Entity)30 BigDecimal (java.math.BigDecimal)11 Test (org.junit.Test)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Map (java.util.Map)7 DataDefinition (com.qcadoo.model.api.DataDefinition)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 FormComponent (com.qcadoo.view.api.components.FormComponent)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 LocaleContextHolder (org.springframework.context.i18n.LocaleContextHolder)4 Lists (com.google.common.collect.Lists)3 OrderFields (com.qcadoo.mes.orders.constants.OrderFields)3 ProductFlowThruDivisionConstants (com.qcadoo.mes.productFlowThruDivision.constants.ProductFlowThruDivisionConstants)3 WarehouseIssueParameterService (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.WarehouseIssueParameterService)3 ProductsToIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.ProductsToIssueFields)3 WarehouseIssueFields (com.qcadoo.mes.productFlowThruDivision.warehouseIssue.constans.WarehouseIssueFields)3 StateChangeContext (com.qcadoo.mes.states.StateChangeContext)3