mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Respond to "convert to native".
This commit is contained in:
@@ -87,6 +87,7 @@ class AccountController extends Controller
|
|||||||
// move date to end of day
|
// move date to end of day
|
||||||
$queryParameters['start']->startOfDay();
|
$queryParameters['start']->startOfDay();
|
||||||
$queryParameters['end']->endOfDay();
|
$queryParameters['end']->endOfDay();
|
||||||
|
Log::debug(sprintf('dashboard(), convert to native: %s', var_export($this->convertToNative, true)));
|
||||||
|
|
||||||
// loop each account, and collect info:
|
// loop each account, and collect info:
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
|
@@ -147,6 +147,7 @@ class ShowController extends Controller
|
|||||||
$enrichment->setUser($admin);
|
$enrichment->setUser($admin);
|
||||||
$selectedGroup = $enrichment->enrichSingle($selectedGroup);
|
$selectedGroup = $enrichment->enrichSingle($selectedGroup);
|
||||||
|
|
||||||
|
|
||||||
/** @var TransactionGroupTransformer $transformer */
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
$transformer = app(TransactionGroupTransformer::class);
|
$transformer = app(TransactionGroupTransformer::class);
|
||||||
$transformer->setParameters($this->parameters);
|
$transformer->setParameters($this->parameters);
|
||||||
|
@@ -558,7 +558,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedJournal($augumentedJournal);
|
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedJournal($augumentedJournal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups = $this->parseSums($groups);
|
$groups = $this->parseSums($groups);
|
||||||
|
|
||||||
return new Collection($groups);
|
return new Collection($groups);
|
||||||
|
@@ -121,6 +121,15 @@ class TransactionGroupTransformer extends AbstractTransformer
|
|||||||
if (null !== $transaction['foreign_amount'] && '' !== $transaction['foreign_amount'] && 0 !== bccomp('0', (string) $transaction['foreign_amount'])) {
|
if (null !== $transaction['foreign_amount'] && '' !== $transaction['foreign_amount'] && 0 !== bccomp('0', (string) $transaction['foreign_amount'])) {
|
||||||
$foreignAmount = app('steam')->positive($transaction['foreign_amount']);
|
$foreignAmount = app('steam')->positive($transaction['foreign_amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set native amount to the normal amount if the currency matches.
|
||||||
|
if($transaction['native_currency']['id'] ?? null === $transaction['currency_id']) {
|
||||||
|
$transaction['native_amount'] = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(array_key_exists('native_amount', $transaction) && null !== $transaction['native_amount']) {
|
||||||
|
$transaction['native_amount'] = app('steam')->positive($transaction['native_amount']);
|
||||||
|
}
|
||||||
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionTypeEnum::WITHDRAWAL->value);
|
$type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionTypeEnum::WITHDRAWAL->value);
|
||||||
|
|
||||||
// must be 0 (int) or NULL
|
// must be 0 (int) or NULL
|
||||||
|
@@ -25,7 +25,7 @@ export default class Dashboard {
|
|||||||
dashboard(start, end) {
|
dashboard(start, end) {
|
||||||
let startStr = format(start, 'y-MM-dd');
|
let startStr = format(start, 'y-MM-dd');
|
||||||
let endStr = format(end, 'y-MM-dd');
|
let endStr = format(end, 'y-MM-dd');
|
||||||
return api.get('/api/v1/chart/account/dashboard', {params: {fix: true, start: startStr, end: endStr}});
|
return api.get('/api/v1/chart/account/dashboard', {params: {start: startStr, end: endStr}});
|
||||||
}
|
}
|
||||||
|
|
||||||
expense(start, end) {
|
expense(start, end) {
|
||||||
|
@@ -40,19 +40,14 @@ export default () => ({
|
|||||||
loadingAccounts: false,
|
loadingAccounts: false,
|
||||||
accountList: [],
|
accountList: [],
|
||||||
convertToNative: false,
|
convertToNative: false,
|
||||||
convertToNativeAvailable: false,
|
|
||||||
chartOptions: null,
|
chartOptions: null,
|
||||||
switchConvertToNative() {
|
|
||||||
this.convertToNative = !this.convertToNative;
|
|
||||||
setVariable('convert_to_native', this.convertToNative);
|
|
||||||
},
|
|
||||||
localCacheKey(type) {
|
localCacheKey(type) {
|
||||||
return 'ds_accounts_' + type;
|
return 'ds_accounts_' + type;
|
||||||
},
|
},
|
||||||
|
|
||||||
eventListeners: {
|
eventListeners: {
|
||||||
['@convert-to-native.window'](event){
|
['@convert-to-native.window'](event){
|
||||||
console.log('I heard that! it is now ' + event.detail);
|
console.log('I heard that! (dashboard/accounts)');
|
||||||
this.convertToNative = event.detail;
|
this.convertToNative = event.detail;
|
||||||
this.accountList = [];
|
this.accountList = [];
|
||||||
chartData = null;
|
chartData = null;
|
||||||
@@ -62,19 +57,16 @@ export default () => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
doSomeReload() {
|
|
||||||
console.log('doSomeReload');
|
|
||||||
},
|
|
||||||
getFreshData() {
|
getFreshData() {
|
||||||
console.log('get fresh data');
|
|
||||||
const start = new Date(window.store.get('start'));
|
const start = new Date(window.store.get('start'));
|
||||||
const end = new Date(window.store.get('end'));
|
const end = new Date(window.store.get('end'));
|
||||||
const chartCacheKey = getCacheKey(this.localCacheKey('chart'), {start: start, end: end})
|
const chartCacheKey = getCacheKey(this.localCacheKey('chart'), {convertToNative: this.convertToNative, start: start, end: end})
|
||||||
|
|
||||||
const cacheValid = window.store.get('cacheValid');
|
const cacheValid = window.store.get('cacheValid');
|
||||||
let cachedData = window.store.get(chartCacheKey);
|
let cachedData = window.store.get(chartCacheKey);
|
||||||
|
|
||||||
if (cacheValid && typeof cachedData !== 'undefined') {
|
if (cacheValid && typeof cachedData !== 'undefined') {
|
||||||
|
console.log('Generate from cache: ', chartCacheKey);
|
||||||
this.drawChart(this.generateOptions(cachedData));
|
this.drawChart(this.generateOptions(cachedData));
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
return;
|
return;
|
||||||
@@ -84,6 +76,7 @@ export default () => ({
|
|||||||
this.chartData = response.data;
|
this.chartData = response.data;
|
||||||
// cache generated options:
|
// cache generated options:
|
||||||
window.store.set(chartCacheKey, response.data);
|
window.store.set(chartCacheKey, response.data);
|
||||||
|
console.log('Generate FRESH!');
|
||||||
this.drawChart(this.generateOptions(this.chartData));
|
this.drawChart(this.generateOptions(this.chartData));
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
@@ -108,14 +101,17 @@ export default () => ({
|
|||||||
|
|
||||||
// use the "native" currency code and use the "native_entries" as array
|
// use the "native" currency code and use the "native_entries" as array
|
||||||
if (this.convertToNative) {
|
if (this.convertToNative) {
|
||||||
console.log('Convert to native!');
|
|
||||||
currencies.push(current.native_currency_code);
|
currencies.push(current.native_currency_code);
|
||||||
dataset.currency_code = current.native_currency_code;
|
dataset.currency_code = current.native_currency_code;
|
||||||
collection = Object.values(current.native_entries);
|
if(!current.hasOwnProperty('native_entries')) {
|
||||||
|
console.error('No native entries ('+this.convertToNative+') found for account: ', current);
|
||||||
|
}
|
||||||
|
if(current.hasOwnProperty('native_entries')) {
|
||||||
|
collection = Object.values(current.native_entries);
|
||||||
|
}
|
||||||
yAxis = 'y' + current.native_currency_code;
|
yAxis = 'y' + current.native_currency_code;
|
||||||
}
|
}
|
||||||
if (!this.convertToNative) {
|
if (!this.convertToNative) {
|
||||||
console.log('NO convert to native!', this.convertToNative);
|
|
||||||
yAxis = 'y' + current.currency_code;
|
yAxis = 'y' + current.currency_code;
|
||||||
dataset.currency_code = current.currency_code;
|
dataset.currency_code = current.currency_code;
|
||||||
currencies.push(current.currency_code);
|
currencies.push(current.currency_code);
|
||||||
@@ -155,9 +151,7 @@ export default () => ({
|
|||||||
return options;
|
return options;
|
||||||
},
|
},
|
||||||
loadChart() {
|
loadChart() {
|
||||||
console.log('loadChart');
|
|
||||||
if (true === this.loading) {
|
if (true === this.loading) {
|
||||||
console.log('already loading chart');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
@@ -175,7 +169,6 @@ export default () => ({
|
|||||||
chart.options = options.options;
|
chart.options = options.options;
|
||||||
chart.data = options.data;
|
chart.data = options.data;
|
||||||
chart.update();
|
chart.update();
|
||||||
console.log('refresh chart');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chart = new Chart(document.querySelector("#account-chart"), options);
|
chart = new Chart(document.querySelector("#account-chart"), options);
|
||||||
@@ -303,9 +296,8 @@ export default () => ({
|
|||||||
]).then((values) => {
|
]).then((values) => {
|
||||||
//console.log('accounts after promises');
|
//console.log('accounts after promises');
|
||||||
this.convertToNative = values[1] && values[3];
|
this.convertToNative = values[1] && values[3];
|
||||||
this.convertToNativeAvailable = values[3];
|
|
||||||
afterPromises = true;
|
afterPromises = true;
|
||||||
console.log('convertToNative in accounts.js: ', values);
|
//console.log('convertToNative in accounts.js: ', values);
|
||||||
|
|
||||||
// main dashboard chart:
|
// main dashboard chart:
|
||||||
this.loadChart();
|
this.loadChart();
|
||||||
|
@@ -35,11 +35,21 @@ export default () => ({
|
|||||||
loading: false,
|
loading: false,
|
||||||
boxData: null,
|
boxData: null,
|
||||||
boxOptions: null,
|
boxOptions: null,
|
||||||
|
eventListeners: {
|
||||||
|
['@convert-to-native.window'](event){
|
||||||
|
this.convertToNative = event.detail;
|
||||||
|
this.accountList = [];
|
||||||
|
console.log('I heard that!');
|
||||||
|
this.boxData = null;
|
||||||
|
this.loadBoxes();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getFreshData() {
|
getFreshData() {
|
||||||
const start = new Date(window.store.get('start'));
|
const start = new Date(window.store.get('start'));
|
||||||
const end = new Date(window.store.get('end'));
|
const end = new Date(window.store.get('end'));
|
||||||
// TODO cache key is hard coded, problem?
|
// TODO cache key is hard coded, problem?
|
||||||
const boxesCacheKey = getCacheKey('ds_boxes_data', {start: start, end: end});
|
const boxesCacheKey = getCacheKey('ds_boxes_data', {convertToNative: this.convertToNative, start: start, end: end});
|
||||||
cleanupCache();
|
cleanupCache();
|
||||||
|
|
||||||
//const cacheValid = window.store.get('cacheValid');
|
//const cacheValid = window.store.get('cacheValid');
|
||||||
|
@@ -166,6 +166,11 @@ export default () => ({
|
|||||||
// properties of the transaction, used in the generation of the chart:
|
// properties of the transaction, used in the generation of the chart:
|
||||||
let transaction = group.attributes.transactions[ii];
|
let transaction = group.attributes.transactions[ii];
|
||||||
let currencyCode = this.convertToNative ? transaction.native_currency_code : transaction.currency_code;
|
let currencyCode = this.convertToNative ? transaction.native_currency_code : transaction.currency_code;
|
||||||
|
if(this.convertToNative && (!transaction.hasOwnProperty('native_amount') || null === transaction.native_amount)) {
|
||||||
|
// skip this transaction, it has no native amount.
|
||||||
|
console.error('No native amount for transaction #' + group.id + ' ('+this.convertToNative+')');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let amount = this.convertToNative ? parseFloat(transaction.native_amount) : parseFloat(transaction.amount);
|
let amount = this.convertToNative ? parseFloat(transaction.native_amount) : parseFloat(transaction.amount);
|
||||||
let flowKey;
|
let flowKey;
|
||||||
|
|
||||||
@@ -313,7 +318,7 @@ export default () => ({
|
|||||||
downloadTransactions(params) {
|
downloadTransactions(params) {
|
||||||
const start = new Date(window.store.get('start'));
|
const start = new Date(window.store.get('start'));
|
||||||
const end = new Date(window.store.get('end'));
|
const end = new Date(window.store.get('end'));
|
||||||
const cacheKey = getCacheKey(SANKEY_CACHE_KEY, {start: start, end: end});
|
const cacheKey = getCacheKey(SANKEY_CACHE_KEY, {convertToNative: this.convertToNative, start: start, end: end});
|
||||||
|
|
||||||
//console.log('Downloading page ' + params.page + '...');
|
//console.log('Downloading page ' + params.page + '...');
|
||||||
const getter = new Get();
|
const getter = new Get();
|
||||||
@@ -353,9 +358,6 @@ export default () => ({
|
|||||||
this.convertToNative = values[0];
|
this.convertToNative = values[0];
|
||||||
convertToNative = values[0];
|
convertToNative = values[0];
|
||||||
|
|
||||||
this.convertToNative = false;
|
|
||||||
convertToNative = false;
|
|
||||||
|
|
||||||
// some translations:
|
// some translations:
|
||||||
translations.all_money = i18next.t('firefly.all_money');
|
translations.all_money = i18next.t('firefly.all_money');
|
||||||
translations.category = i18next.t('firefly.category');
|
translations.category = i18next.t('firefly.category');
|
||||||
|
@@ -28,7 +28,7 @@ export function setVariable(name, value = null) {
|
|||||||
// then again, it's not that slow.
|
// then again, it's not that slow.
|
||||||
|
|
||||||
// set in window.x
|
// set in window.x
|
||||||
// window[name] = value;
|
window[name] = value;
|
||||||
|
|
||||||
// set in store:
|
// set in store:
|
||||||
window.store.set(name, value);
|
window.store.set(name, value);
|
||||||
@@ -36,11 +36,14 @@ export function setVariable(name, value = null) {
|
|||||||
// post to user preferences (because why not):
|
// post to user preferences (because why not):
|
||||||
let putter = new Put();
|
let putter = new Put();
|
||||||
putter.put(name, value).then((response) => {
|
putter.put(name, value).then((response) => {
|
||||||
}).catch(() => {
|
console.log('set "'+name+'" to value: ', value);
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
// preference does not exist (yet).
|
// preference does not exist (yet).
|
||||||
// POST it
|
// POST it
|
||||||
let poster = (new Post);
|
let poster = (new Post);
|
||||||
poster.post(name, value).then((response) => {
|
poster.post(name, value).then((response) => {
|
||||||
|
console.log('POST "'+name+'" to value: ', value);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -9,24 +9,6 @@
|
|||||||
<div class="card-body p-0" style="position: relative;height:400px;">
|
<div class="card-body p-0" style="position: relative;height:400px;">
|
||||||
<canvas id="account-chart"></canvas>
|
<canvas id="account-chart"></canvas>
|
||||||
</div>
|
</div>
|
||||||
<template x-if="convertToNativeAvailable">
|
|
||||||
<div class="card-footer text-end">
|
|
||||||
<template x-if="convertToNative">
|
|
||||||
<button type="button" @click="switchConvertToNative"
|
|
||||||
class="btn btn-outline-info btm-sm">
|
|
||||||
<span
|
|
||||||
class="fa-solid fa-comments-dollar"></span> {{ __('firefly.disable_auto_convert') }}
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
<template x-if="!convertToNative">
|
|
||||||
<button type="button" @click="switchConvertToNative"
|
|
||||||
class="btn btn-outline-info btm-sm">
|
|
||||||
<span
|
|
||||||
class="fa-solid fa-comments-dollar"></span> {{ __('firefly.enable_auto_convert') }}
|
|
||||||
</button>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<div class="row mb-2" x-data="boxes">
|
<div class="row mb-2" x-data="boxes" x-bind="eventListeners">
|
||||||
<div class="col-xl-3 col-lg-6 col-md-12 col-sm-12">
|
<div class="col-xl-3 col-lg-6 col-md-12 col-sm-12">
|
||||||
<div class="small-box text-bg-primary">
|
<div class="small-box text-bg-primary">
|
||||||
<div class="inner balance-box">
|
<div class="inner balance-box">
|
||||||
|
Reference in New Issue
Block a user