mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-23 04:46:44 +00:00
Various code cleanup and refactoring. Restored cache.
This commit is contained in:
@@ -227,9 +227,6 @@ class AccountController extends Controller
|
|||||||
// grouped other months thing:
|
// grouped other months thing:
|
||||||
// oldest transaction in account:
|
// oldest transaction in account:
|
||||||
$start = $repository->firstUseDate($account);
|
$start = $repository->firstUseDate($account);
|
||||||
if ($start->year == 1900) {
|
|
||||||
$start = new Carbon;
|
|
||||||
}
|
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
$start = Navigation::startOfPeriod($start, $range);
|
$start = Navigation::startOfPeriod($start, $range);
|
||||||
$end = Navigation::endOfX(new Carbon, $range);
|
$end = Navigation::endOfX(new Carbon, $range);
|
||||||
@@ -244,8 +241,9 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// $entries = $cache->get();
|
$entries = $cache->get();
|
||||||
// return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
|
|
||||||
|
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// only include asset accounts when this account is an asset:
|
// only include asset accounts when this account is an asset:
|
||||||
|
@@ -16,6 +16,7 @@ namespace FireflyIII\Repositories\Account;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Models\Transaction;
|
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
|
* @param Account $account
|
||||||
*
|
*
|
||||||
* @return Carbon
|
* @return Carbon
|
||||||
*/
|
*/
|
||||||
public function firstUseDate(Account $account): Carbon
|
public function firstUseDate(Account $account): Carbon
|
||||||
{
|
{
|
||||||
$first = new Carbon('1900-01-01');
|
$first = new Carbon;
|
||||||
|
|
||||||
/** @var Transaction $first */
|
/** @var Transaction $first */
|
||||||
$date = $account->transactions()
|
$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 TransactionJournal $journal
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
* @return Transaction
|
* @return Transaction
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction
|
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();
|
$transaction = $journal->transactions()->where('account_id', $account->id)->first();
|
||||||
if (is_null($transaction)) {
|
if (is_null($transaction)) {
|
||||||
$transaction = new Transaction;
|
$transaction = new Transaction;
|
||||||
|
@@ -14,6 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Repositories\Account;
|
namespace FireflyIII\Repositories\Account;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@@ -47,6 +48,8 @@ interface AccountRepositoryInterface
|
|||||||
public function destroy(Account $account, Account $moveTo): bool;
|
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
|
* @param Account $account
|
||||||
*
|
*
|
||||||
* @return Carbon
|
* @return Carbon
|
||||||
@@ -54,10 +57,15 @@ interface AccountRepositoryInterface
|
|||||||
public function firstUseDate(Account $account): Carbon;
|
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 TransactionJournal $journal
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
* @return Transaction
|
* @return Transaction
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction;
|
public function getFirstTransaction(TransactionJournal $journal, Account $account): Transaction;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user