Search in sources :

Example 46 with AccountConfig

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

the class MoveExcessPaymentService method getExcessPayment.

/**
 * Méthode permettant de récupérer les trop-perçus et une facture
 *
 * @param invoice Une facture
 * @return
 * @throws AxelorException
 */
public List<MoveLine> getExcessPayment(Invoice invoice) throws AxelorException {
    Company company = invoice.getCompany();
    AccountConfig accountConfig = Beans.get(AccountConfigService.class).getAccountConfig(company);
    // get advance payments
    List<MoveLine> advancePaymentMoveLines = Beans.get(InvoiceService.class).getMoveLinesFromAdvancePayments(invoice);
    MoveLine moveLine = getOrignalInvoiceMoveLine(invoice);
    if (moveLine != null) {
        advancePaymentMoveLines.add(moveLine);
    }
    if (accountConfig.getAutoReconcileOnInvoice()) {
        List<MoveLine> creditMoveLines = moveLineRepository.all().filter("self.move.company = ?1 AND (self.move.statusSelect = ?2 OR self.move.statusSelect = ?3) AND self.move.ignoreInAccountingOk IN (false,null)" + " AND self.account.useForPartnerBalance = ?4 AND self.credit > 0 and self.amountRemaining > 0" + " AND self.partner = ?5 ORDER BY self.date ASC", company, MoveRepository.STATUS_VALIDATED, MoveRepository.STATUS_ACCOUNTED, true, invoice.getPartner()).fetch();
        log.debug("Nombre de trop-perçus à imputer sur la facture récupéré : {}", creditMoveLines.size());
        advancePaymentMoveLines.addAll(creditMoveLines);
    }
    // remove duplicates
    advancePaymentMoveLines = advancePaymentMoveLines.stream().distinct().collect(Collectors.toList());
    return advancePaymentMoveLines;
}
Also used : Company(com.axelor.apps.base.db.Company) AccountConfigService(com.axelor.apps.account.service.config.AccountConfigService) MoveLine(com.axelor.apps.account.db.MoveLine) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Aggregations

AccountConfig (com.axelor.apps.account.db.AccountConfig)46 Company (com.axelor.apps.base.db.Company)27 Move (com.axelor.apps.account.db.Move)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 BigDecimal (java.math.BigDecimal)17 Account (com.axelor.apps.account.db.Account)14 Partner (com.axelor.apps.base.db.Partner)14 Transactional (com.google.inject.persist.Transactional)14 Journal (com.axelor.apps.account.db.Journal)9 AccountConfigService (com.axelor.apps.account.service.config.AccountConfigService)9 AxelorException (com.axelor.exception.AxelorException)9 AccountingSituation (com.axelor.apps.account.db.AccountingSituation)7 Reconcile (com.axelor.apps.account.db.Reconcile)7 BankDetails (com.axelor.apps.base.db.BankDetails)6 LocalDate (java.time.LocalDate)6 ArrayList (java.util.ArrayList)6 Invoice (com.axelor.apps.account.db.Invoice)5 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 List (java.util.List)4 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)3