Search in sources :

Example 1 with AccountingBatch

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

the class AccountingBatchService method run.

@Override
public Batch run(Model batchModel) throws AxelorException {
    Batch batch;
    AccountingBatch accountingBatch = (AccountingBatch) batchModel;
    switch(accountingBatch.getActionSelect()) {
        case AccountingBatchRepository.ACTION_REIMBURSEMENT:
            if (accountingBatch.getReimbursementTypeSelect() == AccountingBatchRepository.REIMBURSEMENT_TYPE_EXPORT) {
                batch = reimbursementExport(accountingBatch);
            } else if (accountingBatch.getReimbursementTypeSelect() == AccountingBatchRepository.REIMBURSEMENT_TYPE_IMPORT) {
                batch = reimbursementImport(accountingBatch);
            }
            batch = null;
            break;
        case AccountingBatchRepository.ACTION_DEBT_RECOVERY:
            batch = debtRecovery(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_DOUBTFUL_CUSTOMER:
            batch = doubtfulCustomer(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_ACCOUNT_CUSTOMER:
            batch = accountCustomer(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_MOVE_LINE_EXPORT:
            batch = moveLineExport(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_CREDIT_TRANSFER:
            batch = creditTransfer(accountingBatch);
            break;
        case AccountingBatchRepository.ACTION_REALIZE_FIXED_ASSET_LINES:
            batch = realizeFixedAssetLines(accountingBatch);
            break;
        default:
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BASE_BATCH_1), accountingBatch.getActionSelect(), accountingBatch.getCode());
    }
    return batch;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Batch(com.axelor.apps.base.db.Batch) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Example 2 with AccountingBatch

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

the class BatchCloseAnnualAccounts method process.

protected void process() {
    if (!end) {
        AccountingBatch accountingBatch = batch.getAccountingBatch();
        boolean allocatePerPartner = accountingBatch.getAllocatePerPartner();
        boolean closeYear = accountingBatch.getCloseYear();
        boolean openYear = accountingBatch.getOpenYear();
        Year year = accountingBatch.getYear();
        LocalDate endOfYearDate = year.getToDate();
        LocalDate reportedBalanceDate = year.getReportedBalanceDate();
        String origin = accountingBatch.getCode();
        String moveDescription = accountingBatch.getMoveDescription();
        List<Long> accountIdList = accountingCloseAnnualService.getAllAccountOfYear(accountingBatch.getAccountSet(), year);
        List<Pair<Long, Long>> accountAndPartnerPairList = accountingCloseAnnualService.assignPartner(accountIdList, year, allocatePerPartner);
        Account account = null;
        Partner partner = null;
        for (Pair<Long, Long> accountAndPartnerPair : accountAndPartnerPairList) {
            try {
                account = accountRepository.find(accountAndPartnerPair.getLeft());
                if (accountAndPartnerPair.getRight() != null) {
                    partner = partnerRepository.find(accountAndPartnerPair.getRight());
                } else {
                    partner = null;
                }
                List<Move> generateMoves = accountingCloseAnnualService.generateCloseAnnualAccount(yearRepository.find(year.getId()), account, partner, endOfYearDate, reportedBalanceDate, origin, moveDescription, closeYear, openYear, allocatePerPartner);
                if (generateMoves != null && !generateMoves.isEmpty()) {
                    updateAccount(account);
                    for (Move move : generateMoves) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("Account") + " %s", account.getCode()), null, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("Account") + " %s", account.getCode()), e), null, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the account {}", account.getCode());
                break;
            } finally {
                JPA.clear();
            }
        }
    }
}
Also used : Account(com.axelor.apps.account.db.Account) AxelorException(com.axelor.exception.AxelorException) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) Year(com.axelor.apps.base.db.Year) Move(com.axelor.apps.account.db.Move) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) Partner(com.axelor.apps.base.db.Partner) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with AccountingBatch

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

the class AccountingBatchAccountRepository method copy.

@Override
public AccountingBatch copy(AccountingBatch entity, boolean deep) {
    AccountingBatch copy = super.copy(entity, deep);
    copy.setBatchList(null);
    return copy;
}
Also used : AccountingBatch(com.axelor.apps.account.db.AccountingBatch)

Example 4 with AccountingBatch

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

the class BatchCreditTransferExpensePaymentHR method processExpenses.

/**
 * Process expenses that need to be paid.
 *
 * @return
 */
protected List<Expense> processExpenses() {
    List<Expense> 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();
    String filter = "self.ventilated = true " + "AND self.paymentStatusSelect = :paymentStatusSelect " + "AND self.company = :company " + "AND self.user.partner.outPaymentMode = :paymentMode " + "AND self.id NOT IN (:anomalyList)";
    if (manageMultiBanks) {
        filter += " AND self.bankDetails IN (:bankDetailsSet)";
    }
    Query<Expense> query = expenseRepo.all().filter(filter).bind("paymentStatusSelect", InvoicePaymentRepository.STATUS_DRAFT).bind("company", accountingBatch.getCompany()).bind("paymentMode", accountingBatch.getPaymentMode()).bind("anomalyList", anomalyList);
    if (manageMultiBanks) {
        Set<BankDetails> bankDetailsSet = Sets.newHashSet(accountingBatch.getBankDetails());
        if (accountingBatch.getIncludeOtherBankAccounts()) {
            bankDetailsSet.addAll(accountingBatch.getCompany().getBankDetailsList());
        }
        query.bind("bankDetailsSet", bankDetailsSet);
    }
    for (List<Expense> expenseList; !(expenseList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
        for (Expense expense : expenseList) {
            try {
                addPayment(expense, accountingBatch.getBankDetails());
                doneList.add(expense);
                incrementDone();
            } catch (Exception ex) {
                incrementAnomaly();
                anomalyList.add(expense.getId());
                query.bind("anomalyList", anomalyList);
                TraceBackService.trace(ex, ExceptionOriginRepository.CREDIT_TRANSFER, batch.getId());
                ex.printStackTrace();
                log.error(String.format("Credit transfer batch for expense payment: anomaly for expense %s", expense.getExpenseSeq()));
                break;
            }
        }
    }
    return doneList;
}
Also used : Expense(com.axelor.apps.hr.db.Expense) BankDetails(com.axelor.apps.base.db.BankDetails) ArrayList(java.util.ArrayList) AccountingBatch(com.axelor.apps.account.db.AccountingBatch) AxelorException(com.axelor.exception.AxelorException)

Example 5 with AccountingBatch

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

the class AccountingBatchController method actionMoveLineExport.

/**
 * Lancer le batch de calcul du compte client
 *
 * @param request
 * @param response
 */
public void actionMoveLineExport(ActionRequest request, ActionResponse response) {
    AccountingBatch accountingBatch = request.getContext().asType(AccountingBatch.class);
    Batch batch = null;
    batch = Beans.get(AccountingBatchService.class).moveLineExport(Beans.get(AccountingBatchRepository.class).find(accountingBatch.getId()));
    if (batch != null)
        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) AccountingBatchRepository(com.axelor.apps.account.db.repo.AccountingBatchRepository)

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