Add everything range

This commit is contained in:
James Cole
2015-03-02 13:19:13 +01:00
parent 7183d72e5c
commit edda470bf8
5 changed files with 28 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ use Carbon\Carbon;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Session;
/** /**
* Class ReportHelper * Class ReportHelper
@@ -40,12 +41,7 @@ class ReportHelper implements ReportHelperInterface
*/ */
public function firstDate() public function firstDate()
{ {
$journal = Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(); return Session::get('first');
if ($journal) {
return $journal->date;
}
return Carbon::now();
} }
/** /**

View File

@@ -3,12 +3,11 @@
use Auth; use Auth;
use Cache; use Cache;
use Carbon\Carbon; use Carbon\Carbon;
use Navigation; use Input;
use Preferences; use Preferences;
use Redirect; use Redirect;
use Session; use Session;
use URL;
use Input;
/** /**
* Class HomeController * Class HomeController
* *
@@ -24,12 +23,19 @@ class HomeController extends Controller
{ {
} }
public function dateRange() { public function dateRange()
{
$start = new Carbon(Input::get('start')); $start = new Carbon(Input::get('start'));
$end = new Carbon(Input::get('end')); $end = new Carbon(Input::get('end'));
Session::put('start',$start); $diff = $start->diffInDays($end);
Session::put('end',$end);
if ($diff > 50) {
Session::flash('warning', $diff . ' days of data may take a while to load.');
}
Session::put('start', $start);
Session::put('end', $end);
} }
/** /**

View File

@@ -6,9 +6,9 @@ namespace FireflyIII\Http\Middleware;
use Carbon\Carbon; use Carbon\Carbon;
use Closure; use Closure;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Navigation;
use Preferences; use Preferences;
use Session; use Session;
use Navigation;
/** /**
* Class SessionFilter * Class SessionFilter
@@ -59,6 +59,14 @@ class Range
Session::put('start', $start); Session::put('start', $start);
Session::put('end', $end); Session::put('end', $end);
} }
if (!Session::has('first')) {
$journal = $this->auth->user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
if ($journal) {
Session::put('first', $journal->date);
} else {
Session::put('first', Carbon::now());
}
}
} }

View File

@@ -7,7 +7,8 @@ $(function () {
ranges: { ranges: {
'This Month': [moment().startOf('month'), moment().endOf('month')], 'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')], 'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')],
'Next Month': [moment().add('month', 1).startOf('month'), moment().add('month', 1).endOf('month')] 'Next Month': [moment().add('month', 1).startOf('month'), moment().add('month', 1).endOf('month')],
'Everything': [firstDate, moment()]
}, },
opens: 'left', opens: 'left',
@@ -21,6 +22,7 @@ $(function () {
$.post(dateRangeURL, { $.post(dateRangeURL, {
start: start.format('YYYY-MM-DD'), start: start.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD'), end: end.format('YYYY-MM-DD'),
label: label,
_token: token _token: token
}).success(function() { }).success(function() {
window.location.reload(true); window.location.reload(true);

View File

@@ -128,6 +128,7 @@
var titleString = "{{Session::get('start')->format('j M Y')}} - {{Session::get('end')->format('j M Y')}}"; var titleString = "{{Session::get('start')->format('j M Y')}} - {{Session::get('end')->format('j M Y')}}";
var dateRangeURL = "{{route('daterange')}}"; var dateRangeURL = "{{route('daterange')}}";
var token = "{{csrf_token()}}"; var token = "{{csrf_token()}}";
var firstDate = moment("{{Session::get('first')->format('Y-m-d')}}");
$('#daterange span').text(titleString); $('#daterange span').text(titleString);
</script> </script>