2021-01-03 07:11:44 +01:00
|
|
|
<!--
|
|
|
|
|
- TransactionForeignCurrency.vue
|
|
|
|
|
- Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<!-- FOREIGN Currency -->
|
2021-02-22 18:43:26 +01:00
|
|
|
<div class="form-group" v-if="isVisible">
|
2021-01-03 07:11:44 +01:00
|
|
|
<div class="text-xs"> </div>
|
|
|
|
|
<div class="input-group">
|
2021-02-22 18:43:26 +01:00
|
|
|
<select name="foreign_currency_id[]" v-model="selectedCurrency" class="form-control">
|
2021-01-03 07:11:44 +01:00
|
|
|
<option v-for="currency in selectableCurrencies" :label="currency.name" :value="currency.id">{{ currency.name }}</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "TransactionForeignCurrency",
|
2021-02-22 18:43:26 +01:00
|
|
|
props: [
|
|
|
|
|
'index',
|
|
|
|
|
'transactionType',
|
|
|
|
|
'sourceCurrencyId',
|
|
|
|
|
'destinationCurrencyId',
|
|
|
|
|
'selectedCurrencyId'
|
|
|
|
|
],
|
2021-01-03 07:11:44 +01:00
|
|
|
data() {
|
|
|
|
|
return {
|
2021-02-22 18:43:26 +01:00
|
|
|
selectedCurrency: 0,
|
2021-01-03 07:11:44 +01:00
|
|
|
allCurrencies: [],
|
|
|
|
|
selectableCurrencies: [],
|
2021-02-22 18:43:26 +01:00
|
|
|
dstCurrencyId: this.destinationCurrencyId,
|
|
|
|
|
srcCurrencyId: this.sourceCurrencyId,
|
2021-01-03 07:11:44 +01:00
|
|
|
lockedCurrency: 0,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
2021-02-22 18:43:26 +01:00
|
|
|
sourceCurrencyId: function (value) {
|
|
|
|
|
this.srcCurrencyId = value;
|
2021-01-03 07:11:44 +01:00
|
|
|
},
|
2021-02-22 18:43:26 +01:00
|
|
|
destinationCurrencyId: function (value) {
|
|
|
|
|
this.dstCurrencyId = value;
|
2021-01-03 07:11:44 +01:00
|
|
|
},
|
2021-02-22 18:43:26 +01:00
|
|
|
selectedCurrency: function(value) {
|
2021-02-23 06:45:09 +01:00
|
|
|
this.$emit('set-field',{field: 'foreign_currency_id', index: this.index, value: value});
|
2021-02-22 18:43:26 +01:00
|
|
|
},
|
|
|
|
|
transactionType: function (value) {
|
2021-01-03 07:11:44 +01:00
|
|
|
this.lockedCurrency = 0;
|
2021-02-22 18:43:26 +01:00
|
|
|
if ('Transfer' === value) {
|
|
|
|
|
this.lockedCurrency = this.dstCurrencyId;
|
|
|
|
|
this.selectedCurrency = this.dstCurrencyId;
|
2021-01-03 07:11:44 +01:00
|
|
|
}
|
|
|
|
|
this.filterCurrencies();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
created: function () {
|
|
|
|
|
this.getAllCurrencies();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
getAllCurrencies: function () {
|
|
|
|
|
axios.get('./api/v1/autocomplete/currencies')
|
|
|
|
|
.then(response => {
|
|
|
|
|
this.allCurrencies = response.data;
|
|
|
|
|
this.filterCurrencies();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
filterCurrencies() {
|
|
|
|
|
// if a currency is locked only that currency can (and must) be selected:
|
|
|
|
|
if (0 !== this.lockedCurrency) {
|
|
|
|
|
for (let key in this.allCurrencies) {
|
|
|
|
|
if (this.allCurrencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
|
|
|
|
|
let current = this.allCurrencies[key];
|
|
|
|
|
if (current.id === this.lockedCurrency) {
|
|
|
|
|
this.selectableCurrencies = [current];
|
2021-02-22 18:43:26 +01:00
|
|
|
this.selectedCurrency = current.id;
|
2021-01-03 07:11:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.selectableCurrencies = [
|
|
|
|
|
{
|
|
|
|
|
"id": 0,
|
|
|
|
|
"name": this.$t('firefly.no_currency')
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
for (let key in this.allCurrencies) {
|
|
|
|
|
if (this.allCurrencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
|
|
|
|
|
let current = this.allCurrencies[key];
|
2021-02-22 18:43:26 +01:00
|
|
|
this.selectableCurrencies.push(current);
|
2021-01-03 07:11:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
2021-02-22 18:43:26 +01:00
|
|
|
isVisible: function () {
|
|
|
|
|
return !('Transfer' === this.transactionType && this.srcCurrencyId === this.dstCurrencyId);
|
|
|
|
|
}
|
2021-01-03 07:11:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
</style>
|