Search in sources :

Example 16 with AccountingBatch

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

the class AccountingBatchController method actionCreditTransfer.

public void actionCreditTransfer(ActionRequest request, ActionResponse response) {
    AccountingBatch accountingBatch = request.getContext().asType(AccountingBatch.class);
    accountingBatch = Beans.get(AccountingBatchRepository.class).find(accountingBatch.getId());
    Batch batch = Beans.get(AccountingBatchService.class).creditTransfer(accountingBatch);
    response.setFlash(batch.getComments());
    response.setReload(true);
}
Also used : Batch(com.axelor.apps.base.db.Batch) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AccountingBatchService(com.axelor.apps.account.service.batch.AccountingBatchService)

Example 17 with AccountingBatch

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

the class BatchAccountCustomer method process.

@Override
public void process() {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    Company company = accountingBatch.getCompany();
    boolean updateCustAccountOk = accountingBatch.getUpdateCustAccountOk();
    boolean updateDueCustAccountOk = accountingBatch.getUpdateDueCustAccountOk();
    boolean updateDueDebtRecoveryCustAccountOk = accountingBatch.getUpdateDueDebtRecoveryCustAccountOk();
    List<AccountingSituation> accountingSituationList = accountingSituationRepo.all().filter("self.company = ?1", company).fetch();
    int i = 0;
    JPA.clear();
    for (AccountingSituation accountingSituation : accountingSituationList) {
        try {
            accountingSituation = accountCustomerService.updateAccountingSituationCustomerAccount(accountingSituationRepo.find(accountingSituation.getId()), updateCustAccountOk, updateDueCustAccountOk, updateDueDebtRecoveryCustAccountOk);
            if (accountingSituation != null) {
                this.updateAccountingSituation(accountingSituation);
                i++;
            }
        } catch (Exception e) {
            TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_ACCOUNT_1), accountingSituationRepo.find(accountingSituation.getId()).getName()), e), ExceptionOriginRepository.CUSTOMER_ACCOUNT, batch.getId());
            incrementAnomaly();
            log.error("Bug(Anomalie) généré(e) pour la situation compable {}", accountingSituationRepo.find(accountingSituation.getId()).getName());
        } finally {
            if (i % 1 == 0) {
                JPA.clear();
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Example 18 with AccountingBatch

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

the class BatchBankPaymentServiceImpl method createBankOrderFromMonthlyPaymentScheduleLines.

@Override
@Transactional(rollbackOn = { Exception.class })
public BankOrder createBankOrderFromMonthlyPaymentScheduleLines(Batch batch) throws AxelorException, JAXBException, IOException, DatatypeConfigurationException {
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    LocalDate bankOrderDate = accountingBatch.getDueDate();
    Company senderCompany = accountingBatch.getCompany();
    BankDetails senderBankDetails = accountingBatch.getBankDetails();
    if (senderBankDetails == null) {
        senderBankDetails = accountingBatch.getCompany().getDefaultBankDetails();
    }
    PaymentMode paymentMode = accountingBatch.getPaymentMode();
    Currency currency = senderCompany.getCurrency();
    int partnerType = BankOrderRepository.PARTNER_TYPE_CUSTOMER;
    String senderReference = "";
    String senderLabel = "";
    if (bankOrderDate == null) {
        bankOrderDate = appBaseService.getTodayDate(senderCompany);
    }
    BankOrder bankOrder = bankOrderCreateService.createBankOrder(paymentMode, partnerType, bankOrderDate, senderCompany, senderBankDetails, currency, senderReference, senderLabel, BankOrderRepository.TECHNICAL_ORIGIN_AUTOMATIC);
    bankOrder = JPA.save(bankOrder);
    List<PaymentScheduleLine> paymentScheduleLineList;
    int offset = 0;
    try {
        while (!(paymentScheduleLineList = fetchPaymentScheduleLineDoneList(batch, offset)).isEmpty()) {
            bankOrder = bankOrderRepo.find(bankOrder.getId());
            for (PaymentScheduleLine paymentScheduleLine : paymentScheduleLineList) {
                PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
                Partner partner = paymentSchedule.getPartner();
                BankDetails bankDetails = paymentScheduleService.getBankDetails(paymentSchedule);
                BigDecimal amount = paymentScheduleLine.getInTaxAmount();
                String receiverReference = paymentScheduleLine.getName();
                String receiverLabel = paymentScheduleLine.getDebitNumber();
                BankOrderLine bankOrderLine = bankOrderLineService.createBankOrderLine(paymentMode.getBankOrderFileFormat(), null, partner, bankDetails, amount, currency, bankOrderDate, receiverReference, receiverLabel, paymentScheduleLine);
                bankOrder.addBankOrderLineListItem(bankOrderLine);
            }
            bankOrder = JPA.save(bankOrder);
            offset += paymentScheduleLineList.size();
            JPA.clear();
        }
    } catch (Exception e) {
        bankOrder = bankOrderRepo.find(bankOrder.getId());
        bankOrderRepo.remove(bankOrder);
        throw e;
    }
    bankOrder = bankOrderRepo.find(bankOrder.getId());
    bankOrder = bankOrderRepo.save(bankOrder);
    bankOrderService.confirm(bankOrder);
    batch = batchRepo.find(batch.getId());
    batch.setBankOrder(bankOrder);
    return bankOrder;
}
Also used : Company(com.axelor.apps.base.db.Company) BankOrderLine(com.axelor.apps.bankpayment.db.BankOrderLine) PaymentScheduleLine(com.axelor.apps.account.db.PaymentScheduleLine) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) BankDetails(com.axelor.apps.base.db.BankDetails) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) Currency(com.axelor.apps.base.db.Currency) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) BankOrder(com.axelor.apps.bankpayment.db.BankOrder) Partner(com.axelor.apps.base.db.Partner) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 19 with AccountingBatch

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

the class BatchCreditTransferPartnerReimbursementBankPayment method process.

@Override
protected void process() {
    super.process();
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    if (!accountingBatch.getPaymentMode().getGenerateBankOrder()) {
        return;
    }
    // Fetch all reimbursements that are validated for the specified company.
    Query<Reimbursement> query = reimbursementRepo.all().filter("self.statusSelect = :statusSelect AND self.company = :company");
    query.bind("statusSelect", ReimbursementRepository.STATUS_VALIDATED);
    query.bind("company", accountingBatch.getCompany());
    List<Reimbursement> reimbursementList = query.fetch();
    if (reimbursementList.isEmpty()) {
        return;
    }
    accountingBatch = Beans.get(AccountingBatchRepository.class).find(accountingBatch.getId());
    try {
        createBankOrder(accountingBatch, reimbursementList);
    } catch (Exception ex) {
        TraceBackService.trace(ex);
        logger.error(ex.getLocalizedMessage());
    }
}
Also used : AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Reimbursement(com.axelor.apps.account.db.Reimbursement) BatchCreditTransferPartnerReimbursement(com.axelor.apps.account.service.batch.BatchCreditTransferPartnerReimbursement) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 20 with AccountingBatch

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

the class BatchCreditTransferInvoice method processInvoices.

/**
 * Process invoices of the specified document type.
 *
 * @param operationTypeSelect
 * @return
 */
protected List<InvoicePayment> processInvoices(int operationTypeSelect) {
    List<InvoicePayment> doneList = new ArrayList<>();
    // Can't pass an empty collection to the query
    List<Long> anomalyList = Lists.newArrayList(0L);
    AccountingBatch accountingBatch = batch.getAccountingBatch();
    boolean manageMultiBanks = appAccountService.getAppBase().getManageMultiBanks();
    StringBuilder filter = new StringBuilder();
    filter.append("self.operationTypeSelect = :operationTypeSelect " + "AND self.statusSelect = :statusSelect " + "AND self.amountRemaining > 0 " + "AND self.hasPendingPayments = FALSE " + "AND self.company = :company " + "AND self.dueDate <= :dueDate " + "AND self.paymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)" + "AND self.pfpValidateStatusSelect != :pfpValidateStatusSelect");
    if (manageMultiBanks) {
        filter.append(" AND self.companyBankDetails IN (:bankDetailsSet)");
    }
    if (accountingBatch.getCurrency() != null) {
        filter.append(" AND self.currency = :currency");
    }
    Query<Invoice> query = invoiceRepo.all().filter(filter.toString()).bind("operationTypeSelect", operationTypeSelect).bind("statusSelect", InvoiceRepository.STATUS_VENTILATED).bind("company", accountingBatch.getCompany()).bind("dueDate", accountingBatch.getDueDate()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList).bind("pfpValidateStatusSelect", InvoiceRepository.PFP_STATUS_LITIGATION);
    if (manageMultiBanks) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        query.bind("bankDetailsSet", bankDetailsSet);
    }
    if (accountingBatch.getCurrency() != null) {
        query.bind("currency", accountingBatch.getCurrency());
    }
    BankDetailsRepository bankDetailsRepo = Beans.get(BankDetailsRepository.class);
    BankDetails companyBankDetails = accountingBatch.getBankDetails();
    for (List<Invoice> invoiceList; !(invoiceList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        if (!JPA.em().contains(companyBankDetails)) {
            companyBankDetails = bankDetailsRepo.find(companyBankDetails.getId());
        }
        for (Invoice invoice : invoiceList) {
            try {
                doneList.add(invoicePaymentCreateService.createInvoicePayment(invoice, companyBankDetails));
                incrementDone();
            } catch (Exception ex) {
                incrementAnomaly();
                anomalyList.add(invoice.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
                ex.printStackTrace();
                log.error(String.format("Credit transfer batch for invoices: anomaly for invoice %s", invoice.getInvoiceId()));
                break;
            }
        }
    }
    return doneList;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Invoice(com.axelor.apps.account.db.Invoice) BankDetails(com.axelor.apps.base.db.BankDetails) BankDetailsRepository(com.axelor.apps.base.db.repo.BankDetailsRepository) ArrayList(java.util.ArrayList) AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Aggregations

AccountingBatch (com.axelor.apps.account.db.AccountingBatch)21 Batch (com.axelor.apps.base.db.Batch)11 AxelorException (com.axelor.exception.AxelorException)9 AccountingBatchRepository (com.axelor.apps.account.db.repo.AccountingBatchRepository)5 AccountingBatchService (com.axelor.apps.account.service.batch.AccountingBatchService)5 BankDetails (com.axelor.apps.base.db.BankDetails)5 LocalDate (java.time.LocalDate)4 Partner (com.axelor.apps.base.db.Partner)3 ArrayList (java.util.ArrayList)3 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)2 PaymentScheduleLine (com.axelor.apps.account.db.PaymentScheduleLine)2 Reimbursement (com.axelor.apps.account.db.Reimbursement)2 BankOrder (com.axelor.apps.bankpayment.db.BankOrder)2 Company (com.axelor.apps.base.db.Company)2 IOException (java.io.IOException)2 JAXBException (javax.xml.bind.JAXBException)2 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Account (com.axelor.apps.account.db.Account)1 AccountManagement (com.axelor.apps.account.db.AccountManagement)1