Search in sources :

Example 1 with CurrencyService

use of com.axelor.apps.base.service.CurrencyService in project axelor-open-suite by axelor.

the class InvoicePaymentToolServiceImpl method computeAmountPaid.

protected BigDecimal computeAmountPaid(Invoice invoice) throws AxelorException {
    BigDecimal amountPaid = BigDecimal.ZERO;
    if (invoice.getInvoicePaymentList() == null) {
        return amountPaid;
    }
    CurrencyService currencyService = Beans.get(CurrencyService.class);
    Currency invoiceCurrency = invoice.getCurrency();
    for (InvoicePayment invoicePayment : invoice.getInvoicePaymentList()) {
        if (invoicePayment.getStatusSelect() == InvoicePaymentRepository.STATUS_VALIDATED) {
            log.debug("Amount paid without move : {}", invoicePayment.getAmount());
            amountPaid = amountPaid.add(currencyService.getAmountCurrencyConvertedAtDate(invoicePayment.getCurrency(), invoiceCurrency, invoicePayment.getAmount(), invoicePayment.getPaymentDate()));
        }
    }
    boolean isMinus = moveToolService.isMinus(invoice);
    if (isMinus) {
        amountPaid = amountPaid.negate();
    }
    log.debug("Amount paid total : {}", amountPaid);
    return amountPaid;
}
Also used : InvoicePayment(com.axelor.apps.account.db.InvoicePayment) Currency(com.axelor.apps.base.db.Currency) CurrencyService(com.axelor.apps.base.service.CurrencyService) BigDecimal(java.math.BigDecimal)

Aggregations

InvoicePayment (com.axelor.apps.account.db.InvoicePayment)1 Currency (com.axelor.apps.base.db.Currency)1 CurrencyService (com.axelor.apps.base.service.CurrencyService)1 BigDecimal (java.math.BigDecimal)1