This allows the user to set the “default” currency for an asset account (#305). It doesn’t do anything other than this yet.

This commit is contained in:
James Cole
2016-11-25 18:00:29 +01:00
parent 0c72e1831f
commit 728fda0116
6 changed files with 32 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use Amount;
use Carbon\Carbon; use Carbon\Carbon;
use ExpandedForm; use ExpandedForm;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@@ -25,6 +26,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Account\AccountTaskerInterface; use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties; use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Input; use Input;
@@ -68,9 +70,18 @@ class AccountController extends Controller
*/ */
public function create(string $what = 'asset') public function create(string $what = 'asset')
{ {
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); /** @var CurrencyRepositoryInterface $repository */
$subTitle = trans('firefly.make_new_' . $what . '_account'); $repository = app(CurrencyRepositoryInterface::class);
Session::flash('preFilled', []); $currencies = ExpandedForm::makeSelectList($repository->get());
$defaultCurrency = Amount::getDefaultCurrency();
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$subTitle = trans('firefly.make_new_' . $what . '_account');
Session::flash(
'preFilled',
[
'currency_id' => $defaultCurrency->id,
]
);
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
if (session('accounts.create.fromStore') !== true) { if (session('accounts.create.fromStore') !== true) {
@@ -80,7 +91,7 @@ class AccountController extends Controller
Session::flash('gaEventCategory', 'accounts'); Session::flash('gaEventCategory', 'accounts');
Session::flash('gaEventAction', 'create-' . $what); Session::flash('gaEventAction', 'create-' . $what);
return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle')); return view('accounts.create', compact('subTitleIcon', 'what', 'subTitle', 'currencies'));
} }
@@ -137,6 +148,9 @@ class AccountController extends Controller
$what = config('firefly.shortNamesByFullName')[$account->accountType->type]; $what = config('firefly.shortNamesByFullName')[$account->accountType->type];
$subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]); $subTitle = trans('firefly.edit_' . $what . '_account', ['name' => $account->name]);
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$currencies = ExpandedForm::makeSelectList($repository->get());
// put previous url in session if not redirect from store (not "return_to_edit"). // put previous url in session if not redirect from store (not "return_to_edit").
if (session('accounts.edit.fromUpdate') !== true) { if (session('accounts.edit.fromUpdate') !== true) {
@@ -160,12 +174,13 @@ class AccountController extends Controller
'openingBalanceDate' => $openingBalanceDate, 'openingBalanceDate' => $openingBalanceDate,
'openingBalance' => $openingBalanceAmount, 'openingBalance' => $openingBalanceAmount,
'virtualBalance' => $account->virtual_balance, 'virtualBalance' => $account->virtual_balance,
'currency_id' => $account->getMeta('currency_id'),
]; ];
Session::flash('preFilled', $preFilled); Session::flash('preFilled', $preFilled);
Session::flash('gaEventCategory', 'accounts'); Session::flash('gaEventCategory', 'accounts');
Session::flash('gaEventAction', 'edit-' . $what); Session::flash('gaEventAction', 'edit-' . $what);
return view('accounts.edit', compact('account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what')); return view('accounts.edit', compact('currencies', 'account', 'subTitle', 'subTitleIcon', 'openingBalance', 'what'));
} }
/** /**

View File

@@ -42,6 +42,7 @@ class AccountFormRequest extends Request
'name' => trim($this->input('name')), 'name' => trim($this->input('name')),
'active' => intval($this->input('active')) === 1, 'active' => intval($this->input('active')) === 1,
'accountType' => $this->input('what'), 'accountType' => $this->input('what'),
'currency_id' => intval($this->input('currency_id')),
'virtualBalance' => round($this->input('virtualBalance'), 2), 'virtualBalance' => round($this->input('virtualBalance'), 2),
'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')), 'virtualBalanceCurrency' => intval($this->input('amount_currency_id_virtualBalance')),
'iban' => trim($this->input('iban')), 'iban' => trim($this->input('iban')),
@@ -80,6 +81,7 @@ class AccountFormRequest extends Request
'iban' => 'iban', 'iban' => 'iban',
'virtualBalance' => 'numeric', 'virtualBalance' => 'numeric',
'openingBalanceDate' => 'date', 'openingBalanceDate' => 'date',
'currency_id' => 'exists:transaction_currencies,id',
'accountNumber' => 'between:1,255|uniqueAccountNumberForUser', 'accountNumber' => 'between:1,255|uniqueAccountNumberForUser',
'accountRole' => 'in:' . $accountRoles, 'accountRole' => 'in:' . $accountRoles,
'active' => 'boolean', 'active' => 'boolean',

View File

@@ -169,7 +169,7 @@ class Account extends Model
{ {
foreach ($this->accountMeta as $meta) { foreach ($this->accountMeta as $meta) {
if ($meta->name == $fieldName) { if ($meta->name == $fieldName) {
return $meta->data; return strval($meta->data);
} }
} }

View File

@@ -41,7 +41,7 @@ class AccountRepository implements AccountRepositoryInterface
/** @var User */ /** @var User */
private $user; private $user;
/** @var array */ /** @var array */
private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber']; private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber','currency_id'];
/** /**
* AttachmentRepository constructor. * AttachmentRepository constructor.

View File

@@ -17,6 +17,10 @@
</div> </div>
<div class="box-body"> <div class="box-body">
{{ ExpandedForm.text('name') }} {{ ExpandedForm.text('name') }}
{% if what == 'asset' %}
{# Not really mandatory but OK #}
{{ ExpandedForm.select('currency_id', currencies) }}
{% endif %}
</div> </div>
</div> </div>
</div> </div>

View File

@@ -17,6 +17,10 @@
</div> </div>
<div class="box-body"> <div class="box-body">
{{ ExpandedForm.text('name') }} {{ ExpandedForm.text('name') }}
{% if account.accounttype.type == 'Default account' or account.accounttype.type == 'Asset account' %}
{# Not really mandatory but OK #}
{{ ExpandedForm.select('currency_id', currencies) }}
{% endif %}
</div> </div>
</div> </div>