Search in sources :

Example 6 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ReconcileServiceImpl method reconcilePreconditions.

public void reconcilePreconditions(Reconcile reconcile) throws AxelorException {
    MoveLine debitMoveLine = reconcile.getDebitMoveLine();
    MoveLine creditMoveLine = reconcile.getCreditMoveLine();
    if (debitMoveLine == null || creditMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    // Check if move lines companies are the same as the reconcile company
    Company reconcileCompany = reconcile.getCompany();
    Company debitMoveLineCompany = debitMoveLine.getMove().getCompany();
    Company creditMoveLineCompany = creditMoveLine.getMove().getCompany();
    if (!debitMoveLineCompany.equals(reconcileCompany) && !creditMoveLineCompany.equals(reconcileCompany)) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.RECONCILE_7), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), debitMoveLineCompany, creditMoveLineCompany, reconcileCompany));
    }
    // Check if move lines accounts are the same (debit and credit)
    if (!creditMoveLine.getAccount().equals(debitMoveLine.getAccount())) {
        log.debug("Compte ligne de credit : {} , Compte ligne de debit : {}", creditMoveLine.getAccount(), debitMoveLine.getAccount());
        // Check if move lines accounts are compatible
        if (!debitMoveLine.getAccount().getCompatibleAccountSet().contains(creditMoveLine.getAccount())) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECONCILE_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
        }
    }
    // Check if the amount to reconcile is != zero
    if (reconcile.getAmount() == null || reconcile.getAmount().compareTo(BigDecimal.ZERO) == 0) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel());
    }
    if ((reconcile.getAmount().compareTo(creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid())) > 0 || (reconcile.getAmount().compareTo(debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid())) > 0))) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.RECONCILE_5) + " " + I18n.get(IExceptionMessage.RECONCILE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), reconcile.getReconcileSeq(), reconcile.getAmount(), debitMoveLine.getName(), debitMoveLine.getAccount().getLabel(), debitMoveLine.getDebit().subtract(debitMoveLine.getAmountPaid()), creditMoveLine.getName(), creditMoveLine.getAccount().getLabel(), creditMoveLine.getCredit().subtract(creditMoveLine.getAmountPaid()));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine)

Example 7 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AccountingSituationInitServiceImpl method createSupplierAccount.

protected void createSupplierAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsSupplier() == Boolean.FALSE || situation.getSupplierAccount() != null)
        return;
    if (accountConfig.getSupplierAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getSupplierAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_4), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getSupplierAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_5), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getSupplierAccount(), accountConfig.getSupplierAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setSupplierAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 8 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AccountingSituationInitServiceImpl method createCustomerAccount.

protected void createCustomerAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsCustomer() == Boolean.FALSE || situation.getCustomerAccount() != null)
        return;
    if (accountConfig.getCustomerAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CUSTOMER_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getCustomerAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_1), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getCustomerAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_2), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getCustomerAccount(), accountConfig.getCustomerAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setCustomerAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 9 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AccountingSituationInitServiceImpl method createEmployeeAccount.

protected void createEmployeeAccount(AccountConfig accountConfig, AccountingSituation situation, int creationMode) throws AxelorException {
    Partner partner = situation.getPartner();
    if (partner.getIsEmployee() == Boolean.FALSE || situation.getEmployeeAccount() != null)
        return;
    if (accountConfig.getEmployeeAccount() == null) {
        throw new AxelorException(partner, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNT_CONFIG_40), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), situation.getCompany().getName());
    }
    final String accountCode;
    if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_PREFIX) {
        final String prefix = accountConfig.getEmployeeAccountPrefix();
        if (StringUtils.isBlank(prefix)) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_6), situation.getCompany().getName());
        }
        accountCode = getPrefixedAccountCode(prefix, partner);
    } else if (creationMode == AccountConfigRepository.AUTOMATIC_ACCOUNT_CREATION_SEQUENCE) {
        final Sequence sequence = accountConfig.getEmployeeAccountSequence();
        if (sequence == null) {
            throw new AxelorException(situation, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_7), situation.getCompany().getName());
        }
        accountCode = sequenceService.getSequenceNumber(sequence);
    } else {
        throw new AxelorException(situation, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.ACCOUNTING_SITUATION_3), situation.getCompany().getName());
    }
    Account account = this.createAccount(partner.getFullName(), accountCode, accountConfig.getEmployeeAccount(), accountConfig.getEmployeeAccount().getAccountType(), true, situation.getCompany(), true);
    situation.setEmployeeAccount(account);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Sequence(com.axelor.apps.base.db.Sequence) Partner(com.axelor.apps.base.db.Partner)

Example 10 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class AccountingReportServiceImpl method getSequence.

public String getSequence(AccountingReport accountingReport) throws AxelorException {
    SequenceService sequenceService = Beans.get(SequenceService.class);
    if (accountingReport.getReportType() == null) {
        throw new AxelorException(accountingReport, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_NO_REPORT_TYPE));
    }
    int accountingReportTypeSelect = accountingReport.getReportType().getTypeSelect();
    if (accountingReportTypeSelect >= 0 && accountingReportTypeSelect < 1000) {
        String seq = sequenceService.getSequenceNumber(SequenceRepository.ACCOUNTING_REPORT, accountingReport.getCompany());
        if (seq == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_1), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
        }
        return seq;
    } else if (accountingReportTypeSelect >= 1000 && accountingReportTypeSelect < 2000) {
        String seq = sequenceService.getSequenceNumber(SequenceRepository.MOVE_LINE_EXPORT, accountingReport.getCompany());
        if (seq == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_2), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
        }
        return seq;
    } else if (accountingReportTypeSelect >= 2000 && accountingReportTypeSelect < 3000) {
        String seq = sequenceService.getSequenceNumber(SequenceRepository.ANALYTIC_REPORT, accountingReport.getCompany());
        if (seq == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_ANALYTIC_REPORT), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
        }
        return seq;
    } else if (accountingReportTypeSelect == 3000) {
        String seq = sequenceService.getSequenceNumber(SequenceRepository.CUSTOM_ACCOUNTING_REPORT, accountingReport.getCompany());
        if (seq == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_7), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), accountingReport.getCompany().getName());
        }
        return seq;
    }
    throw new AxelorException(accountingReport, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.ACCOUNTING_REPORT_UNKNOWN_ACCOUNTING_REPORT_TYPE), accountingReport.getReportType().getTypeSelect());
}
Also used : AxelorException(com.axelor.exception.AxelorException) SequenceService(com.axelor.apps.base.service.administration.SequenceService)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27