Code to implement #1168 and #1197.

This commit is contained in:
James Cole
2018-03-07 10:18:22 +01:00
parent 6c63583e49
commit a5fd821e0c
16 changed files with 190 additions and 180 deletions

View File

@@ -22,11 +22,9 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use ExpandedForm;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -40,9 +38,6 @@ use View;
*/
class ConvertController extends Controller
{
/** @var AccountRepositoryInterface */
private $accounts;
/** @var JournalRepositoryInterface */
private $repository;
@@ -56,7 +51,6 @@ class ConvertController extends Controller
// some useful repositories:
$this->middleware(
function ($request, $next) {
$this->accounts = app(AccountRepositoryInterface::class);
$this->repository = app(JournalRepositoryInterface::class);
app('view')->share('title', trans('firefly.transactions'));
@@ -81,7 +75,6 @@ class ConvertController extends Controller
}
// @codeCoverageIgnoreEnd
$positiveAmount = $this->repository->getJournalTotal($journal);
$assetAccounts = ExpandedForm::makeSelectList($this->accounts->getActiveAccountsByType([AccountType::DEFAULT, AccountType::ASSET]));
$sourceType = $journal->transactionType;
$subTitle = trans('firefly.convert_to_' . $destinationType->type, ['description' => $journal->description]);
$subTitleIcon = 'fa-exchange';
@@ -110,7 +103,6 @@ class ConvertController extends Controller
'sourceType',
'destinationType',
'journal',
'assetAccounts',
'positiveAmount',
'sourceAccount',
'destinationAccount',

View File

@@ -29,13 +29,10 @@ use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\JournalFormRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@@ -51,9 +48,6 @@ use View;
*/
class SingleController extends Controller
{
/** @var AccountRepositoryInterface */
private $accounts;
/** @var AttachmentHelperInterface */
private $attachments;
@@ -82,7 +76,6 @@ class SingleController extends Controller
// some useful repositories:
$this->middleware(
function ($request, $next) {
$this->accounts = app(AccountRepositoryInterface::class);
$this->budgets = app(BudgetRepositoryInterface::class);
$this->piggyBanks = app(PiggyBankRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
@@ -163,7 +156,6 @@ class SingleController extends Controller
{
$what = strtolower($what);
$what = $request->old('what') ?? $what;
$assetAccounts = $this->groupedActiveAccountList();
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$piggyBanks = $this->piggyBanks->getPiggyBanksWithAmount();
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
@@ -192,7 +184,7 @@ class SingleController extends Controller
return view(
'transactions.single.create',
compact('assetAccounts', 'subTitleIcon', 'budgets', 'what', 'piggies', 'subTitle', 'optionalFields', 'preFilled')
compact('subTitleIcon', 'budgets', 'what', 'piggies', 'subTitle', 'optionalFields', 'preFilled')
);
}
@@ -268,9 +260,8 @@ class SingleController extends Controller
return redirect(route('transactions.split.edit', [$journal->id]));
}
$what = strtolower($transactionType);
$assetAccounts = $this->groupedAccountList();
$budgetList = ExpandedForm::makeSelectListWithEmpty($this->budgets->getBudgets());
$what = strtolower($transactionType);
$budgetList = ExpandedForm::makeSelectListWithEmpty($this->budgets->getBudgets());
// view related code
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
@@ -330,7 +321,7 @@ class SingleController extends Controller
return view(
'transactions.single.edit',
compact('journal', 'optionalFields', 'assetAccounts', 'what', 'budgetList', 'subTitle')
compact('journal', 'optionalFields', 'what', 'budgetList', 'subTitle')
)->with('data', $preFilled);
}
@@ -440,46 +431,6 @@ class SingleController extends Controller
return redirect($this->getPreviousUri('transactions.edit.uri'));
}
/**
* @return array
*/
private function groupedAccountList(): array
{
$accounts = $this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$return = [];
/** @var Account $account */
foreach ($accounts as $account) {
$type = $account->getMeta('accountRole');
if (0 === strlen($type)) {
$type = 'no_account_type'; // @codeCoverageIgnore
}
$key = strval(trans('firefly.opt_group_' . $type));
$return[$key][$account->id] = $account->name;
}
return $return;
}
/**
* @return array
*/
private function groupedActiveAccountList(): array
{
$accounts = $this->accounts->getActiveAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$return = [];
/** @var Account $account */
foreach ($accounts as $account) {
$type = $account->getMeta('accountRole');
if (0 === strlen($type)) {
$type = 'no_account_type'; // @codeCoverageIgnore
}
$key = strval(trans('firefly.opt_group_' . $type));
$return[$key][$account->id] = $account->name;
}
return $return;
}
/**
* @param TransactionJournal $journal
*

View File

@@ -100,15 +100,13 @@ class SplitController extends Controller
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
$currencies = $this->currencies->get();
$accountList = $this->accounts->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$assetAccounts = ExpandedForm::makeSelectList($accountList);
$optionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$budgets = ExpandedForm::makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$preFilled = $this->arrayFromJournal($request, $journal);
$subTitle = trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
$subTitleIcon = 'fa-pencil';
$accountArray = [];
$accountList = $this->accounts->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
$accountArray = [];
// account array to display currency info:
/** @var Account $account */
foreach ($accountList as $account) {
@@ -159,7 +157,7 @@ class SplitController extends Controller
// @codeCoverageIgnoreEnd
$type = strtolower($this->repository->getTransactionType($journal));
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $data['description']])));
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $journal->description])));
Preferences::mark();
// @codeCoverageIgnoreStart