Search in sources :

Example 11 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class OperationOrderServiceImpl method chargeByMachineDays.

public List<Map<String, Object>> chargeByMachineDays(LocalDateTime fromDateTime, LocalDateTime toDateTime) throws AxelorException {
    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
    fromDateTime = fromDateTime.withHour(0).withMinute(0);
    toDateTime = toDateTime.withHour(23).withMinute(59);
    LocalDateTime itDateTime = LocalDateTime.parse(fromDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME);
    if (Duration.between(fromDateTime, toDateTime).toDays() > 500) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS));
    }
    List<OperationOrder> operationOrderListTemp = Beans.get(OperationOrderRepository.class).all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime).fetch();
    Set<String> machineNameList = new HashSet<String>();
    for (OperationOrder operationOrder : operationOrderListTemp) {
        if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
            if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) {
                machineNameList.add(operationOrder.getWorkCenter().getMachine().getName());
            }
        }
    }
    while (!itDateTime.isAfter(toDateTime)) {
        List<OperationOrder> operationOrderList = Beans.get(OperationOrderRepository.class).all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)).fetch();
        Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
        WeeklyPlanningService weeklyPlanningService = Beans.get(WeeklyPlanningService.class);
        for (OperationOrder operationOrder : operationOrderList) {
            if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
                String machine = operationOrder.getWorkCenter().getMachine().getName();
                long numberOfMinutes = 0;
                if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) {
                    numberOfMinutes = Duration.between(itDateTime, operationOrder.getPlannedEndDateT()).toMinutes();
                } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) {
                    numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)).toMinutes();
                } else {
                    numberOfMinutes = Duration.between(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).toMinutes();
                }
                if (numberOfMinutes > 60) {
                    numberOfMinutes = 60;
                }
                long numberOfMinutesPerDay = 0;
                if (operationOrder.getWorkCenter().getMachine().getWeeklyPlanning() != null) {
                    DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(operationOrder.getWorkCenter().getMachine().getWeeklyPlanning(), LocalDateTime.parse(itDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME).toLocalDate());
                    if (dayPlanning != null) {
                        if (dayPlanning.getMorningFrom() != null && dayPlanning.getMorningTo() != null) {
                            numberOfMinutesPerDay = Duration.between(dayPlanning.getMorningFrom(), dayPlanning.getMorningTo()).toMinutes();
                        }
                        if (dayPlanning.getAfternoonFrom() != null && dayPlanning.getAfternoonTo() != null) {
                            numberOfMinutesPerDay += Duration.between(dayPlanning.getAfternoonFrom(), dayPlanning.getAfternoonTo()).toMinutes();
                        }
                        if (dayPlanning.getMorningFrom() != null && dayPlanning.getMorningTo() == null && dayPlanning.getAfternoonFrom() == null && dayPlanning.getAfternoonTo() != null) {
                            numberOfMinutesPerDay += Duration.between(dayPlanning.getMorningFrom(), dayPlanning.getAfternoonTo()).toMinutes();
                        }
                    } else {
                        numberOfMinutesPerDay = 0;
                    }
                } else {
                    numberOfMinutesPerDay = 60 * 24;
                }
                if (numberOfMinutesPerDay != 0) {
                    BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)).divide(new BigDecimal(numberOfMinutesPerDay), 2, RoundingMode.HALF_UP);
                    if (map.containsKey(machine)) {
                        map.put(machine, map.get(machine).add(percentage));
                    } else {
                        map.put(machine, percentage);
                    }
                }
            }
        }
        Set<String> keyList = map.keySet();
        for (String key : machineNameList) {
            if (keyList.contains(key)) {
                int found = 0;
                for (Map<String, Object> mapIt : dataList) {
                    if (mapIt.get("dateTime").equals((Object) itDateTime.format(DATE_FORMAT)) && mapIt.get("machine").equals((Object) key)) {
                        mapIt.put("charge", new BigDecimal(mapIt.get("charge").toString()).add(map.get(key)));
                        found = 1;
                        break;
                    }
                }
                if (found == 0) {
                    Map<String, Object> dataMap = new HashMap<String, Object>();
                    dataMap.put("dateTime", (Object) itDateTime.format(DATE_FORMAT));
                    dataMap.put("charge", (Object) map.get(key));
                    dataMap.put("machine", (Object) key);
                    dataList.add(dataMap);
                }
            }
        }
        itDateTime = itDateTime.plusHours(1);
    }
    return dataList;
}
Also used : LocalDateTime(java.time.LocalDateTime) AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DayPlanning(com.axelor.apps.base.db.DayPlanning) BigDecimal(java.math.BigDecimal) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) HashMap(java.util.HashMap) Map(java.util.Map) OperationOrder(com.axelor.apps.production.db.OperationOrder) HashSet(java.util.HashSet)

Example 12 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class ManufOrderServiceImpl method updateRealQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateRealQty(ManufOrder manufOrder, BigDecimal qtyToUpdate) throws AxelorException {
    ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
    if (!manufOrder.getIsConsProOnOperation()) {
        manufOrderStockMoveService.createNewConsumedStockMoveLineList(manufOrder, qtyToUpdate);
        updateDiffProdProductList(manufOrder);
    } else {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            Beans.get(OperationOrderStockMoveService.class).createNewConsumedStockMoveLineList(operationOrder, qtyToUpdate);
            Beans.get(OperationOrderService.class).updateDiffProdProductList(operationOrder);
        }
    }
    manufOrderStockMoveService.createNewProducedStockMoveLineList(manufOrder, qtyToUpdate);
}
Also used : OperationOrderService(com.axelor.apps.production.service.operationorder.OperationOrderService) OperationOrder(com.axelor.apps.production.db.OperationOrder) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) Transactional(com.google.inject.persist.Transactional)

Example 13 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class CostSheetServiceImpl method computeRealProcess.

protected void computeRealProcess(List<OperationOrder> operationOrders, Unit pieceUnit, BigDecimal producedQty, int bomLevel, CostSheetLine parentCostSheetLine, LocalDate previousCostSheetDate) throws AxelorException {
    for (OperationOrder operationOrder : operationOrders) {
        WorkCenter workCenter = operationOrder.getWorkCenter();
        if (workCenter == null) {
            continue;
        }
        int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
        if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_HUMAN || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
            this.computeRealHumanResourceCost(operationOrder, operationOrder.getPriority(), bomLevel, parentCostSheetLine, previousCostSheetDate);
        }
        if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
            this.computeRealMachineCost(operationOrder, workCenter, producedQty, pieceUnit, bomLevel, parentCostSheetLine, previousCostSheetDate);
        }
    }
}
Also used : WorkCenter(com.axelor.apps.production.db.WorkCenter) OperationOrder(com.axelor.apps.production.db.OperationOrder)

Example 14 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class OperationOrderController method finish.

public void finish(ActionRequest request, ActionResponse response) {
    try {
        OperationOrder operationOrder = request.getContext().asType(OperationOrder.class);
        // this attribute is not in the database, only in the view
        LocalDateTime realStartDateT = operationOrder.getRealStartDateT();
        operationOrder = Beans.get(OperationOrderRepository.class).find(operationOrder.getId());
        operationOrder.setRealStartDateT(realStartDateT);
        Beans.get(OperationOrderWorkflowService.class).finishAndAllOpFinished(operationOrder);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) OperationOrderWorkflowService(com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService) OperationOrder(com.axelor.apps.production.db.OperationOrder) BirtException(org.eclipse.birt.core.exception.BirtException) IOException(java.io.IOException)

Example 15 with OperationOrder

use of com.axelor.apps.production.db.OperationOrder in project axelor-open-suite by axelor.

the class OperationOrderController method cancel.

public void cancel(ActionRequest request, ActionResponse response) {
    try {
        OperationOrder operationOrder = request.getContext().asType(OperationOrder.class);
        Beans.get(OperationOrderWorkflowService.class).cancel(Beans.get(OperationOrderRepository.class).find(operationOrder.getId()));
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : OperationOrderWorkflowService(com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService) OperationOrder(com.axelor.apps.production.db.OperationOrder) BirtException(org.eclipse.birt.core.exception.BirtException) IOException(java.io.IOException)

Aggregations

OperationOrder (com.axelor.apps.production.db.OperationOrder)44 Transactional (com.google.inject.persist.Transactional)24 IOException (java.io.IOException)12 BirtException (org.eclipse.birt.core.exception.BirtException)11 OperationOrderWorkflowService (com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService)10 AxelorException (com.axelor.exception.AxelorException)9 BigDecimal (java.math.BigDecimal)9 OperationOrderRepository (com.axelor.apps.production.db.repo.OperationOrderRepository)8 AppProductionService (com.axelor.apps.production.service.app.AppProductionService)7 LocalDateTime (java.time.LocalDateTime)7 ArrayList (java.util.ArrayList)6 ManufOrder (com.axelor.apps.production.db.ManufOrder)5 Company (com.axelor.apps.base.db.Company)4 ProdProduct (com.axelor.apps.production.db.ProdProduct)4 StockMove (com.axelor.apps.stock.db.StockMove)4 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)4 DayPlanning (com.axelor.apps.base.db.DayPlanning)3 ProdProcessLine (com.axelor.apps.production.db.ProdProcessLine)3 ManufOrderStockMoveService (com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService)3 ProductionOrderService (com.axelor.apps.production.service.productionorder.ProductionOrderService)3