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;
}
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);
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations