use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class InvoiceController method showInvoice.
/**
* Method to generate invoice as a Pdf
*/
@SuppressWarnings("unchecked")
public void showInvoice(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String fileLink;
String title;
try {
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 = Beans.get(InvoicePrintService.class).printInvoices(ids);
title = I18n.get("Invoices");
} else if (context.get("id") != null) {
String format = context.get("format") != null ? context.get("format").toString() : "pdf";
Integer reportType = context.get("reportType") != null ? Integer.parseInt(context.get("reportType").toString()) : null;
Map languageMap = reportType != null && (reportType == 1 || reportType == 3) && context.get("language") != null ? (Map<String, Object>) request.getContext().get("language") : null;
String locale = languageMap != null && languageMap.get("id") != null ? Beans.get(LanguageRepository.class).find(Long.parseLong(languageMap.get("id").toString())).getCode() : null;
fileLink = Beans.get(InvoicePrintService.class).printInvoice(Beans.get(InvoiceRepository.class).find(Long.parseLong(context.get("id").toString())), false, format, reportType, locale);
title = I18n.get("Invoice");
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_3));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class InvoiceLineController method getFixedAssetCategory.
public void getFixedAssetCategory(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
InvoiceLine invoiceLine = context.asType(InvoiceLine.class);
Invoice invoice = this.getInvoice(context);
Product product = invoiceLine.getProduct();
if (invoice == null || product == null) {
return;
}
FixedAssetCategory fixedAssetCategory = null;
if (!product.getAccountManagementList().isEmpty() && (invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_PURCHASE || invoice.getOperationTypeSelect() == InvoiceRepository.OPERATION_TYPE_SUPPLIER_REFUND)) {
Optional<AccountManagement> optionalFixedAssetCategory = product.getAccountManagementList().stream().filter(am -> invoice.getCompany().equals(am.getCompany())).findFirst();
fixedAssetCategory = optionalFixedAssetCategory.isPresent() ? optionalFixedAssetCategory.get().getFixedAssetCategory() : null;
}
response.setValue("fixedAssetCategory", fixedAssetCategory);
}
use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.
the class SaleOrderController method createStockMove.
public void createStockMove(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
try {
if (saleOrder.getId() != null) {
SaleOrderStockService saleOrderStockService = Beans.get(SaleOrderStockService.class);
List<Long> stockMoveList = saleOrderStockService.createStocksMovesFromSaleOrder(Beans.get(SaleOrderRepository.class).find(saleOrder.getId()));
if (stockMoveList != null && stockMoveList.size() == 1) {
response.setView(ActionView.define(I18n.get("Stock move")).model(StockMove.class.getName()).add("form", "stock-move-form").add("grid", "stock-move-grid").param("search-filters", "internal-stock-move-filters").param("forceEdit", "true").domain("self.id = " + stockMoveList.get(0)).context("_showRecord", String.valueOf(stockMoveList.get(0))).context("_userType", StockMoveRepository.USER_TYPE_SALESPERSON).map());
// we have to inject TraceBackService to use non static methods
Beans.get(TraceBackService.class).findLastMessageTraceBack(Beans.get(StockMoveRepository.class).find(stockMoveList.get(0))).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
} else if (stockMoveList != null && stockMoveList.size() > 1) {
response.setView(ActionView.define(I18n.get("Stock move")).model(StockMove.class.getName()).add("grid", "stock-move-grid").add("form", "stock-move-form").param("search-filters", "internal-stock-move-filters").domain("self.id in (" + Joiner.on(",").join(stockMoveList) + ")").context("_userType", StockMoveRepository.USER_TYPE_SALESPERSON).map());
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
StockMoveRepository stockMoveRepository = Beans.get(StockMoveRepository.class);
stockMoveList.stream().map(stockMoveRepository::find).map(traceBackService::findLastMessageTraceBack).filter(Optional::isPresent).map(Optional::get).findAny().ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
} else {
response.setFlash(I18n.get(IExceptionMessage.SO_NO_DELIVERY_STOCK_MOVE_TO_GENERATE));
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.ActionRequest 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.ActionRequest 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);
}
}
Aggregations