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 #}
+ | Budget | +{{ 'budgeted'|_ }} | +Spent | +Left | +||||||
---|---|---|---|---|---|---|---|---|---|---|
- {{ 'budgeted'|_ }}
- - {{ session('start').formatLocalized(monthAndDayFormat) }} - - {{ session('end').formatLocalized(monthAndDayFormat) }} - |
- | -|||||||||
- {{ '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 }} + | + {# +
+ + + | +
+
+
+
+ |
+
+ {{ 'spent'|_ }}
+ + {{ session('start').formatLocalized(monthAndDayFormat) }} - + {{ session('end').formatLocalized(monthAndDayFormat) }} + + |
+ + + | +
+
|
+