use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.
the class ProductionPerShiftListeners method showNotifications.
private void showNotifications(final ViewDefinitionState view) {
FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity pps = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
for (Entity order : getEntityFromLookup(view, ORDER_LOOKUP_REF).asSet()) {
progressQuantitiesDeviationNotifier.compareAndNotify(view, pps, detailsHooks.isCorrectedPlan(view));
for (OrderDates orderDates : OrderDates.of(order).map(Collections::singleton).orElse(Collections.emptySet())) {
nonWorkingShiftsNotifier.checkAndNotify(view, orderDates.getStart().effectiveWithFallback(), pps, detailsHooks.resolveProgressType(view));
}
}
}
use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.
the class OrderDetailsHooksPPS method checkOrderDates.
private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
if (order.getId() == null) {
return;
}
Entity pps = productionPerShiftDataProvider.getProductionPerShiftDD().find().add(SearchRestrictions.belongsTo("order", OrdersConstants.PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER, order.getId())).setMaxResults(1).uniqueResult();
if (pps != null) {
boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(pps, shouldBeCorrected);
DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
Optional<OrderDates> maybeOrderDates;
try {
maybeOrderDates = OrderDates.of(order);
} catch (IllegalArgumentException e) {
return;
}
DataDefinition orderDD = order.getDataDefinition();
Entity dbOrder = orderDD.get(order.getId());
boolean areDatesCorrect = true;
if (maybeOrderDates.isPresent()) {
OrderDates orderDates = maybeOrderDates.get();
Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
Date orderEnd = orderDates.getEnd().effectiveWithFallback().toDate();
Date ppsFinishDate = null;
for (Long id : progressForDayIds) {
Entity progressForDay = progressForDayDD.get(id);
Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
if (progressDate == null) {
progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
}
EntityList dailyProgresses = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS);
for (Entity dailyProgress : dailyProgresses) {
Date shiftFinishDate = ppsTimeHelper.findFinishDate(dailyProgress, progressDate, dbOrder);
if (shiftFinishDate == null) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
return;
}
if (ppsFinishDate == null || ppsFinishDate.before(shiftFinishDate)) {
ppsFinishDate = shiftFinishDate;
}
if (shiftFinishDate.before(orderStart)) {
areDatesCorrect = false;
}
}
}
if (ppsFinishDate != null) {
if (ppsFinishDate.after(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooLate", MessageType.INFO, false);
} else if (ppsFinishDate.before(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooEarly", MessageType.INFO, false);
}
}
}
if (!areDatesCorrect) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
}
}
}
use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.
the class ProductionPerShiftDetailsHooks method checkOrderDates.
private void checkOrderDates(final ViewDefinitionState view, final Entity order) {
FormComponent productionPerShiftForm = (FormComponent) view.getComponentByReference(QcadooViewConstants.L_FORM);
Entity pps = productionPerShiftForm.getPersistedEntityWithIncludedFormValues();
boolean shouldBeCorrected = OrderState.of(order).compareTo(OrderState.PENDING) != 0;
Set<Long> progressForDayIds = productionPerShiftDataProvider.findIdsOfEffectiveProgressForDay(pps, shouldBeCorrected);
DataDefinition progressForDayDD = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PROGRESS_FOR_DAY);
java.util.Optional<OrderDates> maybeOrderDates = OrderDates.of(order);
DataDefinition orderDD = order.getDataDefinition();
Entity dbOrder = orderDD.get(order.getId());
boolean areDatesCorrect = true;
if (maybeOrderDates.isPresent()) {
OrderDates orderDates = maybeOrderDates.get();
Date orderStart = removeTime(orderDates.getStart().effectiveWithFallback().toDate());
Date orderEnd = orderDates.getEnd().effectiveWithFallback().toDate();
Date ppsFinishDate = null;
for (Long id : progressForDayIds) {
Entity progressForDay = progressForDayDD.get(id);
Date progressDate = progressForDay.getDateField(ProgressForDayFields.ACTUAL_DATE_OF_DAY);
if (progressDate == null) {
progressDate = progressForDay.getDateField(ProgressForDayFields.DATE_OF_DAY);
}
EntityList dailyProgresses = progressForDay.getHasManyField(ProgressForDayFields.DAILY_PROGRESS);
for (Entity dailyProgress : dailyProgresses) {
Date shiftFinishDate = ppsTimeHelper.findFinishDate(dailyProgress, progressDate, dbOrder);
if (shiftFinishDate == null) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
return;
}
if (ppsFinishDate == null || ppsFinishDate.before(shiftFinishDate)) {
ppsFinishDate = shiftFinishDate;
}
if (shiftFinishDate.before(orderStart)) {
areDatesCorrect = false;
}
}
}
if (ppsFinishDate != null) {
if (ppsFinishDate.after(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooLate", MessageType.INFO, false);
} else if (ppsFinishDate.before(orderEnd)) {
view.addMessage("productionPerShift.info.endDateTooEarly", MessageType.INFO, false);
}
}
}
if (!areDatesCorrect) {
view.addMessage("productionPerShift.info.invalidStartDate", MessageType.INFO, false);
}
}
use of com.qcadoo.mes.orders.dates.OrderDates in project mes by qcadoo.
the class ProductionPerShiftListeners method updateProgressForDays.
public void updateProgressForDays(final ViewDefinitionState view, final ComponentState state, final String[] args) {
ProgressType progressType = detailsHooks.resolveProgressType(view);
Entity order = getEntityFromLookup(view, ORDER_LOOKUP_REF).get();
Optional<OrderDates> maybeOrderDates = resolveOrderDates(order);
if (!maybeOrderDates.isPresent()) {
return;
}
int lastDay = -1;
List<Shift> shifts = shiftsService.findAll(order.getBelongsToField(OrderFields.PRODUCTION_LINE));
LazyStream<OrderRealizationDay> realizationDaysStream = orderRealizationDaysResolver.asStreamFrom(progressType.extractStartDateTimeFrom(maybeOrderDates.get()), shifts);
AwesomeDynamicListComponent progressForDaysADL = (AwesomeDynamicListComponent) view.getComponentByReference(PROGRESS_ADL_REF);
for (FormComponent progressForDayForm : progressForDaysADL.getFormComponents()) {
FieldComponent dayField = progressForDayForm.findFieldComponentByName(DAY_NUMBER_INPUT_REF);
Integer dayNum = IntegerUtils.parse((String) dayField.getFieldValue());
if (dayNum == null) {
final int maxDayNum = lastDay;
if (realizationDaysStream != null) {
realizationDaysStream = realizationDaysStream.dropWhile(new Predicate<OrderRealizationDay>() {
@Override
public boolean apply(final OrderRealizationDay input) {
return input.getRealizationDayNumber() > maxDayNum;
}
});
OrderRealizationDay realizationDay = realizationDaysStream.head();
setUpProgressForDayRow(progressForDayForm, realizationDay);
lastDay = realizationDay.getRealizationDayNumber();
}
} else {
lastDay = dayNum;
}
}
}
Aggregations