2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
* HomeController.php
|
2017-10-21 08:40:00 +02:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-05-20 12:27:31 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
2016-10-05 06:52:15 +02:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 14:41:58 +01:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
2017-04-09 07:44:22 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-20 08:57:45 +02:00
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2015-02-07 06:49:24 +01:00
|
|
|
use Carbon\Carbon;
|
2017-12-28 19:03:15 +01:00
|
|
|
use FireflyIII\Events\RequestedVersionCheckStatus;
|
2016-11-20 08:57:48 +01:00
|
|
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
2018-04-06 21:38:43 +02:00
|
|
|
use FireflyIII\Http\Middleware\Installer;
|
2017-12-19 19:25:50 +01:00
|
|
|
use FireflyIII\Http\Middleware\IsDemoUser;
|
|
|
|
use FireflyIII\Http\Middleware\IsSandStormUser;
|
2017-12-15 12:59:21 +01:00
|
|
|
use FireflyIII\Models\AccountType;
|
2017-03-05 13:21:36 +01:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2017-10-16 19:01:26 +02:00
|
|
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
2016-06-11 07:38:30 +02:00
|
|
|
use Illuminate\Http\Request;
|
2016-05-13 15:53:39 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2016-06-11 07:38:30 +02:00
|
|
|
use Log;
|
2015-02-07 06:49:24 +01:00
|
|
|
use Preferences;
|
2016-10-29 07:44:46 +02:00
|
|
|
use View;
|
2016-02-11 12:49:04 +01:00
|
|
|
|
2015-02-06 21:23:14 +01:00
|
|
|
/**
|
2017-11-15 12:25:49 +01:00
|
|
|
* Class HomeController.
|
2015-02-06 21:23:14 +01:00
|
|
|
*/
|
2015-02-06 07:23:26 +01:00
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
2016-01-09 08:20:55 +01:00
|
|
|
/**
|
|
|
|
* HomeController constructor.
|
|
|
|
*/
|
2016-01-08 18:29:47 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-01-08 19:13:51 +01:00
|
|
|
parent::__construct();
|
2017-12-16 19:46:36 +01:00
|
|
|
app('view')->share('title', 'Firefly III');
|
|
|
|
app('view')->share('mainTitleIcon', 'fa-fire');
|
2018-04-06 21:38:43 +02:00
|
|
|
$this->middleware(Installer::class);
|
2017-12-19 19:25:50 +01:00
|
|
|
$this->middleware(IsDemoUser::class)->except(['dateRange', 'index']);
|
|
|
|
$this->middleware(IsSandStormUser::class)->only('routes');
|
2018-04-06 21:38:43 +02:00
|
|
|
|
2016-01-08 18:29:47 +01:00
|
|
|
}
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2016-06-11 07:38:30 +02:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
2017-12-15 12:59:21 +01:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2016-06-11 07:38:30 +02:00
|
|
|
*/
|
|
|
|
public function dateRange(Request $request)
|
2015-03-02 13:19:13 +01:00
|
|
|
{
|
2016-06-11 07:38:30 +02:00
|
|
|
$start = new Carbon($request->get('start'));
|
|
|
|
$end = new Carbon($request->get('end'));
|
|
|
|
$label = $request->get('label');
|
2016-04-29 08:56:56 +02:00
|
|
|
$isCustomRange = false;
|
2016-04-25 21:37:08 +02:00
|
|
|
|
2016-06-11 07:38:30 +02:00
|
|
|
Log::debug('Received dateRange', ['start' => $request->get('start'), 'end' => $request->get('end'), 'label' => $request->get('label')]);
|
|
|
|
|
2016-04-25 21:37:08 +02:00
|
|
|
// check if the label is "everything" or "Custom range" which will betray
|
|
|
|
// a possible problem with the budgets.
|
2018-04-02 15:10:40 +02:00
|
|
|
if ($label === (string)trans('firefly.everything') || $label === (string)trans('firefly.customRange')) {
|
2016-04-29 08:56:56 +02:00
|
|
|
$isCustomRange = true;
|
2016-06-11 07:38:30 +02:00
|
|
|
Log::debug('Range is now marked as "custom".');
|
2016-04-25 21:37:08 +02:00
|
|
|
}
|
2015-03-02 13:19:13 +01:00
|
|
|
|
|
|
|
$diff = $start->diffInDays($end);
|
|
|
|
|
|
|
|
if ($diff > 50) {
|
2018-04-02 15:10:40 +02:00
|
|
|
$request->session()->flash('warning', (string)trans('firefly.warning_much_data', ['days' => $diff]));
|
2015-03-02 13:19:13 +01:00
|
|
|
}
|
2015-03-02 12:35:14 +01:00
|
|
|
|
2017-12-15 12:59:21 +01:00
|
|
|
$request->session()->put('is_custom_range', $isCustomRange);
|
|
|
|
Log::debug(sprintf('Set is_custom_range to %s', var_export($isCustomRange, true)));
|
|
|
|
$request->session()->put('start', $start);
|
|
|
|
Log::debug(sprintf('Set start to %s', $start->format('Y-m-d H:i:s')));
|
|
|
|
$request->session()->put('end', $end);
|
|
|
|
Log::debug(sprintf('Set end to %s', $end->format('Y-m-d H:i:s')));
|
|
|
|
|
2018-03-10 20:30:09 +01:00
|
|
|
return response()->json(['ok' => 'ok']);
|
2015-03-02 12:35:14 +01:00
|
|
|
}
|
|
|
|
|
2017-11-01 20:23:28 +01:00
|
|
|
|
2015-02-06 07:23:26 +01:00
|
|
|
/**
|
2017-03-05 13:21:36 +01:00
|
|
|
* @param AccountRepositoryInterface $repository
|
2015-04-13 20:43:58 +02:00
|
|
|
*
|
2016-11-05 18:43:18 +01:00
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
2015-02-06 07:23:26 +01:00
|
|
|
*/
|
2017-03-05 13:21:36 +01:00
|
|
|
public function index(AccountRepositoryInterface $repository)
|
2015-02-06 07:23:26 +01:00
|
|
|
{
|
2016-04-26 21:40:15 +02:00
|
|
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
2016-10-09 08:18:47 +02:00
|
|
|
$count = $repository->count($types);
|
2015-06-01 18:13:54 +02:00
|
|
|
|
2017-11-15 12:25:49 +01:00
|
|
|
if (0 === $count) {
|
2015-07-06 16:27:21 +02:00
|
|
|
return redirect(route('new-user.index'));
|
2015-06-01 18:13:54 +02:00
|
|
|
}
|
2016-10-29 07:44:46 +02:00
|
|
|
$subTitle = trans('firefly.welcomeBack');
|
|
|
|
$transactions = [];
|
|
|
|
$frontPage = Preferences::get(
|
2017-11-15 10:52:29 +01:00
|
|
|
'frontPageAccounts',
|
|
|
|
$repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()
|
2016-05-13 17:22:24 +02:00
|
|
|
);
|
2016-02-05 15:41:40 +01:00
|
|
|
/** @var Carbon $start */
|
2016-02-07 08:31:21 +01:00
|
|
|
$start = session('start', Carbon::now()->startOfMonth());
|
2016-02-05 15:41:40 +01:00
|
|
|
/** @var Carbon $end */
|
2017-09-16 09:24:48 +02:00
|
|
|
$end = session('end', Carbon::now()->endOfMonth());
|
|
|
|
$accounts = $repository->getAccountsById($frontPage->data);
|
2017-11-17 19:31:48 +01:00
|
|
|
$today = new Carbon;
|
2015-04-09 11:52:35 +02:00
|
|
|
|
2017-10-16 19:01:26 +02:00
|
|
|
// zero bills? Hide some elements from view.
|
|
|
|
/** @var BillRepositoryInterface $billRepository */
|
|
|
|
$billRepository = app(BillRepositoryInterface::class);
|
|
|
|
$billCount = $billRepository->getBills()->count();
|
|
|
|
|
2015-02-07 06:49:24 +01:00
|
|
|
foreach ($accounts as $account) {
|
2016-11-20 08:57:48 +01:00
|
|
|
$collector = app(JournalCollectorInterface::class);
|
2016-11-05 10:42:31 +01:00
|
|
|
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit(10)->setPage(1);
|
2016-11-25 16:55:04 +01:00
|
|
|
$set = $collector->getJournals();
|
|
|
|
$transactions[] = [$set, $account];
|
2015-02-07 06:49:24 +01:00
|
|
|
}
|
2015-06-03 21:25:11 +02:00
|
|
|
|
2017-12-28 19:03:15 +01:00
|
|
|
// fire check update event:
|
|
|
|
event(new RequestedVersionCheckStatus(auth()->user()));
|
|
|
|
|
2015-07-12 12:45:41 +02:00
|
|
|
return view(
|
2017-11-15 10:52:29 +01:00
|
|
|
'index',
|
2018-03-09 05:44:35 +01:00
|
|
|
compact('count', 'subTitle', 'transactions', 'billCount', 'start', 'end', 'today')
|
2015-07-12 12:45:41 +02:00
|
|
|
);
|
2015-02-06 07:23:26 +01:00
|
|
|
}
|
2015-06-29 15:23:50 +02:00
|
|
|
|
2015-02-06 04:39:52 +01:00
|
|
|
}
|