mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-03 20:20:37 -06:00
Fix for #1364
This commit is contained in:
parent
f16b2257c6
commit
01c10e320c
@ -189,7 +189,8 @@ class SplitController extends Controller
|
||||
$destinationAccounts = $this->repository->getJournalDestinationAccounts($journal);
|
||||
$array = [
|
||||
'journal_description' => $request->old('journal_description', $journal->description),
|
||||
'journal_amount' => $this->repository->getJournalTotal($journal),
|
||||
'journal_amount' => '0',
|
||||
'journal_foreign_amount' => '0',
|
||||
'sourceAccounts' => $sourceAccounts,
|
||||
'journal_source_account_id' => $request->old('journal_source_account_id', $sourceAccounts->first()->id),
|
||||
'journal_source_account_name' => $request->old('journal_source_account_name', $sourceAccounts->first()->name),
|
||||
@ -213,9 +214,12 @@ class SplitController extends Controller
|
||||
'transactions' => $this->getTransactionDataFromJournal($journal),
|
||||
];
|
||||
// update transactions array with old request data.
|
||||
|
||||
$array['transactions'] = $this->updateWithPrevious($array['transactions'], $request->old());
|
||||
|
||||
// update journal amount and foreign amount:
|
||||
$array['journal_amount'] = array_sum(array_column($array['transactions'], 'amount'));
|
||||
$array['journal_foreign_amount'] = array_sum(array_column($array['transactions'], 'foreign_amount'));
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
63
public/js/ff/transactions/split/edit.js
vendored
63
public/js/ff/transactions/split/edit.js
vendored
@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
|
||||
/** global: originalSum, accounting, what, Modernizr, currencySymbol */
|
||||
/** global: originalSum,originalForeignSum, accounting, what, Modernizr, currencySymbol, foreignCurrencySymbol */
|
||||
|
||||
var destAccounts = {};
|
||||
var srcAccounts = {};
|
||||
@ -69,7 +69,8 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
|
||||
$('input[name$="][amount]"]').on('input', calculateSum);
|
||||
$('input[name$="][amount]"]').on('change', calculateBothSums);
|
||||
$('input[name$="][foreign_amount]"]').on('change', calculateBothSums);
|
||||
|
||||
if (!Modernizr.inputtypes.date) {
|
||||
$('input[type="date"]').datepicker(
|
||||
@ -80,6 +81,12 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
function calculateBothSums() {
|
||||
console.log("Now in calculateBothSums()");
|
||||
calculateSum();
|
||||
calculateForeignSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* New and cool
|
||||
* @param e
|
||||
@ -113,8 +120,8 @@ function cloneDivRow() {
|
||||
source.removeClass('initial-row');
|
||||
source.find('.count').text('#' + count);
|
||||
|
||||
source.find('input[name$="][amount]"]').val("").on('input', calculateSum);
|
||||
source.find('input[name$="][foreign_amount]"]').val("").on('input', calculateSum);
|
||||
source.find('input[name$="][amount]"]').val("").on('change', calculateBothSums);
|
||||
source.find('input[name$="][foreign_amount]"]').val("").on('change', calculateBothSums);
|
||||
if (destAccounts.length > 0) {
|
||||
source.find('input[name$="destination_account_name]"]').typeahead({source: destAccounts, autoSelect: false});
|
||||
}
|
||||
@ -134,7 +141,7 @@ function cloneDivRow() {
|
||||
// remove original click things, add them again:
|
||||
$('.remove-current-split').unbind('click').click(removeDivRow);
|
||||
|
||||
calculateSum();
|
||||
calculateBothSums();
|
||||
resetDivSplits();
|
||||
|
||||
return false;
|
||||
@ -166,16 +173,10 @@ function resetDivSplits() {
|
||||
$.each($('.remove-current-split'), function (i, v) {
|
||||
var button = $(v);
|
||||
button.attr('data-split', i);
|
||||
button.find('i').attr('data-split', i);
|
||||
button.find('span').text(' #' + (i + 1));
|
||||
|
||||
});
|
||||
|
||||
// loop each indicator (#) and update it:
|
||||
$.each($('td.count'), function (i, v) {
|
||||
var cell = $(v);
|
||||
var index = i + 1;
|
||||
cell.text('#' + index);
|
||||
});
|
||||
|
||||
// loop each possible field.
|
||||
|
||||
@ -234,6 +235,7 @@ function resetDivSplits() {
|
||||
|
||||
function calculateSum() {
|
||||
"use strict";
|
||||
console.log("Now in calculateSum()");
|
||||
var left = originalSum * -1;
|
||||
var sum = 0;
|
||||
var set = $('input[name$="][amount]"]');
|
||||
@ -245,14 +247,43 @@ function calculateSum() {
|
||||
sum = Math.round(sum * 100) / 100;
|
||||
left = Math.round(left * 100) / 100;
|
||||
|
||||
console.log("Sum is " + sum + ", left is " + left);
|
||||
|
||||
$('.amount-warning').remove();
|
||||
if (sum !== originalSum) {
|
||||
var holder = $('#journal_amount_holder');
|
||||
var par = holder.find('p.form-control-static');
|
||||
$('<span>').text(' (' + accounting.formatMoney(sum, currencySymbol) + ')').addClass('text-danger amount-warning').appendTo(par);
|
||||
console.log("Is different from original sum " + originalSum);
|
||||
var paragraph = $('#journal_amount_holder').find('p.form-control-static');
|
||||
|
||||
$('<span>').text(' (' + accounting.formatMoney(sum, currencySymbol) + ')').addClass('text-danger amount-warning').appendTo(paragraph);
|
||||
|
||||
// also add what's left to divide (or vice versa)
|
||||
$('<span>').text(' (' + accounting.formatMoney(left, currencySymbol) + ')').addClass('text-danger amount-warning').appendTo(par);
|
||||
$('<span>').text(' (' + accounting.formatMoney(left, currencySymbol) + ')').addClass('text-danger amount-warning').appendTo(paragraph);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function calculateForeignSum() {
|
||||
// "use strict";
|
||||
var left = originalForeignSum * -1;
|
||||
var sum = 0;
|
||||
var set = $('input[name$="][foreign_amount]"]');
|
||||
for (var i = 0; i < set.length; i++) {
|
||||
var current = $(set[i]);
|
||||
sum += (current.val() === "" ? 0 : parseFloat(current.val()));
|
||||
left += (current.val() === "" ? 0 : parseFloat(current.val()));
|
||||
}
|
||||
sum = Math.round(sum * 100) / 100;
|
||||
left = Math.round(left * 100) / 100;
|
||||
|
||||
|
||||
$('.amount-warning-foreign').remove();
|
||||
if (sum !== originalForeignSum) {
|
||||
var paragraph = $('#journal_foreign_amount_holder').find('p.form-control-static');
|
||||
$('<span>').text(' (' + accounting.formatMoney(sum, foreignCurrencySymbol) + ')').addClass('text-danger amount-warning-foreign').appendTo(paragraph);
|
||||
|
||||
// also add what's left to divide (or vice versa)
|
||||
$('<span>').text(' (' + accounting.formatMoney(left, foreignCurrencySymbol) + ')').addClass('text-danger amount-warning-foreign').appendTo(paragraph);
|
||||
}
|
||||
|
||||
}
|
@ -94,6 +94,7 @@ return [
|
||||
'convert_Transfer' => 'Convert transfer',
|
||||
|
||||
'amount' => 'Amount',
|
||||
'foreign_amount' => 'Foreign amount',
|
||||
'date' => 'Date',
|
||||
'interest_date' => 'Interest date',
|
||||
'book_date' => 'Book date',
|
||||
|
@ -50,18 +50,29 @@
|
||||
{{ ExpandedForm.assetAccountList('journal_destination_account_id', preFilled.journal_destination_account_id) }}
|
||||
{% endif %}
|
||||
|
||||
{# TOTAL AMOUNT IS STATIC TEXT #}
|
||||
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
||||
{{ ExpandedForm.staticText('journal_amount', formatAmountByAccount(accountArray[preFilled.journal_source_account_id], preFilled.journal_amount, true) ) }}
|
||||
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
|
||||
{% endif %}
|
||||
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
{{ ExpandedForm.staticText('journal_amount', formatAmountByAccount(accountArray[preFilled.journal_destination_account_id], preFilled.journal_amount, true) ) }}
|
||||
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
|
||||
{% endif %}
|
||||
|
||||
{# show amount and some helper text when making splits: #}
|
||||
{# amount #}
|
||||
<div id="journal_amount_holder" class="form-group">
|
||||
<label for="ffInput_journal_amount" class="col-sm-4 control-label">{{ trans('form.amount') }}</label>
|
||||
<div class="col-sm-8">
|
||||
<p id="ffInput_journal_amount" class="form-control-static">
|
||||
{{ formatAmountBySymbol(preFilled.journal_amount, preFilled.transactions[0].currency_symbol, preFilled.transactions[0].currency_dp) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# foreign amount, if not zero. #}
|
||||
{% if preFilled.journal_foreign_amount != 0 %}
|
||||
<div id="journal_foreign_amount_holder" class="form-group">
|
||||
<label for="ffInput_foreign_journal_amount" class="col-sm-4 control-label">{{ trans('form.foreign_amount') }}</label>
|
||||
<div class="col-sm-8">
|
||||
<p id="ffInput_foreign_journal_amount" class="form-control-static">
|
||||
{{ formatAmountBySymbol(preFilled.journal_foreign_amount, preFilled.transactions[0].foreign_currency_symbol, preFilled.transactions[0].foreign_currency_dp) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
|
||||
{# DATE #}
|
||||
{{ ExpandedForm.date('date', journal.date) }}
|
||||
</div>
|
||||
@ -207,101 +218,83 @@
|
||||
|
||||
|
||||
{% for index, transaction in preFilled.transactions %}
|
||||
<div class="row {% if loop.index0 % 2 == 1 %}bg-gray-light{% endif %} split_row" data-split="{{ loop.index0 }}">
|
||||
{# button #}
|
||||
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6">
|
||||
<a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}">
|
||||
<i class="fa fa-trash" data-split="{{ loop.index0 }}"></i> #{{ loop.index }}</a>
|
||||
</div>
|
||||
<div class="row {% if loop.index0 % 2 == 1 %}bg-gray-light{% endif %} split_row" data-split="{{ loop.index0 }}">
|
||||
{# button #}
|
||||
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6">
|
||||
<a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}">
|
||||
<i class="fa fa-trash" data-split="{{ loop.index0 }}"></i><span> #{{ loop.index }}</span></a>
|
||||
</div>
|
||||
|
||||
{# description #}
|
||||
<div class="col-lg-3 col-md-5 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][transaction_description]"
|
||||
value="{{ transaction.transaction_description }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
|
||||
{# destination for withdrawals: #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][destination_name]"
|
||||
value="{% if transaction.destination_type != 'Cash account' %}{{ transaction.destination_name }}{% endif %}"
|
||||
{# description #}
|
||||
<div class="col-lg-3 col-md-5 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][transaction_description]"
|
||||
value="{{ transaction.transaction_description }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# source for deposits #}
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][source_name]"
|
||||
value="{{ transaction.source_name }}" class="form-control"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# amount#}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
{{ transaction.currency_symbol }} <input class="split_amount_input" type="number" name="transactions[{{ loop.index0 }}][amount]" value="{{ transaction.amount }}"
|
||||
autocomplete="off" step="any">
|
||||
{% if transaction.foreign_amount != null %}
|
||||
{{ transaction.foreign_currency_symbol }} <input class="split_amount_input" type="number" name="transactions[{{ loop.index0 }}][foreign_amount]"
|
||||
value="{{ transaction.foreign_amount }}" autocomplete="off" step="any">
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][foreign_currency_id]" value="{{ transaction.foreign_currency_id }}">
|
||||
{% endif %}
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][transaction_currency_id]"
|
||||
value="{{ transaction.transaction_currency_id }}">
|
||||
</div>
|
||||
{#
|
||||
{% if transaction.foreign_amount != null %}
|
||||
<div class="col-lg-1 col-md-5 col-sm-12 col-xs-12" style="border:1px red solid;">
|
||||
{% else %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12" style="border:1px blue solid;">
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if transaction.foreign_amount != null %}
|
||||
<div class="col-lg-1 col-md-7 col-sm-12 col-xs-12" style="border:1px green solid;">
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">{{ transaction.foreign_currency_symbol }}</div>
|
||||
<input type="number" name="transactions[{{ loop.index0 }}][foreign_amount]"
|
||||
value="{{ transaction.foreign_amount }}"
|
||||
class="form-control" autocomplete="off" step="any">
|
||||
{# destination for withdrawals: #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][destination_name]"
|
||||
value="{% if transaction.destination_type != 'Cash account' %}{{ transaction.destination_name }}{% endif %}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
<input type="hidden"
|
||||
name="transactions[{{ loop.index0 }}][foreign_currency_id]"
|
||||
value="{{ transaction.foreign_currency_id }}">
|
||||
{% endif %}
|
||||
|
||||
{# source for deposits #}
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][source_name]"
|
||||
value="{{ transaction.source_name }}" class="form-control"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# amount#}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
{{ transaction.currency_symbol }} <input class="split_amount_input" type="number"
|
||||
name="transactions[{{ loop.index0 }}][amount]"
|
||||
value="{{ transaction.amount }}"
|
||||
autocomplete="off" step="any">
|
||||
{% if transaction.foreign_amount != null %}
|
||||
{{ transaction.foreign_currency_symbol }} <input class="split_amount_input" type="number"
|
||||
name="transactions[{{ loop.index0 }}][foreign_amount]"
|
||||
value="{{ transaction.foreign_amount }}" autocomplete="off"
|
||||
step="any">
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][foreign_currency_id]"
|
||||
value="{{ transaction.foreign_currency_id }}">
|
||||
{% endif %}
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][transaction_currency_id]"
|
||||
value="{{ transaction.transaction_currency_id }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
#}
|
||||
{# budget #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
|
||||
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
||||
{% for key, budget in budgets %}
|
||||
<option label="{{ budget }}" value="{{ key }}"
|
||||
{% if transaction.budget_id == key %} selected="selected"{% endif %}>{{ budget }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
{# budget #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
|
||||
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
||||
{% for key, budget in budgets %}
|
||||
<option label="{{ budget }}" value="{{ key }}"
|
||||
{% if transaction.budget_id == key %} selected="selected"{% endif %}>{{ budget }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# category #}
|
||||
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][category_name]"
|
||||
value="{{ transaction.category_name }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
{# category #}
|
||||
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
|
||||
<input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][category_name]"
|
||||
value="{{ transaction.category_name }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<p>
|
||||
<br/>
|
||||
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
||||
</p>
|
||||
</div>
|
||||
<p>
|
||||
<br/>
|
||||
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
{# panel for options #}
|
||||
@ -329,14 +322,10 @@
|
||||
{% block scripts %}
|
||||
<script type="text/javascript" src="{{ route('javascript.currencies') }}?ext=.js&v={{ FF_VERSION }}"></script>
|
||||
<script type="text/javascript">
|
||||
var currencySymbol = 'x';
|
||||
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
||||
currencySymbol = currencyInfo[{{ accountArray[preFilled.journal_source_account_id].currency_id }}].symbol;
|
||||
{% endif %}
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
currencySymbol = currencyInfo[{{ accountArray[preFilled.journal_destination_account_id].currency_id }}].symbol;
|
||||
{% endif %}
|
||||
var currencySymbol = "{{ preFilled.transactions[0].currency_symbol }}";
|
||||
var foreignCurrencySymbol = "{{ preFilled.transactions[0].foreign_currency_symbol }}";
|
||||
var originalSum = {{ preFilled.journal_amount }};
|
||||
var originalForeignSum = {{ preFilled.journal_foreign_amount }};
|
||||
var what = "{{ preFilled.what }}";
|
||||
</script>
|
||||
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js?v={{ FF_VERSION }}"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user