Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Various fixes for v2 issues in 5.5.7
James Cole9b0b80d1d485
diff --git a/frontend/src/components/transactions/Create.vue b/frontend/src/components/transactions/Create.vueindex c3c57f2864..5f315e9285 100644--- a/frontend/src/components/transactions/Create.vue+++ b/frontend/src/components/transactions/Create.vue@@ -40,6 +40,7 @@:transaction="transaction":transaction-type="transactionType"v-on:uploaded-attachments="uploadedAttachment($event)"+ v-on:selected-attachments="selectedAttachment($event)"v-on:set-marker-location="storeLocation($event)"v-on:set-account="storeAccountValue($event)"v-on:set-date="storeDate($event)"@@ -166,7 +167,7 @@ export default {// things the process is done working on (3 phases):submittedTransaction: false,submittedLinks: false,- submittedAttachments: false,+ submittedAttachments: -1, // -1 (no attachments), 0 = uploading, 1 = uploaded// transaction was actually submitted?inError: false,@@ -201,14 +202,10 @@ export default {...mapGetters('root', ['listPageSize'])},watch: {- submittedTransaction: function () {- this.finalizeSubmit();- },- submittedLinks: function () {- this.finalizeSubmit();- },submittedAttachments: function () {- this.finalizeSubmit();+ // console.log('Watch submittedAttachments');++ this.finaliseSubmission();}},methods: {@@ -243,7 +240,7 @@ export default {* and creating links. Only once all three steps are executed may the message be shown or the user be* forwarded.*/- finalizeSubmit() {+ finalizeSubmitXX() {// console.log('finalizeSubmit (' + this.submittedTransaction + ', ' + this.submittedAttachments + ', ' + this.submittedLinks + ')');if (this.submittedTransaction && this.submittedAttachments && this.submittedLinks) {// console.log('all true');@@ -265,7 +262,7 @@ export default {this.enableSubmit = true;this.submittedTransaction = false;this.submittedLinks = false;- this.submittedAttachments = false;+ //this.submittedAttachments = false;this.inError = false;@@ -273,8 +270,7 @@ export default {for (let i in this.transactions) {if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {if (this.transactions.hasOwnProperty(i)) {- // console.log('Reset attachment #' + i);- this.updateField({index: i, field: 'transaction_journal_id', value: 0});+ this.updateField({index: i, field: 'clearTrigger', value: true});}}}@@ -291,6 +287,148 @@ export default {}// console.log('Did nothing in finalizeSubmit');},++ submitData: function (url, data) {+ return axios.post(url, data);+ },+ handleSubmissionResponse: function (response) {+ // save some meta data:+ this.returnedGroupId = parseInt(response.data.data.id);+ this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;+ let journals = [];++ // save separate journal ID's (useful ahead in the process):+ let result = response.data.data.attributes.transactions+ for (let i in result) {+ if (result.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ journals.push(parseInt(result[i].transaction_journal_id));+ }+ }++ return new Promise((resolve) => {+ resolve(+ {+ journals: journals,+ }+ );+ });+ },+ submitLinks: function (response, submission) {+ let promises = [];+ // for+ for (let i in response.journals) {+ if (response.journals.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ let journalId = response.journals[i];+ let links = submission.transactions[i].links;+ for (let ii in links) {+ if (links.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {+ let currentLink = links[ii];+ if (0 === currentLink.outward_id) {+ currentLink.outward_id = journalId;+ }+ if (0 === currentLink.inward_id) {+ currentLink.inward_id = journalId;+ }+ promises.push(axios.post('./api/v1/transaction_links', currentLink));+ }+ }+ }+ }+ if (0 === promises.length) {+ return new Promise((resolve) => {+ resolve(+ {+ response: 'from submitLinks'+ }+ );+ });+ }+ return Promise.all(promises);+ },+ submitAttachments: function (response, submission) {+ let anyAttachments = false;+ for (let i in response.journals) {+ if (response.journals.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ let journalId = response.journals[i];+ let hasAttachments = submission.transactions[i].attachments;+ // console.log('Decided that ' + journalId);+ // console.log(hasAttachments);+ if (hasAttachments) {+ // console.log('upload!');+ this.updateField({index: i, field: 'transaction_journal_id', value: journalId});+ anyAttachments = true;+ }+ }+ }++ if (true === anyAttachments) {+ this.submittedAttachments = 0;+ }++ return new Promise((resolve) => {+ resolve(+ {+ response: 'from submitAttachments'+ }+ );+ });+ },+ selectedAttachment: function (payload) {+ this.updateField({index: payload.index, field: 'attachments', value: true});+ },+ finaliseSubmission: function () {+ if (0 === this.submittedAttachments) {+ // console.log('submittedAttachments = ' + this.submittedAttachments);+ return;+ }+ // console.log('finaliseSubmission');+ if (false === this.createAnother) {+ window.location.href = (window.previousURL ?? '/') + '?transaction_group_id=' + this.returnedGroupId + '&message=created';+ return;+ }+ if (false === this.inError) {+ // show message:+ this.errorMessage = '';+ this.successMessage = this.$t('firefly.transaction_stored_link', {ID: this.returnedGroupId, title: this.returnedGroupTitle});+ }++ // enable flags:+ this.enableSubmit = true;+ this.submittedTransaction = false;+ this.submittedAttachments = -1;++ // reset attachments+ if (!this.resetFormAfter) {+ for (let i in this.transactions) {+ if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ if (this.transactions.hasOwnProperty(i)) {+ // console.log('Reset attachment #' + i);+ this.updateField({index: i, field: 'transaction_journal_id', value: 0});+ }+ }+ }+ }+ // reset the form:+ if (this.resetFormAfter) {+ this.resetTransactions();+ this.addTransaction();+ }+ return new Promise((resolve) => {+ resolve(+ {+ response: 'from finaliseSubmission'+ }+ );+ });+ },+ handleSubmissionError: function (error) {+ // oh noes Firefly III has something to bitch about.+ this.enableSubmit = true;++ // but report an error because error:+ this.inError = true;+ this.parseErrors(error.response.data);+ },/*** Actually submit the transaction to Firefly III. This is a fairly complex beast of a thing because multiple things* need to happen in the right order.@@ -305,40 +443,50 @@ export default {const url = './api/v1/transactions';const data = this.convertData();- // console.log('Will submit:');- // console.log(data);-- // POST the transaction.- axios.post(url, data)+ this.submitData(url, data)+ .then(this.handleSubmissionResponse).then(response => {- // console.log('Response is OK!');- // report the transaction is submitted.- this.submittedTransaction = true;-- // submit links and attachments (can only be done when the transaction is created)- this.submitTransactionLinks(data, response);- this.submitAttachments(data, response);-- // meanwhile, store the ID and the title in some easy to access variables.- this.returnedGroupId = parseInt(response.data.data.id);- this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;- // console.log('Group title is now "' + this.groupTitle + '"');- })- .catch(error => {- // oh noes Firefly III has something to bitch about.- this.enableSubmit = true;- // console.log('enable submit = true');- // report the transaction is submitted.- this.submittedTransaction = true;- // also report attachments and links are submitted:- this.submittedAttachments = true;- this.submittedLinks = true;-- // but report an error because error:- this.inError = true;- this.parseErrors(error.response.data);- });- },+ return Promise.all([this.submitLinks(response, data), this.submitAttachments(response, data)]);+ }+ )+ .then(this.finaliseSubmission)+ .catch(this.handleSubmissionError);++ // // console.log('Will submit:');+ // // console.log(data);+ //+ // // POST the transaction.+ // axios.post(url, data)+ // .then(response => {+ // // console.log('Response is OK!');+ // // report the transaction is submitted.+ // this.submittedTransaction = true;+ //+ // // submit links and attachments (can only be done when the transaction is created)+ // this.submitTransactionLinks(data, response);+ // this.submitAttachments(data, response);+ //+ // // meanwhile, store the ID and the title in some easy to access variables.+ // this.returnedGroupId = parseInt(response.data.data.id);+ // this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;+ // // console.log('Group title is now "' + this.groupTitle + '"');+ // })+ // .catch(error => {+ // // oh noes Firefly III has something to bitch about.+ // this.enableSubmit = true;+ // // console.log('enable submit = true');+ // // report the transaction is submitted.+ // this.submittedTransaction = true;+ // // also report attachments and links are submitted:+ // this.submittedAttachments = true;+ // this.submittedLinks = true;+ //+ // // but report an error because error:+ // this.inError = true;+ // this.parseErrors(error.response.data);+ // });+ }+ ,/*** Submitting transactions means we will give each TransactionAttachment component@@ -348,7 +496,7 @@ export default {** The ID is set via the store.*/- submitAttachments: function (data, response) {+ submitAttachmentsX: function (data, response) {// console.log('submitAttachments()');let result = response.data.data.attributes.transactionsfor (let i in data.transactions) {@@ -359,7 +507,8 @@ export default {}}}- },+ }+ ,/*** When a attachment component is done uploading it ends up here. We create an object where we count how many* attachment components have reported back they're done uploading. Of course if they have nothing to upload@@ -368,6 +517,7 @@ export default {* Once the number of components matches the number of splits we know all attachments have been uploaded.*/uploadedAttachment: function (journalId) {+ this.submittedAttachments = 0;// console.log('Triggered uploadedAttachment(' + journalId + ')');let key = 'str' + journalId;this.submittedAttCount[key] = 1;@@ -375,11 +525,12 @@ export default {// console.log('Count is now ' + count);// console.log('Length is ' + this.transactions.length);if (count === this.transactions.length) {- // mark the attachments as stored:- this.submittedAttachments = true;// console.log('Got them all!');+ // mark the attachments as stored:+ this.submittedAttachments = 1;}- },+ }+ ,/*** Responds to changed location.*/@@ -458,11 +609,13 @@ export default {this.submittedLinks = true;});},-parseErrors: function (errors) {for (let i in this.transactions) {- this.resetErrors({index: i});+ if (this.transactions.hasOwnProperty(i)) {+ this.resetErrors({index: i});+ }}+this.successMessage = '';this.errorMessage = this.$t('firefly.errors_submission');if (typeof errors.errors === 'undefined') {@@ -471,12 +624,6 @@ export default {}let payload;- //payload = {index: 0, field: 'description', errors: ['Test error index 0']};- //this.setTransactionError(payload);-- //payload = {index: 1, field: 'description', errors: ['Test error index 1']};- //this.setTransactionError(payload);-let transactionIndex;let fieldName;@@ -701,6 +848,7 @@ export default {// from thing:order: 0,reconciled: false,+ attachments: array.attachments,};if (0 !== array.tags.length) {diff --git a/frontend/src/components/transactions/Edit.vue b/frontend/src/components/transactions/Edit.vueindex 8826416389..46b2059dd1 100644--- a/frontend/src/components/transactions/Edit.vue+++ b/frontend/src/components/transactions/Edit.vue@@ -23,6 +23,7 @@<Alert :message="errorMessage" type="danger"/><Alert :message="successMessage" type="success"/><Alert :message="warningMessage" type="warning"/>+<form @submit="submitTransaction" autocomplete="off"><SplitPills :transactions="transactions"/>@@ -40,7 +41,6 @@:destination-allowed-types="destinationAllowedTypes":source-allowed-types="sourceAllowedTypes":allow-switch="false"- :submitted-transaction="submittedTransaction"v-on:uploaded-attachments="uploadedAttachment($event)"v-on:set-marker-location="storeLocation($event)"v-on:set-account="storeAccountValue($event)"@@ -74,7 +74,8 @@<div class="text-xs d-none d-lg-block d-xl-block"> </div>- <button type="button" class="btn btn-outline-primary btn-block" @click="addTransaction"><i class="far fa-clone"></i> {{ $t('firefly.add_another_split') }}+ <button type="button" class="btn btn-outline-primary btn-block" @click="addTransaction"><i class="far fa-clone"></i>+ {{ $t('firefly.add_another_split') }}</button></div><div class="col">@@ -109,12 +110,14 @@</template><script>-const lodashClonedeep = require('lodash.clonedeep');+import {mapMutations} from "vuex";import Alert from '../partials/Alert';import SplitPills from "./SplitPills";import SplitForm from "./SplitForm";import TransactionGroupTitle from "./TransactionGroupTitle";-import {getDefaultErrors, getDefaultTransaction, toW3CString} from '../../shared/transactions';+import {getDefaultErrors, getDefaultTransaction} from '../../shared/transactions';++const lodashClonedeep = require('lodash.clonedeep');export default {name: "Edit",@@ -156,10 +159,15 @@ export default {// things the process is done working on (3 phases):submittedTransaction: false,- submittedLinks: false,- submittedAttachments: false,+ // submittedLinks: false,+ submittedAttachments: -1, // -1 = no attachments, 0 = uploading, 1 = uploadedinError: false,+ // number of uploaded attachments+ // its an object because we count per transaction journal (which can have multiple attachments)+ // and array doesn't work right.+ submittedAttCount: {},+// meta data for accountsallowedOpposingTypes: {},destinationAllowedTypes: [],@@ -179,21 +187,13 @@ export default {},watch: {- submittedTransaction: function () {- // see finalizeSubmit()- this.finalizeSubmit();- },- submittedLinks: function () {- // see finalizeSubmit()- this.finalizeSubmit();- },submittedAttachments: function () {- // see finalizeSubmit()- this.finalizeSubmit();+ this.finaliseSubmission();}},methods: {+ ...mapMutations('transactions/create', ['updateField',]),/*** Grap transaction group from URL and submit GET.*/@@ -203,8 +203,8 @@ export default {this.parseTransactionGroup(response.data);}).catch(error => {- // console.log('I failed :(');- // console.log(error);+ console.log('I failed :(');+ console.log(error);});},/**@@ -219,6 +219,10 @@ export default {this.groupTitle = attributes.group_title;this.originalGroupTitle = attributes.group_title;+ //this.returnedGroupId = parseInt(response.data.id);+ this.returnedGroupTitle = null === this.originalGroupTitle ? response.data.attributes.transactions[0].description : this.originalGroupTitle;++for (let i in transactions) {if (transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {let result = this.parseTransaction(parseInt(i), transactions[i]);@@ -239,6 +243,8 @@ export default {//console.log('index: ' + index);if (0 === index) {this.transactionType = array.type.charAt(0).toUpperCase() + array.type.slice(1);++ // TODO here you may need to catch stuff like loan/debt/mortgagethis.sourceAllowedTypes = [array.source_type];this.destinationAllowedTypes = [array.destination_type];this.date = array.date.substring(0, 16);@@ -292,7 +298,6 @@ export default {result.zoom_level = array.zoom_level;result.longitude = array.longitude;result.latitude = array.latitude;-// error handlingresult.errors = getDefaultErrors();return result;@@ -370,14 +375,12 @@ export default {});},/**- * TODO same method as Create* Get API value.*/getAllowedOpposingTypes: function () {axios.get('./api/v1/configuration/firefly.allowed_opposing_types').then(response => {this.allowedOpposingTypes = response.data.data.value;- // console.log('Set allowedOpposingTypes');});},/**@@ -389,8 +392,20 @@ export default {});},uploadedAttachment: function (payload) {- // console.log('event: uploadedAttachment');- // console.log(payload);+ //console.log('event: uploadedAttachment');+ //console.log(payload);+ this.submittedAttachments = 0;+ // console.log('Triggered uploadedAttachment(' + journalId + ')');+ let key = 'str' + payload;+ this.submittedAttCount[key] = 1;+ let count = Object.keys(this.submittedAttCount).length;+ //console.log('Count is now ' + count);+ //console.log('Length is ' + this.transactions.length);+ if (count === this.transactions.length) {+ //console.log('Got them all!');+ // mark the attachments as stored:+ this.submittedAttachments = 1;+ }},storeLocation: function (payload) {this.transactions[payload.index].zoom_level = payload.zoomLevel;@@ -405,26 +420,25 @@ export default {this.transactions[index][direction + '_account_name'] = payload.name;},storeDate: function (payload) {- // console.log('event: storeDate');- // console.log(payload);this.date = payload.date;},- storeTime: function (payload) {- this.time = payload.time;- // console.log('event: storeTime');- // console.log(payload);- },storeField: function (payload) {let field = payload.field;if ('category' === field) {field = 'category_name';}- // console.log('event: storeField(' + field + ')');this.transactions[payload.index][field] = payload.value;},removeTransaction: function (payload) {+ //console.log('removeTransaction()');+ //console.log(payload);+ //console.log('length: ' + this.transactions.length);this.transactions.splice(payload.index, 1);+ //console.log('length: ' + this.transactions.length);+++ //this.originalTransactions.splice(payload.index, 1);// this kills the original transactions.this.originalTransactions = [];},@@ -432,9 +446,12 @@ export default {this.groupTitle = payload;},selectedAttachments: function (payload) {+ //console.log('Now in selectedAttachments()');for (let i in this.transactions) {if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {- if (parseInt(this.transactions[i].transaction_journal_id) === parseInt(payload)) {+ // console.log('Payload is');+ // console.log(payload);+ if (parseInt(this.transactions[i].transaction_journal_id) === parseInt(payload.id)) {// console.log('selectedAttachments ' + payload);this.transactions[i].selectedAttachments = true;}@@ -450,56 +467,55 @@ export default {submitTransaction: function (event) {event.preventDefault();let submission = {transactions: []};++ // parse data to see if we should submit anything at all:let shouldSubmit = false;let shouldLinks = false;let shouldUpload = false;++ // if the group title has changed, should submit:if (this.groupTitle !== this.originalGroupTitle) {submission.group_title = this.groupTitle;shouldSubmit = true;}- let transactionCount = this.originalTransactions.length;- let newTransactionCount = this.transactions.length;- // console.log('Found ' + this.transactions.length + ' split(s).');+ // if something with the group title:+ let newTransactionCount = this.transactions.length;if (newTransactionCount > 1 && typeof submission.group_title === 'undefined' && (null === this.originalGroupTitle || '' === this.originalGroupTitle)) {submission.group_title = this.transactions[0].description;+ shouldSubmit = true;}+ // loop each transaction (edited by the user):for (let i in this.transactions) {if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {- // original transaction present?++ // original transaction present:let currentTransaction = this.transactions[i];let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};-+ // the difference:let diff = {};// compare basic fields:- let basicFields = [- 'description',- 'source_account_id', 'source_account_name',- 'destination_account_id', 'destination_account_name',- 'amount', 'foreign_amount', 'foreign_currency_id',- 'category_name', 'budget_id', 'bill_id',- 'interest_date', 'book_date', 'due_date', 'payment_date', 'invoice_date',- 'external_url', 'internal_reference', 'external_id', 'notes',- 'zoom_level', 'longitude', 'latitude'- ];-- // source and destination may be overruled:+ let basicFields = ['description', 'source_account_id', 'source_account_name', 'destination_account_id', 'destination_account_name', 'amount', 'foreign_amount', 'foreign_currency_id', 'category_name', 'budget_id', 'bill_id', 'interest_date', 'book_date', 'due_date', 'payment_date', 'invoice_date', 'external_url', 'internal_reference', 'external_id', 'notes', 'zoom_level', 'longitude', 'latitude'];++ // source and destination are overruled in some cases:if (i > 0) {diff.type = this.transactionType.toLowerCase();- if ('Deposit' === this.transactionType || 'Transfer' === this.transactionType) {+ if ('deposit' === this.transactionType.toLowerCase() || 'transfer' === this.transactionType.toLowerCase()) {// set destination to be whatever is in transaction zero:currentTransaction.destination_account_name = this.originalTransactions[0].destination_account_name;currentTransaction.destination_account_id = this.originalTransactions[0].destination_account_id;}- if ('Withdrawal' === this.transactionType || 'Transfer' === this.transactionType) {++ if ('withdrawal' === this.transactionType.toLowerCase() || 'transfer' === this.transactionType.toLowerCase()) {+ // set source to be whatever is in transaction zero:currentTransaction.source_account_name = this.originalTransactions[0].source_account_name;currentTransaction.source_account_id = this.originalTransactions[0].source_account_id;}- // console.log('Will overrule accounts for split ' + i);}+ // loop the basic fields and verifyfor (let ii in basicFields) {if (basicFields.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {let fieldName = basicFields[ii];@@ -519,13 +535,7 @@ export default {continue;}-- // console.log('Index ' + i + ': Field ' + fieldName + ' updated ("' + originalTransaction[fieldName] + '" > "' + currentTransaction[fieldName] + '")');- // console.log(originalTransaction[fieldName]);- // console.log(currentTransaction[fieldName]);-// some field names may need to be different. little basic but it works:- // console.log('pre: ' + submissionFieldName);if ('source_account_id' === submissionFieldName) {submissionFieldName = 'source_id';}@@ -539,26 +549,19 @@ export default {submissionFieldName = 'destination_name';}-+ // otherwise save them and remember them for submission:diff[submissionFieldName] = currentTransaction[fieldName];shouldSubmit = true;}}}- if (0 !== currentTransaction.piggy_bank_id) {- diff.piggy_bank_id = currentTransaction.piggy_bank_id;- shouldSubmit = true;- }- if (JSON.stringify(currentTransaction.tags) !== JSON.stringify(originalTransaction.tags)) {- // console.log('tags are different');- // console.log(currentTransaction.tags);- // console.log(originalTransaction.tags);- diff.tags = [];//currentTransaction.tags;+ // tags different?+ if (JSON.stringify(currentTransaction.tags) !== JSON.stringify(originalTransaction.tags)) {+ diff.tags = [];if (0 !== currentTransaction.tags.length) {for (let ii in currentTransaction.tags) {if (currentTransaction.tags.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {- // array.tagslet currentTag = currentTransaction.tags[ii];if (typeof currentTag === 'object' && null !== currentTag) {diff.tags.push(currentTag.text);@@ -569,79 +572,258 @@ export default {}}}-shouldSubmit = true;}// compare links:let newLinks = this.compareLinks(currentTransaction.links);let originalLinks = this.compareLinks(originalTransaction.links);- // console.log('links are?');- // console.log(newLinks);- // console.log(originalLinks);if (newLinks !== originalLinks) {- // console.log('links are different!');- // console.log(newLinks);- // console.log(originalLinks);shouldLinks = true;}- // this.transactions[i].selectedAttachments- // console.log(typeof currentTransaction.selectedAttachments);- // console.log(currentTransaction.selectedAttachments);if (typeof currentTransaction.selectedAttachments !== 'undefined' && true === currentTransaction.selectedAttachments) {- // must upload!shouldUpload = true;}- if (- this.date !== this.originalDate- ) {- // console.log('Date and/or time is changed');- // set date and time!+ if (this.date !== this.originalDate) {shouldSubmit = true;diff.date = this.date;}- // console.log('Now at index ' + i);- // console.log(Object.keys(diff).length);+if (Object.keys(diff).length === 0 && newTransactionCount > 1) {- // console.log('Will submit just the ID!');+ // Will submit just the ID!diff.transaction_journal_id = originalTransaction.transaction_journal_id;submission.transactions.push(lodashClonedeep(diff));shouldSubmit = true;} else if (Object.keys(diff).length !== 0) {+ // will submit all:diff.transaction_journal_id = originalTransaction.transaction_journal_id ?? 0;submission.transactions.push(lodashClonedeep(diff));shouldSubmit = true;}}}+ this.submitUpdate(submission, shouldSubmit, shouldLinks, shouldUpload);+ },++ submitData: function (shouldSubmit, submission) {+ //console.log('submitData');+ if (!shouldSubmit) {+ //console.log('No need!');+ return new Promise((resolve) => {+ resolve({});+ });+ }+ const url = './api/v1/transactions/' + this.groupId;+ return axios.put(url, submission);- // console.log('submitTransaction');- // console.log('shouldUpload : ' + shouldUpload);- // console.log('shouldLinks : ' + shouldLinks);- // console.log('shouldSubmit : ' + shouldSubmit);- if (shouldSubmit) {- this.submitUpdate(submission, shouldLinks, shouldUpload);+ },+ handleSubmissionResponse: function (response) {+ //console.log('handleSubmissionResponse()');+ // report the transaction is submitted.+ this.submittedTransaction = true;+ let journals = [];++ // meanwhile, store the ID and the title in some easy to access variables.+ if (typeof response.data !== 'undefined') {+ this.returnedGroupId = parseInt(response.data.data.id) ?? null;+ this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;++ let result = response.data.data.attributes.transactions+ for (let i in result) {+ if (result.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ journals.push(parseInt(result[i].transaction_journal_id));+ }+ }+ } else {+ for (let i in this.transactions) {+ if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ journals.push(this.transactions[i].transaction_journal_id);+ }+ }}+ journals = journals.reverse();+ return new Promise((resolve) => {+ resolve(+ {+ journals: journals,+ }+ );+ });+ },+ submitLinks: function (shouldSubmit) {+ //console.log('submitLinks()');if (!shouldSubmit) {- this.submittedTransaction = true;+ //console.log('no need!');+ return new Promise((resolve) => {+ resolve({});+ });}- if (!shouldLinks) {- this.submittedLinks = true;+ return this.deleteAllOriginalLinks().then(() => this.submitNewLinks());+ },+ submitAttachments: function (shouldSubmit, response) {+ //console.log('submitAttachments');+ if (!shouldSubmit) {+ //console.log('no need!');+ return new Promise((resolve) => {+ resolve({});+ });}- if (!shouldUpload) {- this.submittedAttachments = true;+ //console.log('Do upload thing!');+ //console.log(response);+ let anyAttachments = false;+ for (let i in this.transactions) {+ if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ let transaction = this.transactions[i];+ let journalId = transaction.transaction_journal_id;+ //console.log(journalId);+ if (typeof response !== 'undefined') {+ journalId = response.journals[i]+ }++ let hasAttachments = transaction.selectedAttachments;+ this.transactions[i].transaction_journal_id = journalId;+ this.transactions[i].uploadTrigger = true;+ //console.log('Decided that ' + journalId);+ //console.log('upload index ' + i);+ //console.log(hasAttachments);+ if (hasAttachments) {+ anyAttachments = true;+ }+ }}- if (!shouldSubmit && shouldLinks) {- this.submitTransactionLinks();+ if (true === anyAttachments) {+ this.submittedAttachments = 0;+ }+ },+ finaliseSubmission: function () {+ //console.log('finaliseSubmission');+ if (0 === this.submittedAttachments) {+ return;+ }+ //console.log('continue (' + this.submittedAttachments + ')');+ if (true === this.stayHere && false === this.inError) {+ //console.log('no error + no changes + no redirect');+ // show message:+ this.errorMessage = '';+ this.warningMessage = '';+ this.successMessage = this.$t('firefly.transaction_updated_link', {ID: this.groupId, title: this.returnedGroupTitle});+ }+ // no error + changes + redirect+ if (false === this.stayHere && false === this.inError) {+ //console.log('no error + changes + redirect');+ window.location.href = (window.previousURL ?? '/') + '?transaction_group_id=' + this.groupId + '&message=updated';}- if (!shouldSubmit && shouldLinks) {- // TODO- //this.submittedAttachments();+ this.enableSubmit = true;+ this.submittedAttachments = -1;+ this.inError = false;++ for (let i in this.transactions) {+ if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ if (this.transactions.hasOwnProperty(i)) {+ this.transactions[i].clearTrigger = true;+ }+ }}- // console.log('Done with submit methd.');- //console.log(submission);+ },+ submitUpdate: function (submission, shouldSubmit, shouldLinks, shouldUpload) {+ //console.log('submitUpdate()');+ this.inError = false;++ this.submitData(shouldSubmit, submission)+ .then(this.handleSubmissionResponse) // error or OK+ .then(response => {+ return Promise.all([+ this.submitLinks(shouldLinks, response),+ this.submitAttachments(shouldUpload, response)]);+ }+ )+ .then(this.finaliseSubmission)+ .catch(this.handleSubmissionError);+++ // if (shouldLinks) {+ // promises.push(this.submitTransactionLinks())+ // }+ // if (!shouldLinks) {+ // promises.push(new Promise((resolve) => {+ // resolve({});+ // }));+ // }+ // if (shouldUpload) {+ // console.log('Attachments = Respond to promise from shouldSubmit/!shouldSubmit');+ // promises.push(submissionPromise.then(result => this.uploadAttachments(result)));+ // }+ // if (!shouldUpload) {+ // promises.push(new Promise((resolve) => {+ // resolve({});+ // }));+ // }++ // all promises fulfilled:+ // console.log('All promises done, process results?');+ // Promise.all(promises).then(function (responses) {+ // console.log('I believe all ' + promises.length + ' promises fulfilled!');+ // }).catch(function (errors) {+ // console.log('Somebody errored?');+ // });++ //+ //+ //+ // if (shouldSubmit) {+ // console.log('shouldSubmit');+ // // do submission:+ // // console.log(JSON.stringify(submission));+ // // console.log(submission);+ // axios.put(url, submission)+ // .then(response => {+ // // console.log('Response is OK!');+ // // report the transaction is submitted.+ // this.submittedTransaction = true;+ //+ // // submit links and attachments (can only be done when the transaction is created)+ // if (shouldLinks) {+ // console.log('Submit links using return from server:');+ // this.submitTransactionLinks();+ // }+ // if (shouldUpload) {+ // // console.log('Need to upload.');+ // this.submitAttachments(response.data.data.attributes.transactions);+ // }+ // // meanwhile, store the ID and the title in some easy to access variables.+ // this.returnedGroupId = parseInt(response.data.data.id);+ // this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;+ // }+ // )+ // .catch(error => {+ // console.log('error :(');+ // console.log(error.response.data);+ // // oh noes Firefly III has something to bitch about.+ // this.enableSubmit = true;+ // // report the transaction is submitted.+ // this.submittedTransaction = true;+ // // // also report attachments and links are submitted:+ // this.submittedAttachments = true;+ // this.submittedLinks = true;+ // //+ // // but report an error because error:+ // this.inError = true;+ // this.parseErrors(error.response.data);+ // }+ // );+ // }+ // if (!shouldSubmit && shouldLinks) {+ // // update links+ // console.log('Submit links using whatever is here:');+ // this.submitTransactionLinks();+ // }+ // if (!shouldSubmit && shouldUpload) {+ // // upload+ // // console.log('Need to upload.');+ // this.submitAttachments(this.transactions);+ // }},compareLinks: function (array) {let compare = [];@@ -659,55 +841,26 @@ export default {);}}- // console.log('compareLinks');- // console.log(compare);return JSON.stringify(compare);},- submitUpdate: function (submission, shouldLinks, shouldUpload) {- // console.log('submitUpdate');- this.inError = false;- const url = './api/v1/transactions/' + this.groupId;- // console.log(JSON.stringify(submission));- // console.log(submission);- axios.put(url, submission)- .then(response => {- // console.log('Response is OK!');- // report the transaction is submitted.- this.submittedTransaction = true;-- // submit links and attachments (can only be done when the transaction is created)- if (shouldLinks) {- // console.log('Need to update links.');- this.submitTransactionLinks();- }- if (!shouldLinks) {- // console.log('No need to update links.');- }- // TODO attachments:- // this.submitAttachments(data, response);- //- // // meanwhile, store the ID and the title in some easy to access variables.- this.returnedGroupId = parseInt(response.data.data.id);- this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;- }- )- .catch(error => {- console.log('error :(');- console.log(error.response.data);- // oh noes Firefly III has something to bitch about.- this.enableSubmit = true;- // report the transaction is submitted.- this.submittedTransaction = true;- // // also report attachments and links are submitted:- this.submittedAttachments = true;- this.submittedLinks = true;- //- // but report an error because error:- this.inError = true;- this.parseErrors(error.response.data);- }- );+ uploadAttachments: function (result) {+ //console.log('TODO, upload attachments.');+ if (0 === Object.keys(result).length) {++ for (let i in this.transactions) {+ if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {++ //console.log('updateField(' + i + ', transaction_journal_id, ' + result[i].transaction_journal_id + ')');+ this.updateField({index: i, field: 'transaction_journal_id', value: result[i].transaction_journal_id});+ }+ }+ //console.log('Transactions not changed, use original objects.');+ } else {+ //console.log('Transactions changed!');+ }+ this.submittedAttachments = true;},+parseErrors: function (errors) {for (let i in this.transactions) {if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {@@ -800,83 +953,78 @@ export default {},deleteOriginalLinks: function (transaction) {- // console.log(transaction.links);+ let promises = [];for (let i in transaction.links) {if (transaction.links.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {let current = transaction.links[i];let url = '/api/v1/transaction_links/' + current.id;- axios.delete(url).then(response => {- // TODO response- });+ promises.push(axios.delete(url));}}+ return Promise.all(promises);},- /**- * Submit transaction links.- * TODO same method as CREATE- */- submitTransactionLinks() {- let total = 0;+ deleteAllOriginalLinks: function () {+ //console.log('deleteAllOriginalLinks()');+ // loop to delete old transaction links.let promises = [];-- // console.log('submitTransactionLinks()');for (let i in this.transactions) {if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {// original transaction present?let currentTransaction = this.transactions[i];let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};- // compare links:let newLinks = this.compareLinks(currentTransaction.links);let originalLinks = this.compareLinks(originalTransaction.links);if (newLinks !== originalLinks) {if ('[]' !== originalLinks) {- this.deleteOriginalLinks(originalTransaction);+ promises.push(this.deleteOriginalLinks(originalTransaction));}-- // console.log('links are different!');- // console.log(newLinks);- // console.log(originalLinks);- for (let ii in currentTransaction.links) {- if (currentTransaction.links.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {- let currentLink = currentTransaction.links[ii];- let linkObject = {- inward_id: currentTransaction.transaction_journal_id,- outward_id: currentTransaction.transaction_journal_id,- link_type_id: 'something'- };-- let parts = currentLink.link_type_id.split('-');- linkObject.link_type_id = parts[0];- if ('inward' === parts[1]) {- linkObject.inward_id = currentLink.transaction_journal_id;- }- if ('outward' === parts[1]) {- linkObject.outward_id = currentLink.transaction_journal_id;- }-- // console.log(linkObject);- total++;- // submit transaction link:- promises.push(axios.post('./api/v1/transaction_links', linkObject).then(response => {- // TODO error handling.- }));+ } else {+ promises.push(new Promise((resolve) => {+ resolve({});+ }));+ }+ }+ }+ return Promise.all(promises);+ },+ submitNewLinks: function () {+ //console.log('submitNewLinks()');+ let promises = [];+ for (let i in this.transactions) {+ if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ let currentTransaction = this.transactions[i];+ for (let ii in currentTransaction.links) {+ if (currentTransaction.links.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {+ let currentLink = currentTransaction.links[ii];+ let linkObject = {+ inward_id: currentTransaction.transaction_journal_id,+ outward_id: currentTransaction.transaction_journal_id,+ link_type_id: 'something'+ };++ let parts = currentLink.link_type_id.split('-');+ linkObject.link_type_id = parts[0];+ if ('inward' === parts[1]) {+ linkObject.inward_id = currentLink.transaction_journal_id;}+ if ('outward' === parts[1]) {+ linkObject.outward_id = currentLink.transaction_journal_id;+ }+ promises.push(axios.post('./api/v1/transaction_links', linkObject));}- // shouldLinks = true;}-}}- if (0 === total) {- this.submittedLinks = true;- return;- }- Promise.all(promises).then(function () {- this.submittedLinks = true;- });+ return Promise.all(promises);+ },+ /**+ * Submit transaction links.+ */+ submitTransactionLinksX: function () {+ //return this.deleteAllOriginalLinks().then(() => this.submitNewLinks());},- finalizeSubmit: function () {+ finalizeSubmitX: function () {// console.log('now in finalizeSubmit()');// console.log('submittedTransaction : ' + this.submittedTransaction);// console.log('submittedLinks : ' + this.submittedLinks);diff --git a/frontend/src/components/transactions/SplitForm.vue b/frontend/src/components/transactions/SplitForm.vueindex f6e6921cae..ccf30266d0 100644--- a/frontend/src/components/transactions/SplitForm.vue+++ b/frontend/src/components/transactions/SplitForm.vue@@ -267,8 +267,9 @@v-on="$listeners":custom-fields.sync="customFields":index="index"- :submitted_transaction="submittedTransaction":transaction_journal_id="transaction.transaction_journal_id"+ :upload-trigger="transaction.uploadTrigger"+ :clear-trigger="transaction.clearTrigger"/><TransactionLocationv-model="transaction.location"@@ -347,11 +348,6 @@ export default {type: String,required: true},- submittedTransaction: {- type: Boolean,- required: false,- default: false- }, // need to know if transaction is submitted.sourceAllowedTypes: {type: Array,required: false,@@ -381,21 +377,24 @@ export default {return this.date;},sourceAccount: function () {- // console.log('computed::sourceAccount');+ //console.log('computed::sourceAccount(' + this.index + ')');let value = {id: this.transaction.source_account_id,name: this.transaction.source_account_name,type: this.transaction.source_account_type,};- // console.log(JSON.stringify(value));+ //console.log(JSON.stringify(value));return value;},destinationAccount: function () {- return {+ //console.log('computed::destinationAccount(' + this.index + ')');+ let value = {id: this.transaction.destination_account_id,name: this.transaction.destination_account_name,type: this.transaction.destination_account_type,};+ //console.log(JSON.stringify(value));+ return value;},hasMetaFields: function () {let requiredFields = [diff --git a/frontend/src/components/transactions/TransactionAccount.vue b/frontend/src/components/transactions/TransactionAccount.vueindex 404bc852fe..eedd9a5267 100644--- a/frontend/src/components/transactions/TransactionAccount.vue+++ b/frontend/src/components/transactions/TransactionAccount.vue@@ -23,7 +23,7 @@<div v-if="visible" class="text-xs d-none d-lg-block d-xl-block"><span v-if="0 === this.index">{{ $t('firefly.' + this.direction + '_account') }}</span><span v-if="this.index > 0" class="text-warning">{{ $t('firefly.first_split_overrules_' + this.direction) }}</span>- <!-- <br><span>{{ selectedAccount }}</span> -->+ <br><span>{{ selectedAccount }}</span></div><div v-if="!visible" class="text-xs d-none d-lg-block d-xl-block"> @@ -127,8 +127,8 @@ export default {this.selectedAccount = event;},systemReturnedAccount: function (event) {- // console.log('systemReturnedAccount!');- // console.log('To prevent invalid propogation, set selectedAccountTrigger = false');+ //console.log('systemReturnedAccount!');+ //console.log('To prevent invalid propogation, set selectedAccountTrigger = false');this.selectedAccountTrigger = false;this.selectedAccount = event;},@@ -192,7 +192,7 @@ export default {* @param value*/selectedAccount: function (value) {- // console.log('TransactionAccount::watch selectedAccount()');+ //console.log('TransactionAccount::watch selectedAccount()');// console.log(value);if (true === this.selectedAccountTrigger) {// console.log('$emit alles!');@@ -208,9 +208,18 @@ export default {currency_symbol: value.currency_symbol,});- // console.log('watch::selectedAccount() will now set accountName because selectedAccountTrigger = true');+ //console.log('watch::selectedAccount() will now set accountName because selectedAccountTrigger = true');this.accountName = value.name;}+ if (false === this.selectedAccountTrigger) {+ //console.log('watch::selectedAccount() will NOT set accountName because selectedAccountTrigger = false');+ }+ if (false === this.selectedAccountTrigger && this.accountName !== value.name && null !== value.name) {+ //console.log('watch::selectedAccount() will set accountName. selectedAccountTrigger = false but name is different ("' + this.accountName + '" > "' + value.name + '")');+ this.selectedAccountTrigger = true;+ this.accountName = value.name;+ }+},accountName: function (value) {// console.log('now at watch accountName("' + value + '")');@@ -238,7 +247,7 @@ export default {this.selectedAccountTrigger = false;},value: function (value) {- // console.log('TransactionAccount::watch value(' + JSON.stringify(value) + ')');+ //console.log('TransactionAccount(' + this.index + ')::watch value(' + JSON.stringify(value) + ')');this.systemReturnedAccount(value);// // console.log('Index ' + this.index + ' nwAct: ', value);diff --git a/frontend/src/components/transactions/TransactionAttachments.vue b/frontend/src/components/transactions/TransactionAttachments.vueindex 566242ce43..2116a9e136 100644--- a/frontend/src/components/transactions/TransactionAttachments.vue+++ b/frontend/src/components/transactions/TransactionAttachments.vue@@ -39,27 +39,29 @@<script>export default {name: "TransactionAttachments",- props: ['transaction_journal_id', 'customFields'],+ props: ['transaction_journal_id', 'customFields', 'index', 'uploadTrigger', 'clearTrigger'],data() {return {- availableFields: this.customFields+ availableFields: this.customFields,+ uploads: 0,+ created: 0,+ uploaded: 0,}},watch: {customFields: function (value) {this.availableFields = value;},+ uploadTrigger: function () {+ //console.log('uploadTrigger(' + this.transaction_journal_id + ',' + this.index + ')');+ this.doUpload();+ },+ clearTrigger: function () {+ //console.log('clearTrigger(' + this.transaction_journal_id + ',' + this.index + ')');+ this.$refs.att.value = null;+ },transaction_journal_id: function (value) {- if (!this.showField) {- // console.log('Field is hidden. Emit event!');- this.$emit('uploaded-attachments', value);- return;- }- // console.log('transaction_journal_id changed to ' + value);- // do upload!- if (0 !== value) {- this.doUpload();- }+ //console.log('watch transaction_journal_id: ' + value + ' (index ' + this.index + ')');}},computed: {@@ -71,47 +73,65 @@ export default {}},methods: {- selectedFile: function() {- this.$emit('selected-attachments', this.transaction_journal_id);+ selectedFile: function () {+ this.$emit('selected-attachments', {index: this.index, id: this.transaction_journal_id});+ },+ createAttachment: function (name) {+ // console.log('Now in createAttachment()');+ const uri = './api/v1/attachments';+ const data = {+ filename: name,+ attachable_type: 'TransactionJournal',+ attachable_id: this.transaction_journal_id,+ };+ // create new attachment:+ return axios.post(uri, data);+ },+ uploadAttachment: function (attachmentId, data) {+ this.created++;+ // console.log('Now in uploadAttachment()');+ const uploadUri = './api/v1/attachments/' + attachmentId + '/upload';+ return axios.post(uploadUri, data)+ },+ countAttachment: function () {+ this.uploaded++;+ //console.log('Uploaded ' + this.uploaded + ' / ' + this.uploads);+ if (this.uploaded >= this.uploads) {+ //console.log('All files uploaded. Emit event for ' + this.transaction_journal_id + '(' + this.index + ')');+ this.$emit('uploaded-attachments', this.transaction_journal_id);+ }},doUpload: function () {- // console.log('Now in doUpload() for ' + this.$refs.att.files.length + ' files.');- for (let i in this.$refs.att.files) {- if (this.$refs.att.files.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {- let current = this.$refs.att.files[i];+ let files = this.$refs.att.files;+ this.uploads = files.length;+ // loop all files and create attachments.+ for (let i in files) {+ if (files.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {+ // console.log('Now at file ' + (parseInt(i) + 1) + ' / ' + files.length);+ // read file into file reader:+ let current = files[i];let fileReader = new FileReader();let theParent = this; // dont ask me why i need to do this.- fileReader.onloadend = function (evt) {+ fileReader.onloadend = evt => {if (evt.target.readyState === FileReader.DONE) {- // do upload here- const uri = './api/v1/attachments';- const data = {- filename: current.name,- attachable_type: 'TransactionJournal',- attachable_id: theParent.transaction_journal_id,- };- // create new attachment:- axios.post(uri, data).then(response => {- // upload actual file:- const uploadUri = './api/v1/attachments/' + response.data.data.id + '/upload';- axios- .post(uploadUri, new Blob([evt.target.result]))- .then(attachmentResponse => {- // TODO feedback etc.- // console.log('Uploaded a file. Emit event!');- // console.log(attachmentResponse);- theParent.$emit('uploaded-attachments', this.transaction_journal_id);- });- });+ // console.log('I am done reading file ' + (parseInt(i) + 1));+ this.createAttachment(current.name).then(response => {+ // console.log('Created attachment. Now upload (1)');+ return theParent.uploadAttachment(response.data.data.id, new Blob([evt.target.result]));+ }).then(theParent.countAttachment);}}fileReader.readAsArrayBuffer(current);}}- if (0 === this.$refs.att.files.length) {- // console.log('No files to upload. Emit event!');+ if (0 === files.length) {+ //console.log('No files to upload. Emit event!');this.$emit('uploaded-attachments', this.transaction_journal_id);}+ // Promise.all(promises).then(response => {+ // console.log('All files uploaded. Emit event!');+ // this.$emit('uploaded-attachments', this.transaction_journal_id);+ // });}}diff --git a/frontend/src/components/transactions/TransactionDate.vue b/frontend/src/components/transactions/TransactionDate.vueindex 7677bfd1f8..1c2385e395 100644--- a/frontend/src/components/transactions/TransactionDate.vue+++ b/frontend/src/components/transactions/TransactionDate.vue@@ -19,7 +19,7 @@--><template>- <div class="form-group">+ <div class="form-group" v-if="0===index"><div class="text-xs d-none d-lg-block d-xl-block">{{ $t('firefly.date_and_time') }}</div>@@ -28,7 +28,6 @@ref="date"v-model="dateStr":class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"- :disabled="index > 0":placeholder="dateStr":title="$t('firefly.date')"autocomplete="off"@@ -39,7 +38,6 @@ref="time"v-model="timeStr":class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"- :disabled="index > 0":placeholder="timeStr":title="$t('firefly.time')"autocomplete="off"