use of com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer 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.productionPerShift.domain.DailyProgressContainer 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;
}
Aggregations