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

125 lines
3.4 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-02-06 23:49:24 -06:00
use Auth;
2015-02-07 06:15:40 -06:00
use Cache;
2015-02-06 23:49:24 -06:00
use Carbon\Carbon;
2015-02-06 14:23:14 -06:00
use Navigation;
2015-02-06 23:49:24 -06:00
use Preferences;
2015-02-06 14:23:14 -06:00
use Redirect;
use Session;
2015-02-06 23:49:24 -06:00
use URL;
2015-02-06 12:33:31 -06: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
{
2015-02-05 21:39:52 -06:00
2015-02-06 00:23:26 -06:00
/**
*
*/
public function __construct()
{
2015-02-07 06:15:40 -06:00
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function flush()
{
Cache::flush();
return Redirect::route('index');
2015-02-06 00:23:26 -06:00
}
2015-02-05 21:39:52 -06:00
2015-02-06 00:23:26 -06:00
/**
2015-02-06 14:23:14 -06:00
* @return \Illuminate\View\View
2015-02-06 00:23:26 -06:00
*/
public function index()
{
2015-02-06 23:49:24 -06:00
$count = Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->count();
2015-02-06 00:23:26 -06:00
$title = 'Firefly';
$subTitle = 'What\'s playing?';
$mainTitleIcon = 'fa-fire';
2015-02-06 23:49:24 -06:00
$transactions = [];
$frontPage = Preferences::get('frontPageAccounts', []);
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
2015-02-06 00:23:26 -06:00
2015-02-06 23:49:24 -06:00
if ($frontPage->data == []) {
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*']);
} else {
$accounts = Auth::user()->accounts()->whereIn('id', $frontPage->data)->get(['accounts.*']);
}
foreach ($accounts as $account) {
$set = Auth::user()
2015-02-07 06:15:40 -06:00
->transactionjournals()
->with(['transactions', 'transactioncurrency', 'transactiontype'])
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')->where('accounts.id', $account->id)
->where('date', '>=', $start->format('Y-m-d'))
->where('date', '<=', $end->format('Y-m-d'))
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.id', 'DESC')
->take(10)
->get(['transaction_journals.*']);
2015-02-06 23:49:24 -06:00
if (count($set) > 0) {
$transactions[] = [$set, $account];
}
}
2015-02-07 06:15:40 -06:00
// var_dump($transactions);
2015-02-06 23:49:24 -06:00
return view('index', compact('count', 'title', 'subTitle', 'mainTitleIcon', 'transactions'));
2015-02-06 00:23:26 -06:00
}
2015-02-05 21:39:52 -06:00
2015-02-06 14:23:14 -06:00
/**
* @param string $range
*
* @return mixed
*/
public function rangeJump($range)
{
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
if (in_array($range, $valid)) {
Preferences::set('viewRange', $range);
Session::forget('range');
}
2015-02-06 23:49:24 -06:00
2015-02-06 14:23:14 -06:00
return Redirect::to(URL::previous());
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function sessionNext()
{
2015-02-06 23:49:24 -06:00
$range = Session::get('range');
$start = Session::get('start');
Session::put('start', Navigation::jumpToNext($range, clone $start));
2015-02-06 14:23:14 -06:00
return Redirect::to(URL::previous());
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function sessionPrev()
{
2015-02-06 23:49:24 -06:00
$range = Session::get('range');
$start = Session::get('start');
Session::put('start', Navigation::jumpToPrevious($range, clone $start));
2015-02-06 14:23:14 -06:00
return Redirect::to(URL::previous());
}
2015-02-05 21:39:52 -06:00
}