From 53c80aaef8e8c46a63061bbfcd1d69cd5bf56985 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 25 Apr 2016 14:53:41 +0200 Subject: [PATCH] Small optimizations to reports. --- app/Helpers/Collection/BalanceLine.php | 39 +++++++++++++++++++ app/Helpers/Report/BalanceReportHelper.php | 2 + app/Helpers/Report/BudgetReportHelper.php | 2 +- app/Repositories/Budget/BudgetRepository.php | 1 + resources/views/reports/partials/balance.twig | 5 +++ resources/views/reports/partials/budgets.twig | 6 ++- 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.php index c1544e1578..4c94335662 100644 --- a/app/Helpers/Collection/BalanceLine.php +++ b/app/Helpers/Collection/BalanceLine.php @@ -2,6 +2,7 @@ declare(strict_types = 1); namespace FireflyIII\Helpers\Collection; +use Carbon\Carbon; use FireflyIII\Models\Budget as BudgetModel; use Illuminate\Support\Collection; @@ -24,6 +25,11 @@ class BalanceLine /** @var BudgetModel */ protected $budget; + /** @var Carbon */ + protected $startDate; + /** @var Carbon */ + protected $endDate; + /** @var int */ protected $role = self::ROLE_DEFAULTROLE; @@ -113,6 +119,39 @@ class BalanceLine return ''; } + /** + * @return Carbon + */ + public function getStartDate() + { + return $this->startDate; + } + + /** + * @param Carbon $startDate + */ + public function setStartDate($startDate) + { + $this->startDate = $startDate; + } + + /** + * @return Carbon + */ + public function getEndDate() + { + return $this->endDate; + } + + /** + * @param Carbon $endDate + */ + public function setEndDate($endDate) + { + $this->endDate = $endDate; + } + + /** * If a BalanceLine has a budget/repetition, each BalanceEntry in this BalanceLine * should have a "spent" value, which is the amount of money that has been spent diff --git a/app/Helpers/Report/BalanceReportHelper.php b/app/Helpers/Report/BalanceReportHelper.php index a529ac104a..9a1687c813 100644 --- a/app/Helpers/Report/BalanceReportHelper.php +++ b/app/Helpers/Report/BalanceReportHelper.php @@ -95,6 +95,8 @@ class BalanceReportHelper implements BalanceReportHelperInterface { $line = new BalanceLine; $line->setBudget($budget); + $line->setStartDate($budget->startdate); // returned by getBudgetsAndLimitsInRange + $line->setEndDate($budget->enddate); // returned by getBudgetsAndLimitsInRange // loop accounts: foreach ($accounts as $account) { diff --git a/app/Helpers/Report/BudgetReportHelper.php b/app/Helpers/Report/BudgetReportHelper.php index c5e3a3ea3c..410d90ee6c 100644 --- a/app/Helpers/Report/BudgetReportHelper.php +++ b/app/Helpers/Report/BudgetReportHelper.php @@ -71,7 +71,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface $budgetLine = new BudgetLine; $budgetLine->setBudget($budget); $budgetLine->setRepetition($repetition); - $expenses = $this->getSumOfRange($start, $end, $totalSpent); + $expenses = $this->getSumOfRange($repetition->startdate, $repetition->enddate, $totalSpent); // 200 en -100 is 100, vergeleken met 0 === 1 // 200 en -200 is 0, vergeleken met 0 === 0 diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 232cba03de..6f8d56648e 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -394,6 +394,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn ); } ) + ->orderBy('budgets.id', 'budget_limits.startdate', 'limit_repetitions.enddate') ->get(['budgets.*', 'limit_repetitions.startdate', 'limit_repetitions.enddate', 'limit_repetitions.amount']); $set = $set->sortBy( diff --git a/resources/views/reports/partials/balance.twig b/resources/views/reports/partials/balance.twig index efc5a2ce83..77818df874 100644 --- a/resources/views/reports/partials/balance.twig +++ b/resources/views/reports/partials/balance.twig @@ -25,6 +25,11 @@ {% if balanceLine.getBudget.id %} {{ balanceLine.getTitle }} +
+ {{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }} + — + {{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }} +
{% if(balanceLine.getBudget.amount) %} diff --git a/resources/views/reports/partials/budgets.twig b/resources/views/reports/partials/budgets.twig index c63a0a2766..4326d9ca7f 100644 --- a/resources/views/reports/partials/budgets.twig +++ b/resources/views/reports/partials/budgets.twig @@ -27,7 +27,11 @@ {% if budgetLine.getRepetition.id %} - {{ budgetLine.getRepetition.startdate.formatLocalized(monthAndDayFormat) }} + + {{ budgetLine.getRepetition.startdate.formatLocalized(monthAndDayFormat) }} + — + {{ budgetLine.getRepetition.enddate.formatLocalized(monthAndDayFormat) }} + {% endif %}