diff --git a/frontend/src/components/transactions/Split.vue b/frontend/src/components/transactions/Split.vue index c224df3a38..c5d78872b3 100644 --- a/frontend/src/components/transactions/Split.vue +++ b/frontend/src/components/transactions/Split.vue @@ -42,12 +42,19 @@ :has-submission-error="hasSubmissionErrors.description" :disabled-input="disabledInput" :description="transaction.description" - @update:description="updateDescription"/> + @update:description="updateDescription" + />
- +
- +
@@ -268,15 +274,21 @@ diff --git a/frontend/src/components/transactions/form/SourceAccount.vue b/frontend/src/components/transactions/form/SourceAccount.vue index 83e91dcbd8..e8cbce81b0 100644 --- a/frontend/src/components/transactions/form/SourceAccount.vue +++ b/frontend/src/components/transactions/form/SourceAccount.vue @@ -27,6 +27,7 @@ dense :loading="loading" outlined + new-value-mode="add-unique" :disable="disabledInput" :error="hasSubmissionError" :label="$t('firefly.source_account')" @@ -44,7 +45,7 @@ {{ scope.opt.label }} - {{ scope.opt.description }} + {{ scope.opt.type }} @@ -87,7 +88,8 @@ export default { }, transactionType: { type: String, - required: false + required: false, + default: 'unknown' }, disabledInput: { type: Boolean, @@ -105,16 +107,18 @@ export default { } }, mounted() { - console.log('Mounted'); - //this.options.value = this.stringOptions this.getAccounts(''); + this.model = this.name; + }, methods: { getAccounts: function (query) { this.loading = true; - console.log('getAccounts("'+query+'")'); // default set of account types, will later be set by the transaction type. let types = 'Asset account,Revenue account,Loan,Debt,Mortgage'; + if('deposit' === this.transactionType) { + console.log('NOW DEPOSIT'); + } (new Accounts).get(types, query).then(response => { this.stringOptions = []; for (let i in response.data) { @@ -122,46 +126,31 @@ export default { let current = { label: entry.name, value: entry.id, - description: entry.type + type: entry.type } this.stringOptions.push(current); } //this.stringOptions = response.data.data; - this.options = this.stringOptions; + this.options = this.stringOptions; this.loading = false; - console.log('getAccounts done!'); }); }, filterFn(val, update, abort) { - console.log('filterFn(' + val + ')'); - if (val === '') { - update(() => { - this.getAccounts(''); - //this.options = stringOptions - - // here you have access to "ref" which - // is the Vue reference of the QSelect - }) - return - } update(() => { this.getAccounts(val); - //const needle = val.toLowerCase() - //this.options = this.options.filter(v => v.label.toLowerCase().indexOf(needle) > -1) }) - // console.log('filterFn(' + val + ')'); - // if (this.loading) { - // console.log('return'); - // return - // } - // const needle = val.toLowerCase() - // this.options = this.stringOptions.filter(v => v.label.toLowerCase().indexOf(needle) > -1); + } + }, + watch: { + model: { + handler: function (newVal) { + if(newVal !== undefined) { + this.$emit('update:source', newVal); + } + }, + deep: true } } } - - diff --git a/frontend/src/pages/transactions/Create.vue b/frontend/src/pages/transactions/Create.vue index 23a89b2147..cfd7bdb62f 100644 --- a/frontend/src/pages/transactions/Create.vue +++ b/frontend/src/pages/transactions/Create.vue @@ -59,6 +59,7 @@ 0) { @@ -196,10 +199,9 @@ export default { }, updateTransaction: function (obj) { const index = obj.index; - const transaction = obj.transaction; - console.log('Update transaction ' + index); - console.log(transaction); - this.transactions[index] = transaction; + this.transactions[index] = obj.transaction; + // TODO needs to update all splits if necessary and warn user about it. + this.transactionType = (new CalculateType()).calculateType(this.transactions[0].source, this.transactions[0].destination); }, processSuccess: function (response) { console.log('process success'); diff --git a/frontend/src/support/transactions/calculate-type.js b/frontend/src/support/transactions/calculate-type.js new file mode 100644 index 0000000000..7fbd2f7d15 --- /dev/null +++ b/frontend/src/support/transactions/calculate-type.js @@ -0,0 +1,69 @@ +/* + * calculate-type.js + * Copyright (c) 2023 james@firefly-iii.org + * + * This file is part of Firefly III (https://github.com/firefly-iii). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +export default class CalculateType { + calculateType(source, destination) { + const srcEmpty = this.empty(source); + const dstEmpty = this.empty(destination); + // both are null or '' + if (srcEmpty && dstEmpty) { + return 'unknown'; + } + + // source has data, dest has not + if (typeof source === 'object' && null !== source && dstEmpty) { + if (source.type === 'Asset account' || source.type === 'Loan' || source.type === 'Debt' || source.type === 'Mortgage') { + return 'withdrawal'; + } + if (source.type === 'Revenue account') { + return 'deposit'; + } + } + // dst has data, source has not + if (typeof destination === 'object' && null !== destination && srcEmpty) { + if (destination.type === 'Asset account') { + return 'deposit'; + } + } + // both have data: + if (!srcEmpty && !dstEmpty) { + if (source.type === 'Asset account' && destination.type === 'Expense account') { + return 'withdrawal'; + } + if (source.type === destination.type) { + return 'transfer'; + } + } + + console.error('Cannot handle'); + console.log(source); + console.log(destination); + } + + empty(value) { + if (null === value || '' === value) { + return true; + } + if (null !== value && typeof value === 'object') { + return false; + } + return true; + } +}