Skip to content

Commit

Permalink
Fix #948
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Nov 3, 2017
1 parent d30d6b5 commit 5e3729e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
15 changes: 13 additions & 2 deletions app/Http/Controllers/NewUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Carbon\Carbon;
use FireflyIII\Http\Requests\NewUserFormRequest;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Preferences;
use Session;
use View;
Expand Down Expand Up @@ -81,14 +82,24 @@ public function index(AccountRepositoryInterface $repository)
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository)
public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
{
// create normal asset account:
$this->createAssetAccount($request, $repository);

// create savings account
$this->createSavingsAccount($request, $repository);

// also store currency preference from input:
$currency = $currencyRepository->find(intval($request->input('amount_currency_id_bank_balance')));

if(!is_null($currency->id)) {
// store currency preference:
Preferences::set('currencyPreference', $currency->code);
Preferences::mark();
}


Session::flash('success', strval(trans('firefly.stored_new_accounts_new_user')));
Preferences::mark();

Expand Down Expand Up @@ -137,7 +148,7 @@ private function createSavingsAccount(NewUserFormRequest $request, AccountReposi
'accountRole' => 'savingAsset',
'openingBalance' => round($request->input('savings_balance'), 12),
'openingBalanceDate' => new Carbon,
'currency_id' => intval($request->input('amount_currency_id_savings_balance')),
'currency_id' => intval($request->input('amount_currency_id_bank_balance')),
];
$repository->store($savingsAccount);

Expand Down
1 change: 0 additions & 1 deletion app/Repositories/Currency/CurrencyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public function find(int $currencyId): TransactionCurrency
$currency = TransactionCurrency::find($currencyId);
if (is_null($currency)) {
$currency = new TransactionCurrency;

}

return $currency;
Expand Down
22 changes: 21 additions & 1 deletion app/Support/ExpandedForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ public function nonSelectableAmount(string $name, $value = null, array $options
return $html;
}


/**
* @param string $name
* @param null $value
Expand Down Expand Up @@ -331,6 +330,27 @@ public function nonSelectableBalance(string $name, $value = null, array $options
return $html;
}

/**
* @param string $name
* @param null $value
* @param array $options
*
* @return string
*/
public function number(string $name, $value = null, array $options = []): string
{
$label = $this->label($name, $options);
$options = $this->expandOptionArray($name, $label, $options);
$classes = $this->getHolderClasses($name);
$value = $this->fillFieldValue($name, $value);
$options['step'] = 'any';
unset($options['placeholder']);

$html = view('form.number', compact( 'classes', 'name', 'label', 'value', 'options'))->render();

return $html;
}

/**
* @param $type
* @param $name
Expand Down
1 change: 1 addition & 0 deletions config/twigbridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
'is_safe' => [
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password', 'nonSelectableBalance', 'nonSelectableAmount',
'number'
],
],
'Form' => [
Expand Down
8 changes: 8 additions & 0 deletions resources/views/form/number.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="{{ classes }}" id="{{ name }}_holder">
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>

<div class="col-sm-8">
{{ Form.input('number', name, value, options) }}
{% include 'form/feedback' %}
</div>
</div>
2 changes: 1 addition & 1 deletion resources/views/new-user/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{{ 'savings_balance_text'|_ }}
</p>

{{ ExpandedForm.balance('savings_balance',0) }}
{{ ExpandedForm.number('savings_balance',0) }}

<p>
{{ 'finish_up_new_user'|_ }}
Expand Down

0 comments on commit 5e3729e

Please sign in to comment.