Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand code.
James Cole63fb4350027c
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.phpindex eb42f45c73..7e4f4af4e7 100755--- a/app/Http/Controllers/Controller.php+++ b/app/Http/Controllers/Controller.php@@ -48,36 +48,11 @@ class Controller extends BaseControllerView::share('hideBills', false);View::share('hideTags', false);- if (Auth::check()) {- $pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));- $lang = $pref->data;+ // save some formats:+ $this->monthFormat = (string)trans('config.month');+ $this->monthAndDayFormat = (string)trans('config.month_and_day');+ $this->dateTimeFormat = (string)trans('config.date_time');- App::setLocale($lang);- Carbon::setLocale(substr($lang, 0, 2));- $locale = explode(',', trans('config.locale'));- $locale = array_map('trim', $locale);-- setlocale(LC_TIME, $locale);- setlocale(LC_MONETARY, $locale);-- // save some formats:- $this->monthFormat = (string)trans('config.month');- $this->monthAndDayFormat = (string)trans('config.month_and_day');- $this->dateTimeFormat = (string)trans('config.date_time');-- // change localeconv to a new array:- $numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY);- $localeconv = [- 'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)),- 'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)),- 'frac_digits' => $numberFormatter->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS),- ];- View::share('monthFormat', $this->monthFormat);- View::share('monthAndDayFormat', $this->monthAndDayFormat);- View::share('dateTimeFormat', $this->dateTimeFormat);- View::share('language', $lang);- View::share('localeconv', $localeconv);- }}/**diff --git a/app/Http/Middleware/Range.php b/app/Http/Middleware/Range.phpindex 91e6f4b9aa..2f146f2192 100644--- a/app/Http/Middleware/Range.php+++ b/app/Http/Middleware/Range.php@@ -11,6 +11,7 @@ declare(strict_types = 1);namespace FireflyIII\Http\Middleware;+use App;use Carbon\Carbon;use Closure;use FireflyIII\Exceptions\FireflyException;@@ -19,6 +20,7 @@ use Illuminate\Contracts\Auth\Guard;use Illuminate\Http\Request;use Illuminate\Support\Facades\Auth;use Navigation;+use NumberFormatter;use Preferences;use Session;use View;@@ -62,36 +64,56 @@ class Rangepublic function handle(Request $request, Closure $theNext, $guard = null){if (!Auth::guard($guard)->guest()) {- // ignore preference. set the range to be the current month:- if (!Session::has('start') && !Session::has('end')) {- $viewRange = Preferences::get('viewRange', '1M')->data;- $start = new Carbon;- $start = Navigation::updateStartDate($viewRange, $start);- $end = Navigation::updateEndDate($viewRange, $start);+ // set start, end and finish:+ $this->setRange();- Session::put('start', $start);- Session::put('end', $end);- }- if (!Session::has('first')) {- /** @var JournalRepositoryInterface $repository */- $repository = app(JournalRepositoryInterface::class);- $journal = $repository->first();- $first = Carbon::now()->startOfYear();-- if (!is_null($journal->id)) {- $first = $journal->date;- }- Session::put('first', $first);- }+ // get variables for date range:+ $this->datePicker();+ // set view variables.+ $this->configureView();}- $this->datePicker();return $theNext($request);}+ private function configureView()+ {+ $pref = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'));+ $lang = $pref->data;++ App::setLocale($lang);+ Carbon::setLocale(substr($lang, 0, 2));+ $locale = explode(',', trans('config.locale'));+ $locale = array_map('trim', $locale);++ setlocale(LC_TIME, $locale);+ setlocale(LC_MONETARY, $locale);++ // save some formats:+ $monthFormat = (string)trans('config.month');+ $monthAndDayFormat = (string)trans('config.month_and_day');+ $dateTimeFormat = (string)trans('config.date_time');++ // change localeconv to a new array:+ $numberFormatter = numfmt_create($lang, NumberFormatter::CURRENCY);+ $localeconv = [+ 'mon_decimal_point' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL)),+ 'mon_thousands_sep' => $numberFormatter->getSymbol($numberFormatter->getAttribute(NumberFormatter::MONETARY_GROUPING_SEPARATOR_SYMBOL)),+ 'frac_digits' => $numberFormatter->getAttribute(NumberFormatter::MAX_FRACTION_DIGITS),+ ];+ View::share('monthFormat', $monthFormat);+ View::share('monthAndDayFormat', $monthAndDayFormat);+ View::share('dateTimeFormat', $dateTimeFormat);+ View::share('language', $lang);+ View::share('localeconv', $localeconv);+ }++ /**+ * @throws FireflyException+ */private function datePicker(){$viewRange = Preferences::get('viewRange', '1M')->data;@@ -141,4 +163,33 @@ class RangeView::share('dpRanges', $ranges);}+ /**+ *+ */+ private function setRange()+ {+ // ignore preference. set the range to be the current month:+ if (!Session::has('start') && !Session::has('end')) {++ $viewRange = Preferences::get('viewRange', '1M')->data;+ $start = new Carbon;+ $start = Navigation::updateStartDate($viewRange, $start);+ $end = Navigation::updateEndDate($viewRange, $start);++ Session::put('start', $start);+ Session::put('end', $end);+ }+ if (!Session::has('first')) {+ /** @var JournalRepositoryInterface $repository */+ $repository = app(JournalRepositoryInterface::class);+ $journal = $repository->first();+ $first = Carbon::now()->startOfYear();++ if (!is_null($journal->id)) {+ $first = $journal->date;+ }+ Session::put('first', $first);+ }+ }+}