Files
firefly-iii/app/Http/Controllers/HomeController.php

156 lines
4.1 KiB
PHP
Raw Normal View History

2015-02-06 04:52:16 +01:00
<?php 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;
2015-04-07 18:26:14 +02:00
use Config;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
2015-03-02 13:19:13 +01:00
use Input;
2015-02-07 06:49:24 +01:00
use Preferences;
use Route;
2015-04-07 18:26:14 +02:00
use Session;
use Steam;
2015-07-26 15:51:07 +02: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
{
/**
* 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
2015-03-02 13:19:13 +01:00
public function dateRange()
{
2015-03-02 12:35:14 +01:00
$start = new Carbon(Input::get('start'));
2015-03-02 13:19:13 +01:00
$end = new Carbon(Input::get('end'));
$diff = $start->diffInDays($end);
if ($diff > 50) {
Session::flash('warning', $diff . ' days of data may take a while to load.');
}
2015-03-02 12:35:14 +01:00
2015-03-02 13:19:13 +01:00
Session::put('start', $start);
Session::put('end', $end);
2015-03-02 12:35:14 +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
/**
* @return \Illuminate\Http\RedirectResponse
*/
2015-04-07 18:26:14 +02:00
public function flush()
{
2015-07-05 14:37:36 +02:00
Preferences::mark();
// get all tags.
// update all counts:
$tags = Tag::get();
/** @var Tag $tag */
foreach ($tags as $tag) {
foreach ($tag->transactionjournals()->get() as $journal) {
$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
/**
* @param ARI $repository
*
2015-06-02 17:14:03 +02:00
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
2015-02-06 07:23:26 +01:00
*/
public function index(ARI $repository)
2015-02-06 07:23:26 +01:00
{
2015-06-02 17:14:03 +02:00
$types = Config::get('firefly.accountTypesByIdentifier.asset');
$count = $repository->countAccounts($types);
2015-07-06 18:04:13 +02:00
bcscale(2);
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
}
$title = 'Firefly';
$subTitle = trans('firefly.welcomeBack');
$mainTitleIcon = 'fa-fire';
$transactions = [];
$frontPage = Preferences::get('frontPageAccounts', []);
2016-02-05 15:41:40 +01:00
/** @var Carbon $start */
$start = session('start', Carbon::now()->startOfMonth());
2016-02-05 15:41:40 +01:00
/** @var Carbon $end */
2016-02-04 07:27:03 +01:00
$end = session('end', Carbon::now()->endOfMonth());
2015-08-02 07:41:47 +02:00
$showTour = Preferences::get('tour', true)->data;
$accounts = $repository->getFrontpageAccounts($frontPage);
$savings = $repository->getSavingsAccounts();
$piggyBankAccounts = $repository->getPiggyBankAccounts();
2015-06-03 18:22:47 +02:00
$savingsTotal = 0;
foreach ($savings as $savingAccount) {
2015-07-06 18:04:13 +02:00
$savingsTotal = bcadd($savingsTotal, Steam::balance($savingAccount, $end));
}
2015-04-07 20:54:43 +02:00
$sum = $repository->sumOfEverything();
2015-06-03 21:58:06 +02:00
2016-02-05 15:41:40 +01:00
if (bccomp($sum, '0') !== 0) {
2015-03-29 18:28:49 +02:00
Session::flash(
'error', 'Your transactions are unbalanced. This means a'
2015-06-06 23:09:12 +02:00
. ' withdrawal, deposit or transfer was not stored properly. '
2016-02-05 15:41:40 +01:00
. 'Please check your accounts and transactions for errors (' . $sum . ').'
2015-03-29 18:28:49 +02:00
);
}
2015-02-07 06:49:24 +01:00
foreach ($accounts as $account) {
2015-03-13 08:44:07 +01:00
$set = $repository->getFrontpageTransactions($account, $start, $end);
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(
'index', compact('count', 'showTour', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')
);
2015-02-06 07:23:26 +01:00
}
2015-06-29 15:23:50 +02: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()
{
$ignore = [];
$routes = Route::getRoutes();
foreach ($routes as $route) {
var_dump($route);
exit;
}
}
2015-02-06 04:39:52 +01:00
}