Search in sources :

Example 16 with Journal

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

the class MoveServiceImpl method createMoveUseExcessPayment.

@Override
public void createMoveUseExcessPayment(Invoice invoice) throws AxelorException {
    Company company = invoice.getCompany();
    // Récupération des acomptes de la facture
    List<MoveLine> creditMoveLineList = moveExcessPaymentService.getAdvancePaymentMoveList(invoice);
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    // Récupération des trop-perçus
    creditMoveLineList.addAll(moveExcessPaymentService.getExcessPayment(invoice));
    if (creditMoveLineList != null && creditMoveLineList.size() != 0) {
        Partner partner = invoice.getPartner();
        Account account = invoice.getPartnerAccount();
        MoveLine invoiceCustomerMoveLine = moveToolService.getCustomerMoveLineByLoop(invoice);
        Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
        // Si c'est le même compte sur les trop-perçus et sur la facture, alors on lettre directement
        if (moveToolService.isSameAccount(creditMoveLineList, account)) {
            List<MoveLine> debitMoveLineList = new ArrayList<MoveLine>();
            debitMoveLineList.add(invoiceCustomerMoveLine);
            paymentService.useExcessPaymentOnMoveLines(debitMoveLineList, creditMoveLineList);
        } else // Sinon on créée une O.D. pour passer du compte de la facture à un autre compte sur les
        // trop-perçus
        {
            log.debug("Création d'une écriture comptable O.D. spécifique à l'emploie des trop-perçus {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
            Move move = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
            if (move != null) {
                BigDecimal totalCreditAmount = moveToolService.getTotalCreditAmount(creditMoveLineList);
                BigDecimal amount = totalCreditAmount.min(invoiceCustomerMoveLine.getDebit());
                // Création de la ligne au crédit
                MoveLine creditMoveLine = moveLineService.createMoveLine(move, partner, account, amount, false, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
                move.getMoveLineList().add(creditMoveLine);
                // Emploie des trop-perçus sur les lignes de debit qui seront créées au fil de l'eau
                paymentService.useExcessPaymentWithAmountConsolidated(creditMoveLineList, amount, move, 2, partner, company, account, invoice.getInvoiceDate(), invoice.getDueDate());
                moveValidateService.validate(move);
                // Création de la réconciliation
                Reconcile reconcile = reconcileService.createReconcile(invoiceCustomerMoveLine, creditMoveLine, amount, false);
                if (reconcile != null) {
                    reconcileService.confirmReconcile(reconcile, true);
                }
            }
        }
        invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
    }
}
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) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ArrayList(java.util.ArrayList) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 17 with Journal

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

the class MoveServiceImpl method createMove.

/**
 * Créer une écriture comptable propre à la facture.
 *
 * @param invoice
 * @param consolidate
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
@Override
public Move createMove(Invoice invoice) throws AxelorException {
    Move move = null;
    if (invoice != null && invoice.getInvoiceLineList() != null) {
        Journal journal = invoice.getJournal();
        Company company = invoice.getCompany();
        Partner partner = invoice.getPartner();
        Account account = invoice.getPartnerAccount();
        log.debug("Création d'une écriture comptable spécifique à la facture {} (Société : {}, Journal : {})", new Object[] { invoice.getInvoiceId(), company.getName(), journal.getCode() });
        int functionalOrigin = Beans.get(InvoiceService.class).getPurchaseTypeOrSaleType(invoice);
        if (functionalOrigin == PriceListRepository.TYPE_PURCHASE) {
            functionalOrigin = MoveRepository.FUNCTIONAL_ORIGIN_PURCHASE;
        } else if (functionalOrigin == PriceListRepository.TYPE_SALE) {
            functionalOrigin = MoveRepository.FUNCTIONAL_ORIGIN_SALE;
        } else {
            functionalOrigin = 0;
        }
        move = moveCreateService.createMove(journal, company, invoice.getCurrency(), partner, invoice.getInvoiceDate(), invoice.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, functionalOrigin);
        if (move != null) {
            move.setInvoice(invoice);
            move.setTradingName(invoice.getTradingName());
            boolean isPurchase = InvoiceToolService.isPurchase(invoice);
            boolean isDebitCustomer = moveToolService.isDebitCustomer(invoice, false);
            move.getMoveLineList().addAll(moveLineService.createMoveLines(invoice, move, company, partner, account, journal.getIsInvoiceMoveConsolidated(), isPurchase, isDebitCustomer));
            moveRepository.save(move);
            invoice.setMove(move);
            invoice.setCompanyInTaxTotalRemaining(moveToolService.getInTaxTotalRemaining(invoice));
            moveValidateService.validate(move);
        }
    }
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 18 with Journal

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

the class MoveValidateService method checkPreconditions.

public void checkPreconditions(Move move) throws AxelorException {
    Journal journal = move.getJournal();
    Company company = move.getCompany();
    if (company == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.MOVE_3), move.getReference()));
    }
    if (journal == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.MOVE_2), move.getReference()));
    }
    if (move.getPeriod() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.MOVE_4), move.getReference()));
    }
    if (move.getMoveLineList() == null || move.getMoveLineList().isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, String.format(I18n.get(IExceptionMessage.MOVE_8), move.getReference()));
    }
    if (move.getMoveLineList().stream().allMatch(moveLine -> moveLine.getDebit().add(moveLine.getCredit()).compareTo(BigDecimal.ZERO) == 0)) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, String.format(I18n.get(IExceptionMessage.MOVE_8), move.getReference()));
    }
    MoveLineService moveLineService = Beans.get(MoveLineService.class);
    if (move.getFunctionalOriginSelect() != MoveRepository.FUNCTIONAL_ORIGIN_CLOSURE && move.getFunctionalOriginSelect() != MoveRepository.FUNCTIONAL_ORIGIN_OPENING) {
        for (MoveLine moveLine : move.getMoveLineList()) {
            Account account = moveLine.getAccount();
            if (account.getIsTaxAuthorizedOnMoveLine() && account.getIsTaxRequiredOnMoveLine() && moveLine.getTaxLine() == null) {
                throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.MOVE_9), account.getName(), moveLine.getName()));
            }
            if (moveLine.getAnalyticDistributionTemplate() == null && ObjectUtils.isEmpty(moveLine.getAnalyticMoveLineList()) && account.getAnalyticDistributionAuthorized() && account.getAnalyticDistributionRequiredOnMoveLines()) {
                throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.MOVE_10), account.getName(), moveLine.getName()));
            }
            if (account != null && !account.getAnalyticDistributionAuthorized() && (moveLine.getAnalyticDistributionTemplate() != null || (moveLine.getAnalyticMoveLineList() != null && !moveLine.getAnalyticMoveLineList().isEmpty()))) {
                throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, String.format(I18n.get(IExceptionMessage.MOVE_11), moveLine.getName()));
            }
            moveLineService.validateMoveLine(moveLine);
        }
        this.validateWellBalancedMove(move);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine) Journal(com.axelor.apps.account.db.Journal)

Example 19 with Journal

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

the class MoveAdjustementService method createAdjustmentDebitMove.

/**
 * Creating move of passage in gap regulation (on debit)
 *
 * @param debitMoveLine
 * @return
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createAdjustmentDebitMove(MoveLine debitMoveLine) throws AxelorException {
    Partner partner = debitMoveLine.getPartner();
    Account account = debitMoveLine.getAccount();
    Move debitMove = debitMoveLine.getMove();
    Company company = debitMove.getCompany();
    AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
    BigDecimal debitAmountRemaining = debitMoveLine.getAmountRemaining();
    Journal miscOperationJournal = accountConfigService.getAutoMiscOpeJournal(accountConfig);
    Move adjustmentMove = moveCreateService.createMove(miscOperationJournal, company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, debitMove.getFunctionalOriginSelect());
    // Création de la ligne au crédit
    MoveLine creditAdjustmentMoveLine = moveLineService.createMoveLine(adjustmentMove, partner, account, debitAmountRemaining, false, appAccountService.getTodayDate(company), 1, null, null);
    // Création de la ligne au debit
    MoveLine debitAdjustmentMoveLine = moveLineService.createMoveLine(adjustmentMove, partner, accountConfigService.getCashPositionVariationAccount(accountConfig), debitAmountRemaining, true, appAccountService.getTodayDate(company), 2, null, null);
    adjustmentMove.addMoveLineListItem(creditAdjustmentMoveLine);
    adjustmentMove.addMoveLineListItem(debitAdjustmentMoveLine);
    moveValidateService.validate(adjustmentMove);
    moveRepository.save(adjustmentMove);
}
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) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Transactional(com.google.inject.persist.Transactional)

Example 20 with Journal

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

the class BankReconciliationService method getAccountManagementCashAccounts.

protected Set<String> getAccountManagementCashAccounts(BankReconciliation bankReconciliation) {
    List<AccountManagement> accountManagementList;
    Journal journal = bankReconciliation.getJournal();
    Set<String> cashAccountIdSet = new HashSet<String>();
    BankDetails bankDetails = bankReconciliation.getBankDetails();
    if (journal != null) {
        accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1 AND self.journal = ?2", bankDetails, journal).fetch();
    } else {
        accountManagementList = accountManagementRepository.all().filter("self.bankDetails = ?1", bankDetails).fetch();
    }
    for (AccountManagement accountManagement : accountManagementList) {
        if (accountManagement.getCashAccount() != null) {
            cashAccountIdSet.add(accountManagement.getCashAccount().getId().toString());
        }
    }
    return cashAccountIdSet;
}
Also used : BankDetails(com.axelor.apps.base.db.BankDetails) Journal(com.axelor.apps.account.db.Journal) AccountManagement(com.axelor.apps.account.db.AccountManagement) HashSet(java.util.HashSet)

Aggregations

Journal (com.axelor.apps.account.db.Journal)35 Company (com.axelor.apps.base.db.Company)26 Move (com.axelor.apps.account.db.Move)24 MoveLine (com.axelor.apps.account.db.MoveLine)21 Account (com.axelor.apps.account.db.Account)18 Transactional (com.google.inject.persist.Transactional)18 BigDecimal (java.math.BigDecimal)18 Partner (com.axelor.apps.base.db.Partner)17 LocalDate (java.time.LocalDate)16 ArrayList (java.util.ArrayList)10 AccountConfig (com.axelor.apps.account.db.AccountConfig)9 BankDetails (com.axelor.apps.base.db.BankDetails)9 PaymentMode (com.axelor.apps.account.db.PaymentMode)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 AxelorException (com.axelor.exception.AxelorException)6 Query (javax.persistence.Query)5 Invoice (com.axelor.apps.account.db.Invoice)4 JournalType (com.axelor.apps.account.db.JournalType)4 Reconcile (com.axelor.apps.account.db.Reconcile)4 FixedAsset (com.axelor.apps.account.db.FixedAsset)2