Skip to content

Firefly III: a personal finances manager

Expand transaction links

Sander Dorigo6a674ad33746
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
index 45ca6ac9e1..b412c66f46 100644
--- a/resources/assets/v3/js/pages/transactions/create.js
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -60,6 +60,8 @@ import {switchLink} from "./shared/switch-link.js";
import {removeLink} from "./shared/remove-link.js";
import {saveEditedLink} from "./shared/save-edited-link.js";
import {saveNewLink} from "./shared/save-new-link.js";
+import {redirectAfterTransactionLinks} from './shared/redirect-after-transaction-links.js';
+import {processTransactionLinks} from './shared/process-transaction-links.js';
let create = function () {
return {
@@ -190,6 +192,8 @@ let create = function () {
removeLink: removeLink,
saveEditedLink: saveEditedLink,
saveNewLink: saveNewLink,
+ processTransactionLinks: processTransactionLinks,
+ redirectAfterTransactionLinks: redirectAfterTransactionLinks,
filterForeignCurrencies(code) {
let list = [];
@@ -332,55 +336,7 @@ let create = function () {
},
- processTransactionLinks(transactions) {
- let count = 0;
- for (let i = 0; i < transactions.length; i++) {
- if (transactions.hasOwnProperty(i) && this.links.hasOwnProperty(i)) {
- let journalId = transactions[i];
- for (let j = 0; j < this.links[i].length; j++) {
- if (this.links[i].hasOwnProperty(j)) {
- count++;
- let link = this.links[i][j];
- let left = journalId;
- let right = parseInt(link.journal_id);
- if ('inward' === link.link_type_direction) {
- left = parseInt(link.journal_id);
- right = journalId;
- }
- (new PostLink).post(link.link_type_id, left, right, null).then(() => {
- this.redirectAfterTransactionLinks(i, j);
- }).catch(function (e) {
- console.error(e);
- }).finally(function () {
- console.log('finally');
- });
- }
- }
- }
- }
- if (0 === count) {
- this.formStates.storedLinks = true;
- }
- },
- redirectAfterTransactionLinks(oldI, oldJ) {
- this.links[oldI][oldJ].stored = true;
- let completed = true;
- for (let i = 0; i < this.links.length; i++) {
- if (this.links.hasOwnProperty(i)) {
- for (let j = 0; j < this.links[i].length; j++) {
- if (this.links[i].hasOwnProperty(j)) {
- if (false === this.links[i][i].stored) {
- completed = false;
- }
- }
- }
- }
- }
- if (true === completed) {
- this.formStates.storedLinks = completed;
- this.showMessageOrRedirectUser();
- }
- },
+
save() {
this.notifications.error.show = false;
this.notifications.success.show = false;
diff --git a/resources/assets/v3/js/pages/transactions/edit.js b/resources/assets/v3/js/pages/transactions/edit.js
index f5767096c2..bae79c7f58 100644
--- a/resources/assets/v3/js/pages/transactions/edit.js
+++ b/resources/assets/v3/js/pages/transactions/edit.js
@@ -62,6 +62,8 @@ import {switchLink} from "./shared/switch-link.js";
import {removeLink} from "./shared/remove-link.js";
import {saveEditedLink} from "./shared/save-edited-link.js";
import {saveNewLink} from "./shared/save-new-link.js";
+import {processTransactionLinks} from "./shared/process-transaction-links.js";
+import {redirectAfterTransactionLinks} from "./shared/redirect-after-transaction-links.js";
const urls = getUrls();
@@ -91,6 +93,10 @@ let transactions = function () {
resetButton: true,
rulesButton: true,
webhooksButton: true,
+ // some properties that must all be true before the user can be redirected safely.
+ storedGroup: false,
+ storedLinks: false,
+ storedAttachments: false,
},
// form behavior during transaction
@@ -170,6 +176,8 @@ let transactions = function () {
removeLink: removeLink,
saveEditedLink: saveEditedLink,
saveNewLink: saveNewLink,
+ processTransactionLinks: processTransactionLinks,
+ redirectAfterTransactionLinks: redirectAfterTransactionLinks,
// part of the account selection auto-complete
@@ -387,15 +395,28 @@ let transactions = function () {
// submit the transaction. Multi-stage process thing going on here!
let putter = new Put();
putter.put(submission, {id: this.groupProperties.id}).then((response) => {
+ this.formStates.storedGroup = true;
const group = response.data.data;
// submission was a success!
this.groupProperties.id = parseInt(group.id);
- this.groupProperties.title = group.attributes.group_title ?? group.attributes.transactions[0].description
+ this.groupProperties.title = group.attributes.group_title ?? group.attributes.transactions[0].description;
+
+ // process transaction links
+ // submit all transaction links, based on the order of the transaction IDs
+ let transactions = [];
+ for (let i = 0; i < group.attributes.transactions.length; i++) {
+ if (group.attributes.transactions.hasOwnProperty(i)) {
+ transactions.push(parseInt(group.attributes.transactions[i].transaction_journal_id));
+ }
+ }
+ this.processTransactionLinks(transactions);
// process attachments, if any:
const attachmentCount = processAttachments(this.groupProperties.id, group.attributes.transactions);
-
+ if (0 === attachmentCount) {
+ this.formStates.storedAttachments = true;
+ }
if (attachmentCount > 0) {
// if count is more than zero, system is processing transactions in the background.
this.notifications.wait.show = true;
diff --git a/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js
index 557e019e3e..75771e2f3f 100644
--- a/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js
+++ b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js
@@ -78,7 +78,6 @@ export function parseFromEntries(entries, originals, transactionType) {
current.latitude = entry.latitude.toString();
current.zoom_level = entry.zoom_level;
}
- console.log('Zoom level is now ', entry.zoom_level);
if ('__NO_CODE__' === entry.foreign_currency_code) {
entry.foreign_currency_code = '';
}
diff --git a/resources/assets/v3/js/pages/transactions/shared/process-transaction-links.js b/resources/assets/v3/js/pages/transactions/shared/process-transaction-links.js
new file mode 100644
index 0000000000..c6b1bfc8b0
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/process-transaction-links.js
@@ -0,0 +1,30 @@
+import PostLink from "../../../api/model/transaction-link/post.js";
+
+export function processTransactionLinks(transactions) {
+ let count = 0;
+ for (let i = 0; i < transactions.length; i++) {
+ if (transactions.hasOwnProperty(i) && this.links.hasOwnProperty(i)) {
+ let journalId = transactions[i];
+ for (let j = 0; j < this.links[i].length; j++) {
+ if (this.links[i].hasOwnProperty(j)) {
+ count++;
+ let link = this.links[i][j];
+ let left = journalId;
+ let right = parseInt(link.journal_id);
+ if ('inward' === link.link_type_direction) {
+ left = parseInt(link.journal_id);
+ right = journalId;
+ }
+ (new PostLink).post(link.link_type_id, left, right, null).then(() => {
+ this.redirectAfterTransactionLinks(i, j);
+ }).catch(function (e) {
+ console.error(e);
+ });
+ }
+ }
+ }
+ }
+ if (0 === count) {
+ this.formStates.storedLinks = true;
+ }
+}
diff --git a/resources/assets/v3/js/pages/transactions/shared/redirect-after-transaction-links.js b/resources/assets/v3/js/pages/transactions/shared/redirect-after-transaction-links.js
new file mode 100644
index 0000000000..5ee15826e4
--- /dev/null
+++ b/resources/assets/v3/js/pages/transactions/shared/redirect-after-transaction-links.js
@@ -0,0 +1,19 @@
+export function redirectAfterTransactionLinks(oldI, oldJ) {
+ this.links[oldI][oldJ].stored = true;
+ let completed = true;
+ for (let i = 0; i < this.links.length; i++) {
+ if (this.links.hasOwnProperty(i)) {
+ for (let j = 0; j < this.links[i].length; j++) {
+ if (this.links[i].hasOwnProperty(j)) {
+ if (false === this.links[i][i].stored) {
+ completed = false;
+ }
+ }
+ }
+ }
+ }
+ if (true === completed) {
+ this.formStates.storedLinks = completed;
+ this.showMessageOrRedirectUser();
+ }
+};