mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Debug the account-create controller.
This commit is contained in:
parent
74a3d155b0
commit
abf70a235a
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -135,7 +135,7 @@ class IntroController
|
||||
Log::debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
app('preferences')->set($key, true);
|
||||
|
||||
return response()->json(['result' => sprintf('Reported demo watched for route "%s".', $route)]);
|
||||
return response()->json(['result' => sprintf('Reported demo watched for route "%s" (%s): %s.', $route, $specialPage, $key)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class AccountFormRequest extends Request
|
||||
$data = [
|
||||
'name' => $this->string('name'),
|
||||
'active' => $this->boolean('active'),
|
||||
'account_type' => $this->string('what'),
|
||||
'account_type' => $this->string('objectType'),
|
||||
'account_type_id' => 0,
|
||||
'currency_id' => $this->integer('currency_id'),
|
||||
'virtual_balance' => $this->string('virtual_balance'),
|
||||
|
@ -168,17 +168,17 @@ trait RequestInformation
|
||||
$specificPage = $this->getSpecificPageName();
|
||||
|
||||
// indicator if user has seen the help for this page ( + special page):
|
||||
$key = 'shown_demo_' . $page . $specificPage;
|
||||
$key = sprintf('shown_demo_%s%s', $page, $specificPage);
|
||||
// is there an intro for this route?
|
||||
$intro = config('intro.' . $page) ?? [];
|
||||
$specialIntro = config('intro.' . $page . $specificPage) ?? [];
|
||||
$intro = config(sprintf('intro.%s', $page)) ?? [];
|
||||
$specialIntro = config(sprintf('intro.%s%s', $page, $specificPage)) ?? [];
|
||||
// some routes have a "what" parameter, which indicates a special page:
|
||||
|
||||
$shownDemo = true;
|
||||
// both must be array and either must be > 0
|
||||
if (count($intro) > 0 || count($specialIntro) > 0) {
|
||||
$shownDemo = app('preferences')->get($key, false)->data;
|
||||
Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %d', $key, $shownDemo));
|
||||
Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %s', $key, var_export($shownDemo, true)));
|
||||
}
|
||||
if (!is_bool($shownDemo)) {
|
||||
$shownDemo = true;
|
||||
|
@ -41,9 +41,9 @@ return [
|
||||
],
|
||||
// extra text for asset account creation.
|
||||
'accounts_create_asset' => [
|
||||
'opening_balance' => ['element' => '#ffInput_openingBalance'],
|
||||
'opening_balance' => ['element' => '#ffInput_opening_balance'],
|
||||
'currency' => ['element' => '#ffInput_currency_id'],
|
||||
'virtual' => ['element' => '#ffInput_virtualBalance'],
|
||||
'virtual' => ['element' => '#ffInput_virtual_balance'],
|
||||
],
|
||||
|
||||
// budgets: index
|
||||
|
@ -952,7 +952,7 @@ return [
|
||||
'errors' => 'Errors',
|
||||
'debt_start_date' => 'Start date of debt',
|
||||
'debt_start_amount' => 'Start amount of debt',
|
||||
'debt_start_amount_help' => 'Please enter the original amount of this liability as a positive number. You may also enter the current amount. Make sure to edit the date below to match.',
|
||||
'debt_start_amount_help' => 'If you owe an amount its best to enter a negative amount, because it influences your net worth. If you\'re owed an amount the same applies. Check out the help pages for more information.',
|
||||
'store_new_liabilities_account' => 'Store new liability',
|
||||
'edit_liabilities_account' => 'Edit liability ":name"',
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
{% extends "./layout/default" %}
|
||||
{% block breadcrumbs %}
|
||||
{{ Breadcrumbs.render(Route.getCurrentRoute.getName, what) }}
|
||||
{{ Breadcrumbs.render(Route.getCurrentRoute.getName, objectType) }}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<form action="{{ route('accounts.store') }}" method="post" id="store" class="form-horizontal">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
|
||||
<input type="hidden" name="what" value="{{ what }}"/>
|
||||
<input type="hidden" name="objectType" value="{{ objectType }}"/>
|
||||
<input type="hidden" name="active" value="1"/>
|
||||
|
||||
<div class="row">
|
||||
@ -17,10 +17,10 @@
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.text('name') }}
|
||||
{% if what == 'asset' or what == 'liabilities' %}
|
||||
{% if objectType == 'asset' or objectType == 'liabilities' %}
|
||||
{{ ExpandedForm.currencyList('currency_id', null, {helpText:'account_default_currency'|_}) }}
|
||||
{% endif %}
|
||||
{% if what == 'liabilities' %}
|
||||
{% if objectType == 'liabilities' %}
|
||||
{{ ExpandedForm.select('liability_type_id', liabilityTypes) }}
|
||||
{{ ExpandedForm.amountNoCurrency('opening_balance', null, {label:'debt_start_amount'|_, helpText: 'debt_start_amount_help'|_}) }}
|
||||
{{ ExpandedForm.date('opening_balance_date', null, {label:'debt_start_date'|_}) }}
|
||||
@ -43,7 +43,7 @@
|
||||
{{ ExpandedForm.text('BIC', null, {maxlength: 11}) }}
|
||||
{{ ExpandedForm.text('account_number') }}
|
||||
|
||||
{% if what == 'asset' %}
|
||||
{% if objectType == 'asset' %}
|
||||
|
||||
{{ ExpandedForm.amountNoCurrency('opening_balance') }}
|
||||
{{ ExpandedForm.date('opening_balance_date') }}
|
||||
@ -67,7 +67,7 @@
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn pull-right btn-success">
|
||||
{{ ('store_new_' ~ what ~ '_account')|_ }}
|
||||
{{ ('store_new_' ~ objectType ~ '_account')|_ }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
{% if what == 'liabilities' %}
|
||||
{{ ExpandedForm.select('liability_type_id', liabilityTypes) }}
|
||||
{{ ExpandedForm.amountNoCurrency('openingBalance', null, {label:'debt_start_amount'|_, helpText: 'debt_start_amount_help'|_}) }}
|
||||
{{ ExpandedForm.date('openingBalanceDate', null, {label:'debt_start_date'|_}) }}
|
||||
{{ ExpandedForm.amountNoCurrency('opening_balance', null, {label:'debt_start_amount'|_, helpText: 'debt_start_amount_help'|_}) }}
|
||||
{{ ExpandedForm.date('opening_balance_date', null, {label:'debt_start_date'|_}) }}
|
||||
{{ ExpandedForm.percentage('interest') }}
|
||||
{{ ExpandedForm.select('interest_period', interestPeriods) }}
|
||||
{% endif %}
|
||||
@ -41,19 +41,19 @@
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.text('iban') }}
|
||||
{{ ExpandedForm.text('BIC', null, {maxlength: 11}) }}
|
||||
{% if preFilled.accountRole == 'ccAsset' %}
|
||||
{{ ExpandedForm.text('accountNumber', null , {label:trans('form.creditCardNumber')}) }}
|
||||
{% if preFilled.account_role == 'ccAsset' %}
|
||||
{{ ExpandedForm.text('account_number', null , {label:trans('form.creditCardNumber')}) }}
|
||||
{% else %}
|
||||
{{ ExpandedForm.text('accountNumber') }}
|
||||
{{ ExpandedForm.text('account_number') }}
|
||||
{% endif %}
|
||||
|
||||
{% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %}
|
||||
|
||||
{# get opening balance entry for this thing! #}
|
||||
{{ ExpandedForm.amountNoCurrency('openingBalance',null) }}
|
||||
{{ ExpandedForm.date('openingBalanceDate') }}
|
||||
{{ ExpandedForm.select('accountRole', roles) }}
|
||||
{{ ExpandedForm.amountNoCurrency('virtualBalance',null) }}
|
||||
{{ ExpandedForm.amountNoCurrency('opening_balance',null) }}
|
||||
{{ ExpandedForm.date('opening_balance_date') }}
|
||||
{{ ExpandedForm.select('account_role', roles) }}
|
||||
{{ ExpandedForm.amountNoCurrency('virtual_balance',null) }}
|
||||
|
||||
{% endif %}
|
||||
|
||||
@ -68,14 +68,14 @@
|
||||
</div>
|
||||
|
||||
{# panel for credit card options #}
|
||||
{% if preFilled.accountRole == 'ccAsset' %}
|
||||
{% if preFilled.account_role == 'ccAsset' %}
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'credit_card_options'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.select('ccType',Config.get('firefly.ccTypes')) }}
|
||||
{{ ExpandedForm.date('ccMonthlyPaymentDate',null,{'helpText' : 'Select any year and any month, it will be ignored anway. Only the day of the month is relevant.'}) }}
|
||||
{{ ExpandedForm.select('cc_type',Config.get('firefly.ccTypes')) }}
|
||||
{{ ExpandedForm.date('cc_monthly_payment_date',null,{'helpText' : 'Select any year and any month, it will be ignored anway. Only the day of the month is relevant.'}) }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
@ -112,10 +112,10 @@ Route::group(
|
||||
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'accounts', 'as' => 'accounts.'], function () {
|
||||
|
||||
// show:
|
||||
Route::get('{what}', ['uses' => 'Account\IndexController@index', 'as' => 'index'])->where('what', 'revenue|asset|expense|liabilities');
|
||||
Route::get('{objectType}', ['uses' => 'Account\IndexController@index', 'as' => 'index'])->where('objectType', 'revenue|asset|expense|liabilities');
|
||||
|
||||
// create
|
||||
Route::get('create/{what}', ['uses' => 'Account\CreateController@create', 'as' => 'create'])->where('what', 'revenue|asset|expense|liabilities');
|
||||
Route::get('create/{objectType}', ['uses' => 'Account\CreateController@create', 'as' => 'create'])->where('objectType', 'revenue|asset|expense|liabilities');
|
||||
Route::post('store', ['uses' => 'Account\CreateController@store', 'as' => 'store']);
|
||||
|
||||
|
||||
@ -564,7 +564,7 @@ Route::group(
|
||||
Route::get('rate/{fromCurrencyCode}/{toCurrencyCode}/{date}', ['uses' => 'Json\ExchangeController@getRate', 'as' => 'rate']);
|
||||
|
||||
// intro things:
|
||||
Route::post('intro/finished/{route}/{specificPage?}', ['uses' => 'Json\IntroController@postFinished', 'as' => 'intro.finished']);
|
||||
Route::any('intro/finished/{route}/{specificPage?}', ['uses' => 'Json\IntroController@postFinished', 'as' => 'intro.finished']);
|
||||
Route::post('intro/enable/{route}/{specificPage?}', ['uses' => 'Json\IntroController@postEnable', 'as' => 'intro.enable']);
|
||||
Route::get('intro/{route}/{specificPage?}', ['uses' => 'Json\IntroController@getIntroSteps', 'as' => 'intro']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user