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;
}
Aggregations