2016-05-20 08:57:45 +02:00
|
|
|
<?php
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
* HomeController.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 12:27:31 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-20 08:57:45 +02:00
|
|
|
declare(strict_types = 1);
|
|
|
|
namespace FireflyIII\Http\Controllers;
|
2015-02-06 04:39:52 +01:00
|
|
|
|
2015-07-26 15:51:07 +02:00
|
|
|
use Artisan;
|
2015-02-07 06:49:24 +01:00
|
|
|
use Carbon\Carbon;
|
2016-02-11 12:49:04 +01:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2016-05-13 17:22:24 +02:00
|
|
|
use FireflyIII\Models\AccountType;
|
2015-06-14 21:27:04 +02:00
|
|
|
use FireflyIII\Models\Tag;
|
2015-12-30 08:00:52 +01:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
2016-10-09 21:36:03 +02:00
|
|
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
2016-03-12 14:20:45 +01:00
|
|
|
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
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-02-23 16:15:53 +01:00
|
|
|
use Route;
|
2015-04-07 18:26:14 +02:00
|
|
|
use Session;
|
2015-07-26 15:51:07 +02:00
|
|
|
|
2016-02-11 12:49:04 +01:00
|
|
|
|
2015-02-06 21:23:14 +01:00
|
|
|
/**
|
|
|
|
* Class HomeController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
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();
|
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
|
|
|
|
*/
|
|
|
|
public function dateRange(Request $request)
|
2015-03-02 13:19:13 +01:00
|
|
|
{
|
2016-02-23 16:15:53 +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.
|
|
|
|
if ($label === strval(trans('firefly.everything')) || $label === strval(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) {
|
2016-03-20 11:38:01 +01:00
|
|
|
Session::flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff])));
|
2015-03-02 13:19:13 +01:00
|
|
|
}
|
2015-03-02 12:35:14 +01:00
|
|
|
|
2016-04-29 08:56:56 +02:00
|
|
|
Session::put('is_custom_range', $isCustomRange);
|
2015-03-02 13:19:13 +01:00
|
|
|
Session::put('start', $start);
|
|
|
|
Session::put('end', $end);
|
2015-03-02 12:35:14 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 16:15:53 +01:00
|
|
|
/**
|
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
2016-02-17 21:14:32 +01:00
|
|
|
public function displayError()
|
|
|
|
{
|
|
|
|
throw new FireflyException('A very simple test error.');
|
|
|
|
}
|
|
|
|
|
2015-04-07 20:54:43 +02:00
|
|
|
/**
|
2016-03-12 14:20:45 +01:00
|
|
|
* @param TagRepositoryInterface $repository
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
2015-04-07 20:54:43 +02:00
|
|
|
*/
|
2016-03-12 14:20:45 +01:00
|
|
|
public function flush(TagRepositoryInterface $repository)
|
2015-04-07 18:26:14 +02:00
|
|
|
{
|
2015-07-05 14:37:36 +02:00
|
|
|
|
|
|
|
Preferences::mark();
|
|
|
|
|
2015-06-14 21:27:04 +02:00
|
|
|
// get all tags.
|
|
|
|
// update all counts:
|
2016-03-12 14:20:45 +01:00
|
|
|
$tags = $repository->get();
|
2015-06-14 21:27:04 +02:00
|
|
|
|
|
|
|
/** @var Tag $tag */
|
|
|
|
foreach ($tags as $tag) {
|
2016-08-26 09:30:52 +02:00
|
|
|
foreach ($tag->transactionJournals()->get() as $journal) {
|
2015-06-14 21:27:04 +02:00
|
|
|
$count = $journal->tags()->count();
|
|
|
|
$journal->tag_count = $count;
|
|
|
|
$journal->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-31 20:46:37 +02:00
|
|
|
Session::clear();
|
2015-07-22 22:13:40 +02:00
|
|
|
Artisan::call('cache:clear');
|
2015-04-07 18:26:14 +02:00
|
|
|
|
2015-07-06 16:27:21 +02:00
|
|
|
return redirect(route('index'));
|
2015-03-31 20:46:37 +02:00
|
|
|
}
|
|
|
|
|
2015-02-06 07:23:26 +01:00
|
|
|
/**
|
2016-10-09 21:36:03 +02:00
|
|
|
* @param ARI $repository
|
|
|
|
* @param AccountTaskerInterface $tasker
|
2015-04-13 20:43:58 +02:00
|
|
|
*
|
2016-05-20 11:02:07 +02:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
2015-02-06 07:23:26 +01:00
|
|
|
*/
|
2016-10-10 07:49:39 +02:00
|
|
|
public function index(ARI $repository, AccountTaskerInterface $tasker)
|
2015-02-06 07:23:26 +01:00
|
|
|
{
|
2016-08-11 10:21:32 +02: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
|
|
|
|
2015-06-02 17:14:03 +02:00
|
|
|
if ($count == 0) {
|
2015-07-06 16:27:21 +02:00
|
|
|
return redirect(route('new-user.index'));
|
2015-06-01 18:13:54 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 08:31:21 +01:00
|
|
|
$title = 'Firefly';
|
|
|
|
$subTitle = trans('firefly.welcomeBack');
|
|
|
|
$mainTitleIcon = 'fa-fire';
|
|
|
|
$transactions = [];
|
2016-05-13 17:22:24 +02:00
|
|
|
$frontPage = Preferences::get(
|
2016-10-10 07:49:39 +02: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 */
|
2016-10-14 20:01:17 +02:00
|
|
|
$end = session('end', Carbon::now()->endOfMonth());
|
|
|
|
$showTour = Preferences::get('tour', true)->data;
|
|
|
|
$accounts = $repository->getAccountsById($frontPage->data);
|
|
|
|
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
2015-04-09 11:52:35 +02:00
|
|
|
|
2015-02-07 06:49:24 +01:00
|
|
|
foreach ($accounts as $account) {
|
2016-10-09 21:36:03 +02:00
|
|
|
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
2016-05-13 15:53:39 +02:00
|
|
|
$set = $set->splice(0, 10);
|
2015-06-03 21:58:06 +02:00
|
|
|
|
2015-02-07 06:49:24 +01:00
|
|
|
if (count($set) > 0) {
|
|
|
|
$transactions[] = [$set, $account];
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 21:25:11 +02:00
|
|
|
|
2015-07-12 12:45:41 +02:00
|
|
|
return view(
|
2016-10-20 16:51:05 +02:00
|
|
|
'index', compact('count', 'showTour', 'title', 'subTitle', 'mainTitleIcon', 'transactions', 'showDepositsFrontpage')
|
2015-07-12 12:45:41 +02:00
|
|
|
);
|
2015-02-06 07:23:26 +01:00
|
|
|
}
|
2015-06-29 15:23:50 +02:00
|
|
|
|
2016-02-23 16:15:53 +01:00
|
|
|
/**
|
|
|
|
* Display a list of named routes. Excludes some that cannot be "shown". This method
|
|
|
|
* is used to generate help files (down the road).
|
|
|
|
*/
|
|
|
|
public function routes()
|
|
|
|
{
|
2016-02-23 20:22:53 +01:00
|
|
|
// these routes are not relevant for the help pages:
|
2016-10-23 17:33:53 +02:00
|
|
|
$ignore = ['login', 'registe', 'logout', 'two-fac', 'lost-two', 'confirm', 'resend', 'do_confirm', 'testFla', 'json.', 'piggy-banks.add',
|
|
|
|
'piggy-banks.remove', 'preferences.', 'rules.rule.up', 'rules.rule.down', 'rules.rule-group.up', 'rules.rule-group.down', 'popup.report',
|
|
|
|
'admin.users.domains.block-','import.json','help.'
|
2016-02-23 20:22:53 +01:00
|
|
|
];
|
2016-02-23 16:15:53 +01:00
|
|
|
$routes = Route::getRoutes();
|
2016-10-23 17:33:53 +02:00
|
|
|
|
|
|
|
echo '<pre>';
|
|
|
|
|
2016-02-23 20:22:53 +01:00
|
|
|
/** @var \Illuminate\Routing\Route $route */
|
2016-02-23 16:15:53 +01:00
|
|
|
foreach ($routes as $route) {
|
2016-02-23 20:22:53 +01:00
|
|
|
$name = $route->getName();
|
|
|
|
$methods = $route->getMethods();
|
|
|
|
|
2016-10-23 17:33:53 +02:00
|
|
|
if (!is_null($name) && strlen($name) > 0 && in_array('GET', $methods) && !$this->startsWithAny($ignore, $name)) {
|
|
|
|
echo sprintf('touch %s.md', $name)."\n";
|
2016-02-23 20:22:53 +01:00
|
|
|
|
|
|
|
}
|
2016-02-23 16:15:53 +01:00
|
|
|
}
|
2016-10-23 17:33:53 +02:00
|
|
|
echo '</pre>';
|
|
|
|
|
|
|
|
echo '<hr />';
|
2016-02-23 20:22:53 +01:00
|
|
|
|
2016-10-23 17:33:53 +02:00
|
|
|
return ' ';
|
2016-02-23 16:15:53 +01:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:51:05 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function testFlash()
|
|
|
|
{
|
|
|
|
Session::flash('success', 'This is a success message.');
|
|
|
|
Session::flash('info', 'This is an info message.');
|
|
|
|
Session::flash('warning', 'This is a warning.');
|
|
|
|
Session::flash('error', 'This is an error!');
|
2016-10-22 09:33:03 +02:00
|
|
|
|
2016-10-20 16:51:05 +02:00
|
|
|
return redirect(route('home'));
|
|
|
|
}
|
2016-02-23 20:22:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $array
|
|
|
|
* @param string $needle
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-05-22 15:48:34 +02:00
|
|
|
private
|
|
|
|
function startsWithAny(
|
|
|
|
array $array, string $needle
|
|
|
|
): bool
|
2016-02-23 20:22:53 +01:00
|
|
|
{
|
|
|
|
foreach ($array as $entry) {
|
|
|
|
if ((substr($needle, 0, strlen($entry)) === $entry)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-16 06:48:38 +02:00
|
|
|
|
2015-02-06 04:39:52 +01:00
|
|
|
}
|