Expand charts.

This commit is contained in:
James Cole 2020-03-14 20:30:31 +01:00
parent d1325ffbd8
commit 50b710b4f6
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 83 additions and 5 deletions

View File

@ -170,7 +170,6 @@ class TransactionController extends Controller
return response()->json($chart);
}
/**
* @param string $objectType
* @param Carbon $start
@ -237,4 +236,70 @@ class TransactionController extends Controller
return response()->json($chart);
}
/**
* @param string $objectType
* @param Carbon $start
* @param Carbon $end
*
* @return \Illuminate\Http\JsonResponse
* @throws FireflyException
*/
public function sourceAccounts(string $objectType, Carbon $start, Carbon $end)
{
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($objectType);
$cache->addProperty('chart.transactions.sources');
if ($cache->has()) {
//return response()->json($cache->get()); // @codeCoverageIgnore
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end);
$collector->withAccountInformation();
switch ($objectType) {
default:
throw new FireflyException(sprintf('Cant handle "%s"', $objectType));
case 'withdrawal':
$collector->setTypes([TransactionType::WITHDRAWAL]);
break;
case 'deposit':
$collector->setTypes([TransactionType::DEPOSIT]);
break;
case 'transfers':
$collector->setTypes([TransactionType::TRANSFER]);
break;
}
$result = $collector->getExtractedJournals();
$data = [];
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$name = $journal['source_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$data[$title] = $data[$title] ?? [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
];
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
if (null !== $journal['foreign_amount']) {
$title = sprintf('%s (%s)', $name, $journal['foreign_currency_symbol']);
$data[$title] = $data[$title] ?? [
'amount' => $journal['foreign_amount'],
'currency_symbol' => $journal['currency_symbol'],
];
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['foreign_amount']);
}
}
$chart = $this->generator->multiCurrencyPieChart($data);
$cache->store($chart);
return response()->json($chart);
}
}

View File

@ -24,5 +24,6 @@ $(function () {
multiCurrencyPieChart(categoryChartUri, 'category_chart');
multiCurrencyPieChart(budgetChartUri, 'budget_chart');
multiCurrencyPieChart(destinationChartUri, 'destination_chart');
multiCurrencyPieChart(sourceChartUri, 'source_chart');
}
});

View File

@ -219,6 +219,7 @@ return [
'is_alpha_warning' => 'You are running an ALPHA version. Be wary of bugs and issues.',
'is_beta_warning' => 'You are running an BETA version. Be wary of bugs and issues.',
'all_destination_accounts' => 'Destination accounts',
'all_source_accounts' => 'Source accounts',
// check for updates:
'update_check_title' => 'Check for updates',

View File

@ -17,10 +17,7 @@
{% if periods|length > 0 %}
{% set boxSize = 'col-lg-6 col-md-6 col-sm-12 col-xs-12' %}
{% if objectType == 'withdrawal' %}
{% set boxSize = 'col-lg-4 col-md-6 col-sm-12 col-xs-12' %}
{% endif %}
{% set boxSize = 'col-lg-4 col-md-6 col-sm-12 col-xs-12' %}
<div class="row">
{# for withdrawals, deposits and transfers #}
<div class="{{ boxSize }}">
@ -46,6 +43,18 @@
</div>
</div>
{% endif %}
{% if objectType != 'withdrawal' %}
<div class="{{ boxSize }}">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'all_source_accounts'|_ }}</h3>
</div>
<div class="box-body">
<canvas id="source_chart" style="width:100%;height:250px;" height="250"></canvas>
</div>
</div>
</div>
{% endif %}
{# for all #}
<div class="{{ boxSize }}">
<div class="box">
@ -119,6 +128,7 @@
var categoryChartUri = '{{ route('chart.transactions.categories', [objectType, start.format('Y-m-d'), end.format('Y-m-d')]) }}';
var budgetChartUri = '{{ route('chart.transactions.budgets', [start.format('Y-m-d'), end.format('Y-m-d')]) }}';
var destinationChartUri = '{{ route('chart.transactions.destinationAccounts', [objectType, start.format('Y-m-d'), end.format('Y-m-d')]) }}';
var sourceChartUri = '{{ route('chart.transactions.sourceAccounts', [objectType, start.format('Y-m-d'), end.format('Y-m-d')]) }}';
</script>
<script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>

View File

@ -498,6 +498,7 @@ Route::group(
Route::get('categories/{objectType}/{start_date}/{end_date}', ['uses' => 'TransactionController@categories', 'as' => 'categories']);
Route::get('budgets/{start_date}/{end_date}', ['uses' => 'TransactionController@budgets', 'as' => 'budgets']);
Route::get('destinationAccounts/{objectType}/{start_date}/{end_date}', ['uses' => 'TransactionController@destinationAccounts', 'as' => 'destinationAccounts']);
Route::get('sourceAccounts/{objectType}/{start_date}/{end_date}', ['uses' => 'TransactionController@sourceAccounts', 'as' => 'sourceAccounts']);
//
}