Search in sources :

Example 6 with BankStatement

use of com.axelor.apps.bankpayment.db.BankStatement in project axelor-open-suite by axelor.

the class EbicsPartnerServiceImpl method getBankStatements.

@Transactional
public List<BankStatement> getBankStatements(EbicsPartner ebicsPartner, Collection<BankStatementFileFormat> bankStatementFileFormatCollection) throws AxelorException, IOException {
    List<BankStatement> bankStatementList = Lists.newArrayList();
    EbicsUser transportEbicsUser = ebicsPartner.getTransportEbicsUser();
    if (ebicsPartner.getBsEbicsPartnerServiceList() == null || ebicsPartner.getBsEbicsPartnerServiceList().isEmpty() || transportEbicsUser == null) {
        return bankStatementList;
    }
    LocalDateTime executionDateTime = LocalDateTime.now();
    Date startDate = null;
    Date endDate = null;
    LocalDate bankStatementStartDate = null;
    LocalDate bankStatementToDate = null;
    if (ebicsPartner.getBankStatementGetModeSelect() == EbicsPartnerRepository.GET_MODE_PERIOD) {
        bankStatementStartDate = ebicsPartner.getBankStatementStartDate();
        if (bankStatementStartDate != null) {
            startDate = DateTool.toDate(bankStatementStartDate);
        }
        bankStatementToDate = ebicsPartner.getBankStatementEndDate();
        if (bankStatementToDate != null) {
            endDate = DateTool.toDate(bankStatementToDate);
        }
    } else {
        if (ebicsPartner.getBankStatementLastExeDateT() != null) {
            bankStatementStartDate = ebicsPartner.getBankStatementLastExeDateT().toLocalDate();
        }
        bankStatementToDate = executionDateTime.toLocalDate();
    }
    for (com.axelor.apps.bankpayment.db.EbicsPartnerService bsEbicsPartnerService : ebicsPartner.getBsEbicsPartnerServiceList()) {
        BankStatementFileFormat bankStatementFileFormat = bsEbicsPartnerService.getBankStatementFileFormat();
        if (bankStatementFileFormatCollection != null && !bankStatementFileFormatCollection.isEmpty() && !bankStatementFileFormatCollection.contains(bankStatementFileFormat)) {
            continue;
        }
        try {
            File file = ebicsService.sendFDLRequest(transportEbicsUser, null, startDate, endDate, bsEbicsPartnerService.getEbicsCodification());
            BankStatement bankStatement = bankStatementCreateService.createBankStatement(file, bankStatementStartDate, bankStatementToDate, bankStatementFileFormat, ebicsPartner, executionDateTime);
            bankStatementRepository.save(bankStatement);
            bankStatementList.add(bankStatement);
        } catch (Exception e) {
            TraceBackService.trace(e);
        }
    }
    ebicsPartner.setBankStatementLastExeDateT(executionDateTime);
    Beans.get(EbicsPartnerRepository.class).save(ebicsPartner);
    return bankStatementList;
}
Also used : LocalDateTime(java.time.LocalDateTime) BankStatement(com.axelor.apps.bankpayment.db.BankStatement) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) BankStatementFileFormat(com.axelor.apps.bankpayment.db.BankStatementFileFormat) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) File(java.io.File) EbicsPartnerRepository(com.axelor.apps.bankpayment.db.repo.EbicsPartnerRepository) Transactional(com.google.inject.persist.Transactional)

Example 7 with BankStatement

use of com.axelor.apps.bankpayment.db.BankStatement in project axelor-open-suite by axelor.

the class EbicsPartnerController method getBankStatement.

public void getBankStatement(ActionRequest request, ActionResponse response) {
    try {
        EbicsPartner ebicsPartner = request.getContext().asType(EbicsPartner.class);
        List<BankStatement> bankStatementList = Beans.get(EbicsPartnerService.class).getBankStatements(Beans.get(EbicsPartnerRepository.class).find(ebicsPartner.getId()));
        response.setFlash(String.format(I18n.get("%s bank statements get."), bankStatementList.size()));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
    response.setReload(true);
}
Also used : BankStatement(com.axelor.apps.bankpayment.db.BankStatement) EbicsPartnerService(com.axelor.apps.bankpayment.ebics.service.EbicsPartnerService) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner)

Example 8 with BankStatement

use of com.axelor.apps.bankpayment.db.BankStatement in project axelor-open-suite by axelor.

the class BatchBankStatement method process.

@Override
protected void process() {
    BankPaymentBatch bankPaymentBatch = batch.getBankPaymentBatch();
    Collection<EbicsPartner> ebicsPartners = bankPaymentBatch.getEbicsPartnerSet();
    // on the batch.
    if (ebicsPartners == null || ebicsPartners.isEmpty()) {
        ebicsPartners = getAllActiveEbicsPartners();
    }
    for (EbicsPartner ebicsPartner : ebicsPartners) {
        try {
            List<BankStatement> bankStatementList = ebicsPartnerService.getBankStatements(ebicsPartnerRepository.find(ebicsPartner.getId()), bankPaymentBatch.getBankStatementFileFormatSet());
            bankStatementCount += bankStatementList.size();
            for (BankStatement bankStatement : bankStatementList) {
                try {
                    bankStatementService.runImport(bankStatement, false);
                } catch (AxelorException e) {
                    processError(e, e.getCategory(), ebicsPartner);
                } finally {
                    JPA.clear();
                }
            }
            incrementDone();
        } catch (AxelorException e) {
            processError(e, e.getCategory(), ebicsPartner);
        } catch (Exception e) {
            processError(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, ebicsPartner);
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) BankStatement(com.axelor.apps.bankpayment.db.BankStatement) BankPaymentBatch(com.axelor.apps.bankpayment.db.BankPaymentBatch) EbicsPartner(com.axelor.apps.bankpayment.db.EbicsPartner) AxelorException(com.axelor.exception.AxelorException)

Example 9 with BankStatement

use of com.axelor.apps.bankpayment.db.BankStatement in project axelor-open-suite by axelor.

the class BankStatementController method runImport.

public void runImport(ActionRequest request, ActionResponse response) {
    try {
        BankStatement bankStatement = request.getContext().asType(BankStatement.class);
        bankStatement = Beans.get(BankStatementRepository.class).find(bankStatement.getId());
        Beans.get(BankStatementService.class).runImport(bankStatement, true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
    response.setReload(true);
}
Also used : BankStatementService(com.axelor.apps.bankpayment.service.bankstatement.BankStatementService) BankStatement(com.axelor.apps.bankpayment.db.BankStatement)

Aggregations

BankStatement (com.axelor.apps.bankpayment.db.BankStatement)9 BankStatementFileFormat (com.axelor.apps.bankpayment.db.BankStatementFileFormat)2 EbicsPartner (com.axelor.apps.bankpayment.db.EbicsPartner)2 BankStatementService (com.axelor.apps.bankpayment.service.bankstatement.BankStatementService)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 BankPaymentBatch (com.axelor.apps.bankpayment.db.BankPaymentBatch)1 BankReconciliation (com.axelor.apps.bankpayment.db.BankReconciliation)1 EbicsUser (com.axelor.apps.bankpayment.db.EbicsUser)1 EbicsPartnerRepository (com.axelor.apps.bankpayment.db.repo.EbicsPartnerRepository)1 EbicsPartnerService (com.axelor.apps.bankpayment.ebics.service.EbicsPartnerService)1 BankReconciliationCreateService (com.axelor.apps.bankpayment.service.bankreconciliation.BankReconciliationCreateService)1 BankReconciliationLoadService (com.axelor.apps.bankpayment.service.bankreconciliation.load.BankReconciliationLoadService)1 BankReconciliationLoadAFB120Service (com.axelor.apps.bankpayment.service.bankreconciliation.load.afb120.BankReconciliationLoadAFB120Service)1 File (java.io.File)1 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 Date (java.util.Date)1