use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class BatchPayrollPreparationExport method standardExport.
@Transactional(rollbackOn = { Exception.class })
public MetaFile standardExport(List<PayrollPreparation> payrollPreparationList) throws IOException {
List<String[]> list = new ArrayList<>();
LocalDate today = Beans.get(AppBaseService.class).getTodayDate(hrBatch.getCompany());
for (PayrollPreparation payrollPreparation : payrollPreparationList) {
String[] item = new String[5];
item[0] = payrollPreparation.getEmployee().getName();
item[1] = payrollPreparation.getDuration().toString();
item[2] = payrollPreparation.getLunchVoucherNumber().toString();
item[3] = payrollPreparation.getEmployeeBonusAmount().toString();
item[4] = payrollPreparation.getExtraHoursNumber().toString();
list.add(item);
payrollPreparation.setExported(true);
payrollPreparation.setExportDate(today);
payrollPreparation.setExportTypeSelect(HrBatchRepository.EXPORT_TYPE_STANDARD);
payrollPreparation.addBatchListItem(batch);
payrollPreparationRepository.save(payrollPreparation);
total++;
incrementDone();
}
String fileName = Beans.get(PayrollPreparationService.class).getPayrollPreparationExportName();
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
CsvTool.csvWriter(file.getParent(), file.getName(), ';', Beans.get(PayrollPreparationService.class).getPayrollPreparationExportHeader(), list);
FileInputStream inStream = new FileInputStream(file);
MetaFile metaFile = Beans.get(MetaFiles.class).upload(inStream, file.getName());
return metaFile;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class BatchPayrollPreparationExport method silaeExport.
@Transactional(rollbackOn = { Exception.class })
public MetaFile silaeExport(List<PayrollPreparation> payrollPreparationList) throws IOException, AxelorException {
List<String[]> list = new ArrayList<>();
for (PayrollPreparation payrollPreparation : payrollPreparationList) {
payrollPreparation.addBatchListItem(batch);
payrollPreparationService.exportSilae(payrollPreparation, list);
total++;
incrementDone();
}
String fileName = payrollPreparationService.getPayrollPreparationExportName();
File file = MetaFiles.createTempFile(fileName, ".csv").toFile();
CsvTool.csvWriter(file.getParent(), file.getName(), ';', payrollPreparationService.getPayrollPreparationSilaeExportHeader(), list);
FileInputStream inStream = new FileInputStream(file);
MetaFile metaFile = Beans.get(MetaFiles.class).upload(inStream, file.getName());
return metaFile;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class AccountingReportController method printExportMoveLine.
/**
* @param request
* @param response
*/
public void printExportMoveLine(ActionRequest request, ActionResponse response) {
AccountingReport accountingReport = request.getContext().asType(AccountingReport.class);
accountingReport = Beans.get(AccountingReportRepository.class).find(accountingReport.getId());
AccountingReportService accountingReportService = Beans.get(AccountingReportService.class);
try {
int typeSelect = accountingReport.getReportType().getTypeSelect();
if (accountingReport.getExportTypeSelect() == null || accountingReport.getExportTypeSelect().isEmpty() || typeSelect == 0) {
response.setFlash(I18n.get(IExceptionMessage.ACCOUNTING_REPORT_4));
response.setReload(true);
return;
}
if (accountingReportService.isThereTooManyLines(accountingReport)) {
response.setAlert(I18n.get("A large number of recording has been fetched in this period. Edition can take a while. Do you want to proceed ?"));
}
logger.debug("Type selected : {}", typeSelect);
if ((typeSelect >= AccountingReportRepository.EXPORT_ADMINISTRATION && typeSelect < AccountingReportRepository.REPORT_ANALYTIC_BALANCE)) {
MoveLineExportService moveLineExportService = Beans.get(MoveLineExportService.class);
MetaFile accesssFile = moveLineExportService.exportMoveLine(accountingReport);
if (typeSelect == AccountingReportRepository.EXPORT_ADMINISTRATION && accesssFile != null) {
response.setView(ActionView.define(I18n.get("Export file")).model(App.class.getName()).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + accesssFile.getId() + "/content/download?v=" + accesssFile.getVersion()).param("download", "true").map());
}
} else {
accountingReportService.setPublicationDateTime(accountingReport);
String name = accountingReport.getReportType().getName() + " " + accountingReport.getRef();
String fileLink = accountingReportService.getReportFileLink(accountingReport, name);
logger.debug("Printing " + name);
response.setView(ActionView.define(name).add("html", fileLink).map());
accountingReportService.setStatus(accountingReport);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportPartner method importPartner.
public Object importPartner(Object bean, Map<String, Object> values) {
assert bean instanceof Partner;
Partner partner = (Partner) bean;
partnerService.setPartnerFullName(partner);
final Path path = (Path) values.get("__path__");
String fileName = (String) values.get("picture_fileName");
if (Strings.isNullOrEmpty((fileName))) {
return bean;
}
final File image = path.resolve(fileName).toFile();
try {
final MetaFile metaFile = metaFiles.upload(image);
partner.setPicture(metaFile);
} catch (IOException e) {
e.printStackTrace();
}
return bean;
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class ImportDemoDataController method importDemoDataExcel.
public void importDemoDataExcel(ActionRequest request, ActionResponse response) throws FileNotFoundException, IOException, AxelorException, ParseException, ClassNotFoundException {
MetaFile metaFile = Beans.get(MetaFileRepository.class).find(Long.valueOf(((Map) request.getContext().get("importFile")).get("id").toString()));
File excelFile = MetaFiles.getPath(metaFile).toFile();
if (Files.getFileExtension(excelFile.getName()).equals("xlsx")) {
File tmpFile = File.createTempFile("Import", ".log");
if (Beans.get(ImportDemoDataService.class).importDemoDataExcel(excelFile, tmpFile)) {
response.setFlash(I18n.get(IExceptionMessage.IMPORT_COMPLETED_MESSAGE));
} else {
response.setFlash(I18n.get(IExceptionMessage.INVALID_DATA_FORMAT_ERROR));
}
response.setAttr("$logFile", "hidden", false);
FileInputStream inStream = new FileInputStream(tmpFile);
response.setValue("$logFile", Beans.get(MetaFiles.class).upload(inStream, "Import.log"));
} else {
response.setError(I18n.get(IExceptionMessage.VALIDATE_FILE_TYPE));
}
}
Aggregations