mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Add earned + spent, needs cleaning up still.
This commit is contained in:
@@ -54,12 +54,21 @@ export default () => ({
|
|||||||
if (data.hasOwnProperty(i)) {
|
if (data.hasOwnProperty(i)) {
|
||||||
let current = data[i];
|
let current = data[i];
|
||||||
let code = current.currency_code;
|
let code = current.currency_code;
|
||||||
if (!series.hasOwnProperty(code)) {
|
|
||||||
series[code] = {
|
// create two series, "spent" and "earned".
|
||||||
name: code,
|
for(const type of ['spent', 'earned']) {
|
||||||
yAxisID: '',
|
let typeCode = code + '_' + type;
|
||||||
data: {},
|
if (!series.hasOwnProperty(typeCode)) {
|
||||||
};
|
series[typeCode] = {
|
||||||
|
name: typeCode,
|
||||||
|
code: code,
|
||||||
|
type: type,
|
||||||
|
yAxisID: '',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!currencies.includes(code)) {
|
||||||
currencies.push(code);
|
currencies.push(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,31 +85,38 @@ export default () => ({
|
|||||||
code = current.primary_currency_code;
|
code = current.primary_currency_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop series, add 0 if not present or add actual amount.
|
// twice again, for speny AND earned.
|
||||||
for (const ii in series) {
|
for(const type of ['spent', 'earned']) {
|
||||||
if (series.hasOwnProperty(ii)) {
|
let typeCode = code + '_' + type;
|
||||||
let amount = 0.0;
|
// loop series, add 0 if not present or add actual amount.
|
||||||
if (code === ii) {
|
for (const ii in series) {
|
||||||
// this series' currency matches this column's currency.
|
if (series.hasOwnProperty(typeCode)) {
|
||||||
amount = parseFloat(current.entries.spent);
|
let amount = 0.0;
|
||||||
if(this.convertToPrimary) {
|
if (typeCode === ii) {
|
||||||
amount = parseFloat(current.entries.pc_entries.spent);
|
// this series' currency matches this column's currency.
|
||||||
|
amount = parseFloat(current.entries[type]);
|
||||||
|
if(this.convertToPrimary) {
|
||||||
|
amount = parseFloat(current.entries.pc_entries[type]);
|
||||||
|
}
|
||||||
|
yAxis = 'y' + typeCode;
|
||||||
|
}
|
||||||
|
if (series[typeCode].data.hasOwnProperty(current.label)) {
|
||||||
|
// there is a value for this particular currency. The amount from this column will be added.
|
||||||
|
// (even if this column isn't recorded in this currency and a new filler value is written)
|
||||||
|
// this is so currency conversion works.
|
||||||
|
series[typeCode].data[current.label] = series[typeCode].data[current.label] + amount;
|
||||||
}
|
}
|
||||||
yAxis = 'y' + code;
|
|
||||||
}
|
|
||||||
if (series[ii].data.hasOwnProperty(current.label)) {
|
|
||||||
// there is a value for this particular currency. The amount from this column will be added.
|
|
||||||
// (even if this column isn't recorded in this currency and a new filler value is written)
|
|
||||||
// this is so currency conversion works.
|
|
||||||
series[ii].data[current.label] = series[ii].data[current.label] + amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!series[ii].data.hasOwnProperty(current.label)) {
|
if (!series[typeCode].data.hasOwnProperty(current.label)) {
|
||||||
// this column's amount is not yet set in this series.
|
// this column's amount is not yet set in this series.
|
||||||
series[ii].data[current.label] = amount;
|
series[typeCode].data[current.label] = amount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// add label to x-axis, not unimportant.
|
// add label to x-axis, not unimportant.
|
||||||
if (!options.data.labels.includes(current.label)) {
|
if (!options.data.labels.includes(current.label)) {
|
||||||
options.data.labels.push(current.label);
|
options.data.labels.push(current.label);
|
||||||
@@ -111,9 +127,10 @@ export default () => ({
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
for (const i in series) {
|
for (const i in series) {
|
||||||
let yAxisID = 'y' + i;
|
let yAxisID = 'y' + i;
|
||||||
|
let currencyCode = i.replace('_spent', '').replace('_earned', '');
|
||||||
let dataset = {
|
let dataset = {
|
||||||
label: i,
|
label: i,
|
||||||
currency_code: i,
|
currency_code: currencyCode,
|
||||||
yAxisID: yAxisID,
|
yAxisID: yAxisID,
|
||||||
data: [],
|
data: [],
|
||||||
// backgroundColor: getColors(null, 'background'),
|
// backgroundColor: getColors(null, 'background'),
|
||||||
|
Reference in New Issue
Block a user