mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-26 02:40:43 -06:00
First code for #658
This commit is contained in:
parent
e62b979708
commit
19774f32c2
@ -21,6 +21,7 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\JournalFormRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@ -93,6 +94,7 @@ class SingleController extends Controller
|
||||
$category = $journal->categories()->first();
|
||||
$categoryName = is_null($category) ? '' : $category->name;
|
||||
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->first();
|
||||
$amount = Steam::positive($transaction->amount);
|
||||
$foreignAmount = is_null($transaction->foreign_amount) ? null : Steam::positive($transaction->foreign_amount);
|
||||
@ -107,6 +109,7 @@ class SingleController extends Controller
|
||||
'source_amount' => $amount,
|
||||
'destination_amount' => $foreignAmount,
|
||||
'foreign_amount' => $foreignAmount,
|
||||
'amount_currency_id_amount' => $transaction->foreign_currency_id ?? 0,
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'budget_id' => $budgetId,
|
||||
'category' => $categoryName,
|
||||
|
@ -565,6 +565,19 @@ class ExpandedForm
|
||||
unset($options['currency']);
|
||||
unset($options['placeholder']);
|
||||
|
||||
// perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
|
||||
$preFilled = session('preFilled');
|
||||
$key = 'amount_currency_id_' . $name;
|
||||
$sentCurrencyId = isset($preFilled[$key]) ? intval($preFilled[$key]) : $defaultCurrency->id;
|
||||
|
||||
// find this currency in set of currencies:
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency->id === $sentCurrencyId) {
|
||||
$defaultCurrency = $currency;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure value is formatted nicely:
|
||||
if (!is_null($value) && $value !== '') {
|
||||
$value = round($value, $defaultCurrency->decimal_places);
|
||||
|
@ -23,7 +23,6 @@ $(document).ready(function () {
|
||||
updateForm();
|
||||
updateLayout();
|
||||
updateDescription();
|
||||
updateNativeCurrency();
|
||||
|
||||
|
||||
// when user changes source account or destination, native currency may be different.
|
||||
@ -60,9 +59,15 @@ function getExchangeInstructions() {
|
||||
* There is an input that shows the currency symbol that is native to the selected
|
||||
* acccount. So when the user changes the selected account, the native currency is updated:
|
||||
*/
|
||||
function updateNativeCurrency() {
|
||||
function updateNativeCurrency(useAccountCurrency) {
|
||||
var nativeCurrencyId;
|
||||
if (useAccountCurrency) {
|
||||
var newAccountId = getAccountId();
|
||||
var nativeCurrencyId = accountInfo[newAccountId].preferredCurrency;
|
||||
nativeCurrencyId = accountInfo[newAccountId].preferredCurrency;
|
||||
}
|
||||
if (!useAccountCurrency) {
|
||||
nativeCurrencyId = overruleCurrency;
|
||||
}
|
||||
|
||||
$('.currency-option[data-id="' + nativeCurrencyId + '"]').click();
|
||||
$('[data-toggle="dropdown"]').parent().removeClass('open');
|
||||
@ -180,7 +185,9 @@ function updateForm() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
updateNativeCurrency();
|
||||
// get instructions all the time.
|
||||
updateNativeCurrency(useAccountCurrency);
|
||||
selectsForeignCurrency();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,7 @@
|
||||
<button type="button"
|
||||
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown"
|
||||
aria-expanded="false">
|
||||
<span id="currency_select_symbol_{{ name }}">{{ defaultCurrency.symbol|raw }}</span> <span class="caret"></span>
|
||||
<span id="currency_select_symbol_{{ name }}">{{ defaultCurrency.symbol|raw }}X</span> <span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu currency-dropdown-menu" role="menu">
|
||||
{% for currency in currencies %}
|
||||
|
@ -231,6 +231,10 @@
|
||||
button['{{ type }}'] = '{{ trans('form.store_new_' ~ type) }}';
|
||||
{% endfor %}
|
||||
|
||||
// some code for the foreign amount logic:
|
||||
var useAccountCurrency = {% if preFilled.amount_currency_id_amount > 0 %}false{% else %}true{% endif %};
|
||||
var overruleCurrency = {{ preFilled.amount_currency_id_amount|default(0) }};
|
||||
|
||||
</script>
|
||||
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script>
|
||||
<script type="text/javascript" src="js/lib/bootstrap-tagsinput.min.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user