2014-06-28 02:41:44 -05:00
|
|
|
<?php
|
2014-07-06 08:18:11 -05:00
|
|
|
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
2014-07-23 23:47:28 -05:00
|
|
|
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
|
|
|
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
2014-06-30 00:26:38 -05:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Class HomeController
|
2014-09-09 13:00:04 -05:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
|
2014-07-15 15:16:29 -05:00
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
class HomeController extends BaseController
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
protected $_accounts;
|
|
|
|
protected $_preferences;
|
|
|
|
protected $_journal;
|
|
|
|
|
2014-09-09 13:00:04 -05:00
|
|
|
/**
|
2014-10-12 00:33:45 -05:00
|
|
|
* @param ARI $accounts
|
|
|
|
* @param PHI $preferences
|
2014-09-09 13:00:04 -05:00
|
|
|
* @param TJRI $journal
|
|
|
|
*/
|
2014-10-12 02:29:19 -05:00
|
|
|
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal)
|
2014-07-06 08:18:11 -05:00
|
|
|
{
|
2014-09-09 13:00:04 -05:00
|
|
|
$this->_accounts = $accounts;
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_preferences = $preferences;
|
2014-09-09 13:00:04 -05:00
|
|
|
$this->_journal = $journal;
|
2014-06-30 00:26:38 -05:00
|
|
|
}
|
|
|
|
|
2014-10-12 00:33:45 -05:00
|
|
|
public function jobDev()
|
|
|
|
{
|
|
|
|
$fullName = storage_path() . DIRECTORY_SEPARATOR . 'firefly-export-2014-07-23.json';
|
2014-09-14 14:09:52 -05:00
|
|
|
\Log::notice('Pushed start job.');
|
|
|
|
Queue::push('Firefly\Queue\Import@start', ['file' => $fullName, 'user' => 1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
2014-10-12 00:33:45 -05:00
|
|
|
public function sessionPrev()
|
|
|
|
{
|
2014-09-14 14:09:52 -05:00
|
|
|
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
|
|
|
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
|
|
|
$toolkit->prev();
|
2014-10-09 00:24:47 -05:00
|
|
|
return Redirect::back();
|
|
|
|
//return Redirect::route('index');
|
2014-09-14 14:09:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
2014-10-12 00:33:45 -05:00
|
|
|
public function sessionNext()
|
|
|
|
{
|
2014-09-14 14:09:52 -05:00
|
|
|
/** @var \Firefly\Helper\Toolkit\ToolkitInterface $toolkit */
|
|
|
|
$toolkit = App::make('Firefly\Helper\Toolkit\ToolkitInterface');
|
|
|
|
$toolkit->next();
|
2014-10-09 00:24:47 -05:00
|
|
|
return Redirect::back();
|
|
|
|
//return Redirect::route('index');
|
2014-09-14 14:09:52 -05:00
|
|
|
}
|
|
|
|
|
2014-10-12 00:33:45 -05:00
|
|
|
public function rangeJump($range)
|
|
|
|
{
|
|
|
|
|
2014-10-12 02:29:19 -05:00
|
|
|
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
|
2014-10-12 00:33:45 -05:00
|
|
|
|
2014-10-12 02:29:19 -05:00
|
|
|
if (in_array($range, $valid)) {
|
2014-10-12 00:33:45 -05:00
|
|
|
$this->_preferences->set('viewRange', $range);
|
|
|
|
Session::forget('range');
|
|
|
|
}
|
|
|
|
return Redirect::back();
|
|
|
|
}
|
|
|
|
|
2014-08-09 01:18:07 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function flush()
|
|
|
|
{
|
|
|
|
Cache::flush();
|
|
|
|
|
|
|
|
return Redirect::route('index');
|
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function index()
|
|
|
|
{
|
2014-09-09 13:00:04 -05:00
|
|
|
Event::fire('limits.check');
|
|
|
|
Event::fire('piggybanks.check');
|
|
|
|
Event::fire('recurring.check');
|
2014-08-23 15:32:12 -05:00
|
|
|
|
2014-09-09 13:00:04 -05:00
|
|
|
// count, maybe Firefly needs some introducing text to show:
|
2014-07-15 15:16:29 -05:00
|
|
|
$count = $this->_accounts->count();
|
2014-08-09 01:18:07 -05:00
|
|
|
$start = Session::get('start');
|
2014-09-09 13:00:04 -05:00
|
|
|
$end = Session::get('end');
|
2014-07-05 12:44:26 -05:00
|
|
|
|
2014-07-20 11:24:27 -05:00
|
|
|
|
|
|
|
// get the preference for the home accounts to show:
|
|
|
|
$frontpage = $this->_preferences->get('frontpageAccounts', []);
|
2014-07-23 09:44:20 -05:00
|
|
|
if ($frontpage->data == []) {
|
2014-07-21 00:40:38 -05:00
|
|
|
$accounts = $this->_accounts->getActiveDefault();
|
|
|
|
} else {
|
|
|
|
$accounts = $this->_accounts->getByIds($frontpage->data);
|
|
|
|
}
|
|
|
|
|
2014-07-20 11:24:27 -05:00
|
|
|
$transactions = [];
|
2014-07-23 09:44:20 -05:00
|
|
|
foreach ($accounts as $account) {
|
2014-08-28 00:53:54 -05:00
|
|
|
$set = $this->_journal->getByAccountInDateRange($account, 10, $start, $end);
|
2014-07-24 15:16:42 -05:00
|
|
|
if (count($set) > 0) {
|
|
|
|
$transactions[] = [$set, $account];
|
|
|
|
}
|
2014-07-20 11:24:27 -05:00
|
|
|
}
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
// build the home screen:
|
2014-09-10 07:39:38 -05:00
|
|
|
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')
|
2014-10-12 00:33:45 -05:00
|
|
|
->with('subTitle', 'What\'s playing?')->with('mainTitleIcon', 'fa-fire');
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
2014-07-04 04:39:21 -05:00
|
|
|
}
|