Search in sources :

Example 36 with MetaFile

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;
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ArrayList(java.util.ArrayList) PayrollPreparationService(com.axelor.apps.hr.service.PayrollPreparationService) MetaFile(com.axelor.meta.db.MetaFile) LocalDate(java.time.LocalDate) PayrollPreparation(com.axelor.apps.hr.db.PayrollPreparation) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream) Transactional(com.google.inject.persist.Transactional)

Example 37 with 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;
}
Also used : MetaFiles(com.axelor.meta.MetaFiles) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) PayrollPreparation(com.axelor.apps.hr.db.PayrollPreparation) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream) Transactional(com.google.inject.persist.Transactional)

Example 38 with 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);
    }
}
Also used : App(com.axelor.apps.base.db.App) AccountingReport(com.axelor.apps.account.db.AccountingReport) MoveLineExportService(com.axelor.apps.account.service.MoveLineExportService) MetaFile(com.axelor.meta.db.MetaFile) AccountingReportService(com.axelor.apps.account.service.AccountingReportService)

Example 39 with MetaFile

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;
}
Also used : Path(java.nio.file.Path) MetaFile(com.axelor.meta.db.MetaFile) IOException(java.io.IOException) Partner(com.axelor.apps.base.db.Partner) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile)

Example 40 with MetaFile

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));
    }
}
Also used : MetaFileRepository(com.axelor.meta.db.repo.MetaFileRepository) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) FileInputStream(java.io.FileInputStream) ImportDemoDataService(com.axelor.apps.base.service.imports.ImportDemoDataService)

Aggregations

MetaFile (com.axelor.meta.db.MetaFile)87 File (java.io.File)50 FileInputStream (java.io.FileInputStream)25 IOException (java.io.IOException)24 AxelorException (com.axelor.exception.AxelorException)21 MetaFiles (com.axelor.meta.MetaFiles)18 Transactional (com.google.inject.persist.Transactional)17 ArrayList (java.util.ArrayList)13 Path (java.nio.file.Path)12 InputStream (java.io.InputStream)10 ZipFile (java.util.zip.ZipFile)9 FileOutputStream (java.io.FileOutputStream)8 MetaFileRepository (com.axelor.meta.db.repo.MetaFileRepository)7 ImportHistory (com.axelor.apps.base.db.ImportHistory)6 DMSFile (com.axelor.dms.db.DMSFile)6 HashMap (java.util.HashMap)6 ZipEntry (java.util.zip.ZipEntry)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 App (com.axelor.apps.base.db.App)3