mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:17:30 -04:00
Independent scaling for multi currency data visualizations #1983
This commit is contained in:
parent
d0d510331a
commit
ef93f35bd9
@ -161,4 +161,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function convertCurrency(amount, fromCurrencyId, toCurrencyId) {
|
||||
return fx.convert(amount, {
|
||||
from: currencyMap[fromCurrencyId].code,
|
||||
to: currencyMap[toCurrencyId].code,
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
@ -74,6 +74,7 @@
|
||||
// pre-process the possible groupings (clients, invoices and products)
|
||||
var clients = data.concat();
|
||||
var invoices = _.flatten(_.pluck(clients, 'invoices'));
|
||||
var accountCurrencyId = {{ auth()->user()->account->getCurrencyId() }};
|
||||
|
||||
// remove quotes and recurring invoices
|
||||
invoices = _.filter(invoices, function(invoice) {
|
||||
@ -86,7 +87,7 @@
|
||||
var products = _.flatten(_.pluck(invoices, 'invoice_items'));
|
||||
products = d3.nest()
|
||||
.key(function(d) {
|
||||
return d.product_key + (d.invoice.client.currency && d.invoice.client.currency_id != {{ auth()->user()->account->currency_id }} ?
|
||||
return d.product_key + (d.invoice.client.currency && d.invoice.client.currency_id != accountCurrencyId ?
|
||||
' [' + d.invoice.client.currency.code + ']'
|
||||
: '');
|
||||
})
|
||||
@ -118,31 +119,47 @@
|
||||
|
||||
// create standardized display properties
|
||||
_.each(clients, function(client) {
|
||||
console.log('paid: %s, balance: %s', client.paid_to_date, client.balance);
|
||||
var currencyId = client.currency_id || {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY) }};
|
||||
var total = +client.paid_to_date + +client.balance;
|
||||
if (currencyId != accountCurrencyId) {
|
||||
total = convertCurrency(total, currencyId, accountCurrencyId);
|
||||
}
|
||||
client.displayName = getClientDisplayName(client);
|
||||
client.displayTotal = +client.paid_to_date + +client.balance;
|
||||
client.displayTotal = total;
|
||||
client.displayBalance = +client.balance;
|
||||
client.displayPercent = (+client.paid_to_date / (+client.paid_to_date + +client.balance)).toFixed(2);
|
||||
var oldestInvoice = _.max(client.invoices, function(invoice) { return calculateInvoiceAge(invoice) });
|
||||
client.displayAge = oldestInvoice ? calculateInvoiceAge(oldestInvoice) : -1;
|
||||
client.currencyId = client.currency_id || {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY) }};
|
||||
client.currencyId = currencyId;
|
||||
});
|
||||
|
||||
_.each(invoices, function(invoice) {
|
||||
var currencyId = invoice.client.currency_id || {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY) }};
|
||||
var total = +invoice.amount;
|
||||
if (currencyId != accountCurrencyId) {
|
||||
total = convertCurrency(total, currencyId, accountCurrencyId);
|
||||
}
|
||||
invoice.displayName = invoice.invoice_number;
|
||||
invoice.displayTotal = +invoice.amount;
|
||||
invoice.displayTotal = total;
|
||||
invoice.displayBalance = +invoice.balance;
|
||||
invoice.displayPercent = (+invoice.amount - +invoice.balance) / +invoice.amount;
|
||||
invoice.displayAge = calculateInvoiceAge(invoice);
|
||||
invoice.currencyId = invoice.client.currency_id || {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY) }};
|
||||
invoice.currencyId = currencyId;
|
||||
});
|
||||
|
||||
_.each(products, function(product) {
|
||||
var currencyId = product.values.currency_id;
|
||||
var total = product.values.amount;
|
||||
if (currencyId != accountCurrencyId) {
|
||||
total = convertCurrency(total, currencyId, accountCurrencyId);
|
||||
}
|
||||
product.displayName = product.key;
|
||||
product.displayTotal = product.values.amount;
|
||||
product.displayTotal = total;
|
||||
product.displayBalance = product.values.amount - product.values.paid;
|
||||
product.displayPercent = (product.values.paid / product.values.amount).toFixed(2);
|
||||
product.displayAge = product.values.age;
|
||||
product.currencyId = product.values.currency_id;
|
||||
product.currencyId = currencyId;
|
||||
});
|
||||
|
||||
//console.log(JSON.stringify(clients));
|
||||
|
Loading…
x
Reference in New Issue
Block a user