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' %}