Search in sources :

Example 1 with ShiftEfficiencyCalculationHolder

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;
}
Also used : ShiftEfficiencyCalculationHolder(com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder) ErrorMessage(com.qcadoo.model.api.validators.ErrorMessage) BigDecimal(java.math.BigDecimal)

Example 2 with ShiftEfficiencyCalculationHolder

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;
}
Also used : Shift(com.qcadoo.mes.basic.shift.Shift) ShiftEfficiencyCalculationHolder(com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder) Entity(com.qcadoo.model.api.Entity) DailyProgressKey(com.qcadoo.mes.productionPerShift.domain.DailyProgressKey) DateTimeRange(com.qcadoo.mes.basic.util.DateTimeRange) DailyProgressContainer(com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer) BigDecimal(java.math.BigDecimal) DateTime(org.joda.time.DateTime)

Example 3 with ShiftEfficiencyCalculationHolder

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;
}
Also used : ShiftEfficiencyCalculationHolder(com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder) BigDecimal(java.math.BigDecimal)

Aggregations

ShiftEfficiencyCalculationHolder (com.qcadoo.mes.productionPerShift.domain.ShiftEfficiencyCalculationHolder)3 BigDecimal (java.math.BigDecimal)3 Shift (com.qcadoo.mes.basic.shift.Shift)1 DateTimeRange (com.qcadoo.mes.basic.util.DateTimeRange)1 DailyProgressContainer (com.qcadoo.mes.productionPerShift.domain.DailyProgressContainer)1 DailyProgressKey (com.qcadoo.mes.productionPerShift.domain.DailyProgressKey)1 Entity (com.qcadoo.model.api.Entity)1 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)1 DateTime (org.joda.time.DateTime)1