use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class UsedBatchHooks method onSave.
public void onSave(final DataDefinition usedBatchDD, final Entity usedBatch) {
Entity trackingOperationProductInComponent = usedBatch.getBelongsToField(UsedBatchFields.TRACKING_OPERATION_PRODUCT_IN_COMPONENT);
List<Entity> usedBathes = trackingOperationProductInComponent.getHasManyField(TrackingOperationProductInComponentFields.USED_BATCHES);
if (Objects.nonNull(usedBatch.getId())) {
usedBathes = usedBathes.stream().filter(entity -> !entity.getId().equals(usedBatch.getId())).collect(Collectors.toList());
}
BigDecimal sumUsedBatchesQuantity = usedBathes.stream().map(ub -> ub.getDecimalField(UsedBatchFields.QUANTITY)).reduce(BigDecimal.ZERO, BigDecimal::add);
sumUsedBatchesQuantity = sumUsedBatchesQuantity.add(usedBatch.getDecimalField(UsedBatchFields.QUANTITY));
trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.USED_QUANTITY, sumUsedBatchesQuantity);
Optional<BigDecimal> givenQuantity = productionTrackingService.calculateGivenQuantity(trackingOperationProductInComponent, sumUsedBatchesQuantity);
givenQuantity.ifPresent(gq -> trackingOperationProductInComponent.setField(TrackingOperationProductInComponentFields.GIVEN_QUANTITY, gq));
Entity trackingOperationProductInComponentDb = trackingOperationProductInComponent.getDataDefinition().save(trackingOperationProductInComponent);
if (!trackingOperationProductInComponentDb.isValid()) {
usedBatch.addGlobalError("productionCounting.usedBatch.error.sumUsedBatchesQuantityToBig", false);
}
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class AnomalyExplanationDetailsListeners method onRemoveSelectedEntity.
public void onRemoveSelectedEntity(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent anomalyExplanationsGrid = (GridComponent) view.getComponentByReference("anomalyExplanations");
DataDefinition dataDefinition = dataDefinitionService.get(ProductionCountingConstants.PLUGIN_IDENTIFIER, ProductionCountingConstants.MODEL_ANOMALY_EXPLANATION);
dataDefinition.delete(toArray(anomalyExplanationsGrid.getSelectedEntitiesIds(), Long.class));
FormComponent documentForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
documentForm.performEvent(view, "reset");
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class AnomalyListListeners method completeWithoutIssue.
public void completeWithoutIssue(final ViewDefinitionState view, final ComponentState state, final String[] args) {
GridComponent gridComponent = (GridComponent) view.getComponentByReference(QcadooViewConstants.L_GRID);
for (Long anomalyId : gridComponent.getSelectedEntitiesIds()) {
DataDefinition anomalyDD = getAnomalyDD();
Entity anomaly = anomalyDD.get(anomalyId);
anomaly.setField(AnomalyFields.STATE, AnomalyFields.State.COMPLETED);
anomaly.setField(AnomalyFields.ISSUED, false);
anomalyDD.save(anomaly);
}
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class PPSHelper method getPpsIdForOrder.
public Long getPpsIdForOrder(final Long orderId) {
DataDefinition ppsDateDef = getProductionPerShiftDD();
String query = "select id as ppsId from #productionPerShift_productionPerShift where order.id = :orderId";
Entity projectionResults = ppsDateDef.find(query).setLong("orderId", orderId).setMaxResults(1).uniqueResult();
if (projectionResults == null) {
return null;
}
return (Long) projectionResults.getField("ppsId");
}
use of com.qcadoo.model.api.DataDefinition in project mes by qcadoo.
the class PPSHelper method createPpsForOrderAndReturnId.
public Long createPpsForOrderAndReturnId(final Long orderId) {
DataDefinition productionPerShiftDD = getProductionPerShiftDD();
Entity productionPerShift = productionPerShiftDD.create();
productionPerShift.setField(ProductionPerShiftFields.ORDER, orderId);
productionPerShift.setField(ProductionPerShiftFields.PLANNED_PROGRESS_TYPE, ProgressType.PLANNED.getStringValue());
return productionPerShiftDD.save(productionPerShift).getId();
}
Aggregations