Search in sources :

Example 21 with Reconcile

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

the class ReconcileManagementRepository method copy.

@Override
public Reconcile copy(Reconcile reconcile, boolean deep) {
    Reconcile copy = super.copy(reconcile, deep);
    copy.setCanBeZeroBalanceOk(false);
    copy.setMustBeZeroBalanceOk(false);
    copy.setReconcileSeq(null);
    copy.setStatusSelect(ReconcileRepository.STATUS_DRAFT);
    return copy;
}
Also used : Reconcile(com.axelor.apps.account.db.Reconcile)

Example 22 with Reconcile

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

the class PaymentScheduleLineBankPaymentServiceImpl method cancelInvoicePayments.

@Transactional(rollbackOn = { Exception.class })
protected void cancelInvoicePayments(PaymentScheduleLine paymentScheduleLine) throws AxelorException {
    MoveLineService moveLineService = moveService.getMoveLineService();
    PaymentSchedule paymentSchedule = paymentScheduleLine.getPaymentSchedule();
    MoveLine creditMoveLine = paymentScheduleLine.getAdvanceMoveLine();
    Set<Invoice> invoiceSet = MoreObjects.firstNonNull(paymentSchedule.getInvoiceSet(), Collections.emptySet());
    for (Invoice invoice : invoiceSet) {
        MoveLine debitMoveLine = moveLineService.getDebitCustomerMoveLine(invoice);
        Reconcile reconcile = reconcileRepo.findByMoveLines(debitMoveLine, creditMoveLine);
        if (reconcile == null) {
            continue;
        }
        for (InvoicePayment invoicePayment : invoicePaymentRepo.findByReconcile(reconcile).fetch()) {
            invoicePaymentCancelService.cancel(invoicePayment);
        }
    }
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) MoveLineService(com.axelor.apps.account.service.move.MoveLineService) Invoice(com.axelor.apps.account.db.Invoice) PaymentSchedule(com.axelor.apps.account.db.PaymentSchedule) MoveLine(com.axelor.apps.account.db.MoveLine) Reconcile(com.axelor.apps.account.db.Reconcile) Transactional(com.google.inject.persist.Transactional)

Example 23 with Reconcile

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

the class IrrecoverableService method createIrrecoverableMove.

/**
 * Fonction permettant de créer l'écriture de passage en irrécouvrable d'une échéance
 *
 * @param moveLine Une écriture d'échéance
 * @return
 * @throws AxelorException
 */
public Move createIrrecoverableMove(MoveLine moveLine, String irrecoverableName) throws AxelorException {
    Company company = moveLine.getMove().getCompany();
    Partner payerPartner = moveLine.getPartner();
    BigDecimal amount = moveLine.getAmountRemaining();
    AccountConfig accountConfig = company.getAccountConfig();
    // Move
    Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
    int seq = 1;
    // Credit MoveLine Customer account (411, 416, ...)
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, moveLine.getAccount(), amount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(moveLine, creditMoveLine, amount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    Tax tax = accountConfig.getIrrecoverableStandardRateTax();
    BigDecimal taxRate = taxService.getTaxRate(tax, appAccountService.getTodayDate(company));
    // Debit MoveLine 654. (irrecoverable account)
    BigDecimal divid = taxRate.add(BigDecimal.ONE);
    BigDecimal irrecoverableAmount = amount.divide(divid, 6, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
    MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), irrecoverableAmount, true, appAccountService.getTodayDate(company), 2, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine1);
    // Debit MoveLine 445 (Tax account)
    Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
    BigDecimal taxAmount = amount.subtract(irrecoverableAmount);
    MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, payerPartner, taxAccount, taxAmount, true, appAccountService.getTodayDate(company), 3, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine2);
    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) MoveLine(com.axelor.apps.account.db.MoveLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) Tax(com.axelor.apps.account.db.Tax) 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 24 with Reconcile

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

the class IrrecoverableService method createIrrecoverableMove.

/**
 * Fonction permettant de créer l'écriture de passage en irrécouvrable d'une facture
 *
 * @param invoice Une facture
 * @param prorataRate Le taux de restant à payer sur la facture
 * @param isInvoiceReject La facture est-elle rejetée?
 * @return
 * @throws AxelorException
 */
public Move createIrrecoverableMove(Invoice invoice, BigDecimal prorataRate, boolean isInvoiceReject, String irrecoverableName) throws AxelorException {
    Company company = invoice.getCompany();
    Partner payerPartner = invoice.getPartner();
    AccountConfig accountConfig = company.getAccountConfig();
    // Move
    Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_SALE);
    int seq = 1;
    BigDecimal amount = BigDecimal.ZERO;
    MoveLine debitMoveLine = null;
    BigDecimal creditAmount = null;
    BigDecimal debitAmount = null;
    if (isInvoiceReject) {
        creditAmount = invoice.getRejectMoveLine().getAmountRemaining();
        debitAmount = creditAmount;
    } else {
        creditAmount = invoice.getCompanyInTaxTotalRemaining();
        debitAmount = creditAmount;
    }
    // Debits MoveLines Tva
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        amount = (invoiceLineTax.getTaxTotal().multiply(prorataRate)).setScale(2, RoundingMode.HALF_UP);
        // do not generate move line with amount equal to zero
        if (amount.signum() == 0) {
            continue;
        }
        debitMoveLine = moveLineService.createMoveLine(move, payerPartner, taxAccountService.getAccount(invoiceLineTax.getTaxLine().getTax(), company, false, false), amount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
        move.getMoveLineList().add(debitMoveLine);
        seq++;
        debitAmount = debitAmount.subtract(amount);
    }
    // Debit MoveLine 654 (irrecoverable account)
    debitMoveLine = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), debitAmount, true, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
    move.getMoveLineList().add(debitMoveLine);
    seq++;
    // Getting customer MoveLine from Facture
    MoveLine customerMoveLine = moveService.getMoveToolService().getCustomerMoveLineByQuery(invoice);
    if (customerMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.IRRECOVERABLE_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION), invoice.getInvoiceId());
    }
    customerMoveLine.setIrrecoverableStatusSelect(MoveLineRepository.IRRECOVERABLE_STATUS_PASSED_IN_IRRECOUVRABLE);
    // Credit MoveLine Customer account (411, 416, ...)
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, customerMoveLine.getAccount(), creditAmount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, invoice.getInvoiceId());
    move.getMoveLineList().add(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(customerMoveLine, creditMoveLine, creditAmount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    return move;
}
Also used : AxelorException(com.axelor.exception.AxelorException) 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) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Example 25 with Reconcile

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

the class ReconcileGroupServiceImpl method remove.

@Override
public void remove(Reconcile reconcile) throws AxelorException {
    ReconcileGroup reconcileGroup = reconcile.getReconcileGroup();
    // update move lines
    List<MoveLine> moveLineToRemoveList = moveLineRepository.findByReconcileGroup(reconcileGroup).fetch();
    moveLineToRemoveList.forEach(moveLine -> moveLine.setReconcileGroup(null));
    List<Reconcile> reconcileList = this.getReconcileList(reconcileGroup);
    reconcileList.stream().map(Reconcile::getDebitMoveLine).forEach(moveLine -> moveLine.setReconcileGroup(reconcileGroup));
    reconcileList.stream().map(Reconcile::getCreditMoveLine).forEach(moveLine -> moveLine.setReconcileGroup(reconcileGroup));
    // update status
    updateStatus(reconcileGroup);
}
Also used : ReconcileGroup(com.axelor.apps.account.db.ReconcileGroup) MoveLine(com.axelor.apps.account.db.MoveLine) 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