Search in sources :

Example 6 with Account

use of com.axelor.apps.account.db.Account 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 7 with Account

use of com.axelor.apps.account.db.Account 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 8 with Account

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

the class BatchDoubtfulCustomer method process.

@SuppressWarnings("unchecked")
@Override
protected void process() {
    if (!end) {
        Company company = batch.getAccountingBatch().getCompany();
        AccountConfig accountConfig = company.getAccountConfig();
        Account doubtfulCustomerAccount = accountConfig.getDoubtfulCustomerAccount();
        String sixMonthDebtPassReason = accountConfig.getSixMonthDebtPassReason();
        String threeMonthDebtPassReason = accountConfig.getThreeMonthDebtPassReason();
        // FACTURES
        List<Move> moveList = doubtfulCustomerService.getMove(0, doubtfulCustomerAccount, company);
        log.debug("Nombre d'écritures de facture concernées (Créance de + 6 mois) au 411 : {} ", moveList.size());
        this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, sixMonthDebtPassReason);
        moveList = doubtfulCustomerService.getMove(1, doubtfulCustomerAccount, company);
        log.debug("Nombre d'écritures de facture concernées (Créance de + 3 mois) au 411 : {} ", moveList.size());
        this.createDoubtFulCustomerMove(moveList, doubtfulCustomerAccount, threeMonthDebtPassReason);
        // FACTURES REJETES
        List<MoveLine> moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(0, doubtfulCustomerAccount, company);
        log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 6 mois) au 411 : {} ", moveLineList.size());
        this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, sixMonthDebtPassReason);
        moveLineList = (List<MoveLine>) doubtfulCustomerService.getRejectMoveLine(1, doubtfulCustomerAccount, company);
        log.debug("Nombre de lignes d'écriture de rejet concernées (Créance de + 3 mois) au 411 : {} ", moveLineList.size());
        this.createDoubtFulCustomerRejectMove(moveLineList, doubtfulCustomerAccount, threeMonthDebtPassReason);
        updateCustomerAccountLog += batchAccountCustomer.updateAccountingSituationMarked(companyRepo.find(company.getId()));
    }
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) List(java.util.List) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 9 with Account

use of com.axelor.apps.account.db.Account 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 10 with Account

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

the class FixedAssetLineMoveServiceImpl method generateDisposalMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generateDisposalMove(FixedAssetLine fixedAssetLine) throws AxelorException {
    FixedAsset fixedAsset = fixedAssetLine.getFixedAsset();
    Journal journal = fixedAsset.getJournal();
    Company company = fixedAsset.getCompany();
    Partner partner = fixedAsset.getPartner();
    LocalDate date = fixedAssetLine.getDepreciationDate();
    // Creating move
    Move move = moveCreateService.createMove(journal, company, company.getCurrency(), partner, date, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_FIXED_ASSET);
    if (move != null) {
        List<MoveLine> moveLines = new ArrayList<MoveLine>();
        String origin = fixedAsset.getReference();
        Account chargeAccount = fixedAsset.getFixedAssetCategory().getChargeAccount();
        Account depreciationAccount = fixedAsset.getFixedAssetCategory().getDepreciationAccount();
        Account purchaseAccount = fixedAsset.getPurchaseAccount();
        BigDecimal chargeAmount = fixedAssetLine.getResidualValue();
        BigDecimal cumulativeDepreciationAmount = fixedAssetLine.getCumulativeDepreciation();
        // Creating accounting debit move line for charge account
        MoveLine chargeAccountDebitMoveLine = new MoveLine(move, partner, chargeAccount, date, null, 1, chargeAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(chargeAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), chargeAccountDebitMoveLine);
        // Creating accounting debit move line for deprecation account
        MoveLine deprecationAccountDebitMoveLine = new MoveLine(move, partner, depreciationAccount, date, null, 1, cumulativeDepreciationAmount, BigDecimal.ZERO, fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(deprecationAccountDebitMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), deprecationAccountDebitMoveLine);
        // Creating accounting credit move line
        MoveLine creditMoveLine = new MoveLine(move, partner, purchaseAccount, date, null, 2, BigDecimal.ZERO, fixedAsset.getGrossValue(), fixedAsset.getName(), origin, null, BigDecimal.ZERO, date);
        moveLines.add(creditMoveLine);
        this.addAnalyticToMoveLine(fixedAsset.getAnalyticDistributionTemplate(), creditMoveLine);
        move.getMoveLineList().addAll(moveLines);
    }
    moveRepo.save(move);
    fixedAsset.setDisposalMove(move);
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) FixedAsset(com.axelor.apps.account.db.FixedAsset) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

Account (com.axelor.apps.account.db.Account)59 MoveLine (com.axelor.apps.account.db.MoveLine)27 Company (com.axelor.apps.base.db.Company)26 BigDecimal (java.math.BigDecimal)26 Partner (com.axelor.apps.base.db.Partner)25 Move (com.axelor.apps.account.db.Move)21 AxelorException (com.axelor.exception.AxelorException)20 Journal (com.axelor.apps.account.db.Journal)18 Transactional (com.google.inject.persist.Transactional)18 AccountConfig (com.axelor.apps.account.db.AccountConfig)14 LocalDate (java.time.LocalDate)12 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)10 ArrayList (java.util.ArrayList)10 TaxLine (com.axelor.apps.account.db.TaxLine)8 Invoice (com.axelor.apps.account.db.Invoice)7 Reconcile (com.axelor.apps.account.db.Reconcile)7 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 BankDetails (com.axelor.apps.base.db.BankDetails)6 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 Product (com.axelor.apps.base.db.Product)5