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

96 lines
2.8 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-03-02 06:19:13 -06:00
use Input;
2015-02-06 23:49:24 -06:00
use Preferences;
2015-02-06 14:23:14 -06:00
use Redirect;
use Session;
2015-03-10 11:26:31 -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
{
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
}
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-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-03-06 01:20:27 -06:00
2015-02-06 23:49:24 -06:00
if ($frontPage->data == []) {
2015-03-10 11:26:31 -05:00
$accounts = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
2015-02-06 23:49:24 -06:00
} 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)
2015-03-10 11:26:31 -05:00
->before($end)
->after($start)
2015-02-07 06:15:40 -06:00
->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
2015-02-05 21:39:52 -06:00
}