Move some stuff around.

This commit is contained in:
James Cole 2016-05-20 09:45:24 +02:00
parent 65b8882ed4
commit 724f423692
14 changed files with 58 additions and 80 deletions

View File

@ -64,23 +64,18 @@ class AccountCrud implements AccountCrudInterface
}
/**
* @param Account $account
* @param $accountId
*
* @return TransactionJournal|null
* @return Account
*/
public function openingBalanceTransaction(Account $account): TransactionJournal
public function find(int $accountId): Account
{
$journal = TransactionJournal
::sortCorrectly()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
return new TransactionJournal;
$account = $this->user->accounts()->find($accountId);
if (is_null($account)) {
$account = new Account;
}
return $journal;
return $account;
}
/**
@ -339,4 +334,24 @@ class AccountCrud implements AccountCrudInterface
}
}
/**
* @param Account $account
*
* @return TransactionJournal|null
*/
private function openingBalanceTransaction(Account $account): TransactionJournal
{
$journal = TransactionJournal
::sortCorrectly()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE])
->first(['transaction_journals.*']);
if (is_null($journal)) {
return new TransactionJournal;
}
return $journal;
}
}

View File

@ -13,7 +13,6 @@ namespace FireflyIII\Crud\Account;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\TransactionJournal;
/**
* Interface AccountCrudInterface
@ -31,12 +30,11 @@ interface AccountCrudInterface
public function destroy(Account $account, Account $moveTo): bool;
/**
* @param int $accountId
*
* @param Account $account
*
* @return TransactionJournal
* @return Account
*/
public function openingBalanceTransaction(Account $account) : TransactionJournal;
public function find(int $accountId): Account;
/**
* @param array $data

View File

@ -3,7 +3,6 @@ declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
/**
* Class AccountId
@ -18,10 +17,10 @@ class AccountId extends BasicConverter implements ConverterInterface
*/
public function convert(): Account
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$var = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
$account = $repository->find($var);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$var = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
$account = $crud->find($var);
return $account;
}

View File

@ -23,17 +23,18 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
$account = $repository->find(intval($this->mapped[$this->index][$this->value]));
$account = $crud->find(intval($this->mapped[$this->index][$this->value]));
return $account;
}
if (strlen($this->value) > 0) {
$account = $this->searchOrCreate($repository);
$account = $this->searchOrCreate($repository, $crud);
return $account;
}

View File

@ -4,7 +4,6 @@ namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use Carbon\Carbon;
use FireflyIII\Crud\Account\AccountCrudInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -23,12 +22,10 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
/** @var AccountCrudInterface $crud */
$crud = app(AccountCrudInterface::class);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
if (isset($this->mapped[$this->index][$this->value])) {
$account = $repository->find(intval($this->mapped[$this->index][$this->value]));
$account = $crud->find(intval($this->mapped[$this->index][$this->value]));
return $account;
}

View File

@ -13,7 +13,6 @@ namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use Carbon\Carbon;
use FireflyIII\Crud\Account\AccountCrudInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -32,13 +31,11 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
/** @var AccountCrudInterface $crud */
$crud = app(AccountCrudInterface::class);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
$account = $repository->find(intval($this->mapped[$this->index][$this->value]));
$account = $crud->find(intval($this->mapped[$this->index][$this->value]));
return $account;
}

View File

@ -22,9 +22,10 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
if (isset($this->mapped[$this->index][$this->value])) {
$account = $repository->find($this->mapped[$this->index][$this->value]);
$account = $crud->find($this->mapped[$this->index][$this->value]);
return $account;
}

View File

@ -3,7 +3,6 @@ declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
/**
* Class OpposingAccountId
@ -19,10 +18,9 @@ class OpposingAccountId extends BasicConverter implements ConverterInterface
*/
public function convert(): Account
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
$account = $repository->find($value);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
$account = $crud->find($value);
return $account;
}

View File

@ -3,7 +3,6 @@ declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv\Converter;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
/**
* Class OpposingAccountName
@ -20,11 +19,10 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
*/
public function convert()
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
if (isset($this->mapped[$this->index][$this->value])) {
$account = $repository->find($this->mapped[$this->index][$this->value]);
$account = $crud->find($this->mapped[$this->index][$this->value]);
return $account;
}

View File

@ -7,7 +7,6 @@ use Carbon\Carbon;
use FireflyIII\Crud\Account\AccountCrudInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Validator;
/**
@ -246,8 +245,6 @@ class AssetAccount implements PostProcessorInterface
}
}
// create new if not exists and return that one:
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$accountData = [
'name' => $accountNumber,
'accountType' => 'asset',

View File

@ -84,18 +84,17 @@ class AccountController extends Controller
}
/**
* @param ARI $repository
* @param AccountCrudInterface $crud
* @param Account $account
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroy(ARI $repository, AccountCrudInterface $crud, Account $account)
public function destroy(AccountCrudInterface $crud, Account $account)
{
$type = $account->accountType->type;
$typeName = config('firefly.shortNamesByFullName.' . $type);
$name = $account->name;
$moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
$moveTo = $crud->find(intval(Input::get('move_account_before_delete')));
$crud->destroy($account, $moveTo);

View File

@ -88,10 +88,8 @@ class ReportController extends Controller
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
$budget = $budgetRepository->find(intval($attributes['budgetId']));
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$account = $accountRepository->find(intval($attributes['accountId']));
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$account = $crud->find(intval($attributes['accountId']));
switch (true) {
case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)):
@ -183,7 +181,8 @@ class ReportController extends Controller
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$account = $repository->find(intval($attributes['accountId']));
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$account = $crud->find(intval($attributes['accountId']));
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
$journals = $repository->journalsInPeriod($attributes['accounts'], $types, $attributes['startDate'], $attributes['endDate']);
@ -213,7 +212,8 @@ class ReportController extends Controller
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$account = $repository->find(intval($attributes['accountId']));
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
$account = $crud->find(intval($attributes['accountId']));
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
$journals = $repository->journalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
$destinations = $attributes['accounts']->pluck('id')->toArray();
@ -221,8 +221,8 @@ class ReportController extends Controller
$journals = $journals->filter(
function (TransactionJournal $journal) use ($account, $destinations) {
if (
$journal->source_account_id === $account->id &&
in_array($journal->destination_account_id, $destinations)
$journal->source_account_id === $account->id
&& in_array($journal->destination_account_id, $destinations)
) {
return $journal;
}

View File

@ -170,21 +170,6 @@ class AccountRepository implements AccountRepositoryInterface
return $journals;
}
/**
* @param $accountId
*
* @return Account
*/
public function find(int $accountId): Account
{
$account = $this->user->accounts()->find($accountId);
if (is_null($account)) {
$account = new Account;
}
return $account;
}
/**
* @param Account $account
*

View File

@ -63,13 +63,6 @@ interface AccountRepositoryInterface
*/
public function expensesInPeriod(Collection $accounts, Carbon $start, Carbon $end): Collection;
/**
* @param int $accountId
*
* @return Account
*/
public function find(int $accountId): Account;
/**
* @param Account $account
*