use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class OperationDurationDetailsInOrderListeners method scheduleOrder.
private void scheduleOrder(final Long orderId) {
Entity order = dataDefinitionService.get(OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER).get(orderId);
if (order == null) {
return;
}
Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
if (technology == null) {
return;
}
List<Date> operationStartDates = Lists.newArrayList();
List<Date> operationEndDates = Lists.newArrayList();
DataDefinition technologyOperationComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_OPERATION_COMPONENT);
List<Entity> operations = technologyOperationComponentDD.find().add(SearchRestrictions.belongsTo(TechnologyOperationComponentFields.TECHNOLOGY, technology)).list().getEntities();
Date orderStartDate = order.getDateField(OrderFields.START_DATE);
for (Entity operation : operations) {
Entity operCompTimeCalculation = operationWorkTimeService.createOrGetOperCompTimeCalculation(order, operation);
if (operCompTimeCalculation == null) {
continue;
}
Integer offset = operCompTimeCalculation.getIntegerField(OperCompTimeCalculationsFields.OPERATION_OFF_SET);
Integer duration = operCompTimeCalculation.getIntegerField(OperCompTimeCalculationsFields.EFFECTIVE_OPERATION_REALIZATION_TIME);
operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_FROM, null);
operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_TO, null);
if (offset == null || duration == null) {
continue;
}
if (duration.equals(0)) {
duration = duration + 1;
}
Date dateFrom = productionSchedulingService.getStartDate(order, orderStartDate, offset);
if (dateFrom == null) {
continue;
}
Date dateTo = productionSchedulingService.getFinishDate(order, orderStartDate, (long) offset + duration);
operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_FROM, dateFrom);
operCompTimeCalculation.setField(OperCompTimeCalculationsFields.EFFECTIVE_DATE_TO, dateTo);
operationStartDates.add(dateFrom);
operationEndDates.add(dateTo);
operCompTimeCalculation.getDataDefinition().save(operCompTimeCalculation);
}
Entity orderTimeCalculation = dataDefinitionService.get(TimeNormsConstants.PLUGIN_PRODUCTION_SCHEDULING_IDENTIFIER, TimeNormsConstants.MODEL_ORDER_TIME_CALCULATION).find().add(SearchRestrictions.belongsTo("order", order)).setMaxResults(1).uniqueResult();
orderTimeCalculation.setField(OrderTimeCalculationFields.EFFECTIVE_DATE_FROM, operationStartDates.stream().min(Comparator.naturalOrder()).get());
orderTimeCalculation.setField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO, operationEndDates.stream().max(Comparator.naturalOrder()).get());
orderTimeCalculation.getDataDefinition().save(orderTimeCalculation);
order.setField(OrderFieldsPS.GENERATED_END_DATE, orderRealizationTimeService.setDateToField(orderTimeCalculation.getDateField(OrderTimeCalculationFields.EFFECTIVE_DATE_TO)));
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class OperationXlsxImportService method validateProductionLine.
private void validateProductionLine(final Entity operation, final DataDefinition operationDD) {
Entity productionLine = operation.getBelongsToField(OperationFields.PRODUCTION_LINE);
Entity division = operation.getBelongsToField(OperationFields.DIVISION);
if (Objects.nonNull(productionLine)) {
if (Objects.isNull(division)) {
operation.addError(operationDD.getField(OperationFields.DIVISION), L_QCADOO_VIEW_VALIDATE_FIELD_ERROR_MISSING);
} else {
List<Entity> divisionProductionLines = division.getHasManyField(DivisionFieldsPL.PRODUCTION_LINES);
Optional<Entity> mayBeProductionLine = divisionProductionLines.stream().filter(divisionProductionLine -> divisionProductionLine.getId().equals(productionLine.getId())).findAny();
if (!mayBeProductionLine.isPresent()) {
operation.addError(operationDD.getField(OperationFields.PRODUCTION_LINE), L_QCADOO_VIEW_VALIDATE_FIELD_ERROR_CUSTOM);
}
}
}
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class TechnologyComponentsFlowServiceImpl method getComponentLocation.
@Override
public Optional<Entity> getComponentLocation(Entity technology, Entity product) {
Preconditions.checkArgument(technology != null, "Technology is required.");
Preconditions.checkArgument(technology != null, "Product is required.");
DataDefinition operationProductInComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
Entity operationProductInComponent = operationProductInComponentDD.find().createAlias(OperationProductInComponentFields.OPERATION_COMPONENT, "c", JoinType.INNER).add(belongsTo(OperationProductInComponentFields.PRODUCT, product)).add(belongsTo("c." + TechnologyOperationComponentFields.TECHNOLOGY, technology)).setMaxResults(1).uniqueResult();
if (technologyService.isIntermediateProduct(operationProductInComponent)) {
return Optional.absent();
}
return Optional.fromNullable(operationProductInComponent.getBelongsToField(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION));
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class TechnologyComponentsFlowServiceImpl method getComponentsStock.
@Override
public Map<Long, BigDecimal> getComponentsStock(Entity technology, boolean externalNumberShouldBeNull) {
Preconditions.checkArgument(technology != null, "Technology is required.");
DataDefinition operationProductInComponentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
SearchCriteriaBuilder scb = operationProductInComponentDD.find().createAlias(OperationProductInComponentFields.OPERATION_COMPONENT, "c", JoinType.INNER).createAlias(OperationProductInComponentFieldsPFTD.COMPONENTS_LOCATION, "w", JoinType.LEFT).createAlias("w." + LocationFieldsMFR.RESOURCES, "r", JoinType.LEFT).add(eqField("r." + ResourceFields.PRODUCT, OperationProductInComponentFields.PRODUCT)).add(belongsTo("c." + TechnologyOperationComponentFields.TECHNOLOGY, technology));
if (externalNumberShouldBeNull) {
scb.add(isNull("w." + LocationFields.EXTERNAL_NUMBER));
}
scb.setProjection(list().add(alias(groupField(OperationProductInComponentFields.PRODUCT), OperationProductInComponentFields.PRODUCT)).add(alias(sum("r." + ResourceFields.QUANTITY), ResourceFields.QUANTITY))).addOrder(SearchOrders.asc(ResourceFields.QUANTITY));
List<Entity> componentsStock = scb.list().getEntities();
Map<Long, BigDecimal> stockMap = Maps.newHashMap();
for (Entity componentStock : componentsStock) {
stockMap.put(componentStock.getBelongsToField(OperationProductInComponentFields.PRODUCT).getId(), componentStock.getDecimalField(ResourceFields.QUANTITY));
}
return stockMap;
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class OrderStatesListenerServicePFTD method updateDocumentQuantities.
private void updateDocumentQuantities(Entity order) {
DataDefinition ptDD = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_PRODUCTION_TRACKING);
List<Entity> productionTrackings = ptDD.find().add(SearchRestrictions.belongsTo(ProductionTrackingFields.ORDER, order)).add(SearchRestrictions.eq(ProductionTrackingFields.STATE, ProductionTrackingStateStringValues.ACCEPTED)).list().getEntities();
List<Entity> trackingOperationProductOutComponents = Lists.newArrayList();
for (Entity productionTracking : productionTrackings) {
trackingOperationProductOutComponents.addAll(Lists.newArrayList(productionTracking.getHasManyField(ProductionTrackingFields.TRACKING_OPERATION_PRODUCT_OUT_COMPONENTS)));
}
Multimap<Long, Entity> groupedRecordOutProducts = productionTrackingDocumentsHelper.fillFromBPCProductOut(trackingOperationProductOutComponents, order, true);
for (Long warehouseId : groupedRecordOutProducts.keySet()) {
Entity locationTo = getLocationDD().get(warehouseId);
List<Entity> finalProductRecord = Lists.newArrayList();
Collection<Entity> intermediateRecords = Lists.newArrayList();
for (Entity trackingOperationProductOutComponent : trackingOperationProductOutComponents) {
if (isFinalProductForOrder(order, trackingOperationProductOutComponent.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCT))) {
finalProductRecord.add(trackingOperationProductOutComponent);
} else {
intermediateRecords.add(trackingOperationProductOutComponent);
}
}
Entity existingInboundDocument = getDocumentDD().find().add(SearchRestrictions.belongsTo(DocumentFieldsPFTD.ORDER, order)).add(SearchRestrictions.belongsTo(DocumentFields.LOCATION_TO, locationTo)).add(SearchRestrictions.eq(DocumentFields.STATE, DocumentState.DRAFT.getStringValue())).add(SearchRestrictions.eq(DocumentFields.TYPE, DocumentType.INTERNAL_INBOUND.getStringValue())).setMaxResults(1).uniqueResult();
if (Objects.nonNull(existingInboundDocument)) {
if (Objects.nonNull(finalProductRecord)) {
productionTrackingListenerServicePFTD.updateInternalInboundDocumentForFinalProducts(order, existingInboundDocument, finalProductRecord, true, true);
} else {
productionTrackingListenerServicePFTD.updateInternalInboundDocumentForFinalProducts(order, existingInboundDocument, intermediateRecords, false, true);
}
}
}
}
Aggregations