Fix account controller + coverage.

This commit is contained in:
James Cole
2017-12-31 10:40:27 +01:00
parent 8bcfa729b6
commit b73884160a
7 changed files with 254 additions and 28 deletions

View File

@@ -157,14 +157,14 @@ class AccountController extends Controller
* @throws FireflyException
* @throws FireflyException
*/
public function edit(Request $request, Account $account)
public function edit(Request $request, Account $account, AccountRepositoryInterface $repository)
{
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$what = config('firefly.shortNamesByFullName')[$account->accountType->type];
$subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]);
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$allCurrencies = $repository->get();
$allCurrencies = $currencyRepos->get();
$currencySelectList = ExpandedForm::makeSelectList($allCurrencies);
$roles = [];
foreach (config('firefly.accountRoles') as $role) {
@@ -184,7 +184,7 @@ class AccountController extends Controller
$openingBalanceAmount = '0' === $account->getOpeningBalanceAmount() ? '' : $openingBalanceAmount;
$openingBalanceDate = $account->getOpeningBalanceDate();
$openingBalanceDate = 1900 === $openingBalanceDate->year ? null : $openingBalanceDate->format('Y-m-d');
$currency = $repository->find(intval($account->getMeta('currency_id')));
$currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
$preFilled = [
'accountNumber' => $account->getMeta('accountNumber'),
@@ -196,10 +196,10 @@ class AccountController extends Controller
'openingBalance' => $openingBalanceAmount,
'virtualBalance' => $account->virtual_balance,
'currency_id' => $currency->id,
'notes' => '',
'notes' => '',
];
/** @var Note $note */
$note = $account->notes()->first();
$note = $repository->getNote($account);
if (null !== $note) {
$preFilled['notes'] = $note->text;
}

View File

@@ -87,6 +87,16 @@ class AccountRepository implements AccountRepositoryInterface
return true;
}
/**
* @param Account $account
*
* @return Note|null
*/
public function getNote(Account $account): ?Note
{
return $account->notes()->first();
}
/**
* Returns the date of the very last transaction in this account.
*

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Repositories\Account;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -33,6 +34,12 @@ use Illuminate\Support\Collection;
*/
interface AccountRepositoryInterface
{
/**
* @param Account $account
*
* @return Note|null
*/
public function getNote(Account $account): ?Note;
/**
* Moved here from account CRUD.
*