Search in sources :

Example 6 with Reconcile

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

the class ReconcileController method unreconcile.

// Unreconcile button
public void unreconcile(ActionRequest request, ActionResponse response) {
    Reconcile reconcile = request.getContext().asType(Reconcile.class);
    try {
        Beans.get(ReconcileService.class).unreconcile(Beans.get(ReconcileRepository.class).find(reconcile.getId()));
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ReconcileService(com.axelor.apps.account.service.ReconcileService) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 7 with Reconcile

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

the class MoveServiceImpl method generateReverse.

@Transactional(rollbackOn = { Exception.class })
@Override
public Move generateReverse(Move move, boolean isAutomaticReconcile, boolean isAutomaticAccounting, boolean isUnreconcileOriginalMove, LocalDate dateOfReversion) throws AxelorException {
    Move newMove = moveCreateService.createMove(move.getJournal(), move.getCompany(), move.getCurrency(), move.getPartner(), dateOfReversion, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_ENTRY, move.getFunctionalOriginSelect(), move.getIgnoreInDebtRecoveryOk(), move.getIgnoreInAccountingOk(), move.getAutoYearClosureMove());
    move.setInvoice(move.getInvoice());
    move.setPaymentVoucher(move.getPaymentVoucher());
    boolean validatedMove = move.getStatusSelect() == MoveRepository.STATUS_ACCOUNTED || move.getStatusSelect() == MoveRepository.STATUS_VALIDATED;
    for (MoveLine moveLine : move.getMoveLineList()) {
        log.debug("Moveline {}", moveLine);
        Boolean isDebit = moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0;
        MoveLine newMoveLine = generateReverseMoveLine(newMove, moveLine, dateOfReversion, isDebit);
        if (moveLine.getAnalyticDistributionTemplate() != null) {
            newMoveLine.setAnalyticDistributionTemplate(moveLine.getAnalyticDistributionTemplate());
            List<AnalyticMoveLine> analyticMoveLineList = Beans.get(AnalyticMoveLineService.class).generateLines(newMoveLine.getAnalyticDistributionTemplate(), newMoveLine.getDebit().add(newMoveLine.getCredit()), AnalyticMoveLineRepository.STATUS_REAL_ACCOUNTING, dateOfReversion);
            if (CollectionUtils.isNotEmpty(analyticMoveLineList)) {
                analyticMoveLineList.forEach(analyticMoveLine -> newMoveLine.addAnalyticMoveLineListItem(analyticMoveLine));
            }
        }
        newMove.addMoveLineListItem(newMoveLine);
        if (isUnreconcileOriginalMove) {
            List<Reconcile> reconcileList = Beans.get(ReconcileRepository.class).all().filter("self.statusSelect != ?1 AND (self.debitMoveLine = ?2 OR self.creditMoveLine = ?2)", ReconcileRepository.STATUS_CANCELED, moveLine).fetch();
            for (Reconcile reconcile : reconcileList) {
                reconcileService.unreconcile(reconcile);
            }
        }
        if (validatedMove && isAutomaticReconcile) {
            if (isDebit) {
                reconcileService.reconcile(moveLine, newMoveLine, false, true);
            } else {
                reconcileService.reconcile(newMoveLine, moveLine, false, true);
            }
        }
    }
    if (validatedMove && isAutomaticAccounting) {
        moveValidateService.validate(newMove);
    }
    return moveRepository.save(newMove);
}
Also used : Move(com.axelor.apps.account.db.Move) AnalyticMoveLineService(com.axelor.apps.account.service.AnalyticMoveLineService) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) ReconcileRepository(com.axelor.apps.account.db.repo.ReconcileRepository) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 8 with Reconcile

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

the class MoveServiceImpl method createMoveUseDebit.

@Override
public Move createMoveUseDebit(Invoice invoice, List<MoveLine> debitMoveLines, MoveLine invoiceCustomerMoveLine) throws AxelorException {
    Company company = invoice.getCompany();
    Partner partner = invoice.getPartner();
    Account account = invoice.getPartnerAccount();
    Journal journal = accountConfigService.getAutoMiscOpeJournal(accountConfigService.getAccountConfig(company));
    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() });
    BigDecimal remainingAmount = invoice.getInTaxTotal().abs();
    log.debug("Montant à payer avec l'avoir récupéré : {}", remainingAmount);
    Move oDmove = moveCreateService.createMove(journal, company, null, partner, invoice.getInvoiceDate(), null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
    if (oDmove != null) {
        BigDecimal totalDebitAmount = moveToolService.getTotalDebitAmount(debitMoveLines);
        BigDecimal amount = totalDebitAmount.min(invoiceCustomerMoveLine.getCredit());
        // Création de la ligne au débit
        MoveLine debitMoveLine = moveLineService.createMoveLine(oDmove, partner, account, amount, true, appAccountService.getTodayDate(company), 1, invoice.getInvoiceId(), null);
        oDmove.getMoveLineList().add(debitMoveLine);
        // Emploie des dûs sur les lignes de credit qui seront créées au fil de l'eau
        paymentService.createExcessPaymentWithAmount(debitMoveLines, amount, oDmove, 2, partner, company, null, account, appAccountService.getTodayDate(company));
        moveValidateService.validate(oDmove);
        // Création de la réconciliation
        Reconcile reconcile = reconcileService.createReconcile(debitMoveLine, invoiceCustomerMoveLine, amount, false);
        if (reconcile != null) {
            reconcileService.confirmReconcile(reconcile, true);
        }
    }
    return oDmove;
}
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) Journal(com.axelor.apps.account.db.Journal) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 9 with Reconcile

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

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

the class InvoicePaymentCreateServiceImpl method determineIfReconcileFromInvoice.

/**
 * We try to get to the status of the invoice from the reconcile to see if this move was created
 * from a payment for an advance payment invoice.
 *
 * @param move
 * @return the found advance invoice if the move is from a payment that comes from this invoice.
 *     null in other cases
 */
protected Invoice determineIfReconcileFromInvoice(Move move) {
    List<MoveLine> moveLineList = move.getMoveLineList();
    if (moveLineList == null || moveLineList.size() != 2) {
        return null;
    }
    InvoicePaymentRepository invoicePaymentRepo = Beans.get(InvoicePaymentRepository.class);
    for (MoveLine moveLine : moveLineList) {
        // search for the reconcile between the debit line
        if (moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
            Reconcile reconcile = Beans.get(ReconcileRepository.class).all().filter("self.debitMoveLine = ?", moveLine).fetchOne();
            if (reconcile == null) {
                return null;
            }
            // associated payment
            if (reconcile.getCreditMoveLine() == null || reconcile.getCreditMoveLine().getMove() == null) {
                continue;
            }
            Move candidatePaymentMove = reconcile.getCreditMoveLine().getMove();
            InvoicePayment invoicePayment = invoicePaymentRepo.all().filter("self.move = :_move").bind("_move", candidatePaymentMove).fetchOne();
            // payment, then return true.
            if (invoicePayment != null && invoicePayment.getInvoice() != null && invoicePayment.getInvoice().getOperationSubTypeSelect() == InvoiceRepository.OPERATION_SUB_TYPE_ADVANCE) {
                return invoicePayment.getInvoice();
            }
        }
    }
    return null;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) ReconcileRepository(com.axelor.apps.account.db.repo.ReconcileRepository) InvoicePaymentRepository(com.axelor.apps.account.db.repo.InvoicePaymentRepository) Reconcile(com.axelor.apps.account.db.Reconcile)

Aggregations

Reconcile (com.axelor.apps.account.db.Reconcile)30 MoveLine (com.axelor.apps.account.db.MoveLine)21 BigDecimal (java.math.BigDecimal)18 Transactional (com.google.inject.persist.Transactional)14 Move (com.axelor.apps.account.db.Move)13 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)10 Account (com.axelor.apps.account.db.Account)7 AccountConfig (com.axelor.apps.account.db.AccountConfig)7 Invoice (com.axelor.apps.account.db.Invoice)4 Journal (com.axelor.apps.account.db.Journal)4 LocalDate (java.time.LocalDate)4 ArrayList (java.util.ArrayList)4 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)3 ReconcileGroup (com.axelor.apps.account.db.ReconcileGroup)3 ReconcileRepository (com.axelor.apps.account.db.repo.ReconcileRepository)3 InvoiceLineTax (com.axelor.apps.account.db.InvoiceLineTax)2 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)2 PaymentMode (com.axelor.apps.account.db.PaymentMode)2 PaymentSchedule (com.axelor.apps.account.db.PaymentSchedule)2