Repair charts and balances.

This commit is contained in:
James Cole
2025-09-21 07:35:46 +02:00
parent acc3c294d8
commit 8a06298385
3 changed files with 20 additions and 27 deletions

View File

@@ -211,14 +211,6 @@ export default () => ({
(new Get).show(accountId, new Date(window.store.get('end'))).then((response) => { (new Get).show(accountId, new Date(window.store.get('end'))).then((response) => {
let parent = response.data.data; let parent = response.data.data;
// apply function to each element of parent:
// parent.attributes.balances = parent.attributes.balances.map((balance) => {
// balance.amount_formatted = formatMoney(balance.amount, balance.currency_code);
// return balance;
// });
// console.log(parent);
// get groups for account: // get groups for account:
const params = { const params = {
page: 1, page: 1,
@@ -261,11 +253,14 @@ export default () => ({
accounts.push({ accounts.push({
name: parent.attributes.name, name: parent.attributes.name,
order: parent.attributes.order, order: parent.attributes.order,
current_balance: formatMoney(parent.attributes.current_balance, parent.attributes.currency_code),
pc_current_balance: null === parent.attributes.pc_current_balance ? null : formatMoney(parent.attributes.pc_current_balance, parent.attributes.primary_currency_code),
id: parent.id, id: parent.id,
balances: parent.attributes.balances, //balances: parent.attributes.balances,
groups: groups, groups: groups,
}); });
// console.log(parent.attributes);
count++; count++;
if (count === totalAccounts) { if (count === totalAccounts) {
accounts.sort((a, b) => a.order - b.order); // b - a for reverse sort accounts.sort((a, b) => a.order - b.order); // b - a for reverse sort

View File

@@ -64,13 +64,17 @@ export default () => ({
} }
} }
} }
// loop data again to add amounts to each series. // loop data again to add amounts to each series.
for (const i in data) { for (const i in data) {
if (data.hasOwnProperty(i)) { if (data.hasOwnProperty(i)) {
let yAxis = 'y'; let yAxis = 'y';
let current = data[i]; let current = data[i];
// allow switch to primary currency.
let code = current.currency_code; let code = current.currency_code;
if(this.convertToPrimary) {
code = current.primary_currency_code;
}
// loop series, add 0 if not present or add actual amount. // loop series, add 0 if not present or add actual amount.
for (const ii in series) { for (const ii in series) {
@@ -78,8 +82,11 @@ export default () => ({
let amount = 0.0; let amount = 0.0;
if (code === ii) { if (code === ii) {
// this series' currency matches this column's currency. // this series' currency matches this column's currency.
amount = parseFloat(current.amount); amount = parseFloat(current.entries.spent);
yAxis = 'y' + current.currency_code; if(this.convertToPrimary) {
amount = parseFloat(current.entries.pc_entries.spent);
}
yAxis = 'y' + code;
} }
if (series[ii].data.hasOwnProperty(current.label)) { if (series[ii].data.hasOwnProperty(current.label)) {
// there is a value for this particular currency. The amount from this column will be added. // there is a value for this particular currency. The amount from this column will be added.
@@ -103,7 +110,6 @@ export default () => ({
// loop the series and create ChartJS-compatible data sets. // loop the series and create ChartJS-compatible data sets.
let count = 0; let count = 0;
for (const i in series) { for (const i in series) {
// console.log('series');
let yAxisID = 'y' + i; let yAxisID = 'y' + i;
let dataset = { let dataset = {
label: i, label: i,
@@ -148,16 +154,15 @@ export default () => ({
const end = new Date(window.store.get('end')); const end = new Date(window.store.get('end'));
const cacheKey = getCacheKey('ds_ct_chart', {convertToPrimary: this.convertToPrimary, start: start, end: end}); const cacheKey = getCacheKey('ds_ct_chart', {convertToPrimary: this.convertToPrimary, start: start, end: end});
const cacheValid = window.store.get('cacheValid'); // const cacheValid = window.store.get('cacheValid');
const cacheValid = false;
let cachedData = window.store.get(cacheKey); let cachedData = window.store.get(cacheKey);
if (cacheValid && typeof cachedData !== 'undefined') { if (cacheValid && typeof cachedData !== 'undefined') {
chartData = cachedData; // save chart data for later. chartData = cachedData; // save chart data for later.
this.drawChart(this.generateOptions(chartData)); this.drawChart(this.generateOptions(chartData));
this.loading = false; this.loading = false;
return; return;
} }
const dashboard = new Dashboard(); const dashboard = new Dashboard();
dashboard.dashboard(start, end, null).then((response) => { dashboard.dashboard(start, end, null).then((response) => {
chartData = response.data; // save chart data for later. chartData = response.data; // save chart data for later.
@@ -181,7 +186,6 @@ export default () => ({
this.getFreshData(); this.getFreshData();
}, },
init() { init() {
// console.log('categories init');
Promise.all([getVariable('convert_to_primary', false),]).then((values) => { Promise.all([getVariable('convert_to_primary', false),]).then((values) => {
this.convertToPrimary = values[0]; this.convertToPrimary = values[0];
afterPromises = true; afterPromises = true;

View File

@@ -9,16 +9,10 @@
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h3 class="card-title"> <h3 class="card-title">
<a :href="'{{ route('accounts.show', '') }}/' + account.id" <a :href="'{{ route('accounts.show', '') }}/' + account.id" x-text="account.name"></a>
x-text="account.name"></a>
<span class="small"> <span class="small">
<template x-for="balance in account.balances"> <span class="text-muted">(<span x-text="account.current_balance"></span>)</span>
<template x-if="balance.type === 'current'"> <template x-if="null !== account.pc_current_balance"><span class="text-muted">(<span x-text="account.pc_current_balance"></span>)</span></template>
<span class="text-muted">(<span x-text="balance.amount_formatted"></span>)
</span>
</template>
</template>
</span> </span>
</h3> </h3>
</div> </div>