From a8ec4fe2fd8f4195e03d8cf5fa319e60e5e5cdcf Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 6 Jun 2017 19:30:31 +0200 Subject: [PATCH] New interface for budget overview. --- app/Console/Commands/UpgradeDatabase.php | 2 +- app/Http/Controllers/BudgetController.php | 37 +++- resources/views/budgets/index.twig | 219 ++++++++++++++-------- routes/web.php | 2 +- 4 files changed, 172 insertions(+), 88 deletions(-) diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php index 654267b9d0..107f61f604 100644 --- a/app/Console/Commands/UpgradeDatabase.php +++ b/app/Console/Commands/UpgradeDatabase.php @@ -389,7 +389,7 @@ class UpgradeDatabase extends Command } /** - * + * */ private function verifyCurrencyInfo() { diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 05188a146e..bad2b980dc 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers; use Amount; use Carbon\Carbon; +use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Http\Requests\BudgetFormRequest; @@ -166,16 +167,36 @@ class BudgetController extends Controller } /** + * @param string|null $moment + * * @return View */ - public function index() + public function index(string $moment = null) { + $range = Preferences::get('viewRange', '1M')->data; + $start = session('start', new Carbon); + $end = session('end', new Carbon); + + // make date if present: + if (!is_null($moment) || strlen(strval($moment)) !== 0) { + try { + $start = new Carbon($moment); + $end = Navigation::endOfPeriod($start, $range); + } catch (Exception $e) { + + } + } + $next = clone $end; + $next->addDay(); + $prev = clone $start; + $prev->subDay(); + + $this->repository->cleanupBudgets(); + $budgets = $this->repository->getActiveBudgets(); $inactive = $this->repository->getInactiveBudgets(); - $start = session('start', new Carbon); - $end = session('end', new Carbon); $periodStart = $start->formatLocalized($this->monthAndDayFormat); $periodEnd = $end->formatLocalized($this->monthAndDayFormat); $budgetInformation = $this->collectBudgetInformation($budgets, $start, $end); @@ -184,9 +205,17 @@ class BudgetController extends Controller $spent = array_sum(array_column($budgetInformation, 'spent')); $budgeted = array_sum(array_column($budgetInformation, 'budgeted')); + // display info + $currentMonth = Navigation::periodShow($start, $range); + $nextText = Navigation::periodShow($next, $range); + $prevText = Navigation::periodShow($prev, $range); + return view( 'budgets.index', - compact('available', 'periodStart', 'periodEnd', 'budgetInformation', 'inactive', 'budgets', 'spent', 'budgeted') + compact( + 'available', 'currentMonth', 'next', 'nextText', 'prev', 'prevText', 'periodStart', 'periodEnd', 'budgetInformation', 'inactive', 'budgets', + 'spent', 'budgeted' + ) ); } diff --git a/resources/views/budgets/index.twig b/resources/views/budgets/index.twig index 9ecec09211..8f2823cd0f 100644 --- a/resources/views/budgets/index.twig +++ b/resources/views/budgets/index.twig @@ -87,96 +87,151 @@ {% if budgets.count == 0 and inactive.count == 0 %} {% include 'partials.empty' with {what: 'default', type: 'budgets',route: route('budgets.create')} %} {% endif %} + + {# date thing #}
- {% for budget in budgets %} -
+
-

- - {% if budgetInformation[budget.id]['currentLimit'] %} - {{ budget.name }} - {% else %} - {{ budget.name }} - {% endif %} -

- - -
-
- - +

Period thing

+
+
+
+
+ +
+
+ +
+
+
-
- + + + + +
+
+
+
+

Budget stuff

+
+
+
+ + + + + + + + + + + + {% for budget in budgets %} - - - - + + + {# +
+
 Budget{{ 'budgeted'|_ }}SpentLeft
- {{ 'budgeted'|_ }} -
- {{ session('start').formatLocalized(monthAndDayFormat) }} - - {{ session('end').formatLocalized(monthAndDayFormat) }}
-
-
-
-
{{ defaultCurrency.symbol|raw }}
- - {% if budgetInformation[budget.id]['currentLimit'] %} - {% set repAmount = budgetInformation[budget.id]['currentLimit'].amount %} - {% else %} - {% set repAmount = '0' %} - {% endif %} - -
+
+ +
- {{ 'spent'|_ }} -
- {{ session('start').formatLocalized(monthAndDayFormat) }} - - {{ session('end').formatLocalized(monthAndDayFormat) }} -
+
+ {% if budgetInformation[budget.id]['currentLimit'] %} + {{ budget.name }} + {% else %} + {{ budget.name }} + {% endif %} + +
+
{{ defaultCurrency.symbol|raw }}
+ + {% if budgetInformation[budget.id]['currentLimit'] %} + {% set repAmount = budgetInformation[budget.id]['currentLimit'].amount %} + {% else %} + {% set repAmount = '0' %} + {% endif %} + +
{{ budgetInformation[budget.id]['spent']|formatAmount }} + {{ (repAmount - budgetInformation[budget.id]['spent'])|formatAmount }} +
+ + + + + + + + + {% if budgetInformation[budget.id]['otherLimits'].count > 0 %} + + + + {% endif %} +
+ + + +
+ +
+
+ {{ 'spent'|_ }} +
+ {{ session('start').formatLocalized(monthAndDayFormat) }} - + {{ session('end').formatLocalized(monthAndDayFormat) }} +
+
+ +
+
    + {% for other in budgetInformation[budget.id]['otherLimits'] %} +
  • + + Budgeted + {{ other.amount|formatAmountPlain }} + between + {{ other.start_date.formatLocalized(monthAndDayFormat) }} + and {{ other.end_date.formatLocalized(monthAndDayFormat) }}. +
  • + {% endfor %} +
+
+
+
+
+ #} - {% if budgetInformation[budget.id]['otherLimits'].count > 0 %} - - -
    - {% for other in budgetInformation[budget.id]['otherLimits'] %} -
  • - - Budgeted - {{ other.amount|formatAmountPlain }} - between - {{ other.start_date.formatLocalized(monthAndDayFormat) }} - and {{ other.end_date.formatLocalized(monthAndDayFormat) }}. -
  • - {% endfor %} -
- - - {% endif %} + {% endfor %} +
- {% if loop.index % 3 == 0 %} -
- {% endif %} - {% endfor %}
{% if inactive|length > 0 %} @@ -200,16 +255,16 @@ {% endif %} {% endblock %} -{% block scripts %} - + // budgeted data: + var budgeted = {{ budgeted }}; + var available = {{ available }}; + - -{% endblock %} + + {% endblock %} diff --git a/routes/web.php b/routes/web.php index 4b480c3b1c..d8e969e4ac 100755 --- a/routes/web.php +++ b/routes/web.php @@ -134,7 +134,7 @@ Route::group( */ Route::group( ['middleware' => 'user-full-auth', 'prefix' => 'budgets', 'as' => 'budgets.'], function () { - Route::get('', ['uses' => 'BudgetController@index', 'as' => 'index']); + Route::get('{moment?}', ['uses' => 'BudgetController@index', 'as' => 'index']); Route::get('income', ['uses' => 'BudgetController@updateIncome', 'as' => 'income']); Route::get('create', ['uses' => 'BudgetController@create', 'as' => 'create']); Route::get('edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'edit']);