use of com.axelor.apps.production.db.WorkCenter in project axelor-open-suite by axelor.
the class ProdProcessLineController method updateCapacitySettings.
public void updateCapacitySettings(ActionRequest request, ActionResponse response) {
try {
ProdProcessLine prodProcess = request.getContext().asType(ProdProcessLine.class);
WorkCenter workCenter = prodProcess.getWorkCenter();
if (workCenter != null) {
response.setValue("minCapacityPerCycle", Beans.get(ProdProcessLineService.class).getProdProcessLineMinCapacityPerCycleFromWorkCenter(workCenter));
response.setValue("maxCapacityPerCycle", Beans.get(ProdProcessLineService.class).getProdProcessLineMaxCapacityPerCycleFromWorkCenter(workCenter));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.WorkCenter in project axelor-open-suite by axelor.
the class OperationOrderWorkflowService method computeEntireCycleDuration.
public long computeEntireCycleDuration(OperationOrder operationOrder, BigDecimal qty) throws AxelorException {
ProdProcessLine prodProcessLine = operationOrder.getProdProcessLine();
WorkCenter workCenter = prodProcessLine.getWorkCenter();
long duration = 0;
if (prodProcessLine.getWorkCenter() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PROD_PROCESS_LINE_MISSING_WORK_CENTER), prodProcessLine.getProdProcess() != null ? prodProcessLine.getProdProcess().getCode() : "null", prodProcessLine.getName());
}
BigDecimal maxCapacityPerCycle = prodProcessLine.getMaxCapacityPerCycle();
BigDecimal nbCycles;
if (maxCapacityPerCycle.compareTo(BigDecimal.ZERO) == 0) {
nbCycles = qty;
} else {
nbCycles = qty.divide(maxCapacityPerCycle, 0, RoundingMode.UP);
}
int workCenterTypeSelect = workCenter.getWorkCenterTypeSelect();
if (workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_MACHINE || workCenterTypeSelect == WorkCenterRepository.WORK_CENTER_TYPE_BOTH) {
Machine machine = workCenter.getMachine();
if (machine == null) {
throw new AxelorException(workCenter, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.WORKCENTER_NO_MACHINE), workCenter.getName());
}
duration += machine.getStartingDuration();
duration += machine.getEndingDuration();
duration += nbCycles.subtract(new BigDecimal(1)).multiply(new BigDecimal(machine.getSetupDuration())).longValue();
}
BigDecimal durationPerCycle = new BigDecimal(prodProcessLine.getDurationPerCycle());
duration += nbCycles.multiply(durationPerCycle).longValue();
return duration;
}
use of com.axelor.apps.production.db.WorkCenter in project axelor-open-suite by axelor.
the class CostSheetServiceImpl method _computeMachineCost.
protected void _computeMachineCost(ProdProcessLine prodProcessLine, BigDecimal producedQty, Unit pieceUnit, int bomLevel, CostSheetLine parentCostSheetLine) throws AxelorException {
WorkCenter workCenter = prodProcessLine.getWorkCenter();
if (prodProcessLine.getWorkCenter() == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.PROD_PROCESS_LINE_MISSING_WORK_CENTER), prodProcessLine.getProdProcess() != null ? prodProcessLine.getProdProcess().getCode() : "null", prodProcessLine.getName());
}
int costType = workCenter.getCostTypeSelect();
if (costType == WorkCenterRepository.COST_TYPE_PER_CYCLE) {
costSheetLineService.createWorkCenterMachineCostSheetLine(workCenter, prodProcessLine.getPriority(), bomLevel, parentCostSheetLine, this.getNbCycle(producedQty, prodProcessLine.getMaxCapacityPerCycle()), workCenter.getCostAmount(), cycleUnit);
} else if (costType == WorkCenterRepository.COST_TYPE_PER_HOUR) {
BigDecimal qty = new BigDecimal(prodProcessLine.getDurationPerCycle()).divide(new BigDecimal(3600), appProductionService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP).multiply(this.getNbCycle(producedQty, prodProcessLine.getMaxCapacityPerCycle()));
BigDecimal costPrice = workCenter.getCostAmount().multiply(qty);
costSheetLineService.createWorkCenterMachineCostSheetLine(workCenter, prodProcessLine.getPriority(), bomLevel, parentCostSheetLine, qty, costPrice, hourUnit);
} else if (costType == WorkCenterRepository.COST_TYPE_PER_PIECE) {
BigDecimal costPrice = workCenter.getCostAmount().multiply(producedQty);
costSheetLineService.createWorkCenterMachineCostSheetLine(workCenter, prodProcessLine.getPriority(), bomLevel, parentCostSheetLine, producedQty, costPrice, pieceUnit);
}
}
Aggregations