Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix https://github.com/firefly-iii/firefly-iii/issues/12607
James Colec3a4c8c569ce
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.jsindex ecb0156afe..853d9d689b 100644--- a/resources/assets/v3/js/pages/transactions/create.js+++ b/resources/assets/v3/js/pages/transactions/create.js@@ -298,6 +298,16 @@ let create = function () {}}},+ changedForeignAmount(e) {+ const index = parseInt(e.target.dataset.index);+ this.entries[index].foreign_amount = parseFloat(e.target.value);+ //this.groupProperties.totalAmount = 0;+ // for (let i in this.entries) {+ // if (this.entries.hasOwnProperty(i)) {+ // this.groupProperties.totalAmount = this.groupProperties.totalAmount + parseFloat(this.entries[i].amount);+ // }+ // }+ },addedSplit() {addAllAutocompleteToForm(this.filters);diff --git a/resources/assets/v3/js/pages/transactions/edit.js b/resources/assets/v3/js/pages/transactions/edit.jsindex b930abd075..6d9d238136 100644--- a/resources/assets/v3/js/pages/transactions/edit.js+++ b/resources/assets/v3/js/pages/transactions/edit.js@@ -49,6 +49,7 @@ const urls = getUrls();let transactions = function () {return {+ i18next: null,// transactions are stored in "entries":entries: [],originals: [],@@ -77,6 +78,7 @@ let transactions = function () {// form data (except transactions) is stored in formDataformData: {primaryCurrency: null,+ amountCurrency: null, // this is the currency of the amount field/**/enabledCurrencies: [],primaryCurrencies: [],foreignCurrencies: [],@@ -112,6 +114,14 @@ let transactions = function () {}this.formBehaviour.categorySelectVisible = document.querySelector('input.ac-category').nextSibling.classList.contains('show');},+ changedForeignAmount(e) {+ const index = parseInt(e.target.dataset.index);+ if('' === e.target.value) {+ this.entries[index].foreign_amount = '';+ return;+ }+ this.entries[index].foreign_amount = parseFloat(e.target.value);+ },// submit the transaction form.// basically the same as store.js.@@ -127,7 +137,6 @@ let transactions = function () {this.entries[i].errors = defaultErrorSet();}}-// parse transaction:let transactions = parseFromEntries(this.entries, this.originals, this.groupProperties.transactionType);let submission = {@@ -234,8 +243,6 @@ let transactions = function () {return formatMoney(this.groupProperties.totalAmount, this.entries[0].currency_code ?? 'EUR');},getTags(index) {- console.log('at get tags ' + index);- console.log(this.entries[index].tags);return this.entries[index].tags ?? [];},@@ -251,6 +258,27 @@ let transactions = function () {this.groupProperties.title = data.attributes.group_title ?? data.attributes.transactions[0].description;this.entries = parseDownloadedSplits(data.attributes.transactions, parseInt(data.id));+ // set amountCurrency.+ for(let i in this.formData.enabledCurrencies) {+ if(this.formData.enabledCurrencies.hasOwnProperty(i)) {+ if(this.formData.enabledCurrencies[i].code === this.entries[0].currency_code) {+ this.formData.amountCurrency = this.formData.enabledCurrencies[i];+ console.log('selected ' + this.formData.amountCurrency.code + ' as amount currency.');+ }+ }+ }+ // limit foreignCurrencies to a single one when it's a transfer+ if('transfer' === this.groupProperties.transactionType) {+ this.formData.foreignCurrencies = [];+ for(let i in this.formData.enabledCurrencies) {+ if(this.formData.enabledCurrencies.hasOwnProperty(i)) {+ if(this.formData.enabledCurrencies[i].code === this.entries[0].forein_currency_code) {+ this.formData.foreignCurrencies.push(this.formData.enabledCurrencies[i]);+ }+ }+ }+ }+// remove waiting thing.this.notifications.wait.show = false;}).then(() => {@@ -287,10 +315,10 @@ let transactions = function () {},init() {+ this.i18next = i18next;// download translations and get the transaction group.this.notifications.wait.show = true;this.notifications.wait.text = i18next.t('firefly.wait_loading_transaction');- this.getTransactionGroup();// load meta data.loadCurrencies().then(data => {@@ -299,6 +327,7 @@ let transactions = function () {this.formData.enabledCurrencies = data.enabledCurrencies;this.formData.primaryCurrencies = data.primaryCurrencies;this.formData.foreignCurrencies = data.foreignCurrencies;+ this.getTransactionGroup();});loadBudgets(true).then(data => {diff --git a/resources/assets/v3/js/pages/transactions/shared/load-currencies.js b/resources/assets/v3/js/pages/transactions/shared/load-currencies.jsindex 28bc480c89..e80b74cbc4 100644--- a/resources/assets/v3/js/pages/transactions/shared/load-currencies.js+++ b/resources/assets/v3/js/pages/transactions/shared/load-currencies.js@@ -35,7 +35,7 @@ export function loadCurrencies() {};returnData.foreignCurrencies.push({- id: 0, name: '(no foreign currency)', code: '', default: false, symbol: '', decimal_places: 2,+ id: 0, name: '(no foreign currency)', code: '__NO_CODE__', default: false, symbol: '', decimal_places: 2,});for (let i in response.data.data) {if (response.data.data.hasOwnProperty(i)) {@@ -62,6 +62,7 @@ export function loadCurrencies() {}}}+ console.log(returnData);return returnData;});}diff --git a/resources/assets/v3/js/pages/transactions/shared/parse-downloaded-splits.js b/resources/assets/v3/js/pages/transactions/shared/parse-downloaded-splits.jsindex 95ca3582ea..0b2344b81d 100644--- a/resources/assets/v3/js/pages/transactions/shared/parse-downloaded-splits.js+++ b/resources/assets/v3/js/pages/transactions/shared/parse-downloaded-splits.js@@ -59,7 +59,7 @@ export function parseDownloadedSplits(downloads, groupId) {current.amount = parseFloat(download.amount).toFixed(download.currency_decimal_places);current.currency_code = download.currency_code;if(null !== download.foreign_amount) {- current.forein_currency_code = download.foreign_currency_code;+ current.foreign_currency_code = download.foreign_currency_code;current.foreign_amount = parseFloat(download.foreign_amount).toFixed(download.foreign_currency_decimal_places);}diff --git a/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.jsindex ff0f94b5c8..f62a1a589b 100644--- a/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js+++ b/resources/assets/v3/js/pages/transactions/shared/parse-from-entries.js@@ -77,17 +77,31 @@ export function parseFromEntries(entries, originals, transactionType) {current.latitude = entry.latitude.toString();current.zoom_level = entry.zoomLevel;}-+ if ('__NO_CODE__' === entry.foreign_currency_code) {+ entry.foreign_currency_code = '';+ }// if foreign amount currency code is set:+ current.foreign_amount = null;+ current.foreign_currency_code = null;if (typeof entry.foreign_currency_code !== 'undefined' && '' !== entry.foreign_currency_code.toString()) {current.foreign_currency_code = entry.foreign_currency_code;- if (typeof entry.foreign_amount !== 'undefined' && '' !== entry.foreign_amount.toString()) {+ console.log('There is a foreign currency code set, ', current.foreign_currency_code);+ if (typeof entry.foreign_amount !== 'undefined' && '' !== entry.foreign_amount.toString() && 0.0 !== entry.foreign_amount) {current.foreign_amount = entry.foreign_amount;+ console.log('There is also a foreign amount set, ', current.foreign_amount);}- if (typeof entry.foreign_amount === 'undefined' || '' === entry.foreign_amount.toString()) {- delete current.foreign_amount;- delete current.foreign_currency_code;- }+ // if (typeof entry.foreign_amount === 'undefined' || '' === entry.foreign_amount.toString() || 0.0 === entry.foreign_amount) {+ // delete current.foreign_amount;+ // delete current.foreign_currency_code;+ // current.foreign_amount = null;+ // current.foreign_currency_code = null;+ // console.log('Remove or reset foreign currency info.');+ // }+ }+ if (null === current.foreign_amount || null === current.foreign_currency_code) {+ console.log('Set both to NULL because one of them is NULL.');+ current.foreign_amount = '0';+ current.foreign_currency_code = '';}// if ID is set:@@ -97,18 +111,18 @@ export function parseFromEntries(entries, originals, transactionType) {if (typeof entry.destination_account.id !== 'undefined' && '' !== entry.destination_account.id.toString()) {current.destination_id = entry.destination_account.id;}- if(i > 0) {- if('withdrawal' === transactionType) {+ if (i > 0) {+ if ('withdrawal' === transactionType) {// overrule sourcecurrent.source_id = returnArray[0].source_id;current.source_name = returnArray[0].source_name;}- if('deposit' === transactionType) {+ if ('deposit' === transactionType) {// overrule destinationcurrent.destination_id = returnArray[0].destination_id;current.destination_name = returnArray[0].destination_name;}- if('transfer' === transactionType) {+ if ('transfer' === transactionType) {// overrule bothcurrent.source_id = returnArray[0].source_id;current.source_name = returnArray[0].source_name;diff --git a/resources/views/partials/form/transaction/foreign-amount.blade.php b/resources/views/partials/form/transaction/foreign-amount.blade.phpindex 5ff10a613e..0005763e1a 100644--- a/resources/views/partials/form/transaction/foreign-amount.blade.php+++ b/resources/views/partials/form/transaction/foreign-amount.blade.php@@ -12,7 +12,7 @@:id="'foreign_currency_code_' + index"x-model="transaction.foreign_currency_code"><template x-for="currency in formData.foreignCurrencies">- <option :label="currency.name" :value="currency.code"+ <option :label="currency.name" :value="currency.code" :selected="transaction.foreign_currency_code == currency.code"x-text="currency.name"></option></template></select>@@ -26,11 +26,11 @@<label class="small form-label">{{ __('firefly.amount_destination_account') }}</label></template><input type="number" step="any" min="0"- :id="'amount_' + index"+ :id="'foreign_amount_' + index":data-index="index":class="{'is-invalid': transaction.errors.foreign_amount.length > 0, 'input-mask' : true, 'form-control': true}"x-model="transaction.foreign_amount"- @change="changedAmount"+ @change="changedForeignAmount"placeholder="0.00"><template x-if="transaction.errors.foreign_amount.length > 0"><div class="invalid-feedback" x-text="transaction.errors.foreign_amount[0]"></div>