use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class OrderRealizationDaysResolverTest method shouldResolveRealizationDay4.
@Test
public final void shouldResolveRealizationDay4() {
// given
DateTime startDate = new DateTime(2014, 8, 14, 3, 0, 0);
List<Shift> shifts = ImmutableList.of(shift1, shift2, shift3);
// when
// - 3rd order realization day is Saturday,
// - shift working at given time doesn't work at this date but it's not a first day of order realization,
OrderRealizationDay realizationDay = orderRealizationDaysResolver.find(startDate, 3, false, shifts);
// then
assertRealizationDayState(realizationDay, 5, startDate.toLocalDate().plusDays(4), shifts);
}
use of com.qcadoo.mes.basic.shift.Shift 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);
}
use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class PpsBaseAlgorithmService method fillDailyProgressWithShifts.
private DailyProgressContainer fillDailyProgressWithShifts(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift, Entity order, List<Shift> shifts, DateTime dateOfDay, Date orderStartDate, boolean shouldBeCorrected, int progressForDayQuantity, BigDecimal alreadyPlannedQuantity, boolean allowIncompleteUnits) {
DailyProgressContainer dailyProgressContainer = new DailyProgressContainer();
List<Entity> dailyProgressWithShifts = Lists.newLinkedList();
for (Shift shift : shifts) {
Entity dailyProgress = null;
if (dailyProgressesWithTrackingRecords != null) {
DailyProgressKey key = new DailyProgressKey(shift.getId(), dateOfDay);
dailyProgress = dailyProgressesWithTrackingRecords.get(key);
}
if (dailyProgress != null) {
BigDecimal producedQuantity = dailyProgress.getDecimalField(DailyProgressFields.QUANTITY);
progressForDaysContainer.setAlreadyRegisteredQuantity(progressForDaysContainer.getAlreadyRegisteredQuantity().subtract(producedQuantity, numberService.getMathContext()));
if (shouldBeCorrected) {
dailyProgress = dailyProgress.copy();
dailyProgress.setId(null);
}
dailyProgressWithShifts.add(dailyProgress);
} else if (progressForDaysContainer.getPlannedQuantity().compareTo(BigDecimal.ZERO) > 0) {
dailyProgress = dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_DAILY_PROGRESS).create();
dailyProgress.setField(DailyProgressFields.SHIFT, shift.getEntity());
DateTime orderStartDateDT = new DateTime(orderStartDate, DateTimeZone.getDefault());
BigDecimal shiftEfficiency = BigDecimal.ZERO;
int time = 0;
for (DateTimeRange range : shiftExceptionService.getShiftWorkDateTimes(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift, dateOfDay, true)) {
if (orderStartDate.after(dateOfDay.toDate())) {
range = range.trimBefore(orderStartDateDT);
}
if (range != null) {
ShiftEfficiencyCalculationHolder calculationHolder = calculateShiftEfficiency(progressForDaysContainer, productionPerShift, shift, order, range, shiftEfficiency, progressForDayQuantity, allowIncompleteUnits);
shiftEfficiency = calculationHolder.getShiftEfficiency();
time = time + calculationHolder.getEfficiencyTime();
}
}
if (shiftEfficiency.compareTo(progressForDaysContainer.getPlannedQuantity()) > 0) {
shiftEfficiency = progressForDaysContainer.getPlannedQuantity();
progressForDaysContainer.setPlannedQuantity(BigDecimal.ZERO);
} else {
alreadyPlannedQuantity = alreadyPlannedQuantity.add(shiftEfficiency, numberService.getMathContext());
progressForDaysContainer.setPlannedQuantity(progressForDaysContainer.getPlannedQuantity().subtract(shiftEfficiency, numberService.getMathContext()));
}
if (shiftEfficiency.compareTo(BigDecimal.ZERO) != 0) {
dailyProgress.setField(DailyProgressFields.QUANTITY, numberService.setScaleWithDefaultMathContext(shiftEfficiency));
dailyProgress.setField(DailyProgressFields.EFFICIENCY_TIME, time);
dailyProgressWithShifts.add(dailyProgress);
}
}
}
dailyProgressContainer.setDailyProgress(dailyProgressWithShifts);
return dailyProgressContainer;
}
use of com.qcadoo.mes.basic.shift.Shift 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;
}
}
}
use of com.qcadoo.mes.basic.shift.Shift in project mes by qcadoo.
the class PPSReportXlsHelper method getProductionPerShiftForReport.
public List<Entity> getProductionPerShiftForReport(final Entity goodFoodReport) {
List<Entity> shifts = shiftsService.getShifts();
DateTime dateFrom = new DateTime(goodFoodReport.getDateField(PPSReportFields.DATE_FROM));
Shift shiftFirst = new Shift(shifts.get(0), dateFrom, false);
List<TimeRange> ranges = shiftFirst.findWorkTimeAt(dateFrom.toLocalDate());
LocalTime startTime = ranges.get(0).getFrom();
DateTime firstStartShitTime = dateFrom;
firstStartShitTime = firstStartShitTime.withHourOfDay(startTime.getHourOfDay());
firstStartShitTime = firstStartShitTime.withMinuteOfHour(startTime.getMinuteOfHour());
long dateToInMills = getDateToInMills(goodFoodReport, shifts);
String sql = "select pps from #productionPerShift_productionPerShift as pps where (" + "(" + "('" + firstStartShitTime.toDate().toString() + "' <= pps.order.finishDate and '" + firstStartShitTime.toDate().toString() + "' >= pps.order.startDate) or " + "('" + new Date(dateToInMills).toString().toString() + "' < pps.order.finishDate and '" + new Date(dateToInMills).toString().toString() + "' > pps.order.startDate)" + ") or " + "(" + "(pps.order.startDate >= '" + firstStartShitTime.toDate().toString() + "' and pps.order.startDate <'" + new Date(dateToInMills).toString().toString() + "') or " + "(pps.order.finishDate >= '" + firstStartShitTime.toDate().toString() + "' and pps.order.finishDate < '" + new Date(dateToInMills).toString().toString() + "') " + ")" + ") and pps.order.state <> '05declined' and pps.order.state <> '07abandoned' " + "and pps.order.state <> '04completed' and pps.order.active = true";
return dataDefinitionService.get(ProductionPerShiftConstants.PLUGIN_IDENTIFIER, ProductionPerShiftConstants.MODEL_PRODUCTION_PER_SHIFT).find(sql).list().getEntities();
}
Aggregations