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
{
$sums = [];
$range = app('preferences')->get('viewRange', '1M')->data;
$range = app('navigation')->getViewRange(false);
/** @var array $group */
foreach ($bills as $groupOrder => $group) {

View File

@ -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();

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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 */

View File

@ -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];

View File

@ -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;

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_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'],
];

View File

@ -193,6 +193,14 @@
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
value="last7" {% if viewRange == 'last7' %} checked {% endif %}>
{{ 'pref_last7'|_ }}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="viewRange"
@ -200,6 +208,20 @@
{{ 'pref_1M'|_ }}
</label>
</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">
<label>
@ -208,6 +230,20 @@
{{ 'pref_3M'|_ }}
</label>
</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">
<label>
@ -223,6 +259,20 @@
{{ 'pref_1Y'|_ }}
</label>
</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>