2014-06-28 09:41:44 +02:00
|
|
|
<?php
|
2014-06-30 07:26:38 +02:00
|
|
|
|
2014-07-15 22:16:29 +02:00
|
|
|
/**
|
|
|
|
* Class HomeController
|
2014-09-09 20:00:04 +02:00
|
|
|
*
|
2014-07-15 22:16:29 +02:00
|
|
|
*/
|
2014-07-06 15:18:11 +02:00
|
|
|
class HomeController extends BaseController
|
|
|
|
{
|
2014-11-25 20:44:46 +01:00
|
|
|
public function cleanup()
|
|
|
|
{
|
|
|
|
Auth::loginUsingId(1);
|
|
|
|
/** @var \FireflyIII\Database\TransactionJournal $repository */
|
|
|
|
$repository = App::make('FireflyIII\Database\TransactionJournal');
|
|
|
|
|
|
|
|
/** @var \FireflyIII\Database\Account $acct */
|
|
|
|
$acct = App::make('FireflyIII\Database\Account');
|
|
|
|
|
|
|
|
|
|
|
|
$journals = $repository->get();
|
|
|
|
|
|
|
|
/** @var TransactionJournal $journal */
|
|
|
|
foreach ($journals as $journal) {
|
|
|
|
|
|
|
|
if ($journal->TransactionType->type == 'Withdrawal') {
|
|
|
|
echo '#' . $journal->id . ': ' . e($journal->description);
|
|
|
|
/** @var Transaction $transaction */
|
|
|
|
foreach ($journal->transactions as $transaction) {
|
|
|
|
if (floatval($transaction->amount) > 0) {
|
|
|
|
// this is the one with the beneficiary account!
|
|
|
|
if ($transaction->account->accountType->type == 'Beneficiary account') {
|
|
|
|
echo ', <span style="color:red;">should be an expense account</span>';
|
|
|
|
if (Input::get('update') == 'true') {
|
|
|
|
$newAccount = $acct->firstExpenseAccountOrCreate($transaction->account->name);
|
|
|
|
$transaction->account_id = $newAccount->id;
|
|
|
|
$transaction->save();
|
|
|
|
|
|
|
|
echo '<span style="color:darkgreen">, updated!</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '<br />';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
|
2014-08-09 08:18:07 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function flush()
|
|
|
|
{
|
|
|
|
Cache::flush();
|
|
|
|
|
|
|
|
return Redirect::route('index');
|
|
|
|
}
|
|
|
|
|
2014-07-15 22:16:29 +02:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-06 15:18:11 +02:00
|
|
|
public function index()
|
|
|
|
{
|
2014-09-09 20:00:04 +02:00
|
|
|
// count, maybe Firefly needs some introducing text to show:
|
2014-11-11 18:16:59 +01:00
|
|
|
/** @var \FireflyIII\Database\Account $acct */
|
|
|
|
$acct = App::make('FireflyIII\Database\Account');
|
|
|
|
|
|
|
|
/** @var \FireflyIII\Database\TransactionJournal $jrnls */
|
|
|
|
$jrnls = App::make('FireflyIII\Database\TransactionJournal');
|
|
|
|
|
2014-11-12 14:38:32 +01:00
|
|
|
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
|
|
|
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
|
|
|
|
2014-11-11 18:16:59 +01:00
|
|
|
$count = $acct->countAssetAccounts();
|
|
|
|
|
2014-08-09 08:18:07 +02:00
|
|
|
$start = Session::get('start');
|
2014-09-09 20:00:04 +02:00
|
|
|
$end = Session::get('end');
|
2014-07-05 19:44:26 +02:00
|
|
|
|
2014-07-20 18:24:27 +02:00
|
|
|
|
|
|
|
// get the preference for the home accounts to show:
|
2014-11-12 14:38:32 +01:00
|
|
|
$frontpage = $preferences->get('frontpageAccounts', []);
|
2014-07-23 16:44:20 +02:00
|
|
|
if ($frontpage->data == []) {
|
2014-11-11 18:16:59 +01:00
|
|
|
$accounts = $acct->getAssetAccounts();
|
2014-07-21 07:40:38 +02:00
|
|
|
} else {
|
2014-11-11 18:16:59 +01:00
|
|
|
$accounts = $acct->getByIds($frontpage->data);
|
2014-07-21 07:40:38 +02:00
|
|
|
}
|
|
|
|
|
2014-07-20 18:24:27 +02:00
|
|
|
$transactions = [];
|
2014-07-23 16:44:20 +02:00
|
|
|
foreach ($accounts as $account) {
|
2014-11-11 18:16:59 +01:00
|
|
|
$set = $jrnls->getInDateRangeAccount($account, 10, $start, $end);
|
2014-07-24 22:16:42 +02:00
|
|
|
if (count($set) > 0) {
|
|
|
|
$transactions[] = [$set, $account];
|
|
|
|
}
|
2014-07-20 18:24:27 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 15:18:11 +02:00
|
|
|
// build the home screen:
|
2014-11-12 22:36:02 +01:00
|
|
|
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')->with('subTitle', 'What\'s playing?')
|
|
|
|
->with('mainTitleIcon', 'fa-fire');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $range
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function rangeJump($range)
|
|
|
|
{
|
|
|
|
|
|
|
|
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
|
|
|
|
|
|
|
|
/** @var \FireflyIII\Shared\Preferences\PreferencesInterface $preferences */
|
|
|
|
$preferences = App::make('FireflyIII\Shared\Preferences\PreferencesInterface');
|
|
|
|
|
|
|
|
if (in_array($range, $valid)) {
|
|
|
|
$preferences->set('viewRange', $range);
|
|
|
|
Session::forget('range');
|
|
|
|
}
|
|
|
|
|
|
|
|
return Redirect::back();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function sessionNext()
|
|
|
|
{
|
2014-11-21 11:12:22 +01:00
|
|
|
Navigation::next();
|
2014-11-12 22:36:02 +01:00
|
|
|
|
|
|
|
return Redirect::back();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function sessionPrev()
|
|
|
|
{
|
2014-11-21 11:12:22 +01:00
|
|
|
Navigation::prev();
|
2014-11-12 22:36:02 +01:00
|
|
|
|
|
|
|
return Redirect::back();
|
2014-07-06 15:18:11 +02:00
|
|
|
}
|
2014-07-04 11:39:21 +02:00
|
|
|
}
|