Search in sources :

Example 26 with Reconcile

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

the class ReconcileGroupServiceImpl method mergeReconcileGroups.

@Override
@Transactional
public ReconcileGroup mergeReconcileGroups(List<ReconcileGroup> reconcileGroupList) {
    Company company = reconcileGroupList.get(0).getCompany();
    ReconcileGroup reconcileGroup = createReconcileGroup(company);
    List<Reconcile> reconcileList = reconcileRepository.all().filter("self.reconcileGroup.id IN (:reconcileGroupIds)").bind("reconcileGroupIds", reconcileGroupList.stream().map(ReconcileGroup::getId).collect(Collectors.toList())).fetch();
    reconcileList.forEach(reconcile -> addToReconcileGroup(reconcileGroup, reconcile));
    for (ReconcileGroup toDeleteReconcileGroup : reconcileGroupList) {
        reconcileGroupRepository.remove(toDeleteReconcileGroup);
    }
    return reconcileGroupRepository.save(reconcileGroup);
}
Also used : Company(com.axelor.apps.base.db.Company) ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 27 with Reconcile

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

the class ReconcileServiceImpl method reconcile.

/**
 * Méthode permettant de lettrer une écriture au débit avec une écriture au crédit
 *
 * @param debitMoveLine
 * @param creditMoveLine
 * @throws AxelorException
 */
public Reconcile reconcile(MoveLine debitMoveLine, MoveLine creditMoveLine, boolean canBeZeroBalanceOk, boolean updateInvoicePayments) throws AxelorException {
    BigDecimal amount = debitMoveLine.getAmountRemaining().min(creditMoveLine.getAmountRemaining());
    Reconcile reconcile = this.createReconcile(debitMoveLine, creditMoveLine, amount, canBeZeroBalanceOk);
    if (reconcile != null) {
        this.confirmReconcile(reconcile, updateInvoicePayments);
        return reconcile;
    }
    return null;
}
Also used : BigDecimal(java.math.BigDecimal) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 28 with Reconcile

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

the class ReconcileServiceImpl method canBeZeroBalance.

/**
 * Procédure permettant de gérer les écarts de règlement, check sur la case à cocher 'Peut être
 * soldé' Alors nous utilisons la règle de gestion consitant à imputer l'écart sur un compte
 * transitoire si le seuil est respecté
 *
 * @param reconcile Une reconciliation
 * @throws AxelorException
 */
@Transactional(rollbackOn = { Exception.class })
public void canBeZeroBalance(Reconcile reconcile) throws AxelorException {
    MoveLine debitMoveLine = reconcile.getDebitMoveLine();
    BigDecimal debitAmountRemaining = debitMoveLine.getAmountRemaining();
    log.debug("Montant à payer / à lettrer au débit : {}", debitAmountRemaining);
    if (debitAmountRemaining.compareTo(BigDecimal.ZERO) > 0) {
        Company company = reconcile.getDebitMoveLine().getMove().getCompany();
        AccountConfig accountConfig = accountConfigService.getAccountConfig(company);
        if (debitAmountRemaining.plus().compareTo(accountConfig.getThresholdDistanceFromRegulation()) < 0 || reconcile.getMustBeZeroBalanceOk()) {
            log.debug("Seuil respecté");
            MoveLine creditAdjustMoveLine = moveAdjustementService.createAdjustmentCreditMove(debitMoveLine);
            // Création de la réconciliation
            Reconcile newReconcile = this.createReconcile(debitMoveLine, creditAdjustMoveLine, debitAmountRemaining, false);
            if (newReconcile != null) {
                this.confirmReconcile(newReconcile, true);
                reconcileRepository.save(newReconcile);
            }
        }
    }
    reconcile.setCanBeZeroBalanceOk(false);
    log.debug("Fin de la gestion des écarts de règlement");
}
Also used : Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 29 with Reconcile

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

the class ReconcileServiceImpl method balanceCredit.

/**
 * Solder le trop-perçu si il respect les règles de seuil
 *
 * @param creditMoveLine
 * @param company
 * @throws AxelorException
 */
public void balanceCredit(MoveLine creditMoveLine) throws AxelorException {
    if (creditMoveLine != null) {
        BigDecimal creditAmountRemaining = creditMoveLine.getAmountRemaining();
        log.debug("Montant à payer / à lettrer au crédit : {}", creditAmountRemaining);
        if (creditAmountRemaining.compareTo(BigDecimal.ZERO) > 0) {
            AccountConfig accountConfig = accountConfigService.getAccountConfig(creditMoveLine.getMove().getCompany());
            if (creditAmountRemaining.plus().compareTo(accountConfig.getThresholdDistanceFromRegulation()) < 0) {
                log.debug("Seuil respecté");
                MoveLine debitAdjustmentMoveLine = moveAdjustementService.createAdjustmentCreditMove(creditMoveLine);
                // Création de la réconciliation
                Reconcile newReconcile = this.createReconcile(debitAdjustmentMoveLine, creditMoveLine, creditAmountRemaining, false);
                if (newReconcile != null) {
                    this.confirmReconcile(newReconcile, true);
                    reconcileRepository.save(newReconcile);
                }
            }
        }
    }
}
Also used : MoveLine(com.axelor.apps.account.db.MoveLine) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 30 with Reconcile

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

the class DoubtfulCustomerService method createDoubtFulCustomerRejectMove.

/**
 * Procédure permettant de créer les écritures de passage en client douteux pour chaque ligne
 * d'écriture de rejet de facture
 *
 * @param moveLine Une ligne d'écritures de rejet 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 createDoubtFulCustomerRejectMove(MoveLine moveLine, Account doubtfulCustomerAccount, String debtPassReason) throws AxelorException {
    log.debug("Ecriture concernée : {} ", moveLine.getName());
    Company company = moveLine.getMove().getCompany();
    Partner partner = moveLine.getPartner();
    LocalDate todayDate = appBaseService.getTodayDate(company);
    Move newMove = moveService.getMoveCreateService().createMove(company.getAccountConfig().getAutoMiscOpeJournal(), company, null, partner, moveLine.getMove().getPaymentMode(), MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
    BigDecimal amountRemaining = moveLine.getAmountRemaining();
    // Ecriture au crédit sur le 411
    MoveLine creditMoveLine = moveLineService.createMoveLine(newMove, partner, moveLine.getAccount(), amountRemaining, false, todayDate, 1, moveLine.getName(), debtPassReason);
    newMove.addMoveLineListItem(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(moveLine, creditMoveLine, amountRemaining, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    // Ecriture au débit sur le 416 (client douteux)
    MoveLine debitMoveLine = moveLineService.createMoveLine(newMove, newMove.getPartner(), doubtfulCustomerAccount, amountRemaining, true, todayDate, 2, moveLine.getName(), debtPassReason);
    newMove.getMoveLineList().add(debitMoveLine);
    debitMoveLine.setInvoiceReject(moveLine.getInvoiceReject());
    debitMoveLine.setPassageReason(debtPassReason);
    moveService.getMoveValidateService().validate(newMove);
    moveRepo.save(newMove);
    this.invoiceRejectProcess(debitMoveLine, doubtfulCustomerAccount, debtPassReason);
}
Also used : Company(com.axelor.apps.base.db.Company) 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