Search in sources :

Example 6 with SubrogationRelease

use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.

the class SubrogationReleaseController method exportToCSV.

public void exportToCSV(ActionRequest request, ActionResponse response) {
    try {
        SubrogationRelease subrogationRelease = request.getContext().asType(SubrogationRelease.class);
        Beans.get(SubrogationReleaseService.class).exportToCSV(subrogationRelease);
        response.setReload(true);
    } catch (Exception e) {
        response.setError(e.getMessage());
        TraceBackService.trace(e);
    }
}
Also used : SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) SubrogationReleaseService(com.axelor.apps.account.service.SubrogationReleaseService)

Example 7 with SubrogationRelease

use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.

the class InvoiceManagementRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    try {
        final String subrogationStatusSelect = "$subrogationStatusSelect";
        if (context.get("_model") != null && context.get("_model").toString().equals(SubrogationRelease.class.getName())) {
            if (context.get("id") != null) {
                long id = (long) context.get("id");
                SubrogationRelease subrogationRelease = Beans.get(SubrogationReleaseRepository.class).find(id);
                if (subrogationRelease != null && subrogationRelease.getStatusSelect() != null) {
                    json.put(subrogationStatusSelect, subrogationRelease.getStatusSelect());
                } else {
                    json.put(subrogationStatusSelect, SubrogationReleaseRepository.STATUS_NEW);
                }
            }
        } else {
            json.put(subrogationStatusSelect, SubrogationReleaseRepository.STATUS_NEW);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return super.populate(json, context);
}
Also used : SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) PersistenceException(javax.persistence.PersistenceException)

Example 8 with SubrogationRelease

use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.

the class SubrogationReleaseManagementRepository method copy.

@Override
public SubrogationRelease copy(SubrogationRelease entity, boolean deep) {
    SubrogationRelease srCopy = super.copy(entity, deep);
    srCopy.setStatusSelect(STATUS_NEW);
    srCopy.clearInvoiceSet();
    return srCopy;
}
Also used : SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease)

Example 9 with SubrogationRelease

use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.

the class SubrogationReleaseServiceImpl method exportToCSV.

@Override
public String exportToCSV(SubrogationRelease subrogationRelease) throws AxelorException, IOException {
    String dataExportDir = appBaseService.getDataExportDir();
    List<String[]> allMoveLineData = new ArrayList<>();
    Comparator<Invoice> byInvoiceDate = (i1, i2) -> i1.getInvoiceDate().compareTo(i2.getInvoiceDate());
    Comparator<Invoice> byDueDate = (i1, i2) -> i1.getDueDate().compareTo(i2.getDueDate());
    Comparator<Invoice> byInvoiceId = (i1, i2) -> i1.getInvoiceId().compareTo(i2.getInvoiceId());
    List<Invoice> releaseDetails = subrogationRelease.getInvoiceSet().stream().sorted(byInvoiceDate.thenComparing(byDueDate).thenComparing(byInvoiceId)).collect(Collectors.toList());
    for (Invoice invoice : releaseDetails) {
        String[] items = new String[6];
        BigDecimal inTaxTotal = invoice.getInTaxTotal().abs();
        if (InvoiceToolService.isOutPayment(invoice)) {
            inTaxTotal = inTaxTotal.negate();
        }
        items[0] = invoice.getPartner().getPartnerSeq();
        items[1] = invoice.getInvoiceId();
        items[2] = invoice.getInvoiceDate().toString();
        items[3] = invoice.getDueDate().toString();
        items[4] = inTaxTotal.toString();
        items[5] = invoice.getCurrency().getCode();
        allMoveLineData.add(items);
    }
    AccountConfigService accountConfigService = Beans.get(AccountConfigService.class);
    String filePath = accountConfigService.getAccountConfig(subrogationRelease.getCompany()).getExportPath();
    filePath = filePath == null ? dataExportDir : dataExportDir + filePath;
    new File(filePath).mkdirs();
    String fileName = String.format("%s %s.csv", I18n.get("Subrogation release"), subrogationRelease.getSequenceNumber());
    Files.createDirectories(Paths.get(filePath));
    Path path = Paths.get(filePath, fileName);
    CsvTool.csvWriter(filePath, fileName, ';', null, allMoveLineData);
    try (InputStream is = new FileInputStream(path.toFile())) {
        Beans.get(MetaFiles.class).attach(is, fileName, subrogationRelease);
    }
    return path.toString();
}
Also used : Company(com.axelor.apps.base.db.Company) Query(com.axelor.db.Query) AccountConfig(com.axelor.apps.account.db.AccountConfig) Move(com.axelor.apps.account.db.Move) MoveService(com.axelor.apps.account.service.move.MoveService) Inject(com.google.inject.Inject) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) CsvTool(com.axelor.apps.tool.file.CsvTool) I18n(com.axelor.i18n.I18n) Path(java.nio.file.Path) MetaFiles(com.axelor.meta.MetaFiles) Journal(com.axelor.apps.account.db.Journal) Sequence(com.axelor.apps.base.db.Sequence) JPA(com.axelor.db.JPA) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) Files(java.nio.file.Files) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Invoice(com.axelor.apps.account.db.Invoice) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) File(java.io.File) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) SequenceService(com.axelor.apps.base.service.administration.SequenceService) List(java.util.List) ReportSettings(com.axelor.apps.report.engine.ReportSettings) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) Paths(java.nio.file.Paths) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) IReport(com.axelor.apps.account.report.IReport) Comparator(java.util.Comparator) SubrogationReleaseRepository(com.axelor.apps.account.db.repo.SubrogationReleaseRepository) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) InputStream(java.io.InputStream) Path(java.nio.file.Path) MetaFiles(com.axelor.meta.MetaFiles) Invoice(com.axelor.apps.account.db.Invoice) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) FileInputStream(java.io.FileInputStream) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) File(java.io.File)

Example 10 with SubrogationRelease

use of com.axelor.apps.account.db.SubrogationRelease in project axelor-open-suite by axelor.

the class NotificationServiceImpl method getSubrogationRelease.

protected SubrogationRelease getSubrogationRelease(NotificationItem notificationItem) {
    Invoice invoice = notificationItem.getInvoice();
    TypedQuery<SubrogationRelease> query = JPA.em().createQuery("SELECT self FROM SubrogationRelease self JOIN self.invoiceSet invoices WHERE self.statusSelect = :statusSelect AND invoices.id IN (:invoiceId)", SubrogationRelease.class);
    query.setParameter("statusSelect", SubrogationReleaseRepository.STATUS_ACCOUNTED);
    query.setParameter("invoiceId", invoice.getId());
    List<SubrogationRelease> subrogationReleaseResultList = query.getResultList();
    if (subrogationReleaseResultList != null && !subrogationReleaseResultList.isEmpty()) {
        return subrogationReleaseResultList.get(0);
    }
    return null;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) SubrogationRelease(com.axelor.apps.account.db.SubrogationRelease)

Aggregations

SubrogationRelease (com.axelor.apps.account.db.SubrogationRelease)11 SubrogationReleaseService (com.axelor.apps.account.service.SubrogationReleaseService)5 Invoice (com.axelor.apps.account.db.Invoice)4 Move (com.axelor.apps.account.db.Move)3 MoveLine (com.axelor.apps.account.db.MoveLine)3 Company (com.axelor.apps.base.db.Company)3 Account (com.axelor.apps.account.db.Account)2 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 Journal (com.axelor.apps.account.db.Journal)2 Transactional (com.google.inject.persist.Transactional)2 BigDecimal (java.math.BigDecimal)2 ReportFactory (com.axelor.apps.ReportFactory)1 Notification (com.axelor.apps.account.db.Notification)1 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)1 MoveRepository (com.axelor.apps.account.db.repo.MoveRepository)1 SubrogationReleaseRepository (com.axelor.apps.account.db.repo.SubrogationReleaseRepository)1 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 IReport (com.axelor.apps.account.report.IReport)1 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)1 InvoiceToolService (com.axelor.apps.account.service.invoice.InvoiceToolService)1