mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-09 22:26:04 +00:00
Fix #678
This commit is contained in:
@@ -16,8 +16,8 @@ var descriptions = {};
|
|||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
$('.btn-do-split').click(cloneRow);
|
$('.btn-do-split').click(cloneDivRow);
|
||||||
$('.remove-current-split').click(removeRow);
|
$('.remove-current-split').click(removeDivRow);
|
||||||
|
|
||||||
$.getJSON('json/expense-accounts').done(function (data) {
|
$.getJSON('json/expense-accounts').done(function (data) {
|
||||||
destAccounts = data;
|
destAccounts = data;
|
||||||
@@ -67,7 +67,33 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New and cool
|
||||||
|
* @param e
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function removeDivRow(e) {
|
||||||
|
"use strict";
|
||||||
|
var rows = $('div.split_row');
|
||||||
|
if (rows.length === 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var row = $(e.target);
|
||||||
|
var index = row.data('split');
|
||||||
|
$('div.split_row[data-split="' + index + '"]').remove();
|
||||||
|
|
||||||
|
|
||||||
|
resetDivSplits();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OLD
|
||||||
|
* @param e
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
function removeRow(e) {
|
function removeRow(e) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var rows = $('table.split-table tbody tr');
|
var rows = $('table.split-table tbody tr');
|
||||||
@@ -85,6 +111,47 @@ function removeRow(e) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New and cool
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function cloneDivRow() {
|
||||||
|
"use strict";
|
||||||
|
var source = $('div.split_row').last().clone();
|
||||||
|
var count = $('div.split_row').length + 1;
|
||||||
|
source.removeClass('initial-row');
|
||||||
|
source.find('.count').text('#' + count);
|
||||||
|
|
||||||
|
source.find('input[name$="][amount]"]').val("").on('input', calculateSum);
|
||||||
|
if (destAccounts.length > 0) {
|
||||||
|
source.find('input[name$="destination_account_name]"]').typeahead({source: destAccounts});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destAccounts.length > 0) {
|
||||||
|
source.find('input[name$="source_account_name]"]').typeahead({source: srcAccounts});
|
||||||
|
}
|
||||||
|
if (categories.length > 0) {
|
||||||
|
source.find('input[name$="category]"]').typeahead({source: categories});
|
||||||
|
}
|
||||||
|
if (descriptions.length > 0) {
|
||||||
|
source.find('input[name$="description]"]').typeahead({source: descriptions});
|
||||||
|
}
|
||||||
|
|
||||||
|
$('div.split_row_holder').append(source);
|
||||||
|
|
||||||
|
// remove original click things, add them again:
|
||||||
|
$('.remove-current-split').unbind('click').click(removeRow);
|
||||||
|
|
||||||
|
calculateSum();
|
||||||
|
resetDivSplits();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OLD
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
function cloneRow() {
|
function cloneRow() {
|
||||||
"use strict";
|
"use strict";
|
||||||
var source = $('.table.split-table tbody tr').last().clone();
|
var source = $('.table.split-table tbody tr').last().clone();
|
||||||
@@ -119,6 +186,100 @@ function cloneRow() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New and hip
|
||||||
|
*/
|
||||||
|
function resetDivSplits() {
|
||||||
|
"use strict";
|
||||||
|
// loop rows, reset numbers:
|
||||||
|
|
||||||
|
// update the row split number:
|
||||||
|
$.each($('div.split_row'), function (i, v) {
|
||||||
|
var row = $(v);
|
||||||
|
row.attr('data-split', i);
|
||||||
|
|
||||||
|
// add or remove class with bg thing
|
||||||
|
if(i % 2 === 0) {
|
||||||
|
row.removeClass('bg-gray-light');
|
||||||
|
}
|
||||||
|
if(i % 2 === 1) {
|
||||||
|
row.addClass('bg-gray-light');
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// loop each remove button, update the index
|
||||||
|
$.each($('.remove-current-split'), function (i, v) {
|
||||||
|
var button = $(v);
|
||||||
|
button.attr('data-split', i);
|
||||||
|
button.find('i').attr('data-split', i);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
// ends with ][description]
|
||||||
|
$.each($('input[name$="][description]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][description]');
|
||||||
|
});
|
||||||
|
// ends with ][destination_account_name]
|
||||||
|
$.each($('input[name$="][destination_account_name]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][destination_account_name]');
|
||||||
|
});
|
||||||
|
// ends with ][source_account_name]
|
||||||
|
$.each($('input[name$="][source_account_name]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][source_account_name]');
|
||||||
|
});
|
||||||
|
// ends with ][amount]
|
||||||
|
$.each($('input[name$="][amount]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][amount]');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ends with ][foreign_amount]
|
||||||
|
$.each($('input[name$="][foreign_amount]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][foreign_amount]');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ends with ][transaction_currency_id]
|
||||||
|
$.each($('input[name$="][transaction_currency_id]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][transaction_currency_id]');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ends with ][foreign_currency_id]
|
||||||
|
$.each($('input[name$="][foreign_currency_id]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][foreign_currency_id]');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ends with ][budget_id]
|
||||||
|
$.each($('select[name$="][budget_id]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][budget_id]');
|
||||||
|
});
|
||||||
|
|
||||||
|
// ends with ][category]
|
||||||
|
$.each($('input[name$="][category]"]'), function (i, v) {
|
||||||
|
var input = $(v);
|
||||||
|
input.attr('name', 'transactions[' + i + '][category]');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OLD
|
||||||
|
*/
|
||||||
function resetSplits() {
|
function resetSplits() {
|
||||||
"use strict";
|
"use strict";
|
||||||
// loop rows, reset numbers:
|
// loop rows, reset numbers:
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
|
<h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'optional_field_meta_data'|_ }}</h3>
|
<h3 class="box-title">{{ 'optional_field_meta_data'|_ }}</h3>
|
||||||
@@ -185,105 +185,108 @@
|
|||||||
<h3 class="box-title">{{ 'splits'|_ }}</h3>
|
<h3 class="box-title">{{ 'splits'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<table class="table table-bordered table-condensed table-striped split-table">
|
<div class="container-fluid split_row_holder">
|
||||||
<thead>
|
<div class="row bg-gray-light" style="padding-bottom:3px;">
|
||||||
<tr>
|
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6"> </div>
|
||||||
<th> </th>
|
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6"><strong>{{ trans('list.split_number') }}</strong></div>
|
||||||
<th>{{ trans('list.split_number') }}</th>
|
<div class="col-lg-3 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.description') }}</strong></div>
|
||||||
<th>{{ trans('list.description') }}</th>
|
|
||||||
|
|
||||||
{# withdrawal and deposit have a destination. #}
|
{# withdrawal and deposit have a destination. #}
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<th>{{ trans('list.destination') }}</th>
|
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.destination') }}</strong></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# Deposit has a source #}
|
||||||
{# DEPOSIT HAS A SOURCE #}
|
|
||||||
{% if preFilled.what == 'deposit' %}
|
{% if preFilled.what == 'deposit' %}
|
||||||
<th>{{ trans('list.source') }}</th>
|
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.source') }}</strong></div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="col-lg-1 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.amount') }}</strong></div>
|
||||||
|
{% if transaction.foreign_amount != null %}
|
||||||
|
<div class="col-lg-1 col-md-7 col-sm-12 col-xs-12"> </div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<th colspan="2">{{ trans('list.amount') }}</th>
|
|
||||||
|
|
||||||
{# only withdrawal has budget #}
|
{# only withdrawal has budget #}
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<th>{{ trans('list.budget') }}</th>
|
<div class="col-lg-1 col-md-6 col-sm-12 col-xs-12"><strong>{{ trans('list.budget') }}</strong></div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12"><strong>{{ trans('list.category') }}</strong></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% 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></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{# index #}
|
||||||
|
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6 count">#{{ loop.index }}</div>
|
||||||
|
|
||||||
|
{# description #}
|
||||||
|
<div class="col-lg-3 col-md-5 col-sm-12 col-xs-12">
|
||||||
|
<input type="text" name="transactions[{{ loop.index0 }}][description]" value="{{ 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 type="text" name="transactions[{{ loop.index0 }}][destination_account_name]"
|
||||||
|
value="{{ transaction.destination_account_name }}" class="form-control"/>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<th>{{ trans('list.category') }}</th>
|
{# source for deposits #}
|
||||||
</tr>
|
{% if preFilled.what == 'deposit' %}
|
||||||
</thead>
|
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||||
<tbody>
|
<input type="text" name="transactions[{{ loop.index0 }}][source_account_name]"
|
||||||
{% for index, transaction in preFilled.transactions %}
|
value="{{ transaction.source_account_name }}" class="form-control"/>
|
||||||
<tr data-split="{{ loop.index0 }}">
|
</div>
|
||||||
<td><a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}"><i
|
{% endif %}
|
||||||
class="fa fa-trash" data-split="{{ loop.index0 }}"></i></a></td>
|
|
||||||
<td class="count">#{{ loop.index }}</td>
|
|
||||||
<td>
|
|
||||||
<input type="text" name="transactions[{{ loop.index0 }}][description]" value="{{ transaction.description }}"
|
|
||||||
class="form-control"/>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<!-- withdrawal has several destination names. -->
|
{# amount#}
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
<div class="col-lg-1 col-md-5 col-sm-12 col-xs-12">
|
||||||
<td>
|
<div class="input-group">
|
||||||
<input type="text" name="transactions[{{ loop.index0 }}][destination_account_name]"
|
<div class="input-group-addon">{{ transaction.transaction_currency_symbol }}</div>
|
||||||
value="{{ transaction.destination_account_name }}"
|
<input type="number" name="transactions[{{ loop.index0 }}][amount]" value="{{ transaction.amount }}"
|
||||||
class="form-control"/>
|
class="form-control" autocomplete="off" step="any" min="0.01">
|
||||||
</td>
|
</div>
|
||||||
{% endif %}
|
<input type="hidden" name="transactions[{{ loop.index0 }}][transaction_currency_id]"
|
||||||
|
value="{{ transaction.transaction_currency_id }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
{# deposit has several source names #}
|
{# foreign amount #}
|
||||||
{% if preFilled.what == 'deposit' %}
|
{% if transaction.foreign_amount != null %}
|
||||||
<td>
|
<div class="col-lg-1 col-md-7 col-sm-12 col-xs-12">
|
||||||
<input type="text" name="transactions[{{ loop.index0 }}][source_account_name]"
|
|
||||||
value="{{ transaction.source_account_name }}"
|
|
||||||
class="form-control"/>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# two fields for amount #}
|
|
||||||
<td style="width:10%;">
|
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-addon">{{ transaction.transaction_currency_symbol }}</div>
|
<div class="input-group-addon">{{ transaction.foreign_currency_symbol }}</div>
|
||||||
<input type="number" name="transactions[{{ loop.index0 }}][amount]" value="{{ transaction.amount }}"
|
<input type="number" name="transactions[{{ loop.index0 }}][foreign_amount]" value="{{ transaction.foreign_amount }}"
|
||||||
class="form-control" autocomplete="off" step="any" min="0.01">
|
class="form-control" autocomplete="off" step="any" min="0.01">
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="transactions[{{ loop.index0 }}][transaction_currency_id]" value="{{ transaction.transaction_currency_id }}">
|
<input type="hidden"
|
||||||
</td>
|
name="transactions[{{ loop.index0 }}][foreign_currency_id]"
|
||||||
{# foreign amount #}
|
value="{{ transaction.foreign_currency_id }}">
|
||||||
<td style="width:10%;">
|
</div>
|
||||||
{% if transaction.foreign_amount != null %}
|
{% endif %}
|
||||||
<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" min="0.01">
|
|
||||||
</div>
|
|
||||||
<input type="hidden" name="transactions[{{ loop.index0 }}][foreign_currency_id]" value="{{ transaction.foreign_currency_id }}">
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{% if preFilled.what == 'withdrawal' %}
|
{# budget #}
|
||||||
<td>
|
{% if preFilled.what == 'withdrawal' %}
|
||||||
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
<div class="col-lg-1 col-md-6 col-sm-12 col-xs-12">
|
||||||
{% for key, budget in budgets %}
|
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
||||||
<option label="{{ budget }}" value="{{ key }}"
|
{% for key, budget in budgets %}
|
||||||
{% if transaction.budget_id == key %}
|
<option label="{{ budget }}" value="{{ key }}"
|
||||||
selected="selected"
|
{% if transaction.budget_id == key %} selected="selected"{% endif %}>{{ budget }}</option>
|
||||||
{% endif %}
|
{% endfor %}
|
||||||
>{{ budget }}</option>
|
</select>
|
||||||
{% endfor %}
|
</div>
|
||||||
</select>
|
{% endif %}
|
||||||
</td>
|
|
||||||
{% endif %}
|
{# category #}
|
||||||
<td>
|
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
|
||||||
<input type="text" name="transactions[{{ loop.index0 }}][category]" value="{{ transaction.category }}"
|
<input type="text" name="transactions[{{ loop.index0 }}][category]" value="{{ transaction.category }}"
|
||||||
class="form-control"/>
|
class="form-control"/>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
|
||||||
<p>
|
<p>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
||||||
|
Reference in New Issue
Block a user