mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Various fixes for v2 issues in 5.5.7
This commit is contained in:
parent
dcd123a9ec
commit
9b0b80d1d4
@ -40,6 +40,7 @@
|
|||||||
:transaction="transaction"
|
:transaction="transaction"
|
||||||
:transaction-type="transactionType"
|
:transaction-type="transactionType"
|
||||||
v-on:uploaded-attachments="uploadedAttachment($event)"
|
v-on:uploaded-attachments="uploadedAttachment($event)"
|
||||||
|
v-on:selected-attachments="selectedAttachment($event)"
|
||||||
v-on:set-marker-location="storeLocation($event)"
|
v-on:set-marker-location="storeLocation($event)"
|
||||||
v-on:set-account="storeAccountValue($event)"
|
v-on:set-account="storeAccountValue($event)"
|
||||||
v-on:set-date="storeDate($event)"
|
v-on:set-date="storeDate($event)"
|
||||||
@ -166,7 +167,7 @@ export default {
|
|||||||
// things the process is done working on (3 phases):
|
// things the process is done working on (3 phases):
|
||||||
submittedTransaction: false,
|
submittedTransaction: false,
|
||||||
submittedLinks: false,
|
submittedLinks: false,
|
||||||
submittedAttachments: false,
|
submittedAttachments: -1, // -1 (no attachments), 0 = uploading, 1 = uploaded
|
||||||
|
|
||||||
// transaction was actually submitted?
|
// transaction was actually submitted?
|
||||||
inError: false,
|
inError: false,
|
||||||
@ -201,14 +202,10 @@ export default {
|
|||||||
...mapGetters('root', ['listPageSize'])
|
...mapGetters('root', ['listPageSize'])
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
submittedTransaction: function () {
|
|
||||||
this.finalizeSubmit();
|
|
||||||
},
|
|
||||||
submittedLinks: function () {
|
|
||||||
this.finalizeSubmit();
|
|
||||||
},
|
|
||||||
submittedAttachments: function () {
|
submittedAttachments: function () {
|
||||||
this.finalizeSubmit();
|
// console.log('Watch submittedAttachments');
|
||||||
|
|
||||||
|
this.finaliseSubmission();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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
|
* and creating links. Only once all three steps are executed may the message be shown or the user be
|
||||||
* forwarded.
|
* forwarded.
|
||||||
*/
|
*/
|
||||||
finalizeSubmit() {
|
finalizeSubmitXX() {
|
||||||
// console.log('finalizeSubmit (' + this.submittedTransaction + ', ' + this.submittedAttachments + ', ' + this.submittedLinks + ')');
|
// console.log('finalizeSubmit (' + this.submittedTransaction + ', ' + this.submittedAttachments + ', ' + this.submittedLinks + ')');
|
||||||
if (this.submittedTransaction && this.submittedAttachments && this.submittedLinks) {
|
if (this.submittedTransaction && this.submittedAttachments && this.submittedLinks) {
|
||||||
// console.log('all true');
|
// console.log('all true');
|
||||||
@ -265,7 +262,7 @@ export default {
|
|||||||
this.enableSubmit = true;
|
this.enableSubmit = true;
|
||||||
this.submittedTransaction = false;
|
this.submittedTransaction = false;
|
||||||
this.submittedLinks = false;
|
this.submittedLinks = false;
|
||||||
this.submittedAttachments = false;
|
//this.submittedAttachments = false;
|
||||||
this.inError = false;
|
this.inError = false;
|
||||||
|
|
||||||
|
|
||||||
@ -273,8 +270,7 @@ export default {
|
|||||||
for (let i in this.transactions) {
|
for (let i in this.transactions) {
|
||||||
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
||||||
if (this.transactions.hasOwnProperty(i)) {
|
if (this.transactions.hasOwnProperty(i)) {
|
||||||
// console.log('Reset attachment #' + i);
|
this.updateField({index: i, field: 'clearTrigger', value: true});
|
||||||
this.updateField({index: i, field: 'transaction_journal_id', value: 0});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,6 +287,148 @@ export default {
|
|||||||
}
|
}
|
||||||
// console.log('Did nothing in finalizeSubmit');
|
// 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
|
* 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.
|
* need to happen in the right order.
|
||||||
@ -305,40 +443,50 @@ export default {
|
|||||||
const url = './api/v1/transactions';
|
const url = './api/v1/transactions';
|
||||||
const data = this.convertData();
|
const data = this.convertData();
|
||||||
|
|
||||||
// console.log('Will submit:');
|
this.submitData(url, data)
|
||||||
// console.log(data);
|
.then(this.handleSubmissionResponse)
|
||||||
|
|
||||||
// POST the transaction.
|
|
||||||
axios.post(url, data)
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// console.log('Response is OK!');
|
return Promise.all([this.submitLinks(response, data), this.submitAttachments(response, data)]);
|
||||||
// report the transaction is submitted.
|
}
|
||||||
this.submittedTransaction = true;
|
)
|
||||||
|
.then(this.finaliseSubmission)
|
||||||
|
.catch(this.handleSubmissionError);
|
||||||
|
|
||||||
// submit links and attachments (can only be done when the transaction is created)
|
// // console.log('Will submit:');
|
||||||
this.submitTransactionLinks(data, response);
|
// // console.log(data);
|
||||||
this.submitAttachments(data, response);
|
//
|
||||||
|
// // POST the transaction.
|
||||||
// meanwhile, store the ID and the title in some easy to access variables.
|
// axios.post(url, data)
|
||||||
this.returnedGroupId = parseInt(response.data.data.id);
|
// .then(response => {
|
||||||
this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;
|
// // console.log('Response is OK!');
|
||||||
// console.log('Group title is now "' + this.groupTitle + '"');
|
// // report the transaction is submitted.
|
||||||
})
|
// this.submittedTransaction = true;
|
||||||
.catch(error => {
|
//
|
||||||
// oh noes Firefly III has something to bitch about.
|
// // submit links and attachments (can only be done when the transaction is created)
|
||||||
this.enableSubmit = true;
|
// this.submitTransactionLinks(data, response);
|
||||||
// console.log('enable submit = true');
|
// this.submitAttachments(data, response);
|
||||||
// report the transaction is submitted.
|
//
|
||||||
this.submittedTransaction = true;
|
// // meanwhile, store the ID and the title in some easy to access variables.
|
||||||
// also report attachments and links are submitted:
|
// this.returnedGroupId = parseInt(response.data.data.id);
|
||||||
this.submittedAttachments = true;
|
// this.returnedGroupTitle = null === response.data.data.attributes.group_title ? response.data.data.attributes.transactions[0].description : response.data.data.attributes.group_title;
|
||||||
this.submittedLinks = true;
|
// // console.log('Group title is now "' + this.groupTitle + '"');
|
||||||
|
// })
|
||||||
// but report an error because error:
|
// .catch(error => {
|
||||||
this.inError = true;
|
// // oh noes Firefly III has something to bitch about.
|
||||||
this.parseErrors(error.response.data);
|
// 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
|
* Submitting transactions means we will give each TransactionAttachment component
|
||||||
@ -348,7 +496,7 @@ export default {
|
|||||||
*
|
*
|
||||||
* The ID is set via the store.
|
* The ID is set via the store.
|
||||||
*/
|
*/
|
||||||
submitAttachments: function (data, response) {
|
submitAttachmentsX: function (data, response) {
|
||||||
// console.log('submitAttachments()');
|
// console.log('submitAttachments()');
|
||||||
let result = response.data.data.attributes.transactions
|
let result = response.data.data.attributes.transactions
|
||||||
for (let i in data.transactions) {
|
for (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
|
* 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
|
* 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.
|
* Once the number of components matches the number of splits we know all attachments have been uploaded.
|
||||||
*/
|
*/
|
||||||
uploadedAttachment: function (journalId) {
|
uploadedAttachment: function (journalId) {
|
||||||
|
this.submittedAttachments = 0;
|
||||||
// console.log('Triggered uploadedAttachment(' + journalId + ')');
|
// console.log('Triggered uploadedAttachment(' + journalId + ')');
|
||||||
let key = 'str' + journalId;
|
let key = 'str' + journalId;
|
||||||
this.submittedAttCount[key] = 1;
|
this.submittedAttCount[key] = 1;
|
||||||
@ -375,11 +525,12 @@ export default {
|
|||||||
// console.log('Count is now ' + count);
|
// console.log('Count is now ' + count);
|
||||||
// console.log('Length is ' + this.transactions.length);
|
// console.log('Length is ' + this.transactions.length);
|
||||||
if (count === this.transactions.length) {
|
if (count === this.transactions.length) {
|
||||||
// mark the attachments as stored:
|
|
||||||
this.submittedAttachments = true;
|
|
||||||
// console.log('Got them all!');
|
// console.log('Got them all!');
|
||||||
|
// mark the attachments as stored:
|
||||||
|
this.submittedAttachments = 1;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
,
|
||||||
/**
|
/**
|
||||||
* Responds to changed location.
|
* Responds to changed location.
|
||||||
*/
|
*/
|
||||||
@ -458,11 +609,13 @@ export default {
|
|||||||
this.submittedLinks = true;
|
this.submittedLinks = true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
parseErrors: function (errors) {
|
parseErrors: function (errors) {
|
||||||
for (let i in this.transactions) {
|
for (let i in this.transactions) {
|
||||||
this.resetErrors({index: i});
|
if (this.transactions.hasOwnProperty(i)) {
|
||||||
|
this.resetErrors({index: i});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.successMessage = '';
|
this.successMessage = '';
|
||||||
this.errorMessage = this.$t('firefly.errors_submission');
|
this.errorMessage = this.$t('firefly.errors_submission');
|
||||||
if (typeof errors.errors === 'undefined') {
|
if (typeof errors.errors === 'undefined') {
|
||||||
@ -471,12 +624,6 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let payload;
|
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 transactionIndex;
|
||||||
let fieldName;
|
let fieldName;
|
||||||
|
|
||||||
@ -701,6 +848,7 @@ export default {
|
|||||||
// from thing:
|
// from thing:
|
||||||
order: 0,
|
order: 0,
|
||||||
reconciled: false,
|
reconciled: false,
|
||||||
|
attachments: array.attachments,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (0 !== array.tags.length) {
|
if (0 !== array.tags.length) {
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<Alert :message="errorMessage" type="danger"/>
|
<Alert :message="errorMessage" type="danger"/>
|
||||||
<Alert :message="successMessage" type="success"/>
|
<Alert :message="successMessage" type="success"/>
|
||||||
<Alert :message="warningMessage" type="warning"/>
|
<Alert :message="warningMessage" type="warning"/>
|
||||||
|
|
||||||
<form @submit="submitTransaction" autocomplete="off">
|
<form @submit="submitTransaction" autocomplete="off">
|
||||||
<SplitPills :transactions="transactions"/>
|
<SplitPills :transactions="transactions"/>
|
||||||
|
|
||||||
@ -40,7 +41,6 @@
|
|||||||
:destination-allowed-types="destinationAllowedTypes"
|
:destination-allowed-types="destinationAllowedTypes"
|
||||||
:source-allowed-types="sourceAllowedTypes"
|
:source-allowed-types="sourceAllowedTypes"
|
||||||
:allow-switch="false"
|
:allow-switch="false"
|
||||||
:submitted-transaction="submittedTransaction"
|
|
||||||
v-on:uploaded-attachments="uploadedAttachment($event)"
|
v-on:uploaded-attachments="uploadedAttachment($event)"
|
||||||
v-on:set-marker-location="storeLocation($event)"
|
v-on:set-marker-location="storeLocation($event)"
|
||||||
v-on:set-account="storeAccountValue($event)"
|
v-on:set-account="storeAccountValue($event)"
|
||||||
@ -74,7 +74,8 @@
|
|||||||
<div class="text-xs d-none d-lg-block d-xl-block">
|
<div class="text-xs d-none d-lg-block d-xl-block">
|
||||||
|
|
||||||
</div>
|
</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>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@ -109,12 +110,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const lodashClonedeep = require('lodash.clonedeep');
|
import {mapMutations} from "vuex";
|
||||||
import Alert from '../partials/Alert';
|
import Alert from '../partials/Alert';
|
||||||
import SplitPills from "./SplitPills";
|
import SplitPills from "./SplitPills";
|
||||||
import SplitForm from "./SplitForm";
|
import SplitForm from "./SplitForm";
|
||||||
import TransactionGroupTitle from "./TransactionGroupTitle";
|
import TransactionGroupTitle from "./TransactionGroupTitle";
|
||||||
import {getDefaultErrors, getDefaultTransaction, toW3CString} from '../../shared/transactions';
|
import {getDefaultErrors, getDefaultTransaction} from '../../shared/transactions';
|
||||||
|
|
||||||
|
const lodashClonedeep = require('lodash.clonedeep');
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Edit",
|
name: "Edit",
|
||||||
@ -156,10 +159,15 @@ export default {
|
|||||||
|
|
||||||
// things the process is done working on (3 phases):
|
// things the process is done working on (3 phases):
|
||||||
submittedTransaction: false,
|
submittedTransaction: false,
|
||||||
submittedLinks: false,
|
// submittedLinks: false,
|
||||||
submittedAttachments: false,
|
submittedAttachments: -1, // -1 = no attachments, 0 = uploading, 1 = uploaded
|
||||||
inError: false,
|
inError: 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 accounts
|
// meta data for accounts
|
||||||
allowedOpposingTypes: {},
|
allowedOpposingTypes: {},
|
||||||
destinationAllowedTypes: [],
|
destinationAllowedTypes: [],
|
||||||
@ -179,21 +187,13 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
submittedTransaction: function () {
|
|
||||||
// see finalizeSubmit()
|
|
||||||
this.finalizeSubmit();
|
|
||||||
},
|
|
||||||
submittedLinks: function () {
|
|
||||||
// see finalizeSubmit()
|
|
||||||
this.finalizeSubmit();
|
|
||||||
},
|
|
||||||
submittedAttachments: function () {
|
submittedAttachments: function () {
|
||||||
// see finalizeSubmit()
|
this.finaliseSubmission();
|
||||||
this.finalizeSubmit();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapMutations('transactions/create', ['updateField',]),
|
||||||
/**
|
/**
|
||||||
* Grap transaction group from URL and submit GET.
|
* Grap transaction group from URL and submit GET.
|
||||||
*/
|
*/
|
||||||
@ -203,8 +203,8 @@ export default {
|
|||||||
this.parseTransactionGroup(response.data);
|
this.parseTransactionGroup(response.data);
|
||||||
}
|
}
|
||||||
).catch(error => {
|
).catch(error => {
|
||||||
// console.log('I failed :(');
|
console.log('I failed :(');
|
||||||
// console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -219,6 +219,10 @@ export default {
|
|||||||
this.groupTitle = attributes.group_title;
|
this.groupTitle = attributes.group_title;
|
||||||
this.originalGroupTitle = 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) {
|
for (let i in transactions) {
|
||||||
if (transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
if (transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
||||||
let result = this.parseTransaction(parseInt(i), transactions[i]);
|
let result = this.parseTransaction(parseInt(i), transactions[i]);
|
||||||
@ -239,6 +243,8 @@ export default {
|
|||||||
//console.log('index: ' + index);
|
//console.log('index: ' + index);
|
||||||
if (0 === index) {
|
if (0 === index) {
|
||||||
this.transactionType = array.type.charAt(0).toUpperCase() + array.type.slice(1);
|
this.transactionType = array.type.charAt(0).toUpperCase() + array.type.slice(1);
|
||||||
|
|
||||||
|
// TODO here you may need to catch stuff like loan/debt/mortgage
|
||||||
this.sourceAllowedTypes = [array.source_type];
|
this.sourceAllowedTypes = [array.source_type];
|
||||||
this.destinationAllowedTypes = [array.destination_type];
|
this.destinationAllowedTypes = [array.destination_type];
|
||||||
this.date = array.date.substring(0, 16);
|
this.date = array.date.substring(0, 16);
|
||||||
@ -292,7 +298,6 @@ export default {
|
|||||||
result.zoom_level = array.zoom_level;
|
result.zoom_level = array.zoom_level;
|
||||||
result.longitude = array.longitude;
|
result.longitude = array.longitude;
|
||||||
result.latitude = array.latitude;
|
result.latitude = array.latitude;
|
||||||
|
|
||||||
// error handling
|
// error handling
|
||||||
result.errors = getDefaultErrors();
|
result.errors = getDefaultErrors();
|
||||||
return result;
|
return result;
|
||||||
@ -370,14 +375,12 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* TODO same method as Create
|
|
||||||
* Get API value.
|
* Get API value.
|
||||||
*/
|
*/
|
||||||
getAllowedOpposingTypes: function () {
|
getAllowedOpposingTypes: function () {
|
||||||
axios.get('./api/v1/configuration/firefly.allowed_opposing_types')
|
axios.get('./api/v1/configuration/firefly.allowed_opposing_types')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.allowedOpposingTypes = response.data.data.value;
|
this.allowedOpposingTypes = response.data.data.value;
|
||||||
// console.log('Set allowedOpposingTypes');
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -389,8 +392,20 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
uploadedAttachment: function (payload) {
|
uploadedAttachment: function (payload) {
|
||||||
// console.log('event: uploadedAttachment');
|
//console.log('event: uploadedAttachment');
|
||||||
// console.log(payload);
|
//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) {
|
storeLocation: function (payload) {
|
||||||
this.transactions[payload.index].zoom_level = payload.zoomLevel;
|
this.transactions[payload.index].zoom_level = payload.zoomLevel;
|
||||||
@ -405,26 +420,25 @@ export default {
|
|||||||
this.transactions[index][direction + '_account_name'] = payload.name;
|
this.transactions[index][direction + '_account_name'] = payload.name;
|
||||||
},
|
},
|
||||||
storeDate: function (payload) {
|
storeDate: function (payload) {
|
||||||
// console.log('event: storeDate');
|
|
||||||
// console.log(payload);
|
|
||||||
this.date = payload.date;
|
this.date = payload.date;
|
||||||
},
|
},
|
||||||
storeTime: function (payload) {
|
|
||||||
this.time = payload.time;
|
|
||||||
// console.log('event: storeTime');
|
|
||||||
// console.log(payload);
|
|
||||||
},
|
|
||||||
storeField: function (payload) {
|
storeField: function (payload) {
|
||||||
let field = payload.field;
|
let field = payload.field;
|
||||||
if ('category' === field) {
|
if ('category' === field) {
|
||||||
field = 'category_name';
|
field = 'category_name';
|
||||||
}
|
}
|
||||||
// console.log('event: storeField(' + field + ')');
|
|
||||||
this.transactions[payload.index][field] = payload.value;
|
this.transactions[payload.index][field] = payload.value;
|
||||||
|
|
||||||
},
|
},
|
||||||
removeTransaction: function (payload) {
|
removeTransaction: function (payload) {
|
||||||
|
//console.log('removeTransaction()');
|
||||||
|
//console.log(payload);
|
||||||
|
//console.log('length: ' + this.transactions.length);
|
||||||
this.transactions.splice(payload.index, 1);
|
this.transactions.splice(payload.index, 1);
|
||||||
|
//console.log('length: ' + this.transactions.length);
|
||||||
|
|
||||||
|
|
||||||
|
//this.originalTransactions.splice(payload.index, 1);
|
||||||
// this kills the original transactions.
|
// this kills the original transactions.
|
||||||
this.originalTransactions = [];
|
this.originalTransactions = [];
|
||||||
},
|
},
|
||||||
@ -432,9 +446,12 @@ export default {
|
|||||||
this.groupTitle = payload;
|
this.groupTitle = payload;
|
||||||
},
|
},
|
||||||
selectedAttachments: function (payload) {
|
selectedAttachments: function (payload) {
|
||||||
|
//console.log('Now in selectedAttachments()');
|
||||||
for (let i in this.transactions) {
|
for (let i in this.transactions) {
|
||||||
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
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);
|
// console.log('selectedAttachments ' + payload);
|
||||||
this.transactions[i].selectedAttachments = true;
|
this.transactions[i].selectedAttachments = true;
|
||||||
}
|
}
|
||||||
@ -450,56 +467,55 @@ export default {
|
|||||||
submitTransaction: function (event) {
|
submitTransaction: function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let submission = {transactions: []};
|
let submission = {transactions: []};
|
||||||
|
|
||||||
|
// parse data to see if we should submit anything at all:
|
||||||
let shouldSubmit = false;
|
let shouldSubmit = false;
|
||||||
let shouldLinks = false;
|
let shouldLinks = false;
|
||||||
let shouldUpload = false;
|
let shouldUpload = false;
|
||||||
|
|
||||||
|
// if the group title has changed, should submit:
|
||||||
if (this.groupTitle !== this.originalGroupTitle) {
|
if (this.groupTitle !== this.originalGroupTitle) {
|
||||||
submission.group_title = this.groupTitle;
|
submission.group_title = this.groupTitle;
|
||||||
shouldSubmit = true;
|
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)) {
|
if (newTransactionCount > 1 && typeof submission.group_title === 'undefined' && (null === this.originalGroupTitle || '' === this.originalGroupTitle)) {
|
||||||
submission.group_title = this.transactions[0].description;
|
submission.group_title = this.transactions[0].description;
|
||||||
|
shouldSubmit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loop each transaction (edited by the user):
|
||||||
for (let i in this.transactions) {
|
for (let i in this.transactions) {
|
||||||
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
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 currentTransaction = this.transactions[i];
|
||||||
let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};
|
let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};
|
||||||
|
// the difference:
|
||||||
let diff = {};
|
let diff = {};
|
||||||
|
|
||||||
// compare basic fields:
|
// compare basic fields:
|
||||||
let basicFields = [
|
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'];
|
||||||
'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:
|
// source and destination are overruled in some cases:
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
diff.type = this.transactionType.toLowerCase();
|
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:
|
// set destination to be whatever is in transaction zero:
|
||||||
currentTransaction.destination_account_name = this.originalTransactions[0].destination_account_name;
|
currentTransaction.destination_account_name = this.originalTransactions[0].destination_account_name;
|
||||||
currentTransaction.destination_account_id = this.originalTransactions[0].destination_account_id;
|
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_name = this.originalTransactions[0].source_account_name;
|
||||||
currentTransaction.source_account_id = this.originalTransactions[0].source_account_id;
|
currentTransaction.source_account_id = this.originalTransactions[0].source_account_id;
|
||||||
}
|
}
|
||||||
// console.log('Will overrule accounts for split ' + i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loop the basic fields and verify
|
||||||
for (let ii in basicFields) {
|
for (let ii in basicFields) {
|
||||||
if (basicFields.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {
|
if (basicFields.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {
|
||||||
let fieldName = basicFields[ii];
|
let fieldName = basicFields[ii];
|
||||||
@ -519,13 +535,7 @@ export default {
|
|||||||
continue;
|
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:
|
// some field names may need to be different. little basic but it works:
|
||||||
// console.log('pre: ' + submissionFieldName);
|
|
||||||
if ('source_account_id' === submissionFieldName) {
|
if ('source_account_id' === submissionFieldName) {
|
||||||
submissionFieldName = 'source_id';
|
submissionFieldName = 'source_id';
|
||||||
}
|
}
|
||||||
@ -539,26 +549,19 @@ export default {
|
|||||||
submissionFieldName = 'destination_name';
|
submissionFieldName = 'destination_name';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// otherwise save them and remember them for submission:
|
||||||
diff[submissionFieldName] = currentTransaction[fieldName];
|
diff[submissionFieldName] = currentTransaction[fieldName];
|
||||||
shouldSubmit = true;
|
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) {
|
if (0 !== currentTransaction.tags.length) {
|
||||||
for (let ii in currentTransaction.tags) {
|
for (let ii in currentTransaction.tags) {
|
||||||
if (currentTransaction.tags.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {
|
if (currentTransaction.tags.hasOwnProperty(ii) && /^0$|^[1-9]\d*$/.test(ii) && ii <= 4294967294) {
|
||||||
// array.tags
|
|
||||||
let currentTag = currentTransaction.tags[ii];
|
let currentTag = currentTransaction.tags[ii];
|
||||||
if (typeof currentTag === 'object' && null !== currentTag) {
|
if (typeof currentTag === 'object' && null !== currentTag) {
|
||||||
diff.tags.push(currentTag.text);
|
diff.tags.push(currentTag.text);
|
||||||
@ -569,79 +572,258 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldSubmit = true;
|
shouldSubmit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compare links:
|
// compare links:
|
||||||
let newLinks = this.compareLinks(currentTransaction.links);
|
let newLinks = this.compareLinks(currentTransaction.links);
|
||||||
let originalLinks = this.compareLinks(originalTransaction.links);
|
let originalLinks = this.compareLinks(originalTransaction.links);
|
||||||
// console.log('links are?');
|
|
||||||
// console.log(newLinks);
|
|
||||||
// console.log(originalLinks);
|
|
||||||
if (newLinks !== originalLinks) {
|
if (newLinks !== originalLinks) {
|
||||||
// console.log('links are different!');
|
|
||||||
// console.log(newLinks);
|
|
||||||
// console.log(originalLinks);
|
|
||||||
shouldLinks = true;
|
shouldLinks = true;
|
||||||
}
|
}
|
||||||
// this.transactions[i].selectedAttachments
|
|
||||||
// console.log(typeof currentTransaction.selectedAttachments);
|
|
||||||
// console.log(currentTransaction.selectedAttachments);
|
|
||||||
if (typeof currentTransaction.selectedAttachments !== 'undefined' && true === currentTransaction.selectedAttachments) {
|
if (typeof currentTransaction.selectedAttachments !== 'undefined' && true === currentTransaction.selectedAttachments) {
|
||||||
// must upload!
|
|
||||||
shouldUpload = true;
|
shouldUpload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (this.date !== this.originalDate) {
|
||||||
this.date !== this.originalDate
|
|
||||||
) {
|
|
||||||
// console.log('Date and/or time is changed');
|
|
||||||
// set date and time!
|
|
||||||
shouldSubmit = true;
|
shouldSubmit = true;
|
||||||
diff.date = this.date;
|
diff.date = this.date;
|
||||||
}
|
}
|
||||||
// console.log('Now at index ' + i);
|
|
||||||
// console.log(Object.keys(diff).length);
|
|
||||||
if (Object.keys(diff).length === 0 && newTransactionCount > 1) {
|
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;
|
diff.transaction_journal_id = originalTransaction.transaction_journal_id;
|
||||||
submission.transactions.push(lodashClonedeep(diff));
|
submission.transactions.push(lodashClonedeep(diff));
|
||||||
shouldSubmit = true;
|
shouldSubmit = true;
|
||||||
} else if (Object.keys(diff).length !== 0) {
|
} else if (Object.keys(diff).length !== 0) {
|
||||||
|
// will submit all:
|
||||||
diff.transaction_journal_id = originalTransaction.transaction_journal_id ?? 0;
|
diff.transaction_journal_id = originalTransaction.transaction_journal_id ?? 0;
|
||||||
submission.transactions.push(lodashClonedeep(diff));
|
submission.transactions.push(lodashClonedeep(diff));
|
||||||
shouldSubmit = true;
|
shouldSubmit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.submitUpdate(submission, shouldSubmit, shouldLinks, shouldUpload);
|
||||||
|
},
|
||||||
|
|
||||||
// console.log('submitTransaction');
|
submitData: function (shouldSubmit, submission) {
|
||||||
// console.log('shouldUpload : ' + shouldUpload);
|
//console.log('submitData');
|
||||||
// console.log('shouldLinks : ' + shouldLinks);
|
|
||||||
// console.log('shouldSubmit : ' + shouldSubmit);
|
|
||||||
if (shouldSubmit) {
|
|
||||||
this.submitUpdate(submission, shouldLinks, shouldUpload);
|
|
||||||
}
|
|
||||||
if (!shouldSubmit) {
|
if (!shouldSubmit) {
|
||||||
this.submittedTransaction = true;
|
//console.log('No need!');
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve({});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!shouldLinks) {
|
const url = './api/v1/transactions/' + this.groupId;
|
||||||
this.submittedLinks = true;
|
return axios.put(url, submission);
|
||||||
|
|
||||||
|
},
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!shouldUpload) {
|
journals = journals.reverse();
|
||||||
this.submittedAttachments = true;
|
return new Promise((resolve) => {
|
||||||
|
resolve(
|
||||||
|
{
|
||||||
|
journals: journals,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
submitLinks: function (shouldSubmit) {
|
||||||
|
//console.log('submitLinks()');
|
||||||
|
if (!shouldSubmit) {
|
||||||
|
//console.log('no need!');
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve({});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!shouldSubmit && shouldLinks) {
|
return this.deleteAllOriginalLinks().then(() => this.submitNewLinks());
|
||||||
this.submitTransactionLinks();
|
},
|
||||||
|
submitAttachments: function (shouldSubmit, response) {
|
||||||
|
//console.log('submitAttachments');
|
||||||
|
if (!shouldSubmit) {
|
||||||
|
//console.log('no need!');
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve({});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//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 (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) {
|
this.enableSubmit = true;
|
||||||
// TODO
|
this.submittedAttachments = -1;
|
||||||
//this.submittedAttachments();
|
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) {
|
compareLinks: function (array) {
|
||||||
let compare = [];
|
let compare = [];
|
||||||
@ -659,55 +841,26 @@ export default {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log('compareLinks');
|
|
||||||
// console.log(compare);
|
|
||||||
return JSON.stringify(compare);
|
return JSON.stringify(compare);
|
||||||
},
|
},
|
||||||
submitUpdate: function (submission, shouldLinks, shouldUpload) {
|
uploadAttachments: function (result) {
|
||||||
// console.log('submitUpdate');
|
//console.log('TODO, upload attachments.');
|
||||||
this.inError = false;
|
if (0 === Object.keys(result).length) {
|
||||||
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)
|
for (let i in this.transactions) {
|
||||||
if (shouldLinks) {
|
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
||||||
// console.log('Need to update links.');
|
|
||||||
this.submitTransactionLinks();
|
//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});
|
||||||
if (!shouldLinks) {
|
}
|
||||||
// console.log('No need to update links.');
|
}
|
||||||
}
|
//console.log('Transactions not changed, use original objects.');
|
||||||
// TODO attachments:
|
} else {
|
||||||
// this.submitAttachments(data, response);
|
//console.log('Transactions changed!');
|
||||||
//
|
}
|
||||||
// // meanwhile, store the ID and the title in some easy to access variables.
|
this.submittedAttachments = true;
|
||||||
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);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
parseErrors: function (errors) {
|
parseErrors: function (errors) {
|
||||||
for (let i in this.transactions) {
|
for (let i in this.transactions) {
|
||||||
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
||||||
@ -800,83 +953,78 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteOriginalLinks: function (transaction) {
|
deleteOriginalLinks: function (transaction) {
|
||||||
// console.log(transaction.links);
|
let promises = [];
|
||||||
for (let i in transaction.links) {
|
for (let i in transaction.links) {
|
||||||
if (transaction.links.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
if (transaction.links.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
||||||
let current = transaction.links[i];
|
let current = transaction.links[i];
|
||||||
let url = '/api/v1/transaction_links/' + current.id;
|
let url = '/api/v1/transaction_links/' + current.id;
|
||||||
axios.delete(url).then(response => {
|
promises.push(axios.delete(url));
|
||||||
// TODO response
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
deleteAllOriginalLinks: function () {
|
||||||
* Submit transaction links.
|
//console.log('deleteAllOriginalLinks()');
|
||||||
* TODO same method as CREATE
|
// loop to delete old transaction links.
|
||||||
*/
|
|
||||||
submitTransactionLinks() {
|
|
||||||
let total = 0;
|
|
||||||
let promises = [];
|
let promises = [];
|
||||||
|
|
||||||
// console.log('submitTransactionLinks()');
|
|
||||||
for (let i in this.transactions) {
|
for (let i in this.transactions) {
|
||||||
if (this.transactions.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
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 currentTransaction = this.transactions[i];
|
||||||
let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};
|
let originalTransaction = this.originalTransactions.hasOwnProperty(i) ? this.originalTransactions[i] : {};
|
||||||
// compare links:
|
|
||||||
let newLinks = this.compareLinks(currentTransaction.links);
|
let newLinks = this.compareLinks(currentTransaction.links);
|
||||||
let originalLinks = this.compareLinks(originalTransaction.links);
|
let originalLinks = this.compareLinks(originalTransaction.links);
|
||||||
if (newLinks !== originalLinks) {
|
if (newLinks !== originalLinks) {
|
||||||
if ('[]' !== originalLinks) {
|
if ('[]' !== originalLinks) {
|
||||||
this.deleteOriginalLinks(originalTransaction);
|
promises.push(this.deleteOriginalLinks(originalTransaction));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// console.log('links are different!');
|
promises.push(new Promise((resolve) => {
|
||||||
// console.log(newLinks);
|
resolve({});
|
||||||
// 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.
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// shouldLinks = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 === total) {
|
return Promise.all(promises);
|
||||||
this.submittedLinks = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Promise.all(promises).then(function () {
|
|
||||||
this.submittedLinks = true;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
finalizeSubmit: function () {
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.all(promises);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Submit transaction links.
|
||||||
|
*/
|
||||||
|
submitTransactionLinksX: function () {
|
||||||
|
//return this.deleteAllOriginalLinks().then(() => this.submitNewLinks());
|
||||||
|
},
|
||||||
|
finalizeSubmitX: function () {
|
||||||
// console.log('now in finalizeSubmit()');
|
// console.log('now in finalizeSubmit()');
|
||||||
// console.log('submittedTransaction : ' + this.submittedTransaction);
|
// console.log('submittedTransaction : ' + this.submittedTransaction);
|
||||||
// console.log('submittedLinks : ' + this.submittedLinks);
|
// console.log('submittedLinks : ' + this.submittedLinks);
|
||||||
|
@ -267,8 +267,9 @@
|
|||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
:custom-fields.sync="customFields"
|
:custom-fields.sync="customFields"
|
||||||
:index="index"
|
:index="index"
|
||||||
:submitted_transaction="submittedTransaction"
|
|
||||||
:transaction_journal_id="transaction.transaction_journal_id"
|
:transaction_journal_id="transaction.transaction_journal_id"
|
||||||
|
:upload-trigger="transaction.uploadTrigger"
|
||||||
|
:clear-trigger="transaction.clearTrigger"
|
||||||
/>
|
/>
|
||||||
<TransactionLocation
|
<TransactionLocation
|
||||||
v-model="transaction.location"
|
v-model="transaction.location"
|
||||||
@ -347,11 +348,6 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
submittedTransaction: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: false
|
|
||||||
}, // need to know if transaction is submitted.
|
|
||||||
sourceAllowedTypes: {
|
sourceAllowedTypes: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: false,
|
required: false,
|
||||||
@ -381,21 +377,24 @@ export default {
|
|||||||
return this.date;
|
return this.date;
|
||||||
},
|
},
|
||||||
sourceAccount: function () {
|
sourceAccount: function () {
|
||||||
// console.log('computed::sourceAccount');
|
//console.log('computed::sourceAccount(' + this.index + ')');
|
||||||
let value = {
|
let value = {
|
||||||
id: this.transaction.source_account_id,
|
id: this.transaction.source_account_id,
|
||||||
name: this.transaction.source_account_name,
|
name: this.transaction.source_account_name,
|
||||||
type: this.transaction.source_account_type,
|
type: this.transaction.source_account_type,
|
||||||
};
|
};
|
||||||
// console.log(JSON.stringify(value));
|
//console.log(JSON.stringify(value));
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
destinationAccount: function () {
|
destinationAccount: function () {
|
||||||
return {
|
//console.log('computed::destinationAccount(' + this.index + ')');
|
||||||
|
let value = {
|
||||||
id: this.transaction.destination_account_id,
|
id: this.transaction.destination_account_id,
|
||||||
name: this.transaction.destination_account_name,
|
name: this.transaction.destination_account_name,
|
||||||
type: this.transaction.destination_account_type,
|
type: this.transaction.destination_account_type,
|
||||||
};
|
};
|
||||||
|
//console.log(JSON.stringify(value));
|
||||||
|
return value;
|
||||||
},
|
},
|
||||||
hasMetaFields: function () {
|
hasMetaFields: function () {
|
||||||
let requiredFields = [
|
let requiredFields = [
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<div v-if="visible" class="text-xs d-none d-lg-block d-xl-block">
|
<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="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>
|
<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>
|
||||||
<div v-if="!visible" class="text-xs d-none d-lg-block d-xl-block">
|
<div v-if="!visible" class="text-xs d-none d-lg-block d-xl-block">
|
||||||
|
|
||||||
@ -127,8 +127,8 @@ export default {
|
|||||||
this.selectedAccount = event;
|
this.selectedAccount = event;
|
||||||
},
|
},
|
||||||
systemReturnedAccount: function (event) {
|
systemReturnedAccount: function (event) {
|
||||||
// console.log('systemReturnedAccount!');
|
//console.log('systemReturnedAccount!');
|
||||||
// console.log('To prevent invalid propogation, set selectedAccountTrigger = false');
|
//console.log('To prevent invalid propogation, set selectedAccountTrigger = false');
|
||||||
this.selectedAccountTrigger = false;
|
this.selectedAccountTrigger = false;
|
||||||
this.selectedAccount = event;
|
this.selectedAccount = event;
|
||||||
},
|
},
|
||||||
@ -192,7 +192,7 @@ export default {
|
|||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
selectedAccount: function (value) {
|
selectedAccount: function (value) {
|
||||||
// console.log('TransactionAccount::watch selectedAccount()');
|
//console.log('TransactionAccount::watch selectedAccount()');
|
||||||
// console.log(value);
|
// console.log(value);
|
||||||
if (true === this.selectedAccountTrigger) {
|
if (true === this.selectedAccountTrigger) {
|
||||||
// console.log('$emit alles!');
|
// console.log('$emit alles!');
|
||||||
@ -208,9 +208,18 @@ export default {
|
|||||||
currency_symbol: value.currency_symbol,
|
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;
|
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) {
|
accountName: function (value) {
|
||||||
// console.log('now at watch accountName("' + value + '")');
|
// console.log('now at watch accountName("' + value + '")');
|
||||||
@ -238,7 +247,7 @@ export default {
|
|||||||
this.selectedAccountTrigger = false;
|
this.selectedAccountTrigger = false;
|
||||||
},
|
},
|
||||||
value: function (value) {
|
value: function (value) {
|
||||||
// console.log('TransactionAccount::watch value(' + JSON.stringify(value) + ')');
|
//console.log('TransactionAccount(' + this.index + ')::watch value(' + JSON.stringify(value) + ')');
|
||||||
this.systemReturnedAccount(value);
|
this.systemReturnedAccount(value);
|
||||||
|
|
||||||
// // console.log('Index ' + this.index + ' nwAct: ', value);
|
// // console.log('Index ' + this.index + ' nwAct: ', value);
|
||||||
|
@ -39,27 +39,29 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: "TransactionAttachments",
|
name: "TransactionAttachments",
|
||||||
props: ['transaction_journal_id', 'customFields'],
|
props: ['transaction_journal_id', 'customFields', 'index', 'uploadTrigger', 'clearTrigger'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
availableFields: this.customFields
|
availableFields: this.customFields,
|
||||||
|
uploads: 0,
|
||||||
|
created: 0,
|
||||||
|
uploaded: 0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
customFields: function (value) {
|
customFields: function (value) {
|
||||||
this.availableFields = 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) {
|
transaction_journal_id: function (value) {
|
||||||
if (!this.showField) {
|
//console.log('watch transaction_journal_id: ' + value + ' (index ' + this.index + ')');
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -71,47 +73,65 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectedFile: function() {
|
selectedFile: function () {
|
||||||
this.$emit('selected-attachments', this.transaction_journal_id);
|
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 () {
|
doUpload: function () {
|
||||||
// console.log('Now in doUpload() for ' + this.$refs.att.files.length + ' files.');
|
let files = this.$refs.att.files;
|
||||||
for (let i in this.$refs.att.files) {
|
this.uploads = files.length;
|
||||||
if (this.$refs.att.files.hasOwnProperty(i) && /^0$|^[1-9]\d*$/.test(i) && i <= 4294967294) {
|
// loop all files and create attachments.
|
||||||
let current = this.$refs.att.files[i];
|
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 fileReader = new FileReader();
|
||||||
let theParent = this; // dont ask me why i need to do this.
|
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) {
|
if (evt.target.readyState === FileReader.DONE) {
|
||||||
// do upload here
|
// console.log('I am done reading file ' + (parseInt(i) + 1));
|
||||||
const uri = './api/v1/attachments';
|
this.createAttachment(current.name).then(response => {
|
||||||
const data = {
|
// console.log('Created attachment. Now upload (1)');
|
||||||
filename: current.name,
|
return theParent.uploadAttachment(response.data.data.id, new Blob([evt.target.result]));
|
||||||
attachable_type: 'TransactionJournal',
|
}).then(theParent.countAttachment);
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileReader.readAsArrayBuffer(current);
|
fileReader.readAsArrayBuffer(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 === this.$refs.att.files.length) {
|
if (0 === files.length) {
|
||||||
// console.log('No files to upload. Emit event!');
|
//console.log('No files to upload. Emit event!');
|
||||||
this.$emit('uploaded-attachments', this.transaction_journal_id);
|
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);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<template>
|
<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">
|
<div class="text-xs d-none d-lg-block d-xl-block">
|
||||||
{{ $t('firefly.date_and_time') }}
|
{{ $t('firefly.date_and_time') }}
|
||||||
</div>
|
</div>
|
||||||
@ -28,7 +28,6 @@
|
|||||||
ref="date"
|
ref="date"
|
||||||
v-model="dateStr"
|
v-model="dateStr"
|
||||||
:class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"
|
:class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"
|
||||||
:disabled="index > 0"
|
|
||||||
:placeholder="dateStr"
|
:placeholder="dateStr"
|
||||||
:title="$t('firefly.date')"
|
:title="$t('firefly.date')"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
@ -39,7 +38,6 @@
|
|||||||
ref="time"
|
ref="time"
|
||||||
v-model="timeStr"
|
v-model="timeStr"
|
||||||
:class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"
|
:class="errors.length > 0 ? 'form-control is-invalid' : 'form-control'"
|
||||||
:disabled="index > 0"
|
|
||||||
:placeholder="timeStr"
|
:placeholder="timeStr"
|
||||||
:title="$t('firefly.time')"
|
:title="$t('firefly.time')"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
|
Loading…
Reference in New Issue
Block a user