use of com.axelor.apps.stock.db.repo.StockLocationRepository in project axelor-open-suite by axelor.
the class StockLocationController method print.
/**
* Method that generate inventory as a pdf
*
* @param request
* @param response
* @return
* @throws BirtException
* @throws IOException
*/
public void print(ActionRequest request, ActionResponse response) throws AxelorException {
Context context = request.getContext();
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockLocationMap = (LinkedHashMap<String, Object>) context.get("_stockLocation");
Integer stockLocationId = (Integer) stockLocationMap.get("id");
StockLocationService stockLocationService = Beans.get(StockLocationService.class);
StockLocationRepository stockLocationRepository = Beans.get(StockLocationRepository.class);
StockLocation stockLocation = stockLocationId != null ? stockLocationRepository.find(new Long(stockLocationId)) : null;
String locationIds = "";
String printType = (String) context.get("printingType");
String exportType = (String) context.get("exportTypeSelect");
@SuppressWarnings("unchecked") List<Integer> lstSelectedLocations = (List<Integer>) context.get("_ids");
if (lstSelectedLocations != null) {
for (Integer it : lstSelectedLocations) {
Set<Long> idSet = stockLocationService.getContentStockLocationIds(stockLocationRepository.find(new Long(it)));
if (!idSet.isEmpty()) {
locationIds += Joiner.on(",").join(idSet) + ",";
}
}
}
if (!locationIds.equals("")) {
locationIds = locationIds.substring(0, locationIds.length() - 1);
stockLocation = stockLocationRepository.find(new Long(lstSelectedLocations.get(0)));
} else if (stockLocation != null && stockLocation.getId() != null) {
Set<Long> idSet = stockLocationService.getContentStockLocationIds(stockLocationRepository.find(stockLocation.getId()));
if (!idSet.isEmpty()) {
locationIds = Joiner.on(",").join(idSet);
}
}
if (!locationIds.equals("")) {
String language = ReportSettings.getPrintingLocale(null);
String title = I18n.get("Stock location");
if (stockLocation.getName() != null) {
title = lstSelectedLocations == null ? I18n.get("Stock location") + " " + stockLocation.getName() : I18n.get("Stock location(s)");
}
if (stockLocationService.isConfigMissing(stockLocation, Integer.parseInt(printType))) {
response.setNotify(I18n.get(IExceptionMessage.STOCK_CONFIGURATION_MISSING));
}
String fileLink = ReportFactory.createReport(IReport.STOCK_LOCATION, title + "-${date}").addParam("StockLocationId", locationIds).addParam("Timezone", null).addParam("Locale", language).addFormat(exportType).addParam("PrintType", printType).generate().getFileLink();
logger.debug("Printing " + title);
response.setView(ActionView.define(title).add("html", fileLink).map());
} else {
response.setFlash(I18n.get(IExceptionMessage.LOCATION_2));
}
response.setCanClose(true);
}
Aggregations