Debug the account-create controller.

This commit is contained in:
James Cole
2019-06-22 05:51:32 +02:00
parent 74a3d155b0
commit abf70a235a
10 changed files with 96 additions and 74 deletions

View File

@@ -63,32 +63,19 @@ class CreateController extends Controller
/**
* Create a new account.
*
* @param Request $request
* @param string|null $what
* @param Request $request
* @param string|null $objectType
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create(Request $request, string $what = null)
public function create(Request $request, string $objectType = null)
{
$what = $what ?? 'asset';
$objectType = $objectType ?? 'asset';
$defaultCurrency = app('amount')->getDefaultCurrency();
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$subTitle = (string)trans('firefly.make_new_' . $what . '_account');
$roles = [];
foreach (config('firefly.accountRoles') as $role) {
$roles[$role] = (string)trans('firefly.account_role_' . $role);
}
// types of liability:
$debt = $this->repository->getAccountTypeByType(AccountType::DEBT);
$loan = $this->repository->getAccountTypeByType(AccountType::LOAN);
$mortgage = $this->repository->getAccountTypeByType(AccountType::MORTGAGE);
$liabilityTypes = [
$debt->id => (string)trans('firefly.account_type_' . AccountType::DEBT),
$loan->id => (string)trans('firefly.account_type_' . AccountType::LOAN),
$mortgage->id => (string)trans('firefly.account_type_' . AccountType::MORTGAGE),
];
asort($liabilityTypes);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType));
$roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes();
// interest calculation periods:
$interestPeriods = [
@@ -111,12 +98,11 @@ class CreateController extends Controller
$this->rememberPreviousUri('accounts.create.uri');
}
$request->session()->forget('accounts.create.fromStore');
Log::channel('audit')->info('Create new account.');
Log::channel('audit')->info('Creating new account.');
return view('accounts.create', compact('subTitleIcon', 'what', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes'));
return view('accounts.create', compact('subTitleIcon', 'objectType', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes'));
}
/**
* Store the new account.
*
@@ -132,7 +118,7 @@ class CreateController extends Controller
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));
app('preferences')->mark();
Log::channel('audit')->info('Store new account.', $data);
Log::channel('audit')->info('Stored new account.', $data);
// update preferences if necessary:
$frontPage = app('preferences')->get('frontPageAccounts', [])->data;
@@ -148,10 +134,46 @@ class CreateController extends Controller
// set value so create routine will not overwrite URL:
$request->session()->put('accounts.create.fromStore', true);
$redirect = redirect(route('accounts.create', [$request->input('what')]))->withInput();
$redirect = redirect(route('accounts.create', [$request->input('objectType')]))->withInput();
}
return $redirect;
}
/**
* @codeCoverageIgnore
* @return array
*/
protected function getRoles(): array
{
$roles = [];
foreach (config('firefly.accountRoles') as $role) {
$roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role));
}
return $roles;
}
/**
* @codeCoverageIgnore
* @return array
*/
protected function getLiabilityTypes(): array
{
// types of liability:
$debt = $this->repository->getAccountTypeByType(AccountType::DEBT);
$loan = $this->repository->getAccountTypeByType(AccountType::LOAN);
$mortgage = $this->repository->getAccountTypeByType(AccountType::MORTGAGE);
/** @noinspection NullPointerExceptionInspection */
$liabilityTypes = [
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
$loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
$mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
];
asort($liabilityTypes);
return $liabilityTypes;
}
}

View File

@@ -67,8 +67,8 @@ class EditController extends Controller
/**
* Edit account overview.
*
* @param Request $request
* @param Account $account
* @param Request $request
* @param Account $account
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
@@ -126,21 +126,21 @@ class EditController extends Controller
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$preFilled = [
'account_number' => $repository->getMetaValue($account, 'accountNumber'),
'account_role' => $repository->getMetaValue($account, 'accountRole'),
'cc_type' => $repository->getMetaValue($account, 'ccType'),
'cc_monthly_payment_date' => $repository->getMetaValue($account, 'ccMonthlyPaymentDate'),
'BIC' => $repository->getMetaValue($account, 'BIC'),
'opening_balance_date' => $openingBalanceDate,
'liability_type_id' => $account->account_type_id,
'opening_balance' => $openingBalanceAmount,
'virtual_balance' => $account->virtual_balance,
'currency_id' => $currency->id,
'include_net_worth' => $includeNetWorth,
'interest' => $repository->getMetaValue($account, 'interest'),
'interest_period' => $repository->getMetaValue($account, 'interest_period'),
'notes' => $this->repository->getNoteText($account),
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
'account_number' => $repository->getMetaValue($account, 'account_number'),
'account_role' => $repository->getMetaValue($account, 'account_role'),
'cc_type' => $repository->getMetaValue($account, 'cc_type'),
'cc_monthly_payment_date' => $repository->getMetaValue($account, 'cc_monthly_payment_date'),
'BIC' => $repository->getMetaValue($account, 'BIC'),
'opening_balance_date' => $openingBalanceDate,
'liability_type_id' => $account->account_type_id,
'opening_balance' => $openingBalanceAmount,
'virtual_balance' => $account->virtual_balance,
'currency_id' => $currency->id,
'include_net_worth' => $includeNetWorth,
'interest' => $repository->getMetaValue($account, 'interest'),
'interest_period' => $repository->getMetaValue($account, 'interest_period'),
'notes' => $this->repository->getNoteText($account),
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
];
$request->session()->flash('preFilled', $preFilled);
@@ -155,7 +155,7 @@ class EditController extends Controller
* Update the account.
*
* @param AccountFormRequest $request
* @param Account $account
* @param Account $account
*
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/