Search in sources :

Example 1 with Reconcile

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

the class ReimbursementExportService method createReimbursementMove.

/**
 * Methode permettant de créer l'écriture de remboursement
 *
 * @param reimbursement Un objet d'export des prélèvements
 * @throws AxelorException
 */
public void createReimbursementMove(Reimbursement reimbursement, Company company) throws AxelorException {
    reimbursement = reimbursementRepo.find(reimbursement.getId());
    Partner partner = null;
    Move newMove = null;
    boolean first = true;
    AccountConfig accountConfig = company.getAccountConfig();
    if (reimbursement.getMoveLineSet() != null && !reimbursement.getMoveLineSet().isEmpty()) {
        int seq = 1;
        for (MoveLine moveLine : reimbursement.getMoveLineSet()) {
            BigDecimal amountRemaining = moveLine.getAmountRemaining();
            if (amountRemaining.compareTo(BigDecimal.ZERO) > 0) {
                partner = moveLine.getPartner();
                // On passe les lignes d'écriture (trop perçu) à l'état 'remboursé'
                moveLine.setReimbursementStatusSelect(MoveLineRepository.REIMBURSEMENT_STATUS_REIMBURSED);
                if (first) {
                    newMove = moveService.getMoveCreateService().createMove(accountConfig.getReimbursementJournal(), company, null, partner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_PAYMENT);
                    first = false;
                }
                // Création d'une ligne au débit
                MoveLine newDebitMoveLine = moveLineService.createMoveLine(newMove, partner, moveLine.getAccount(), amountRemaining, true, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
                newMove.getMoveLineList().add(newDebitMoveLine);
                if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
                    newDebitMoveLine.setDescription(reimbursement.getDescription());
                }
                seq++;
                // Création de la réconciliation
                Reconcile reconcile = reconcileService.createReconcile(newDebitMoveLine, moveLine, amountRemaining, false);
                if (reconcile != null) {
                    reconcileService.confirmReconcile(reconcile, true);
                }
            }
        }
        // Création de la ligne au crédit
        MoveLine newCreditMoveLine = moveLineService.createMoveLine(newMove, partner, accountConfig.getReimbursementAccount(), reimbursement.getAmountReimbursed(), false, appAccountService.getTodayDate(company), seq, reimbursement.getRef(), reimbursement.getDescription());
        newMove.getMoveLineList().add(newCreditMoveLine);
        if (reimbursement.getDescription() != null && !reimbursement.getDescription().isEmpty()) {
            newCreditMoveLine.setDescription(reimbursement.getDescription());
        }
        moveService.getMoveValidateService().validate(newMove);
        moveRepo.save(newMove);
    }
}
Also used : Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) 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 2 with Reconcile

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

the class ReconcileGroupServiceImpl method isBalanced.

@Override
public boolean isBalanced(List<Reconcile> reconcileList) {
    List<MoveLine> debitMoveLineList = reconcileList.stream().map(Reconcile::getDebitMoveLine).distinct().collect(Collectors.toList());
    List<MoveLine> creditMoveLineList = reconcileList.stream().map(Reconcile::getCreditMoveLine).distinct().collect(Collectors.toList());
    List<Account> accountList = debitMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList());
    accountList.addAll(creditMoveLineList.stream().map(MoveLine::getAccount).distinct().collect(Collectors.toList()));
    for (Account account : accountList) {
        BigDecimal totalDebit = debitMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getDebit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        BigDecimal totalCredit = creditMoveLineList.stream().filter(moveLine -> moveLine.getAccount().equals(account)).map(MoveLine::getCredit).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
        if (totalDebit.compareTo(totalCredit) != 0) {
            return false;
        }
    }
    return true;
}
Also used : Company(com.axelor.apps.base.db.Company) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) ReconcileRepository(com.axelor.apps.account.db.repo.ReconcileRepository) Inject(com.google.inject.Inject) ReconcileGroupRepository(com.axelor.apps.account.db.repo.ReconcileGroupRepository) Reconcile(com.axelor.apps.account.db.Reconcile) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) Account(com.axelor.apps.account.db.Account) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) BigDecimal(java.math.BigDecimal) List(java.util.List) ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) CollectionUtils(org.apache.commons.collections.CollectionUtils) I18n(com.axelor.i18n.I18n) Optional(java.util.Optional) MoveLineRepository(com.axelor.apps.account.db.repo.MoveLineRepository) Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 3 with Reconcile

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

the class ReconcileGroupServiceImpl method unletter.

@Override
@Transactional(rollbackOn = { Exception.class })
public void unletter(ReconcileGroup reconcileGroup) throws AxelorException {
    List<Reconcile> reconcileList = this.getReconcileList(reconcileGroup);
    for (Reconcile reconcile : reconcileList) {
        reconcileService.unreconcile(reconcile);
    }
    reconcileGroup.setUnletteringDate(appBaseService.getTodayDate(reconcileGroup.getCompany()));
    reconcileGroup.setStatusSelect(ReconcileGroupRepository.STATUS_UNLETTERED);
    reconcileGroupRepository.save(reconcileGroup);
}
Also used : Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 4 with Reconcile

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

the class ReconcileServiceImpl method createReconcile.

/**
 * Permet de créer une réconciliation en passant les paramètres qu'il faut
 *
 * @param lineDebit Une ligne d'écriture au débit
 * @param lineCredit Une ligne d'écriture au crédit
 * @param amount Le montant à reconciler
 * @param canBeZeroBalanceOk Peut être soldé?
 * @return Une reconciliation
 */
@Transactional
public Reconcile createReconcile(MoveLine debitMoveLine, MoveLine creditMoveLine, BigDecimal amount, boolean canBeZeroBalanceOk) {
    if (ReconcileService.isReconcilable(debitMoveLine, creditMoveLine) && amount.compareTo(BigDecimal.ZERO) > 0) {
        log.debug("Create Reconcile (Company : {}, Debit MoveLine : {}, Credit MoveLine : {}, Amount : {}, Can be zero balance ? {} )", debitMoveLine.getMove().getCompany(), debitMoveLine.getName(), creditMoveLine.getName(), amount, canBeZeroBalanceOk);
        Reconcile reconcile = new Reconcile(debitMoveLine.getMove().getCompany(), amount.setScale(2, RoundingMode.HALF_UP), debitMoveLine, creditMoveLine, ReconcileRepository.STATUS_DRAFT, canBeZeroBalanceOk);
        if (!moveToolService.isDebitMoveLine(debitMoveLine)) {
            reconcile.setDebitMoveLine(creditMoveLine);
            reconcile.setCreditMoveLine(debitMoveLine);
        }
        return reconcileRepository.save(reconcile);
    }
    return null;
}
Also used : Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 5 with Reconcile

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

the class DoubtfulCustomerService method createDoubtFulCustomerMove.

/**
 * Procédure permettant de créer les écritures de passage en client douteux pour chaque écriture
 * de facture
 *
 * @param move Une écritures de facture
 * @param doubtfulCustomerAccount Un compte client douteux
 * @param debtPassReason Un motif de passage en client douteux
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void createDoubtFulCustomerMove(Move move, Account doubtfulCustomerAccount, String debtPassReason) throws AxelorException {
    log.debug("Concerned account move : {} ", move.getReference());
    Company company = move.getCompany();
    Partner partner = move.getPartner();
    Invoice invoice = move.getInvoice();
    Move newMove = moveService.getMoveCreateService().createMove(company.getAccountConfig().getAutoMiscOpeJournal(), company, invoice.getCurrency(), partner, move.getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, move.getFunctionalOriginSelect());
    newMove.setInvoice(invoice);
    LocalDate todayDate = appBaseService.getTodayDate(company);
    MoveLine invoicePartnerMoveLine = null;
    for (MoveLine moveLine : move.getMoveLineList()) {
        if (moveLine.getAccount().getUseForPartnerBalance() && moveLine.getAmountRemaining().compareTo(BigDecimal.ZERO) > 0 && moveLine.getAccount() != doubtfulCustomerAccount && moveLine.getDebit().compareTo(BigDecimal.ZERO) > 0) {
            invoicePartnerMoveLine = moveLine;
        }
    }
    String origin = "";
    BigDecimal amountRemaining = BigDecimal.ZERO;
    MoveLine creditMoveLine = null;
    if (invoicePartnerMoveLine != null) {
        amountRemaining = invoicePartnerMoveLine.getAmountRemaining();
        // Debit move line on partner account
        creditMoveLine = moveLineService.createMoveLine(newMove, partner, invoicePartnerMoveLine.getAccount(), amountRemaining, false, todayDate, 1, move.getInvoice().getInvoiceId(), debtPassReason);
        newMove.getMoveLineList().add(creditMoveLine);
        origin = creditMoveLine.getOrigin();
    }
    // Credit move line on partner account
    MoveLine debitMoveLine = moveLineService.createMoveLine(newMove, partner, doubtfulCustomerAccount, amountRemaining, true, todayDate, 2, origin, debtPassReason);
    newMove.getMoveLineList().add(debitMoveLine);
    debitMoveLine.setPassageReason(debtPassReason);
    moveService.getMoveValidateService().validate(newMove);
    moveRepo.save(newMove);
    if (creditMoveLine != null) {
        Reconcile reconcile = reconcileService.createReconcile(invoicePartnerMoveLine, creditMoveLine, amountRemaining, false);
        if (reconcile != null) {
            reconcileService.confirmReconcile(reconcile, true);
        }
    }
    this.invoiceProcess(newMove, doubtfulCustomerAccount, debtPassReason);
}
Also used : Company(com.axelor.apps.base.db.Company) Invoice(com.axelor.apps.account.db.Invoice) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

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