mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 10:53:37 +00:00
Fixed #267
This commit is contained in:
@@ -18,8 +18,9 @@ use FireflyIII\Models\AccountType;
|
|||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Input;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Route;
|
use Route;
|
||||||
use Session;
|
use Session;
|
||||||
@@ -41,18 +42,24 @@ class HomeController extends Controller
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dateRange()
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
*/
|
||||||
|
public function dateRange(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$start = new Carbon(Input::get('start'));
|
$start = new Carbon($request->get('start'));
|
||||||
$end = new Carbon(Input::get('end'));
|
$end = new Carbon($request->get('end'));
|
||||||
$label = Input::get('label');
|
$label = $request->get('label');
|
||||||
$isCustomRange = false;
|
$isCustomRange = false;
|
||||||
|
|
||||||
|
Log::debug('Received dateRange', ['start' => $request->get('start'), 'end' => $request->get('end'), 'label' => $request->get('label')]);
|
||||||
|
|
||||||
// check if the label is "everything" or "Custom range" which will betray
|
// check if the label is "everything" or "Custom range" which will betray
|
||||||
// a possible problem with the budgets.
|
// a possible problem with the budgets.
|
||||||
if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {
|
if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {
|
||||||
$isCustomRange = true;
|
$isCustomRange = true;
|
||||||
|
Log::debug('Range is now marked as "custom".');
|
||||||
}
|
}
|
||||||
|
|
||||||
$diff = $start->diffInDays($end);
|
$diff = $start->diffInDays($end);
|
||||||
@@ -173,11 +180,11 @@ class HomeController extends Controller
|
|||||||
$search = [
|
$search = [
|
||||||
'{account}', '{what}', '{rule}', '{tj}', '{category}', '{budget}', '{code}', '{date}', '{attachment}', '{bill}', '{limitrepetition}',
|
'{account}', '{what}', '{rule}', '{tj}', '{category}', '{budget}', '{code}', '{date}', '{attachment}', '{bill}', '{limitrepetition}',
|
||||||
'{currency}', '{jobKey}', '{piggyBank}', '{ruleGroup}', '{rule}', '{route}', '{unfinishedJournal}',
|
'{currency}', '{jobKey}', '{piggyBank}', '{ruleGroup}', '{rule}', '{route}', '{unfinishedJournal}',
|
||||||
'{reportType}', '{start_date}', '{end_date}', '{accountList}','{tag}','{journalList}'
|
'{reportType}', '{start_date}', '{end_date}', '{accountList}', '{tag}', '{journalList}',
|
||||||
|
|
||||||
];
|
];
|
||||||
$replace = [1, 'asset', 1, 1, 1, 1, 'abc', '2016-01-01', 1, 1, 1, 1, 1, 1, 1, 1, 'index', 1,
|
$replace = [1, 'asset', 1, 1, 1, 1, 'abc', '2016-01-01', 1, 1, 1, 1, 1, 1, 1, 1, 'index', 1,
|
||||||
'default', '20160101', '20160131', '1,2',1,'1,2'
|
'default', '20160101', '20160131', '1,2', 1, '1,2',
|
||||||
];
|
];
|
||||||
if (count($search) != count($replace)) {
|
if (count($search) != count($replace)) {
|
||||||
echo 'count';
|
echo 'count';
|
||||||
|
@@ -13,6 +13,7 @@ namespace FireflyIII\Http\Middleware;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Contracts\Auth\Guard;
|
use Illuminate\Contracts\Auth\Guard;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -64,7 +65,6 @@ class Range
|
|||||||
// ignore preference. set the range to be the current month:
|
// ignore preference. set the range to be the current month:
|
||||||
if (!Session::has('start') && !Session::has('end')) {
|
if (!Session::has('start') && !Session::has('end')) {
|
||||||
|
|
||||||
/** @var \FireflyIII\Models\Preference $viewRange */
|
|
||||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||||
$start = new Carbon;
|
$start = new Carbon;
|
||||||
$start = Navigation::updateStartDate($viewRange, $start);
|
$start = Navigation::updateStartDate($viewRange, $start);
|
||||||
@@ -94,14 +94,51 @@ class Range
|
|||||||
|
|
||||||
private function datePicker()
|
private function datePicker()
|
||||||
{
|
{
|
||||||
|
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||||
|
$start = Session::get('start');
|
||||||
|
$end = Session::get('end');
|
||||||
|
$prevStart = Navigation::subtractPeriod($start, $viewRange);// subtract for previous period
|
||||||
|
$prevEnd = Navigation::subtractPeriod($end, $viewRange);
|
||||||
|
$nextStart = Navigation::addPeriod($start, $viewRange, 0);// add for previous period
|
||||||
|
$nextEnd = Navigation::addPeriod($end, $viewRange, 0);
|
||||||
|
$ranges = [];
|
||||||
|
$ranges['current'] = [$start->format('Y-m-d'), $end->format('Y-m-d')];
|
||||||
|
$ranges['previous'] = [$prevStart->format('Y-m-d'), $prevEnd->format('Y-m-d')];
|
||||||
|
$ranges['next'] = [$nextStart->format('Y-m-d'), $nextEnd->format('Y-m-d')];
|
||||||
|
|
||||||
|
switch ($viewRange) {
|
||||||
|
case '1D':
|
||||||
|
$format = (string)trans('config.month_and_day');
|
||||||
|
break;
|
||||||
|
case '3M':
|
||||||
|
$format = (string)trans('config.quarter_in_year');
|
||||||
|
break;
|
||||||
|
case '6M':
|
||||||
|
$format = (string)trans('config.half_year');
|
||||||
|
break;
|
||||||
|
case '1Y':
|
||||||
|
$format = (string)trans('config.year');
|
||||||
|
break;
|
||||||
|
case '1M':
|
||||||
|
$format = (string)trans('config.month');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new FireflyException('The date picker does not yet support "' . $viewRange . '".');
|
||||||
|
case '1W':
|
||||||
|
$format = (string)trans('config.week_in_year');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$current = Carbon::now()->formatLocalized('%B %Y');
|
$current = $start->formatLocalized($format);
|
||||||
$next = Carbon::now()->endOfMonth()->addDay()->formatLocalized('%B %Y');
|
$next = $nextStart->formatLocalized($format);
|
||||||
$prev = Carbon::now()->startOfMonth()->subDay()->formatLocalized('%B %Y');
|
$prev = $prevStart->formatLocalized($format);
|
||||||
View::share('currentPeriodName', $current);
|
View::share('dpStart', $start->format('Y-m-d'));
|
||||||
View::share('previousPeriodName', $prev);
|
View::share('dpEnd', $end->format('Y-m-d'));
|
||||||
View::share('nextPeriodName', $next);
|
View::share('dpCurrent', $current);
|
||||||
|
View::share('dpPrevious', $prev);
|
||||||
|
View::share('dpNext', $next);
|
||||||
|
View::share('dpRanges', $ranges);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,14 +6,9 @@ $(function () {
|
|||||||
$('.currency-option').click(currencySelect);
|
$('.currency-option').click(currencySelect);
|
||||||
|
|
||||||
var ranges = {};
|
var ranges = {};
|
||||||
// range for the current period:
|
ranges[dateRangeConfig.currentPeriod] = [moment(dateRangeConfig.ranges.current[0]), moment(dateRangeConfig.ranges.current[1])];
|
||||||
ranges[dateRangeConfig.currentPeriod] = [moment().startOf('month'), moment().endOf('month')];
|
ranges[dateRangeConfig.previousPeriod] = [moment(dateRangeConfig.ranges.previous[0]), moment(dateRangeConfig.ranges.previous[1])];
|
||||||
|
ranges[dateRangeConfig.nextPeriod] = [moment(dateRangeConfig.ranges.next[0]), moment(dateRangeConfig.ranges.next[1])];
|
||||||
// range for the previous period:
|
|
||||||
ranges[dateRangeConfig.previousPeriod] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')];
|
|
||||||
|
|
||||||
// range for the next period:
|
|
||||||
ranges[dateRangeConfig.nextPeriod] = [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')];
|
|
||||||
|
|
||||||
// range for everything:
|
// range for everything:
|
||||||
ranges[dateRangeConfig.everything] = [dateRangeConfig.firstDate, moment()];
|
ranges[dateRangeConfig.everything] = [dateRangeConfig.firstDate, moment()];
|
||||||
@@ -51,7 +46,7 @@ $(function () {
|
|||||||
console.log('Succesfully sent new date range [' + start.format('YYYY-MM-DD') + '-' + end.format('YYYY-MM-DD') + '].');
|
console.log('Succesfully sent new date range [' + start.format('YYYY-MM-DD') + '-' + end.format('YYYY-MM-DD') + '].');
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
console.log('Could not send new date range [' + start.format('YYYY-MM-DD') + '-' + end.format('YYYY-MM-DD') + ']');
|
console.log('Could not send new date range.');
|
||||||
alert('Could not change date range');
|
alert('Could not change date range');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -167,20 +167,21 @@
|
|||||||
|
|
||||||
// date range picker configuration:
|
// date range picker configuration:
|
||||||
var dateRangeConfig = {
|
var dateRangeConfig = {
|
||||||
startDate: moment("{{ Session.get('start').format('Y-m-d') }}"),
|
startDate: moment("{{ dpStart }}"),
|
||||||
endDate: moment("{{ Session.get('end').format('Y-m-d') }}"),
|
endDate: moment("{{ dpEnd }}"),
|
||||||
linkTitle: "{{ Session.get('start').formatLocalized(monthAndDayFormat) }} - {{ Session.get('end').formatLocalized(monthAndDayFormat) }}",
|
linkTitle: "{{ Session.get('start').formatLocalized(monthAndDayFormat) }} - {{ Session.get('end').formatLocalized(monthAndDayFormat) }}",
|
||||||
URL: "{{ route('daterange') }}",
|
URL: "{{ route('daterange') }}",
|
||||||
firstDate: moment("{{ Session.get('first').format('Y-m-d') }}"),
|
firstDate: moment("{{ Session.get('first').format('Y-m-d') }}"),
|
||||||
currentPeriod: "{{ currentPeriodName }}",
|
currentPeriod: "{{ dpCurrent }}",
|
||||||
previousPeriod: "{{ previousPeriodName }}",
|
previousPeriod: "{{ dpPrevious }}",
|
||||||
nextPeriod: "{{ nextPeriodName }}",
|
nextPeriod: "{{ dpNext }}",
|
||||||
everything: '{{ 'everything'|_ }}',
|
everything: '{{ 'everything'|_ }}',
|
||||||
customRangeLabel: '{{ 'customRange'|_ }}',
|
customRangeLabel: '{{ 'customRange'|_ }}',
|
||||||
applyLabel: '{{ 'apply'|_ }}',
|
applyLabel: '{{ 'apply'|_ }}',
|
||||||
cancelLabel: '{{ 'cancel'|_ }}',
|
cancelLabel: '{{ 'cancel'|_ }}',
|
||||||
fromLabel: '{{ 'from'|_ }}',
|
fromLabel: '{{ 'from'|_ }}',
|
||||||
toLabel: '{{ 'to'|_ }}'
|
toLabel: '{{ 'to'|_ }}',
|
||||||
|
ranges: {{ dpRanges|json_encode|raw }}
|
||||||
};
|
};
|
||||||
|
|
||||||
var token = "{{ csrf_token() }}";
|
var token = "{{ csrf_token() }}";
|
||||||
|
Reference in New Issue
Block a user