Search in sources :

Example 1 with OperationOrderRepository

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

the class OperationOrderServiceImpl method chargeByMachineHours.

public List<Map<String, Object>> chargeByMachineHours(LocalDateTime fromDateTime, LocalDateTime toDateTime) throws AxelorException {
    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
    LocalDateTime itDateTime = LocalDateTime.parse(fromDateTime.toString(), DateTimeFormatter.ISO_DATE_TIME);
    OperationOrderRepository operationOrderRepo = Beans.get(OperationOrderRepository.class);
    if (Duration.between(fromDateTime, toDateTime).toDays() > 20) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS));
    }
    List<OperationOrder> operationOrderListTemp = operationOrderRepo.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 = operationOrderRepo.all().filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)).fetch();
        Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
        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;
                }
                BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)).divide(new BigDecimal(60), 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)) {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                dataMap.put("dateTime", (Object) itDateTime.format(DATE_TIME_FORMAT));
                dataMap.put("charge", (Object) map.get(key));
                dataMap.put("machine", (Object) key);
                dataList.add(dataMap);
            } else {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                dataMap.put("dateTime", (Object) itDateTime.format(DATE_TIME_FORMAT));
                dataMap.put("charge", (Object) BigDecimal.ZERO);
                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) BigDecimal(java.math.BigDecimal) 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 2 with OperationOrderRepository

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

the class OperationOrderController method machineChange.

public void machineChange(ActionRequest request, ActionResponse response) {
    try {
        OperationOrder operationOrder = request.getContext().asType(OperationOrder.class);
        OperationOrderRepository operationOrderRepo = Beans.get(OperationOrderRepository.class);
        OperationOrderWorkflowService operationOrderWorkflowService = Beans.get(OperationOrderWorkflowService.class);
        operationOrder = operationOrderRepo.find(operationOrder.getId());
        if (operationOrder != null && operationOrder.getStatusSelect() == OperationOrderRepository.STATUS_PLANNED) {
            operationOrder = operationOrderWorkflowService.replan(operationOrder);
            List<OperationOrder> operationOrderList = operationOrderRepo.all().filter("self.manufOrder = ?1 AND self.priority >= ?2 AND self.statusSelect = 3 AND self.id != ?3", operationOrder.getManufOrder(), operationOrder.getPriority(), operationOrder.getId()).order("priority").order("plannedEndDateT").fetch();
            for (OperationOrder operationOrderIt : operationOrderList) {
                operationOrderWorkflowService.replan(operationOrderIt);
            }
            response.setReload(true);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : OperationOrderWorkflowService(com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService) OperationOrderRepository(com.axelor.apps.production.db.repo.OperationOrderRepository) 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)2 OperationOrderRepository (com.axelor.apps.production.db.repo.OperationOrderRepository)2 OperationOrderWorkflowService (com.axelor.apps.production.service.operationorder.OperationOrderWorkflowService)1 AxelorException (com.axelor.exception.AxelorException)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BirtException (org.eclipse.birt.core.exception.BirtException)1