This commit is contained in:
James Cole
2019-11-09 15:30:52 +01:00
parent 16a4adcd07
commit 9332808d7f
3 changed files with 44 additions and 14 deletions

2
public/v1/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -22,10 +22,9 @@
<div class="form-group" v-bind:class="{ 'has-error': hasError()}"> <div class="form-group" v-bind:class="{ 'has-error': hasError()}">
<label class="col-sm-4 control-label" ref="cur"></label> <label class="col-sm-4 control-label" ref="cur"></label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="number" ref="amount" :value="value" @input="handleInput" step="any" <input type="number" @input="handleInput" ref="amount" :value="value" step="any" class="form-control"
class="form-control"
name="amount[]" name="amount[]"
title="amount" autocomplete="off" v-bind:placeholder="$t('firefly.amount')"> title="$t('firefly.amount')" autocomplete="off" v-bind:placeholder="$t('firefly.amount')">
<ul class="list-unstyled" v-for="error in this.error"> <ul class="list-unstyled" v-for="error in this.error">
<li class="text-danger">{{ error }}</li> <li class="text-danger">{{ error }}</li>
</ul> </ul>

View File

@@ -19,7 +19,11 @@
--> -->
<template> <template>
<div class="form-group" v-bind:class="{ 'has-error': hasError()}" v-if="null == this.transactionType || null != this.transactionType && (this.enabledCurrencies.length > 2 && this.transactionType === 'Deposit') || this.transactionType.toLowerCase() === 'transfer'"> <div class="form-group" v-bind:class="{ 'has-error': hasError()}" v-if="
null == this.transactionType ||
null != this.transactionType && (this.enabledCurrencies.length > 2 && (this.transactionType.toLowerCase() === 'deposit' || this.transactionType.toLowerCase() === 'withdrawal')) ||
this.liability ||
(null != this.transactionType && this.transactionType.toLowerCase() === 'transfer')">
<div class="col-sm-4"> <div class="col-sm-4">
<select class="form-control" ref="currency_select" name="foreign_currency[]" @input="handleInput"> <select class="form-control" ref="currency_select" name="foreign_currency[]" @input="handleInput">
<option <option
@@ -49,43 +53,68 @@
<script> <script>
export default { export default {
name: "ForeignAmountSelect", name: "ForeignAmountSelect",
props: ['source', 'destination', 'transactionType', 'value', 'error', 'no_currency', 'title'],
props: ['source', 'destination', 'transactionType', 'value', 'error', 'no_currency', 'title',],
mounted() { mounted() {
console.log('loadCurrencies()');
this.liability = false;
this.loadCurrencies(); this.loadCurrencies();
}, },
data() { data() {
return { return {
currencies: [], currencies: [],
enabledCurrencies: [], enabledCurrencies: [],
exclude: null exclude: null,
// liability overrules the drop down list if the source or dest is a liability
liability: false
} }
}, },
watch: { watch: {
source: function () { source: function () {
console.log('watch source in foreign currency');
this.changeData(); this.changeData();
}, },
destination: function () { destination: function () {
console.log('watch destination in foreign currency');
this.changeData(); this.changeData();
}, },
transactionType: function () { transactionType: function () {
console.log('watch transaction type in foreign currency');
this.changeData(); this.changeData();
} }
}, },
methods: { methods: {
hasError: function () { hasError: function () {
console.log('Has error');
return this.error.length > 0; return this.error.length > 0;
}, },
handleInput(e) { handleInput(e) {
this.$emit('input', { console.log('handleInput');
amount: +this.$refs.amount.value, let obj = {
amount: this.$refs.amount.value,
currency_id: this.$refs.currency_select.value, currency_id: this.$refs.currency_select.value,
} };
console.log(obj);
this.$emit('input', obj
); );
}, },
changeData: function () { changeData: function () {
console.log('Now in changeData()');
this.enabledCurrencies = []; this.enabledCurrencies = [];
if (this.transactionType === 'Transfer') { let destType = this.destination.type ? this.destination.type.toLowerCase() : 'invalid';
// lock source on currencyID of destination let srcType = this.source.type ? this.source.type.toLowerCase() : 'invalid';
let tType =this.transactionType ? this.transactionType.toLowerCase() : 'invalid';
let liabilities = ['loan','debt','mortgage'];
let sourceIsLiability = liabilities.indexOf(srcType) !== -1;
let destIsLiability = liabilities.indexOf(destType) !== -1;
console.log(srcType + ' (source) is a liability: ' + sourceIsLiability);
console.log(destType + ' (dest) is a liability: ' + destIsLiability);
if (tType === 'transfer' || destIsLiability || sourceIsLiability) {
console.log('Source is liability OR dest is liability, OR transfer. Lock list on currency of destination.');
this.liability = true;
// lock dropdown list on on currencyID of destination.
for (const key in this.currencies) { for (const key in this.currencies) {
if (this.currencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) { if (this.currencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
if (this.currencies[key].id === this.destination.currency_id) { if (this.currencies[key].id === this.destination.currency_id) {
@@ -96,8 +125,9 @@
console.log('Enabled currencies length is now ' + this.enabledCurrencies.length); console.log('Enabled currencies length is now ' + this.enabledCurrencies.length);
return; return;
} }
// if type is withdrawal, list all but skip the source account ID. // if type is withdrawal, list all but skip the source account ID.
if (this.transactionType === 'Withdrawal' && this.source) { if (tType === 'withdrawal' && this.source && false === sourceIsLiability) {
for (const key in this.currencies) { for (const key in this.currencies) {
if (this.currencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) { if (this.currencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
if (this.source.currency_id !== this.currencies[key].id) { if (this.source.currency_id !== this.currencies[key].id) {
@@ -109,7 +139,7 @@
} }
// if type is deposit, list all but skip the source account ID. // if type is deposit, list all but skip the source account ID.
if (this.transactionType === 'Deposit' && this.destination) { if (tType === 'deposit' && this.destination) {
for (const key in this.currencies) { for (const key in this.currencies) {
if (this.currencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) { if (this.currencies.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
if (this.destination.currency_id !== this.currencies[key].id) { if (this.destination.currency_id !== this.currencies[key].id) {
@@ -126,6 +156,7 @@
} }
}, },
loadCurrencies: function () { loadCurrencies: function () {
console.log('loadCurrencies');
let URI = document.getElementsByTagName('base')[0].href + "json/currencies"; let URI = document.getElementsByTagName('base')[0].href + "json/currencies";
axios.get(URI, {}).then((res) => { axios.get(URI, {}).then((res) => {
this.currencies = [ this.currencies = [