Skip to content

Firefly III: a personal finances manager

Expand charts.

James Cole50b710b4f6fb
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' %}
<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>
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']);
//
}