Add options to set ranges.

This commit is contained in:
James Cole 2023-02-11 07:37:05 +01:00
parent c979cfcd89
commit f001675066
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
10 changed files with 84 additions and 29 deletions

View File

@ -154,7 +154,7 @@ class IndexController extends Controller
private function getSums(array $bills): array private function getSums(array $bills): array
{ {
$sums = []; $sums = [];
$range = app('preferences')->get('viewRange', '1M')->data; $range = app('navigation')->getViewRange(false);
/** @var array $group */ /** @var array $group */
foreach ($bills as $groupOrder => $group) { foreach ($bills as $groupOrder => $group) {

View File

@ -104,8 +104,8 @@ class IndexController extends Controller
Log::debug('Start of IndexController::index()'); Log::debug('Start of IndexController::index()');
// collect some basic vars: // collect some basic vars:
$range = (string)app('preferences')->get('viewRange', '1M')->data; $range = app('navigation')->getViewRange(true);
$start = $start ?? session('start', Carbon::now()->startOfMonth()); $start = $start ?? session('start', today(config('app.timezone'))->startOfMonth());
$end = $end ?? app('navigation')->endOfPeriod($start, $range); $end = $end ?? app('navigation')->endOfPeriod($start, $range);
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
$currencies = $this->currencyRepository->get(); $currencies = $this->currencyRepository->get();

View File

@ -89,7 +89,7 @@ class CategoryController extends Controller
/** @var CategoryRepositoryInterface $repository */ /** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class); $repository = app(CategoryRepositoryInterface::class);
$start = $repository->firstUseDate($category) ?? $this->getDate(); $start = $repository->firstUseDate($category) ?? $this->getDate();
$range = app('preferences')->get('viewRange', '1M')->data; $range = app('navigation')->getViewRange(false);
$start = app('navigation')->startOfPeriod($start, $range); $start = app('navigation')->startOfPeriod($start, $range);
$end = $this->getDate(); $end = $this->getDate();
@ -118,8 +118,8 @@ class CategoryController extends Controller
*/ */
public function frontPage(): JsonResponse public function frontPage(): JsonResponse
{ {
$start = session('start', Carbon::now()->startOfMonth()); $start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', Carbon::now()->endOfMonth()); $end = session('end', today(config('app.timezone'))->endOfMonth());
// chart properties for cache: // chart properties for cache:
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($start); $cache->addProperty($start);
@ -293,7 +293,7 @@ class CategoryController extends Controller
*/ */
public function specificPeriod(Category $category, Carbon $date): JsonResponse 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); $start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end'); $end = session()->get('end');
if ($end < $start) { if ($end < $start) {

View File

@ -96,7 +96,7 @@ class PreferencesController extends Controller
ksort($groupedAccounts); ksort($groupedAccounts);
$accountIds = $accounts->pluck('id')->toArray(); $accountIds = $accounts->pluck('id')->toArray();
$viewRangePref = app('preferences')->get('viewRange', '1M'); $viewRangePref = app('navigation')->getViewRange(false);
$viewRange = $viewRangePref->data; $viewRange = $viewRangePref->data;
$frontPageAccounts = app('preferences')->get('frontPageAccounts', $accountIds); $frontPageAccounts = app('preferences')->get('frontPageAccounts', $accountIds);

View File

@ -106,7 +106,7 @@ class Range
setlocale(LC_TIME, $localeArray); setlocale(LC_TIME, $localeArray);
$moneyResult = setlocale(LC_MONETARY, $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) { if (false === $moneyResult) {
Log::error('Could not set locale. The following array doesnt work: ', $localeArray); Log::error('Could not set locale. The following array doesnt work: ', $localeArray);
app('view')->share('invalidMonetaryLocale', true); app('view')->share('invalidMonetaryLocale', true);

View File

@ -95,7 +95,7 @@ trait GetConfigurationData
*/ */
protected function getDateRangeConfig(): array // get configuration + get preferences. protected function getDateRangeConfig(): array // get configuration + get preferences.
{ {
$viewRange = (string)app('preferences')->get('viewRange', '1M')->data; $viewRange = app('navigation')->getViewRange(false);
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start'); $start = session('start');
/** @var Carbon $end */ /** @var Carbon $end */
@ -117,18 +117,20 @@ trait GetConfigurationData
$customPeriodEnd = app('navigation')->endOfPeriod($customPeriodStart, $viewRange); $customPeriodEnd = app('navigation')->endOfPeriod($customPeriodStart, $viewRange);
$ranges[$index] = [$customPeriodStart, $customPeriodEnd]; $ranges[$index] = [$customPeriodStart, $customPeriodEnd];
} }
// then add previous range and next range // then add previous range and next range, but skip this for the lastX and YTD stuff.
$previousDate = app('navigation')->subtractPeriod($start, $viewRange); if (!in_array($viewRange, config('firefly.dynamic_date_ranges', []), true)) {
$index = app('navigation')->periodShow($previousDate, $viewRange); $previousDate = app('navigation')->subtractPeriod($start, $viewRange);
$previousStart = app('navigation')->startOfPeriod($previousDate, $viewRange); $index = app('navigation')->periodShow($previousDate, $viewRange);
$previousEnd = app('navigation')->endOfPeriod($previousStart, $viewRange); $previousStart = app('navigation')->startOfPeriod($previousDate, $viewRange);
$ranges[$index] = [$previousStart, $previousEnd]; $previousEnd = app('navigation')->endOfPeriod($previousStart, $viewRange);
$ranges[$index] = [$previousStart, $previousEnd];
$nextDate = app('navigation')->addPeriod($start, $viewRange, 0); $nextDate = app('navigation')->addPeriod($start, $viewRange, 0);
$index = app('navigation')->periodShow($nextDate, $viewRange); $index = app('navigation')->periodShow($nextDate, $viewRange);
$nextStart = app('navigation')->startOfPeriod($nextDate, $viewRange); $nextStart = app('navigation')->startOfPeriod($nextDate, $viewRange);
$nextEnd = app('navigation')->endOfPeriod($nextStart, $viewRange); $nextEnd = app('navigation')->endOfPeriod($nextStart, $viewRange);
$ranges[$index] = [$nextStart, $nextEnd]; $ranges[$index] = [$nextStart, $nextEnd];
}
// today: // today:
/** @var Carbon $todayStart */ /** @var Carbon $todayStart */

View File

@ -85,7 +85,7 @@ trait PeriodOverview
*/ */
protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array 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]; [$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
// properties for cache // properties for cache
@ -95,7 +95,7 @@ trait PeriodOverview
$cache->addProperty('account-show-period-entries'); $cache->addProperty('account-show-period-entries');
$cache->addProperty($account->id); $cache->addProperty($account->id);
if ($cache->has()) { if ($cache->has()) {
// return $cache->get(); return $cache->get();
} }
/** @var array $dates */ /** @var array $dates */
$dates = app('navigation')->blockPeriods($start, $end, $range); $dates = app('navigation')->blockPeriods($start, $end, $range);
@ -276,7 +276,7 @@ trait PeriodOverview
*/ */
protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array 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]; [$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
// properties for entries with their amounts. // properties for entries with their amounts.
@ -356,7 +356,7 @@ trait PeriodOverview
*/ */
protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array 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]; [$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
@ -412,7 +412,7 @@ trait PeriodOverview
protected function getNoCategoryPeriodOverview(Carbon $theDate): array protected function getNoCategoryPeriodOverview(Carbon $theDate): array
{ {
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d'))); 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(); $first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date; $start = null === $first ? new Carbon() : $first->date;
$end = clone $theDate; $end = clone $theDate;
@ -483,7 +483,7 @@ trait PeriodOverview
*/ */
protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags. 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]; [$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
// properties for cache // properties for cache
@ -558,7 +558,7 @@ trait PeriodOverview
*/ */
protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array 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)); $types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType));
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end]; [$start, $end] = $end < $start ? [$end, $start] : [$start, $end];

View File

@ -694,7 +694,7 @@ class Navigation
'MTD', 'MTD',
]; ];
if (in_array($range, $list, true)) { if (in_array($range, $list, true)) {
$end = Carbon::now(config('app.timezone')); $end = today(config('app.timezone'));
$end->endOfDay(); $end->endOfDay();
Log::debug(sprintf('updateEndDate returns "%s"', $end->format('Y-m-d'))); Log::debug(sprintf('updateEndDate returns "%s"', $end->format('Y-m-d')));
return $end; return $end;

View File

@ -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_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'], '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 // only used in v1
'allowed_sort_parameters' => ['order', 'name', 'iban'], 'allowed_sort_parameters' => ['order', 'name', 'iban'],
]; ];

View File

@ -193,6 +193,14 @@
</label> </label>
</div> </div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="last7" {% if viewRange == 'last7' %} checked {% endif %}>
{{ 'pref_last7'|_ }}
</label>
</div>
<div class="radio"> <div class="radio">
<label> <label>
<input type="radio" name="viewRange" <input type="radio" name="viewRange"
@ -200,6 +208,20 @@
{{ 'pref_1M'|_ }} {{ 'pref_1M'|_ }}
</label> </label>
</div> </div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="last30" {% if viewRange == 'last30' %} checked {% endif %}>
{{ 'pref_last30'|_ }}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="MTD" {% if viewRange == 'MTD' %} checked {% endif %}>
{{ 'pref_MTD'|_ }}
</label>
</div>
<div class="radio"> <div class="radio">
<label> <label>
@ -208,6 +230,20 @@
{{ 'pref_3M'|_ }} {{ 'pref_3M'|_ }}
</label> </label>
</div> </div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="last90" {% if viewRange == 'last90' %} checked {% endif %}>
{{ 'pref_last90'|_ }}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="QTD" {% if viewRange == 'QTD' %} checked {% endif %}>
{{ 'pref_QTD'|_ }}
</label>
</div>
<div class="radio"> <div class="radio">
<label> <label>
@ -223,6 +259,20 @@
{{ 'pref_1Y'|_ }} {{ 'pref_1Y'|_ }}
</label> </label>
</div> </div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="YTD" {% if viewRange == 'YTD' %} checked {% endif %}>
{{ 'pref_YTD'|_ }}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="last365" {% if viewRange == 'last365' %} checked {% endif %}>
{{ 'pref_last365'|_ }}
</label>
</div>
</div> </div>
</div> </div>