use of com.axelor.apps.production.db.UnitCostCalculation in project axelor-open-suite by axelor.
the class UnitCostCalculationController method runUnitCostCalc.
public void runUnitCostCalc(ActionRequest request, ActionResponse response) throws AxelorException {
try {
UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
Beans.get(UnitCostCalculationService.class).runUnitCostCalc(unitCostCalculation);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.UnitCostCalculation in project axelor-open-suite by axelor.
the class UnitCostCalculationController method exportUnitCostCalc.
public void exportUnitCostCalc(ActionRequest request, ActionResponse response) throws IOException {
try {
UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
String fileName = unitCostCalculation.getUnitCostCalcSeq() + "-" + Beans.get(AppProductionService.class).getTodayDateTime().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
MetaFile metaFile = Beans.get(UnitCostCalculationService.class).exportUnitCostCalc(unitCostCalculation, fileName);
response.setView(ActionView.define(fileName).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + metaFile.getId() + "/content/download?v=" + metaFile.getVersion()).map());
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.UnitCostCalculation in project axelor-open-suite by axelor.
the class UnitCostCalculationController method updateUnitCosts.
public void updateUnitCosts(ActionRequest request, ActionResponse response) throws AxelorException {
try {
UnitCostCalculation unitCostCalculation = request.getContext().asType(UnitCostCalculation.class);
unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculation.getId());
Beans.get(UnitCostCalculationService.class).updateUnitCosts(unitCostCalculation);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.production.db.UnitCostCalculation in project axelor-open-suite by axelor.
the class UnitCostCalculationController method importUnitCostCalc.
@SuppressWarnings("unchecked")
public void importUnitCostCalc(ActionRequest request, ActionResponse response) throws IOException {
try {
LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) request.getContext().get("metaFile");
MetaFile dataFile = Beans.get(MetaFileRepository.class).find(((Integer) map.get("id")).longValue());
File csvFile = MetaFiles.getPath(dataFile).toFile();
Long unitCostCalculationId = Long.valueOf(request.getContext().get("_id").toString());
UnitCostCalculation unitCostCalculation = Beans.get(UnitCostCalculationRepository.class).find(unitCostCalculationId);
if (Files.getFileExtension(csvFile.getName()).equals("csv")) {
Beans.get(UnitCostCalculationService.class).importUnitCostCalc(dataFile, unitCostCalculation);
response.setCanClose(true);
} else {
response.setError(IExceptionMessage.UNIT_COST_CALCULATION_IMPORT_CSV_ERROR);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations