This commit is contained in:
James Cole 2018-04-15 08:52:58 +02:00
parent 11e93eac3d
commit 0c2c5d5344
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 107 additions and 33 deletions

View File

@ -24,6 +24,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Http\Requests\NewUserFormRequest;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Preferences;
@ -35,6 +36,9 @@ use View;
*/
class NewUserController extends Controller
{
/** @var AccountRepositoryInterface */
private $repository;
/**
* NewUserController constructor.
*/
@ -44,55 +48,70 @@ class NewUserController extends Controller
$this->middleware(
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
return $next($request);
}
);
}
/**
* @param AccountRepositoryInterface $repository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*/
public function index(AccountRepositoryInterface $repository)
public function index()
{
app('view')->share('title', trans('firefly.welcome'));
app('view')->share('mainTitleIcon', 'fa-fire');
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $repository->count($types);
$count = $this->repository->count($types);
$languages = [];
if ($count > 0) {
return redirect(route('index'));
}
return view('new-user.index');
return view('new-user.index', compact('languages'));
}
/**
* @param NewUserFormRequest $request
* @param AccountRepositoryInterface $repository
* @param CurrencyRepositoryInterface $currencyRepository
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
public function submit(NewUserFormRequest $request, CurrencyRepositoryInterface $currencyRepository)
{
// create normal asset account:
$this->createAssetAccount($request, $repository);
$language = $request->string('language');
if (!array_key_exists($language, config('firefly.languages'))) {
$language = 'en_US';
// create savings account
$this->createSavingsAccount($request, $repository);
}
// also store currency preference from input:
// set language preference:
Preferences::set('language', $language);
// Store currency preference from input:
$currency = $currencyRepository->findNull((int)$request->input('amount_currency_id_bank_balance'));
if (null !== $currency) {
// store currency preference:
Preferences::set('currencyPreference', $currency->code);
Preferences::mark();
// if is null, set to EUR:
if (null === $currency) {
$currency = $currencyRepository->findByCodeNull('EUR');
}
// create normal asset account:
$this->createAssetAccount($request, $currency);
// create savings account
$this->createSavingsAccount($request, $currency, $language);
// create cash wallet account
$this->createCashWalletAccount($currency, $language);
// store currency preference:
Preferences::set('currencyPreference', $currency->code);
Preferences::mark();
// set default optional fields:
$visibleFields = [
'interest_date' => true,
@ -114,12 +133,12 @@ class NewUserController extends Controller
}
/**
* @param NewUserFormRequest $request
* @param AccountRepositoryInterface $repository
* @param NewUserFormRequest $request
* @param TransactionCurrency $currency
*
* @return bool
*/
private function createAssetAccount(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
private function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool
{
$assetAccount = [
'name' => $request->get('bank_name'),
@ -131,24 +150,51 @@ class NewUserController extends Controller
'accountRole' => 'defaultAsset',
'openingBalance' => $request->input('bank_balance'),
'openingBalanceDate' => new Carbon,
'currency_id' => (int)$request->input('amount_currency_id_bank_balance'),
'currency_id' => $currency->id,
];
$repository->store($assetAccount);
$this->repository->store($assetAccount);
return true;
}
/**
* @param NewUserFormRequest $request
* @param AccountRepositoryInterface $repository
* @param TransactionCurrency $currency
* @param string $language
*
* @return bool
*/
private function createSavingsAccount(NewUserFormRequest $request, AccountRepositoryInterface $repository): bool
private function createCashWalletAccount(TransactionCurrency $currency, string $language): bool
{
$assetAccount = [
'name' => (string)trans('firefly.cash_wallet', [], $language),
'iban' => null,
'accountType' => 'asset',
'virtualBalance' => 0,
'account_type_id' => null,
'active' => true,
'accountRole' => 'cashWalletAsset',
'openingBalance' => null,
'openingBalanceDate' => null,
'currency_id' => $currency->id,
];
$this->repository->store($assetAccount);
return true;
}
/**
* @param NewUserFormRequest $request
* @param TransactionCurrency $currency
* @param string $language
*
* @return bool
*/
private function createSavingsAccount(NewUserFormRequest $request, TransactionCurrency $currency, string $language): bool
{
$savingsAccount = [
'name' => $request->get('bank_name') . ' savings account',
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
'iban' => null,
'accountType' => 'asset',
'account_type_id' => null,
@ -157,9 +203,9 @@ class NewUserController extends Controller
'accountRole' => 'savingAsset',
'openingBalance' => $request->input('savings_balance'),
'openingBalanceDate' => new Carbon,
'currency_id' => (int)$request->input('amount_currency_id_bank_balance'),
'currency_id' => $currency->id,
];
$repository->store($savingsAccount);
$this->repository->store($savingsAccount);
return true;
}

View File

@ -165,7 +165,7 @@ return [
'default_export_format' => 'csv',
'default_import_format' => 'csv',
'bill_periods' => ['weekly', 'monthly', 'quarterly', 'half-year', 'yearly'],
'accountRoles' => ['defaultAsset', 'sharedAsset', 'savingAsset', 'ccAsset',],
'accountRoles' => ['defaultAsset', 'sharedAsset', 'savingAsset', 'ccAsset','cashWalletAsset'],
'ccTypes' => [
'monthlyFull' => 'Full payment every month',
],

View File

@ -267,7 +267,10 @@ return [
'move_rule_group_down' => 'Move rule group down',
'save_rules_by_moving' => 'Save these rule(s) by moving them to another rule group:',
'make_new_rule' => 'Make new rule in rule group ":title"',
'rule_is_strict' => 'strict rule',
'rule_is_not_strict' => 'non-strict rule',
'rule_help_stop_processing' => 'When you check this box, later rules in this group will not be executed.',
'rule_help_strict' => 'In strict rules ALL triggers must fire for the action(s) to be executed. In non-strict rules, ANY trigger is enough for the action(s) to be executed.',
'rule_help_active' => 'Inactive rules will never fire.',
'stored_new_rule' => 'Stored new rule with title ":title"',
'deleted_rule' => 'Deleted rule with title ":title"',
@ -636,8 +639,8 @@ return [
'over_budget_warn' => '<i class="fa fa-money"></i> Normally you budget about :amount per day. This is :over_amount per day.',
// bills:
'matching_on' => 'Matching on',
'between_amounts' => 'between :low and :high.',
'match_between_amounts' => 'Bill matches transactions between :low and :high.',
'bill_related_rules' => 'Rules related to this bill',
'repeats' => 'Repeats',
'connected_journals' => 'Connected transactions',
'auto_match_on' => 'Automatically matched by Firefly III',
@ -647,13 +650,13 @@ return [
'deleted_bill' => 'Deleted bill ":name"',
'edit_bill' => 'Edit bill ":name"',
'more' => 'More',
'rescan_old' => 'Rescan old transactions',
'rescan_old' => 'Run rules again, on all transactions',
'update_bill' => 'Update bill',
'updated_bill' => 'Updated bill ":name"',
'store_new_bill' => 'Store new bill',
'stored_new_bill' => 'Stored new bill ":name"',
'cannot_scan_inactive_bill' => 'Inactive bills cannot be scanned.',
'rescanned_bill' => 'Rescanned everything.',
'rescanned_bill' => 'Rescanned everything, and linked :total transaction(s) to the bill.',
'average_bill_amount_year' => 'Average bill amount (:year)',
'average_bill_amount_overall' => 'Average bill amount (overall)',
'bill_is_active' => 'Bill is active',
@ -807,6 +810,10 @@ return [
'savings_balance_text' => 'Firefly III will automatically create a savings account for you. By default, there will be no money in your savings account, but if you tell Firefly III the balance it will be stored as such.',
'finish_up_new_user' => 'That\'s it! You can continue by pressing <strong>Submit</strong>. You will be taken to the index of Firefly III.',
'stored_new_accounts_new_user' => 'Yay! Your new accounts have been stored.',
'set_preferred_language' => 'If you prefer to use Firefly III in another language, please indicate so here.',
'language' => 'Language',
'new_savings_account' => ':bank_name savings account',
'cash_wallet' => 'Cash wallet',
// home page:
'yourAccounts' => 'Your accounts',
@ -955,6 +962,7 @@ return [
'account_role_sharedAsset' => 'Shared asset account',
'account_role_savingAsset' => 'Savings account',
'account_role_ccAsset' => 'Credit card',
'account_role_cashWalletAsset' => 'Cash wallet',
'budget_chart_click' => 'Please click on a budget name in the table above to see a chart.',
'category_chart_click' => 'Please click on a category name in the table above to see a chart.',
'in_out_accounts' => 'Earned and spent per combination',

View File

@ -34,11 +34,12 @@ return [
'amount_min' => 'Minimum amount',
'amount_max' => 'Maximum amount',
'match' => 'Matches on',
'strict' => 'Strict mode',
'repeat_freq' => 'Repeats',
'journal_currency_id' => 'Currency',
'currency_id' => 'Currency',
'transaction_currency_id' => 'Currency',
'external_ip' => 'Your server\'s external IP',
'external_ip' => 'Your server\'s external IP',
'attachments' => 'Attachments',
'journal_amount' => 'Amount',
'journal_source_account_name' => 'Revenue account (source)',

View File

@ -92,6 +92,7 @@ return [
'piggy-banks_show_piggyEvents' => 'Any additions or removals are also listed here.',
// bill index
'bills_index_rules' => 'Here you see which rules will check if this bill is hit',
'bills_index_paid_in_period' => 'This field indicates when the bill was last paid.',
'bills_index_expected_in_period' => 'This field indicates for each bill if and when the next bill is expected to hit.',

View File

@ -33,6 +33,24 @@
{{ ExpandedForm.number('savings_balance',0) }}
<p>
{{ 'set_preferred_language'|_ }}
</p>
<div id="language_holder" class="form-group">
<label for="language_holder_select" class="col-sm-4 control-label">{{ 'language'|_ }}</label>
<div class="col-sm-8">
<select class="form-control" id="lang_holder" name="language">
{% for key, lang in Config.get('firefly.languages') %}
<option {% if language == key %}
selected
{% endif %} value="{{ key }}">{{ lang.name_locale }} ({{ lang.name_english }})</option>
{% endfor %}
</select>
</div>
</div>
<p>
{{ 'finish_up_new_user'|_ }}
</p>