Currency conversion on dashboard completed payments is incorrect. #562

This commit is contained in:
Hillel Coren 2023-06-01 12:57:07 +03:00
parent 9b8d6ea8d4
commit 5fef99ac1b
1 changed files with 11 additions and 3 deletions

View File

@ -458,14 +458,22 @@ List<ChartDataGroup> chartPayments(
double completedAmount = payment.completedAmount; double completedAmount = payment.completedAmount;
double refunded = payment.refunded; double refunded = payment.refunded;
var invoice = InvoiceEntity();
if (payment.invoicePaymentables.isNotEmpty) {
final paymentable = payment.invoicePaymentables.first;
invoice = invoiceMap[paymentable.invoiceId] ?? InvoiceEntity();
}
// Handle "All" // Handle "All"
if (settings.currencyId == kCurrencyAll && if (settings.currencyId == kCurrencyAll &&
client.currencyId != company.currencyId) { client.currencyId != company.currencyId) {
final exchangeRate = payment.hasExchangeRate final exchangeRate = payment.hasExchangeRate
? payment.exchangeRate ? payment.exchangeRate
: getExchangeRate(currencyMap, : invoice.hasExchangeRate
fromCurrencyId: client.currencyId, ? invoice.exchangeRate
toCurrencyId: company.currencyId); : getExchangeRate(currencyMap,
fromCurrencyId: client.currencyId,
toCurrencyId: company.currencyId);
completedAmount *= exchangeRate; completedAmount *= exchangeRate;
refunded *= exchangeRate; refunded *= exchangeRate;
} }