diff --git a/app/Http/Controllers/Bill/IndexController.php b/app/Http/Controllers/Bill/IndexController.php index f40768057a..ba5fbba79c 100644 --- a/app/Http/Controllers/Bill/IndexController.php +++ b/app/Http/Controllers/Bill/IndexController.php @@ -154,7 +154,7 @@ class IndexController extends Controller private function getSums(array $bills): array { $sums = []; - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(false); /** @var array $group */ foreach ($bills as $groupOrder => $group) { diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index 7f06d75ced..7110ece221 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -104,8 +104,8 @@ class IndexController extends Controller Log::debug('Start of IndexController::index()'); // collect some basic vars: - $range = (string)app('preferences')->get('viewRange', '1M')->data; - $start = $start ?? session('start', Carbon::now()->startOfMonth()); + $range = app('navigation')->getViewRange(true); + $start = $start ?? session('start', today(config('app.timezone'))->startOfMonth()); $end = $end ?? app('navigation')->endOfPeriod($start, $range); $defaultCurrency = app('amount')->getDefaultCurrency(); $currencies = $this->currencyRepository->get(); diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index aadd6e1e2b..0aa5c67e93 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -89,7 +89,7 @@ class CategoryController extends Controller /** @var CategoryRepositoryInterface $repository */ $repository = app(CategoryRepositoryInterface::class); $start = $repository->firstUseDate($category) ?? $this->getDate(); - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(false); $start = app('navigation')->startOfPeriod($start, $range); $end = $this->getDate(); @@ -118,8 +118,8 @@ class CategoryController extends Controller */ public function frontPage(): JsonResponse { - $start = session('start', Carbon::now()->startOfMonth()); - $end = session('end', Carbon::now()->endOfMonth()); + $start = session('start', today(config('app.timezone'))->startOfMonth()); + $end = session('end', today(config('app.timezone'))->endOfMonth()); // chart properties for cache: $cache = new CacheProperties(); $cache->addProperty($start); @@ -293,7 +293,7 @@ class CategoryController extends Controller */ public function specificPeriod(Category $category, Carbon $date): JsonResponse { - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(false); $start = app('navigation')->startOfPeriod($date, $range); $end = session()->get('end'); if ($end < $start) { diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php index efab3cc8d3..be8226b255 100644 --- a/app/Http/Controllers/PreferencesController.php +++ b/app/Http/Controllers/PreferencesController.php @@ -96,7 +96,7 @@ class PreferencesController extends Controller ksort($groupedAccounts); $accountIds = $accounts->pluck('id')->toArray(); - $viewRangePref = app('preferences')->get('viewRange', '1M'); + $viewRangePref = app('navigation')->getViewRange(false); $viewRange = $viewRangePref->data; $frontPageAccounts = app('preferences')->get('frontPageAccounts', $accountIds); diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.php index 3db1a776a9..5fb60e1c94 100644 --- a/app/Http/Middleware/Range.php +++ b/app/Http/Middleware/Range.php @@ -106,7 +106,7 @@ class Range setlocale(LC_TIME, $localeArray); $moneyResult = setlocale(LC_MONETARY, $localeArray); - // send error to view if could not set money format + // send error to view, if could not set money format if (false === $moneyResult) { Log::error('Could not set locale. The following array doesnt work: ', $localeArray); app('view')->share('invalidMonetaryLocale', true); diff --git a/app/Support/Http/Controllers/GetConfigurationData.php b/app/Support/Http/Controllers/GetConfigurationData.php index 80ca465497..fd06294bfb 100644 --- a/app/Support/Http/Controllers/GetConfigurationData.php +++ b/app/Support/Http/Controllers/GetConfigurationData.php @@ -95,7 +95,7 @@ trait GetConfigurationData */ protected function getDateRangeConfig(): array // get configuration + get preferences. { - $viewRange = (string)app('preferences')->get('viewRange', '1M')->data; + $viewRange = app('navigation')->getViewRange(false); /** @var Carbon $start */ $start = session('start'); /** @var Carbon $end */ @@ -117,18 +117,20 @@ trait GetConfigurationData $customPeriodEnd = app('navigation')->endOfPeriod($customPeriodStart, $viewRange); $ranges[$index] = [$customPeriodStart, $customPeriodEnd]; } - // then add previous range and next range - $previousDate = app('navigation')->subtractPeriod($start, $viewRange); - $index = app('navigation')->periodShow($previousDate, $viewRange); - $previousStart = app('navigation')->startOfPeriod($previousDate, $viewRange); - $previousEnd = app('navigation')->endOfPeriod($previousStart, $viewRange); - $ranges[$index] = [$previousStart, $previousEnd]; + // then add previous range and next range, but skip this for the lastX and YTD stuff. + if (!in_array($viewRange, config('firefly.dynamic_date_ranges', []), true)) { + $previousDate = app('navigation')->subtractPeriod($start, $viewRange); + $index = app('navigation')->periodShow($previousDate, $viewRange); + $previousStart = app('navigation')->startOfPeriod($previousDate, $viewRange); + $previousEnd = app('navigation')->endOfPeriod($previousStart, $viewRange); + $ranges[$index] = [$previousStart, $previousEnd]; - $nextDate = app('navigation')->addPeriod($start, $viewRange, 0); - $index = app('navigation')->periodShow($nextDate, $viewRange); - $nextStart = app('navigation')->startOfPeriod($nextDate, $viewRange); - $nextEnd = app('navigation')->endOfPeriod($nextStart, $viewRange); - $ranges[$index] = [$nextStart, $nextEnd]; + $nextDate = app('navigation')->addPeriod($start, $viewRange, 0); + $index = app('navigation')->periodShow($nextDate, $viewRange); + $nextStart = app('navigation')->startOfPeriod($nextDate, $viewRange); + $nextEnd = app('navigation')->endOfPeriod($nextStart, $viewRange); + $ranges[$index] = [$nextStart, $nextEnd]; + } // today: /** @var Carbon $todayStart */ diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php index 60d1d2e5c6..1dd659259d 100644 --- a/app/Support/Http/Controllers/PeriodOverview.php +++ b/app/Support/Http/Controllers/PeriodOverview.php @@ -85,7 +85,7 @@ trait PeriodOverview */ protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array { - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(true); [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; // properties for cache @@ -95,7 +95,7 @@ trait PeriodOverview $cache->addProperty('account-show-period-entries'); $cache->addProperty($account->id); if ($cache->has()) { - // return $cache->get(); + return $cache->get(); } /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); @@ -276,7 +276,7 @@ trait PeriodOverview */ protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array { - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(true); [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; // properties for entries with their amounts. @@ -356,7 +356,7 @@ trait PeriodOverview */ protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array { - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(true); [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; @@ -412,7 +412,7 @@ trait PeriodOverview protected function getNoCategoryPeriodOverview(Carbon $theDate): array { Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d'))); - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(true); $first = $this->journalRepos->firstNull(); $start = null === $first ? new Carbon() : $first->date; $end = clone $theDate; @@ -483,7 +483,7 @@ trait PeriodOverview */ protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags. { - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(true); [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; // properties for cache @@ -558,7 +558,7 @@ trait PeriodOverview */ protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array { - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('navigation')->getViewRange(true); $types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType)); [$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index cdf7844c22..0f46c420f5 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -694,7 +694,7 @@ class Navigation 'MTD', ]; if (in_array($range, $list, true)) { - $end = Carbon::now(config('app.timezone')); + $end = today(config('app.timezone')); $end->endOfDay(); Log::debug(sprintf('updateEndDate returns "%s"', $end->format('Y-m-d'))); return $end; diff --git a/config/firefly.php b/config/firefly.php index 9c80a9fa11..ce9cb18201 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -878,6 +878,9 @@ return [ 'valid_cc_fields' => ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'], 'valid_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'], + // dynamic date ranges are as follows: + 'dynamic_date_ranges' => ['last7', 'last30', 'last90', 'last365', 'MTD', 'QTD', 'YTD'], + // only used in v1 'allowed_sort_parameters' => ['order', 'name', 'iban'], ]; diff --git a/resources/views/preferences/index.twig b/resources/views/preferences/index.twig index f0efadc2fa..63bbfc09a5 100644 --- a/resources/views/preferences/index.twig +++ b/resources/views/preferences/index.twig @@ -193,6 +193,14 @@ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +