mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 12:54:31 -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>
|
</script>
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
// pre-process the possible groupings (clients, invoices and products)
|
// pre-process the possible groupings (clients, invoices and products)
|
||||||
var clients = data.concat();
|
var clients = data.concat();
|
||||||
var invoices = _.flatten(_.pluck(clients, 'invoices'));
|
var invoices = _.flatten(_.pluck(clients, 'invoices'));
|
||||||
|
var accountCurrencyId = {{ auth()->user()->account->getCurrencyId() }};
|
||||||
|
|
||||||
// remove quotes and recurring invoices
|
// remove quotes and recurring invoices
|
||||||
invoices = _.filter(invoices, function(invoice) {
|
invoices = _.filter(invoices, function(invoice) {
|
||||||
@ -86,7 +87,7 @@
|
|||||||
var products = _.flatten(_.pluck(invoices, 'invoice_items'));
|
var products = _.flatten(_.pluck(invoices, 'invoice_items'));
|
||||||
products = d3.nest()
|
products = d3.nest()
|
||||||
.key(function(d) {
|
.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 + ']'
|
' [' + d.invoice.client.currency.code + ']'
|
||||||
: '');
|
: '');
|
||||||
})
|
})
|
||||||
@ -118,31 +119,47 @@
|
|||||||
|
|
||||||
// create standardized display properties
|
// create standardized display properties
|
||||||
_.each(clients, function(client) {
|
_.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.displayName = getClientDisplayName(client);
|
||||||
client.displayTotal = +client.paid_to_date + +client.balance;
|
client.displayTotal = total;
|
||||||
client.displayBalance = +client.balance;
|
client.displayBalance = +client.balance;
|
||||||
client.displayPercent = (+client.paid_to_date / (+client.paid_to_date + +client.balance)).toFixed(2);
|
client.displayPercent = (+client.paid_to_date / (+client.paid_to_date + +client.balance)).toFixed(2);
|
||||||
var oldestInvoice = _.max(client.invoices, function(invoice) { return calculateInvoiceAge(invoice) });
|
var oldestInvoice = _.max(client.invoices, function(invoice) { return calculateInvoiceAge(invoice) });
|
||||||
client.displayAge = oldestInvoice ? calculateInvoiceAge(oldestInvoice) : -1;
|
client.displayAge = oldestInvoice ? calculateInvoiceAge(oldestInvoice) : -1;
|
||||||
client.currencyId = client.currency_id || {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY) }};
|
client.currencyId = currencyId;
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(invoices, function(invoice) {
|
_.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.displayName = invoice.invoice_number;
|
||||||
invoice.displayTotal = +invoice.amount;
|
invoice.displayTotal = total;
|
||||||
invoice.displayBalance = +invoice.balance;
|
invoice.displayBalance = +invoice.balance;
|
||||||
invoice.displayPercent = (+invoice.amount - +invoice.balance) / +invoice.amount;
|
invoice.displayPercent = (+invoice.amount - +invoice.balance) / +invoice.amount;
|
||||||
invoice.displayAge = calculateInvoiceAge(invoice);
|
invoice.displayAge = calculateInvoiceAge(invoice);
|
||||||
invoice.currencyId = invoice.client.currency_id || {{ Session::get(SESSION_CURRENCY, DEFAULT_CURRENCY) }};
|
invoice.currencyId = currencyId;
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(products, function(product) {
|
_.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.displayName = product.key;
|
||||||
product.displayTotal = product.values.amount;
|
product.displayTotal = total;
|
||||||
product.displayBalance = product.values.amount - product.values.paid;
|
product.displayBalance = product.values.amount - product.values.paid;
|
||||||
product.displayPercent = (product.values.paid / product.values.amount).toFixed(2);
|
product.displayPercent = (product.values.paid / product.values.amount).toFixed(2);
|
||||||
product.displayAge = product.values.age;
|
product.displayAge = product.values.age;
|
||||||
product.currencyId = product.values.currency_id;
|
product.currencyId = currencyId;
|
||||||
});
|
});
|
||||||
|
|
||||||
//console.log(JSON.stringify(clients));
|
//console.log(JSON.stringify(clients));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user