use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class ProjectedStockController method showChartProjectedStock.
public void showChartProjectedStock(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
List<Map<String, Object>> dataList = new ArrayList<>();
@SuppressWarnings("unchecked") Collection<Map<String, Object>> contextMrpLineList = (Collection<Map<String, Object>>) context.get("_mrpLineListToProject");
List<MrpLine> mrpLineList = contextMrpLineList.stream().map(map -> Mapper.toBean(MrpLine.class, map)).collect(Collectors.toList());
if (!mrpLineList.isEmpty()) {
List<MrpLine> mrpLineLastList = new ArrayList<>();
MrpLine lastMrpLine = mrpLineList.get(0);
for (int i = 1; i < mrpLineList.size(); ++i) {
MrpLine mrpLine = mrpLineList.get(i);
if (mrpLine.getMaturityDate().isAfter(lastMrpLine.getMaturityDate())) {
mrpLineLastList.add(lastMrpLine);
}
lastMrpLine = mrpLine;
}
mrpLineLastList.add(lastMrpLine);
lastMrpLine = mrpLineList.get(0);
LocalDate mrpDate = lastMrpLine.getMaturityDate();
for (MrpLine mrpLine : mrpLineLastList) {
mrpDate = addInterElementForProjectedStockChart(dataList, lastMrpLine, mrpDate, mrpLine);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("name", mrpLine.getMaturityDate());
dataMap.put("cumulativeQty", mrpLine.getCumulativeQty());
dataList.add(dataMap);
lastMrpLine = mrpLine;
}
}
response.setData(dataList);
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class ManufOrderController method finish.
public void finish(ActionRequest request, ActionResponse response) {
try {
Long manufOrderId = (Long) request.getContext().get("id");
ManufOrder manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrderId);
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
long tracebackCount = traceBackService.countMessageTraceBack(manufOrder);
if (!Beans.get(ManufOrderWorkflowService.class).finish(manufOrder)) {
response.setNotify(I18n.get(IExceptionMessage.MANUF_ORDER_EMAIL_NOT_SENT));
} else if (traceBackService.countMessageTraceBack(manufOrder) > tracebackCount) {
traceBackService.findLastMessageTraceBack(manufOrder).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
}
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class SopLineController method fillMrpForecast.
public void fillMrpForecast(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> productCategoryMap = (LinkedHashMap<String, Object>) context.get("_productCategory");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> currencyMap = (LinkedHashMap<String, Object>) sopLineMap.get("currency");
BigDecimal sopSalesForecast = new BigDecimal(sopLineMap.get("sopSalesForecast").toString());
Long productCategoryId = Long.parseLong(productCategoryMap.get("id").toString());
Currency currency = currencyRepo.find(Long.parseLong(currencyMap.get("id").toString()));
BigDecimal totalForecast = BigDecimal.ZERO;
SortedSet<Map<String, Object>> mrpForecastSet = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("code")));
List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.productCategory.id = ?1 ", productCategoryId).fetch();
if (productList != null) {
for (Product product : productList) {
Map<String, Object> map = new HashMap<String, Object>();
MrpForecast mrpForecast = mrpForecastRepo.all().filter("self.product.id = ?1 AND self.technicalOrigin = ?2", product.getId(), MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP).fetchOne();
if (mrpForecast != null) {
map = Mapper.toMap(mrpForecast);
BigDecimal totalPrice = mrpForecast.getQty().multiply(product.getSalePrice());
map.put("$totalPrice", totalPrice);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
totalForecast = totalForecast.add(totalPrice);
mrpForecastSet.add(map);
continue;
}
map.put("product", product);
map.put("qty", BigDecimal.ZERO);
map.put("$totalPrice", BigDecimal.ZERO);
map.put("$unitPrice", product.getSalePrice());
map.put("code", product.getCode());
mrpForecastSet.add(map);
}
}
response.setValue("$mrpForecasts", mrpForecastSet);
response.setValue("$sopSalesForecast", sopSalesForecast);
response.setValue("$totalForecast", totalForecast);
response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()));
response.setValue("$currency", currency);
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class ManufOrderController method multiLevelManufOrderOnLoad.
/**
* Called from manuf order form, on clicking "Multi-level planning" button.
*
* @param request
* @param response
*/
public void multiLevelManufOrderOnLoad(ActionRequest request, ActionResponse response) {
try {
Long moId = Long.valueOf(request.getContext().get("id").toString());
ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
boolean showOnlyMissingQty = request.getContext().get("_showOnlyMissingQty") != null && Boolean.parseBoolean(request.getContext().get("_showOnlyMissingQty").toString());
ProdProductProductionRepository prodProductProductionRepository = Beans.get(ProdProductProductionRepository.class);
List<ProdProduct> prodProducts = mo.getToConsumeProdProductList().stream().filter(prodProduct -> prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_FINISHED_PRODUCT || prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT).filter(prodProduct -> !showOnlyMissingQty || prodProductProductionRepository.computeMissingQty(prodProduct.getProduct().getId(), prodProduct.getQty(), moId).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
response.setValue("$components", prodProducts);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.
the class StockMoveController method printStockMove.
/**
* Method called from stock move form and grid view. Print one or more stock move as PDF
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void printStockMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
StockMovePrintService stockMovePrintService = Beans.get(StockMovePrintService.class);
if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = stockMovePrintService.printStockMoves(ids);
title = I18n.get("Stock Moves");
} else if (context.get("id") != null) {
StockMove stockMove = Beans.get(StockMoveRepository.class).find(Long.parseLong(context.get("id").toString()));
title = stockMovePrintService.getFileName(stockMove);
fileLink = stockMovePrintService.printStockMove(stockMove, ReportSettings.FORMAT_PDF);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations