From 50b710b4f6fb7ff0b7265503386acbfa21ff5f80 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 14 Mar 2020 20:30:31 +0100 Subject: [PATCH] Expand charts. --- .../Chart/TransactionController.php | 67 ++++++++++++++++++- public/v1/js/ff/transactions/index.js | 1 + resources/lang/en_US/firefly.php | 1 + resources/views/v1/transactions/index.twig | 18 +++-- routes/web.php | 1 + 5 files changed, 83 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Chart/TransactionController.php b/app/Http/Controllers/Chart/TransactionController.php index 6bea98b9dc..95b3743eb7 100644 --- a/app/Http/Controllers/Chart/TransactionController.php +++ b/app/Http/Controllers/Chart/TransactionController.php @@ -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); + } + } \ No newline at end of file diff --git a/public/v1/js/ff/transactions/index.js b/public/v1/js/ff/transactions/index.js index 93749d5eb9..1ce056df8d 100644 --- a/public/v1/js/ff/transactions/index.js +++ b/public/v1/js/ff/transactions/index.js @@ -24,5 +24,6 @@ $(function () { multiCurrencyPieChart(categoryChartUri, 'category_chart'); multiCurrencyPieChart(budgetChartUri, 'budget_chart'); multiCurrencyPieChart(destinationChartUri, 'destination_chart'); + multiCurrencyPieChart(sourceChartUri, 'source_chart'); } }); \ No newline at end of file diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 97bfafa8ef..2d589d5bef 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -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', diff --git a/resources/views/v1/transactions/index.twig b/resources/views/v1/transactions/index.twig index 17b1db6d3e..f50ffd01a4 100644 --- a/resources/views/v1/transactions/index.twig +++ b/resources/views/v1/transactions/index.twig @@ -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' %}
{# for withdrawals, deposits and transfers #}
@@ -46,6 +43,18 @@
{% endif %} + {% if objectType != 'withdrawal' %} +
+
+
+

{{ 'all_source_accounts'|_ }}

+
+
+ +
+
+
+ {% endif %} {# for all #}
@@ -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')]) }}'; diff --git a/routes/web.php b/routes/web.php index 7734d0abc9..1d1542765a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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']); // }