Various code cleanup and refactoring. Restored cache.

This commit is contained in:
James Cole
2016-10-09 10:53:37 +02:00
parent a4d2ed74fc
commit 39ea9e85a7
3 changed files with 25 additions and 7 deletions

View File

@@ -226,10 +226,7 @@ class AccountController extends Controller
// grouped other months thing:
// oldest transaction in account:
$start = $repository->firstUseDate($account);
if ($start->year == 1900) {
$start = new Carbon;
}
$start = $repository->firstUseDate($account);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($start, $range);
$end = Navigation::endOfX(new Carbon, $range);
@@ -244,8 +241,9 @@ class AccountController extends Controller
if ($cache->has()) {
// $entries = $cache->get();
// return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
$entries = $cache->get();
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
}
// only include asset accounts when this account is an asset:

View File

@@ -16,6 +16,7 @@ namespace FireflyIII\Repositories\Account;
use Carbon\Carbon;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Transaction;
@@ -85,13 +86,15 @@ class AccountRepository implements AccountRepositoryInterface
}
/**
* Returns the date of the first time the Account has been used, or today if it has never been used.
*
* @param Account $account
*
* @return Carbon
*/
public function firstUseDate(Account $account): Carbon
{
$first = new Carbon('1900-01-01');
$first = new Carbon;
/** @var Transaction $first */
$date = $account->transactions()
@@ -108,13 +111,22 @@ class AccountRepository implements AccountRepositoryInterface
}
/**
* Returns the transaction from a journal that is related to a given account. Since a journal generally only contains
* two transactions, this will return one of the two. This method fails horribly when the journal has more than two transactions,
* but luckily it isn't used for such folly.
*
* @param TransactionJournal $journal
* @param Account $account
*
* @return Transaction
* @throws FireflyException
*/
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction
{
$count = $journal->transactions()->count();
if ($count > 2) {
throw new FireflyException(sprintf('Cannot use getFirstTransaction on journal #%d', $journal->id));
}
$transaction = $journal->transactions()->where('account_id', $account->id)->first();
if (is_null($transaction)) {
$transaction = new Transaction;

View File

@@ -14,6 +14,7 @@ declare(strict_types = 1);
namespace FireflyIII\Repositories\Account;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
@@ -47,6 +48,8 @@ interface AccountRepositoryInterface
public function destroy(Account $account, Account $moveTo): bool;
/**
* Returns the date of the first time the Account has been used, or today if it has never been used.
*
* @param Account $account
*
* @return Carbon
@@ -54,10 +57,15 @@ interface AccountRepositoryInterface
public function firstUseDate(Account $account): Carbon;
/**
* Returns the transaction from a journal that is related to a given account. Since a journal generally only contains
* two transactions, this will return one of the two. This method fails horribly when the journal has more than two transactions,
* but luckily it isn't used for such folly.
*
* @param TransactionJournal $journal
* @param Account $account
*
* @return Transaction
* @throws FireflyException
*/
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction;