use of com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder in project mes by qcadoo.
the class PpsTechNormAndWorkersAlgorithmService method calculateShiftEfficiency.
@Override
protected ShiftEfficiencyCalculationHolder calculateShiftEfficiency(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift, Shift shift, Entity order, DateTimeRange range, BigDecimal shiftEfficiency, int progressForDayQuantity, boolean allowIncompleteUnits) {
ShiftEfficiencyCalculationHolder calculationHolder = new ShiftEfficiencyCalculationHolder();
int workersOnLine = workersOnLineService.getWorkersOnLine(order.getBelongsToField(OrderFields.PRODUCTION_LINE), shift.getEntity(), range.getFrom());
if (workersOnLine == 0) {
progressForDaysContainer.addError(new ErrorMessage("productionPerShift.automaticAlgorithm.noAssignmentForShift", false, order.getBelongsToField(OrderFields.PRODUCTION_LINE).getStringField(ProductionLineFields.NUMBER)));
throw new IllegalStateException("No assignment for shift");
}
BigDecimal scaledNorm = getStandardPerformanceNorm(progressForDaysContainer, order);
Long minuets = range.durationInMins();
BigDecimal efficiencyForRange = calculateEfficiencyForRange(scaledNorm, workersOnLine, minuets, allowIncompleteUnits);
shiftEfficiency = shiftEfficiency.add(efficiencyForRange, numberService.getMathContext());
calculationHolder.setShiftEfficiency(shiftEfficiency);
if (shiftEfficiency.compareTo(progressForDaysContainer.getPlannedQuantity()) > 0) {
calculateEfficiencyTime(calculationHolder, progressForDaysContainer.getPlannedQuantity(), workersOnLine, scaledNorm);
} else {
calculateEfficiencyTime(calculationHolder, shiftEfficiency, workersOnLine, scaledNorm);
}
return calculationHolder;
}
use of com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder 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.productionPerShift.domain.ShiftEfficiencyCalculationHolder in project mes by qcadoo.
the class PpsTechNormAlgorithmService method calculateShiftEfficiency.
@Override
protected ShiftEfficiencyCalculationHolder calculateShiftEfficiency(ProgressForDaysContainer progressForDaysContainer, Entity productionPerShift, Shift shift, Entity order, DateTimeRange range, BigDecimal shiftEfficiency, int progressForDayQuantity, boolean allowIncompleteUnits) {
ShiftEfficiencyCalculationHolder calculationHolder = new ShiftEfficiencyCalculationHolder();
BigDecimal scaledNorm = getStandardPerformanceNorm(progressForDaysContainer, order);
long minutes = range.durationInMins();
BigDecimal efficiencyForRange = calculateEfficiencyForRange(scaledNorm, minutes, allowIncompleteUnits);
shiftEfficiency = shiftEfficiency.add(efficiencyForRange, numberService.getMathContext());
calculationHolder.setShiftEfficiency(shiftEfficiency);
if (shiftEfficiency.compareTo(progressForDaysContainer.getPlannedQuantity()) > 0) {
calculateEfficiencyTime(calculationHolder, progressForDaysContainer.getPlannedQuantity(), scaledNorm);
} else {
calculateEfficiencyTime(calculationHolder, shiftEfficiency, scaledNorm);
}
return calculationHolder;
}
Aggregations