mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 19:16:51 +00:00
Expand currency options in transaction form.
This commit is contained in:
@@ -67,22 +67,31 @@ let transactions = function () {
|
|||||||
if (sourceType === destType && ['Asset account', 'Loan', 'Debt', 'Mortgage'].includes(sourceType)) {
|
if (sourceType === destType && ['Asset account', 'Loan', 'Debt', 'Mortgage'].includes(sourceType)) {
|
||||||
this.transactionType = 'transfer';
|
this.transactionType = 'transfer';
|
||||||
console.log('Transaction type is detected to be "' + this.transactionType + '".');
|
console.log('Transaction type is detected to be "' + this.transactionType + '".');
|
||||||
|
|
||||||
|
// this also locks the amount into the amount of the source account
|
||||||
|
// and the foreign amount (if different) in that of the destination account.
|
||||||
|
console.log('filter down currencies for transfer.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// withdrawals:
|
// withdrawals:
|
||||||
if ('Asset account' === sourceType && ['Expense account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
|
if ('Asset account' === sourceType && ['Expense account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
|
||||||
this.transactionType = 'withdrawal';
|
this.transactionType = 'withdrawal';
|
||||||
console.log('Transaction type is detected to be "' + this.transactionType + '".');
|
console.log('[a] Transaction type is detected to be "' + this.transactionType + '".');
|
||||||
|
this.filterNativeCurrencies(this.entries[0].source_account.currency_code);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ('Asset account' === sourceType && 'unknown' === destType) {
|
if ('Asset account' === sourceType && 'unknown' === destType) {
|
||||||
this.transactionType = 'withdrawal';
|
this.transactionType = 'withdrawal';
|
||||||
console.log('Transaction type is detected to be "' + this.transactionType + '".');
|
console.log('[b] Transaction type is detected to be "' + this.transactionType + '".');
|
||||||
|
console.log(this.entries[0].source_account);
|
||||||
|
this.filterNativeCurrencies(this.entries[0].source_account.currency_code);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Expense account' === destType) {
|
if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Expense account' === destType) {
|
||||||
this.transactionType = 'withdrawal';
|
this.transactionType = 'withdrawal';
|
||||||
console.log('Transaction type is detected to be "' + this.transactionType + '".');
|
console.log('[c] Transaction type is detected to be "' + this.transactionType + '".');
|
||||||
|
this.filterNativeCurrencies(this.entries[0].source_account.currency_code);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,9 +114,33 @@ let transactions = function () {
|
|||||||
{
|
{
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
alpine_name: item.name,
|
||||||
type: item.type,
|
type: item.type,
|
||||||
|
currency_code: item.currency_code,
|
||||||
};
|
};
|
||||||
console.log('Changed source account into a known ' + item.type.toLowerCase());
|
console.log('Changed source account into a known ' + item.type.toLowerCase());
|
||||||
|
document.querySelector('#form')._x_dataStack[0].detectTransactionType();
|
||||||
|
},
|
||||||
|
filterNativeCurrencies(code) {
|
||||||
|
console.log('filterNativeCurrencies("' + code + '")');
|
||||||
|
let list = [];
|
||||||
|
let currency;
|
||||||
|
for (let i in this.enabledCurrencies) {
|
||||||
|
if (this.enabledCurrencies.hasOwnProperty(i)) {
|
||||||
|
let current = this.enabledCurrencies[i];
|
||||||
|
if (current.code === code) {
|
||||||
|
currency = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.push(currency);
|
||||||
|
this.nativeCurrencies = list;
|
||||||
|
// this also forces the currency_code on ALL entries.
|
||||||
|
for(let i in this.entries) {
|
||||||
|
if(this.entries.hasOwnProperty(i)) {
|
||||||
|
this.entries[i].currency_code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
changedAmount(e) {
|
changedAmount(e) {
|
||||||
const index = parseInt(e.target.dataset.index);
|
const index = parseInt(e.target.dataset.index);
|
||||||
@@ -126,9 +159,12 @@ let transactions = function () {
|
|||||||
{
|
{
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
|
alpine_name: item.name,
|
||||||
type: item.type,
|
type: item.type,
|
||||||
|
currency_code: item.currency_code,
|
||||||
};
|
};
|
||||||
console.log('Changed destination account into a known ' + item.type.toLowerCase());
|
console.log('Changed destination account into a known ' + item.type.toLowerCase());
|
||||||
|
document.querySelector('#form')._x_dataStack[0].detectTransactionType();
|
||||||
},
|
},
|
||||||
loadCurrencies() {
|
loadCurrencies() {
|
||||||
console.log('Loading user currencies.');
|
console.log('Loading user currencies.');
|
||||||
@@ -138,10 +174,10 @@ let transactions = function () {
|
|||||||
};
|
};
|
||||||
let getter = new Get();
|
let getter = new Get();
|
||||||
getter.list({}).then((response) => {
|
getter.list({}).then((response) => {
|
||||||
for(let i in response.data.data) {
|
for (let i in response.data.data) {
|
||||||
if(response.data.data.hasOwnProperty(i)) {
|
if (response.data.data.hasOwnProperty(i)) {
|
||||||
let current = response.data.data[i];
|
let current = response.data.data[i];
|
||||||
if(current.attributes.enabled) {
|
if (current.attributes.enabled) {
|
||||||
let obj =
|
let obj =
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -153,10 +189,11 @@ let transactions = function () {
|
|||||||
decimal_places: current.attributes.decimal_places,
|
decimal_places: current.attributes.decimal_places,
|
||||||
|
|
||||||
};
|
};
|
||||||
if(obj.default) {
|
if (obj.default) {
|
||||||
this.defaultCurrency = obj;
|
this.defaultCurrency = obj;
|
||||||
}
|
}
|
||||||
this.enabledCurrencies.push(obj);
|
this.enabledCurrencies.push(obj);
|
||||||
|
this.nativeCurrencies.push(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,33 +202,43 @@ let transactions = function () {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
changeSourceAccount(item, ac) {
|
changeSourceAccount(item, ac) {
|
||||||
|
console.log('changeSourceAccount');
|
||||||
if (typeof item === 'undefined') {
|
if (typeof item === 'undefined') {
|
||||||
const index = parseInt(ac._searchInput.attributes['data-index'].value);
|
const index = parseInt(ac._searchInput.attributes['data-index'].value);
|
||||||
let source = document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account;
|
let source = document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account;
|
||||||
if (source.name === ac._searchInput.value) {
|
if (source.name === ac._searchInput.value) {
|
||||||
console.warn('Ignore hallucinated source account name change to "' + ac._searchInput.value + '"');
|
console.warn('Ignore hallucinated source account name change to "' + ac._searchInput.value + '"');
|
||||||
|
document.querySelector('#form')._x_dataStack[0].detectTransactionType();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account =
|
document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account =
|
||||||
{
|
{
|
||||||
name: ac._searchInput.value,
|
name: ac._searchInput.value,
|
||||||
|
alpine_name: ac._searchInput.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Changed source account into a unknown account called "' + ac._searchInput.value + '"');
|
console.log('Changed source account into a unknown account called "' + ac._searchInput.value + '"');
|
||||||
|
document.querySelector('#form')._x_dataStack[0].detectTransactionType();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeDestAccount(item, ac) {
|
changeDestAccount(item, ac) {
|
||||||
|
let destination = document.querySelector('#form')._x_dataStack[0].$data.entries[0].destination_account;
|
||||||
if (typeof item === 'undefined') {
|
if (typeof item === 'undefined') {
|
||||||
const index = parseInt(ac._searchInput.attributes['data-index'].value);
|
const index = parseInt(ac._searchInput.attributes['data-index'].value);
|
||||||
let destination = document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account;
|
let destination = document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account;
|
||||||
|
|
||||||
if (destination.name === ac._searchInput.value) {
|
if (destination.name === ac._searchInput.value) {
|
||||||
console.warn('Ignore hallucinated destination account name change to "' + ac._searchInput.value + '"');
|
console.warn('Ignore hallucinated destination account name change to "' + ac._searchInput.value + '"');
|
||||||
|
document.querySelector('#form')._x_dataStack[0].detectTransactionType();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account =
|
document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account =
|
||||||
{
|
{
|
||||||
name: ac._searchInput.value,
|
name: ac._searchInput.value,
|
||||||
|
alpine_name: ac._searchInput.value,
|
||||||
};
|
};
|
||||||
console.log('Changed destination account into a unknown account called "' + ac._searchInput.value + '"');
|
console.log('Changed destination account into a unknown account called "' + ac._searchInput.value + '"');
|
||||||
|
document.querySelector('#form')._x_dataStack[0].detectTransactionType();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ function getAccount() {
|
|||||||
return {
|
return {
|
||||||
id: '',
|
id: '',
|
||||||
name: '',
|
name: '',
|
||||||
|
alpine_name: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,10 +38,10 @@ export function parseFromEntries(entries, transactionType) {
|
|||||||
current.currency_code = entry.currency_code;
|
current.currency_code = entry.currency_code;
|
||||||
|
|
||||||
// if ID is set:
|
// if ID is set:
|
||||||
if ('' !== entry.source_account.id.toString()) {
|
if (typeof entry.source_account.id !== 'undefined' && '' !== entry.source_account.id.toString()) {
|
||||||
current.source_id = entry.source_account.id;
|
current.source_id = entry.source_account.id;
|
||||||
}
|
}
|
||||||
if ('' !== entry.destination_account.id.toString()) {
|
if (typeof entry.destination_account.id !== 'undefined' && '' !== entry.destination_account.id.toString()) {
|
||||||
current.destination_id = entry.destination_account.id;
|
current.destination_id = entry.destination_account.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -98,7 +98,7 @@
|
|||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control ac-source"
|
class="form-control ac-source"
|
||||||
:id="'source_' + index"
|
:id="'source_' + index"
|
||||||
x-model="transaction.source_account.name"
|
x-model="transaction.source_account.alpine_name"
|
||||||
:data-index="index"
|
:data-index="index"
|
||||||
placeholder="{{ __('firefly.source_account') }}">
|
placeholder="{{ __('firefly.source_account') }}">
|
||||||
</div>
|
</div>
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
<input type="text"
|
<input type="text"
|
||||||
class="form-control ac-dest"
|
class="form-control ac-dest"
|
||||||
:id="'dest_' + index"
|
:id="'dest_' + index"
|
||||||
x-model="transaction.destination_account.name"
|
x-model="transaction.destination_account.alpine_name"
|
||||||
:data-index="index"
|
:data-index="index"
|
||||||
placeholder="{{ __('firefly.destination_account') }}">
|
placeholder="{{ __('firefly.destination_account') }}">
|
||||||
</div>
|
</div>
|
||||||
@@ -148,7 +148,7 @@
|
|||||||
<select class="form-control" :id="'currency_code_' + index"
|
<select class="form-control" :id="'currency_code_' + index"
|
||||||
x-model="transaction.currency_code"
|
x-model="transaction.currency_code"
|
||||||
>
|
>
|
||||||
<template x-for="currency in enabledCurrencies">
|
<template x-for="currency in nativeCurrencies">
|
||||||
<option :selected="currency.id == defaultCurrency.id" :label="currency.name" :value="currency.code" x-text="currency.name"></option>
|
<option :selected="currency.id == defaultCurrency.id" :label="currency.name" :value="currency.code" x-text="currency.name"></option>
|
||||||
</template>
|
</template>
|
||||||
</select>
|
</select>
|
||||||
@@ -160,7 +160,7 @@
|
|||||||
:data-index="index"
|
:data-index="index"
|
||||||
x-model="transaction.amount"
|
x-model="transaction.amount"
|
||||||
@change="changedAmount"
|
@change="changedAmount"
|
||||||
placeholder="Amount">
|
placeholder="0.00">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user