Search in sources :

Example 1 with DailyProgressKey

use of com.qcadoo.mes.productionPerShift.domain.DailyProgressKey in project mes by qcadoo.

the class DailyProgressService method getDailyProgressesWithTrackingRecords.

/**
 * Creates map of daily progresses with accepted production tracking records only, and fills keys with quantity produced in
 * that record
 *
 * @param pps
 * @return
 */
public Map<DailyProgressKey, Entity> getDailyProgressesWithTrackingRecords(final Entity pps) {
    Map<DailyProgressKey, Entity> dailyProgresses = Maps.newHashMap();
    Entity order = pps.getBelongsToField(ProductionPerShiftFields.ORDER);
    Entity product = order.getBelongsToField(OrderFields.PRODUCT);
    String typeOfProductionRecording = order.getStringField(OrderFieldsPC.TYPE_OF_PRODUCTION_RECORDING);
    Entity toc = null;
    if (TypeOfProductionRecording.FOR_EACH.getStringValue().equals(typeOfProductionRecording)) {
        Entity technology = order.getBelongsToField(OrderFields.TECHNOLOGY);
        EntityTree operationsTree = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);
        toc = operationsTree.getRoot();
    }
    List<Entity> mainOutProductComponents = getMainOutProductComponentsForOrderAndProduct(order, toc, product);
    for (Entity outProduct : mainOutProductComponents) {
        Entity trackingRecord = outProduct.getBelongsToField(TrackingOperationProductOutComponentFields.PRODUCTION_TRACKING);
        Long shiftId = trackingRecord.getBelongsToField(ProductionTrackingFields.SHIFT).getId();
        Date startDate = trackingRecord.getDateField(ProductionTrackingFields.SHIFT_START_DAY);
        Optional<Entity> dailyProgress = findDailyProgress(pps, shiftId, startDate);
        DailyProgressKey key = new DailyProgressKey(outProduct.getDecimalField(TrackingOperationProductOutComponentFields.USED_QUANTITY), shiftId, startDate);
        if (dailyProgress.isPresent()) {
            Entity entity = dailyProgress.get();
            entity.setField(DailyProgressFields.QUANTITY, key.getQuantity());
            dailyProgresses.put(key, entity);
        }
    }
    return dailyProgresses;
}
Also used : Entity(com.qcadoo.model.api.Entity) DailyProgressKey(com.qcadoo.mes.productionPerShift.domain.DailyProgressKey) EntityTree(com.qcadoo.model.api.EntityTree) Date(java.util.Date)

Example 2 with DailyProgressKey

use of com.qcadoo.mes.productionPerShift.domain.DailyProgressKey in project mes by qcadoo.

the class PpsBaseAlgorithmService method calculateRegisteredQuantity.

private BigDecimal calculateRegisteredQuantity(final ProgressForDaysContainer progressForDaysContainer, final Entity order, final Entity pps, BigDecimal plannedQuantity) {
    BigDecimal alreadyRegisteredQuantity = progressForDaysContainer.getAlreadyRegisteredQuantity();
    if (pps != null) {
        dailyProgressesWithTrackingRecords = dailyProgressService.getDailyProgressesWithTrackingRecords(pps);
        for (Map.Entry<DailyProgressKey, Entity> entry : dailyProgressesWithTrackingRecords.entrySet()) {
            alreadyRegisteredQuantity = alreadyRegisteredQuantity.add(entry.getKey().getQuantity());
        }
        progressForDaysContainer.setAlreadyRegisteredQuantity(alreadyRegisteredQuantity);
    } else {
        dailyProgressesWithTrackingRecords = null;
    }
    progressForDaysContainer.setPlannedQuantity(plannedQuantity.subtract(alreadyRegisteredQuantity, numberService.getMathContext()));
    return progressForDaysContainer.getPlannedQuantity();
}
Also used : Entity(com.qcadoo.model.api.Entity) DailyProgressKey(com.qcadoo.mes.productionPerShift.domain.DailyProgressKey) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 3 with DailyProgressKey

use of com.qcadoo.mes.productionPerShift.domain.DailyProgressKey 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)

Aggregations

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