Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand currency options in transaction form.
James Cole447ec632992d
diff --git a/resources/assets/v2/pages/transactions/create.js b/resources/assets/v2/pages/transactions/create.jsindex 54d819f7d8..26daaedc82 100644--- a/resources/assets/v2/pages/transactions/create.js+++ b/resources/assets/v2/pages/transactions/create.js@@ -67,22 +67,31 @@ let transactions = function () {if (sourceType === destType && ['Asset account', 'Loan', 'Debt', 'Mortgage'].includes(sourceType)) {this.transactionType = 'transfer';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;}// withdrawals:if ('Asset account' === sourceType && ['Expense account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {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;}if ('Asset account' === sourceType && 'unknown' === destType) {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;}if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Expense account' === destType) {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;}@@ -105,9 +114,33 @@ let transactions = function () {{id: item.id,name: item.name,+ alpine_name: item.name,type: item.type,+ currency_code: item.currency_code,};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) {const index = parseInt(e.target.dataset.index);@@ -126,9 +159,12 @@ let transactions = function () {{id: item.id,name: item.name,+ alpine_name: item.name,type: item.type,+ currency_code: item.currency_code,};console.log('Changed destination account into a known ' + item.type.toLowerCase());+ document.querySelector('#form')._x_dataStack[0].detectTransactionType();},loadCurrencies() {console.log('Loading user currencies.');@@ -138,10 +174,10 @@ let transactions = function () {};let getter = new Get();getter.list({}).then((response) => {- for(let i in response.data.data) {- if(response.data.data.hasOwnProperty(i)) {+ for (let i in response.data.data) {+ if (response.data.data.hasOwnProperty(i)) {let current = response.data.data[i];- if(current.attributes.enabled) {+ if (current.attributes.enabled) {let obj ={@@ -153,10 +189,11 @@ let transactions = function () {decimal_places: current.attributes.decimal_places,};- if(obj.default) {+ if (obj.default) {this.defaultCurrency = obj;}this.enabledCurrencies.push(obj);+ this.nativeCurrencies.push(obj);}}}@@ -165,33 +202,43 @@ let transactions = function () {});},changeSourceAccount(item, ac) {+ console.log('changeSourceAccount');if (typeof item === 'undefined') {const index = parseInt(ac._searchInput.attributes['data-index'].value);let source = document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account;if (source.name === ac._searchInput.value) {console.warn('Ignore hallucinated source account name change to "' + ac._searchInput.value + '"');+ document.querySelector('#form')._x_dataStack[0].detectTransactionType();return;}document.querySelector('#form')._x_dataStack[0].$data.entries[index].source_account ={name: ac._searchInput.value,+ alpine_name: 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) {+ let destination = document.querySelector('#form')._x_dataStack[0].$data.entries[0].destination_account;if (typeof item === 'undefined') {const index = parseInt(ac._searchInput.attributes['data-index'].value);let destination = document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account;+if (destination.name === ac._searchInput.value) {console.warn('Ignore hallucinated destination account name change to "' + ac._searchInput.value + '"');+ document.querySelector('#form')._x_dataStack[0].detectTransactionType();return;}document.querySelector('#form')._x_dataStack[0].$data.entries[index].destination_account ={name: ac._searchInput.value,+ alpine_name: ac._searchInput.value,};console.log('Changed destination account into a unknown account called "' + ac._searchInput.value + '"');+ document.querySelector('#form')._x_dataStack[0].detectTransactionType();}},diff --git a/resources/assets/v2/pages/transactions/shared/create-empty-split.js b/resources/assets/v2/pages/transactions/shared/create-empty-split.jsindex be4c43f466..7c04df54ae 100644--- a/resources/assets/v2/pages/transactions/shared/create-empty-split.js+++ b/resources/assets/v2/pages/transactions/shared/create-empty-split.js@@ -25,6 +25,7 @@ function getAccount() {return {id: '',name: '',+ alpine_name: '',};}diff --git a/resources/assets/v2/pages/transactions/shared/parse-from-entries.js b/resources/assets/v2/pages/transactions/shared/parse-from-entries.jsindex 388f6fbfda..82c5e36320 100644--- a/resources/assets/v2/pages/transactions/shared/parse-from-entries.js+++ b/resources/assets/v2/pages/transactions/shared/parse-from-entries.js@@ -38,10 +38,10 @@ export function parseFromEntries(entries, transactionType) {current.currency_code = entry.currency_code;// 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;}- 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;}diff --git a/resources/views/v2/transactions/create.blade.php b/resources/views/v2/transactions/create.blade.phpindex 288abe5bac..651d84225c 100644--- a/resources/views/v2/transactions/create.blade.php+++ b/resources/views/v2/transactions/create.blade.php@@ -98,7 +98,7 @@<input type="text"class="form-control ac-source":id="'source_' + index"- x-model="transaction.source_account.name"+ x-model="transaction.source_account.alpine_name":data-index="index"placeholder="{{ __('firefly.source_account') }}"></div>@@ -112,7 +112,7 @@<input type="text"class="form-control ac-dest":id="'dest_' + index"- x-model="transaction.destination_account.name"+ x-model="transaction.destination_account.alpine_name":data-index="index"placeholder="{{ __('firefly.destination_account') }}"></div>@@ -148,7 +148,7 @@<select class="form-control" :id="'currency_code_' + index"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></template></select>@@ -160,7 +160,7 @@:data-index="index"x-model="transaction.amount"@change="changedAmount"- placeholder="Amount">+ placeholder="0.00"></div></div></div>