mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 02:45:58 +00:00
First code for #658
This commit is contained in:
@@ -21,6 +21,7 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
|||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Http\Requests\JournalFormRequest;
|
use FireflyIII\Http\Requests\JournalFormRequest;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
@@ -86,39 +87,41 @@ class SingleController extends Controller
|
|||||||
|
|
||||||
public function cloneTransaction(TransactionJournal $journal)
|
public function cloneTransaction(TransactionJournal $journal)
|
||||||
{
|
{
|
||||||
$source = $journal->sourceAccountList()->first();
|
$source = $journal->sourceAccountList()->first();
|
||||||
$destination = $journal->destinationAccountList()->first();
|
$destination = $journal->destinationAccountList()->first();
|
||||||
$budget = $journal->budgets()->first();
|
$budget = $journal->budgets()->first();
|
||||||
$budgetId = is_null($budget) ? 0 : $budget->id;
|
$budgetId = is_null($budget) ? 0 : $budget->id;
|
||||||
$category = $journal->categories()->first();
|
$category = $journal->categories()->first();
|
||||||
$categoryName = is_null($category) ? '' : $category->name;
|
$categoryName = is_null($category) ? '' : $category->name;
|
||||||
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
|
$tags = join(',', $journal->tags()->get()->pluck('tag')->toArray());
|
||||||
$transaction = $journal->transactions()->first();
|
/** @var Transaction $transaction */
|
||||||
$amount = Steam::positive($transaction->amount);
|
$transaction = $journal->transactions()->first();
|
||||||
$foreignAmount = is_null($transaction->foreign_amount) ? null : Steam::positive($transaction->foreign_amount);
|
$amount = Steam::positive($transaction->amount);
|
||||||
|
$foreignAmount = is_null($transaction->foreign_amount) ? null : Steam::positive($transaction->foreign_amount);
|
||||||
|
|
||||||
$preFilled = [
|
$preFilled = [
|
||||||
'description' => $journal->description,
|
'description' => $journal->description,
|
||||||
'source_account_id' => $source->id,
|
'source_account_id' => $source->id,
|
||||||
'source_account_name' => $source->name,
|
'source_account_name' => $source->name,
|
||||||
'destination_account_id' => $destination->id,
|
'destination_account_id' => $destination->id,
|
||||||
'destination_account_name' => $destination->name,
|
'destination_account_name' => $destination->name,
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
'source_amount' => $amount,
|
'source_amount' => $amount,
|
||||||
'destination_amount' => $foreignAmount,
|
'destination_amount' => $foreignAmount,
|
||||||
'foreign_amount' => $foreignAmount,
|
'foreign_amount' => $foreignAmount,
|
||||||
'date' => $journal->date->format('Y-m-d'),
|
'amount_currency_id_amount' => $transaction->foreign_currency_id ?? 0,
|
||||||
'budget_id' => $budgetId,
|
'date' => $journal->date->format('Y-m-d'),
|
||||||
'category' => $categoryName,
|
'budget_id' => $budgetId,
|
||||||
'tags' => $tags,
|
'category' => $categoryName,
|
||||||
'interest_date' => $journal->getMeta('interest_date'),
|
'tags' => $tags,
|
||||||
'book_date' => $journal->getMeta('book_date'),
|
'interest_date' => $journal->getMeta('interest_date'),
|
||||||
'process_date' => $journal->getMeta('process_date'),
|
'book_date' => $journal->getMeta('book_date'),
|
||||||
'due_date' => $journal->getMeta('due_date'),
|
'process_date' => $journal->getMeta('process_date'),
|
||||||
'payment_date' => $journal->getMeta('payment_date'),
|
'due_date' => $journal->getMeta('due_date'),
|
||||||
'invoice_date' => $journal->getMeta('invoice_date'),
|
'payment_date' => $journal->getMeta('payment_date'),
|
||||||
'internal_reference' => $journal->getMeta('internal_reference'),
|
'invoice_date' => $journal->getMeta('invoice_date'),
|
||||||
'notes' => $journal->getMeta('notes'),
|
'internal_reference' => $journal->getMeta('internal_reference'),
|
||||||
|
'notes' => $journal->getMeta('notes'),
|
||||||
];
|
];
|
||||||
Session::flash('preFilled', $preFilled);
|
Session::flash('preFilled', $preFilled);
|
||||||
|
|
||||||
|
@@ -565,6 +565,19 @@ class ExpandedForm
|
|||||||
unset($options['currency']);
|
unset($options['currency']);
|
||||||
unset($options['placeholder']);
|
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:
|
// make sure value is formatted nicely:
|
||||||
if (!is_null($value) && $value !== '') {
|
if (!is_null($value) && $value !== '') {
|
||||||
$value = round($value, $defaultCurrency->decimal_places);
|
$value = round($value, $defaultCurrency->decimal_places);
|
||||||
|
@@ -23,7 +23,6 @@ $(document).ready(function () {
|
|||||||
updateForm();
|
updateForm();
|
||||||
updateLayout();
|
updateLayout();
|
||||||
updateDescription();
|
updateDescription();
|
||||||
updateNativeCurrency();
|
|
||||||
|
|
||||||
|
|
||||||
// when user changes source account or destination, native currency may be different.
|
// 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
|
* 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:
|
* acccount. So when the user changes the selected account, the native currency is updated:
|
||||||
*/
|
*/
|
||||||
function updateNativeCurrency() {
|
function updateNativeCurrency(useAccountCurrency) {
|
||||||
var newAccountId = getAccountId();
|
var nativeCurrencyId;
|
||||||
var nativeCurrencyId = accountInfo[newAccountId].preferredCurrency;
|
if (useAccountCurrency) {
|
||||||
|
var newAccountId = getAccountId();
|
||||||
|
nativeCurrencyId = accountInfo[newAccountId].preferredCurrency;
|
||||||
|
}
|
||||||
|
if (!useAccountCurrency) {
|
||||||
|
nativeCurrencyId = overruleCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
$('.currency-option[data-id="' + nativeCurrencyId + '"]').click();
|
$('.currency-option[data-id="' + nativeCurrencyId + '"]').click();
|
||||||
$('[data-toggle="dropdown"]').parent().removeClass('open');
|
$('[data-toggle="dropdown"]').parent().removeClass('open');
|
||||||
@@ -180,7 +185,9 @@ function updateForm() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateNativeCurrency();
|
// get instructions all the time.
|
||||||
|
updateNativeCurrency(useAccountCurrency);
|
||||||
|
selectsForeignCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<button type="button"
|
<button type="button"
|
||||||
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown"
|
class="btn btn-default dropdown-toggle currency-dropdown" id="currency_dropdown_{{ name }}" data-toggle="dropdown"
|
||||||
aria-expanded="false">
|
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>
|
</button>
|
||||||
<ul class="dropdown-menu currency-dropdown-menu" role="menu">
|
<ul class="dropdown-menu currency-dropdown-menu" role="menu">
|
||||||
{% for currency in currencies %}
|
{% for currency in currencies %}
|
||||||
|
@@ -231,6 +231,10 @@
|
|||||||
button['{{ type }}'] = '{{ trans('form.store_new_' ~ type) }}';
|
button['{{ type }}'] = '{{ trans('form.store_new_' ~ type) }}';
|
||||||
{% endfor %}
|
{% 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>
|
||||||
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></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>
|
<script type="text/javascript" src="js/lib/bootstrap-tagsinput.min.js"></script>
|
||||||
|
Reference in New Issue
Block a user