From f5a21f64c06fcf4c351c7b9b62bbd545f1d10649 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 22 Jan 2016 10:10:51 +0100 Subject: [PATCH] More magic words. --- app/Http/Controllers/ReportController.php | 11 +-------- app/Support/Binder/Date.php | 30 +++++++++++++---------- resources/views/reports/index.twig | 6 ++--- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index c462b879ce..0f973c6c16 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -45,14 +45,6 @@ class ReportController extends Controller { $start = Session::get('first'); $months = $this->helper->listOfMonths($start); - $startOfMonth = clone Session::get('start'); - $endOfMonth = clone Session::get('start'); - $startOfYear = clone Session::get('start'); - $endOfYear = clone Session::get('start'); - $startOfMonth->startOfMonth(); - $endOfMonth->endOfMonth(); - $startOfYear->startOfYear(); - $endOfYear->endOfYear(); // does the user have shared accounts? $accounts = $repository->getAccounts(['Default account', 'Asset account']); @@ -67,8 +59,7 @@ class ReportController extends Controller return view( 'reports.index', compact( - 'months', 'accounts', 'start', 'accountList', - 'startOfMonth', 'endOfMonth', 'startOfYear', 'endOfYear' + 'months', 'accounts', 'start', 'accountList' ) ); } diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.php index 08089fc103..e03a3238f9 100644 --- a/app/Support/Binder/Date.php +++ b/app/Support/Binder/Date.php @@ -32,21 +32,25 @@ class Date implements BinderInterface */ public static function routeBinder($value, $route) { - if($value === 'currentMonthStart') { - return Carbon::now()->startOfMonth(); - } - if($value === 'currentMonthEnd') { - return Carbon::now()->endOfMonth(); - } + switch ($value) { + default: + try { + $date = new Carbon($value); + } catch (Exception $e) { + Log::error('Could not parse date "' . $value . '" for user #' . Auth::user()->id); + throw new NotFoundHttpException; + } + return $date; + case 'currentMonthStart': + return Carbon::now()->startOfMonth(); + case 'currentMonthEnd': + return Carbon::now()->endOfMonth(); + case 'currentYearStart': + return Carbon::now()->startOfYear(); + case 'currentYearEnd': + return Carbon::now()->endOfYear(); - try { - $date = new Carbon($value); - } catch (Exception $e) { - Log::error('Could not parse date "' . $value . '" for user #' . Auth::user()->id); - throw new NotFoundHttpException; } - - return $date; } } diff --git a/resources/views/reports/index.twig b/resources/views/reports/index.twig index 83e38c4f56..9be5d59c57 100644 --- a/resources/views/reports/index.twig +++ b/resources/views/reports/index.twig @@ -103,8 +103,8 @@
  • {{ 'report_this_year_quick'|_ }}
  • @@ -112,7 +112,7 @@ {{ 'report_all_time_quick'|_ }}