Skip to content

Firefly III: a personal finances manager

Expand split functionality.

James Cole039b8df21bd0
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
index 2ff02cca15..32f74552df 100644
--- a/resources/assets/v3/js/pages/transactions/create.js
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -122,7 +122,8 @@ let create = function () {
foreignCurrencies: [], // this is the select list for foreign currencies.
budgets: [],
piggyBanks: [],
- subscriptions: []
+ subscriptions: [],
+ linkTypes: [],
},
@@ -246,6 +247,52 @@ let create = function () {
// TODO don't do this on a timeout!
}, 500);
},
+ switchLink(e) {
+ let rowIndex = parseInt(e.currentTarget.dataset.rowIndex);
+ let index = parseInt(e.currentTarget.dataset.index);
+ let linkTypeId = parseInt(this.links[index][rowIndex].link_type.split('_')[0]);
+ let linkTypeDirection = this.links[index][rowIndex].link_type.split('_')[1];
+ let linkType = this.formData.linkTypes.find(link => link.id === linkTypeId);
+ // switch link type.
+ linkTypeDirection = 'inward' === linkTypeDirection ? 'outward' : 'inward';
+ if(typeof linkType === 'undefined') {
+ console.error('Link type not found for id ' + linkTypeId);
+ console.log(this.formData.linkTypes);
+ return;
+ }
+ this.links[index][rowIndex].link_type = linkType.id + '_' + linkTypeDirection;
+ this.links[index][rowIndex].link_type_label = linkType[linkTypeDirection];
+ this.links[index][rowIndex].link_type_direction = linkTypeDirection;
+ },
+ removeLink(e) {
+ let rowIndex = parseInt(e.currentTarget.dataset.rowIndex);
+ let index = parseInt(e.currentTarget.dataset.index);
+ this.links[index].splice(rowIndex,1);
+ },
+ saveEditedLink(e) {
+ let rowIndex = parseInt(e.currentTarget.dataset.rowIndex);
+ let index = parseInt(e.currentTarget.dataset.index);
+ let selector = e.currentTarget.parentNode.querySelector('select[name="new-link-type"]');
+
+ let linkType = selector.value;
+ let linkTypeId = parseInt(linkType.split('_')[0]);
+ let linkTypeDirection = linkType.split('_')[1];
+ let linkTypeObj = this.formData.linkTypes.find(link => link.id === linkTypeId);
+ if(typeof linkTypeObj === 'undefined') {
+ console.error('Link type not found for id ' + linkTypeId);
+ return;
+ }
+ this.links[index][rowIndex].link_type = linkTypeId + '_' + linkTypeDirection;
+ this.links[index][rowIndex].link_type_id = linkTypeId;
+ this.links[index][rowIndex].link_type_direction = linkTypeDirection;
+ this.links[index][rowIndex].link_type_label = linkTypeObj[linkTypeDirection];
+ this.links[index][rowIndex].editMode = false;
+ },
+ editLink(e) {
+ let rowIndex = parseInt(e.currentTarget.dataset.rowIndex);
+ let index = parseInt(e.currentTarget.dataset.index);
+ this.links[index][rowIndex].editMode = true;
+ },
saveNewLink(e) {
let index = parseInt(e.currentTarget.dataset.index);
@@ -254,6 +301,11 @@ let create = function () {
let linkLabel = linkSelect.options[linkSelect.selectedIndex].innerHTML;
let searchBox = document.getElementById('links_modal_search_' + index);
let hiddenField = searchBox.parentNode.querySelector('input[name="search"]');
+
+ let linkTypeId = parseInt(linkType.split('_')[0]);
+ let linkTypeDirection = linkType.split('_')[1];
+ let linkTypeObj = this.formData.linkTypes.find(link => link.id === linkTypeId);
+
if('' === linkType || '' === hiddenField.value || '' === searchBox.value) {
return;
}
@@ -264,17 +316,20 @@ let create = function () {
this.links[index].push(
{
id: 0,
- type: linkType,
- label: linkLabel,
+ link_type: linkTypeId + '_' + linkTypeDirection,
+ link_type_id: linkTypeId,
+ link_type_direction: linkTypeDirection,
+ link_type_label: linkTypeObj[linkTypeDirection],
journal_id: hiddenField.value,
group_id: hiddenField.value,
- description: searchBox.value,
+ journal_description: searchBox.value,
editMode: false,
}
);
searchBox.value = '';
hiddenField.value = '';
},
+
createAutocomplete(fieldIdentifier, url) {
let token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
@@ -335,7 +390,14 @@ let create = function () {
if(true === data.links) {
loadTransactionLinks().then(data => {
//console.log(data);
- this.formData.linkTypes = data;
+ for(let i = 0; i < data.length; i++) {
+ if(data.hasOwnProperty(i)) {
+ let current = data[i];
+ current.id = parseInt(current.id);
+ this.formData.linkTypes.push(current);
+ }
+ }
+ //this.formData.linkTypes = data;
this.formStates.loadingLinks = false;
this.createAutocomplete('links_modal_search_0','api/v1/autocomplete/transactions-with-meta');
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 6c989c8558..0ac10f8b89 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -350,6 +350,7 @@ return [
// search
'search' => 'Search',
'search_query' => 'Query',
+ 'search_query_here' => 'Search here...',
'search_found_transactions' => 'Firefly III found :count transaction in :time seconds.|Firefly III found :count transactions in :time seconds.',
'search_found_more_transactions' => 'Firefly III found more than :count transactions in :time seconds.',
'search_for_overview' => 'Firefly III is searching for transactions that fulfill <b>all</b> of the following conditions:',
@@ -2755,6 +2756,9 @@ return [
'(partially) refunds' => '(partially) refunds',
'(partially) pays for' => '(partially) pays for',
'(partially) reimburses' => '(partially) reimburses',
+ 'explain_related' => 'You can link transactions. The link doesn\'t do anything YET, but this is on my list.',
+ 'no_relations_yet' => 'This transaction has no relations to other transactions (yet).',
+ 'auto_save_active' => 'Changes are saved automatically.',
// split a transaction:
'splits' => 'Splits',
@@ -2858,7 +2862,10 @@ return [
'overview_for_recurrence' => 'Overview for recurring transaction ":title"',
'warning_duplicates_repetitions' => 'In rare instances, dates appear twice in this list. This can happen when multiple repetitions collide. Firefly III will always generate one transaction per day.',
'created_transactions' => 'Related transactions',
+ 'related_transactions' => 'Related transactions',
'manage_related_transactions' => 'Manage related transactions',
+ 'link_header_create' => 'Link this new transaction to existing transactions',
+ 'link_header_edit' => 'Link this transaction to existing transactions',
'switch' => 'Switch',
'expected_withdrawals' => 'Expected withdrawals',
'expected_deposits' => 'Expected deposits',
diff --git a/resources/views/components/transaction/split.blade.php b/resources/views/components/transaction/split.blade.php
index d846e24c4f..fd3fe7e1fe 100644
--- a/resources/views/components/transaction/split.blade.php
+++ b/resources/views/components/transaction/split.blade.php
@@ -150,10 +150,10 @@
<div class="row">
<div class="col">
<p><em class="text-info">
- TODO Bla bla bla explanation.
+ {{ __('firefly.explain_related') }}
</em>
<template x-if="0 === links[index].length">
- <em>TODO This transaction has no relations to other transactions (yet).</em>
+ <em>{{ __('firefly.no_relations_yet') }}</em>
</template>
</p>
</div>
@@ -163,19 +163,45 @@
<div class="col">
<table class="table table-sm table-bordered">
<tr>
- <th colspan="2">Transaction relations</th>
+ <th colspan="2">{{ __('firefly.related_transactions') }}</th>
</tr>
<template x-for="link, key in links[index]" key="link.id">
<tr>
<td>
- <span x-text="link.label"></span> <a :href="'transactions/show-by-journal/' + link.journal_id" target="_blank"><span x-text="link.description"></span></a>
+ <template x-if="!link.editMode">
+ <span>
+ <span x-text="link.link_type_label"></span> <a :href="'transactions/show-by-journal/' + link.journal_id" target="_blank"><span x-text="link.journal_description"></span></a>
+ </span>
+ </template>
+ <template x-if="link.editMode">
+ <div class="row">
+ <div class="col">
+ <div class="input-group">
+ <select name="new-link-type" class="form-control">
+ <template x-for="type in formData.linkTypes ">
+ <option :selected="type.id === link.link_type_id && 'inward' === link.link_type_direction" :value="type.id + '_inward'" :label="type.inward" x-text="type.inward"></option>
+ </template>
+ <template x-for="type in formData.linkTypes">
+ <option :selected="type.id === link.link_type_id && 'outward' === link.link_type_direction" :value="type.id + '_outward'" :label="type.outward" x-text="type.outward"></option>
+ </template>
+ </select>
+ <button type="button" :data-index="index" :data-row-index="key" @click.prevent="saveEditedLink" class="btn btn-sm btn-outline-success"><em class="bi bi-check"></em></button>
+ </div>
+ </div>
+ <div class="col">
+ <input type="text" readonly class="form-control-plaintext" :value="link.journal_description">
+ </div>
+ </div>
+ </template>
</td>
<td class="w-20">
+ <template x-if="!link.editMode">
<div class="btn-group btn-group-sm">
- <button :data-row-index="key" @click.prevent="switchLink" class="btn btn-outline-secondary" title="{{ __('firefly.switch') }}"><em class="bi bi-arrow-left-right"></em></button>
- <button :data-row-index="key" @click.prevent="editLink" class="btn btn-outline-secondary" title="{{ __('firefly.edit') }}"><em class="bi bi-pencil"></em></button>
- <button :data-row-index="key" @click.prevent="removeLink" class="btn btn-outline-danger" title="{{ __('firefly.delete') }}"><em class="bi bi-trash"></em></button>
+ <button :data-index="index" :data-row-index="key" @click.prevent="switchLink" class="btn btn-outline-secondary" title="{{ __('firefly.switch') }}"><em class="bi bi-arrow-left-right"></em></button>
+ <button :data-index="index" :data-row-index="key" @click.prevent="editLink" class="btn btn-outline-secondary" title="{{ __('firefly.edit') }}"><em class="bi bi-pencil"></em></button>
+ <button :data-index="index" :data-row-index="key" @click.prevent="removeLink" class="btn btn-outline-danger" title="{{ __('firefly.delete') }}"><em class="bi bi-trash"></em></button>
</div>
+ </template>
</td>
</tr>
</template>
@@ -186,10 +212,15 @@
</template>
<div class="row">
<div class="col">
- <h5>Link this (TODO NEW?) transaction to another transaction</h5>
+ <template x-if="'create' === formBehaviour.formType">
+ <h5>{{ __('firefly.link_header_create') }}</h5>
+ </template>
+ <template x-if="'edit' === formBehaviour.formType">
+ <h5>{{ __('firefly.link_header_edit') }}</h5>
+ </template>
<div class="row">
<div class="col w-30">
- <input type="text" readonly class="form-control-plaintext" value="This transaction">
+ <input type="text" readonly class="form-control-plaintext" value="{{ __('firefly.this_transaction') }}">
</div>
<div class="col">
<select class="form-control" name="link_type_id" :data-index="index" :id="'link_type_id_' + index">
@@ -202,10 +233,10 @@
</select>
</div>
<div class="col">
- <input type="text" name="search" :id="'links_modal_search_' + index" class="form-control linked-transactions-search" placeholder="TODO Search here..." aria-label="TODO Search here...">
+ <input type="text" name="search" :id="'links_modal_search_' + index" class="form-control linked-transactions-search" placeholder="{{ __('firefly.search_query_here') }}" aria-label="{{ __('firefly.search_query_here') }}">
</div>
<div class="col w-15 text-end">
- <input type="submit" name="submit" :data-index="index" @click.prevent="saveNewLink" value="TODO Save" class="btn btn-primary">
+ <input type="submit" name="submit" :data-index="index" @click.prevent="saveNewLink" value="{{ __('firefly.add') }}" class="btn btn-primary">
</div>
</div>
</div>
@@ -216,10 +247,12 @@
<div class="modal-footer">
<div class="row inline" style="width:100%;">
<div class="col align-middle d-flex align-items-center">
- <em><small>Changes are saved automatically</small></em>
+ <em><small>
+ {{ __('firefly.auto_save_active') }}
+ </small></em>
</div>
<div class="col text-end">
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ __('firefly.close') }}</button>
</div>
</div>
</div>