From 3d4feff7deb8e98bcbcf2ff092627c4ede6ed8c2 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 24 Feb 2017 20:27:26 +0100 Subject: [PATCH] More code for the tag report. --- app/Helpers/Chart/MetaPieChart.php | 23 ++++- app/Helpers/Chart/MetaPieChartInterface.php | 7 ++ .../Controllers/Chart/TagReportController.php | 96 ++++++++++++++++++- resources/views/transactions/index.twig | 4 - routes/web.php | 6 +- 5 files changed, 125 insertions(+), 11 deletions(-) diff --git a/app/Helpers/Chart/MetaPieChart.php b/app/Helpers/Chart/MetaPieChart.php index 6c340b5389..ba50d55738 100644 --- a/app/Helpers/Chart/MetaPieChart.php +++ b/app/Helpers/Chart/MetaPieChart.php @@ -47,7 +47,6 @@ class MetaPieChart implements MetaPieChartInterface 'budget' => ['transaction_journal_budget_id', 'transaction_budget_id'], 'category' => ['transaction_journal_category_id', 'transaction_category_id'], ]; - /** @var array */ protected $repositories = [ @@ -55,10 +54,10 @@ class MetaPieChart implements MetaPieChartInterface 'budget' => BudgetRepositoryInterface::class, 'category' => CategoryRepositoryInterface::class, ]; - - /** @var Carbon */ protected $start; + /** @var Collection */ + protected $tags; /** @var string */ protected $total = '0'; /** @var User */ @@ -87,7 +86,6 @@ class MetaPieChart implements MetaPieChartInterface if ($this->collectOtherObjects && $direction === 'expense') { /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); - $collector->setUser($this->user); $collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]); $journals = $collector->getJournals(); $sum = strval($journals->sum('transaction_amount')); @@ -182,6 +180,18 @@ class MetaPieChart implements MetaPieChartInterface return $this; } + /** + * @param Collection $tags + * + * @return MetaPieChartInterface + */ + public function setTags(Collection $tags): MetaPieChartInterface + { + $this->tags = $tags; + + return $this; + } + /** * @param User $user * @@ -219,6 +229,11 @@ class MetaPieChart implements MetaPieChartInterface if ($this->categories->count() > 0) { $collector->setCategories($this->categories); } + if ($this->tags->count() > 0) { + $collector->setTags($this->tags); + $collector->withCategoryInformation(); + $collector->withBudgetInformation(); + } $accountIds = $this->accounts->pluck('id')->toArray(); $transactions = $collector->getJournals(); diff --git a/app/Helpers/Chart/MetaPieChartInterface.php b/app/Helpers/Chart/MetaPieChartInterface.php index 006300d308..b4aa0cd736 100644 --- a/app/Helpers/Chart/MetaPieChartInterface.php +++ b/app/Helpers/Chart/MetaPieChartInterface.php @@ -72,6 +72,13 @@ interface MetaPieChartInterface */ public function setStart(Carbon $start): MetaPieChartInterface; + /** + * @param Collection $tags + * + * @return MetaPieChartInterface + */ + public function setTags(Collection $tags): MetaPieChartInterface; + /** * @param User $user * diff --git a/app/Http/Controllers/Chart/TagReportController.php b/app/Http/Controllers/Chart/TagReportController.php index afa6fb8c31..c4a6eb3cba 100644 --- a/app/Http/Controllers/Chart/TagReportController.php +++ b/app/Http/Controllers/Chart/TagReportController.php @@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers\Chart; use Carbon\Carbon; use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Report\Tag\MonthReportGenerator; +use FireflyIII\Helpers\Chart\MetaPieChartInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Tag; @@ -40,6 +41,100 @@ class TagReportController extends Controller $this->generator = app(GeneratorInterface::class); } + /** + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end + * @param string $others + * + * @return \Illuminate\Http\JsonResponse + */ + public function accountExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end, string $others) + { + /** @var MetaPieChartInterface $helper */ + $helper = app(MetaPieChartInterface::class); + $helper->setAccounts($accounts); + $helper->setTags($tags); + $helper->setStart($start); + $helper->setEnd($end); + $helper->setCollectOtherObjects(intval($others) === 1); + $chartData = $helper->generate('expense', 'account'); + $data = $this->generator->pieChart($chartData); + + return Response::json($data); + } + + /** + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end + * @param string $others + * + * @return \Illuminate\Http\JsonResponse + */ + public function accountIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end, string $others) + { + /** @var MetaPieChartInterface $helper */ + $helper = app(MetaPieChartInterface::class); + $helper->setAccounts($accounts); + $helper->setTags($tags); + $helper->setStart($start); + $helper->setEnd($end); + $helper->setCollectOtherObjects(intval($others) === 1); + $chartData = $helper->generate('income', 'account'); + $data = $this->generator->pieChart($chartData); + + return Response::json($data); + } + + /** + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end + * + * @return \Illuminate\Http\JsonResponse + */ + public function budgetExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) + { + /** @var MetaPieChartInterface $helper */ + $helper = app(MetaPieChartInterface::class); + $helper->setAccounts($accounts); + $helper->setTags($tags); + $helper->setStart($start); + $helper->setEnd($end); + $helper->setCollectOtherObjects(false); + $chartData = $helper->generate('expense', 'budget'); + $data = $this->generator->pieChart($chartData); + + return Response::json($data); + } + + /** + * @param Collection $accounts + * @param Collection $tags + * @param Carbon $start + * @param Carbon $end + * + * @return \Illuminate\Http\JsonResponse + */ + public function categoryExpense(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) + { + /** @var MetaPieChartInterface $helper */ + $helper = app(MetaPieChartInterface::class); + $helper->setAccounts($accounts); + $helper->setTags($tags); + $helper->setStart($start); + $helper->setEnd($end); + $helper->setCollectOtherObjects(false); + $chartData = $helper->generate('expense', 'category'); + $data = $this->generator->pieChart($chartData); + + return Response::json($data); + } + /** * @param Collection $accounts * @param Collection $tags @@ -146,7 +241,6 @@ class TagReportController extends Controller return Response::json($data); } - /** * @param Collection $accounts * @param Collection $tags diff --git a/resources/views/transactions/index.twig b/resources/views/transactions/index.twig index 1b86e5ac6b..33f8253f0c 100644 --- a/resources/views/transactions/index.twig +++ b/resources/views/transactions/index.twig @@ -7,9 +7,6 @@ {% block content %} - {% if journals.count == 0 %} - {% include 'partials.empty' with {what: what, type: 'transactions',route: route('transactions.create', [what])} %} - {% else %}
@@ -44,7 +41,6 @@
- {% endif %} {% endblock %} {% block scripts %} diff --git a/routes/web.php b/routes/web.php index 9317011312..5a70819fd4 100755 --- a/routes/web.php +++ b/routes/web.php @@ -333,13 +333,15 @@ Route::group( 'account/expense/{accountList}/{tagList}/{start_date}/{end_date}/{others}', ['uses' => 'TagReportController@accountExpense', 'as' => 'account-expense'] ); + + // new routes Route::get( 'budget/expense/{accountList}/{tagList}/{start_date}/{end_date}', ['uses' => 'TagReportController@budgetExpense', 'as' => 'budget-expense'] ); - Route::get( - 'category/expense/{accountList}/{tagList}/{start_date}/{end_date}', + Route::get('category/expense/{accountList}/{tagList}/{start_date}/{end_date}', ['uses' => 'TagReportController@categoryExpense', 'as' => 'category-expense'] + );