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

130 lines
3.5 KiB
PHP
Raw Normal View History

2015-02-05 21:52:16 -06:00
<?php namespace FireflyIII\Http\Controllers;
2015-02-05 21:39:52 -06:00
2015-07-26 08:51:07 -05:00
use Artisan;
2015-02-06 23:49:24 -06:00
use Carbon\Carbon;
2015-04-07 11:26:14 -05:00
use Config;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
2015-03-02 06:19:13 -06:00
use Input;
2016-01-08 11:29:47 -06:00
use Log;
2015-02-06 23:49:24 -06:00
use Preferences;
2015-04-07 11:26:14 -05:00
use Session;
use Steam;
2015-07-26 08:51:07 -05:00
2015-02-06 14:23:14 -06:00
/**
* Class HomeController
*
* @package FireflyIII\Http\Controllers
*/
2015-02-06 00:23:26 -06:00
class HomeController extends Controller
{
/**
* HomeController constructor.
*/
2016-01-08 11:29:47 -06:00
public function __construct()
{
2016-01-08 12:13:51 -06:00
parent::__construct();
2016-01-08 11:29:47 -06:00
}
2015-02-05 21:39:52 -06:00
2015-03-02 06:19:13 -06:00
public function dateRange()
{
2015-03-02 05:35:14 -06:00
$start = new Carbon(Input::get('start'));
2015-03-02 06:19:13 -06: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 05:35:14 -06:00
2015-03-02 06:19:13 -06:00
Session::put('start', $start);
Session::put('end', $end);
2015-03-02 05:35:14 -06:00
}
2015-04-07 13:54:43 -05:00
/**
* @return \Illuminate\Http\RedirectResponse
*/
2015-04-07 11:26:14 -05:00
public function flush()
{
2015-07-05 07:37:36 -05: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 13:46:37 -05:00
Session::clear();
2015-07-22 15:13:40 -05:00
Artisan::call('cache:clear');
2015-04-07 11:26:14 -05:00
2015-07-06 09:27:21 -05:00
return redirect(route('index'));
2015-03-31 13:46:37 -05:00
}
2015-02-06 00:23:26 -06:00
/**
* @param ARI $repository
*
2015-06-02 10:14:03 -05:00
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
2015-02-06 00:23:26 -06:00
*/
public function index(ARI $repository)
2015-02-06 00:23:26 -06:00
{
2016-01-08 11:29:47 -06:00
Log::debug('You are at index.');
2015-06-02 10:14:03 -05:00
$types = Config::get('firefly.accountTypesByIdentifier.asset');
$count = $repository->countAccounts($types);
2015-07-06 11:04:13 -05:00
bcscale(2);
2015-06-01 11:13:54 -05:00
2015-06-02 10:14:03 -05:00
if ($count == 0) {
2015-07-06 09:27:21 -05:00
return redirect(route('new-user.index'));
2015-06-01 11:13:54 -05:00
}
2015-08-02 00:41:47 -05:00
$title = 'Firefly';
$subTitle = trans('firefly.welcomeBack');
$mainTitleIcon = 'fa-fire';
$transactions = [];
$frontPage = Preferences::get('frontPageAccounts', []);
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
$showTour = Preferences::get('tour', true)->data;
$accounts = $repository->getFrontpageAccounts($frontPage);
$savings = $repository->getSavingsAccounts();
$piggyBankAccounts = $repository->getPiggyBankAccounts();
2015-06-03 11:22:47 -05:00
$savingsTotal = 0;
foreach ($savings as $savingAccount) {
2015-07-06 11:04:13 -05:00
$savingsTotal = bcadd($savingsTotal, Steam::balance($savingAccount, $end));
}
2015-04-07 13:54:43 -05:00
$sum = $repository->sumOfEverything();
2015-06-03 14:58:06 -05:00
2015-03-29 12:44:59 -05:00
if ($sum != 0) {
2015-03-29 11:28:49 -05:00
Session::flash(
'error', 'Your transactions are unbalanced. This means a'
2015-06-06 16:09:12 -05:00
. ' withdrawal, deposit or transfer was not stored properly. '
. 'Please check your accounts and transactions for errors.'
2015-03-29 11:28:49 -05:00
);
}
2015-02-06 23:49:24 -06:00
foreach ($accounts as $account) {
2015-03-13 02:44:07 -05:00
$set = $repository->getFrontpageTransactions($account, $start, $end);
2015-06-03 14:58:06 -05:00
2015-02-06 23:49:24 -06:00
if (count($set) > 0) {
$transactions[] = [$set, $account];
}
}
2015-06-03 14:25:11 -05:00
2015-07-12 05:45:41 -05:00
return view(
'index', compact('count', 'showTour', 'title', 'savings', 'subTitle', 'mainTitleIcon', 'transactions', 'savingsTotal', 'piggyBankAccounts')
);
2015-02-06 00:23:26 -06:00
}
2015-06-29 08:23:50 -05:00
2015-02-05 21:39:52 -06:00
}